-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathtest_static-supplies.py
69 lines (54 loc) · 2.08 KB
/
test_static-supplies.py
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from WF_SDK import device, static, supplies, error # import instruments
from time import sleep # needed for delays
"""-----------------------------------------------------------------------"""
try:
# connect to the device
device_data = device.open()
"""-----------------------------------"""
# start the positive supply
supplies_data = supplies.data()
supplies_data.master_state = True
supplies_data.state = True
supplies_data.voltage = 3.3
supplies.switch(device_data, supplies_data)
# set maximum current
if device_data.name == "Digital Discovery" or device_data.name == "Analog Discovery Pro 3X50":
static.set_current(device_data, 16)
# set all pins as output
for index in range(16):
static.set_mode(device_data, index, True)
try:
while True:
# repeat
mask = 1
while mask < 0x10000:
# go through possible states
for index in range(16):
# set the state of every DIO channel
static.set_state(device_data, index, not(mask & pow(2, index)))
sleep(0.1) # delay
mask <<= 1 # switch mask
while mask > 1:
# go through possible states backward
mask >>= 1 # switch mask
for index in range(16):
# set the state of every DIO channel
static.set_state(device_data, index, not(mask & pow(2, index)))
sleep(0.1) # delay
except KeyboardInterrupt:
# stop if Ctrl+C is pressed
pass
finally:
# stop the static I/O
static.close(device_data)
# stop and reset the power supplies
supplies_data.master_state = False
supplies.switch(device_data, supplies_data)
supplies.close(device_data)
"""-----------------------------------"""
# close the connection
device.close(device_data)
except error as e:
print(e)
# close the connection
device.close(device.data)