I finally get it running. For those who are interested I included a code snippet (unfortunate indentation is removed) and corresponding output.
Code
import os, termios
import time
serialport = ‘/com/0’
serialfd = ‘’
def checkIfConsIsSet(stats, const, cname):
if stats & const:
print ‘%s is set’ % cname
return True
else:
print ‘%s is NOT set’ % cname
return False
try:
print “Openning serial port…”
serialfd = os.open(serialport, os.O_RDWR | os.O_NONBLOCK)
if serialfd:
print "Serial port settings: ", termios.tcgetattr(serialfd)
print “Constants: MS_DCD=%d, MS_RTS=%d” % (termios.MS_DCD, termios.MS_RTS)
# Getting serial stats
estat, mstat = termios.tcgetstats(serialfd)
print "1 termios stats: ", (estat, mstat)
checkIfConsIsSet(mstat, termios.MS_RTS, ‘MS_RTS’)
print ‘>>> Toggling MS_RTS’
termios.tcsetsignals(serialfd, termios.MS_RTS)
estat, mstat = termios.tcgetstats(serialfd)
print "2. termios stats, mstat: ", (estat, mstat)
checkIfConsIsSet(mstat, termios.MS_RTS, ‘MS_RTS’)
print ‘Waiting 5 secs…’
time.sleep(5)
print ‘>>> Reseting the MS_RTS…’
tmp = mstat & ( not termios.MS_RTS )
termios.tcsetsignals(serialfd, tmp)
estat, mstat = termios.tcgetstats(serialfd)
print "3. termios stats: ", (estat, mstat)
checkIfConsIsSet(mstat, termios.MS_RTS, ‘MS_RTS’)
print “Closing serial port…”
os.close(serialfd)
except:
print “Error: Problem occured while openning socket”
Output
Openning serial port…
Serial port settings: [0, 0, 48, 0, 115200, 115200, [‘\x11’, ‘\x13’, ‘\x00’, ‘\x00’, ‘\x00’, ‘\x00’, ‘\x00’, ‘\x00’, ‘\x00’]]
Constants: MS_DCD=128, MS_RTS=2
1 termios stats: (0, 128)
MS_RTS is NOT set
>>> Toggling MS_RTS
2. termios stats, mstat: (0, 130)
MS_RTS is set
Waiting 5 secs…
>>> Reseting the MS_RTS…
3. termios stats: (0, 128)
MS_RTS is NOT set
Closing serial port…
This code is controlling the RTS. Please also refer to [1].
Many thanks again for the help.
Chris
[1] http://www.digi.com/wiki/developer/index.php/Digi_Python_Programmer's_Guide#termios