11#!/usr/bin/env python3
22
3- import visa
3+ import pyvisa
44import time
55import sys
66
@@ -54,9 +54,9 @@ def test_srq():
5454 assert (inst .read_stb () == 0 )
5555 inst .write ("123" )
5656
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)
6060 #inst.wait_for_srq()
6161 time .sleep (0.3 )
6262 stb = inst .read_stb ()
@@ -77,8 +77,8 @@ def test_read_timeout():
7777 t0 = time .monotonic ()
7878 try :
7979 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 :
8282 print (" Got expected exception" )
8383 t = time .monotonic () - t0
8484 assert ((t * 1000.0 ) > (inst .timeout - 300 ))
@@ -99,23 +99,27 @@ def test_abort_in():
9999 t0 = time .monotonic ()
100100 try :
101101 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 :
104104 print (" Got expected exception" )
105105 t = time .monotonic () - t0
106106 assert ((t * 1000.0 ) > (inst .timeout - 300 ))
107107 assert ((t * 1000.0 ) < (inst .timeout + 300 ))
108108 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)
110110 inst .timeout = 800
111111 y = inst .read ()
112112 assert (y == "xxx\r \n " )
113113
114114def test_indicate ():
115115 # 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 )
117117 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 } "
119123
120124
121125def test_multi_read ():
@@ -131,19 +135,19 @@ def test_multi_read():
131135 #inst.chunk_size = old_chunk_size
132136
133137def 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 )
135139 inst .read_stb ()
136140 # This is an invalid request, should create stall.
137141 try :
138142 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 :
141145 pass
142146
143147 assert (inst .read_stb () == 0 )
144148
145149
146- rm = visa .ResourceManager ()
150+ rm = pyvisa .ResourceManager ()
147151reslist = rm .list_resources ("USB?::?*::INSTR" )
148152print (reslist )
149153
@@ -167,7 +171,6 @@ def test_stall_ep0():
167171print ("+ multi read" )
168172test_multi_read ()
169173
170-
171174print ("+ echo delay=0" )
172175inst .write ("delay 0" )
173176test_echo (1 ,175 )
0 commit comments