Electronics > Mechanical & Automation Engineering

Programming TSP in Python (Keithley DMM7510)

(1/2) > >>

Coolboy4999:
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: ---my_instrument.write("display.input.prompt(display.BUTTONS_YESNO, \"Continue?\")")
--- End code ---
... 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

jeremy:
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.

Coolboy4999:
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: ---my_instrument = rm.open_resource(address)
(...)
val = my_instrument.read()
--- End code ---
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?

jeremy:
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

jeremy:
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

Navigation

[0] Message Index

[#] Next page

There was an error while thanking
Thanking...
Go to full version
Powered by SMFPacks Advanced Attachments Uploader Mod