Skip to content

Commit 8d06107

Browse files
authored
Merge pull request #1 from wlgrd/discovery
adds method to discover ppk2
2 parents bd1bbb8 + 9916fd7 commit 8d06107

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

example.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,15 @@
99
import time
1010
from src.ppk2_api import PPK2_API
1111

12-
ppk2_test = PPK2_API("/dev/ttyACM0")
12+
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}')
16+
else:
17+
print(f'Too many connected PPK2\'s: {ppk2s_connected}')
18+
exit()
19+
20+
ppk2_test = PPK2_API(ppk2_port)
1321
ppk2_test.get_modifiers()
1422
ppk2_test.use_ampere_meter() # set ampere meter mode
1523
ppk2_test.toggle_DUT_power("OFF") # disable DUT power

src/ppk2_api.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,13 @@ def _handle_raw_data(self, adc_value):
171171

172172
return analog_value
173173

174+
@staticmethod
175+
def list_devices():
176+
import serial.tools.list_ports
177+
ports = serial.tools.list_ports.comports()
178+
devices = [port.device for port in ports if port.product == 'PPK2']
179+
return devices
180+
174181
def get_data(self):
175182
"""Return readings of one sampling period"""
176183
sampling_data = self.ser.read(self.ser.in_waiting)

0 commit comments

Comments
 (0)