Can Python serial support run at 45.45 baud?
MRAB
google at mrabarnett.plus.com
Sat Feb 14 13:48:56 EST 2009
John Nagle wrote:
> John Nagle wrote:
>
>> OK, tried to open the port, using Python 2.6, latest PySerial
>> and PyWin32:
>>
>> ser = serial.Serial(port, baudrate=baud,
>> bytesize=serial.FIVEBITS,
>> parity=serial.PARITY_NONE,
>> stopbits=serial.STOPBITS_TWO)
>>
>> ValueError: Cannot configure port, some setting was wrong. Original
>> message: (87, 'SetCommState', 'The parameter is incorrect.')
>>
>> Something doesn't like "serial.FIVEBITS". That's a valid value,
>> according
>> to "http://pyserial.wiki.sourceforge.net/pySerial". If changed to
>> "serial.EIGHTBITS", the code will execute, but of course does the wrong
>> thing. That looks like a bug.
>
> OK, here's what's wrong. The allowed numbers for stop bits in
> Windows are
>
> ONESTOPBIT 0 1 stop bit.
> ONE5STOPBITS 1 1.5 stop bits.
> TWOSTOPBITS 2 2 stop bits.
>
> The Python interface, however, only exports STOPBITS_ONE and STOPBITS_TWO.
> See "serialutil.py", at line 9, and "serialwin32.py" at lines 141-146.
>
> Microsoft documentation
> ("http://msdn.microsoft.com/en-us/library/aa363214(VS.85).aspx") says:
>
> * The use of 5 data bits with 2 stop bits is an invalid combination,
> as is 6, 7, or 8 data bits with 1.5 stop bits.
>
> So the correct combination, 5 bits with 1.5 stop bits, isn't supported in
> Python. 1 stop bit will not physically work on Baudot teletypes; the
> main camshaft doesn't come around fast enough. (Yes, there's an actual
> mechanical reason for 1.5 stop bits.) Requesting 2 stop bits at the
> Python level gets a reject at the Win32 level. (Not sure why Win32
> doesn't allow that; extra stop bits just add delay, but don't hurt
> anything. But it's not supported.)
>
> Linux has a different set of restrictions; Linux offers only 1 or 2 stop
> bits, and won't do arbitrary baud rates via the "termios" data structure,
> although there are other ways to request that. At the hardware level,
> there's a clock rate, a counter, and a divisor, so arbitrary baud
> rates can be set.
>
If 5+2 is invalid, could you work around it with 6+1 instead (one of the
data bits masquerading as a stop bit)? Presumably the device on the
other end won't care as long as it gets the bits it expects...
More information about the Python-list
mailing list