def __init__(self, resource_manager_session, resource_name, parsed=None, open_timeout=None): if isinstance(resource_name, common.MockInterface): parsed = rname.parse_resource_name(resource_name.resource_name) parsed['mock'] = resource_name elif parsed is None: parsed = rname.parse_resource_name(resource_name) self.parsed = parsed self.open_timeout = open_timeout #: Used as a place holder for the object doing the lowlevel communication. self.interface = None #: Used for attributes not handled by the underlying interface. #: Values are get or set automatically by get_attribute and set_attribute #: Add your own by overriding after_parsing. self.attrs = { constants.VI_ATTR_RM_SESSION: resource_manager_session, constants.VI_ATTR_RSRC_NAME: str(parsed), constants.VI_ATTR_RSRC_CLASS: parsed.resource_class, constants.VI_ATTR_INTF_TYPE: parsed.interface_type } self.after_parsing()
def open(self, session, resource_name, access_mode=constants.AccessModes.no_lock, open_timeout=constants.VI_TMO_IMMEDIATE): """Opens a session to the specified resource. Corresponds to viOpen function of the VISA library. :param session: Resource Manager session (should always be a session returned from open_default_resource_manager()). :param resource_name: Unique symbolic name of a resource. :param access_mode: Specifies the mode by which the resource is to be accessed. (constants.AccessModes) :param open_timeout: Specifies the maximum time period (in milliseconds) that this operation waits before returning an error. :return: Unique logical identifier reference to a session, return value of the library call. :rtype: session, VISAStatus """ try: open_timeout = int(open_timeout) except ValueError: raise ValueError('open_timeout (%r) must be an integer (or compatible type)' % open_timeout) try: parsed = rname.parse_resource_name(resource_name) except rname.InvalidResourceName: return 0, StatusCode.error_invalid_resource_name cls = sessions.Session.get_session_class(parsed.interface_type_const, parsed.resource_class) sess = cls(session, resource_name, parsed, open_timeout) return self._register(sess), StatusCode.success
def __init__( self, resource_manager_session: int, resource_name: str, parsed: rname.ResourceName = None, ) -> None: if parsed is None: parsed = rname.parse_resource_name(resource_name) self.parsed = parsed self.attrs = { constants.VI_ATTR_RM_SESSION: resource_manager_session, constants.VI_ATTR_RSRC_NAME: str(parsed), constants.VI_ATTR_RSRC_CLASS: parsed.resource_class, constants.VI_ATTR_INTF_TYPE: parsed.interface_type_const } self.session_type = None self.session_index = resource_manager_session self._device: Optional[BaseMocker] = None self._read_buffer = "" self._events: Dict[constants.EventType, Queue] = { i: Queue() for i in self._SUPPORTED_EVENTS } self._events_enabled: Dict[constants.EventType, bool] = { i: False for i in self._SUPPORTED_EVENTS } self._events_dict_lock = RLock() self.resource_lock = RLock()
def open(self, session, resource_name, access_mode=constants.AccessModes.no_lock, open_timeout=constants.VI_TMO_IMMEDIATE): """Opens a session to the specified resource. Corresponds to viOpen function of the VISA library. :param session: Resource Manager session (should always be a session returned from open_default_resource_manager()). :param resource_name: Unique symbolic name of a resource. :param access_mode: Specifies the mode by which the resource is to be accessed. (constants.AccessModes) :param open_timeout: Specifies the maximum time period (in milliseconds) that this operation waits before returning an error. :return: Unique logical identifier reference to a session, return value of the library call. :rtype: session, VISAStatus """ try: open_timeout = int(open_timeout) except ValueError: raise ValueError('open_timeout (%r) must be an integer (or compatible type)' % open_timeout) try: parsed = rname.parse_resource_name(resource_name) except rname.InvalidResourceName: return 0, constants.StatusCode.error_invalid_resource_name cls = sessions.Session.get_session_class(parsed.interface_type_const, parsed.resource_class) sess = cls(session, resource_name, parsed) return self._register(sess), constants.StatusCode.success
def resource_name(self, value): p = rname.parse_resource_name(value) self._resource_name = str(p) try: self._query_eom, self._response_eom = self._eoms[(p.interface_type_const, p.resource_class)] except KeyError: logger.warning("No eom provided for %s, %s." "Using LF." % (p.interface_type_const, p.resource_class)) self._query_eom, self._response_eom = b"\n", b"\n"
def open( self, session: VISARMSession, resource_name: str, access_mode: constants.AccessModes = constants.AccessModes.no_lock, open_timeout: int = constants.VI_TMO_IMMEDIATE, ) -> Tuple[VISASession, StatusCode]: """Opens a session to the specified resource. Corresponds to viOpen function of the VISA library. Parameters ---------- session : VISARMSession Resource Manager session (should always be a session returned from open_default_resource_manager()). resource_name : str Unique symbolic name of a resource. access_mode : constants.AccessModes, optional Specifies the mode by which the resource is to be accessed. open_timeout : int Specifies the maximum time period (in milliseconds) that this operation waits before returning an error. constants.VI_TMO_IMMEDIATE and constants.VI_TMO_INFINITE are used as min and max. Returns ------- VISASession Unique logical identifier reference to a session StatusCode Return value of the library call. """ try: open_timeout = int(open_timeout) except ValueError: raise ValueError( "open_timeout (%r) must be an integer (or compatible type)" % open_timeout ) try: parsed = rname.parse_resource_name(resource_name) except rname.InvalidResourceName: return ( VISASession(0), self.handle_return_value(None, StatusCode.error_invalid_resource_name), ) cls = sessions.Session.get_session_class( parsed.interface_type_const, parsed.resource_class ) sess = cls(session, resource_name, parsed, open_timeout) return self._register(sess), StatusCode.success
def __init__(self, resource_manager_session, resource_name, parsed=None, open_timeout=None): if isinstance(resource_name, common.MockInterface): parsed = rname.parse_resource_name(resource_name.resource_name) parsed["mock"] = resource_name elif parsed is None: parsed = rname.parse_resource_name(resource_name) self.parsed = parsed self.open_timeout = open_timeout #: Used as a place holder for the object doing the lowlevel #: communication. self.interface = None #: Used for attributes not handled by the underlying interface. #: Values are get or set automatically by get_attribute and #: set_attribute #: Add your own by overriding after_parsing. self.attrs = { constants.VI_ATTR_RM_SESSION: resource_manager_session, constants.VI_ATTR_RSRC_NAME: str(parsed), constants.VI_ATTR_RSRC_CLASS: parsed.resource_class, constants.VI_ATTR_INTF_TYPE: parsed.interface_type, constants.VI_ATTR_TMO_VALUE: (self._get_timeout, self._set_timeout), } #: Timeout expressed in second or None for the absence of a timeout. #: The default value is set when calling #: self.set_attribute(attr, default_timeout) self.timeout = None #: Set the default timeout from constants attr = constants.VI_ATTR_TMO_VALUE default_timeout = attributes.AttributesByID[attr].default self.set_attribute(attr, default_timeout) self.after_parsing()
def resource_name(self, value): p = rname.parse_resource_name(value) self._resource_name = str(p) try: self._query_eom, self._response_eom =\ self._eoms[(p.interface_type_const, p.resource_class)] except KeyError: logger.warning('No eom provided for %s, %s.' 'Using LF.' % (p.interface_type_const, p.resource_class)) self._query_eom, self._response_eom = b'\n', b'\n'
def __init__(self, resource_manager_session, resource_name, parsed=None): if isinstance(resource_name, common.MockInterface): parsed = rname.parse_resource_name(resource_name.resource_name) parsed['mock'] = resource_name elif parsed is None: parsed = rname.parse_resource_name(resource_name) self.parsed = parsed #: Used as a place holder for the object doing the lowlevel communication. self.interface = None #: Used for attributes not handled by the underlying interface. #: Values are get or set automatically by get_attribute and set_attribute #: Add your own by overriding after_parsing. self.attrs = {constants.VI_ATTR_RM_SESSION: resource_manager_session, constants.VI_ATTR_RSRC_NAME: str(parsed), constants.VI_ATTR_RSRC_CLASS: parsed.resource_class, constants.VI_ATTR_INTF_TYPE: parsed.interface_type} self.after_parsing()
def __init__(self, resource_manager_session, resource_name, parsed=None): if parsed is None: parsed = rname.parse_resource_name(resource_name) self.parsed = parsed self.attrs = {constants.VI_ATTR_RM_SESSION: resource_manager_session, constants.VI_ATTR_RSRC_NAME: str(parsed), constants.VI_ATTR_RSRC_CLASS: parsed.resource_class, constants.VI_ATTR_INTF_TYPE: parsed.interface_type_const} self.after_parsing() #: devices.Device self.device = None
def __init__(self, resource_manager_session, resource_name, parsed=None, open_timeout=None): if isinstance(resource_name, common.MockInterface): parsed = rname.parse_resource_name(resource_name.resource_name) parsed['mock'] = resource_name elif parsed is None: parsed = rname.parse_resource_name(resource_name) self.parsed = parsed self.open_timeout = open_timeout #: Used as a place holder for the object doing the lowlevel #: communication. self.interface = None #: Used for attributes not handled by the underlying interface. #: Values are get or set automatically by get_attribute and #: set_attribute #: Add your own by overriding after_parsing. self.attrs = {constants.VI_ATTR_RM_SESSION: resource_manager_session, constants.VI_ATTR_RSRC_NAME: str(parsed), constants.VI_ATTR_RSRC_CLASS: parsed.resource_class, constants.VI_ATTR_INTF_TYPE: parsed.interface_type, constants.VI_ATTR_TMO_VALUE: (self._get_timeout, self._set_timeout)} #: Timeout expressed in second or None for the absence of a timeout. #: The default value is set when calling #: self.set_attribute(attr, default_timeout) self.timeout = None #: Set the default timeout from constants attr = constants.VI_ATTR_TMO_VALUE default_timeout = attributes.AttributesByID[attr].default self.set_attribute(attr, default_timeout) self.after_parsing()
def __init__(self, resource_manager_session, resource_name, parsed=None): if parsed is None: parsed = rname.parse_resource_name(resource_name) self.parsed = parsed self.attrs = { constants.VI_ATTR_RM_SESSION: resource_manager_session, constants.VI_ATTR_RSRC_NAME: str(parsed), constants.VI_ATTR_RSRC_CLASS: parsed.resource_class, constants.VI_ATTR_INTF_TYPE: parsed.interface_type_const } self.after_parsing() #: devices.Device self.device = None
def open(self, session, resource_name, access_mode=constants.AccessModes.no_lock, open_timeout=constants.VI_TMO_IMMEDIATE): """Opens a session to the specified resource. Corresponds to viOpen function of the VISA library. :param session: Resource Manager session (should always be a session returned from open_default_resource_manager()). :param resource_name: Unique symbolic name of a resource. :param access_mode: Specifies the mode by which the resource is to be accessed. (constants.AccessModes) :param open_timeout: Specifies the maximum time period (in milliseconds) that this operation waits before returning an error. :return: Unique logical identifier reference to a session, return value of the library call. :rtype: session, :class:`pyvisa.constants.StatusCode` """ try: open_timeout = int(open_timeout) except ValueError: raise ValueError( 'open_timeout (%r) must be an integer (or compatible type)' % open_timeout) try: parsed = rname.parse_resource_name(resource_name) except rname.InvalidResourceName: raise Exception("ERROR: invalid resource name") # Loops through all session types, tries to parse the resource name and if ok, open it. cls = sessions.Session.get_session_class(parsed.interface_type_const, parsed.resource_class) sess = cls(session, resource_name, parsed) try: sess.device = self.devices[sess.attrs[constants.VI_ATTR_RSRC_NAME]] except KeyError: raise Exception("ERROR: resource %s not found" % resource_name) return self._register(sess), constants.StatusCode.success
def __init__( self, resource_manager_session: VISARMSession, resource_name: str, parsed: Optional[rname.ResourceName] = None, open_timeout: Optional[float] = None, ) -> None: if parsed is None: parsed = rname.parse_resource_name(resource_name) self.parsed = parsed self.open_timeout = open_timeout #: Used as a place holder for the object doing the lowlevel communication. self.interface = None #: Used for attributes not handled by the underlying interface. #: Values are get or set automatically by get_attribute and #: set_attribute #: Add your own by overriding after_parsing. self.attrs = { ResourceAttribute.resource_manager_session: resource_manager_session, ResourceAttribute.resource_name: str(parsed), ResourceAttribute.resource_class: parsed.resource_class, ResourceAttribute.interface_type: parsed.interface_type_const, ResourceAttribute.timeout_value: (self._get_timeout, self._set_timeout), } #: Timeout expressed in second or None for the absence of a timeout. #: The default value is set when calling self.set_attribute(attr, default_timeout) self.timeout = None #: Set the default timeout from constants attr = ResourceAttribute.timeout_value default_timeout = attributes.AttributesByID[attr].default self.set_attribute(attr, default_timeout) self.after_parsing()
def __init__( self, resource_manager_session: int, resource_name: str, parsed: rname.ResourceName = None, ) -> None: if parsed is None: parsed = rname.parse_resource_name(resource_name) self.parsed = parsed self.attrs = { constants.VI_ATTR_RM_SESSION: resource_manager_session, constants.VI_ATTR_RSRC_NAME: str(parsed), constants.VI_ATTR_RSRC_CLASS: parsed.resource_class, constants.VI_ATTR_INTF_TYPE: parsed.interface_type_const } self.session_type = None self.session_index = resource_manager_session self._device: Optional[BaseMocker] = None self._read_buffer = ""
def resource_name(self, value): p = rname.parse_resource_name(value) self._resource_name = str(p) self._query_eom, self._response_eom =\ self._eoms[(p.interface_type_const, p.resource_class)]