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

Serial driver for Pocket PC

Rate me:
Please Sign up or sign in to vote.
4.69/5 (22 votes)
26 Mar 2006CPOL2 min read 175K   2.5K   64   62
How to add a new serial port to a Pocket PC device and how to drive this port.

Sample Image - DemoDriver.jpg

Introduction

This article shows how to create Windows CE serial driver. This will add a new serial (COM) port to the device, allowing applications to use this port the same way standard hardware ports are used. The new virtual port provides the same interface as hardware ports do.

Background

The purpose of creating a virtual port is to allow applications (like Tomtom and Destinator) to receive data from a GPS antenna connected to the hardware serial port (COM1) and also to save the received GPS signals to play back when needed and simulate the actual driving.

Using the code

The driver is a DLL that exports the following functions:

  • COM_Init
  • COM_Deinit
  • COM_Open
  • COM_Close
  • COM_Read
  • COM_Write
  • COM_Seek
  • COM_IOControl
  • COM_PowerDown
  • COM_PowerUp
DEMODLL_API DWORD COM_Init(
     LPCTSTR pContext, LPCVOID lpvBusContext );
DEMODLL_API BOOL COM_Deinit(
     DWORD hDeviceContext );
DEMODLL_API DWORD COM_Open(
     DWORD hDeviceContext, DWORD AccessCode, DWORD ShareMode );
DEMODLL_API BOOL COM_Close(
     DWORD hOpenContext );
DEMODLL_API BOOL COM_IOControl(
     DWORD hOpenContext, DWORD dwCode, PBYTE pBufIn, DWORD dwLenIn,
     PBYTE pBufOut, DWORD dwLenOut, PDWORD pdwActualOut );
DEMODLL_API void COM_PowerUp(
     DWORD hDeviceContext );
DEMODLL_API void COM_PowerDown(
     DWORD hDeviceContext );
DEMODLL_API DWORD COM_Read(
     DWORD hOpenContext, LPVOID pBuffer, DWORD Count );
DEMODLL_API DWORD COM_Write(
     DWORD hOpenContext, LPCVOID pBuffer, DWORD Count );
DEMODLL_API DWORD COM_Seek(
     DWORD hOpenContext, long Amount, WORD Type );

In the current sample driver, we map the new serial port to a hardware port (managed port), so all operations on the new port will perform the same operations on the managed port. We also open a log file, and we write all performed operations to this log.

Another important part is how to install the driver on a Pocket PC device. The DLL file must be placed in the \Windows directory, and registry must be updated with the following information:

HKEY_LOCAL_MACHINE\Drivers\BuiltIn\Serial6
    Dll = DemoDriver.dll
    FriendlyName = Demo Driver
    Index = 6
    Order = 2
    Prefix = COM
    ManagePort = 1

In this example, we create a virtual port COM6, but this can be any number from 1 to 9. The ManagePort entry is not required by the OS to create a serial port. This entry is used by our demo driver to define the hardware port number to map to.

The easiest way to install the driver is to create a CAB file that will copy the DemoDriver.dll file to the \Windows directory and update all the registry settings. We provide a sample .inf file to be used with CabWiz to create a CAB file.

[Version]
Signature    = "$Windows NT$"
Provider    = "Code Project"
CESignature    = "$Windows CE$"

[CEStrings]
AppName = "DemoDriver"
InstallDir = %CE2%

[Strings]
reg_path = Drivers\Builtin\Serial6

[DefaultInstall]
CopyFiles    = Dllfiles
Addreg        = Regkeys

[SourceDisksNames]
1 =, "Common Files",, .

[SourceDisksFiles]
DemoDriver.dll    = 1

[DestinationDirs]
Dllfiles = 0, %CE2%

[Dllfiles]
"DemoDriver.dll"

[Regkeys]
HKLM,%reg_path%,Dll,0x00000000,DemoDriver.dll
HKLM,%reg_path%,Prefix,0x00000000,COM
HKLM,%reg_path%,FriendlyName,0x00000000,Demo Driver
HKLM,%reg_path%,Index,0x00010001,6
HKLM,%reg_path%,Order,0x00010001,2
HKLM,%reg_path%,ManagePort,0x00010001,1

Having the CAB file, we copy it to the device and click to install. Soft reset is needed for the OS to start operating the driver.

