[Python-Dev] Python vs. chat (conversation with modem)
Bertram Scharpf
b.scharpf at tesionmail.de
Wed Apr 7 15:46:14 EDT 2004
Hi,
in simple serial communication, I found a problem that
doesn't arise, when I'm doing exactly the same with the
`chat' program.
I admit my hardware is a little bit special and may have
problems itself. It is an ISDN telephone, Elmeg C200d at ta.
With a normal modem, everything works fine.
For a speech call, my telephone wants me to send a command
'at&b30' before dialing (otherwise the modem functionality
is dialing).
When I send the commands with `chat', the device is
dialing, but when I send them from a Python script, the
communication hangs.
My code is (simplified):
class Modem:
def __init__( self, device = '/dev/ttyS0'):
self.modem = open( device, 'w+')
self.command( 'atz')
def send( self, cmd):
print >>self.modem, cmd + '\r'
def expect( self, patt):
import select
...
def command( self, cmd):
self.send( cmd)
self.expect( 'OK')
def dial_orig( self, nr):
self.command( 'at&b30')
# On this request, the modem won't send an answer.
self.command( 'atdt,%s;h0z' % nr)
self.command( 'at&b31')
def dial_chat( self, nr):
"That's working!?"
script += [ repr( ''), 'atz',
'OK', r'at\&b30dt,\\T\;h0z',
'OK', r'\\c']
chatcmd = '/usr/sbin/chat -vs -T %s %s <%s >%s' % \
(nr, ' '.join( script), self.modem.name, self.modem.name)
import os
os.system( chatcmd)
dial = dial_chat
(The full script is available at
`http://www.bertram-scharpf.de/dial.py'.)
On the 'atz' an answer of 'OK' is sent back, but not on the
'at&b30' request. `chat' receives an OK. Setting the
termcaps exactly to what chat would have chosen didn't help.
I have found this behaviour in the versions 2.1, 2.2 and 2.3.
$ uname -srmp
Linux 2.4.18-bs1 i586 unknown
Do I have any chance to find out what happens?
Bertram
--
Bertram Scharpf
Stuttgart, Deutschland/Germany
http://www.bertram-scharpf.de
More information about the Python-Dev
mailing list