【问题标题】:Not getting output from serial没有从串口获取输出
【发布时间】:2014-09-20 14:01:18
【问题描述】:

我有一个简单的脚本,它是与设备的串行连接。 我正在尝试发送命令,但不知何故我没有得到输出,而是我的输入。 这是我的脚本:

#!/usr/bin/python
import serial
ser = serial.Serial('/dev/ttyUSB0', 19200, timeout=1)
x = ser.write('AT')          #  write a string
s = ser.read(x)        # read x bytes (timeout)
#line = ser.readline()   # read a '\n' terminated line
print (s)
ser.close()

注意:我只需要使用“写入”来发送命令并使用“读取”来获取输出。

没关系!!! 我设法通过尝试模拟输入键、在新行中打印响应并打印多个字节来解决我的问题(注意:未指定生成的字节量“A”作为所有成功输出和“C”的通用响应对于所有失败的输出。)

#!/usr/bin/python
import serial
ser = serial.Serial('/dev/ttyUSB0', 19200, timeout=1)
x = ser.write('AT' + '\r\n')          #  write a string
s = ser.read(100)        # read x bytes (timeout)
#line = ser.readline()   # read a '\n' terminated line
print (s)
ser.close()

【问题讨论】:

    标签: python serial-port pyserial


    【解决方案1】:

    工作答案包含在上面的编辑中。我也会考虑任何更好的解决方案。感谢观看。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-06-05
      • 2023-03-10
      • 2020-09-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-22
      相关资源
      最近更新 更多