Skip to content

Commit d7f237c

Browse files
committed
create find_arduino.py
This is the file where the actual functionality will go.
1 parent 55ed7c6 commit d7f237c

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

find_arduino.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from boards import boards_dict
2+
from serial.tools import list_ports
3+
import re
4+
5+
def check_ports():
6+
not_arduinos = []
7+
arduinos = []
8+
for connection in list_ports.comports():
9+
port,hwid,desc = connection
10+
vid_pid = re.search(r"(?<=VID\:PID\=)[0-9|A-Z|a-z]{4}\:[0-9|A-Z|a-z]{4}", desc)
11+
vid_pid = None if vid_pid is None else vid_pid.group()
12+
print(vid_pid)
13+
if vid_pid is None:
14+
not_arduinos.append(connection)
15+
else:
16+
try:
17+
board = boards_dict[vid_pid]
18+
arduinos.append((board,connection))
19+
except KeyError:
20+
not_arduinos.append(connection)
21+
return arduinos, not_arduinos
22+
23+
if __name__ == "__main__":
24+
arduinos, not_arduinos = check_ports()
25+
for ard in arduinos:
26+
print(ard)
27+
for nard in not_arduinos:
28+
print(nard)

0 commit comments

Comments
 (0)