Click here to Skip to main content
Click here to Skip to main content

Enumerating Serial Ports On Pocket PC

, 10 Dec 2005
Rate this:
Please Sign up or sign in to vote.
C++ Class to enumerate COM ports on Pocket PC
Sample Image - COMEnum.gif

Introduction

Getting information about available ports on Pocket PC device is troublesome due to the fact that Pocket PC registry is different from the ones found in PC operating systems. Information on how to do it in Pocket PC is scarce and quite often does not work. For instance, code posted here recommends to detect IrDA port by looking it up in "HKEY_LOCAL_MACHINE\\Comm\\IrDA" which does not work on Pocket PC 2002 and Pocket PC 2003.

This article introduces CCOMEnum class as an attempt to overcome these issues.

Background

CCOMEnum class finds all available COM ports by parsing "HKEY_LOCAL_MACHINE\\Drivers\\Active" content. All found ports and related data are stored in the structure. Class offers an option of qualifying found ports by obtaining a handle. Qualifying will reduce the number of found ports. Why not do qualifying always? One example - USB port. It is a slave on Pocket PC. Therefore it will not show up when qualify is enabled.

Using the Code

COM Port enumeration is done by calling EnumerateCOMs() function:

virtual void EnumerateCOMs(BOOL Verify);

Verify parameter will control whether or not to verify port by obtaining a handle to it. Once EnumerateCOMs() is called, other member functions can be used to view the data. GetTotalComs() will return number of ports found. This number can be used in for loops or if statements when reading data from CCOMEnum class:

#include "CCOMEnum.h"

CCOMEnum    Enumerator;
UINT        i;
CString    portName;
CString    portKey;
int        portIndex;

Enumerator.EnumerateCOMs(FALSE);

i = 2;

for(i=0; i < Enumerator.GetTotalComs(); i++)
{
    if(Enumerator.GetPortSimpleKey(i) == "Serial2")
    {
        portName     = Enumerator.GetPortName(i);    // "COM2:"
        portKey        = Enumerator.GetPortKey(i);    // 
        portIndex    = Enumerator.GetPortIndex(i);    // Such as 2
    }
}

GetPortSimpleKey() and GetPortKey() return CString value that can be used to sort ports out by functionality.

History

The current version is 1.0. Although this code will be periodically updated here, for the latest code please check developer's web site http://www.advatronix.com/. There, you can also download a pre-built executable.

License

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

About the Author

advatronix
Web Developer
United States United States
No Biography provided

Comments and Discussions

 
GeneralAnother way PinmemberAndrewAZ5-Dec-06 22:33 
QuestionRe: Another way Pinmembermarkusschroth3-Jan-07 9:26 
AnswerRe: Another way [modified] PinmemberAndrewAZ8-Jan-07 22:22 
QuestionUsage of CString::Format PinmemberMechJayTi19-Sep-06 0:02 
QuestionAnother possibility PinmemberTony Kmoch12-Dec-05 23:30 

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.

| Advertise | Privacy | Mobile
Web01 | 2.8.140721.1 | Last Updated 10 Dec 2005
Article Copyright 2005 by advatronix
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid