Click here to Skip to main content
Licence CPOL
First Posted 6 Mar 2006
Views 109,265
Downloads 777
Bookmarked 58 times

Serial driver for Pocket PC

By | 26 Mar 2006 | Article
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)

About the Author

Eugene Ochakovsky

Architect
Visicom
Israel Israel

Member

Follow on Twitter Follow on Twitter


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
Generaldifferent baud rate Pinmemberpguido5:02 17 Jan '11  
GeneralCan't load the driver in WM5 and WM6 Pinmembermgr0:13 7 Aug '10  
GeneralFailed to load the driver. Pinmembervoquochung22:09 27 Oct '08  
GeneralRegarding Copy to SIM PinmemberSreekanth Muralidharan14:57 13 Jul '08  
GeneralVirtual COM Pinmemberpoornimaniranjan23:03 12 May '08  
Questiondetecting the process connecting a virtual port Pinmembermk1758:34 7 Mar '08  
QuestionSerial Driver Pinmemberkathalora19:11 5 Nov '07  
AnswerRe: Serial Driver PinmemberEugene Ochakovski21:47 5 Nov '07  
QuestionRe: Serial Driver Pinmemberkathalora15:28 6 Nov '07  
QuestionWindows CE or Microsoft mobile 5.0? Pinmemberkonbanke19:43 14 Oct '07  
QuestionVirtual COM Port Pair? PinmemberEricGHLU17:35 30 Sep '07  
AnswerRe: Virtual COM Port Pair? PinmemberEugene Ochakovski21:40 30 Sep '07  
QuestionFailed to open Virtual COM Port in Windows Mobile 5? PinmemberEricGHLU17:29 30 Sep '07  
AnswerRe: Failed to open Virtual COM Port in Windows Mobile 5? PinmemberEugene Ochakovski21:36 30 Sep '07  
GeneralThanks for your help PinmemberXuewu Liu20:50 8 Sep '07  
GeneralFirst Steps / Buffer Overflow > 2000 Byte [modified] PinmemberAtlan198020:39 26 Jul '07  
GeneralNice one PinmemberMarcel Schlebusch6:14 24 Jul '07  
QuestionHow can i use WM5 ? Pinmemberhyohaeng7:11 20 Jul '07  
AnswerRe: How can i use WM5 ? PinmemberEugene Ochakovski21:42 21 Jul '07  
QuestionVirtual serial port Pair Pinmemberkum8416:34 17 Jul '07  
AnswerRe: Virtual serial port Pair PinmemberEugene Ochakovski21:18 17 Jul '07  
Question[Q] Mapping COM-port PDA to Terminal Host Pinmemberlongvalery20:00 11 Jul '07  
QuestionAny example create serial port in Windows XP? Pinmemberpctimhk20:20 3 May '07  
QuestionMultiple port registration Pinmemberkolda23:31 17 Feb '07  
AnswerRe: Multiple port registration PinmemberEugene Ochakovski1:13 18 Feb '07  

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 27 Mar 2006
Article Copyright 2006 by Eugene Ochakovsky
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid