使用 pySerial 读取响应 AT 命令 [英] Read response AT command with pySerial

查看:81
本文介绍了使用 pySerial 读取响应 AT 命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下示例代码:

import serial

ser = serial.Serial('/dev/ttyUSB1', 115200, timeout=5)
ser.write("AT\r")
response =  ser.readline()
ser.write(chr(26)) 
ser.close()

print response

我的目标是发送AT命令并得到您的答复OK.

My goal is to send the AT command and get your answer OK.

PySerial readline() 的文档说读取收到的数据直到找到换行符,问题是我的打印没有返回任何内容.

The documentation of PySerial readline() says reads the data received until it finds a line break, the problem is that my print is returning nothing.

我确信在AT命令之后,3G调制解调器给我发送的响应是OK.有谁知道无法检索到答案的原因吗?

I'm sure that after the AT command, the response that the 3G modem sends me is OK. Anyone know the reason why you can not retrieve the answer?

PS:使用像CuteCom这样的程序,我确认设备可以工作并且它响应AT命令.

PS: using programs like CuteCom, I got confirmation that the device works and that it responds to AT commands.

推荐答案

为了补充问题评论,请试试这个,看看有没有什么变化:

In order to complement the question comments, please try this and see if anything changes:

import serial

ser = serial.Serial('/dev/ttyUSB1', 115200, timeout=5)
ser.write("AT\r")
response =  ser.read(2)
print response
ser.close()

如果一切正常,然后将\r"添加到您的 write() 并将 ser.read(2) 替换为 ser.readline() 并设置超时值再次归零.

If everything works, then add the "\r" to your write() and replace the ser.read(2) with ser.readline() and set the timeout value to zero again.

这篇关于使用 pySerial 读取响应 AT 命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