通过电缆从ArduPilot的遥测端口读取数据

1 投票
1 回答
1460 浏览
提问于 2025-04-18 09:50

你好。

我需要通过SERIAL-USB转换器和USB线,从ArduPilotMega的遥测端口读取遥测数据。

我该怎么做呢?

在这里输入图片描述

我尝试使用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', '\xc0', '\xf6', '8', ',', '\xba', 'E', '8', '%', '\x14', '\x01', 'J', '\x00', '\x00', '\x00', '\x00', 'Q', '\xc0', 'c', '>', '\x00', '\x00', '\xc2', '\x1a', '\x01', '\x1b', '\x12', '"', '\x00', '\x00', '\xff', '\xff', '\xfc', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\xa1', '\x0e', '\x01', '\x1d', 'V', '\x00', '\xdb', 'D', 'f', '>', '\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', '.', ....

我该怎么解码这些数据呢?

这样做是对的吗?

谢谢!

1 个回答

2

看起来你正在读取十六进制字符,然后把它们连接在一起。试试这个方法:

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()

撰写回答