[Mono-dev] Question on SerialPort - Serial.c

foros at arocholl.com foros at arocholl.com
Sun Jan 13 22:56:18 UTC 2013


>>Does Microsoft's implementation accept *any* baud rate, or are there only
some that it accepts that Mono doesn't? If Microsoft's accepts any then
maybe the baud rate validation should be moved from Mono.

 

Apparently, yes, MS accepts any baudrate but zero or lower than zero.

 

I tested several custom baudrate values and, as far as I can see, all them
are accepted by .NET SerialPort. Perhaps the Microsoft approach is to ask
the underlying driver to validate baudrates, if at all. In the case of the
Windows CP2102 driver, it will accept any baudrate including ones that are
not physically supported. For instance I tested 1,500,000bps which is not
really going to work on the physical CP2102 hardware (max available speed is
920,000bps on the CP2102 device) and still the SerialPort accepts the
1,500,000 bps, connects to it and if you read the baudrate property, it
returns 1,500,000. So probably the Mono approach is too limited, because it
really depends on a switch/case with a set of hardcoded, predefined values. 

 

See a fraction of Serial.c below

 

            switch (baud_rate)

            {

..

            case 115200: 

                baud_rate = B115200;

                break;

            case 57600:

                baud_rate = B57600;

                break;

..

            case 50:

            case 0:

            default:

                baud_rate = -1;

                        break;

            }

 

Anything that is unknown goes to <default> which in the end returns an
unsupported baudrate exception to the caller.

 

However, that doesn't seem the way the Windows .NET SerialPort class works
and, in today's world of interconnected USB COM custom devices, it really
puts a hard limit on baudrates you can use. Interestingly, the documentation
of SerialPort::Open doesn't explicitly document any baudrate value being
invalid, except if it is equal or lower than zero. From MSDN:

 


ArgumentOutOfRangeException
<http://msdn.microsoft.com/en-us/library/system.argumentoutofrangeexception%
28v=vs.100%29.aspx> 

One or more of the properties for this instance are invalid. For example,
the
<http://msdn.microsoft.com/en-us/library/system.io.ports.serialport.parity%2
8v=vs.100%29.aspx> Parity,
<http://msdn.microsoft.com/en-us/library/system.io.ports.serialport.databits
%28v=vs.100%29.aspx> DataBits, or
<http://msdn.microsoft.com/en-us/library/system.io.ports.serialport.handshak
e%28v=vs.100%29.aspx> Handshake properties are not valid values; the
<http://msdn.microsoft.com/en-us/library/system.io.ports.serialport.baudrate
%28v=vs.100%29.aspx> BaudRate is less than or equal to zero; the
<http://msdn.microsoft.com/en-us/library/system.io.ports.serialport.readtime
out%28v=vs.100%29.aspx> ReadTimeout or
<http://msdn.microsoft.com/en-us/library/system.io.ports.serialport.writetim
eout%28v=vs.100%29.aspx> WriteTimeout property is less than zero and is not
<http://msdn.microsoft.com/en-us/library/system.io.ports.serialport.infinite
timeout%28v=vs.100%29.aspx> InfiniteTimeout. 

 

 

So except anyone disagree, baudrate values should not be checked for
anything different than that. I will then fill in a bugzilla entry and pull
a request in a few days. I am a Mercurial guy so have to get used to GIT in
the first place.

 

In general terms, how often a new Mono version is released with all the
accumulated fixes? I saw releases are probably a few months apart in the
official download site, is that driven by a scheduled event of any kind?

 

>> You should be able to run "make" and "make install" in the directory of
the file you're modifying, and that should compile and install just that
component.

 

Thanks for the tip, this is much better. It works nicely.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ximian.com/pipermail/mono-devel-list/attachments/20130113/333d7f4e/attachment.html>


More information about the Mono-devel-list mailing list