'ioctl ' call in python (serial port reading)

Michael Hudson mwh at python.net
Tue Dec 4 11:04:31 CET 2001


mixo <mixo at beth.uniforum.org.za> writes:

> I am current trying to drop 'RTS' (Request To Send)
> on a serial port. In 'c' I do the following :
> 
> ++++++++++++++++++++++++++++++++++++++++++++++++
> .
> .
> 
> int fd, mdlns;//fd is a  file discriptor
> .
> .
> 
> ioctl (fd, TIOCMGET, &mdlns);
> mdlns &= ~TIOCM_RTS;
> ioctl (fd, TIOCMSET, &mdlns);
> .
> .
> .
> +++++++++++++++++++++++++++++++++++++++++++++++
> 
> What would the equivilent code in 'python' be?
> How can I disable 'RTS' on a serial port?
> 

Something a bit like this:

import fcntl, struct, termios

s = fcntl.ioctl(fd, termios.TIOCMGET, "\000\000\000\000")
i = struct.unpack('l', s)[0]
i &=~ termios.TIOCM_RTS
s = struct.pack('l', i)
fcntl.ioctl(fd, termios.TIOCMSET, s)

Not tested!

Cheers,
M.

-- 
  Our Constitution never promised us a good or efficient government,
  just a representative one. And that's what we got.
      -- http://www.advogato.org/person/mrorganic/diary.html?start=109



More information about the Python-list mailing list