Skip to content

Commit 8c9459d

Browse files
authored
Merge pull request #43 from IRNAS/add_sn_to_discovery
list_devices: prints serial when discovering ppk2
2 parents e3fb545 + 29fd996 commit 8c9459d

File tree

3 files changed

+22
-11
lines changed

3 files changed

+22
-11
lines changed

example.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@
1010
from ppk2_api.ppk2_api import PPK2_API
1111

1212
ppk2s_connected = PPK2_API.list_devices()
13-
if(len(ppk2s_connected) == 1):
14-
ppk2_port = ppk2s_connected[0]
15-
print(f'Found PPK2 at {ppk2_port}')
13+
if len(ppk2s_connected) == 1:
14+
ppk2_port = ppk2s_connected[0][0]
15+
ppk2_serial = ppk2s_connected[0][1]
16+
print(f"Found PPK2 at {ppk2_port} with serial number {ppk2_serial}")
1617
else:
17-
print(f'Too many connected PPK2\'s: {ppk2s_connected}')
18+
print(f"Too many connected PPK2's: {ppk2s_connected}")
1819
exit()
1920

2021
ppk2_test = PPK2_API(ppk2_port, timeout=1, write_timeout=1, exclusive=True)

example_mp.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@
1010
from ppk2_api.ppk2_api import PPK2_MP as PPK2_API
1111

1212
ppk2s_connected = PPK2_API.list_devices()
13-
if(len(ppk2s_connected) == 1):
14-
ppk2_port = ppk2s_connected[0]
15-
print(f'Found PPK2 at {ppk2_port}')
13+
if len(ppk2s_connected) == 1:
14+
ppk2_port = ppk2s_connected[0][0]
15+
ppk2_serial = ppk2s_connected[0][1]
16+
print(f"Found PPK2 at {ppk2_port} with serial number {ppk2_serial}")
1617
else:
17-
print(f'Too many connected PPK2\'s: {ppk2s_connected}')
18+
print(f"Too many connected PPK2's: {ppk2s_connected}")
1819
exit()
1920

2021
ppk2_test = PPK2_API(ppk2_port, buffer_max_size_seconds=1, buffer_chunk_seconds=0.01, timeout=1, write_timeout=1, exclusive=True)

src/ppk2_api/ppk2_api.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,11 +213,20 @@ def _handle_raw_data(self, adc_value):
213213
@staticmethod
214214
def list_devices():
215215
import serial.tools.list_ports
216+
216217
ports = serial.tools.list_ports.comports()
217-
if os.name == 'nt':
218-
devices = [port.device for port in ports if port.description.startswith("nRF Connect USB CDC ACM")]
218+
if os.name == "nt":
219+
devices = [
220+
(port.device, port.serial_number[:8])
221+
for port in ports
222+
if port.description.startswith("nRF Connect USB CDC ACM")
223+
]
219224
else:
220-
devices = [port.device for port in ports if port.product == 'PPK2']
225+
devices = [
226+
(port.device, port.serial_number[:8])
227+
for port in ports
228+
if port.product == "PPK2"
229+
]
221230
return devices
222231

223232
def get_data(self):

0 commit comments

Comments
 (0)