Reading responses from Modem.

Peter Hansen peter at engcorp.com
Thu Jul 22 09:48:31 EDT 2004


Etienne Labuschagne wrote:

> Assuming the modem is on COM5:
> 
> m = open('COM5','wb+')
> m.write('+++\r\n')
> m.flush()
> m.write('ATQ0V1E0\r\n')
> m.flush()
> m.write('ATDT5551234;\r\n')
> m.flush()
> response = m.read()
> 
> The above program works fine when running it AFTER looking at the modem
> diagnostics under the modem's properties in Windows 2000.  If the machine is
> restarted and the diagnostics is not run, the program blocks at the response
> = m.read() and I never get a response from the modem.
> 
> Obviously the windows diagnostics tool does something to initialise the
> modem for responses - everything else works (the modem dials, etc.)
> 
> Any suggestions on how to "wake up" the modem without doing the diagnostics
> every time?

It's strongly recommended (by me, anyway) to use PySerial to
talk to things on serial ports, especially on Windows, rather
than trying to treat them like files.  In the case of your
particular problem, you can at least take advantage of a
read timeout to avoid problems where you might have a
partial command already in the buffer, etc.

Note: the +++ string is typically required to have delays
with *no* data transmitted on either side of it for one
second or it might not work.  Just sending +++ in the middle
of a stream of data will not work.

-Peter



More information about the Python-list mailing list