mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-27 16:03:34 +08:00
Tools/HIL: default to USB UART if available
This commit is contained in:
+26
-1
@@ -9,6 +9,7 @@ import unittest
|
||||
import os
|
||||
import sys
|
||||
import datetime
|
||||
import serial.tools.list_ports as list_ports
|
||||
|
||||
COLOR_RED = "\x1b[31m"
|
||||
COLOR_GREEN = "\x1b[32m"
|
||||
@@ -38,6 +39,7 @@ def print_line(line):
|
||||
else:
|
||||
print('{0}'.format(line), end='')
|
||||
|
||||
|
||||
def do_test(port, baudrate, test_name):
|
||||
ser = serial.Serial(port, baudrate, bytesize=serial.EIGHTBITS, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, timeout=1, xonxoff=False, rtscts=False, dsrdtr=False)
|
||||
|
||||
@@ -47,6 +49,7 @@ def do_test(port, baudrate, test_name):
|
||||
# wait for nsh prompt
|
||||
while True:
|
||||
ser.write("\n".encode("ascii"))
|
||||
ser.flush()
|
||||
|
||||
serial_line = ser.readline().decode("ascii", errors='ignore')
|
||||
|
||||
@@ -206,8 +209,30 @@ class TestHardwareMethods(unittest.TestCase):
|
||||
self.assertTrue(do_test(self.TEST_DEVICE, self.TEST_BAUDRATE, "versioning"))
|
||||
|
||||
def main():
|
||||
|
||||
default_device = None
|
||||
device_required = True
|
||||
|
||||
# select USB UART as default if there's only 1
|
||||
ports = list(serial.tools.list_ports.grep('USB UART'))
|
||||
|
||||
if (len(ports) == 1):
|
||||
default_device = ports[0].device
|
||||
device_required = False
|
||||
|
||||
print("Default USB UART port: {0}".format(ports[0].name))
|
||||
print(" device: {0}".format(ports[0].device))
|
||||
print(" description: \"{0}\" ".format(ports[0].description))
|
||||
print(" hwid: {0}".format(ports[0].hwid))
|
||||
#print(" vid: {0}, pid: {1}".format(ports[0].vid, ports[0].pid))
|
||||
#print(" serial_number: {0}".format(ports[0].serial_number))
|
||||
#print(" location: {0}".format(ports[0].location))
|
||||
print(" manufacturer: {0}".format(ports[0].manufacturer))
|
||||
#print(" product: {0}".format(ports[0].product))
|
||||
#print(" interface: {0}".format(ports[0].interface))
|
||||
|
||||
parser = ArgumentParser(description=__doc__)
|
||||
parser.add_argument('--device', "-d", nargs='?', default=None, help='', required=True)
|
||||
parser.add_argument('--device', "-d", nargs='?', default=default_device, help='', required=device_required)
|
||||
parser.add_argument("--baudrate", "-b", dest="baudrate", type=int, help="Mavlink port baud rate (default=57600)", default=57600)
|
||||
args = parser.parse_args()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user