Print output of AT command

流过昼夜 提交于 2020-01-15 11:45:27

问题


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?


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/16910998/print-output-of-at-command

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!