-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdebugger.py
More file actions
44 lines (33 loc) · 866 Bytes
/
Copy pathdebugger.py
File metadata and controls
44 lines (33 loc) · 866 Bytes
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
import threading
import serial
import os
running = True
def read_line(ss: serial.Serial):
ans = bytearray()
while running:
c = ss.read()
if len(c) == 0:
continue
if c[0] == ord('\r') or c[0] == ord('\n'):
break
ans.append(c[0])
return bytes(ans)
def read_serial(port):
sock = serial.Serial(port, 115200, timeout=1)
print(f"{port}: open!")
while running:
line = read_line(sock).decode()
if line == "":
continue
print(f"{port}: {line}")
print(f"{port}: close!")
sock.close()
def main():
path = os.listdir("/dev/cg")
for p in path:
if "ctl" not in p:
threading.Thread(target=read_serial, args=(os.path.join("/dev/cg/", p),)).start()
if __name__ == '__main__':
main()
input()
running = False