We have implemented a solution using P/Invoke which was inspired by the
following article (which comes with code):

http://msdn.microsoft.com/msdnmag/issues/02/10/NETSerialComm/default.aspx

There is also a more recent article somewhere that has code that works for
both the full and the compact frameworks.

We chose to go the simple route and make only synchronous ReadFile and
WriteFile calls, avoiding the extra complexity of overlapped IO.  If we
needed asynchronous behaviour we just ran the serial operations in their
own thread.

Our final port class has only a fraction of the code that they provide as
we cleaned out all of the flexibility that we did not need.

If you roll your own solution, make sure you test under various
conditions.  For instance, we found that everytime we locked our Windows
session (Win-L key combination), at the point in time that we unlocked it,
the serial port would throw a Win32 #995 exception.  If your machine does
this, you will probably want to handle it at a fairly low level.  There
are also other thinks you need to do to recover from comm errors such as
calling PurgeCom after calling ClearCommError to properly reset the port.

It was a lot of work, but we ended up with a solid serial port class.  I'm
looking forward to comparing it to the .NET 2.0 class.

The following link also has a lot of resources:

http://www.lvr.com/serport.htm

Good luck.

Kevin

===================================
This list is hosted by DevelopMentorĀ®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to