mirror of
https://github.com/hathach/tinyusb.git
synced 2025-02-21 03:40:52 +00:00
Add Linux support to tmc example
Replaces visa include with pyvisa, as visa use with PyVISA is being deprecated.
This commit is contained in:
parent
62d4652f86
commit
dc2f00cca1
@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import visa
|
import pyvisa as visa
|
||||||
import time
|
import time
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
@ -36,8 +36,8 @@ def test_trig():
|
|||||||
time.sleep(0.3) # SRQ may have some delay
|
time.sleep(0.3) # SRQ may have some delay
|
||||||
assert (inst.read_stb() & 0x40), "SRQ not set after 0.3 seconds"
|
assert (inst.read_stb() & 0x40), "SRQ not set after 0.3 seconds"
|
||||||
assert (inst.read_stb() == 0)
|
assert (inst.read_stb() == 0)
|
||||||
|
|
||||||
|
|
||||||
def test_mav():
|
def test_mav():
|
||||||
inst.write("delay 50")
|
inst.write("delay 50")
|
||||||
inst.read_stb() # clear STB
|
inst.read_stb() # clear STB
|
||||||
@ -45,15 +45,15 @@ def test_mav():
|
|||||||
inst.write("123")
|
inst.write("123")
|
||||||
time.sleep(0.3)
|
time.sleep(0.3)
|
||||||
assert (inst.read_stb() & 0x10), "MAV not set after 0.5 seconds"
|
assert (inst.read_stb() & 0x10), "MAV not set after 0.5 seconds"
|
||||||
|
|
||||||
rsp = inst.read()
|
rsp = inst.read()
|
||||||
assert(rsp == "123\r\n")
|
assert(rsp == "123\r\n")
|
||||||
|
|
||||||
|
|
||||||
def test_srq():
|
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(visa.constants.VI_EVENT_SERVICE_REQ, visa.constants.VI_QUEUE)
|
||||||
#waitrsp = inst.wait_on_event(visa.constants.VI_EVENT_SERVICE_REQ, 5000)
|
#waitrsp = inst.wait_on_event(visa.constants.VI_EVENT_SERVICE_REQ, 5000)
|
||||||
#inst.discard_events(visa.constants.VI_EVENT_SERVICE_REQ, visa.constants.VI_QUEUE)
|
#inst.discard_events(visa.constants.VI_EVENT_SERVICE_REQ, visa.constants.VI_QUEUE)
|
||||||
@ -64,7 +64,7 @@ def test_srq():
|
|||||||
assert (stb == 0x50),msg
|
assert (stb == 0x50),msg
|
||||||
|
|
||||||
assert (inst.read_stb() == 0x10), "SRQ set at second read!"
|
assert (inst.read_stb() == 0x10), "SRQ set at second read!"
|
||||||
|
|
||||||
rsp = inst.read()
|
rsp = inst.read()
|
||||||
assert(rsp == "123\r\n")
|
assert(rsp == "123\r\n")
|
||||||
|
|
||||||
@ -110,14 +110,14 @@ def test_abort_in():
|
|||||||
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(visa.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}"
|
assert((retv[1] == visa.constants.StatusCode(0)) and (retv[0] == b'\x01')), f"indicator pulse failed: retv={retv}"
|
||||||
|
|
||||||
|
|
||||||
def test_multi_read():
|
def test_multi_read():
|
||||||
old_chunk_size = inst.chunk_size
|
old_chunk_size = inst.chunk_size
|
||||||
longstr = "0123456789abcdefghijklmnopqrstuvwxyz" * 10
|
longstr = "0123456789abcdefghijklmnopqrstuvwxyz" * 10
|
||||||
@ -129,7 +129,7 @@ def test_multi_read():
|
|||||||
y = inst.read()
|
y = inst.read()
|
||||||
assert (x + "\r\n" == y)
|
assert (x + "\r\n" == y)
|
||||||
#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(visa.constants.VI_ATTR_USB_INTFC_NUM)
|
||||||
inst.read_stb()
|
inst.read_stb()
|
||||||
@ -139,17 +139,25 @@ def test_stall_ep0():
|
|||||||
assert false
|
assert false
|
||||||
except visa.VisaIOError:
|
except visa.VisaIOError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
assert (inst.read_stb() == 0)
|
assert (inst.read_stb() == 0)
|
||||||
|
|
||||||
|
os = sys.platform
|
||||||
|
if os == "linux" or os == "linux2":
|
||||||
|
rm = visa.ResourceManager("@py")
|
||||||
|
elif os == "darwin":
|
||||||
|
## Not tested
|
||||||
|
print("Mac not tested\n");
|
||||||
|
sys.exit()
|
||||||
|
elif os == "win32":
|
||||||
|
rm = visa.ResourceManager("/c/Windows/system32/visa64.dll")
|
||||||
|
|
||||||
rm = visa.ResourceManager("/c/Windows/system32/visa64.dll")
|
|
||||||
reslist = rm.list_resources("USB?::?*::INSTR")
|
reslist = rm.list_resources("USB?::?*::INSTR")
|
||||||
print(reslist)
|
print(reslist)
|
||||||
|
|
||||||
if (len(reslist) == 0):
|
if (len(reslist) == 0):
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
inst = rm.open_resource(reslist[0]);
|
inst = rm.open_resource(reslist[0]);
|
||||||
inst.timeout = 3000
|
inst.timeout = 3000
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user