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?

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.