Author Topic: Programming TSP in Python (Keithley DMM7510)  (Read 2042 times)

0 Members and 1 Guest are viewing this topic.

Offline Coolboy4999Topic starter

  • Newbie
  • Posts: 6
  • Country: pt
Programming TSP in Python (Keithley DMM7510)
« on: May 24, 2022, 01:51:33 pm »
Hello there.

I've recently started a project on a DMM7510 :-DMM, 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: [Select]
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 :D
 

Offline jeremy

  • Super Contributor
  • ***
  • Posts: 1079
  • Country: au
Re: Programming TSP in Python (Keithley DMM7510)
« Reply #1 on: May 24, 2022, 02:34:38 pm »
Can you just do something like:

while 1:
    try:
        val = inst.read()
        break
    catch pyvisa.errors.VisaIOError as e:
        if was_timeout(e):
            continue
        else:
            raise

You 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.
 

Offline Coolboy4999Topic starter

  • Newbie
  • Posts: 6
  • Country: pt
Re: Programming TSP in Python (Keithley DMM7510)
« Reply #2 on: May 26, 2022, 01:10:38 pm »
hey jeremy

Firstly 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: [Select]
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?
« Last Edit: May 26, 2022, 01:28:52 pm by Coolboy4999 »
 

Offline jeremy

  • Super Contributor
  • ***
  • Posts: 1079
  • Country: au
Re: Programming TSP in Python (Keithley DMM7510)
« Reply #3 on: May 26, 2022, 01:15:02 pm »
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):
            break
        else:
            raise
 

Offline jeremy

  • Super Contributor
  • ***
  • Posts: 1079
  • Country: au
Re: Programming TSP in Python (Keithley DMM7510)
« Reply #4 on: May 26, 2022, 01:19:58 pm »
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
 

Offline Coolboy4999Topic starter

  • Newbie
  • Posts: 6
  • Country: pt
Re: Programming TSP in Python (Keithley DMM7510)
« Reply #5 on: May 30, 2022, 01:41:22 pm »
hello again, jeremy

I 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
« Last Edit: May 31, 2022, 08:32:14 am by Coolboy4999 »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf