1

I am using python to communicate with GSM modem connected in my ttyUSB port.

import serial
from curses import ascii

ser=serial.Serial('/dev/ttyUSB0', 9600, timeout=3)
command = ser.write('AT+CMGR=3\r\n')
print command

Now to communicate with my modem, I pass AT commands from python, I need to print the output of the complete command string. How do I do it?

Janne Karila
  • 24,266
  • 6
  • 53
  • 94
Kushal Shah
  • 165
  • 1
  • 13

2 Answers2

1

If you mean how to get output from the modem, use read, readline or readlines methods of ser. See tutorial.

Janne Karila
  • 24,266
  • 6
  • 53
  • 94
0

First, an AT command should be terminated with only \r and not \r\n (unless you have changed S3, and you should not do that), see V.250 for more details on that and AT commands in general (e.g. if you have not already read that specification it is highly recommended).

Then, for reading from the serial port, this is already covered in Janne Karila's answer.

Thirdly, in order to handle AT commands you must read and parse the responses you get from the modem, see this answer for description of how this should be done.

Community
  • 1
  • 1
hlovdal
  • 26,565
  • 10
  • 94
  • 165