RTS/CTS and DTR/DTS control

M

Mike

Is there a library in Python that will give me control over the
handshaking lines directly?

Thanks
 
H

Howard Lightstone

Is there a library in Python that will give me control over the
handshaking lines directly?

Thanks

For Windoze, I heartily recommend siomodule.
( http://starship.python.net/crew/roger )

This is a wrapper around a well-designed professional serial I/O package.
The Python version includes the dll for free (when used with Python).
 
M

Mike

I am running Linux, Python 2.2.2. It would be nice (not mandatory)
to be cross platform though.

Thanks,
Mike
 
P

Peter Hansen

Mike said:
I am running Linux, Python 2.2.2. It would be nice (not mandatory)
to be cross platform though.

You call them handshaking lines, so one might infer you want
to use them as such while doing serial communications. Are
you in fact actually planning to control them as discrete
inputs and outputs, for some kind of control application?
(If not, I'm curious why you want to control them directly.)

There is Chris Liechti's library, which you can find with
http://www.google.com/search?q=python+serial+port but I'm
not sure it supports direct control of the I/Os... if it
doesn't you should be able to get direct control of those
lines under Linux using appropriate fcntl.ioctl() calls, I
would think, though I haven't done it myself.

-Peter
 
P

Peter Hansen

Mike said:
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
 
P

Peter Hansen

Peter said:
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

Look at the main site... you might find something else of interest there. <wink>

-Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top