Mike wrote:
On Fri, 04 Jul 2003 19:36:45 -0400, Peter Hansen wrote:
Mike wrote: > Is there a library in Python that will give me control over the
> handshaking lines directly?
I actually want to control my X10 firecracker device. I have done it in
Java (on Windows) already but now I want to do it in Python on Linux. You
control the device by wiggling the control lines with certain patterns.
Okay, that helps. Are there any tight timing constraints with X10?
It's been a while since I looked at the specs. Pretty low data rate,
isn't it?
Here's a few snippets/ideas that might help get you started, if there's
nothing off the shelf:
From inside a "SerialPort" class we've built, which is lacking
what you need but has some pieces that might be relevant:
class SerialPort:
def some method():
self.port = os.open(self.portName, os.O_RDWR | os.O_NOCTTY )
def CD(self):
'''retrieve CD status'''
status = fcntl.ioctl(self.port, TIOCMGET, TIOCM_zero_str)
value = struct.unpack('I', status)[0] & TIOCM_CD
if value > 0:
return 1
else:
return 0
At the top, we have some ugly constants defined, probably grabbed from
various web pages/google searches on Linux serial ports:
-------------
# The following may be Linux specific
TIOCM_CD = 0x040
TIOCM_CAR = 0x040
TIOCMGET = 0x5415
TIOCMSET = 0x5418
# The following is used to convert between C's long to Python's int.
TIOCM_zero_str = struct.pack('I', 0)
-------------
A quick search again with Google using TIOCMSET and TIOCM_CTS and a bunch
of others finally led to this, which might be the best yet, and includes
some constant definitions that might let you get something working, if
this doesn't directly solve your problem:
http://sparc.dnsalias.net/Python_stuff/PosixSerial.py
Good luck!
-Peter