pyvisa / pyvisa-py

A pure python PyVISA backend
https://pyvisa-py.readthedocs.io
MIT License
282 stars 120 forks source link

sessions: set the default timeout through the API #160

Closed MatthieuDartiailh closed 6 years ago

MatthieuDartiailh commented 6 years ago

This allows to respect overridden behavior in subclasses.

@Sugarsplash could please test ? I do not have access to a test machine currently

Closes #159

MarcoVogt commented 6 years ago

The initial error seems to be fixed, yet another one appears:

In [1]: import visa
   ...: rm = visa.ResourceManager()
   ...: dso = rm.open_resource('TCPIP::192.168.10.5::INSTR')
   ...: dso.query("*IDN?")
   ...: 
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-1-d70f2f85e7e2> in <module>()
      1 import visa
      2 rm = visa.ResourceManager()
----> 3 dso = rm.open_resource('TCPIP::192.168.10.5::INSTR')
      4 dso.query("*IDN?")

/home/silab/miniconda2/lib/python2.7/site-packages/pyvisa/highlevel.pyc in open_resource(self, resource_name, access_mode, open_timeout, resource_pyclass, **kwargs)
   1722                 raise ValueError('%r is not a valid attribute for type %s' % (key, res.__class__.__name__))
   1723 
-> 1724         res.open(access_mode, open_timeout)
   1725 
   1726         for key, value in kwargs.items():

/home/silab/miniconda2/lib/python2.7/site-packages/pyvisa/resources/resource.pyc in open(self, access_mode, open_timeout)
    207         logger.debug('%s - opening ...', self._resource_name, extra=self._logging_extra)
    208         with self._resource_manager.ignore_warning(constants.VI_SUCCESS_DEV_NPRESENT):
--> 209             self.session, status = self._resource_manager.open_bare_resource(self._resource_name, access_mode, open_timeout)
    210 
    211             if status == constants.VI_SUCCESS_DEV_NPRESENT:

/home/silab/miniconda2/lib/python2.7/site-packages/pyvisa/highlevel.pyc in open_bare_resource(self, resource_name, access_mode, open_timeout)
   1679         :return: Unique logical identifier reference to a session.
   1680         """
-> 1681         return self.visalib.open(self.session, resource_name, access_mode, open_timeout)
   1682 
   1683     def open_resource(self, resource_name,

/home/silab/miniconda2/lib/python2.7/site-packages/pyvisa-py/highlevel.pyc in open(self, session, resource_name, access_mode, open_timeout)
    192         cls = sessions.Session.get_session_class(parsed.interface_type_const, parsed.resource_class)
    193 
--> 194         sess = cls(session, resource_name, parsed, open_timeout)
    195 
    196         return self._register(sess), StatusCode.success

/home/silab/miniconda2/lib/python2.7/site-packages/pyvisa-py/sessions.pyc in __init__(self, resource_manager_session, resource_name, parsed, open_timeout)
    194         attr = constants.VI_ATTR_TMO_VALUE
    195         default_timeout = attributes.AttributesByID[attr].default
--> 196         self.set_attribute(attr, default_timeout)
    197 
    198         #: Used as a place holder for the object doing the lowlevel

/home/silab/miniconda2/lib/python2.7/site-packages/pyvisa-py/sessions.pyc in set_attribute(self, attribute, attribute_state)
    407         # First try to answer those attributes that are registered in
    408         # self.attrs, see Session.after_parsing
--> 409         if attribute in self.attrs:
    410             value = self.attrs[attribute]
    411             status = StatusCode.success

AttributeError: 'TCPIPInstrSession' object has no attribute 'attrs'
MatthieuDartiailh commented 6 years ago

Sorry for that as I said I do not have a convenient testing system at the moment. The last commit should fix the issue. Please test @MarcoVogt .

jake42 commented 6 years ago

Works fine here with the second patch.

MatthieuDartiailh commented 6 years ago

Thanks for the feedback @jake42 . I will merge then and try to make a bugfix release later this week.

bors r+

jake42 commented 6 years ago

Great, thanks for your work!

bors[bot] commented 6 years ago

Build succeeded

MatthieuDartiailh commented 6 years ago

The release is now live on PyPI.