termios question

Allen W. Ingling ingling at ctrvax.vanderbilt.edu
Mon Feb 21 10:27:09 EST 2000


I can't seem to set the serial port baud rate using the termios
module.   Permissions on ttyS0 are both read and write for root, and
I run Python as root.   I'm running  Python 1.5.2 on RedHat 6.1, if
that's any help.  Here's an example:

>>> import os
>>> import TERMIOS
>>> import termios
>>> fd = os.open("/dev/ttyS0", os.O_RDWR | os.O_NOCTTY | os.O_NDELAY)
>>> attribs = termios.tcgetattr(fd)
>>> attribs
[1280, 5, 3261, 35387, 13, 13, ['\003', '\034', '\177', '\025',
'\004', '\000', '\001', '\000', '\021', '\023', '\032', '\000',
'\022', '\017', '\027', '\026', '\000', '\000', '\000', '\000',
'\000', '\000', '\000', '\000', '\000', '\000', '\000', '\000',
'\000', '\000', '\000', '\000']]
>>> attribs[2] = attribs[2] & ~TERMIOS.CBAUD
>>> attribs[2] = attribs[2] | TERMIOS.B1200
>>> attribs
[1280, 5, 3257, 35387, 13, 13, ['\003', '\034', '\177', '\025',
'\004', '\000', '\001', '\000', '\021', '\023', '\032', '\000',
'\022', '\017', '\027', '\026', '\000', '\000', '\000', '\000',
'\000', '\000', '\000', '\000', '\000', '\000', '\000', '\000',
'\000', '\000', '\000', '\000']]
>>> termios.tcsetattr(fd, TERMIOS.TCSANOW, attribs)
>>> attribs2 = termios.tcgetattr(fd)
>>> attribs2
[1280, 5, 3261, 35387, 13, 13, ['\003', '\034', '\177', '\025',
'\004', '\000', '\001', '\000', '\021', '\023', '\032', '\000',
'\022', '\017', '\027', '\026', '\000', '\000', '\000', '\000',
'\000', '\000', '\000', '\000', '\000', '\000', '\000', '\000',
'\000', '\000', '\000', '\000']]
>>> os.close(fd)


Shouldn't the call to tcsetattr have changed the 2th member of the
list returned by tcgetattr from 3261 to 3237 ?   Any suggestions about
what the problem might be ?

Outside of python there is no indication of a serial port problem,
for example, minicom sets the serial port parameters.  In fact, if
I open the port, read the serial port parameters, and close the port
from Python, then launch minicom and close it, then return to Python
and reopen the port and reread the parameters, I find that minicom has
changed the parameters.


  Allen.Ingling at vanderbilt.edu








More information about the Python-list mailing list