pexpect baudrate and mode settings

Bryce Bolton bryce.bolton at gmail.com
Thu Sep 21 02:29:39 EDT 2006


Hi,

>
> I've written a short script in pexpect to open the serial port and get 100
> bytes.  The script does receive a string of garbage, but not the good text
> seen when I open a minicom terminal and look at ttyS0.
>
> I know that the baud rate is wrong, and the other settings (such as 8N1)
> are unknown to me and may also be wrong.
>
>
> Question: In Linux, how do I set the baud rate = 19200, 8N1 in pexpect
> scenario?  (this example is close to the pexpect documentation, but I used
> the fdpexpect.fdspawn extension because pexpect.spawn didn't work.
>
> #!/bin/python
> import pexpect
> import os
> import fdpexpect
> fd = os.open("/dev/ttyS0", os.O_RDWR|os.O_NONBLOCK|os.O_NOCTTY )
> m = fdpexpect.fdspawn(fd) # Note integer fd is used instead of usual
> string.
> m.send("+++") # Escape sequence
> m.send("ATZ0\r") # Reset modem to profile 0
> string1 = m.read(100)
> print "%s" % string1
>
>
> Would the baudrate setup be similiar under windows?  Any examples out
> there?
>
> In short, setting of critical parameters is unclear under pexpect's
> documentation, but may be obvious to those more familiar with os.open or
> other filesystem internals.
>
> Thanks,
> Bryce
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20060920/34d80322/attachment.html>


More information about the Python-list mailing list