Under Linux I can use python-pexpect and pyserial.
However pexpect uses PTY which is not native supported under Win32 (could
use cygwin, but I'd rather not), and pyserial does not support 'fileno()'
under Win32.
Does anyone have a suggestion of:
1) An alternative to pexpect which works on Win32.
2) An alternative to pyserial which can treat the device via normal FileIO
calls, whilst maintaining some level of compatability with Linux.
Cheers,
Simon.
--
You received this message because you are subscribed to the Google Groups "calgary python user group" group.
To post to this group, send email to python...@googlegroups.com.
To unsubscribe from this group, send email to pythoncalgar...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/pythoncalgary?hl=en.
It seems that the 'recommended' way to communicate with a serial port is
with PySerial, which under Linux does use FileIO and supports FileNo() to
find out the file handles for the device.
However under Windows, PySerial uses 'win32file' actions which don't
support FileNo(). This incompatibility is noted in the API page:
http://pyserial.sourceforge.net/pyserial_api.html
My quest is to script up control of a serial device which can be done with
a combination of PySerial and python-pexpect (fdpexpect), and under Linux
this is simple and clean.
--
#!/usr/bin/env python
import serial
import fdpexpect
# Open serial port and bond to pexpect
device = serial.Serial(port="COM2", baudrate=115200)
dut = fdpexpect.fdspawn(device)
# Request MEID
dut.send("AT#MEID?\r")
dut.expect("OK")
print "MEID is ",dut.before
dut.close()
--
Under Window this fails on many layers:
1). pexpect requires PTY, which is not Win32. I found an alternate
'wexpect' which uses Wtty in which it runs an application, but doesn't
know about direct FileIO (object?) access.
2). fdexpect assumes that it's actioning on FileIO.
3). As noted above PySerial does not give you a way to find file hands
with FileIO.
I'm still trying to get my head around how this _should_ work cross
platform, and have a feeling that 'pexpect' should be able to work on a
objects directly, without having discover a file handle and then use
FileIO actions.
Any suggestions that people have would be very welcome.
Cheers,
Simon.
Cheers,
Simon.
Expect is itself a nice, power full scripting language which is pretty
well suited to automated testing:
http://en.wikipedia.org/wiki/Expect
I was hoping that all the underlying stuff could be abstracted out, so
that the test scripts could boil down to send 'this', expect 'this' or
'this' and do 'this' on error/timeout.
Doing this via pexpect looked nicer than using the real (TCL based) Expect
that I started with. If I'm handing the code off to someone else at some
point, it is nicer if they can just adapt the 'send'/'expect' commands as
required without really having to learn python.
Simon.