Click here to Skip to main content
15,886,664 members
Articles / Mobile Apps / Windows Mobile

Serial Port Enumeration on Windows Mobile

Rate me:
Please Sign up or sign in to vote.
3.88/5 (11 votes)
28 Nov 2007CPOL1 min read 119.6K   45.3K   50   23
How to enumerate serial ports in a Windows Mobile device (including the virtual ports created by the Microsoft Bluetooth stack).

Screenshot - WMEnumComPorts.png

Introduction

This short article describes a serial port enumeration method for Windows Mobile devices that includes the Microsoft Bluetooth stack virtual COM ports.

Background

I was recently asked to write a little user interface that would enumerate all COM ports on Windows Mobile devices and that, if possible, provided a brief description of the attached device. After looking around CodeProject for a solution, I found a very promising approach in Joaquín's article. I followed a similar approach by enumerating all the keys under HKEY_LOCAL_MACHINE\Drivers\Active but found a big problem: on devices with the Microsoft Bluetooth stack, the virtual COM ports are not listed under this key. Interestingly, the Widcomm Bluetooth stack does seem to get this right.

The image above shows two Windows Mobile devices running the sample application. On the right, you see a screen capture of a WM6 Asus P535 with the Widcomm Bluetooth stack. All the enumerated ports were drawn from the active drivers registry key as I stated above. On the left, you see a WM5 i-mate K-Jam device with the Microsoft Bluetooth stack. In order to retrieve the information about the COM6: port, I had to look elsewhere in the registry, namely under the Software\Microsoft\Bluetooth\Serial\Ports key.

Using the code

Using the serial port enumeration code is quite simple. Start by declaring an object of type CSerialPortEnum:

C++
CSerialPortEnum portEnum;

Now, we are ready to enumerate the serial ports:

C++
size_t i;
int    iItem = 0;

for(i = 0; i < portEnum.GetCount(); ++i)
{
    const CSerialPortInfo *pInfo = portEnum[i];

    if(pInfo != NULL)
    {
        iItem = listPort.AddItem(iItem, 0, pInfo->GetPortName());
        listPort.SetItemText(iItem, 1, pInfo->GetDescription());
    }
}

Please note that the enumeration object does not sort the list by COM port number. If you need to reuse the object to enumerate the serial ports again, just call the EnumeratePorts function.

Also note that this code has only been tested on Windows Mobile 5 and 6 devices (Pocket PC).

History

  • 2007-11-29 - First publication on CodeProject.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Frotcom International
Portugal Portugal
I work on R&D for Frotcom International, a company that develops web-based fleet management solutions.

Comments and Discussions

 
GeneralBluetooth virtual serial por Pin
xiaboyang31-Mar-11 20:30
xiaboyang31-Mar-11 20:30 
GeneralFinding GPS device Pin
werner.keilholz13-Feb-09 11:29
werner.keilholz13-Feb-09 11:29 
GeneralRe: Finding GPS device Pin
João Paulo Figueira13-Feb-09 11:56
professionalJoão Paulo Figueira13-Feb-09 11:56 
GeneralRe: Finding GPS device Pin
werner.keilholz13-Feb-09 12:27
werner.keilholz13-Feb-09 12:27 
GeneralRe: Finding GPS device Pin
João Paulo Figueira14-Feb-09 1:12
professionalJoão Paulo Figueira14-Feb-09 1:12 
GeneralRe: Finding GPS device Pin
werner.keilholz15-Feb-09 5:24
werner.keilholz15-Feb-09 5:24 
QuestionGetting Audio Stream from Phone coonected via USB or Blue Tooth Pin
pankaj motiyar15-Jul-08 19:50
pankaj motiyar15-Jul-08 19:50 
GeneralHello sir Pin
TheLibra17-May-08 20:33
TheLibra17-May-08 20:33 
GeneralProblem with enumeration Pin
susilrani13-May-08 22:39
susilrani13-May-08 22:39 
GeneralRe: Problem with enumeration Pin
João Paulo Figueira13-May-08 23:00
professionalJoão Paulo Figueira13-May-08 23:00 
Questionhow to get infromation from serial port Pin
susilrani12-May-08 17:05
susilrani12-May-08 17:05 
AnswerRe: how to get infromation from serial port Pin
João Paulo Figueira12-May-08 22:10
professionalJoão Paulo Figueira12-May-08 22:10 
Do you mean querying the GPS device via serial port?

Regards,
João Paulo Figueira
DAD MVP

GeneralRe: how to get infromation from serial port [modified] Pin
susilrani12-May-08 22:59
susilrani12-May-08 22:59 
GeneralRe: how to get infromation from serial port Pin
susilrani13-May-08 15:11
susilrani13-May-08 15:11 
GeneralRe: how to get infromation from serial port Pin
João Paulo Figueira13-May-08 23:31
professionalJoão Paulo Figueira13-May-08 23:31 
GeneralRe: how to get infromation from serial port Pin
susilrani14-May-08 18:48
susilrani14-May-08 18:48 
GeneralProblem of running the application Pin
lisaqau16-Apr-08 21:59
lisaqau16-Apr-08 21:59 
GeneralRe: Problem of running the application Pin
Fred Strathmann17-Apr-08 16:56
Fred Strathmann17-Apr-08 16:56 
GeneralRe: Problem of running the application Pin
susilrani9-May-08 0:06
susilrani9-May-08 0:06 
GeneralRe: Problem of running the application Pin
João Paulo Figueira9-May-08 0:10
professionalJoão Paulo Figueira9-May-08 0:10 
GeneralRe: Problem of running the application Pin
susilrani9-May-08 16:29
susilrani9-May-08 16:29 
QuestionWhat about XP and Vista? Pin
lotfimira11-Apr-08 7:55
lotfimira11-Apr-08 7:55 
AnswerRe: What about XP and Vista? Pin
João Paulo Figueira11-Apr-08 8:33
professionalJoão Paulo Figueira11-Apr-08 8:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.