目的: 設計一個GUI介面 包含兩個 UART 控制, 一個影像輸出, 一個畫radar偵測點的區域, 最右側為指令輸出與接收到的訊息視窗
UART1為arduino的控制port
UART2為radar console port
下面為windows跟樹莓派共用抓取com port 的code
def serial_ports():
# return serial.tools.list_ports.comports()
if sys.platform.startswith('win'):
ports = ['COM%s' % (i + 1) for i in range(256)]
elif sys.platform.startswith('linux') or sys.platform.startswith('cygwin'):
# this excludes your current terminal"/dev/tty"
ports = glob.glob('/dev/tty[A-Za-z]*')
port_list = list(serial.tools.list_ports.comports())
print(len(port_list), 'ports found')
elif sys.platform.startswith('darwin'):
ports = glob.glob('/dev/tty.*')
else:
raise EnvironmentError('Unsupported platform')
result = []
for port in ports:
try:
ser = serial.Serial(port, 9600)
ser.close()
result.append(port)
except (OSError, serial.SerialException):
pass
return result
windows 上執行
樹莓派上執行