Serial port IO question
David Stokes
tdc0331 at hti.com
Tue Jul 27 14:07:27 EDT 1999
I am attempting to send a ^M (Control-M) down a serial port and then
read back from that same port. The application is an old UPS that will
send back system status after a ^M. The code below opens the port but
the readline seems to be returning what I wrote. My guess is that I
haven't really grabbed I/O stream for the read operation. Any
suggestions?
Dave Stokes
-------
#!/usr/bin/env python
import sys, string
upsdev = "/dev/ttyS1" # Serial port attached to ups
class get_ups:
def __init__(self):
print "Getting ups status"
def get_ups_data_p(self):
upsdata = open( upsdev, 'r+'); # open port to ups
upsdata.write("\015") # send ^M to ask for
status
upsdata.flush()
upsbuffer = upsdata.readline() # get status back
upsdata.close()
if __name__ == '__main__':
ups_status = get_ups()
ups_status.get_ups_data_p()
More information about the Python-list
mailing list