summaryrefslogtreecommitdiff
path: root/examples/device/usbtmc/visaQuery.py
diff options
context:
space:
mode:
authorNathan Conrad <[email protected]>2019-09-18 21:31:38 -0400
committerNathan Conrad <[email protected]>2019-09-18 21:34:26 -0400
commit9a726dc7ed9af8f9b035b18a667105a48d8d6d8a (patch)
tree540f08c113c07f99037275c05be7f45ea7d1ae07 /examples/device/usbtmc/visaQuery.py
parent99d03fcaee64104df96e332a2347aa7ecc1b6172 (diff)
More fixes, and a bit of SRQ.
Diffstat (limited to 'examples/device/usbtmc/visaQuery.py')
-rw-r--r--examples/device/usbtmc/visaQuery.py69
1 files changed, 69 insertions, 0 deletions
diff --git a/examples/device/usbtmc/visaQuery.py b/examples/device/usbtmc/visaQuery.py
new file mode 100644
index 000000000..fa3d7f5e8
--- /dev/null
+++ b/examples/device/usbtmc/visaQuery.py
@@ -0,0 +1,69 @@
+import visa
+import time
+import sys
+
+
+def test_idn():
+ idn = inst.query("*idn?");
+ assert idn == "TinyUSB,ModelNumber,SerialNumber,FirmwareVer123456\r\n"
+
+def test_echo():
+ longstr = "0123456789abcdef" * 50
+
+ #Next try echo from 1 to 175 characters (200 is max buffer size on DUT)
+ for i in range(49,175):
+ x = longstr[0:i]
+ xt = x + inst.write_termination
+ y = inst.query(x)
+ assert(xt == y), f"echo {i}"
+
+def test_mav():
+ assert (inst.read_stb() == 0)
+ inst.write("123")
+ time.sleep(0.3)
+ assert (inst.read_stb() & 0x10), "MAV not set after 0.5 seconds"
+
+ rsp = inst.read()
+ assert(rsp == "123\r\n")
+
+
+def test_srq():
+ assert (inst.read_stb() == 0)
+ inst.write("123")
+
+ #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)
+ #inst.discard_events(visa.constants.VI_EVENT_SERVICE_REQ, visa.constants.VI_QUEUE)
+ #inst.wait_for_srq()
+ time.sleep(0.3)
+ stb = inst.read_stb()
+ msg = "SRQ not set after 0.5 seconds, was {:02x}".format(stb)
+ assert (stb == 0x50),msg
+
+ assert (inst.read_stb() == 0x10), "SRQ set at second read!"
+
+ rsp = inst.read()
+ assert(rsp == "123\r\n")
+
+
+rm = visa.ResourceManager("/c/Windows/system32/visa64.dll")
+reslist = rm.list_resources("USB?::?*::INSTR")
+print(reslist)
+
+if (len(reslist) == 0):
+ sys.exit()
+
+inst = rm.open_resource(reslist[0]);
+inst.timeout = 3000
+inst.clear()
+
+#print(idn);
+inst.clear()
+
+test_idn()
+test_echo()
+test_mav()
+test_srq()
+
+inst.close()
+print("Test complete")