'ioctl ' call in python (serial port reading)

mixo mixo at beth.uniforum.org.za
Tue Dec 4 06:07:31 EST 2001


Michael Hudson wrote:

> 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.
> 
> 

Thanks.

P.S I had to change
     "i &=~ termios.TIOCM_RTS"  to "i = (i) & ~TIOCM_RTS"
      For one reason or another I don't "TIOxxxx" defined
      in "termios" module,so I also had to define them


#from /usr/include/asm/termios.h
TIOCMGET =0x5415
TIOCMSET =0x5418
TIOCM_RTS =0x004










More information about the Python-list mailing list