Addressing the modem via pyserial

Discussion in 'Python' started by Doru-Catalin Togea, Jan 18, 2006.

  1. 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. >>
    <<<< ================================== >>>>
     
    Doru-Catalin Togea, Jan 18, 2006
    #1
    1. Advertising

  2. 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>
     
    Fredrik Lundh, Jan 18, 2006
    #2
    1. Advertising

  3. 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
     
    Roel Schroeven, Jan 18, 2006
    #3
  4. Doru-Catalin Togea

    springer8

    Joined:
    Aug 31, 2009
    Messages:
    1
    Accessing the modem via pySerial

    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.
     
    springer8, Aug 31, 2009
    #4
  5. Doru-Catalin Togea

    Schawm

    Joined:
    Dec 30, 2009
    Messages:
    5
    AT commands with pyserial

    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")
     
    Schawm, Dec 30, 2009
    #5
  6. Doru-Catalin Togea

    Schawm

    Joined:
    Dec 30, 2009
    Messages:
    5
    It works well with
    ser.write("atd000195079CEA\r") # write a string
    reply = ser.readline()
    print reply

    Regards. Schawm RS
     
    Schawm, Jan 5, 2010
    #6
  7. Doru-Catalin Togea

    nephews

    Joined:
    Nov 9, 2010
    Messages:
    1
    sendBreak

    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()
     
    nephews, Nov 9, 2010
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. K R Lal

    Download SMS from MOBILE / GSM Modem

    K R Lal, May 17, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    560
    K R Lal
    May 17, 2005
  2. Roberto
    Replies:
    1
    Views:
    545
  3. 127.0.0.1
    Replies:
    1
    Views:
    791
  4. Alex
    Replies:
    4
    Views:
    3,746
  5. sp
    Replies:
    1
    Views:
    832
    Steven Cheng [MSFT]
    Aug 28, 2008
Loading...

Share This Page