def __init__(self, resource_name=None, **keyw): """ResourceTemplate class constructor. It opens a session to the resource. Parameters: resource_name -- (optional) the VISA name for the resource, e.g. "GPIB::10". If "None", it's assumed that the resource manager is to be constructed. keyw -- keyword argument for the class constructor of the device instance to be generated. Allowed arguments: lock, timeout. See Instrument class for a detailed description. """ _warn_for_invalid_keyword_arguments(keyw, ("lock", "timeout")) if self.__class__ is ResourceTemplate: raise TypeError("trying to instantiate an abstract class") if resource_name is not None: # is none for the resource manager warnings.filterwarnings("ignore", "VI_SUCCESS_DEV_NPRESENT") self.vi = vpp43.open(resource_manager.session, resource_name, keyw.get("lock", VI_NO_LOCK)) if vpp43.get_status() == VI_SUCCESS_DEV_NPRESENT: # okay, the device was not ready when we opened the session. # Now it gets five seconds more to become ready. Every 0.1 # seconds we probe it with viClear. passed_time = 0 # in seconds while passed_time < 5.0: time.sleep(0.1) passed_time += 0.1 try: vpp43.clear(self.vi) except VisaIOError as error: if error.error_code == VI_ERROR_NLISTENERS: continue else: raise break else: # Very last chance, this time without exception handling time.sleep(0.1) passed_time += 0.1 vpp43.clear(self.vi) _removefilter("ignore", "VI_SUCCESS_DEV_NPRESENT") timeout = keyw.get("timeout", 5) if timeout is None: vpp43.set_attribute(self.vi, VI_ATTR_TMO_VALUE, VI_TMO_INFINITE) else: self.timeout = timeout
def __init__(self, resource_name=None, **keyw): """ResourceTemplate class constructor. It opens a session to the resource. Parameters: resource_name -- (optional) the VISA name for the resource, e.g. "GPIB::10". If "None", it's assumed that the resource manager is to be constructed. keyw -- keyword argument for the class constructor of the device instance to be generated. Allowed arguments: lock, timeout. See Instrument class for a detailed description. """ _warn_for_invalid_keyword_arguments(keyw, ("lock", "timeout")) if self.__class__ is ResourceTemplate: raise TypeError, "trying to instantiate an abstract class" if resource_name is not None: # is none for the resource manager warnings.filterwarnings("ignore", "VI_SUCCESS_DEV_NPRESENT") self.vi = vpp43.open(resource_manager.session, resource_name, keyw.get("lock", VI_NO_LOCK)) if vpp43.get_status() == VI_SUCCESS_DEV_NPRESENT: # okay, the device was not ready when we opened the session. # Now it gets five seconds more to become ready. Every 0.1 # seconds we probe it with viClear. passed_time = 0 # in seconds while passed_time < 5.0: time.sleep(0.1) passed_time += 0.1 try: vpp43.clear(self.vi) except VisaIOError, error: if error.error_code == VI_ERROR_NLISTENERS: continue else: raise break else: # Very last chance, this time without exception handling time.sleep(0.1) passed_time += 0.1 vpp43.clear(self.vi) _removefilter("ignore", "VI_SUCCESS_DEV_NPRESENT") timeout = keyw.get("timeout", 5) if timeout is None: vpp43.set_attribute(self.vi, VI_ATTR_TMO_VALUE, VI_TMO_INFINITE) else: self.timeout = timeout
def __init__(self, resource_name=None, **keyw): _warn_for_invalid_keyword_arguments(keyw, ("lock", "timeout")) if self.__class__ is ResourceTemplate: raise TypeError("trying to instantiate an abstract class") if resource_name is None: # is none for the resource manager return warnings.filterwarnings("ignore", "VI_SUCCESS_DEV_NPRESENT") self.vi = vpp43.open(resource_manager.session, resource_name, keyw.get("lock", VI_NO_LOCK)) if vpp43.get_status() == VI_SUCCESS_DEV_NPRESENT: # okay, the device was not ready when we opened the session. # Now it gets five seconds more to become ready. Every 0.1 # seconds we probe it with viClear. passed_time = 0 # in seconds while passed_time < 5.0: time.sleep(0.1) passed_time += 0.1 try: vpp43.clear(self.vi) except VisaIOError as error: if error.error_code != VI_ERROR_NLISTENERS: raise break else: # Very last chance, this time without exception handling time.sleep(0.1) passed_time += 0.1 vpp43.clear(self.vi) _removefilter("ignore", "VI_SUCCESS_DEV_NPRESENT") timeout = keyw.get("timeout", 5) if timeout is None: vpp43.set_attribute(self.vi, VI_ATTR_TMO_VALUE, VI_TMO_INFINITE) else: self.timeout = timeout