def gpib_pass_control(self, primary_address: int, secondary_address: int) -> StatusCode: """Tell a GPIB device to become controller in charge (CIC). Corresponds to viGpibPassControl function of the VISA library. Parameters ---------- primary_address : int Primary address of the GPIB device to which you want to pass control. secondary_address : int Secondary address of the targeted GPIB device. If the targeted device does not have a secondary address, this parameter should contain the value Constants.VI_NO_SEC_ADDR. Returns ------- StatusCode Return value of the library call. """ # ibpct need to get the device id matching the primary and secondary address logger.debug("GPIB.pass control") try: did = gpib.dev(self.parsed.board, primary_address, secondary_address) except gpib.GpibError: logger.exception("Failed to get id for %s, %d", primary_address, secondary_address) return StatusCode.error_resource_not_found status = gpib_lib.ibpct(did) return convert_gpib_status(status)
def gpib_pass_control(self, primary_address, secondary_address): """Tell the GPIB device at the specified address to become controller in charge (CIC). Corresponds to viGpibPassControl function of the VISA library. :param session: Unique logical identifier to a session. :param primary_address: Primary address of the GPIB device to which you want to pass control. :param secondary_address: Secondary address of the targeted GPIB device. If the targeted device does not have a secondary address, this parameter should contain the value Constants.VI_NO_SEC_ADDR. :return: return value of the library call. :rtype: :class:`pyvisa.constants.StatusCode` """ # ibpct need to get the device id matching the primary and secondary address logger.debug('GPIB.pass control') try: did = gpib.dev(self.parsed.board, primary_address, secondary_address) except gpib.GpibError: logger.exception('Failed to get id for %s, %d', primary_address, secondary_address) return StatusCode.error_resource_not_found status = gpib_lib.ibpct(did) return convert_gpib_status(status)
def get_attribute(self, attribute: ResourceAttribute) -> Tuple[Any, StatusCode]: """Get the value for a given VISA attribute for this session. Does a few checks before and calls before dispatching to `_get_attribute`. Parameters ---------- attribute : ResourceAttribute Resource attribute for which the state query is made Returns ------- Any The state of the queried attribute for a specified resource. StatusCode Return value of the library call. """ # Check if the attribute value is defined. try: attr = attributes.AttributesByID[attribute] except KeyError: return 0, StatusCode.error_nonsupported_attribute # Check if the attribute is defined for this session type. if not attr.in_resource(self.session_type): return 0, StatusCode.error_nonsupported_attribute # Check if reading the attribute is allowed. if not attr.read: raise Exception("Do not now how to handle write only attributes.") # First try to answer those attributes that are registered in # self.attrs, see Session.after_parsing if attribute in self.attrs: value = self.attrs[attribute] status = StatusCode.success if isinstance(value, tuple): getter = value[0] value, status = ( getter(attribute) if getter else (0, StatusCode.error_nonsupported_attribute) ) return value, status # Dispatch to `_get_attribute`, which must be implemented by subclasses try: return self._get_attribute(attribute) except UnknownAttribute as e: logger.exception(str(e)) return 0, StatusCode.error_nonsupported_attribute
def set_attribute(self, attribute, attribute_state): """Set the attribute_state value for a given VISA attribute for this session. Does a few checks before and calls before dispatching to `_gst_attribute`. :param attribute: Resource attribute for which the state query is made. :param attribute_state: value. :return: The return value of the library call. :rtype: VISAStatus """ # Check if the attribute value is defined. try: attr = attributes.AttributesByID[attribute] except KeyError: return StatusCode.error_nonsupported_attribute # Check if the attribute is defined for this session type. if not attr.in_resource(self.session_type): return StatusCode.error_nonsupported_attribute # Check if writing the attribute is allowed. if not attr.write: return StatusCode.error_attribute_read_only # First try to answer those attributes that are registered in # self.attrs, see Session.after_parsing if attribute in self.attrs: value = self.attrs[attribute] status = StatusCode.success if isinstance(value, tuple): setter = value[1] status = (setter(attribute, attribute_state) if setter else StatusCode.error_nonsupported_attribute) else: self.attrs[attribute] = attribute_state return status # Dispatch to `_set_attribute`, which must be implemented by subclasses try: return self._set_attribute(attribute, attribute_state) except ValueError: return StatusCode.error_nonsupported_attribute_state except NotImplementedError: e = UnknownAttribute(attribute) logger.exception(str(e)) return StatusCode.error_nonsupported_attribute except UnknownAttribute as e: logger.exception(str(e)) return StatusCode.error_nonsupported_attribute
def set_attribute(self, attribute, attribute_state): """Set the attribute_state value for a given VISA attribute for this session. Does a few checks before and calls before dispatching to `_gst_attribute`. :param attribute: Resource attribute for which the state query is made. :param attribute_state: value. :return: The return value of the library call. :rtype: VISAStatus """ # Check if the attribute value is defined. try: attr = attributes.AttributesByID[attribute] except KeyError: return constants.StatusCode.error_nonsupported_attribute # Check if the attribute is defined for this session type. if not attr.in_resource(self.session_type): return constants.StatusCode.error_nonsupported_attribute # Check if writing the attribute is allowed. if not attr.write: return constants.StatusCode.error_attribute_read_only # First try to answer those attributes that are common to all session types # or user defined because they are not defined by the interface. if attribute in self.attrs: self.attrs[attribute] = attribute_state return constants.StatusCode.success elif attribute == constants.VI_ATTR_TMO_VALUE: try: self.timeout = attribute_state except: return constants.StatusCode.error_nonsupported_attribute_state return constants.StatusCode.success # Dispatch to `_set_attribute`, which must be implemented by subclasses. try: return self._set_attribute(attribute, attribute_state) except ValueError: return constants.StatusCode.error_nonsupported_attribute_state except NotImplementedError: e = UnknownAttribute(attribute) logger.exception(str(e)) return constants.StatusCode.error_nonsupported_attribute except UnknownAttribute as e: logger.exception(str(e)) return constants.StatusCode.error_nonsupported_attribute
def get_attribute(self, attribute): """Get the value for a given VISA attribute for this session. Does a few checks before and calls before dispatching to `_get_attribute`. :param attribute: Resource attribute for which the state query is made :return: The state of the queried attribute for a specified resource, return value of the library call. :rtype: (unicode | str | list | int, VISAStatus) """ # Check if the attribute value is defined. try: attr = attributes.AttributesByID[attribute] except KeyError: return 0, StatusCode.error_nonsupported_attribute # Check if the attribute is defined for this session type. if not attr.in_resource(self.session_type): return 0, StatusCode.error_nonsupported_attribute # Check if reading the attribute is allowed. if not attr.read: raise Exception('Do not now how to handle write only attributes.') # First try to answer those attributes that are registered in # self.attrs, see Session.after_parsing if attribute in self.attrs: value = self.attrs[attribute] status = StatusCode.success if isinstance(value, tuple): getter = value[0] value, status = (getter(attribute) if getter else (0, StatusCode.error_nonsupported_attribute)) return value, status # Dispatch to `_get_attribute`, which must be implemented by subclasses try: return self._get_attribute(attribute) except UnknownAttribute as e: logger.exception(str(e)) return 0, StatusCode.error_nonsupported_attribute
def get_attribute(self, attribute): """Get the value for a given VISA attribute for this session. Does a few checks before and calls before dispatching to `_get_attribute`. :param attribute: Resource attribute for which the state query is made :return: The state of the queried attribute for a specified resource, return value of the library call. :rtype: (unicode | str | list | int, VISAStatus) """ # Check if the attribute value is defined. try: attr = attributes.AttributesByID[attribute] except KeyError: return 0, constants.StatusCode.error_nonsupported_attribute # Check if the attribute is defined for this session type. if not attr.in_resource(self.session_type): return 0, constants.StatusCode.error_nonsupported_attribute # Check if reading the attribute is allowed. if not attr.read: raise Exception('Do not now how to handle write only attributes.') # First try to answer those attributes that are common to all session types # or user defined because they are not defined by the interface. if attribute in self.attrs: return self.attrs[attribute], constants.StatusCode.success elif attribute == constants.VI_ATTR_TMO_VALUE: return self.timeout, constants.StatusCode.success # Dispatch to `_get_attribute`, which must be implemented by subclasses. try: return self._get_attribute(attribute) except UnknownAttribute as e: logger.exception(str(e)) return 0, constants.StatusCode.error_nonsupported_attribute