Programming TSP in Python (Keithley DMM7510) - Page 1
Forum section: electronics / general

author: Coolboy4999
author_rank: Newbie
timestamp: May 24, 2022, 01:51:33 pm
content: Hello there.I've recently started a project on a DMM7510, connected by USB to a PC (Windows OS) where Python code is running, sending TSP commands to the device. (PyUSB, PyVISA and all the other libs already incorporated and working fine).My Python code successfully sends the TSP commands to the device and it executes them, but I'm looking at a way to get some return values from the TSP commands onto my Python code.For example, I'm using the DMM's display as an user interface (instead of the PC's CMD or a Python generated one [for now, at least]) and if I were to send a TSP commands like this...Code:my_instrument.write("display.input.prompt(display.BUTTONS_YESNO, \"Continue?\")")... I'd want the Python code to know which YES/NO Button was pressed, since I'm placing all the "decision-making" there.Any tips?P.S.: I've received a reply on another forum (https://forum.tek.com/viewtopic.php?f=363&t=143055) but I encountered another issue. Before you reply please do have a look at what was answered. Much appreciated

author: jeremy
author_rank: Super Contributor
timestamp: May 24, 2022, 02:34:38 pm
content: Can you just do something like:while 1:try:val = inst.read()breakcatch pyvisa.errors.VisaIOError as e:if was_timeout(e):continueelse:raiseYou would need to implement “was_timeout” yourself; basically just inspect the exception to see if it was the timeout like you mentioned in your Tek forum post.

author: Coolboy4999
author_rank: Newbie
timestamp: May 26, 2022, 01:10:38 pm
content: hey jeremyFirstly I think you mistook Python for another language (Java, maybe, idk), because in Python the syntax is "try ... except".Anyways, now my code does seem to "wait" for an input but only at the first instance of running the code. On the following times, it fetches the previous value/button pressed as I had already mentioned.Maybe I need to clear the "read()" buffer before actually reading it, no?Also, this ".read()" function:Code:my_instrument = rm.open_resource(address)(...)val = my_instrument.read()It isn't the same as "dmm.measure.read()", "dmm.digitize.read()", "file.read()" or "tspnet.read()", right? I can't seem to find it on the Reference Manual (https://download.tek.com/manual/DMM7510-901-01_B_May_2015_Ref.pdf)Also, not a Python expert, I'm not sure how to handle/check that Error "type" in the "was_timeout()" function. Tips?

author: jeremy
author_rank: Super Contributor
timestamp: May 26, 2022, 01:15:02 pm
content: Yes, you are correct about the except, C++ has been corrupting my brain lately…Yes, you probably need to empty the buffer at the beginning of the next iteration or run script. If there isn’t a function for it, you could just do a similar thing:while 1:try:val = inst.read()except pyvisa.errors.VisaIOError as e:if was_timeout(e):breakelse:raise

author: jeremy
author_rank: Super Contributor
timestamp: May 26, 2022, 01:19:58 pm
content: To check the error, it looks like you can do something like:def was_timeout(e):return e.abbreviation == "VI_ERROR_TMO"Edit: see implementation here:https://github.com/pyvisa/pyvisa/blob/93329a327c1926e599627dbc5b6915c7f59d2ec4/pyvisa/errors.py#L575

author: Coolboy4999
author_rank: Newbie
timestamp: May 30, 2022, 01:41:22 pm
content: hello again, jeremyI haven't been able to have my Python wait for my TSP return and when it does it returns a wrong value.I found a function ".waitevent()" but it doesn't seem to perform as expected for "display.input.prompt(...)" as it does for "display.prompt()".I'm running low on confidence on this architecture.Also, I've found in some other tests that I've kind of wrongly using "if" and other loops in a "my_instrument.write()" call.If I insert the command in ".write()" as formatted text (https://www.w3resource.com/python-exercises/string/python-data-type-string-exercise-26.php, should the command work then?Any tips?P.S: I've received a reply on the other forum (https://forum.tek.com/viewtopic.php?f=363&t=143055&p=290852#p290844). Have a look