-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
46 lines (35 loc) · 1.07 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from window_usb.serialport import SerialPort, list_serialports
import threading
import time
serial_port = None
stop_signal = False
def handle_received(self):
while not stop_signal:
if not serial_port.is_open:
stop_signal = True
break
print(serial_port.read())
time.sleep(0.01)
if __name__== '__main__':
port_list = list_serialports()
if len(port_list) == 0:
print("Not found ports")
exit()
elif len(port_list) == 1:
port = port_list[0]
else:
print("scan.....")
for index, name in enumerate(port_list):
print(index, name)
print("select: ", end="")
input_data = input()
index = int(input_data)
port = port_list[index]
serial_port = SerialPort(port=port, baudrate=921600, timeout=0.1, write_timeout=0)
if serial_port is None:
exit()
stop_signal = False
threading.Thread(target=handle_received, daemon=True).start()
while stop_signal:
input_data = input()
serial_port.write(input_data)