2014-06-15 78 views
0

美好的一天。使用電纜從ArduPilot的遙測端口讀取數據

我需要使用SERIAL-USB轉換器和USB電纜從ArduPilotMega的遙測端口 讀取遙測。

我該怎麼做呢?

enter image description here

我嘗試使用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','\ x1','\ x01','\ x00','\ x00','\ x00','\ x00','\ x00','\ x00',' \ x1b', '\ x12','''','\ x00','\ x00','\ xff','\ xff','\ xfc','\ x00','\ x00', '\ x00','\ x00','\ x00','\ x00','\ xa1','\ x0e','\ x01','\ x1d','V', '\ x00', '\ x'','D','f','>','\ r','\ xec','\ x1f','\ x01','\ x01', '\ xfc','\ 'x00','\ x00','\ x00','\ x00','\ x00','\ x01','\ x00', '\ xff',' \ x00','\ x00','\ x00','\ x00','\ xed', '\ xfe','\ xa4','\ x01','\ xf6','。',。 ...

我該如何解碼它?

這是正確的方法嗎?

謝謝!

+0

我的解決方案:在使用特萊姆端口的USB端口instad和這個[蟒示例](https://github.com/marhar/eastbay-mavlink/tree/master/demos) – Ilya

回答

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