Click here to Skip to main content
Licence CPOL
First Posted 28 Nov 2007
Views 65,616
Downloads 727
Bookmarked 44 times

Serial Port Enumeration on Windows Mobile

By | 28 Nov 2007 | Article
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:

CSerialPortEnum portEnum;

Now, we are ready to enumerate the serial ports:

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)

About the Author

Joao Paulo Figueira

Software Developer
Primeworks
Portugal Portugal

Member

João is a partner at Primeworks, a company that develops remote database access software for Windows Mobile. He also works for Frotcom, a company that develops web-based fleet management solutions.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralBluetooth virtual serial por Pinmemberxiaboyang20:30 31 Mar '11  
GeneralFinding GPS device Pinmemberwerner.keilholz11:29 13 Feb '09  
GeneralRe: Finding GPS device PinmemberJoao Paulo Figueira11:56 13 Feb '09  
GeneralRe: Finding GPS device Pinmemberwerner.keilholz12:27 13 Feb '09  
GeneralRe: Finding GPS device PinmemberJoao Paulo Figueira1:12 14 Feb '09  
GeneralRe: Finding GPS device Pinmemberwerner.keilholz5:24 15 Feb '09  
QuestionGetting Audio Stream from Phone coonected via USB or Blue Tooth Pinmemberpankaj motiyar19:50 15 Jul '08  
GeneralHello sir PinmemberTheLibra20:33 17 May '08  
GeneralProblem with enumeration Pinmembersusilrani22:39 13 May '08  
GeneralRe: Problem with enumeration PinmemberJoao Paulo Figueira23:00 13 May '08  
Questionhow to get infromation from serial port Pinmembersusilrani17:05 12 May '08  
AnswerRe: how to get infromation from serial port PinmemberJoao Paulo Figueira22:10 12 May '08  
GeneralRe: how to get infromation from serial port [modified] Pinmembersusilrani22:59 12 May '08  
GeneralRe: how to get infromation from serial port Pinmembersusilrani15:11 13 May '08  
GeneralRe: how to get infromation from serial port PinmemberJoao Paulo Figueira23:31 13 May '08  
GeneralRe: how to get infromation from serial port Pinmembersusilrani18:48 14 May '08  
GeneralProblem of running the application Pinmemberlisaqau21:59 16 Apr '08  
GeneralRe: Problem of running the application PinmemberFred Strathmann16:56 17 Apr '08  
GeneralRe: Problem of running the application Pinmembersusilrani0:06 9 May '08  
GeneralRe: Problem of running the application PinmemberJoao Paulo Figueira0:10 9 May '08  
GeneralRe: Problem of running the application Pinmembersusilrani16:29 9 May '08  
QuestionWhat about XP and Vista? Pinmemberlotfimira7:55 11 Apr '08  
AnswerRe: What about XP and Vista? PinmemberJoao Paulo Figueira8:33 11 Apr '08  

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

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

Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120528.1 | Last Updated 29 Nov 2007
Article Copyright 2007 by Joao Paulo Figueira
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid