Serial programming
dkhchan at my-deja.com
dkhchan at my-deja.com
Sun Jun 13 21:25:06 EDT 1999
I try but not success. Modem receive my command (I try to dail out)
but I have not get any respone. Anything I missed??
My program:
#!/usr/bin/python
modem = open('/dev/ttyS0', 'w+')
modem.write('ATZ\r')
print modem.read() # no respone here
modem.close()
DORAEMON.HK
In article <i5a83.2876$nn.847925 at news.shore.net>,
"Michael P. Reilly" <arcege at shore.net> wrote:
> DORAEMON.HK <abc at def.ghi.jkl> wrote:
> : I am looking for some example in python about send and receive data
from
> : serial port. Like send "ATZ" and receive "OK". Any help?? Thanks
a lot!!
>
> You can open the device file directly and handle the information
> yourself. UNIX devices are handle just like files. You can change
> device attributes (speed, parity, etc.) with the termios module or
> fcntl.ioctl function.
>
> modem = open('/dev/cua0', 'r+')
> modem.write('AT\r')
> f = modem.read()
> if f[:2] != 'OK':
> raise ValueError, "modem not okay"
> ...
>
> There are some Expect modules/extensions around that could help you as
> well; my ExpectPy extention is at
> http://starship.python.net/~arcege/ExpectPy/. You can find others
> through the Python website.
>
> import ExpectPy
> modem = ExpectPy.spawnfile(open('/dev/cua0', 'r+'))
> modem.send("AT\r")
> try:
> f = modem.expect(
> (ExpectPy.EXACT, "OK\r\n", "OK"),
> (ExpectPy.GLOB, "*\r\n", "Not OK")
> )
> if f == "Not OK":
> raise ValueError, "modem not okay"
> except (ValueError, ExpectPy.TimeoutError), value:
> raise ValueError, value
>
> I hope this helps.
>
> -Arcege
>
>
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
More information about the Python-list
mailing list