forked from labjack/LabJackPython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathu3allio.py
More file actions
68 lines (55 loc) · 1.89 KB
/
Copy pathu3allio.py
File metadata and controls
68 lines (55 loc) · 1.89 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
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
# Based on u3allio.c
import sys
from datetime import datetime
import u3
try:
numChannels = int(sys.argv[1])
except:
print("Missing or invalid integer value argument that specifies the number of analog inputs.")
print("Exiting.")
sys.exit()
quickSample = 1
longSettling = 0
latestAinValues = [0] * numChannels
numIterations = 1000
d = u3.U3()
d.getCalibrationData()
try:
# Configure the IOs before the test starts
FIOEIOAnalog = (2 ** numChannels) - 1
fios = FIOEIOAnalog & 0xFF
eios = FIOEIOAnalog // 256
d.configIO(FIOAnalog=fios, EIOAnalog=eios)
d.getFeedback(u3.PortDirWrite(Direction=[0, 0, 0], WriteMask=[0, 0, 15]))
feedbackArguments = []
feedbackArguments.append(u3.DAC0_8(Value=125))
feedbackArguments.append(u3.PortStateRead())
# Check if the U3 is an HV
if d.configU3()['VersionInfo'] & 18 == 18:
isHV = True
else:
isHV = False
for i in range(numChannels):
feedbackArguments.append(u3.AIN(i, 31, QuickSample=quickSample, LongSettling=longSettling))
start = datetime.now()
# Call Feedback 1000 (default) times
i = 0
while i < numIterations:
results = d.getFeedback(feedbackArguments)
for j in range(numChannels):
# Figure out if the channel is low or high voltage to use the correct calibration
if isHV is True and j < 4:
lowVoltage = False
else:
lowVoltage = True
latestAinValues[j] = d.binaryToCalibratedAnalogVoltage(results[2 + j], isLowVoltage=lowVoltage, isSingleEnded=True)
i += 1
end = datetime.now()
delta = end - start
print("Time difference: %s" % delta)
dm = delta / numIterations
print("Time per iteration: %s" % dm)
print("Time per iteration in millis: %s" % (dm.microseconds / 1000.0))
print("Last readings: %s" % latestAinValues)
finally:
d.close()