[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
baud_rate = B115200;
baud_rate = B57600;
baud_rate = -1;
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:
One or more of the properties for this instance are invalid. For example,
%28v=vs.100%29.aspx> DataBits, or
e%28v=vs.100%29.aspx> Handshake properties are not valid values; the
%28v=vs.100%29.aspx> BaudRate is less than or equal to zero; the
out%28v=vs.100%29.aspx> ReadTimeout or
eout%28v=vs.100%29.aspx> WriteTimeout property is less than zero and is not
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
Thanks for the tip, this is much better. It works nicely.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Mono-devel-list