[Tutor] Raw Bits! (Control characters ahoy!)

doug shawhan doug.shawhan at gmail.com
Mon Apr 17 23:40:45 CEST 2006


I am in the middle of a project that requires me to send and retrieve
information from a machine connected to a serial port. My problems are
these:

1. I cannot send control characters
2. I cannot read data streaming from the serial port


I have been doing fine with:

os.system("echo '5' >/dev/tty00")
os.system("echo '8' >/dev/tty00")


and the like to the remote machine, but I need to be able to send control
characters the same way to scroll through menus. I have tried pyserial and
pexpect with mixed (mostly horrible) results (not the fault of the module
builders!), thus far the simple act of echoing the strings to the serial
port is the only reliable method I have found.

Reading from the serial port has also been problematic. I find that simply
opening the port /dev/tty00 file and using readlines(), read() or whatever
gives me empty strings or lists. Pbth.

So first: how should I go about adding the hex escape sequences (\x0a and
\x50) to the above strings in their raw form?
second: what method should I use to read a raw stream from the serial port
for a given period?

I have looked carefully at the neat and tidy miniterm.py example in the
pyserial examples directory, and see how one can continuously read via a
thread from the port, but have not been able to replicate it thus far.

Any help whatsoever would be great! I'm beginning to feel a little
lightheaded. Thanks!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20060417/27ca42b3/attachment.html 


More information about the Tutor mailing list