Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Addressing the modem via pyserial

Reply
Thread Tools

Addressing the modem via pyserial

 
 
Doru-Catalin Togea
Guest
Posts: n/a
 
      01-18-2006
Hi!

I asked previously how to address the COM port from Python and I was
directed to pyserial. It is very elegant and I guess it works very well.

However, it seems that what I try to do is more complicated than I first
thought. I want to make my modem place a call using the number '1234'. The
modem is connected to COM3 on my computer. So I tried the following:

-------------------------------
import serial

ser = serial.Serial(2) # COM3
ser.timeout = 2 # otherwise the read(2) which follows blocks for ever
ser.write("atdt1234")
reply = ser.read(2)
print reply
ser.close()
print "ok"
-------------------------------

In the HyperTerminal which comes with Win XP Pro, I can set up a
connection to COM3 and there type the 'atdt1234' command. It works (I get
a call since I have the modem connected to a device with a phone on it).

My question is actually: will an at-command like 'atdt1234' translate to
ser.write('atdt1234')?

Secondly, a modem question: I have found a lot of web pages about
at-commands listing the hayes command set. Still many of them do not seem
to work on two different modems I have tried. Like '&$' should display an
overview of the commands supported by the modem. Ii tried this in the
HyperTerminal where I can place the above mentioned call, and I get
'ERROR'. I also get 'ERROR' for most other commands I try.

Any ideas?

Thanks,
Catalin

--

<<<< ================================== >>>>
<< We are what we repeatedly do. >>
<< Excellence, therefore, is not an act >>
<< but a habit. >>
<<<< ================================== >>>>
 
Reply With Quote
 
 
 
 
Fredrik Lundh
Guest
Posts: n/a
 
      01-18-2006
Doru-Catalin Togea wrote:

> In the HyperTerminal which comes with Win XP Pro, I can set up a
> connection to COM3 and there type the 'atdt1234' command. It works (I get
> a call since I have the modem connected to a device with a phone on it).


even without pressing enter?

> My question is actually: will an at-command like 'atdt1234' translate to
> ser.write('atdt1234')?


try

ser.write('atdt1234\r\n')

or just

ser.write('atdt1234\n')

</F>



 
Reply With Quote
 
 
 
 
Roel Schroeven
Guest
Posts: n/a
 
      01-18-2006
Doru-Catalin Togea schreef:
> My question is actually: will an at-command like 'atdt1234' translate to
> ser.write('atdt1234')?


You'll have to include the end-of-line; I guess 'atdt1234\n' should
work, otherwise you can try 'atdt1234\r\n' or 'atdt1234\r'.

Also, don't forget that you have to set the modem into command mode if
it was not already (using '+++' and a pause before and/or after that
IIRC), but I guess that's not the problem in this case.

> Secondly, a modem question: I have found a lot of web pages about
> at-commands listing the hayes command set. Still many of them do not
> seem to work on two different modems I have tried. Like '&$' should
> display an overview of the commands supported by the modem. Ii tried
> this in the HyperTerminal where I can place the above mentioned call,
> and I get 'ERROR'. I also get 'ERROR' for most other commands I try.


Unfortunately the hayes command set is not a well-defined standard
supported by all modems. There are almost as many variations as there
are modems. In the good old days the user manual that came with the
modem had an overview of the available commands for that modem.

--
If I have been able to see further, it was only because I stood
on the shoulders of giants. -- Isaac Newton

Roel Schroeven
 
Reply With Quote
 
springer8 springer8 is offline
Junior Member
Join Date: Aug 2009
Posts: 1
 
      08-31-2009
Hello all

This is my first post on this forum, so greetings to everyone here

I have a similar problem to that posted by Doru-Catalin Togea. I am also trying to communicate with my internal modem using AT commands via pySerial in Windows.

To test this I started with this bit of code....

import serial
myport = serial.Serial(2, timeout=2) # COM 3 where modem is, with \n timeout to avoid locking up
myport.write('at&v')
reply = myport.readline()
print reply
myport.close()

This was just to see if my modem would reply to a simple status request (at&v).
However, when I read and print that reply all I get is an echo of whatever I wrote in the myport.write statement. In the above example therefore, the print reply statement comes back with 'at&v', just as entered in the write statement. I tried this with +++ before it, and \r, \n & even \r\n. Nothing made any difference.

It seems as if the myport.write function is not actually getting to the modem at all. Even if the statement was problematic for the modem in some way, I would have expected an error or message of some kind from the modem itself, not just an echo of whatever I write to the port.

Just to make the point I adjusted the above code as follows....

import serial
myport = serial.Serial(2, timeout=2) # COM 3 where modem is, with \n timeout to avoid locking up
myport.write('happy christmas')
reply = myport.readline()
print reply
myport.close()


The reply was happy christmas. Surely if the myport.write function was reaching the modem this would have caused some kind of error message.

I'd appreciate any advice anyone can offer as to what I might be mising here. I have looked through the docs for the python serial module but can't find anything helpful there.

Doru-Catalin Togea, did you manage to get your code working properly in the end ??

Thanks in advance if anyone can help me.
 
Reply With Quote
 
Schawm Schawm is offline
Junior Member
Join Date: Dec 2009
Posts: 5
 
      12-30-2009
Hi everybody!

I have the same problem list above. I canīt connect a bluetooth device with serial module from Python, my script is very simple and it works directly on hyperterminal by windows. I posted my code below if someone has any hit I would appreciate. Thanks in advance.


import serial
ser = serial.Serial(2) # open first serial port
print ser
print ser.portstr # check which port was really used
ser.write("atd000195079CEA\n\r") # write a string

ser.write("123test")
 
Reply With Quote
 
Schawm Schawm is offline
Junior Member
Join Date: Dec 2009
Posts: 5
 
      01-05-2010
It works well with
ser.write("atd000195079CEA\r") # write a string
reply = ser.readline()
print reply

Regards. Schawm RS
 
Reply With Quote
 
nephews nephews is offline
Junior Member
Join Date: Nov 2010
Posts: 1
 
      11-09-2010
Hi,

I had a similar problem (couldn't read response from modem)

The solution that worked for me was to add a sendBreak() after the write command.

Code:
import serial

modem = serial.Serial(0)

modem.write('AT\r\n')
modem.sendBreak()

reply = modem.read(modem.inWaiting())
print reply

modem.close()
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
addressing string to modem on COM1 in Win98se Stormy nospam@nospam.invalid Computer Support 21 07-16-2006 04:24 PM
win32 pyserial requires javax.comm for py2exe? Grant Edwards Python 6 06-29-2004 11:05 PM
pyserial with Mac and USB converter, possible? jorjun Python 1 01-08-2004 02:43 PM
Re: Pyserial question David Goodger Python 0 01-05-2004 04:10 PM
Pyserial question Diez B. Roggisch Python 1 01-05-2004 03:59 PM



Advertisments