Repository navigation
Expand file tree
/
Copy pathopen_device_example.py
More file actions
40 lines (35 loc) · 1.51 KB
/
Copy pathopen_device_example.py
File metadata and controls
40 lines (35 loc) · 1.51 KB
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
import ics
# Tells our custom open_device() function to do special behavior
# with neoVI Server enabled so we can successfully open devices
enable_use_server = True
def dev_name(device):
# Return a friendly name of the device (ie. neoVI FIRE2 CY1234)
if int("AA0000", 36) <= device.SerialNumber <= int("ZZZZZZ", 36):
return device.Name + " " + ics.base36enc(device.SerialNumber)
else:
return device.Name + " " + str(device.SerialNumber)
def open_device(index=0):
device = None
if enable_use_server:
# ics.open_device() won't open a device if we have handles open already
# so we need to find them and specify which ones to connect to.
devices = ics.find_devices()
print("Opening Device {} (Open Client handles: {})...".format(dev_name(devices[index]), devices[index].NumberOfClients))
ics.open_device(devices[index])
device = devices[index]
else:
print("Opening Device...")
device = ics.open_device()
print("Opened Device %s." % dev_name(device))
return device
if __name__ == "__main__":
# Lets figure out how many are connected to the PC and display it
connected_count = len(ics.find_devices())
print("Found {} connected device(s)...".format(connected_count))
for i in range(connected_count):
# Lets open the device
device = open_device(i)
# the device will automatically close here
# because the device object is going out of
# scope.
print("Finished.")