[Mono-dev] Serial ports in mono - event notification

Engler, Eric Eric.Engler at zcsterling.com
Mon Oct 15 13:45:53 EDT 2007

Hash: SHA256

>What is the current status on the event notification mechanism of 
>serial ports in  Mono? 

I can't comment on the Mono status question but I thought I'd pass along
a lesson I learned about serial events in Windows. They are notoriously
late in many cases due to buffering. They are supposed to occur quick
enough to let you stream at a high baud rate, but Windows XP tries to
reduce the frequency of the events because it can cache the data (it
caches a lot more than the small UART cache buffer). This is maddening
for people like me who want to know immediately when a byte has been

If you only need a relatively low baud rate, or if you can tolerate a
delay in notification, this may be fine. In my case I needed 115K baud
and I had to know immediately when a byte was received (I could not
accept any significant latency).

I took a 2-prong approach to fix my problem. Firstly, when I am in a
routine that knows how many bytes to expect I go into a tight loop and
receive that number of bytes. Secondly, when I am not sure when to
expect incoming data, I hook the Windows Application_Idle event and I
poll the serial port to see if it found any data. This polling gives me
immediate notification without delay, but the Application_Idle event
doesn't occur often enough to let me stream data at 115K baud, so that's
why I combined both approaches. Another advantage of this approach is
that it freed me from the threading concern of having to marshal over
the data from a background event over to the GUI thread (not difficult,
but still a little bit of a pain).

You can see my Windows application here (a visual debugger for

Mono serial events (when implemented) might not share this Windows XP
problem, especially when running on linux, but if you need one
application to work on both environments this is something to consider.


NOTICE:  The information contained in this electronic mail transmission is intended by the sender for the sole use of the named individual or entity to which it is directed and may contain information that is privileged or 
otherwise confidential.  Please do not copy it or use it for any purposes, or disclose its contents to any other person.  To do so could violate state and Federal privacy laws.  If you have received this electronic mail
transmission in error, please delete it from your system without copying or forwarding it, and notify the sender of the error by reply email or by telephone, so that the sender's address records can be corrected.  Thank you for your cooperation.

Version: PGP Universal 2.6.2
Charset: us-ascii


More information about the Mono-devel-list mailing list