Can Python serial support run at 45.45 baud?

MRAB google at mrabarnett.plus.com
Sat Feb 14 19:07:20 CET 2009


John Nagle wrote:
> Grant Edwards wrote:
>> On 2009-02-14, John Nagle <nagle at animats.com> wrote:
>>
>>> Can Python's serial port support be made to run at 45.45 baud,
>>> the old "60 speed" Teletype machine speed? 
>>
>> If your hardware and OS supports it, Python can be made to
>> support it.
> 
>    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)
> 
> Traceback (most recent call last):
>   File "serialtest.py", line 27, in <module>
>     main()
>   File "serialtest.py", line 24, in main
>     ser = openportbaudot(0,45.45)
>   File "serialtest.py", line 17, in openportbaudot
>     stopbits=serial.STOPBITS_TWO)
>   File "D:\python26\lib\site-packages\serial\serialutil.py", line 171, 
> in __init__
>     self.open()
>   File "D:\python26\lib\site-packages\serial\serialwin32.py", line 63, 
> in open
>     self._reconfigurePort()
>   File "D:\python26\lib\site-packages\serial\serialwin32.py", line 171, 
> in _reconfigurePort
>     raise ValueError("Cannot configure port, some setting was wrong. 
> Original message: %s" % e)
> 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.
> 
>    I tried various values for "baud".  PySerial will accept "45", and 
> even "45.45", although I doubt that it's really calculating the serial 
> port divisor
> values from a floating point value.   (Standard serial port hardware can do
> 45.45 baud, and most PCs with non-USB serial ports will do it quite well.)
> For my application, 45 baud should work, with two stop bits; the
> tolerances aren't that tight.
> 
I don't think it's a Python bug. The MSDN website says this:

(http://msdn.microsoft.com/en-us/library/aa363214(VS.85).aspx.)

When a DCB structure is used to configure the 8250, the following 
restrictions apply to the values specified for the ByteSize and StopBits 
members:

     * The number of data bits must be 5 to 8 bits.
     * 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.




More information about the Python-list mailing list