1
1
#!/usr/bin/env python3
2
2
3
- import visa
3
+ import pyvisa
4
4
import time
5
5
import sys
6
6
@@ -54,9 +54,9 @@ def test_srq():
54
54
assert (inst .read_stb () == 0 )
55
55
inst .write ("123" )
56
56
57
- #inst.enable_event(visa .constants.VI_EVENT_SERVICE_REQ, visa .constants.VI_QUEUE)
58
- #waitrsp = inst.wait_on_event(visa .constants.VI_EVENT_SERVICE_REQ, 5000)
59
- #inst.discard_events(visa .constants.VI_EVENT_SERVICE_REQ, visa .constants.VI_QUEUE)
57
+ #inst.enable_event(pyvisa .constants.VI_EVENT_SERVICE_REQ, pyvisa .constants.VI_QUEUE)
58
+ #waitrsp = inst.wait_on_event(pyvisa .constants.VI_EVENT_SERVICE_REQ, 5000)
59
+ #inst.discard_events(pyvisa .constants.VI_EVENT_SERVICE_REQ, pyvisa .constants.VI_QUEUE)
60
60
#inst.wait_for_srq()
61
61
time .sleep (0.3 )
62
62
stb = inst .read_stb ()
@@ -77,8 +77,8 @@ def test_read_timeout():
77
77
t0 = time .monotonic ()
78
78
try :
79
79
rsp = inst .read ()
80
- assert (false ), "Read should have resulted in timeout"
81
- except visa .VisaIOError :
80
+ assert (False ), "Read should have resulted in timeout"
81
+ except pyvisa .VisaIOError :
82
82
print (" Got expected exception" )
83
83
t = time .monotonic () - t0
84
84
assert ((t * 1000.0 ) > (inst .timeout - 300 ))
@@ -99,23 +99,27 @@ def test_abort_in():
99
99
t0 = time .monotonic ()
100
100
try :
101
101
rsp = inst .read ()
102
- assert (false ), "Read should have resulted in timeout"
103
- except visa .VisaIOError :
102
+ assert (False ), "Read should have resulted in timeout"
103
+ except pyvisa .VisaIOError :
104
104
print (" Got expected exception" )
105
105
t = time .monotonic () - t0
106
106
assert ((t * 1000.0 ) > (inst .timeout - 300 ))
107
107
assert ((t * 1000.0 ) < (inst .timeout + 300 ))
108
108
print (f" Delay was { t :0.3} " )
109
- # Response is still in queue, so send a clear (to be more helpful to the next test)
109
+ # Response is still in queue, so read it out (to be more helpful to the next test)
110
110
inst .timeout = 800
111
111
y = inst .read ()
112
112
assert (y == "xxx\r \n " )
113
113
114
114
def test_indicate ():
115
115
# perform indicator pulse
116
- usb_iface = inst .get_visa_attribute (visa .constants .VI_ATTR_USB_INTFC_NUM )
116
+ usb_iface = inst .get_visa_attribute (pyvisa .constants .VI_ATTR_USB_INTFC_NUM )
117
117
retv = inst .control_in (request_type_bitmap_field = 0xA1 , request_id = 64 , request_value = 0x0000 , index = usb_iface , length = 0x0001 )
118
- assert ((retv [1 ] == visa .constants .StatusCode (0 )) and (retv [0 ] == b'\x01 ' )), f"indicator pulse failed: retv={ retv } "
118
+ # pyvisa used to return (statuscode,bytes), but now only returns bytes, so we need to handle both cases
119
+ if (isinstance (retv ,bytes )):
120
+ assert (retv == b'\x01 ' )
121
+ else :
122
+ assert ((retv [1 ] == pyvisa .constants .StatusCode (0 )) and (retv [0 ] == b'\x01 ' )), f"indicator pulse failed: retv={ retv } "
119
123
120
124
121
125
def test_multi_read ():
@@ -131,19 +135,19 @@ def test_multi_read():
131
135
#inst.chunk_size = old_chunk_size
132
136
133
137
def test_stall_ep0 ():
134
- usb_iface = inst .get_visa_attribute (visa .constants .VI_ATTR_USB_INTFC_NUM )
138
+ usb_iface = inst .get_visa_attribute (pyvisa .constants .VI_ATTR_USB_INTFC_NUM )
135
139
inst .read_stb ()
136
140
# This is an invalid request, should create stall.
137
141
try :
138
142
retv = inst .control_in (request_type_bitmap_field = 0xA1 , request_id = 60 , request_value = 0x0000 , index = usb_iface , length = 0x0001 )
139
- assert false
140
- except visa .VisaIOError :
143
+ assert ( False )
144
+ except pyvisa .VisaIOError :
141
145
pass
142
146
143
147
assert (inst .read_stb () == 0 )
144
148
145
149
146
- rm = visa .ResourceManager ()
150
+ rm = pyvisa .ResourceManager ()
147
151
reslist = rm .list_resources ("USB?::?*::INSTR" )
148
152
print (reslist )
149
153
@@ -167,7 +171,6 @@ def test_stall_ep0():
167
171
print ("+ multi read" )
168
172
test_multi_read ()
169
173
170
-
171
174
print ("+ echo delay=0" )
172
175
inst .write ("delay 0" )
173
176
test_echo (1 ,175 )
0 commit comments