Skip to content

Commit 0de73aa

Browse files
brainwavecoder9DomThePorcupine
authored andcommitted
Add support for Windows (huggingface#494)
1 parent fc26069 commit 0de73aa

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed
+15-9
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,42 @@
1+
import os
12
import time
23
from pathlib import Path
34

5+
from serial.tools import list_ports # Part of pyserial library
6+
47

58
def find_available_ports():
6-
ports = []
7-
for path in Path("/dev").glob("tty*"):
8-
ports.append(str(path))
9+
if os.name == "nt": # Windows
10+
# List COM ports using pyserial
11+
ports = [port.device for port in list_ports.comports()]
12+
else: # Linux/macOS
13+
# List /dev/tty* ports for Unix-based systems
14+
ports = [str(path) for path in Path("/dev").glob("tty*")]
915
return ports
1016

1117

1218
def find_port():
1319
print("Finding all available ports for the MotorsBus.")
1420
ports_before = find_available_ports()
15-
print(ports_before)
21+
print("Ports before disconnecting:", ports_before)
1622

17-
print("Remove the usb cable from your MotorsBus and press Enter when done.")
18-
input()
23+
print("Remove the USB cable from your MotorsBus and press Enter when done.")
24+
input() # Wait for user to disconnect the device
1925

20-
time.sleep(0.5)
26+
time.sleep(0.5) # Allow some time for port to be released
2127
ports_after = find_available_ports()
2228
ports_diff = list(set(ports_before) - set(ports_after))
2329

2430
if len(ports_diff) == 1:
2531
port = ports_diff[0]
2632
print(f"The port of this MotorsBus is '{port}'")
27-
print("Reconnect the usb cable.")
33+
print("Reconnect the USB cable.")
2834
elif len(ports_diff) == 0:
2935
raise OSError(f"Could not detect the port. No difference was found ({ports_diff}).")
3036
else:
3137
raise OSError(f"Could not detect the port. More than one port was found ({ports_diff}).")
3238

3339

3440
if __name__ == "__main__":
35-
# Helper to find the usb port associated to all your MotorsBus.
41+
# Helper to find the USB port associated with your MotorsBus.
3642
find_port()

0 commit comments

Comments
 (0)