python-ivi / python-ivi

A Python implementation of the Interchangeable Virtual Instrument standard.
MIT License
218 stars 123 forks source link

PyVISA wrapper inside python-ivi doesn't have a way set VISA timeout #62

Open rmax7 opened 7 years ago

rmax7 commented 7 years ago

The default timeout is currently 2000 msec. But I need it to be higher (~ 5000 msec) in order to fetch screenshot from oscilloscope. But the PyVisaInstrument class in the pyvisa.py wrapper does not provide a method to set timeout.

I was able to fetch the screenshot successfully when I add the following method to ivi/interface/pyvisa.py

def set_timeout(self):
    "Set timeout to specific value"
    self.instrument.timeout = 5000

I was hoping I would be able to do it from my instrument object instead of modifying the ivi library source. For example like,

scope = ivi.agilent.agilentMSOX4024A("TCPIP0::10.0.0.254::INSTR")
scope.timeout = 5000

But it didn't work. Am I missing something?

rmax7 commented 7 years ago

I was able to figure it out with help of a good friend.

scope.timeout = 5000

didn't work because of the following: You can see that, for the object "scope" here, after several layers of inheritance the base class is ivi.

But ivi actually creates the instrument object through pyvisa.py wrapper which in turn uses the open_resource method as required by PyVISA.

Here is the snippet from ivi.py

if 'pyvisa' in globals():
    # connect with PyVISA
    self._interface = pyvisa.PyVisaInstrument(resource)

and the snippet from pyvisa.py

# New style PyVISA
visa_rm = visa.ResourceManager()
visa_instrument_opener = visa_rm.open_resource

class PyVisaInstrument:
    "PyVisa wrapper instrument interface client"
    def __init__(self, resource, *args, **kwargs):
        if type(resource) is str:
            self.instrument = visa_instrument_opener(resource, *args, **kwargs)

So, in order to access the timeout attribute correctly, you have to use the following:

scope._interface.instrument.timeout = 5000
edupo commented 5 years ago

@rmax7 Thank you for posting this. I was getting crazy with this issue lately...