Return to Hard &  Software    CFSerialIO

The .NET Compact Framework in Visual Studio 2003 does not provide any native serial port methods.  There are a several classes available online, but I thought I needed to write my own.  I tried to keep it simple, and to the point.  Add the CFSerialPortClass.dll (.NET Assembly) to your SDE project.  The object model appears above.

Note:  You must debug your serial port applications on physical hardware.  The PocketPC 2002 Emulator that is furnished with Visual Studio simply does not emulate the serial port correctly.  Also, performance and timing issues suggest that you should use the actual target hardware, to avoid difficult debugging issues, "down the road."

The class implements OnComm receive events.  Your code may enable these events by setting the EnableOnComm property.  Both Text (ASCII) and Binary data handling are provided.  A CommError event is generated for certain communications errors and if a Break is received.  See the CommErrorFlags Enum for details.

Namespace:  SerialIO

ClassName: SerialPort

The included .NET example was written using VB (as was the SerialPort class).  Source code for the class module is available to readers of my book, Visual Basic Programmer's Guide to Serial Communications, and it is included with the 4th Edition, Published July 2004, Revised March 2006 (click here for information).  Send me email about this (dick_grier@msn.com).  For most users, all that will be needed is the Assembly (DLL) in the download.

FAQ:  You must debug serial communications on actual hardware.  The emulator provided with Visual Studio .NET 2003, just like the one that was part of Embedded Visual Tools 3.0, does not emulate the serial port properly. 

Download Now (Includes CFTerminal Solution and a simple C# example, about 60 KB).      

Disclaimer:  This free software is furnished without a warranty of any kind.  Treat it like beta software; use it, but remember -- you received more than you paid for.  If you have problems or questions, feel free to contact me.  However, my response will be governed by time and other obligations.

Revision History:

April 10, 2003.  Fixed a bug in the InputArray (binary receive) method.  Expanded the CFSerialTerminal example.

April 12, 2003.  Fixed a (potential) bug in the FIFO used to buffer binary data.  Expanded the CFSerialTerminal example to test these changes.

April 15, 2003.  Added the InBufferCount property (a nice feature if using Polled receive).  Expanded the CFTerminal example to test.

May 12, 2003.  Added CD (carrier detect), DSR (dataset ready), CTS (clear to send), and RI (ring indicate) properties.  These return the UART Modem Status Register states, and reflect the corresponding hardware input lines.  Expanded the CFTerminal example to test.

June 2, 2003.  Fixed an error in the InBufferCount property procedure.  A Null Reference error might be generated under some circumstances.

July 1,2003.  Added to the terminal example to illustrate the methods required to marshal data from OnComm receive to display in a form.  Added an example that illustrates waiting for a specific response (terminated by a carriage return character).

September 23, 2003.  Fix setting Parity.  Hardware flow control added (use the CTSFlowcontrol property; this implements CTS/RTS handshaking).

November 25, 2003.  Fix potential race condition in the background read thread that could cause a fatal exception when doing polled receive.

January 29, 2004.  Add additional flow control refinement (ReadThread input mode flowcontrol).  Add CommError event.  Expand terminal example: Log Receive Data To File.

February 3, 2004.  Fix Xon/Xoff bug.

July 28, 2004.  Some Windows CE systems number serial ports starting with zero (0).  The DLL now supports Com0-10.  Use Com0 with care!

Return to Hard &  Software