mirror of
https://github.com/hathach/tinyusb.git
synced 2025-01-31 05:52:55 +08:00
USBTMC: Update test python code to use the new pyvisa namespace, and other misc fixes
This commit is contained in:
parent
4a9fe813a8
commit
3d4d37375b
@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import visa
|
import pyvisa
|
||||||
import time
|
import time
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
@ -54,9 +54,9 @@ def test_srq():
|
|||||||
assert (inst.read_stb() == 0)
|
assert (inst.read_stb() == 0)
|
||||||
inst.write("123")
|
inst.write("123")
|
||||||
|
|
||||||
#inst.enable_event(visa.constants.VI_EVENT_SERVICE_REQ, visa.constants.VI_QUEUE)
|
#inst.enable_event(pyvisa.constants.VI_EVENT_SERVICE_REQ, pyvisa.constants.VI_QUEUE)
|
||||||
#waitrsp = inst.wait_on_event(visa.constants.VI_EVENT_SERVICE_REQ, 5000)
|
#waitrsp = inst.wait_on_event(pyvisa.constants.VI_EVENT_SERVICE_REQ, 5000)
|
||||||
#inst.discard_events(visa.constants.VI_EVENT_SERVICE_REQ, visa.constants.VI_QUEUE)
|
#inst.discard_events(pyvisa.constants.VI_EVENT_SERVICE_REQ, pyvisa.constants.VI_QUEUE)
|
||||||
#inst.wait_for_srq()
|
#inst.wait_for_srq()
|
||||||
time.sleep(0.3)
|
time.sleep(0.3)
|
||||||
stb = inst.read_stb()
|
stb = inst.read_stb()
|
||||||
@ -77,8 +77,8 @@ def test_read_timeout():
|
|||||||
t0 = time.monotonic()
|
t0 = time.monotonic()
|
||||||
try:
|
try:
|
||||||
rsp = inst.read()
|
rsp = inst.read()
|
||||||
assert(false), "Read should have resulted in timeout"
|
assert(False), "Read should have resulted in timeout"
|
||||||
except visa.VisaIOError:
|
except pyvisa.VisaIOError:
|
||||||
print(" Got expected exception")
|
print(" Got expected exception")
|
||||||
t = time.monotonic() - t0
|
t = time.monotonic() - t0
|
||||||
assert ((t*1000.0) > (inst.timeout - 300))
|
assert ((t*1000.0) > (inst.timeout - 300))
|
||||||
@ -99,23 +99,27 @@ def test_abort_in():
|
|||||||
t0 = time.monotonic()
|
t0 = time.monotonic()
|
||||||
try:
|
try:
|
||||||
rsp = inst.read()
|
rsp = inst.read()
|
||||||
assert(false), "Read should have resulted in timeout"
|
assert(False), "Read should have resulted in timeout"
|
||||||
except visa.VisaIOError:
|
except pyvisa.VisaIOError:
|
||||||
print(" Got expected exception")
|
print(" Got expected exception")
|
||||||
t = time.monotonic() - t0
|
t = time.monotonic() - t0
|
||||||
assert ((t*1000.0) > (inst.timeout - 300))
|
assert ((t*1000.0) > (inst.timeout - 300))
|
||||||
assert ((t*1000.0) < (inst.timeout + 300))
|
assert ((t*1000.0) < (inst.timeout + 300))
|
||||||
print(f" Delay was {t:0.3}")
|
print(f" Delay was {t:0.3}")
|
||||||
# Response is still in queue, so send a clear (to be more helpful to the next test)
|
# Response is still in queue, so read it out (to be more helpful to the next test)
|
||||||
inst.timeout = 800
|
inst.timeout = 800
|
||||||
y = inst.read()
|
y = inst.read()
|
||||||
assert(y == "xxx\r\n")
|
assert(y == "xxx\r\n")
|
||||||
|
|
||||||
def test_indicate():
|
def test_indicate():
|
||||||
# perform indicator pulse
|
# perform indicator pulse
|
||||||
usb_iface = inst.get_visa_attribute(visa.constants.VI_ATTR_USB_INTFC_NUM)
|
usb_iface = inst.get_visa_attribute(pyvisa.constants.VI_ATTR_USB_INTFC_NUM)
|
||||||
retv = inst.control_in(request_type_bitmap_field=0xA1, request_id=64, request_value=0x0000, index=usb_iface, length=0x0001)
|
retv = inst.control_in(request_type_bitmap_field=0xA1, request_id=64, request_value=0x0000, index=usb_iface, length=0x0001)
|
||||||
assert((retv[1] == visa.constants.StatusCode(0)) and (retv[0] == b'\x01')), f"indicator pulse failed: retv={retv}"
|
# pyvisa used to return (statuscode,bytes), but now only returns bytes, so we need to handle both cases
|
||||||
|
if(isinstance(retv,bytes)):
|
||||||
|
assert(retv == b'\x01')
|
||||||
|
else:
|
||||||
|
assert((retv[1] == pyvisa.constants.StatusCode(0)) and (retv[0] == b'\x01')), f"indicator pulse failed: retv={retv}"
|
||||||
|
|
||||||
|
|
||||||
def test_multi_read():
|
def test_multi_read():
|
||||||
@ -131,19 +135,19 @@ def test_multi_read():
|
|||||||
#inst.chunk_size = old_chunk_size
|
#inst.chunk_size = old_chunk_size
|
||||||
|
|
||||||
def test_stall_ep0():
|
def test_stall_ep0():
|
||||||
usb_iface = inst.get_visa_attribute(visa.constants.VI_ATTR_USB_INTFC_NUM)
|
usb_iface = inst.get_visa_attribute(pyvisa.constants.VI_ATTR_USB_INTFC_NUM)
|
||||||
inst.read_stb()
|
inst.read_stb()
|
||||||
# This is an invalid request, should create stall.
|
# This is an invalid request, should create stall.
|
||||||
try:
|
try:
|
||||||
retv = inst.control_in(request_type_bitmap_field=0xA1, request_id=60, request_value=0x0000, index=usb_iface, length=0x0001)
|
retv = inst.control_in(request_type_bitmap_field=0xA1, request_id=60, request_value=0x0000, index=usb_iface, length=0x0001)
|
||||||
assert false
|
assert(False)
|
||||||
except visa.VisaIOError:
|
except pyvisa.VisaIOError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
assert (inst.read_stb() == 0)
|
assert (inst.read_stb() == 0)
|
||||||
|
|
||||||
|
|
||||||
rm = visa.ResourceManager()
|
rm = pyvisa.ResourceManager()
|
||||||
reslist = rm.list_resources("USB?::?*::INSTR")
|
reslist = rm.list_resources("USB?::?*::INSTR")
|
||||||
print(reslist)
|
print(reslist)
|
||||||
|
|
||||||
@ -167,7 +171,6 @@ inst.timeout = 2000
|
|||||||
print("+ multi read")
|
print("+ multi read")
|
||||||
test_multi_read()
|
test_multi_read()
|
||||||
|
|
||||||
|
|
||||||
print("+ echo delay=0")
|
print("+ echo delay=0")
|
||||||
inst.write("delay 0")
|
inst.write("delay 0")
|
||||||
test_echo(1,175)
|
test_echo(1,175)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user