To make the driver work on WM5 devices, we have to sign the DLL. In this example, we used a method provided in this article: Deploy own certificate built-in our application's CAB (thanks to the author). Our example includes a self signed certificate called MyCert.pfx, and the Cab\PreXML_MyCert.xml file that we provide to CabWiz while creating the cab file.

To sign the driver, we call:

signtool.exe sign /f MyCert.pfx DemoDriver.dll

To create a CAB file, we run:

CabWiz.exe driver.inf /prexml PreXML_MyCert.xml

History

  • March 7, 2006 - The first release.
  • March 27, 2006 - Added code signing for WM5 support.

License

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


Written By
Chief Technology Officer Patrol-IT
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionGSM 07.10 MUX Pin
skid_m28-Aug-06 23:06
skid_m28-Aug-06 23:06 
AnswerRe: GSM 07.10 MUX Pin
Eugene Ochakovsky28-Aug-06 23:14
Eugene Ochakovsky28-Aug-06 23:14 
GeneralRe: GSM 07.10 MUX Pin
skid_m28-Aug-06 23:21
skid_m28-Aug-06 23:21 
GeneralSmall bug Pin
Christian Pare13-Jul-06 11:58
Christian Pare13-Jul-06 11:58 
GeneralRe: Small bug Pin
Eugene Ochakovsky14-Jul-06 11:19
Eugene Ochakovsky14-Jul-06 11:19 
GeneralFailed to open driver... Pin
regtrlhgtrpo11-May-06 6:20
regtrlhgtrpo11-May-06 6:20 
GeneralRe: Failed to open driver... Pin
Eugene Ochakovsky11-May-06 6:43
Eugene Ochakovsky11-May-06 6:43 
GeneralRe: Failed to open driver... Pin
regtrlhgtrpo11-May-06 6:55
regtrlhgtrpo11-May-06 6:55 
Eugene,

Thank you for your very quick reply, I can see the COM6 in ZTerm, but it also
says it can't open it.

You are right, so I'm going to modify the driver not to interact with the
hardware, I saw this is a VC Embedded project, is that okay if I open it with
a VS2005 ? I guess so but I'd like to be sure I'm doing the right thing Smile | :)

Thanks in advance for your help Smile | :)

Florent,
GeneralHELP... Pin
terry_wu_12189-May-06 3:13
terry_wu_12189-May-06 3:13 
GeneralRe: HELP... Pin
Eugene Ochakovsky9-May-06 3:31
Eugene Ochakovsky9-May-06 3:31 
GeneralRe: HELP... Pin
terry_wu_12189-May-06 4:51
terry_wu_12189-May-06 4:51 
GeneralRe: HELP... Pin
coldfish.zhu7-Jun-09 21:13
coldfish.zhu7-Jun-09 21:13 
GeneralProblem signing the files Pin
mERGER3-May-06 22:33
mERGER3-May-06 22:33 
GeneralRe: Problem signing the files Pin
Eugene Ochakovsky4-May-06 1:15
Eugene Ochakovsky4-May-06 1:15 
GeneralRe: Problem signing the files Pin
mERGER11-May-06 7:56
mERGER11-May-06 7:56 
GeneralRe: Problem signing the files Pin
Eugene Ochakovsky11-May-06 8:10
Eugene Ochakovsky11-May-06 8:10 
GeneralWindows CE.NET Pin
kingdomkao19-Apr-06 3:59
kingdomkao19-Apr-06 3:59 
GeneralRe: Windows CE.NET Pin
Eugene Ochakovsky4-May-06 1:14
Eugene Ochakovsky4-May-06 1:14 
GeneralRe: Windows CE.NET Pin
kingdomkao4-May-06 15:04
kingdomkao4-May-06 15:04 
GeneralBluetooth problem Pin
Tom476-Apr-06 6:34
Tom476-Apr-06 6:34 
GeneralRe: Bluetooth problem Pin
Eugene Ochakovsky6-Apr-06 8:01
Eugene Ochakovsky6-Apr-06 8:01 
GeneralRe: Bluetooth problem Pin
High20066-Apr-06 8:11
High20066-Apr-06 8:11 
QuestionPossible for Windows XP as well? Pin
Baldvin Hansson4-Apr-06 0:47
Baldvin Hansson4-Apr-06 0:47 
GeneralVery Good Work Pin
KoriFrancis3-Apr-06 2:19
KoriFrancis3-Apr-06 2:19 
QuestionGPS simulation Pin
sowtschi27-Mar-06 2:47
sowtschi27-Mar-06 2:47 

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.