-
Notifications
You must be signed in to change notification settings - Fork 2
/
test-bitlib.py
99 lines (94 loc) · 3.96 KB
/
test-bitlib.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
'''Test the BitScope Library by connecting with the first available device
and performing a capture and dump. Requires BitLib 2.0 and Python Bindings'''
from bitlib import *
MY_DEVICE = 0 # one open device only
MY_CHANNEL = 0 # channel to capture and display
MY_PROBE_FILE = "" # default probe file if unspecified
MY_MODE = BL_MODE_FAST # preferred capture mode
MY_RATE = 1000000 # default sample rate we'll use for capture.
MY_SIZE = 5 # number of samples we'll capture (simply a connectivity test)
TRUE = 1
MODES = ("FAST","DUAL","MIXED","LOGIC","STREAM")
SOURCES = ("POD","BNC","X10","X20","X50","ALT","GND")
def main(argv=None):
#
# Open the first device found (only)
#
print("Starting: Attempting to open one device...")
if BL_Open(MY_PROBE_FILE,1):
#
# Open succeeded (report versions).
#
print(" Library: %s (%s)" % (
BL_Version(BL_VERSION_LIBRARY),
BL_Version(BL_VERSION_BINDING)))
#
# Select this device (optional, it's already selected).
#
BL_Select(BL_SELECT_DEVICE,MY_DEVICE)
#
# Report the link, device and channel information.
#
print(" Link: %s" % BL_Name(0))
print("BitScope: %s (%s)" % (BL_Version(BL_VERSION_DEVICE),BL_ID()))
print("Channels: %d (%d analog + %d logic)" % (
BL_Count(BL_COUNT_ANALOG)+BL_Count(BL_COUNT_LOGIC),
BL_Count(BL_COUNT_ANALOG),BL_Count(BL_COUNT_LOGIC)))
#
# Determine which modes the device supports.
#
print(" Modes:" + "".join(["%s" % (
(" " + MODES[i]) if i == BL_Mode(i) else "") for i in range(len(MODES))]))
#
# Report canonic capture specification in LOGIC (if supported) or FAST mode (otherwise.
#
BL_Mode(BL_MODE_LOGIC) == BL_MODE_LOGIC or BL_Mode(BL_MODE_FAST)
print(" Capture: %d @ %.0fHz = %fs (%s)" % (
BL_Size(),BL_Rate(),
BL_Time(),MODES[BL_Mode()]))
#
# Report the maximum offset range (if the device supports offsets).
#
BL_Range(BL_Count(BL_COUNT_RANGE));
if BL_Offset(-1000) != BL_Offset(1000):
print(" Offset: %+.4gV to %+.4gV" % (
BL_Offset(1000), BL_Offset(-1000)))
#
# Report the input source provided by the device and their respective ranges.
#
for i in range(len(SOURCES)):
if i == BL_Select(2,i):
print(" %s: " % SOURCES[i] + " ".join(["%5.2fV" % BL_Range(n) for n in range(BL_Count(3)-1,-1,-1)]))
#
# Set up to capture MY_SIZE samples at MY_RATE from CH-A via the POD input using the highest range.
#
BL_Mode(MY_MODE) # prefered capture mode
BL_Intro(BL_ZERO); # optional, default BL_ZERO
BL_Delay(BL_ZERO); # optional, default BL_ZERO
BL_Rate(MY_RATE); # optional, default BL_MAX_RATE
BL_Size(MY_SIZE); # optional default BL_MAX_SIZE
BL_Select(BL_SELECT_CHANNEL,MY_CHANNEL); # choose the channel
BL_Trigger(BL_ZERO,BL_TRIG_RISE); # optional when untriggered */
BL_Select(BL_SELECT_SOURCE,BL_SOURCE_POD); # use the POD input */
BL_Range(BL_Count(BL_COUNT_RANGE)); # maximum range
BL_Offset(BL_ZERO); # optional, default 0
BL_Enable(TRUE); # at least one channel must be initialised
#
# Perform an (untriggered) trace (this is the actual data capture).
#
BL_Trace()
#
# Acquire (i.e. upload) the captured data (which may be less than MY_SIZE!).
#
DATA = BL_Acquire()
print(" Data(%d): " % MY_SIZE + ", ".join(["%f" % DATA[n] for n in range(len(DATA))]))
#
# Close the library to release resources (we're done).
#
BL_Close()
print("Finished: Library closed, resources released.")
else:
print(" FAILED: device not found (check your probe file).")
if __name__ == "__main__":
import sys
sys.exit(main())