Resources | Resources |



Connecting a Brew MP application to a PC through USB/IPort

Base version:

Brew MP 1.0

Tested version:

Brew MP 1.0

Phone tested:



This topic describes how to

  • Connect a Brew® MP application to a PC via USB/IPort

  • Send Attention (AT) commands to the Attention Command Processor (ATCOP)


The application needs to use the correct COM port and the correct commands.

Example - Determining which COM port to use

To determine which COM port to use:

  1. Open Device Manager.

    Under Modems, you should see a modem corresponding to the device.

  2. Right-click on the modem and select Properties.

  3. In the Properties dialog box for the modem, click the Modem tab.

    At the top of the Modem tab, the Port value indicates the COM port to use.

Example - Sending AT commands to the ATCOP

After the application successfully sends an AT$BREW command, the application communicates with the Brew MP Serial Command Processor (BSCOP). The BSCOP commands have numbers prepended to them, such as 01ver or 02app.

If the application opens AEESIO_PORT_INCOMING, the application gains control of the port that enters (or is already in BSCOP). The port also only opens when the transition into BSCOP occurs.

Note: If you're writing an internal tool for the device, you may want to consider using Connect. It handles the serial port/connectivity issues, provides reliability, and has other features such as the ability to copy files, send events, and start applets.

The following sample code is from a file called siousage.c. SIO is a protected class. To create it, you must declare a dependency on AEECLSID_SERIAL in your MIF.

// Our applet's structure
typedef struct SIOUsage
   AEEApplet      a;
   IPort         *piPort;
   AEECallback    cbReadable;
   AEECallback    cbWriteable;
} SIOUsage;

static int SIOUsage_Init(SIOUsage *pme)
   int nErr;

   nErr = ISHELL_CreateInstance(pme->a.m_pIShell, AEECLSID_SERIAL,

   if (nErr != SUCCESS)
      return EFAILED;

   // The following line opens the USB serial port.  To open the RS-232
   // serial port, use AEESIO_PORT_SIO1
   nErr = IPORT_Open(pme->piPort, AEESIO_PORT_USB1);
   if (nErr != SUCCESS && nErr != AEEPORT_WAIT)
   // There was some unknown error opening the port
      DBGPRINTF("Error opening port");
      return EFAILED;

   // Setup our callbacks.  These are called when there is *probably* data
   // to be written or read.
   CALLBACK_Init(&pme->cbReadable, SIOUsage_TryRead, (void*)pme);
   CALLBACK_Init(&pme->cbWriteable, SIOUsage_TryWrite, (void*)pme);
   IPORT_Readable(pme->piPort, &pme->cbReadable);
   IPORT_Writeable(pme->piPort, &pme->cbWriteable);

   // At this point, if nErr is AEEPORT_WAIT, the serial port is opening.
   // We'll know this is complete when our cbWriteable callback fires.
   // Normally, we'll receive AEEPORT_WAIT instead of SUCCESS.

static void SIOUsage_TryRead(void *po)
   SIOUsage *pme = (SIOUsage*)po;
   int32 dwRead;
   char buf[100];

   // We can *probably* read data here
   dwRead = IPORT_Read(pme->piPort, buf, sizeof(buf));

   // Log a message if we did read data
   if (dwRead > 0)
      DBGPRINTF("Read %ld bytes of data", dwRead);

   // Remember that we need to reset our readable callback
   IPORT_Readable(pme->piPort, &pme->cbReadable);

static void SIOUsage_TryWrite(void *po)
   SIOUsage *pme = (SIOUsage*)po&
   int32 dwWrite&
   char *pBuf = "Hello World!";

   // If you want to know if the port successfully got opened, do it here.
   //   what you want to do is nErr = IPORT_Open(pme->piPort, NULL);

   // We can *probably* write data here
   dwWrite = IPORT_Write(pme->piPort, pBuf, STRLEN(pBuf));

   // Log a message if we did read data
   if (dwWrite > 0)
      DBGPRINTF("We wrote %ld bytes of data", dwWrite);

   // Remember that we need to reset our writeable callback
   IPORT_Writeable(pme->piPort, &pme->cbWriteable);