Click here to Skip to main content
12,635,441 members (23,057 online)
Click here to Skip to main content
Add your own
alternative version

Stats

140.8K views
2K downloads
64 bookmarked
Posted

Serial driver for Pocket PC

, 26 Mar 2006 CPOL
Rate this:
Please Sign up or sign in to vote.
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)

Share

About the Author

Eugene Ochakovsky
Chief Technology Officer Patrol-IT
United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

 
Generaldifferent baud rate Pin
pguido17-Jan-11 6:02
memberpguido17-Jan-11 6:02 
GeneralCan't load the driver in WM5 and WM6 Pin
mgr7-Aug-10 1:13
membermgr7-Aug-10 1:13 
GeneralFailed to load the driver. Pin
voquochung27-Oct-08 23:09
membervoquochung27-Oct-08 23:09 
GeneralRegarding Copy to SIM Pin
Sreekanth Muralidharan13-Jul-08 15:57
memberSreekanth Muralidharan13-Jul-08 15:57 
GeneralVirtual COM Pin
poornimaniranjan13-May-08 0:03
memberpoornimaniranjan13-May-08 0:03 
Questiondetecting the process connecting a virtual port Pin
mk1757-Mar-08 9:34
membermk1757-Mar-08 9:34 
QuestionSerial Driver Pin
kathalora5-Nov-07 20:11
memberkathalora5-Nov-07 20:11 
AnswerRe: Serial Driver Pin
Eugene Ochakovski5-Nov-07 22:47
memberEugene Ochakovski5-Nov-07 22:47 
QuestionRe: Serial Driver Pin
kathalora6-Nov-07 16:28
memberkathalora6-Nov-07 16:28 
QuestionWindows CE or Microsoft mobile 5.0? Pin
konbanke14-Oct-07 20:43
memberkonbanke14-Oct-07 20:43 
QuestionVirtual COM Port Pair? Pin
EricGHLU30-Sep-07 18:35
memberEricGHLU30-Sep-07 18:35 
AnswerRe: Virtual COM Port Pair? Pin
Eugene Ochakovski30-Sep-07 22:40
memberEugene Ochakovski30-Sep-07 22:40 
QuestionFailed to open Virtual COM Port in Windows Mobile 5? Pin
EricGHLU30-Sep-07 18:29
memberEricGHLU30-Sep-07 18:29 
AnswerRe: Failed to open Virtual COM Port in Windows Mobile 5? Pin
Eugene Ochakovski30-Sep-07 22:36
memberEugene Ochakovski30-Sep-07 22:36 
GeneralThanks for your help Pin
Xuewu Liu8-Sep-07 21:50
memberXuewu Liu8-Sep-07 21:50 
GeneralFirst Steps / Buffer Overflow > 2000 Byte [modified] Pin
Atlan198026-Jul-07 21:39
memberAtlan198026-Jul-07 21:39 
GeneralNice one Pin
Marcel Schlebusch24-Jul-07 7:14
memberMarcel Schlebusch24-Jul-07 7:14 
QuestionHow can i use WM5 ? Pin
hyohaeng20-Jul-07 8:11
memberhyohaeng20-Jul-07 8:11 
AnswerRe: How can i use WM5 ? Pin
Eugene Ochakovski21-Jul-07 22:42
memberEugene Ochakovski21-Jul-07 22:42 
QuestionVirtual serial port Pair Pin
kum8417-Jul-07 17:34
memberkum8417-Jul-07 17:34 
AnswerRe: Virtual serial port Pair Pin
Eugene Ochakovski17-Jul-07 22:18
memberEugene Ochakovski17-Jul-07 22:18 
Question[Q] Mapping COM-port PDA to Terminal Host Pin
longvalery11-Jul-07 21:00
memberlongvalery11-Jul-07 21:00 
QuestionAny example create serial port in Windows XP? Pin
pctimhk3-May-07 21:20
memberpctimhk3-May-07 21:20 
QuestionMultiple port registration Pin
kolda18-Feb-07 0:31
memberkolda18-Feb-07 0:31 
AnswerRe: Multiple port registration Pin
Eugene Ochakovski18-Feb-07 2:13
memberEugene Ochakovski18-Feb-07 2:13 

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.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.161208.2 | Last Updated 27 Mar 2006
Article Copyright 2006 by Eugene Ochakovsky
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid