美好的一天。
我需要从ArduPilotMega的遥测端口读取遥测数据 使用SERIAL-USB转换器和USB电缆。
我该怎么做?
我尝试使用python:
import serial
ser = serial.Serial(port='/dev/ttyUSB0', baudrate=57600, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, bytesize=serial.EIGHTBITS, timeout=0)
print("connected to: " + ser.portstr)
line = []
while True:
for c in ser.read():
line.append(c)
if c == '\n':
print line
line = []
结果如下所示:
连接到:/ dev / ttyUSB0 [' \ x1c',' \ x01',' \ x1e',' V',' \ x00', ' \ x8c',' =',' \ xe2',' \ xbc',' v',& #39; \ xc0',' \ xf6',' 8',',',' \ xba', ' E',' 8','%',' \ x14',' \ x01',&# 39; J',' \ x00',' \ x00',' \ x00',' \ x00', ' Q',' \ xc0',' c','>',' \ x00',& #39; \ x00',' \ xc2',' \ x1a',' \ x01',' \ x1b', ' \ x12','"',' \ x00',' \ x00',' \ xff&# 39;,' \ xff',' \ xfc',' \ x00',' \ x00', ' \ x00',' \ x00',' \ x00',' \ x00',' \ xa1', ' \ x0e',' \ x01',' \ x1d',' V', ' \ x00',' \ xdb',' D',' f','>',& #39; \ r',' \ xec',' \ x1f',' \ x01',' \ x01', ' \ xfc',' \ x00',' \ xfc',' \ x00',' \ xfc', ' \ x00',' \ x01',' \ x00', ' \ xff',' \ x00',' \ x00',' \ x00',' \ x00', ' \ x00',' \ x00',' \ xed', ' \ xfe',' \ xa4',' \ x01',' \ xf6','。', ....
我该怎么解码?
这是正确的方法吗?
谢谢!
答案 0 :(得分:1)
看起来你正在读取十六进制字符,然后将它们连接起来。试试这个:
import serial
ser = serial.Serial(port='/dev/ttyUSB0', baudrate=57600, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, bytesize=serial.EIGHTBITS, timeout=0)
print("connected to: " + ser.portstr)
while True:
print ser.readline()