fcntl, serial ports and serial signals on RS232.

Grant Edwards invalid at invalid.invalid
Thu Apr 8 18:17:34 CEST 2010

On 2010-04-07, Max Kotasek <mawrman at gmail.com> wrote:

> I'm trying to figure out how to parse the responses from fcntl.ioctl()
> calls that modify the serial lines in a way that asserts that the line
> is now changed.

Two comments:

  1) None of the Linux serial drivers I've worked on return line states
     except when you call TIOCMGET.

  2) If the TIOCMBI[S|C] call returned a 'success' value, then the
     line was set to what you requested.

If you want to read back the state that you just wrote, you can call
TIOCMGET, but for the "output" pins it's always going to return the 
last value that was written.

> For example I may want to drop RTS explicitly, and
> assert that the line has been dropped before returning.

Call TIOCMSET.  If it doesn't return an error, then you're done.

> Here is a brief snippet of code that I've been using to do that, but
> not sure what to do with the returned response:

What returned response?

The only thing that is returned by TIOCMBIS/TIOCMBIC is a status value
of 0 for success and <0 for failure. IIRC, that value is checked by
Python's fcntl.ioctl wrapper and it will raise an exception on

> Is someone familiar with manipulating serial signals like this in
> python?


> Am I even taking the right approach by using the fcntl.ioctl call?

Yes.  When you set/clear RTS or DTR do they not go up/down?

Even if you can't use pyserial, it's a good source for example code.

Grant Edwards               grant.b.edwards        Yow! TONY RANDALL!  Is YOUR
                                  at               life a PATIO of FUN??

More information about the Python-list mailing list