Can Python serial support run at 45.45 baud?

John Nagle nagle at animats.com
Sat Feb 14 13:26:22 EST 2009


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.

					John Nagle



More information about the Python-list mailing list