Resource classes

Resources are high level abstractions to managing specific sessions. An instance of one of these classes is returned by the open_resource() depending on the resource type.

Generic classes

Specific Classes

class pyvisa.resources.Resource(resource_manager: ResourceManager, resource_name: str)[source]

Base class for resources.

Do not instantiate directly, use pyvisa.highlevel.ResourceManager.open_resource().

before_close() None[source]

Called just before closing an instrument.

clear() None[source]

Clear this resource.

close() None[source]

Closes the VISA session and marks the handle as invalid.

disable_event(event_type: EventType, mechanism: EventMechanism) None[source]

Disable notification for an event type(s) via the specified mechanism(s).

Parameters:
  • event_type (constants.EventType) – Logical event identifier.

  • mechanism (constants.EventMechanism) – Specifies event handling mechanisms to be disabled.

discard_events(event_type: EventType, mechanism: EventMechanism) None[source]

Discards event occurrences for an event type and mechanism in this resource.

Parameters:
  • event_type (constants.EventType) – Logical event identifier.

  • mechanism (constants.EventMechanism) – Specifies event handling mechanisms to be disabled.

enable_event(event_type: EventType, mechanism: EventMechanism, context: None = None) None[source]

Enable event occurrences for specified event types and mechanisms in this resource.

Parameters:
  • event_type (constants.EventType) – Logical event identifier.

  • mechanism (constants.EventMechanism) – Specifies event handling mechanisms to be enabled

  • context (None) – Not currently used, leave as None.

get_visa_attribute(name: ResourceAttribute) Any[source]

Retrieves the state of an attribute in this resource.

One should prefer the dedicated descriptor for often used attributes since those perform checks and automatic conversion on the value.

Parameters:

name (constants.ResourceAttribute) – Resource attribute for which the state query is made.

Returns:

The state of the queried attribute for a specified resource.

Return type:

Any

ignore_warning(*warnings_constants: StatusCode) ContextManager[source]

Ignoring warnings context manager for the current resource.

Parameters:

warnings_constants (constants.StatusCode) – Constants identifying the warnings to ignore.

implementation_version: Attribute[int]

Resource version that identifies the revisions or implementations of a resource.

install_handler(event_type: EventType, handler: Callable[[VISASession, EventType, VISAEventContext, Any], None], user_handle=None) Any[source]

Install handlers for event callbacks in this resource.

Parameters:
  • event_type (constants.EventType) – Logical event identifier.

  • handler (VISAHandler) – Handler function to be installed by a client application.

  • user_handle – A value specified by an application that can be used for identifying handlers uniquely for an event type. Depending on the backend they may be restriction on the possible values. Look at the backend install_visa_handler for more details.

Returns:

User handle in a format amenable to the backend. This is this representation of the handle that should be used when unistalling a handler.

Return type:

Any

interface_number: Attribute[int]

Board number for the given interface.

interface_type: Attribute[InterfaceType]

Interface type of the given session.

property last_status: StatusCode

Last status code for this session.

lock(timeout: float | Literal['default'] = 'default', requested_key: str | None = None) str[source]

Establish a shared lock to the resource.

Parameters:
  • timeout (Union[float, Literal["default"]], optional) – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. Defaults to “default” which means use self.timeout.

  • requested_key (Optional[str], optional) – Access key used by another session with which you want your session to share a lock or None to generate a new shared access key.

Returns:

A new shared access key if requested_key is None, otherwise, same value as the requested_key

Return type:

str

lock_context(timeout: float | Literal['default'] = 'default', requested_key: str | None = 'exclusive') Iterator[str | None][source]

A context that locks

Parameters:
  • timeout (Union[float, Literal["default"]], optional) – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. Defaults to “default” which means use self.timeout.

  • requested_key (Optional[str], optional) – When using default of ‘exclusive’ the lock is an exclusive lock. Otherwise it is the access key for the shared lock or None to generate a new shared access key.

Yields:

Optional[str] – The access_key if applicable.

lock_excl(timeout: float | Literal['default'] = 'default') None[source]

Establish an exclusive lock to the resource.

Parameters:

timeout (Union[float, Literal["default"]], optional) – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. Defaults to “default” which means use self.timeout.

lock_state: Attribute[AccessModes]

Current locking state of the resource.

open(access_mode: AccessModes = AccessModes.no_lock, open_timeout: int = 5000) None[source]

Opens a session to the specified resource.

Parameters:
  • access_mode (constants.AccessModes, optional) – Specifies the mode by which the resource is to be accessed. Defaults to constants.AccessModes.no_lock.

  • open_timeout (int, optional) – If the access_mode parameter requests a lock, then this parameter specifies the absolute time period (in milliseconds) that the resource waits to get unlocked before this operation returns an error. Defaults to 5000.

classmethod register(interface_type: InterfaceType, resource_class: str) Callable[[Type[T]], Type[T]][source]

Create a decorator to register a class.

The class is associated to an interface type, resource class pair.

Parameters:
  • interface_type (constants.InterfaceType) – Interface type for which to register a wrapper class.

  • resource_class (str) – Resource class for which to register a wrapper class.

Returns:

Decorator registering the class. Raises TypeError if some VISA attributes are missing on the registered class.

Return type:

Callable[[Type[T]], Type[T]]

resource_class: Attribute[str]

Resource class (for example, “INSTR”) as defined by the canonical resource name.

property resource_info: ResourceInfo

Get the extended information of this resource.

resource_manager: ResourceManager

Reference to the resource manager used by this resource

resource_manufacturer_name: Attribute[str]

Manufacturer name of the vendor that implemented the VISA library.

resource_name: Attribute[str]

Unique identifier for a resource compliant with the address structure.

property session: VISASession

Resource session handle.

Raises:

errors.InvalidSession – Raised if session is closed.

set_visa_attribute(name: ResourceAttribute, state: Any) StatusCode[source]

Set the state of an attribute.

One should prefer the dedicated descriptor for often used attributes since those perform checks and automatic conversion on the value.

Parameters:
  • name (constants.ResourceAttribute) – Attribute for which the state is to be modified.

  • state (Any) – The state of the attribute to be set for the specified object.

Returns:

Return value of the library call.

Return type:

constants.StatusCode

spec_version: Attribute[int]

Version of the VISA specification to which the implementation is compliant.

timeout: Attribute[float]

Timeout in milliseconds for all resource I/O operations.

uninstall_handler(event_type: EventType, handler: Callable[[VISASession, EventType, VISAEventContext, Any], None], user_handle=None) None[source]

Uninstalls handlers for events in this resource.

Parameters:
  • event_type (constants.EventType) – Logical event identifier.

  • handler (VISAHandler) – Handler function to be uninstalled by a client application.

  • user_handle (Any) – The user handle returned by install_handler.

unlock() None[source]

Relinquishes a lock for the specified resource.

visa_attributes_classes: ClassVar[Set[Type[Attribute]]] = {<class 'pyvisa.attributes.AttrVI_ATTR_INTF_INST_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_TYPE'>, <class 'pyvisa.attributes.AttrVI_ATTR_MAX_QUEUE_LENGTH'>, <class 'pyvisa.attributes.AttrVI_ATTR_RM_SESSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_CLASS'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_IMPL_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_LOCK_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_SPEC_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_TMO_VALUE'>, <class 'pyvisa.attributes.AttrVI_ATTR_USER_DATA'>}

VISA attribute descriptor classes that can be used to introspect the supported attributes and the possible values. The “often used” ones are generally directly available on the resource.

visalib: VisaLibraryBase

Reference to the VISA library instance used by the resource

wait_on_event(in_event_type: EventType, timeout: int, capture_timeout: bool = False) WaitResponse[source]

Waits for an occurrence of the specified event in this resource.

in_event_typeconstants.EventType

Logical identifier of the event(s) to wait for.

timeoutint

Absolute time period in time units that the resource shall wait for a specified event to occur before returning the time elapsed error. The time unit is in milliseconds. None means waiting forever if necessary.

capture_timeoutbool, optional

When True will not produce a VisaIOError(VI_ERROR_TMO) but instead return a WaitResponse with timed_out=True.

Returns:

Object that contains event_type, context and ret value.

Return type:

WaitResponse

wrap_handler(callable: Callable[[Resource, Event, Any], None]) Callable[[VISASession, EventType, VISAEventContext, Any], None][source]

Wrap an event handler to provide the signature expected by VISA.

The handler is expected to have the following signature: handler(resource: Resource, event: Event, user_handle: Any) -> None.

The wrapped handler should be used only to handle events on the resource used to wrap the handler.

class pyvisa.resources.MessageBasedResource(resource_manager: ResourceManager, resource_name: str)[source]

Base class for resources that use message based communication.

CR: str = '\r'
LF: str = '\n'
allow_dma: Attribute[bool]

Should I/O accesses use DMA (True) or Programmed I/O (False).

assert_trigger() None[source]

Sends a software trigger to the device.

before_close() None

Called just before closing an instrument.

chunk_size: int = 20480

Number of bytes to read at a time. Some resources (serial) may not support large chunk sizes.

clear() None

Clear this resource.

close() None

Closes the VISA session and marks the handle as invalid.

disable_event(event_type: EventType, mechanism: EventMechanism) None

Disable notification for an event type(s) via the specified mechanism(s).

Parameters:
  • event_type (constants.EventType) – Logical event identifier.

  • mechanism (constants.EventMechanism) – Specifies event handling mechanisms to be disabled.

discard_events(event_type: EventType, mechanism: EventMechanism) None

Discards event occurrences for an event type and mechanism in this resource.

Parameters:
  • event_type (constants.EventType) – Logical event identifier.

  • mechanism (constants.EventMechanism) – Specifies event handling mechanisms to be disabled.

enable_event(event_type: EventType, mechanism: EventMechanism, context: None = None) None

Enable event occurrences for specified event types and mechanisms in this resource.

Parameters:
  • event_type (constants.EventType) – Logical event identifier.

  • mechanism (constants.EventMechanism) – Specifies event handling mechanisms to be enabled

  • context (None) – Not currently used, leave as None.

property encoding: str

Encoding used for read and write operations.

flush(mask: BufferOperation) None[source]

Manually clears the specified buffers.

Depending on the value of the mask this can cause the buffer data to be written to the device.

Parameters:

mask (constants.BufferOperation) – Specifies the action to be taken with flushing the buffer. See highlevel.VisaLibraryBase.flush for a detailed description.

get_visa_attribute(name: ResourceAttribute) Any

Retrieves the state of an attribute in this resource.

One should prefer the dedicated descriptor for often used attributes since those perform checks and automatic conversion on the value.

Parameters:

name (constants.ResourceAttribute) – Resource attribute for which the state query is made.

Returns:

The state of the queried attribute for a specified resource.

Return type:

Any

ignore_warning(*warnings_constants: StatusCode) ContextManager

Ignoring warnings context manager for the current resource.

Parameters:

warnings_constants (constants.StatusCode) – Constants identifying the warnings to ignore.

implementation_version: Attribute[int]

Resource version that identifies the revisions or implementations of a resource.

install_handler(event_type: EventType, handler: Callable[[VISASession, EventType, VISAEventContext, Any], None], user_handle=None) Any

Install handlers for event callbacks in this resource.

Parameters:
  • event_type (constants.EventType) – Logical event identifier.

  • handler (VISAHandler) – Handler function to be installed by a client application.

  • user_handle – A value specified by an application that can be used for identifying handlers uniquely for an event type. Depending on the backend they may be restriction on the possible values. Look at the backend install_visa_handler for more details.

Returns:

User handle in a format amenable to the backend. This is this representation of the handle that should be used when unistalling a handler.

Return type:

Any

interface_number: Attribute[int]

Board number for the given interface.

interface_type: Attribute[constants.InterfaceType]

Interface type of the given session.

io_protocol: Attribute[IOProtocol]

IO protocol to use. See the attribute definition for more details.

property last_status: StatusCode

Last status code for this session.

lock(timeout: float | Literal['default'] = 'default', requested_key: str | None = None) str

Establish a shared lock to the resource.

Parameters:
  • timeout (Union[float, Literal["default"]], optional) – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. Defaults to “default” which means use self.timeout.

  • requested_key (Optional[str], optional) – Access key used by another session with which you want your session to share a lock or None to generate a new shared access key.

Returns:

A new shared access key if requested_key is None, otherwise, same value as the requested_key

Return type:

str

lock_context(timeout: float | Literal['default'] = 'default', requested_key: str | None = 'exclusive') Iterator[str | None]

A context that locks

Parameters:
  • timeout (Union[float, Literal["default"]], optional) – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. Defaults to “default” which means use self.timeout.

  • requested_key (Optional[str], optional) – When using default of ‘exclusive’ the lock is an exclusive lock. Otherwise it is the access key for the shared lock or None to generate a new shared access key.

Yields:

Optional[str] – The access_key if applicable.

lock_excl(timeout: float | Literal['default'] = 'default') None

Establish an exclusive lock to the resource.

Parameters:

timeout (Union[float, Literal["default"]], optional) – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. Defaults to “default” which means use self.timeout.

lock_state: Attribute[constants.AccessModes]

Current locking state of the resource.

open(access_mode: AccessModes = AccessModes.no_lock, open_timeout: int = 5000) None

Opens a session to the specified resource.

Parameters:
  • access_mode (constants.AccessModes, optional) – Specifies the mode by which the resource is to be accessed. Defaults to constants.AccessModes.no_lock.

  • open_timeout (int, optional) – If the access_mode parameter requests a lock, then this parameter specifies the absolute time period (in milliseconds) that the resource waits to get unlocked before this operation returns an error. Defaults to 5000.

query(message: str, delay: float | None = None) str[source]

A combination of write(message) and read()

Parameters:
  • message (str) – The message to send.

  • delay (Optional[float], optional) – Delay in seconds between write and read operations. If None, defaults to self.query_delay.

Returns:

Answer from the device.

Return type:

str

query_ascii_values(message: str, converter: ~typing.Literal['s', 'b', 'c', 'd', 'o', 'x', 'X', 'e', 'E', 'f', 'F', 'g', 'G'] | ~typing.Callable[[str], ~typing.Any] = 'f', separator: str | ~typing.Callable[[str], ~typing.Iterable[str]] = ',', container: ~typing.Type | ~typing.Callable[[~typing.Iterable], ~typing.Sequence] = <class 'list'>, delay: float | None = None) Sequence[Any][source]

Query the device for values in ascii format returning an iterable of values.

Parameters:
  • message (str) – The message to send.

  • converter (ASCII_CONVERTER, optional) – Str format of function to convert each value. Default to “f”.

  • separator (Union[str, Callable[[str], Iterable[str]]]) – str or callable used to split the data into individual elements. If a str is given, data.split(separator) is used. Default to “,”.

  • container (Union[Type, Callable[[Iterable], Sequence]], optional) – Container type to use for the output data. Possible values are: list, tuple, np.ndarray, etc, Default to list.

  • delay (Optional[float], optional) – Delay in seconds between write and read operations. If None, defaults to self.query_delay.

Returns:

Parsed data.

Return type:

Sequence

query_binary_values(message: str, datatype: ~typing.Literal['s', 'b', 'B', 'h', 'H', 'i', 'I', 'l', 'L', 'q', 'Q', 'f', 'd'] = 'f', is_big_endian: bool = False, container: ~typing.Type | ~typing.Callable[[~typing.Iterable], ~typing.Sequence] = <class 'list'>, delay: float | None = None, header_fmt: ~typing.Literal['ieee', 'hp', 'empty'] = 'ieee', expect_termination: bool = True, data_points: int = 0, chunk_size: int | None = None) Sequence[int | float][source]

Query the device for values in binary format returning an iterable of values.

Parameters:
  • message (str) – The message to send.

  • datatype (BINARY_DATATYPES, optional) – Format string for a single element. See struct module. ‘f’ by default.

  • is_big_endian (bool, optional) – Are the data in big or little endian order. Defaults to False.

  • container (Union[Type, Callable[[Iterable], Sequence]], optional) – Container type to use for the output data. Possible values are: list, tuple, np.ndarray, etc, Default to list.

  • delay (Optional[float], optional) – Delay in seconds between write and read operations. If None, defaults to self.query_delay.

  • header_fmt (util.BINARY_HEADERS, optional) – Format of the header prefixing the data. Defaults to ‘ieee’.

  • expect_termination (bool, optional) – When set to False, the expected length of the binary values block does not account for the final termination character (the read termination). Defaults to True.

  • data_points (int, optional) – Number of points expected in the block. This is used only if the instrument does not report it itself. This will be converted in a number of bytes based on the datatype. Defaults to 0.

  • chunk_size (int, optional) – Size of the chunks to read from the device. Using larger chunks may be faster for large amount of data.

Returns:

Data read from the device.

Return type:

Sequence[Union[int, float]]

query_delay: float = 0.0

Delay in s to sleep between the write and read occuring in a query

read(termination: str | None = None, encoding: str | None = None) str[source]

Read a string from the device.

Reading stops when the device stops sending (e.g. by setting appropriate bus lines), or the termination characters sequence was detected. Attention: Only the last character of the termination characters is really used to stop reading, however, the whole sequence is compared to the ending of the read string message. If they don’t match, a warning is issued.

Parameters:
  • termination (Optional[str], optional) – Alternative character termination to use. If None, the value of read_termination is used. Defaults to None.

  • encoding (Optional[str], optional) – Alternative encoding to use to turn bytes into str. If None, the value of encoding is used. Defaults to None.

Returns:

Message read from the instrument and decoded.

Return type:

str

read_ascii_values(converter: ~typing.Literal['s', 'b', 'c', 'd', 'o', 'x', 'X', 'e', 'E', 'f', 'F', 'g', 'G'] | ~typing.Callable[[str], ~typing.Any] = 'f', separator: str | ~typing.Callable[[str], ~typing.Iterable[str]] = ',', container: ~typing.Type | ~typing.Callable[[~typing.Iterable], ~typing.Sequence] = <class 'list'>) Sequence[source]

Read values from the device in ascii format returning an iterable of values.

Parameters:

converter (ASCII_CONVERTER, optional) – Str format of function to convert each value. Default to “f”.

separatorUnion[str, Callable[[str], Iterable[str]]]

str or callable used to split the data into individual elements. If a str is given, data.split(separator) is used. Default to “,”.

containerUnion[Type, Callable[[Iterable], Sequence]], optional

Container type to use for the output data. Possible values are: list, tuple, np.ndarray, etc, Default to list.

Returns:

Parsed data.

Return type:

Sequence

read_binary_values(datatype: ~typing.Literal['s', 'b', 'B', 'h', 'H', 'i', 'I', 'l', 'L', 'q', 'Q', 'f', 'd'] = 'f', is_big_endian: bool = False, container: ~typing.Type | ~typing.Callable[[~typing.Iterable], ~typing.Sequence] = <class 'list'>, header_fmt: ~typing.Literal['ieee', 'hp', 'empty'] = 'ieee', expect_termination: bool = True, data_points: int = -1, chunk_size: int | None = None) Sequence[int | float][source]

Read values from the device in binary format returning an iterable of values.

Parameters:
  • datatype (BINARY_DATATYPES, optional) – Format string for a single element. See struct module. ‘f’ by default.

  • is_big_endian (bool, optional) – Are the data in big or little endian order. Defaults to False.

  • container (Union[Type, Callable[[Iterable], Sequence]], optional) – Container type to use for the output data. Possible values are: list, tuple, np.ndarray, etc, Default to list.

  • header_fmt (util.BINARY_HEADERS, optional) – Format of the header prefixing the data. Defaults to ‘ieee’.

  • expect_termination (bool, optional) – When set to False, the expected length of the binary values block does not account for the final termination character (the read termination). Defaults to True.

  • data_points (int, optional) – Number of points expected in the block. This is used only if the instrument does not report it itself. This will be converted in a number of bytes based on the datatype. Defaults to 0.

  • chunk_size (int, optional) – Size of the chunks to read from the device. Using larger chunks may be faster for large amount of data.

Returns:

Data read from the device.

Return type:

Sequence[Union[int, float]]

read_bytes(count: int, chunk_size: int | None = None, break_on_termchar: bool = False) bytes[source]

Read a certain number of bytes from the instrument.

Parameters:
  • count (int) – The number of bytes to read from the instrument.

  • chunk_size (Optional[int], optional) – The chunk size to use to perform the reading. If count > chunk_size multiple low level operations will be performed. Defaults to None, meaning the resource wide set value is set.

  • break_on_termchar (bool, optional) – Should the reading stop when a termination character is encountered or when the message ends. Defaults to False.

Returns:

Bytes read from the instrument.

Return type:

bytes

read_raw(size: int | None = None) bytes[source]

Read the unmodified string sent from the instrument to the computer.

In contrast to read(), no termination characters are stripped.

Parameters:

size (Optional[int], optional) – The chunk size to use to perform the reading. Defaults to None, meaning the resource wide set value is set.

Returns:

Bytes read from the instrument.

Return type:

bytes

read_stb() int[source]

Service request status register.

property read_termination: str | None

Read termination character.

read_termination_context(new_termination: str) Iterator[source]
classmethod register(interface_type: InterfaceType, resource_class: str) Callable[[Type[T]], Type[T]]

Create a decorator to register a class.

The class is associated to an interface type, resource class pair.

Parameters:
  • interface_type (constants.InterfaceType) – Interface type for which to register a wrapper class.

  • resource_class (str) – Resource class for which to register a wrapper class.

Returns:

Decorator registering the class. Raises TypeError if some VISA attributes are missing on the registered class.

Return type:

Callable[[Type[T]], Type[T]]

resource_class: Attribute[str]

Resource class (for example, “INSTR”) as defined by the canonical resource name.

property resource_info: ResourceInfo

Get the extended information of this resource.

resource_manager: highlevel.ResourceManager

Reference to the resource manager used by this resource

resource_manufacturer_name: Attribute[str]

Manufacturer name of the vendor that implemented the VISA library.

resource_name: Attribute[str]

Unique identifier for a resource compliant with the address structure.

send_end: Attribute[bool]

Should END be asserted during the transfer of the last byte of the buffer.

property session: VISASession

Resource session handle.

Raises:

errors.InvalidSession – Raised if session is closed.

set_visa_attribute(name: ResourceAttribute, state: Any) StatusCode

Set the state of an attribute.

One should prefer the dedicated descriptor for often used attributes since those perform checks and automatic conversion on the value.

Parameters:
  • name (constants.ResourceAttribute) – Attribute for which the state is to be modified.

  • state (Any) – The state of the attribute to be set for the specified object.

Returns:

Return value of the library call.

Return type:

constants.StatusCode

spec_version: Attribute[int]

Version of the VISA specification to which the implementation is compliant.

property stb: int

Service request status register.

timeout: Attribute[float]

Timeout in milliseconds for all resource I/O operations.

uninstall_handler(event_type: EventType, handler: Callable[[VISASession, EventType, VISAEventContext, Any], None], user_handle=None) None

Uninstalls handlers for events in this resource.

Parameters:
  • event_type (constants.EventType) – Logical event identifier.

  • handler (VISAHandler) – Handler function to be uninstalled by a client application.

  • user_handle (Any) – The user handle returned by install_handler.

unlock() None

Relinquishes a lock for the specified resource.

visa_attributes_classes: ClassVar[Set[Type[attributes.Attribute]]] = {<class 'pyvisa.attributes.AttrVI_ATTR_INTF_INST_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_TYPE'>, <class 'pyvisa.attributes.AttrVI_ATTR_MAX_QUEUE_LENGTH'>, <class 'pyvisa.attributes.AttrVI_ATTR_RM_SESSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_CLASS'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_IMPL_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_LOCK_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_SPEC_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_TMO_VALUE'>, <class 'pyvisa.attributes.AttrVI_ATTR_USER_DATA'>}

VISA attribute descriptor classes that can be used to introspect the supported attributes and the possible values. The “often used” ones are generally directly available on the resource.

visalib: highlevel.VisaLibraryBase

Reference to the VISA library instance used by the resource

wait_on_event(in_event_type: EventType, timeout: int, capture_timeout: bool = False) WaitResponse

Waits for an occurrence of the specified event in this resource.

in_event_typeconstants.EventType

Logical identifier of the event(s) to wait for.

timeoutint

Absolute time period in time units that the resource shall wait for a specified event to occur before returning the time elapsed error. The time unit is in milliseconds. None means waiting forever if necessary.

capture_timeoutbool, optional

When True will not produce a VisaIOError(VI_ERROR_TMO) but instead return a WaitResponse with timed_out=True.

Returns:

Object that contains event_type, context and ret value.

Return type:

WaitResponse

wrap_handler(callable: Callable[[Resource, Event, Any], None]) Callable[[VISASession, EventType, VISAEventContext, Any], None]

Wrap an event handler to provide the signature expected by VISA.

The handler is expected to have the following signature: handler(resource: Resource, event: Event, user_handle: Any) -> None.

The wrapped handler should be used only to handle events on the resource used to wrap the handler.

write(message: str, termination: str | None = None, encoding: str | None = None) int[source]

Write a string message to the device.

The write_termination is always appended to it.

Parameters:
  • message (str) – The message to be sent.

  • termination (Optional[str], optional) – Alternative character termination to use. If None, the value of write_termination is used. Defaults to None.

  • encoding (Optional[str], optional) – Alternative encoding to use to turn str into bytes. If None, the value of encoding is used. Defaults to None.

Returns:

Number of bytes written.

Return type:

int

write_ascii_values(message: str, values: Sequence[Any], converter: Literal['s', 'b', 'c', 'd', 'o', 'x', 'X', 'e', 'E', 'f', 'F', 'g', 'G'] | Callable[[str], Any] = 'f', separator: str | Callable[[Iterable[str]], str] = ',', termination: str | None = None, encoding: str | None = None)[source]

Write a string message to the device followed by values in ascii format.

The write_termination is always appended to it.

Parameters:
  • message (str) – Header of the message to be sent.

  • values (Sequence[Any]) – Data to be writen to the device.

  • converter (Union[str, Callable[[Any], str]], optional) – Str formatting codes or function used to convert each value. Defaults to “f”.

  • separator (Union[str, Callable[[Iterable[str]], str]], optional) – Str or callable that join the values in a single str. If a str is given, separator.join(values) is used. Defaults to ‘,’

  • termination (Optional[str], optional) – Alternative character termination to use. If None, the value of write_termination is used. Defaults to None.

  • encoding (Optional[str], optional) – Alternative encoding to use to turn str into bytes. If None, the value of encoding is used. Defaults to None.

Returns:

Number of bytes written.

Return type:

int

write_binary_values(message: str, values: Sequence[Any], datatype: Literal['s', 'b', 'B', 'h', 'H', 'i', 'I', 'l', 'L', 'q', 'Q', 'f', 'd'] = 'f', is_big_endian: bool = False, termination: str | None = None, encoding: str | None = None, header_fmt: Literal['ieee', 'hp', 'empty'] = 'ieee')[source]

Write a string message to the device followed by values in binary format.

The write_termination is always appended to it.

Parameters:
  • message (str) – The header of the message to be sent.

  • values (Sequence[Any]) – Data to be written to the device.

  • datatype (util.BINARY_DATATYPES, optional) – The format string for a single element. See struct module.

  • is_big_endian (bool, optional) – Are the data in big or little endian order.

  • termination (Optional[str], optional) – Alternative character termination to use. If None, the value of write_termination is used. Defaults to None.

  • encoding (Optional[str], optional) – Alternative encoding to use to turn str into bytes. If None, the value of encoding is used. Defaults to None.

  • header_fmt (util.BINARY_HEADERS) – Format of the header prefixing the data.

Returns:

Number of bytes written.

Return type:

int

write_raw(message: bytes) int[source]

Write a byte message to the device.

Parameters:

message (bytes) – The message to be sent.

Returns:

Number of bytes written

Return type:

int

property write_termination: str

Write termination character.

class pyvisa.resources.RegisterBasedResource(resource_manager: ResourceManager, resource_name: str)[source]

Base class for resources that use register based communication.

before_close() None

Called just before closing an instrument.

clear() None

Clear this resource.

close() None

Closes the VISA session and marks the handle as invalid.

disable_event(event_type: EventType, mechanism: EventMechanism) None

Disable notification for an event type(s) via the specified mechanism(s).

Parameters:
  • event_type (constants.EventType) – Logical event identifier.

  • mechanism (constants.EventMechanism) – Specifies event handling mechanisms to be disabled.

discard_events(event_type: EventType, mechanism: EventMechanism) None

Discards event occurrences for an event type and mechanism in this resource.

Parameters:
  • event_type (constants.EventType) – Logical event identifier.

  • mechanism (constants.EventMechanism) – Specifies event handling mechanisms to be disabled.

enable_event(event_type: EventType, mechanism: EventMechanism, context: None = None) None

Enable event occurrences for specified event types and mechanisms in this resource.

Parameters:
  • event_type (constants.EventType) – Logical event identifier.

  • mechanism (constants.EventMechanism) – Specifies event handling mechanisms to be enabled

  • context (None) – Not currently used, leave as None.

get_visa_attribute(name: ResourceAttribute) Any

Retrieves the state of an attribute in this resource.

One should prefer the dedicated descriptor for often used attributes since those perform checks and automatic conversion on the value.

Parameters:

name (constants.ResourceAttribute) – Resource attribute for which the state query is made.

Returns:

The state of the queried attribute for a specified resource.

Return type:

Any

ignore_warning(*warnings_constants: StatusCode) ContextManager

Ignoring warnings context manager for the current resource.

Parameters:

warnings_constants (constants.StatusCode) – Constants identifying the warnings to ignore.

implementation_version: Attribute[int]

Resource version that identifies the revisions or implementations of a resource.

install_handler(event_type: EventType, handler: Callable[[VISASession, EventType, VISAEventContext, Any], None], user_handle=None) Any

Install handlers for event callbacks in this resource.

Parameters:
  • event_type (constants.EventType) – Logical event identifier.

  • handler (VISAHandler) – Handler function to be installed by a client application.

  • user_handle – A value specified by an application that can be used for identifying handlers uniquely for an event type. Depending on the backend they may be restriction on the possible values. Look at the backend install_visa_handler for more details.

Returns:

User handle in a format amenable to the backend. This is this representation of the handle that should be used when unistalling a handler.

Return type:

Any

interface_number: Attribute[int]

Board number for the given interface.

interface_type: Attribute[constants.InterfaceType]

Interface type of the given session.

property last_status: StatusCode

Last status code for this session.

lock(timeout: float | Literal['default'] = 'default', requested_key: str | None = None) str

Establish a shared lock to the resource.

Parameters:
  • timeout (Union[float, Literal["default"]], optional) – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. Defaults to “default” which means use self.timeout.

  • requested_key (Optional[str], optional) – Access key used by another session with which you want your session to share a lock or None to generate a new shared access key.

Returns:

A new shared access key if requested_key is None, otherwise, same value as the requested_key

Return type:

str

lock_context(timeout: float | Literal['default'] = 'default', requested_key: str | None = 'exclusive') Iterator[str | None]

A context that locks

Parameters:
  • timeout (Union[float, Literal["default"]], optional) – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. Defaults to “default” which means use self.timeout.

  • requested_key (Optional[str], optional) – When using default of ‘exclusive’ the lock is an exclusive lock. Otherwise it is the access key for the shared lock or None to generate a new shared access key.

Yields:

Optional[str] – The access_key if applicable.

lock_excl(timeout: float | Literal['default'] = 'default') None

Establish an exclusive lock to the resource.

Parameters:

timeout (Union[float, Literal["default"]], optional) – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. Defaults to “default” which means use self.timeout.

lock_state: Attribute[constants.AccessModes]

Current locking state of the resource.

move_in(space: AddressSpace, offset: int, length: int, width: DataWidth, extended: bool = False) List[int][source]

Move a block of data to local memory from the given address space and offset.

Corresponds to viMoveIn* functions of the VISA library.

Parameters:
  • space (constants.AddressSpace) – Address space from which to move the data.

  • offset (int) – Offset (in bytes) of the address or register from which to read.

  • length (int) – Number of elements to transfer, where the data width of the elements to transfer is identical to the source data width.

  • width (Union[Literal[8, 16, 32, 64], constants.DataWidth]) – Number of bits to read per element.

  • extended (bool, optional) – Use 64 bits offset independent of the platform, by default False.

Returns:

  • data (List[int]) – Data read from the bus

  • status_code (constants.StatusCode) – Return value of the library call.

Raises:

ValueError – Raised if an invalid width is specified.

move_out(space: AddressSpace, offset: int, length: int, data: Iterable[int], width: DataWidth, extended: bool = False) StatusCode[source]

Move a block of data from local memory to the given address space and offset.

Corresponds to viMoveOut* functions of the VISA library.

Parameters:
  • space (constants.AddressSpace) – Address space into which move the data.

  • offset (int) – Offset (in bytes) of the address or register from which to read.

  • length (int) – Number of elements to transfer, where the data width of the elements to transfer is identical to the source data width.

  • data (Iterable[int]) – Data to write to bus.

  • width (Union[Literal[8, 16, 32, 64], constants.DataWidth]) – Number of bits to per element.

  • extended (bool, optional) – Use 64 bits offset independent of the platform, by default False.

Returns:

Return value of the library call.

Return type:

constants.StatusCode

Raises:

ValueError – Raised if an invalid width is specified.

open(access_mode: AccessModes = AccessModes.no_lock, open_timeout: int = 5000) None

Opens a session to the specified resource.

Parameters:
  • access_mode (constants.AccessModes, optional) – Specifies the mode by which the resource is to be accessed. Defaults to constants.AccessModes.no_lock.

  • open_timeout (int, optional) – If the access_mode parameter requests a lock, then this parameter specifies the absolute time period (in milliseconds) that the resource waits to get unlocked before this operation returns an error. Defaults to 5000.

read_memory(space: AddressSpace, offset: int, width: DataWidth, extended: bool = False) int[source]

Read a value from the specified memory space and offset.

Parameters:
  • space (constants.AddressSpace) – Specifies the address space from which to read.

  • offset (int) – Offset (in bytes) of the address or register from which to read.

  • width (Union[Literal[8, 16, 32, 64], constants.DataWidth]) – Number of bits to read (8, 16, 32 or 64).

  • extended (bool, optional) – Use 64 bits offset independent of the platform.

Returns:

data – Data read from memory

Return type:

int

Raises:

ValueError – Raised if an invalid width is specified.

classmethod register(interface_type: InterfaceType, resource_class: str) Callable[[Type[T]], Type[T]]

Create a decorator to register a class.

The class is associated to an interface type, resource class pair.

Parameters:
  • interface_type (constants.InterfaceType) – Interface type for which to register a wrapper class.

  • resource_class (str) – Resource class for which to register a wrapper class.

Returns:

Decorator registering the class. Raises TypeError if some VISA attributes are missing on the registered class.

Return type:

Callable[[Type[T]], Type[T]]

resource_class: Attribute[str]

Resource class (for example, “INSTR”) as defined by the canonical resource name.

property resource_info: ResourceInfo

Get the extended information of this resource.

resource_manager: highlevel.ResourceManager

Reference to the resource manager used by this resource

resource_manufacturer_name: Attribute[str]

Manufacturer name of the vendor that implemented the VISA library.

resource_name: Attribute[str]

Unique identifier for a resource compliant with the address structure.

property session: VISASession

Resource session handle.

Raises:

errors.InvalidSession – Raised if session is closed.

set_visa_attribute(name: ResourceAttribute, state: Any) StatusCode

Set the state of an attribute.

One should prefer the dedicated descriptor for often used attributes since those perform checks and automatic conversion on the value.

Parameters:
  • name (constants.ResourceAttribute) – Attribute for which the state is to be modified.

  • state (Any) – The state of the attribute to be set for the specified object.

Returns:

Return value of the library call.

Return type:

constants.StatusCode

spec_version: Attribute[int]

Version of the VISA specification to which the implementation is compliant.

timeout: Attribute[float]

Timeout in milliseconds for all resource I/O operations.

uninstall_handler(event_type: EventType, handler: Callable[[VISASession, EventType, VISAEventContext, Any], None], user_handle=None) None

Uninstalls handlers for events in this resource.

Parameters:
  • event_type (constants.EventType) – Logical event identifier.

  • handler (VISAHandler) – Handler function to be uninstalled by a client application.

  • user_handle (Any) – The user handle returned by install_handler.

unlock() None

Relinquishes a lock for the specified resource.

visa_attributes_classes: ClassVar[Set[Type[attributes.Attribute]]] = {<class 'pyvisa.attributes.AttrVI_ATTR_INTF_INST_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_TYPE'>, <class 'pyvisa.attributes.AttrVI_ATTR_MAX_QUEUE_LENGTH'>, <class 'pyvisa.attributes.AttrVI_ATTR_RM_SESSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_CLASS'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_IMPL_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_LOCK_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_SPEC_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_TMO_VALUE'>, <class 'pyvisa.attributes.AttrVI_ATTR_USER_DATA'>}

VISA attribute descriptor classes that can be used to introspect the supported attributes and the possible values. The “often used” ones are generally directly available on the resource.

visalib: highlevel.VisaLibraryBase

Reference to the VISA library instance used by the resource

wait_on_event(in_event_type: EventType, timeout: int, capture_timeout: bool = False) WaitResponse

Waits for an occurrence of the specified event in this resource.

in_event_typeconstants.EventType

Logical identifier of the event(s) to wait for.

timeoutint

Absolute time period in time units that the resource shall wait for a specified event to occur before returning the time elapsed error. The time unit is in milliseconds. None means waiting forever if necessary.

capture_timeoutbool, optional

When True will not produce a VisaIOError(VI_ERROR_TMO) but instead return a WaitResponse with timed_out=True.

Returns:

Object that contains event_type, context and ret value.

Return type:

WaitResponse

wrap_handler(callable: Callable[[Resource, Event, Any], None]) Callable[[VISASession, EventType, VISAEventContext, Any], None]

Wrap an event handler to provide the signature expected by VISA.

The handler is expected to have the following signature: handler(resource: Resource, event: Event, user_handle: Any) -> None.

The wrapped handler should be used only to handle events on the resource used to wrap the handler.

write_memory(space: AddressSpace, offset: int, data: int, width: DataWidth, extended: bool = False) StatusCode[source]

Write a value to the specified memory space and offset.

Parameters:
  • space (constants.AddressSpace) – Specifies the address space.

  • offset (int) – Offset (in bytes) of the address or register from which to read.

  • data (int) – Data to write to bus.

  • width (Union[Literal[8, 16, 32, 64], constants.DataWidth]) – Number of bits to read.

  • extended (bool, optional) – Use 64 bits offset independent of the platform, by default False.

Returns:

Return value of the library call.

Return type:

constants.StatusCode

Raises:

ValueError – Raised if an invalid width is specified.

class pyvisa.resources.SerialInstrument(resource_manager: ResourceManager, resource_name: str)[source]

Communicates with devices of type ASRL<board>[::INSTR]

Do not instantiate directly, use pyvisa.highlevel.ResourceManager.open_resource().

CR: str = '\r'
LF: str = '\n'
allow_dma: Attribute[bool]

Should I/O accesses use DMA (True) or Programmed I/O (False).

allow_transmit: Attribute[bool]

Manually control transmission. The default value is True.

assert_trigger() None

Sends a software trigger to the device.

baud_rate: Attribute[int]

Baud rate of the interface. The default value is 9600.

before_close() None

Called just before closing an instrument.

break_length: Attribute[int]

Duration (in milliseconds) of the break signal. The default value is 250.

break_state: Attribute[LineState]

Manually control the assertion state of the break signal. The default state is constants.LineState.unasserted (VI_STATE_UNASSERTED).

bytes_in_buffer: Attribute[int]

Number of bytes available in the low- level I/O receive buffer.

chunk_size: int = 20480

Number of bytes to read at a time. Some resources (serial) may not support large chunk sizes.

clear() None

Clear this resource.

close() None

Closes the VISA session and marks the handle as invalid.

data_bits: Attribute[int]

Number of data bits contained in each frame (from 5 to 8). The default value is 8.

disable_event(event_type: EventType, mechanism: EventMechanism) None

Disable notification for an event type(s) via the specified mechanism(s).

Parameters:
  • event_type (constants.EventType) – Logical event identifier.

  • mechanism (constants.EventMechanism) – Specifies event handling mechanisms to be disabled.

discard_events(event_type: EventType, mechanism: EventMechanism) None

Discards event occurrences for an event type and mechanism in this resource.

Parameters:
  • event_type (constants.EventType) – Logical event identifier.

  • mechanism (constants.EventMechanism) – Specifies event handling mechanisms to be disabled.

discard_null: Attribute[bool]

If set to True, NUL characters are discarded. The default is False.

enable_event(event_type: EventType, mechanism: EventMechanism, context: None = None) None

Enable event occurrences for specified event types and mechanisms in this resource.

Parameters:
  • event_type (constants.EventType) – Logical event identifier.

  • mechanism (constants.EventMechanism) – Specifies event handling mechanisms to be enabled

  • context (None) – Not currently used, leave as None.

property encoding: str

Encoding used for read and write operations.

end_input: Attribute[SerialTermination]

Method used to terminate read operations. The default value is constants.SerialTermination.termination_char (VI_ASRL_END_TERMCHAR).

end_output: Attribute[SerialTermination]

Method used to terminate write operations. The default value is constants.SerialTermination.none (VI_ASRL_END_NONE) and terminates when all requested data is transferred or when an error occurs.

flow_control: Attribute[ControlFlow]

Indicates the type of flow control used by the transfer mechanism. The default value is constants.ControlFlow.none (VI_ASRL_FLOW_NONE).

flush(mask: BufferOperation) None

Manually clears the specified buffers.

Depending on the value of the mask this can cause the buffer data to be written to the device.

Parameters:

mask (constants.BufferOperation) – Specifies the action to be taken with flushing the buffer. See highlevel.VisaLibraryBase.flush for a detailed description.

get_visa_attribute(name: ResourceAttribute) Any

Retrieves the state of an attribute in this resource.

One should prefer the dedicated descriptor for often used attributes since those perform checks and automatic conversion on the value.

Parameters:

name (constants.ResourceAttribute) – Resource attribute for which the state query is made.

Returns:

The state of the queried attribute for a specified resource.

Return type:

Any

ignore_warning(*warnings_constants: StatusCode) ContextManager

Ignoring warnings context manager for the current resource.

Parameters:

warnings_constants (constants.StatusCode) – Constants identifying the warnings to ignore.

implementation_version: Attribute[int]

Resource version that identifies the revisions or implementations of a resource.

install_handler(event_type: EventType, handler: Callable[[VISASession, EventType, VISAEventContext, Any], None], user_handle=None) Any

Install handlers for event callbacks in this resource.

Parameters:
  • event_type (constants.EventType) – Logical event identifier.

  • handler (VISAHandler) – Handler function to be installed by a client application.

  • user_handle – A value specified by an application that can be used for identifying handlers uniquely for an event type. Depending on the backend they may be restriction on the possible values. Look at the backend install_visa_handler for more details.

Returns:

User handle in a format amenable to the backend. This is this representation of the handle that should be used when unistalling a handler.

Return type:

Any

interface_number: Attribute[int]

Board number for the given interface.

interface_type: Attribute[constants.InterfaceType]

Interface type of the given session.

io_protocol: Attribute[constants.IOProtocol]

IO protocol to use. See the attribute definition for more details.

property last_status: StatusCode

Last status code for this session.

lock(timeout: float | Literal['default'] = 'default', requested_key: str | None = None) str

Establish a shared lock to the resource.

Parameters:
  • timeout (Union[float, Literal["default"]], optional) – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. Defaults to “default” which means use self.timeout.

  • requested_key (Optional[str], optional) – Access key used by another session with which you want your session to share a lock or None to generate a new shared access key.

Returns:

A new shared access key if requested_key is None, otherwise, same value as the requested_key

Return type:

str

lock_context(timeout: float | Literal['default'] = 'default', requested_key: str | None = 'exclusive') Iterator[str | None]

A context that locks

Parameters:
  • timeout (Union[float, Literal["default"]], optional) – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. Defaults to “default” which means use self.timeout.

  • requested_key (Optional[str], optional) – When using default of ‘exclusive’ the lock is an exclusive lock. Otherwise it is the access key for the shared lock or None to generate a new shared access key.

Yields:

Optional[str] – The access_key if applicable.

lock_excl(timeout: float | Literal['default'] = 'default') None

Establish an exclusive lock to the resource.

Parameters:

timeout (Union[float, Literal["default"]], optional) – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. Defaults to “default” which means use self.timeout.

lock_state: Attribute[constants.AccessModes]

Current locking state of the resource.

open(access_mode: AccessModes = AccessModes.no_lock, open_timeout: int = 5000) None

Opens a session to the specified resource.

Parameters:
  • access_mode (constants.AccessModes, optional) – Specifies the mode by which the resource is to be accessed. Defaults to constants.AccessModes.no_lock.

  • open_timeout (int, optional) – If the access_mode parameter requests a lock, then this parameter specifies the absolute time period (in milliseconds) that the resource waits to get unlocked before this operation returns an error. Defaults to 5000.

parity: Attribute[Parity]

Parity used with every frame transmitted and received. The default value is constants.Parity.none (VI_ASRL_PAR_NONE).

query(message: str, delay: float | None = None) str

A combination of write(message) and read()

Parameters:
  • message (str) – The message to send.

  • delay (Optional[float], optional) – Delay in seconds between write and read operations. If None, defaults to self.query_delay.

Returns:

Answer from the device.

Return type:

str

query_ascii_values(message: str, converter: ~typing.Literal['s', 'b', 'c', 'd', 'o', 'x', 'X', 'e', 'E', 'f', 'F', 'g', 'G'] | ~typing.Callable[[str], ~typing.Any] = 'f', separator: str | ~typing.Callable[[str], ~typing.Iterable[str]] = ',', container: ~typing.Type | ~typing.Callable[[~typing.Iterable], ~typing.Sequence] = <class 'list'>, delay: float | None = None) Sequence[Any]

Query the device for values in ascii format returning an iterable of values.

Parameters:
  • message (str) – The message to send.

  • converter (ASCII_CONVERTER, optional) – Str format of function to convert each value. Default to “f”.

  • separator (Union[str, Callable[[str], Iterable[str]]]) – str or callable used to split the data into individual elements. If a str is given, data.split(separator) is used. Default to “,”.

  • container (Union[Type, Callable[[Iterable], Sequence]], optional) – Container type to use for the output data. Possible values are: list, tuple, np.ndarray, etc, Default to list.

  • delay (Optional[float], optional) – Delay in seconds between write and read operations. If None, defaults to self.query_delay.

Returns:

Parsed data.

Return type:

Sequence

query_binary_values(message: str, datatype: ~typing.Literal['s', 'b', 'B', 'h', 'H', 'i', 'I', 'l', 'L', 'q', 'Q', 'f', 'd'] = 'f', is_big_endian: bool = False, container: ~typing.Type | ~typing.Callable[[~typing.Iterable], ~typing.Sequence] = <class 'list'>, delay: float | None = None, header_fmt: ~typing.Literal['ieee', 'hp', 'empty'] = 'ieee', expect_termination: bool = True, data_points: int = 0, chunk_size: int | None = None) Sequence[int | float]

Query the device for values in binary format returning an iterable of values.

Parameters:
  • message (str) – The message to send.

  • datatype (BINARY_DATATYPES, optional) – Format string for a single element. See struct module. ‘f’ by default.

  • is_big_endian (bool, optional) – Are the data in big or little endian order. Defaults to False.

  • container (Union[Type, Callable[[Iterable], Sequence]], optional) – Container type to use for the output data. Possible values are: list, tuple, np.ndarray, etc, Default to list.

  • delay (Optional[float], optional) – Delay in seconds between write and read operations. If None, defaults to self.query_delay.

  • header_fmt (util.BINARY_HEADERS, optional) – Format of the header prefixing the data. Defaults to ‘ieee’.

  • expect_termination (bool, optional) – When set to False, the expected length of the binary values block does not account for the final termination character (the read termination). Defaults to True.

  • data_points (int, optional) – Number of points expected in the block. This is used only if the instrument does not report it itself. This will be converted in a number of bytes based on the datatype. Defaults to 0.

  • chunk_size (int, optional) – Size of the chunks to read from the device. Using larger chunks may be faster for large amount of data.

Returns:

Data read from the device.

Return type:

Sequence[Union[int, float]]

query_delay: float = 0.0

Delay in s to sleep between the write and read occuring in a query

read(termination: str | None = None, encoding: str | None = None) str

Read a string from the device.

Reading stops when the device stops sending (e.g. by setting appropriate bus lines), or the termination characters sequence was detected. Attention: Only the last character of the termination characters is really used to stop reading, however, the whole sequence is compared to the ending of the read string message. If they don’t match, a warning is issued.

Parameters:
  • termination (Optional[str], optional) – Alternative character termination to use. If None, the value of read_termination is used. Defaults to None.

  • encoding (Optional[str], optional) – Alternative encoding to use to turn bytes into str. If None, the value of encoding is used. Defaults to None.

Returns:

Message read from the instrument and decoded.

Return type:

str

read_ascii_values(converter: ~typing.Literal['s', 'b', 'c', 'd', 'o', 'x', 'X', 'e', 'E', 'f', 'F', 'g', 'G'] | ~typing.Callable[[str], ~typing.Any] = 'f', separator: str | ~typing.Callable[[str], ~typing.Iterable[str]] = ',', container: ~typing.Type | ~typing.Callable[[~typing.Iterable], ~typing.Sequence] = <class 'list'>) Sequence

Read values from the device in ascii format returning an iterable of values.

Parameters:

converter (ASCII_CONVERTER, optional) – Str format of function to convert each value. Default to “f”.

separatorUnion[str, Callable[[str], Iterable[str]]]

str or callable used to split the data into individual elements. If a str is given, data.split(separator) is used. Default to “,”.

containerUnion[Type, Callable[[Iterable], Sequence]], optional

Container type to use for the output data. Possible values are: list, tuple, np.ndarray, etc, Default to list.

Returns:

Parsed data.

Return type:

Sequence

read_binary_values(datatype: ~typing.Literal['s', 'b', 'B', 'h', 'H', 'i', 'I', 'l', 'L', 'q', 'Q', 'f', 'd'] = 'f', is_big_endian: bool = False, container: ~typing.Type | ~typing.Callable[[~typing.Iterable], ~typing.Sequence] = <class 'list'>, header_fmt: ~typing.Literal['ieee', 'hp', 'empty'] = 'ieee', expect_termination: bool = True, data_points: int = -1, chunk_size: int | None = None) Sequence[int | float]

Read values from the device in binary format returning an iterable of values.

Parameters:
  • datatype (BINARY_DATATYPES, optional) – Format string for a single element. See struct module. ‘f’ by default.

  • is_big_endian (bool, optional) – Are the data in big or little endian order. Defaults to False.

  • container (Union[Type, Callable[[Iterable], Sequence]], optional) – Container type to use for the output data. Possible values are: list, tuple, np.ndarray, etc, Default to list.

  • header_fmt (util.BINARY_HEADERS, optional) – Format of the header prefixing the data. Defaults to ‘ieee’.

  • expect_termination (bool, optional) – When set to False, the expected length of the binary values block does not account for the final termination character (the read termination). Defaults to True.

  • data_points (int, optional) – Number of points expected in the block. This is used only if the instrument does not report it itself. This will be converted in a number of bytes based on the datatype. Defaults to 0.

  • chunk_size (int, optional) – Size of the chunks to read from the device. Using larger chunks may be faster for large amount of data.

Returns:

Data read from the device.

Return type:

Sequence[Union[int, float]]

read_bytes(count: int, chunk_size: int | None = None, break_on_termchar: bool = False) bytes

Read a certain number of bytes from the instrument.

Parameters:
  • count (int) – The number of bytes to read from the instrument.

  • chunk_size (Optional[int], optional) – The chunk size to use to perform the reading. If count > chunk_size multiple low level operations will be performed. Defaults to None, meaning the resource wide set value is set.

  • break_on_termchar (bool, optional) – Should the reading stop when a termination character is encountered or when the message ends. Defaults to False.

Returns:

Bytes read from the instrument.

Return type:

bytes

read_raw(size: int | None = None) bytes

Read the unmodified string sent from the instrument to the computer.

In contrast to read(), no termination characters are stripped.

Parameters:

size (Optional[int], optional) – The chunk size to use to perform the reading. Defaults to None, meaning the resource wide set value is set.

Returns:

Bytes read from the instrument.

Return type:

bytes

read_stb() int

Service request status register.

property read_termination: str | None

Read termination character.

read_termination_context(new_termination: str) Iterator
classmethod register(interface_type: InterfaceType, resource_class: str) Callable[[Type[T]], Type[T]]

Create a decorator to register a class.

The class is associated to an interface type, resource class pair.

Parameters:
  • interface_type (constants.InterfaceType) – Interface type for which to register a wrapper class.

  • resource_class (str) – Resource class for which to register a wrapper class.

Returns:

Decorator registering the class. Raises TypeError if some VISA attributes are missing on the registered class.

Return type:

Callable[[Type[T]], Type[T]]

replace_char: Attribute[str]

Character to be used to replace incoming characters that arrive with errors. The default character is ‘0’.

resource_class: Attribute[str]

Resource class (for example, “INSTR”) as defined by the canonical resource name.

property resource_info: ResourceInfo

Get the extended information of this resource.

resource_manager: highlevel.ResourceManager

Reference to the resource manager used by this resource

resource_manufacturer_name: Attribute[str]

Manufacturer name of the vendor that implemented the VISA library.

resource_name: Attribute[str]

Unique identifier for a resource compliant with the address structure.

send_end: Attribute[bool]

Should END be asserted during the transfer of the last byte of the buffer.

property session: VISASession

Resource session handle.

Raises:

errors.InvalidSession – Raised if session is closed.

set_visa_attribute(name: ResourceAttribute, state: Any) StatusCode

Set the state of an attribute.

One should prefer the dedicated descriptor for often used attributes since those perform checks and automatic conversion on the value.

Parameters:
  • name (constants.ResourceAttribute) – Attribute for which the state is to be modified.

  • state (Any) – The state of the attribute to be set for the specified object.

Returns:

Return value of the library call.

Return type:

constants.StatusCode

spec_version: Attribute[int]

Version of the VISA specification to which the implementation is compliant.

property stb: int

Service request status register.

stop_bits: Attribute[StopBits]

Number of stop bits used to indicate the end of a frame. The default value is constants.StopBits.one (VI_ASRL_STOP_ONE).

timeout: Attribute[float]

Timeout in milliseconds for all resource I/O operations.

uninstall_handler(event_type: EventType, handler: Callable[[VISASession, EventType, VISAEventContext, Any], None], user_handle=None) None

Uninstalls handlers for events in this resource.

Parameters:
  • event_type (constants.EventType) – Logical event identifier.

  • handler (VISAHandler) – Handler function to be uninstalled by a client application.

  • user_handle (Any) – The user handle returned by install_handler.

unlock() None

Relinquishes a lock for the specified resource.

visa_attributes_classes: ClassVar[Set[Type[attributes.Attribute]]] = {<class 'pyvisa.attributes.AttrVI_ATTR_ASRL_ALLOW_TRANSMIT'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_AVAIL_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_BAUD'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_BREAK_LEN'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_BREAK_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_CONNECTED'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_CTS_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_DATA_BITS'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_DCD_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_DISCARD_NULL'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_DSR_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_DTR_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_END_IN'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_END_OUT'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_FLOW_CNTRL'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_PARITY'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_REPLACE_CHAR'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_RI_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_RTS_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_STOP_BITS'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_WIRE_MODE'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_XOFF_CHAR'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_XON_CHAR'>, <class 'pyvisa.attributes.AttrVI_ATTR_DMA_ALLOW_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_FILE_APPEND_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_INST_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_TYPE'>, <class 'pyvisa.attributes.AttrVI_ATTR_IO_PROT'>, <class 'pyvisa.attributes.AttrVI_ATTR_MAX_QUEUE_LENGTH'>, <class 'pyvisa.attributes.AttrVI_ATTR_RD_BUF_OPER_MODE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RD_BUF_SIZE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RM_SESSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_CLASS'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_IMPL_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_LOCK_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_SPEC_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_SEND_END_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_SUPPRESS_END_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_TERMCHAR'>, <class 'pyvisa.attributes.AttrVI_ATTR_TERMCHAR_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_TMO_VALUE'>, <class 'pyvisa.attributes.AttrVI_ATTR_TRIG_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_USER_DATA'>, <class 'pyvisa.attributes.AttrVI_ATTR_WR_BUF_OPER_MODE'>, <class 'pyvisa.attributes.AttrVI_ATTR_WR_BUF_SIZE'>}

VISA attribute descriptor classes that can be used to introspect the supported attributes and the possible values. The “often used” ones are generally directly available on the resource.

visalib: highlevel.VisaLibraryBase

Reference to the VISA library instance used by the resource

wait_on_event(in_event_type: EventType, timeout: int, capture_timeout: bool = False) WaitResponse

Waits for an occurrence of the specified event in this resource.

in_event_typeconstants.EventType

Logical identifier of the event(s) to wait for.

timeoutint

Absolute time period in time units that the resource shall wait for a specified event to occur before returning the time elapsed error. The time unit is in milliseconds. None means waiting forever if necessary.

capture_timeoutbool, optional

When True will not produce a VisaIOError(VI_ERROR_TMO) but instead return a WaitResponse with timed_out=True.

Returns:

Object that contains event_type, context and ret value.

Return type:

WaitResponse

wrap_handler(callable: Callable[[Resource, Event, Any], None]) Callable[[VISASession, EventType, VISAEventContext, Any], None]

Wrap an event handler to provide the signature expected by VISA.

The handler is expected to have the following signature: handler(resource: Resource, event: Event, user_handle: Any) -> None.

The wrapped handler should be used only to handle events on the resource used to wrap the handler.

write(message: str, termination: str | None = None, encoding: str | None = None) int

Write a string message to the device.

The write_termination is always appended to it.

Parameters:
  • message (str) – The message to be sent.

  • termination (Optional[str], optional) – Alternative character termination to use. If None, the value of write_termination is used. Defaults to None.

  • encoding (Optional[str], optional) – Alternative encoding to use to turn str into bytes. If None, the value of encoding is used. Defaults to None.

Returns:

Number of bytes written.

Return type:

int

write_ascii_values(message: str, values: Sequence[Any], converter: Literal['s', 'b', 'c', 'd', 'o', 'x', 'X', 'e', 'E', 'f', 'F', 'g', 'G'] | Callable[[str], Any] = 'f', separator: str | Callable[[Iterable[str]], str] = ',', termination: str | None = None, encoding: str | None = None)

Write a string message to the device followed by values in ascii format.

The write_termination is always appended to it.

Parameters:
  • message (str) – Header of the message to be sent.

  • values (Sequence[Any]) – Data to be writen to the device.

  • converter (Union[str, Callable[[Any], str]], optional) – Str formatting codes or function used to convert each value. Defaults to “f”.

  • separator (Union[str, Callable[[Iterable[str]], str]], optional) – Str or callable that join the values in a single str. If a str is given, separator.join(values) is used. Defaults to ‘,’

  • termination (Optional[str], optional) – Alternative character termination to use. If None, the value of write_termination is used. Defaults to None.

  • encoding (Optional[str], optional) – Alternative encoding to use to turn str into bytes. If None, the value of encoding is used. Defaults to None.

Returns:

Number of bytes written.

Return type:

int

write_binary_values(message: str, values: Sequence[Any], datatype: Literal['s', 'b', 'B', 'h', 'H', 'i', 'I', 'l', 'L', 'q', 'Q', 'f', 'd'] = 'f', is_big_endian: bool = False, termination: str | None = None, encoding: str | None = None, header_fmt: Literal['ieee', 'hp', 'empty'] = 'ieee')

Write a string message to the device followed by values in binary format.

The write_termination is always appended to it.

Parameters:
  • message (str) – The header of the message to be sent.

  • values (Sequence[Any]) – Data to be written to the device.

  • datatype (util.BINARY_DATATYPES, optional) – The format string for a single element. See struct module.

  • is_big_endian (bool, optional) – Are the data in big or little endian order.

  • termination (Optional[str], optional) – Alternative character termination to use. If None, the value of write_termination is used. Defaults to None.

  • encoding (Optional[str], optional) – Alternative encoding to use to turn str into bytes. If None, the value of encoding is used. Defaults to None.

  • header_fmt (util.BINARY_HEADERS) – Format of the header prefixing the data.

Returns:

Number of bytes written.

Return type:

int

write_raw(message: bytes) int

Write a byte message to the device.

Parameters:

message (bytes) – The message to be sent.

Returns:

Number of bytes written

Return type:

int

property write_termination: str

Write termination character.

xoff_char: Attribute[str]

XOFF character used for XON/XOFF flow control (both directions). The default character is ‘0x13’.

xon_char: Attribute[str]

XON character used for XON/XOFF flow control (both directions). The default character is ‘0x11’.

class pyvisa.resources.TCPIPInstrument(resource_manager: ResourceManager, resource_name: str)[source]

Communicates with to devices of type TCPIP::host address[::INSTR]

More complex resource names can be specified with the following grammar:

TCPIP[board]::host address[::LAN device name][::INSTR]

Do not instantiate directly, use pyvisa.highlevel.ResourceManager.open_resource().

CR: str = '\r'
LF: str = '\n'
allow_dma: Attribute[bool]

Should I/O accesses use DMA (True) or Programmed I/O (False).

assert_trigger() None

Sends a software trigger to the device.

before_close() None

Called just before closing an instrument.

chunk_size: int = 20480

Number of bytes to read at a time. Some resources (serial) may not support large chunk sizes.

clear() None

Clear this resource.

close() None

Closes the VISA session and marks the handle as invalid.

control_ren(mode: RENLineOperation) StatusCode

Controls the state of the GPIB Remote Enable (REN) interface line.

The remote/local state of the device can also be controlled optionally.

Corresponds to viGpibControlREN function of the VISA library.

Parameters:

mode (constants.RENLineOperation) – Specifies the state of the REN line and optionally the device remote/local state.

Returns:

Return value of the library call.

Return type:

constants.StatusCode

disable_event(event_type: EventType, mechanism: EventMechanism) None

Disable notification for an event type(s) via the specified mechanism(s).

Parameters:
  • event_type (constants.EventType) – Logical event identifier.

  • mechanism (constants.EventMechanism) – Specifies event handling mechanisms to be disabled.

discard_events(event_type: EventType, mechanism: EventMechanism) None

Discards event occurrences for an event type and mechanism in this resource.

Parameters:
  • event_type (constants.EventType) – Logical event identifier.

  • mechanism (constants.EventMechanism) – Specifies event handling mechanisms to be disabled.

enable_event(event_type: EventType, mechanism: EventMechanism, context: None = None) None

Enable event occurrences for specified event types and mechanisms in this resource.

Parameters:
  • event_type (constants.EventType) – Logical event identifier.

  • mechanism (constants.EventMechanism) – Specifies event handling mechanisms to be enabled

  • context (None) – Not currently used, leave as None.

property encoding: str

Encoding used for read and write operations.

flush(mask: BufferOperation) None

Manually clears the specified buffers.

Depending on the value of the mask this can cause the buffer data to be written to the device.

Parameters:

mask (constants.BufferOperation) – Specifies the action to be taken with flushing the buffer. See highlevel.VisaLibraryBase.flush for a detailed description.

get_visa_attribute(name: ResourceAttribute) Any

Retrieves the state of an attribute in this resource.

One should prefer the dedicated descriptor for often used attributes since those perform checks and automatic conversion on the value.

Parameters:

name (constants.ResourceAttribute) – Resource attribute for which the state query is made.

Returns:

The state of the queried attribute for a specified resource.

Return type:

Any

ignore_warning(*warnings_constants: StatusCode) ContextManager

Ignoring warnings context manager for the current resource.

Parameters:

warnings_constants (constants.StatusCode) – Constants identifying the warnings to ignore.

implementation_version: Attribute[int]

Resource version that identifies the revisions or implementations of a resource.

install_handler(event_type: EventType, handler: Callable[[VISASession, EventType, VISAEventContext, Any], None], user_handle=None) Any

Install handlers for event callbacks in this resource.

Parameters:
  • event_type (constants.EventType) – Logical event identifier.

  • handler (VISAHandler) – Handler function to be installed by a client application.

  • user_handle – A value specified by an application that can be used for identifying handlers uniquely for an event type. Depending on the backend they may be restriction on the possible values. Look at the backend install_visa_handler for more details.

Returns:

User handle in a format amenable to the backend. This is this representation of the handle that should be used when unistalling a handler.

Return type:

Any

interface_number: Attribute[int]

Board number for the given interface.

interface_type: Attribute[constants.InterfaceType]

Interface type of the given session.

io_protocol: Attribute[constants.IOProtocol]

IO protocol to use. See the attribute definition for more details.

property last_status: StatusCode

Last status code for this session.

lock(timeout: float | Literal['default'] = 'default', requested_key: str | None = None) str

Establish a shared lock to the resource.

Parameters:
  • timeout (Union[float, Literal["default"]], optional) – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. Defaults to “default” which means use self.timeout.

  • requested_key (Optional[str], optional) – Access key used by another session with which you want your session to share a lock or None to generate a new shared access key.

Returns:

A new shared access key if requested_key is None, otherwise, same value as the requested_key

Return type:

str

lock_context(timeout: float | Literal['default'] = 'default', requested_key: str | None = 'exclusive') Iterator[str | None]

A context that locks

Parameters:
  • timeout (Union[float, Literal["default"]], optional) – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. Defaults to “default” which means use self.timeout.

  • requested_key (Optional[str], optional) – When using default of ‘exclusive’ the lock is an exclusive lock. Otherwise it is the access key for the shared lock or None to generate a new shared access key.

Yields:

Optional[str] – The access_key if applicable.

lock_excl(timeout: float | Literal['default'] = 'default') None

Establish an exclusive lock to the resource.

Parameters:

timeout (Union[float, Literal["default"]], optional) – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. Defaults to “default” which means use self.timeout.

lock_state: Attribute[constants.AccessModes]

Current locking state of the resource.

open(access_mode: AccessModes = AccessModes.no_lock, open_timeout: int = 5000) None

Opens a session to the specified resource.

Parameters:
  • access_mode (constants.AccessModes, optional) – Specifies the mode by which the resource is to be accessed. Defaults to constants.AccessModes.no_lock.

  • open_timeout (int, optional) – If the access_mode parameter requests a lock, then this parameter specifies the absolute time period (in milliseconds) that the resource waits to get unlocked before this operation returns an error. Defaults to 5000.

query(message: str, delay: float | None = None) str

A combination of write(message) and read()

Parameters:
  • message (str) – The message to send.

  • delay (Optional[float], optional) – Delay in seconds between write and read operations. If None, defaults to self.query_delay.

Returns:

Answer from the device.

Return type:

str

query_ascii_values(message: str, converter: ~typing.Literal['s', 'b', 'c', 'd', 'o', 'x', 'X', 'e', 'E', 'f', 'F', 'g', 'G'] | ~typing.Callable[[str], ~typing.Any] = 'f', separator: str | ~typing.Callable[[str], ~typing.Iterable[str]] = ',', container: ~typing.Type | ~typing.Callable[[~typing.Iterable], ~typing.Sequence] = <class 'list'>, delay: float | None = None) Sequence[Any]

Query the device for values in ascii format returning an iterable of values.

Parameters:
  • message (str) – The message to send.

  • converter (ASCII_CONVERTER, optional) – Str format of function to convert each value. Default to “f”.

  • separator (Union[str, Callable[[str], Iterable[str]]]) – str or callable used to split the data into individual elements. If a str is given, data.split(separator) is used. Default to “,”.

  • container (Union[Type, Callable[[Iterable], Sequence]], optional) – Container type to use for the output data. Possible values are: list, tuple, np.ndarray, etc, Default to list.

  • delay (Optional[float], optional) – Delay in seconds between write and read operations. If None, defaults to self.query_delay.

Returns:

Parsed data.

Return type:

Sequence

query_binary_values(message: str, datatype: ~typing.Literal['s', 'b', 'B', 'h', 'H', 'i', 'I', 'l', 'L', 'q', 'Q', 'f', 'd'] = 'f', is_big_endian: bool = False, container: ~typing.Type | ~typing.Callable[[~typing.Iterable], ~typing.Sequence] = <class 'list'>, delay: float | None = None, header_fmt: ~typing.Literal['ieee', 'hp', 'empty'] = 'ieee', expect_termination: bool = True, data_points: int = 0, chunk_size: int | None = None) Sequence[int | float]

Query the device for values in binary format returning an iterable of values.

Parameters:
  • message (str) – The message to send.

  • datatype (BINARY_DATATYPES, optional) – Format string for a single element. See struct module. ‘f’ by default.

  • is_big_endian (bool, optional) – Are the data in big or little endian order. Defaults to False.

  • container (Union[Type, Callable[[Iterable], Sequence]], optional) – Container type to use for the output data. Possible values are: list, tuple, np.ndarray, etc, Default to list.

  • delay (Optional[float], optional) – Delay in seconds between write and read operations. If None, defaults to self.query_delay.

  • header_fmt (util.BINARY_HEADERS, optional) – Format of the header prefixing the data. Defaults to ‘ieee’.

  • expect_termination (bool, optional) – When set to False, the expected length of the binary values block does not account for the final termination character (the read termination). Defaults to True.

  • data_points (int, optional) – Number of points expected in the block. This is used only if the instrument does not report it itself. This will be converted in a number of bytes based on the datatype. Defaults to 0.

  • chunk_size (int, optional) – Size of the chunks to read from the device. Using larger chunks may be faster for large amount of data.

Returns:

Data read from the device.

Return type:

Sequence[Union[int, float]]

query_delay: float = 0.0

Delay in s to sleep between the write and read occuring in a query

read(termination: str | None = None, encoding: str | None = None) str

Read a string from the device.

Reading stops when the device stops sending (e.g. by setting appropriate bus lines), or the termination characters sequence was detected. Attention: Only the last character of the termination characters is really used to stop reading, however, the whole sequence is compared to the ending of the read string message. If they don’t match, a warning is issued.

Parameters:
  • termination (Optional[str], optional) – Alternative character termination to use. If None, the value of read_termination is used. Defaults to None.

  • encoding (Optional[str], optional) – Alternative encoding to use to turn bytes into str. If None, the value of encoding is used. Defaults to None.

Returns:

Message read from the instrument and decoded.

Return type:

str

read_ascii_values(converter: ~typing.Literal['s', 'b', 'c', 'd', 'o', 'x', 'X', 'e', 'E', 'f', 'F', 'g', 'G'] | ~typing.Callable[[str], ~typing.Any] = 'f', separator: str | ~typing.Callable[[str], ~typing.Iterable[str]] = ',', container: ~typing.Type | ~typing.Callable[[~typing.Iterable], ~typing.Sequence] = <class 'list'>) Sequence

Read values from the device in ascii format returning an iterable of values.

Parameters:

converter (ASCII_CONVERTER, optional) – Str format of function to convert each value. Default to “f”.

separatorUnion[str, Callable[[str], Iterable[str]]]

str or callable used to split the data into individual elements. If a str is given, data.split(separator) is used. Default to “,”.

containerUnion[Type, Callable[[Iterable], Sequence]], optional

Container type to use for the output data. Possible values are: list, tuple, np.ndarray, etc, Default to list.

Returns:

Parsed data.

Return type:

Sequence

read_binary_values(datatype: ~typing.Literal['s', 'b', 'B', 'h', 'H', 'i', 'I', 'l', 'L', 'q', 'Q', 'f', 'd'] = 'f', is_big_endian: bool = False, container: ~typing.Type | ~typing.Callable[[~typing.Iterable], ~typing.Sequence] = <class 'list'>, header_fmt: ~typing.Literal['ieee', 'hp', 'empty'] = 'ieee', expect_termination: bool = True, data_points: int = -1, chunk_size: int | None = None) Sequence[int | float]

Read values from the device in binary format returning an iterable of values.

Parameters:
  • datatype (BINARY_DATATYPES, optional) – Format string for a single element. See struct module. ‘f’ by default.

  • is_big_endian (bool, optional) – Are the data in big or little endian order. Defaults to False.

  • container (Union[Type, Callable[[Iterable], Sequence]], optional) – Container type to use for the output data. Possible values are: list, tuple, np.ndarray, etc, Default to list.

  • header_fmt (util.BINARY_HEADERS, optional) – Format of the header prefixing the data. Defaults to ‘ieee’.

  • expect_termination (bool, optional) – When set to False, the expected length of the binary values block does not account for the final termination character (the read termination). Defaults to True.

  • data_points (int, optional) – Number of points expected in the block. This is used only if the instrument does not report it itself. This will be converted in a number of bytes based on the datatype. Defaults to 0.

  • chunk_size (int, optional) – Size of the chunks to read from the device. Using larger chunks may be faster for large amount of data.

Returns:

Data read from the device.

Return type:

Sequence[Union[int, float]]

read_bytes(count: int, chunk_size: int | None = None, break_on_termchar: bool = False) bytes

Read a certain number of bytes from the instrument.

Parameters:
  • count (int) – The number of bytes to read from the instrument.

  • chunk_size (Optional[int], optional) – The chunk size to use to perform the reading. If count > chunk_size multiple low level operations will be performed. Defaults to None, meaning the resource wide set value is set.

  • break_on_termchar (bool, optional) – Should the reading stop when a termination character is encountered or when the message ends. Defaults to False.

Returns:

Bytes read from the instrument.

Return type:

bytes

read_raw(size: int | None = None) bytes

Read the unmodified string sent from the instrument to the computer.

In contrast to read(), no termination characters are stripped.

Parameters:

size (Optional[int], optional) – The chunk size to use to perform the reading. Defaults to None, meaning the resource wide set value is set.

Returns:

Bytes read from the instrument.

Return type:

bytes

read_stb() int

Service request status register.

property read_termination: str | None

Read termination character.

read_termination_context(new_termination: str) Iterator
classmethod register(interface_type: InterfaceType, resource_class: str) Callable[[Type[T]], Type[T]]

Create a decorator to register a class.

The class is associated to an interface type, resource class pair.

Parameters:
  • interface_type (constants.InterfaceType) – Interface type for which to register a wrapper class.

  • resource_class (str) – Resource class for which to register a wrapper class.

Returns:

Decorator registering the class. Raises TypeError if some VISA attributes are missing on the registered class.

Return type:

Callable[[Type[T]], Type[T]]

resource_class: Attribute[str]

Resource class (for example, “INSTR”) as defined by the canonical resource name.

property resource_info: ResourceInfo

Get the extended information of this resource.

resource_manager: highlevel.ResourceManager

Reference to the resource manager used by this resource

resource_manufacturer_name: Attribute[str]

Manufacturer name of the vendor that implemented the VISA library.

resource_name: Attribute[str]

Unique identifier for a resource compliant with the address structure.

send_end: Attribute[bool]

Should END be asserted during the transfer of the last byte of the buffer.

property session: VISASession

Resource session handle.

Raises:

errors.InvalidSession – Raised if session is closed.

set_visa_attribute(name: ResourceAttribute, state: Any) StatusCode

Set the state of an attribute.

One should prefer the dedicated descriptor for often used attributes since those perform checks and automatic conversion on the value.

Parameters:
  • name (constants.ResourceAttribute) – Attribute for which the state is to be modified.

  • state (Any) – The state of the attribute to be set for the specified object.

Returns:

Return value of the library call.

Return type:

constants.StatusCode

spec_version: Attribute[int]

Version of the VISA specification to which the implementation is compliant.

property stb: int

Service request status register.

timeout: Attribute[float]

Timeout in milliseconds for all resource I/O operations.

uninstall_handler(event_type: EventType, handler: Callable[[VISASession, EventType, VISAEventContext, Any], None], user_handle=None) None

Uninstalls handlers for events in this resource.

Parameters:
  • event_type (constants.EventType) – Logical event identifier.

  • handler (VISAHandler) – Handler function to be uninstalled by a client application.

  • user_handle (Any) – The user handle returned by install_handler.

unlock() None

Relinquishes a lock for the specified resource.

visa_attributes_classes: ClassVar[Set[Type[attributes.Attribute]]] = {<class 'pyvisa.attributes.AttrVI_ATTR_DMA_ALLOW_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_FILE_APPEND_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_INST_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_TYPE'>, <class 'pyvisa.attributes.AttrVI_ATTR_IO_PROT'>, <class 'pyvisa.attributes.AttrVI_ATTR_MAX_QUEUE_LENGTH'>, <class 'pyvisa.attributes.AttrVI_ATTR_RD_BUF_OPER_MODE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RD_BUF_SIZE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RM_SESSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_CLASS'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_IMPL_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_LOCK_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_SPEC_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_SEND_END_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_SUPPRESS_END_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_TCPIP_ADDR'>, <class 'pyvisa.attributes.AttrVI_ATTR_TCPIP_DEVICE_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_TCPIP_HISLIP_MAX_MESSAGE_KB'>, <class 'pyvisa.attributes.AttrVI_ATTR_TCPIP_HISLIP_OVERLAP_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_TCPIP_HISLIP_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_TCPIP_HOSTNAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_TCPIP_IS_HISLIP'>, <class 'pyvisa.attributes.AttrVI_ATTR_TERMCHAR'>, <class 'pyvisa.attributes.AttrVI_ATTR_TERMCHAR_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_TMO_VALUE'>, <class 'pyvisa.attributes.AttrVI_ATTR_TRIG_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_USER_DATA'>, <class 'pyvisa.attributes.AttrVI_ATTR_WR_BUF_OPER_MODE'>, <class 'pyvisa.attributes.AttrVI_ATTR_WR_BUF_SIZE'>}

VISA attribute descriptor classes that can be used to introspect the supported attributes and the possible values. The “often used” ones are generally directly available on the resource.

visalib: VisaLibraryBase

Will be present when used as a mixin with Resource

wait_on_event(in_event_type: EventType, timeout: int, capture_timeout: bool = False) WaitResponse

Waits for an occurrence of the specified event in this resource.

in_event_typeconstants.EventType

Logical identifier of the event(s) to wait for.

timeoutint

Absolute time period in time units that the resource shall wait for a specified event to occur before returning the time elapsed error. The time unit is in milliseconds. None means waiting forever if necessary.

capture_timeoutbool, optional

When True will not produce a VisaIOError(VI_ERROR_TMO) but instead return a WaitResponse with timed_out=True.

Returns:

Object that contains event_type, context and ret value.

Return type:

WaitResponse

wrap_handler(callable: Callable[[Resource, Event, Any], None]) Callable[[VISASession, EventType, VISAEventContext, Any], None]

Wrap an event handler to provide the signature expected by VISA.

The handler is expected to have the following signature: handler(resource: Resource, event: Event, user_handle: Any) -> None.

The wrapped handler should be used only to handle events on the resource used to wrap the handler.

write(message: str, termination: str | None = None, encoding: str | None = None) int

Write a string message to the device.

The write_termination is always appended to it.

Parameters:
  • message (str) – The message to be sent.

  • termination (Optional[str], optional) – Alternative character termination to use. If None, the value of write_termination is used. Defaults to None.

  • encoding (Optional[str], optional) – Alternative encoding to use to turn str into bytes. If None, the value of encoding is used. Defaults to None.

Returns:

Number of bytes written.

Return type:

int

write_ascii_values(message: str, values: Sequence[Any], converter: Literal['s', 'b', 'c', 'd', 'o', 'x', 'X', 'e', 'E', 'f', 'F', 'g', 'G'] | Callable[[str], Any] = 'f', separator: str | Callable[[Iterable[str]], str] = ',', termination: str | None = None, encoding: str | None = None)

Write a string message to the device followed by values in ascii format.

The write_termination is always appended to it.

Parameters:
  • message (str) – Header of the message to be sent.

  • values (Sequence[Any]) – Data to be writen to the device.

  • converter (Union[str, Callable[[Any], str]], optional) – Str formatting codes or function used to convert each value. Defaults to “f”.

  • separator (Union[str, Callable[[Iterable[str]], str]], optional) – Str or callable that join the values in a single str. If a str is given, separator.join(values) is used. Defaults to ‘,’

  • termination (Optional[str], optional) – Alternative character termination to use. If None, the value of write_termination is used. Defaults to None.

  • encoding (Optional[str], optional) – Alternative encoding to use to turn str into bytes. If None, the value of encoding is used. Defaults to None.

Returns:

Number of bytes written.

Return type:

int

write_binary_values(message: str, values: Sequence[Any], datatype: Literal['s', 'b', 'B', 'h', 'H', 'i', 'I', 'l', 'L', 'q', 'Q', 'f', 'd'] = 'f', is_big_endian: bool = False, termination: str | None = None, encoding: str | None = None, header_fmt: Literal['ieee', 'hp', 'empty'] = 'ieee')

Write a string message to the device followed by values in binary format.

The write_termination is always appended to it.

Parameters:
  • message (str) – The header of the message to be sent.

  • values (Sequence[Any]) – Data to be written to the device.

  • datatype (util.BINARY_DATATYPES, optional) – The format string for a single element. See struct module.

  • is_big_endian (bool, optional) – Are the data in big or little endian order.

  • termination (Optional[str], optional) – Alternative character termination to use. If None, the value of write_termination is used. Defaults to None.

  • encoding (Optional[str], optional) – Alternative encoding to use to turn str into bytes. If None, the value of encoding is used. Defaults to None.

  • header_fmt (util.BINARY_HEADERS) – Format of the header prefixing the data.

Returns:

Number of bytes written.

Return type:

int

write_raw(message: bytes) int

Write a byte message to the device.

Parameters:

message (bytes) – The message to be sent.

Returns:

Number of bytes written

Return type:

int

property write_termination: str

Write termination character.

class pyvisa.resources.TCPIPSocket(resource_manager: ResourceManager, resource_name: str)[source]

Communicates with to devices of type TCPIP::host address::port::SOCKET

More complex resource names can be specified with the following grammar:

TCPIP[board]::host address::port::SOCKET

Do not instantiate directly, use pyvisa.highlevel.ResourceManager.open_resource().

CR: str = '\r'
LF: str = '\n'
allow_dma: Attribute[bool]

Should I/O accesses use DMA (True) or Programmed I/O (False).

assert_trigger() None

Sends a software trigger to the device.

before_close() None

Called just before closing an instrument.

chunk_size: int = 20480

Number of bytes to read at a time. Some resources (serial) may not support large chunk sizes.

clear() None

Clear this resource.

close() None

Closes the VISA session and marks the handle as invalid.

disable_event(event_type: EventType, mechanism: EventMechanism) None

Disable notification for an event type(s) via the specified mechanism(s).

Parameters:
  • event_type (constants.EventType) – Logical event identifier.

  • mechanism (constants.EventMechanism) – Specifies event handling mechanisms to be disabled.

discard_events(event_type: EventType, mechanism: EventMechanism) None

Discards event occurrences for an event type and mechanism in this resource.

Parameters:
  • event_type (constants.EventType) – Logical event identifier.

  • mechanism (constants.EventMechanism) – Specifies event handling mechanisms to be disabled.

enable_event(event_type: EventType, mechanism: EventMechanism, context: None = None) None

Enable event occurrences for specified event types and mechanisms in this resource.

Parameters:
  • event_type (constants.EventType) – Logical event identifier.

  • mechanism (constants.EventMechanism) – Specifies event handling mechanisms to be enabled

  • context (None) – Not currently used, leave as None.

property encoding: str

Encoding used for read and write operations.

flush(mask: BufferOperation) None

Manually clears the specified buffers.

Depending on the value of the mask this can cause the buffer data to be written to the device.

Parameters:

mask (constants.BufferOperation) – Specifies the action to be taken with flushing the buffer. See highlevel.VisaLibraryBase.flush for a detailed description.

get_visa_attribute(name: ResourceAttribute) Any

Retrieves the state of an attribute in this resource.

One should prefer the dedicated descriptor for often used attributes since those perform checks and automatic conversion on the value.

Parameters:

name (constants.ResourceAttribute) – Resource attribute for which the state query is made.

Returns:

The state of the queried attribute for a specified resource.

Return type:

Any

ignore_warning(*warnings_constants: StatusCode) ContextManager

Ignoring warnings context manager for the current resource.

Parameters:

warnings_constants (constants.StatusCode) – Constants identifying the warnings to ignore.

implementation_version: Attribute[int]

Resource version that identifies the revisions or implementations of a resource.

install_handler(event_type: EventType, handler: Callable[[VISASession, EventType, VISAEventContext, Any], None], user_handle=None) Any

Install handlers for event callbacks in this resource.

Parameters:
  • event_type (constants.EventType) – Logical event identifier.

  • handler (VISAHandler) – Handler function to be installed by a client application.

  • user_handle – A value specified by an application that can be used for identifying handlers uniquely for an event type. Depending on the backend they may be restriction on the possible values. Look at the backend install_visa_handler for more details.

Returns:

User handle in a format amenable to the backend. This is this representation of the handle that should be used when unistalling a handler.

Return type:

Any

interface_number: Attribute[int]

Board number for the given interface.

interface_type: Attribute[constants.InterfaceType]

Interface type of the given session.

io_protocol: Attribute[constants.IOProtocol]

IO protocol to use. See the attribute definition for more details.

property last_status: StatusCode

Last status code for this session.

lock(timeout: float | Literal['default'] = 'default', requested_key: str | None = None) str

Establish a shared lock to the resource.

Parameters:
  • timeout (Union[float, Literal["default"]], optional) – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. Defaults to “default” which means use self.timeout.

  • requested_key (Optional[str], optional) – Access key used by another session with which you want your session to share a lock or None to generate a new shared access key.

Returns:

A new shared access key if requested_key is None, otherwise, same value as the requested_key

Return type:

str

lock_context(timeout: float | Literal['default'] = 'default', requested_key: str | None = 'exclusive') Iterator[str | None]

A context that locks

Parameters:
  • timeout (Union[float, Literal["default"]], optional) – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. Defaults to “default” which means use self.timeout.

  • requested_key (Optional[str], optional) – When using default of ‘exclusive’ the lock is an exclusive lock. Otherwise it is the access key for the shared lock or None to generate a new shared access key.

Yields:

Optional[str] – The access_key if applicable.

lock_excl(timeout: float | Literal['default'] = 'default') None

Establish an exclusive lock to the resource.

Parameters:

timeout (Union[float, Literal["default"]], optional) – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. Defaults to “default” which means use self.timeout.

lock_state: Attribute[constants.AccessModes]

Current locking state of the resource.

open(access_mode: AccessModes = AccessModes.no_lock, open_timeout: int = 5000) None

Opens a session to the specified resource.

Parameters:
  • access_mode (constants.AccessModes, optional) – Specifies the mode by which the resource is to be accessed. Defaults to constants.AccessModes.no_lock.

  • open_timeout (int, optional) – If the access_mode parameter requests a lock, then this parameter specifies the absolute time period (in milliseconds) that the resource waits to get unlocked before this operation returns an error. Defaults to 5000.

query(message: str, delay: float | None = None) str

A combination of write(message) and read()

Parameters:
  • message (str) – The message to send.

  • delay (Optional[float], optional) – Delay in seconds between write and read operations. If None, defaults to self.query_delay.

Returns:

Answer from the device.

Return type:

str

query_ascii_values(message: str, converter: ~typing.Literal['s', 'b', 'c', 'd', 'o', 'x', 'X', 'e', 'E', 'f', 'F', 'g', 'G'] | ~typing.Callable[[str], ~typing.Any] = 'f', separator: str | ~typing.Callable[[str], ~typing.Iterable[str]] = ',', container: ~typing.Type | ~typing.Callable[[~typing.Iterable], ~typing.Sequence] = <class 'list'>, delay: float | None = None) Sequence[Any]

Query the device for values in ascii format returning an iterable of values.

Parameters:
  • message (str) – The message to send.

  • converter (ASCII_CONVERTER, optional) – Str format of function to convert each value. Default to “f”.

  • separator (Union[str, Callable[[str], Iterable[str]]]) – str or callable used to split the data into individual elements. If a str is given, data.split(separator) is used. Default to “,”.

  • container (Union[Type, Callable[[Iterable], Sequence]], optional) – Container type to use for the output data. Possible values are: list, tuple, np.ndarray, etc, Default to list.

  • delay (Optional[float], optional) – Delay in seconds between write and read operations. If None, defaults to self.query_delay.

Returns:

Parsed data.

Return type:

Sequence

query_binary_values(message: str, datatype: ~typing.Literal['s', 'b', 'B', 'h', 'H', 'i', 'I', 'l', 'L', 'q', 'Q', 'f', 'd'] = 'f', is_big_endian: bool = False, container: ~typing.Type | ~typing.Callable[[~typing.Iterable], ~typing.Sequence] = <class 'list'>, delay: float | None = None, header_fmt: ~typing.Literal['ieee', 'hp', 'empty'] = 'ieee', expect_termination: bool = True, data_points: int = 0, chunk_size: int | None = None) Sequence[int | float]

Query the device for values in binary format returning an iterable of values.

Parameters:
  • message (str) – The message to send.

  • datatype (BINARY_DATATYPES, optional) – Format string for a single element. See struct module. ‘f’ by default.

  • is_big_endian (bool, optional) – Are the data in big or little endian order. Defaults to False.

  • container (Union[Type, Callable[[Iterable], Sequence]], optional) – Container type to use for the output data. Possible values are: list, tuple, np.ndarray, etc, Default to list.

  • delay (Optional[float], optional) – Delay in seconds between write and read operations. If None, defaults to self.query_delay.

  • header_fmt (util.BINARY_HEADERS, optional) – Format of the header prefixing the data. Defaults to ‘ieee’.

  • expect_termination (bool, optional) – When set to False, the expected length of the binary values block does not account for the final termination character (the read termination). Defaults to True.

  • data_points (int, optional) – Number of points expected in the block. This is used only if the instrument does not report it itself. This will be converted in a number of bytes based on the datatype. Defaults to 0.

  • chunk_size (int, optional) – Size of the chunks to read from the device. Using larger chunks may be faster for large amount of data.

Returns:

Data read from the device.

Return type:

Sequence[Union[int, float]]

query_delay: float = 0.0

Delay in s to sleep between the write and read occuring in a query

read(termination: str | None = None, encoding: str | None = None) str

Read a string from the device.

Reading stops when the device stops sending (e.g. by setting appropriate bus lines), or the termination characters sequence was detected. Attention: Only the last character of the termination characters is really used to stop reading, however, the whole sequence is compared to the ending of the read string message. If they don’t match, a warning is issued.

Parameters:
  • termination (Optional[str], optional) – Alternative character termination to use. If None, the value of read_termination is used. Defaults to None.

  • encoding (Optional[str], optional) – Alternative encoding to use to turn bytes into str. If None, the value of encoding is used. Defaults to None.

Returns:

Message read from the instrument and decoded.

Return type:

str

read_ascii_values(converter: ~typing.Literal['s', 'b', 'c', 'd', 'o', 'x', 'X', 'e', 'E', 'f', 'F', 'g', 'G'] | ~typing.Callable[[str], ~typing.Any] = 'f', separator: str | ~typing.Callable[[str], ~typing.Iterable[str]] = ',', container: ~typing.Type | ~typing.Callable[[~typing.Iterable], ~typing.Sequence] = <class 'list'>) Sequence

Read values from the device in ascii format returning an iterable of values.

Parameters:

converter (ASCII_CONVERTER, optional) – Str format of function to convert each value. Default to “f”.

separatorUnion[str, Callable[[str], Iterable[str]]]

str or callable used to split the data into individual elements. If a str is given, data.split(separator) is used. Default to “,”.

containerUnion[Type, Callable[[Iterable], Sequence]], optional

Container type to use for the output data. Possible values are: list, tuple, np.ndarray, etc, Default to list.

Returns:

Parsed data.

Return type:

Sequence

read_binary_values(datatype: ~typing.Literal['s', 'b', 'B', 'h', 'H', 'i', 'I', 'l', 'L', 'q', 'Q', 'f', 'd'] = 'f', is_big_endian: bool = False, container: ~typing.Type | ~typing.Callable[[~typing.Iterable], ~typing.Sequence] = <class 'list'>, header_fmt: ~typing.Literal['ieee', 'hp', 'empty'] = 'ieee', expect_termination: bool = True, data_points: int = -1, chunk_size: int | None = None) Sequence[int | float]

Read values from the device in binary format returning an iterable of values.

Parameters:
  • datatype (BINARY_DATATYPES, optional) – Format string for a single element. See struct module. ‘f’ by default.

  • is_big_endian (bool, optional) – Are the data in big or little endian order. Defaults to False.

  • container (Union[Type, Callable[[Iterable], Sequence]], optional) – Container type to use for the output data. Possible values are: list, tuple, np.ndarray, etc, Default to list.

  • header_fmt (util.BINARY_HEADERS, optional) – Format of the header prefixing the data. Defaults to ‘ieee’.

  • expect_termination (bool, optional) – When set to False, the expected length of the binary values block does not account for the final termination character (the read termination). Defaults to True.

  • data_points (int, optional) – Number of points expected in the block. This is used only if the instrument does not report it itself. This will be converted in a number of bytes based on the datatype. Defaults to 0.

  • chunk_size (int, optional) – Size of the chunks to read from the device. Using larger chunks may be faster for large amount of data.

Returns:

Data read from the device.

Return type:

Sequence[Union[int, float]]

read_bytes(count: int, chunk_size: int | None = None, break_on_termchar: bool = False) bytes

Read a certain number of bytes from the instrument.

Parameters:
  • count (int) – The number of bytes to read from the instrument.

  • chunk_size (Optional[int], optional) – The chunk size to use to perform the reading. If count > chunk_size multiple low level operations will be performed. Defaults to None, meaning the resource wide set value is set.

  • break_on_termchar (bool, optional) – Should the reading stop when a termination character is encountered or when the message ends. Defaults to False.

Returns:

Bytes read from the instrument.

Return type:

bytes

read_raw(size: int | None = None) bytes

Read the unmodified string sent from the instrument to the computer.

In contrast to read(), no termination characters are stripped.

Parameters:

size (Optional[int], optional) – The chunk size to use to perform the reading. Defaults to None, meaning the resource wide set value is set.

Returns:

Bytes read from the instrument.

Return type:

bytes

read_stb() int

Service request status register.

property read_termination: str | None

Read termination character.

read_termination_context(new_termination: str) Iterator
classmethod register(interface_type: InterfaceType, resource_class: str) Callable[[Type[T]], Type[T]]

Create a decorator to register a class.

The class is associated to an interface type, resource class pair.

Parameters:
  • interface_type (constants.InterfaceType) – Interface type for which to register a wrapper class.

  • resource_class (str) – Resource class for which to register a wrapper class.

Returns:

Decorator registering the class. Raises TypeError if some VISA attributes are missing on the registered class.

Return type:

Callable[[Type[T]], Type[T]]

resource_class: Attribute[str]

Resource class (for example, “INSTR”) as defined by the canonical resource name.

property resource_info: ResourceInfo

Get the extended information of this resource.

resource_manager: highlevel.ResourceManager

Reference to the resource manager used by this resource

resource_manufacturer_name: Attribute[str]

Manufacturer name of the vendor that implemented the VISA library.

resource_name: Attribute[str]

Unique identifier for a resource compliant with the address structure.

send_end: Attribute[bool]

Should END be asserted during the transfer of the last byte of the buffer.

property session: VISASession

Resource session handle.

Raises:

errors.InvalidSession – Raised if session is closed.

set_visa_attribute(name: ResourceAttribute, state: Any) StatusCode

Set the state of an attribute.

One should prefer the dedicated descriptor for often used attributes since those perform checks and automatic conversion on the value.

Parameters:
  • name (constants.ResourceAttribute) – Attribute for which the state is to be modified.

  • state (Any) – The state of the attribute to be set for the specified object.

Returns:

Return value of the library call.

Return type:

constants.StatusCode

spec_version: Attribute[int]

Version of the VISA specification to which the implementation is compliant.

property stb: int

Service request status register.

timeout: Attribute[float]

Timeout in milliseconds for all resource I/O operations.

uninstall_handler(event_type: EventType, handler: Callable[[VISASession, EventType, VISAEventContext, Any], None], user_handle=None) None

Uninstalls handlers for events in this resource.

Parameters:
  • event_type (constants.EventType) – Logical event identifier.

  • handler (VISAHandler) – Handler function to be uninstalled by a client application.

  • user_handle (Any) – The user handle returned by install_handler.

unlock() None

Relinquishes a lock for the specified resource.

visa_attributes_classes: ClassVar[Set[Type[attributes.Attribute]]] = {<class 'pyvisa.attributes.AttrVI_ATTR_DMA_ALLOW_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_FILE_APPEND_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_INST_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_TYPE'>, <class 'pyvisa.attributes.AttrVI_ATTR_IO_PROT'>, <class 'pyvisa.attributes.AttrVI_ATTR_MAX_QUEUE_LENGTH'>, <class 'pyvisa.attributes.AttrVI_ATTR_RD_BUF_OPER_MODE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RD_BUF_SIZE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RM_SESSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_CLASS'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_IMPL_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_LOCK_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_SPEC_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_SEND_END_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_SUPPRESS_END_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_TCPIP_ADDR'>, <class 'pyvisa.attributes.AttrVI_ATTR_TCPIP_HOSTNAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_TCPIP_KEEPALIVE'>, <class 'pyvisa.attributes.AttrVI_ATTR_TCPIP_NODELAY'>, <class 'pyvisa.attributes.AttrVI_ATTR_TCPIP_PORT'>, <class 'pyvisa.attributes.AttrVI_ATTR_TERMCHAR'>, <class 'pyvisa.attributes.AttrVI_ATTR_TERMCHAR_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_TMO_VALUE'>, <class 'pyvisa.attributes.AttrVI_ATTR_USER_DATA'>, <class 'pyvisa.attributes.AttrVI_ATTR_WR_BUF_OPER_MODE'>, <class 'pyvisa.attributes.AttrVI_ATTR_WR_BUF_SIZE'>}

VISA attribute descriptor classes that can be used to introspect the supported attributes and the possible values. The “often used” ones are generally directly available on the resource.

visalib: highlevel.VisaLibraryBase

Reference to the VISA library instance used by the resource

wait_on_event(in_event_type: EventType, timeout: int, capture_timeout: bool = False) WaitResponse

Waits for an occurrence of the specified event in this resource.

in_event_typeconstants.EventType

Logical identifier of the event(s) to wait for.

timeoutint

Absolute time period in time units that the resource shall wait for a specified event to occur before returning the time elapsed error. The time unit is in milliseconds. None means waiting forever if necessary.

capture_timeoutbool, optional

When True will not produce a VisaIOError(VI_ERROR_TMO) but instead return a WaitResponse with timed_out=True.

Returns:

Object that contains event_type, context and ret value.

Return type:

WaitResponse

wrap_handler(callable: Callable[[Resource, Event, Any], None]) Callable[[VISASession, EventType, VISAEventContext, Any], None]

Wrap an event handler to provide the signature expected by VISA.

The handler is expected to have the following signature: handler(resource: Resource, event: Event, user_handle: Any) -> None.

The wrapped handler should be used only to handle events on the resource used to wrap the handler.

write(message: str, termination: str | None = None, encoding: str | None = None) int

Write a string message to the device.

The write_termination is always appended to it.

Parameters:
  • message (str) – The message to be sent.

  • termination (Optional[str], optional) – Alternative character termination to use. If None, the value of write_termination is used. Defaults to None.

  • encoding (Optional[str], optional) – Alternative encoding to use to turn str into bytes. If None, the value of encoding is used. Defaults to None.

Returns:

Number of bytes written.

Return type:

int

write_ascii_values(message: str, values: Sequence[Any], converter: Literal['s', 'b', 'c', 'd', 'o', 'x', 'X', 'e', 'E', 'f', 'F', 'g', 'G'] | Callable[[str], Any] = 'f', separator: str | Callable[[Iterable[str]], str] = ',', termination: str | None = None, encoding: str | None = None)

Write a string message to the device followed by values in ascii format.

The write_termination is always appended to it.

Parameters:
  • message (str) – Header of the message to be sent.

  • values (Sequence[Any]) – Data to be writen to the device.

  • converter (Union[str, Callable[[Any], str]], optional) – Str formatting codes or function used to convert each value. Defaults to “f”.

  • separator (Union[str, Callable[[Iterable[str]], str]], optional) – Str or callable that join the values in a single str. If a str is given, separator.join(values) is used. Defaults to ‘,’

  • termination (Optional[str], optional) – Alternative character termination to use. If None, the value of write_termination is used. Defaults to None.

  • encoding (Optional[str], optional) – Alternative encoding to use to turn str into bytes. If None, the value of encoding is used. Defaults to None.

Returns:

Number of bytes written.

Return type:

int

write_binary_values(message: str, values: Sequence[Any], datatype: Literal['s', 'b', 'B', 'h', 'H', 'i', 'I', 'l', 'L', 'q', 'Q', 'f', 'd'] = 'f', is_big_endian: bool = False, termination: str | None = None, encoding: str | None = None, header_fmt: Literal['ieee', 'hp', 'empty'] = 'ieee')

Write a string message to the device followed by values in binary format.

The write_termination is always appended to it.

Parameters:
  • message (str) – The header of the message to be sent.

  • values (Sequence[Any]) – Data to be written to the device.

  • datatype (util.BINARY_DATATYPES, optional) – The format string for a single element. See struct module.

  • is_big_endian (bool, optional) – Are the data in big or little endian order.

  • termination (Optional[str], optional) – Alternative character termination to use. If None, the value of write_termination is used. Defaults to None.

  • encoding (Optional[str], optional) – Alternative encoding to use to turn str into bytes. If None, the value of encoding is used. Defaults to None.

  • header_fmt (util.BINARY_HEADERS) – Format of the header prefixing the data.

Returns:

Number of bytes written.

Return type:

int

write_raw(message: bytes) int

Write a byte message to the device.

Parameters:

message (bytes) – The message to be sent.

Returns:

Number of bytes written

Return type:

int

property write_termination: str

Write termination character.

class pyvisa.resources.USBInstrument(resource_manager: ResourceManager, resource_name: str)[source]

USB INSTR resources USB::manufacturer ID::model code::serial number

More complex resource names can be specified with the following grammar:

USB[board]::manufacturer ID::model code::serial number[::USB interface number][::INSTR]

Do not instantiate directly, use pyvisa.highlevel.ResourceManager.open_resource().

CR: str = '\r'
LF: str = '\n'
allow_dma: Attribute[bool]

Should I/O accesses use DMA (True) or Programmed I/O (False).

assert_trigger() None

Sends a software trigger to the device.

before_close() None

Called just before closing an instrument.

chunk_size: int = 20480

Number of bytes to read at a time. Some resources (serial) may not support large chunk sizes.

clear() None

Clear this resource.

close() None

Closes the VISA session and marks the handle as invalid.

control_in(request_type_bitmap_field: int, request_id: int, request_value: int, index: int, length: int = 0) bytes[source]

Performs a USB control pipe transfer from the device.

Parameters:
  • request_type_bitmap_field (int) – bmRequestType parameter of the setup stage of a USB control transfer.

  • request_id (int) – bRequest parameter of the setup stage of a USB control transfer.

  • request_value (int) – wValue parameter of the setup stage of a USB control transfer.

  • index (int) – wIndex parameter of the setup stage of a USB control transfer. This is usually the index of the interface or endpoint.

  • length (int) – wLength parameter of the setup stage of a USB control transfer. This value also specifies the size of the data buffer to receive the data from the optional data stage of the control transfer.

Returns:

The data buffer that receives the data from the optional data stage of the control transfer.

Return type:

bytes

control_out(request_type_bitmap_field: int, request_id: int, request_value: int, index: int, data: bytes = b'')[source]

Performs a USB control pipe transfer to the device.

Parameters:
  • request_type_bitmap_field (int) – bmRequestType parameter of the setup stage of a USB control transfer.

  • request_id (int) – bRequest parameter of the setup stage of a USB control transfer.

  • request_value (int) – wValue parameter of the setup stage of a USB control transfer.

  • index (int) – wIndex parameter of the setup stage of a USB control transfer. This is usually the index of the interface or endpoint.

  • data (bytes) – The data buffer that sends the data in the optional data stage of the control transfer.

control_ren(mode: RENLineOperation) StatusCode

Controls the state of the GPIB Remote Enable (REN) interface line.

The remote/local state of the device can also be controlled optionally.

Corresponds to viGpibControlREN function of the VISA library.

Parameters:

mode (constants.RENLineOperation) – Specifies the state of the REN line and optionally the device remote/local state.

Returns:

Return value of the library call.

Return type:

constants.StatusCode

disable_event(event_type: EventType, mechanism: EventMechanism) None

Disable notification for an event type(s) via the specified mechanism(s).

Parameters:
  • event_type (constants.EventType) – Logical event identifier.

  • mechanism (constants.EventMechanism) – Specifies event handling mechanisms to be disabled.

discard_events(event_type: EventType, mechanism: EventMechanism) None

Discards event occurrences for an event type and mechanism in this resource.

Parameters:
  • event_type (constants.EventType) – Logical event identifier.

  • mechanism (constants.EventMechanism) – Specifies event handling mechanisms to be disabled.

enable_event(event_type: EventType, mechanism: EventMechanism, context: None = None) None

Enable event occurrences for specified event types and mechanisms in this resource.

Parameters:
  • event_type (constants.EventType) – Logical event identifier.

  • mechanism (constants.EventMechanism) – Specifies event handling mechanisms to be enabled

  • context (None) – Not currently used, leave as None.

property encoding: str

Encoding used for read and write operations.

flush(mask: BufferOperation) None

Manually clears the specified buffers.

Depending on the value of the mask this can cause the buffer data to be written to the device.

Parameters:

mask (constants.BufferOperation) – Specifies the action to be taken with flushing the buffer. See highlevel.VisaLibraryBase.flush for a detailed description.

get_visa_attribute(name: ResourceAttribute) Any

Retrieves the state of an attribute in this resource.

One should prefer the dedicated descriptor for often used attributes since those perform checks and automatic conversion on the value.

Parameters:

name (constants.ResourceAttribute) – Resource attribute for which the state query is made.

Returns:

The state of the queried attribute for a specified resource.

Return type:

Any

ignore_warning(*warnings_constants: StatusCode) ContextManager

Ignoring warnings context manager for the current resource.

Parameters:

warnings_constants (constants.StatusCode) – Constants identifying the warnings to ignore.

implementation_version: Attribute[int]

Resource version that identifies the revisions or implementations of a resource.

install_handler(event_type: EventType, handler: Callable[[VISASession, EventType, VISAEventContext, Any], None], user_handle=None) Any

Install handlers for event callbacks in this resource.

Parameters:
  • event_type (constants.EventType) – Logical event identifier.

  • handler (VISAHandler) – Handler function to be installed by a client application.

  • user_handle – A value specified by an application that can be used for identifying handlers uniquely for an event type. Depending on the backend they may be restriction on the possible values. Look at the backend install_visa_handler for more details.

Returns:

User handle in a format amenable to the backend. This is this representation of the handle that should be used when unistalling a handler.

Return type:

Any

interface_number: Attribute[int]

USB interface number used by the given session.

interface_type: Attribute[constants.InterfaceType]

Interface type of the given session.

io_protocol: Attribute[constants.IOProtocol]

IO protocol to use. See the attribute definition for more details.

is_4882_compliant: Attribute[bool]

Whether the device is 488.2 compliant.

property last_status: StatusCode

Last status code for this session.

lock(timeout: float | Literal['default'] = 'default', requested_key: str | None = None) str

Establish a shared lock to the resource.

Parameters:
  • timeout (Union[float, Literal["default"]], optional) – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. Defaults to “default” which means use self.timeout.

  • requested_key (Optional[str], optional) – Access key used by another session with which you want your session to share a lock or None to generate a new shared access key.

Returns:

A new shared access key if requested_key is None, otherwise, same value as the requested_key

Return type:

str

lock_context(timeout: float | Literal['default'] = 'default', requested_key: str | None = 'exclusive') Iterator[str | None]

A context that locks

Parameters:
  • timeout (Union[float, Literal["default"]], optional) – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. Defaults to “default” which means use self.timeout.

  • requested_key (Optional[str], optional) – When using default of ‘exclusive’ the lock is an exclusive lock. Otherwise it is the access key for the shared lock or None to generate a new shared access key.

Yields:

Optional[str] – The access_key if applicable.

lock_excl(timeout: float | Literal['default'] = 'default') None

Establish an exclusive lock to the resource.

Parameters:

timeout (Union[float, Literal["default"]], optional) – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. Defaults to “default” which means use self.timeout.

lock_state: Attribute[constants.AccessModes]

Current locking state of the resource.

manufacturer_id: Attribute[int]

Manufacturer identification number of the device.

manufacturer_name: Attribute[str]

Manufacturer name.

maximum_interrupt_size: Attribute[int]

Maximum size of data that will be stored by any given USB interrupt.

model_code: Attribute[int]

Model code for the device.

model_name: Attribute[str]

Model name of the device.

open(access_mode: AccessModes = AccessModes.no_lock, open_timeout: int = 5000) None

Opens a session to the specified resource.

Parameters:
  • access_mode (constants.AccessModes, optional) – Specifies the mode by which the resource is to be accessed. Defaults to constants.AccessModes.no_lock.

  • open_timeout (int, optional) – If the access_mode parameter requests a lock, then this parameter specifies the absolute time period (in milliseconds) that the resource waits to get unlocked before this operation returns an error. Defaults to 5000.

query(message: str, delay: float | None = None) str

A combination of write(message) and read()

Parameters:
  • message (str) – The message to send.

  • delay (Optional[float], optional) – Delay in seconds between write and read operations. If None, defaults to self.query_delay.

Returns:

Answer from the device.

Return type:

str

query_ascii_values(message: str, converter: ~typing.Literal['s', 'b', 'c', 'd', 'o', 'x', 'X', 'e', 'E', 'f', 'F', 'g', 'G'] | ~typing.Callable[[str], ~typing.Any] = 'f', separator: str | ~typing.Callable[[str], ~typing.Iterable[str]] = ',', container: ~typing.Type | ~typing.Callable[[~typing.Iterable], ~typing.Sequence] = <class 'list'>, delay: float | None = None) Sequence[Any]

Query the device for values in ascii format returning an iterable of values.

Parameters:
  • message (str) – The message to send.

  • converter (ASCII_CONVERTER, optional) – Str format of function to convert each value. Default to “f”.

  • separator (Union[str, Callable[[str], Iterable[str]]]) – str or callable used to split the data into individual elements. If a str is given, data.split(separator) is used. Default to “,”.

  • container (Union[Type, Callable[[Iterable], Sequence]], optional) – Container type to use for the output data. Possible values are: list, tuple, np.ndarray, etc, Default to list.

  • delay (Optional[float], optional) – Delay in seconds between write and read operations. If None, defaults to self.query_delay.

Returns:

Parsed data.

Return type:

Sequence

query_binary_values(message: str, datatype: ~typing.Literal['s', 'b', 'B', 'h', 'H', 'i', 'I', 'l', 'L', 'q', 'Q', 'f', 'd'] = 'f', is_big_endian: bool = False, container: ~typing.Type | ~typing.Callable[[~typing.Iterable], ~typing.Sequence] = <class 'list'>, delay: float | None = None, header_fmt: ~typing.Literal['ieee', 'hp', 'empty'] = 'ieee', expect_termination: bool = True, data_points: int = 0, chunk_size: int | None = None) Sequence[int | float]

Query the device for values in binary format returning an iterable of values.

Parameters:
  • message (str) – The message to send.

  • datatype (BINARY_DATATYPES, optional) – Format string for a single element. See struct module. ‘f’ by default.

  • is_big_endian (bool, optional) – Are the data in big or little endian order. Defaults to False.

  • container (Union[Type, Callable[[Iterable], Sequence]], optional) – Container type to use for the output data. Possible values are: list, tuple, np.ndarray, etc, Default to list.

  • delay (Optional[float], optional) – Delay in seconds between write and read operations. If None, defaults to self.query_delay.

  • header_fmt (util.BINARY_HEADERS, optional) – Format of the header prefixing the data. Defaults to ‘ieee’.

  • expect_termination (bool, optional) – When set to False, the expected length of the binary values block does not account for the final termination character (the read termination). Defaults to True.

  • data_points (int, optional) – Number of points expected in the block. This is used only if the instrument does not report it itself. This will be converted in a number of bytes based on the datatype. Defaults to 0.

  • chunk_size (int, optional) – Size of the chunks to read from the device. Using larger chunks may be faster for large amount of data.

Returns:

Data read from the device.

Return type:

Sequence[Union[int, float]]

query_delay: float = 0.0

Delay in s to sleep between the write and read occuring in a query

read(termination: str | None = None, encoding: str | None = None) str

Read a string from the device.

Reading stops when the device stops sending (e.g. by setting appropriate bus lines), or the termination characters sequence was detected. Attention: Only the last character of the termination characters is really used to stop reading, however, the whole sequence is compared to the ending of the read string message. If they don’t match, a warning is issued.

Parameters:
  • termination (Optional[str], optional) – Alternative character termination to use. If None, the value of read_termination is used. Defaults to None.

  • encoding (Optional[str], optional) – Alternative encoding to use to turn bytes into str. If None, the value of encoding is used. Defaults to None.

Returns:

Message read from the instrument and decoded.

Return type:

str

read_ascii_values(converter: ~typing.Literal['s', 'b', 'c', 'd', 'o', 'x', 'X', 'e', 'E', 'f', 'F', 'g', 'G'] | ~typing.Callable[[str], ~typing.Any] = 'f', separator: str | ~typing.Callable[[str], ~typing.Iterable[str]] = ',', container: ~typing.Type | ~typing.Callable[[~typing.Iterable], ~typing.Sequence] = <class 'list'>) Sequence

Read values from the device in ascii format returning an iterable of values.

Parameters:

converter (ASCII_CONVERTER, optional) – Str format of function to convert each value. Default to “f”.

separatorUnion[str, Callable[[str], Iterable[str]]]

str or callable used to split the data into individual elements. If a str is given, data.split(separator) is used. Default to “,”.

containerUnion[Type, Callable[[Iterable], Sequence]], optional

Container type to use for the output data. Possible values are: list, tuple, np.ndarray, etc, Default to list.

Returns:

Parsed data.

Return type:

Sequence

read_binary_values(datatype: ~typing.Literal['s', 'b', 'B', 'h', 'H', 'i', 'I', 'l', 'L', 'q', 'Q', 'f', 'd'] = 'f', is_big_endian: bool = False, container: ~typing.Type | ~typing.Callable[[~typing.Iterable], ~typing.Sequence] = <class 'list'>, header_fmt: ~typing.Literal['ieee', 'hp', 'empty'] = 'ieee', expect_termination: bool = True, data_points: int = -1, chunk_size: int | None = None) Sequence[int | float]

Read values from the device in binary format returning an iterable of values.

Parameters:
  • datatype (BINARY_DATATYPES, optional) – Format string for a single element. See struct module. ‘f’ by default.

  • is_big_endian (bool, optional) – Are the data in big or little endian order. Defaults to False.

  • container (Union[Type, Callable[[Iterable], Sequence]], optional) – Container type to use for the output data. Possible values are: list, tuple, np.ndarray, etc, Default to list.

  • header_fmt (util.BINARY_HEADERS, optional) – Format of the header prefixing the data. Defaults to ‘ieee’.

  • expect_termination (bool, optional) – When set to False, the expected length of the binary values block does not account for the final termination character (the read termination). Defaults to True.

  • data_points (int, optional) – Number of points expected in the block. This is used only if the instrument does not report it itself. This will be converted in a number of bytes based on the datatype. Defaults to 0.

  • chunk_size (int, optional) – Size of the chunks to read from the device. Using larger chunks may be faster for large amount of data.

Returns:

Data read from the device.

Return type:

Sequence[Union[int, float]]

read_bytes(count: int, chunk_size: int | None = None, break_on_termchar: bool = False) bytes

Read a certain number of bytes from the instrument.

Parameters:
  • count (int) – The number of bytes to read from the instrument.

  • chunk_size (Optional[int], optional) – The chunk size to use to perform the reading. If count > chunk_size multiple low level operations will be performed. Defaults to None, meaning the resource wide set value is set.

  • break_on_termchar (bool, optional) – Should the reading stop when a termination character is encountered or when the message ends. Defaults to False.

Returns:

Bytes read from the instrument.

Return type:

bytes

read_raw(size: int | None = None) bytes

Read the unmodified string sent from the instrument to the computer.

In contrast to read(), no termination characters are stripped.

Parameters:

size (Optional[int], optional) – The chunk size to use to perform the reading. Defaults to None, meaning the resource wide set value is set.

Returns:

Bytes read from the instrument.

Return type:

bytes

read_stb() int

Service request status register.

property read_termination: str | None

Read termination character.

read_termination_context(new_termination: str) Iterator
classmethod register(interface_type: InterfaceType, resource_class: str) Callable[[Type[T]], Type[T]]

Create a decorator to register a class.

The class is associated to an interface type, resource class pair.

Parameters:
  • interface_type (constants.InterfaceType) – Interface type for which to register a wrapper class.

  • resource_class (str) – Resource class for which to register a wrapper class.

Returns:

Decorator registering the class. Raises TypeError if some VISA attributes are missing on the registered class.

Return type:

Callable[[Type[T]], Type[T]]

resource_class: Attribute[str]

Resource class (for example, “INSTR”) as defined by the canonical resource name.

property resource_info: ResourceInfo

Get the extended information of this resource.

resource_manager: highlevel.ResourceManager

Reference to the resource manager used by this resource

resource_manufacturer_name: Attribute[str]

Manufacturer name of the vendor that implemented the VISA library.

resource_name: Attribute[str]

Unique identifier for a resource compliant with the address structure.

send_end: Attribute[bool]

Should END be asserted during the transfer of the last byte of the buffer.

serial_number: Attribute[str]

USB serial number of this device.

property session: VISASession

Resource session handle.

Raises:

errors.InvalidSession – Raised if session is closed.

set_visa_attribute(name: ResourceAttribute, state: Any) StatusCode

Set the state of an attribute.

One should prefer the dedicated descriptor for often used attributes since those perform checks and automatic conversion on the value.

Parameters:
  • name (constants.ResourceAttribute) – Attribute for which the state is to be modified.

  • state (Any) – The state of the attribute to be set for the specified object.

Returns:

Return value of the library call.

Return type:

constants.StatusCode

spec_version: Attribute[int]

Version of the VISA specification to which the implementation is compliant.

property stb: int

Service request status register.

timeout: Attribute[float]

Timeout in milliseconds for all resource I/O operations.

uninstall_handler(event_type: EventType, handler: Callable[[VISASession, EventType, VISAEventContext, Any], None], user_handle=None) None

Uninstalls handlers for events in this resource.

Parameters:
  • event_type (constants.EventType) – Logical event identifier.

  • handler (VISAHandler) – Handler function to be uninstalled by a client application.

  • user_handle (Any) – The user handle returned by install_handler.

unlock() None

Relinquishes a lock for the specified resource.

usb_protocol: Attribute[int]

USB protocol used by this USB interface.

visa_attributes_classes: ClassVar[Set[Type[attributes.Attribute]]] = {<class 'pyvisa.attributes.AttrVI_ATTR_4882_COMPLIANT'>, <class 'pyvisa.attributes.AttrVI_ATTR_DMA_ALLOW_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_FILE_APPEND_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_INST_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_TYPE'>, <class 'pyvisa.attributes.AttrVI_ATTR_IO_PROT'>, <class 'pyvisa.attributes.AttrVI_ATTR_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_MAX_QUEUE_LENGTH'>, <class 'pyvisa.attributes.AttrVI_ATTR_MODEL_CODE'>, <class 'pyvisa.attributes.AttrVI_ATTR_MODEL_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RD_BUF_OPER_MODE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RD_BUF_SIZE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RM_SESSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_CLASS'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_IMPL_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_LOCK_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_SPEC_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_SEND_END_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_SUPPRESS_END_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_TERMCHAR'>, <class 'pyvisa.attributes.AttrVI_ATTR_TERMCHAR_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_TMO_VALUE'>, <class 'pyvisa.attributes.AttrVI_ATTR_USB_INTFC_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_USB_MAX_INTR_SIZE'>, <class 'pyvisa.attributes.AttrVI_ATTR_USB_PROTOCOL'>, <class 'pyvisa.attributes.AttrVI_ATTR_USB_SERIAL_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_USER_DATA'>, <class 'pyvisa.attributes.AttrVI_ATTR_WR_BUF_OPER_MODE'>, <class 'pyvisa.attributes.AttrVI_ATTR_WR_BUF_SIZE'>}

VISA attribute descriptor classes that can be used to introspect the supported attributes and the possible values. The “often used” ones are generally directly available on the resource.

visalib: VisaLibraryBase

Will be present when used as a mixin with Resource

wait_on_event(in_event_type: EventType, timeout: int, capture_timeout: bool = False) WaitResponse

Waits for an occurrence of the specified event in this resource.

in_event_typeconstants.EventType

Logical identifier of the event(s) to wait for.

timeoutint

Absolute time period in time units that the resource shall wait for a specified event to occur before returning the time elapsed error. The time unit is in milliseconds. None means waiting forever if necessary.

capture_timeoutbool, optional

When True will not produce a VisaIOError(VI_ERROR_TMO) but instead return a WaitResponse with timed_out=True.

Returns:

Object that contains event_type, context and ret value.

Return type:

WaitResponse

wrap_handler(callable: Callable[[Resource, Event, Any], None]) Callable[[VISASession, EventType, VISAEventContext, Any], None]

Wrap an event handler to provide the signature expected by VISA.

The handler is expected to have the following signature: handler(resource: Resource, event: Event, user_handle: Any) -> None.

The wrapped handler should be used only to handle events on the resource used to wrap the handler.

write(message: str, termination: str | None = None, encoding: str | None = None) int

Write a string message to the device.

The write_termination is always appended to it.

Parameters:
  • message (str) – The message to be sent.

  • termination (Optional[str], optional) – Alternative character termination to use. If None, the value of write_termination is used. Defaults to None.

  • encoding (Optional[str], optional) – Alternative encoding to use to turn str into bytes. If None, the value of encoding is used. Defaults to None.

Returns:

Number of bytes written.

Return type:

int

write_ascii_values(message: str, values: Sequence[Any], converter: Literal['s', 'b', 'c', 'd', 'o', 'x', 'X', 'e', 'E', 'f', 'F', 'g', 'G'] | Callable[[str], Any] = 'f', separator: str | Callable[[Iterable[str]], str] = ',', termination: str | None = None, encoding: str | None = None)

Write a string message to the device followed by values in ascii format.

The write_termination is always appended to it.

Parameters:
  • message (str) – Header of the message to be sent.

  • values (Sequence[Any]) – Data to be writen to the device.

  • converter (Union[str, Callable[[Any], str]], optional) – Str formatting codes or function used to convert each value. Defaults to “f”.

  • separator (Union[str, Callable[[Iterable[str]], str]], optional) – Str or callable that join the values in a single str. If a str is given, separator.join(values) is used. Defaults to ‘,’

  • termination (Optional[str], optional) – Alternative character termination to use. If None, the value of write_termination is used. Defaults to None.

  • encoding (Optional[str], optional) – Alternative encoding to use to turn str into bytes. If None, the value of encoding is used. Defaults to None.

Returns:

Number of bytes written.

Return type:

int

write_binary_values(message: str, values: Sequence[Any], datatype: Literal['s', 'b', 'B', 'h', 'H', 'i', 'I', 'l', 'L', 'q', 'Q', 'f', 'd'] = 'f', is_big_endian: bool = False, termination: str | None = None, encoding: str | None = None, header_fmt: Literal['ieee', 'hp', 'empty'] = 'ieee')

Write a string message to the device followed by values in binary format.

The write_termination is always appended to it.

Parameters:
  • message (str) – The header of the message to be sent.

  • values (Sequence[Any]) – Data to be written to the device.

  • datatype (util.BINARY_DATATYPES, optional) – The format string for a single element. See struct module.

  • is_big_endian (bool, optional) – Are the data in big or little endian order.

  • termination (Optional[str], optional) – Alternative character termination to use. If None, the value of write_termination is used. Defaults to None.

  • encoding (Optional[str], optional) – Alternative encoding to use to turn str into bytes. If None, the value of encoding is used. Defaults to None.

  • header_fmt (util.BINARY_HEADERS) – Format of the header prefixing the data.

Returns:

Number of bytes written.

Return type:

int

write_raw(message: bytes) int

Write a byte message to the device.

Parameters:

message (bytes) – The message to be sent.

Returns:

Number of bytes written

Return type:

int

property write_termination: str

Write termination character.

class pyvisa.resources.USBRaw(resource_manager: ResourceManager, resource_name: str)[source]

USB RAW resources: USB::manufacturer ID::model code::serial number::RAW

More complex resource names can be specified with the following grammar:

USB[board]::manufacturer ID::model code::serial number[::USB interface number]::RAW

Do not instantiate directly, use pyvisa.highlevel.ResourceManager.open_resource().

CR: str = '\r'
LF: str = '\n'
allow_dma: Attribute[bool]

Should I/O accesses use DMA (True) or Programmed I/O (False).

assert_trigger() None

Sends a software trigger to the device.

before_close() None

Called just before closing an instrument.

chunk_size: int = 20480

Number of bytes to read at a time. Some resources (serial) may not support large chunk sizes.

clear() None

Clear this resource.

close() None

Closes the VISA session and marks the handle as invalid.

disable_event(event_type: EventType, mechanism: EventMechanism) None

Disable notification for an event type(s) via the specified mechanism(s).

Parameters:
  • event_type (constants.EventType) – Logical event identifier.

  • mechanism (constants.EventMechanism) – Specifies event handling mechanisms to be disabled.

discard_events(event_type: EventType, mechanism: EventMechanism) None

Discards event occurrences for an event type and mechanism in this resource.

Parameters:
  • event_type (constants.EventType) – Logical event identifier.

  • mechanism (constants.EventMechanism) – Specifies event handling mechanisms to be disabled.

enable_event(event_type: EventType, mechanism: EventMechanism, context: None = None) None

Enable event occurrences for specified event types and mechanisms in this resource.

Parameters:
  • event_type (constants.EventType) – Logical event identifier.

  • mechanism (constants.EventMechanism) – Specifies event handling mechanisms to be enabled

  • context (None) – Not currently used, leave as None.

property encoding: str

Encoding used for read and write operations.

flush(mask: BufferOperation) None

Manually clears the specified buffers.

Depending on the value of the mask this can cause the buffer data to be written to the device.

Parameters:

mask (constants.BufferOperation) – Specifies the action to be taken with flushing the buffer. See highlevel.VisaLibraryBase.flush for a detailed description.

get_visa_attribute(name: ResourceAttribute) Any

Retrieves the state of an attribute in this resource.

One should prefer the dedicated descriptor for often used attributes since those perform checks and automatic conversion on the value.

Parameters:

name (constants.ResourceAttribute) – Resource attribute for which the state query is made.

Returns:

The state of the queried attribute for a specified resource.

Return type:

Any

ignore_warning(*warnings_constants: StatusCode) ContextManager

Ignoring warnings context manager for the current resource.

Parameters:

warnings_constants (constants.StatusCode) – Constants identifying the warnings to ignore.

implementation_version: Attribute[int]

Resource version that identifies the revisions or implementations of a resource.

install_handler(event_type: EventType, handler: Callable[[VISASession, EventType, VISAEventContext, Any], None], user_handle=None) Any

Install handlers for event callbacks in this resource.

Parameters:
  • event_type (constants.EventType) – Logical event identifier.

  • handler (VISAHandler) – Handler function to be installed by a client application.

  • user_handle – A value specified by an application that can be used for identifying handlers uniquely for an event type. Depending on the backend they may be restriction on the possible values. Look at the backend install_visa_handler for more details.

Returns:

User handle in a format amenable to the backend. This is this representation of the handle that should be used when unistalling a handler.

Return type:

Any

interface_number: Attribute[int]

USB interface number used by the given session.

interface_type: Attribute[constants.InterfaceType]

Interface type of the given session.

io_protocol: Attribute[constants.IOProtocol]

IO protocol to use. See the attribute definition for more details.

property last_status: StatusCode

Last status code for this session.

lock(timeout: float | Literal['default'] = 'default', requested_key: str | None = None) str

Establish a shared lock to the resource.

Parameters:
  • timeout (Union[float, Literal["default"]], optional) – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. Defaults to “default” which means use self.timeout.

  • requested_key (Optional[str], optional) – Access key used by another session with which you want your session to share a lock or None to generate a new shared access key.

Returns:

A new shared access key if requested_key is None, otherwise, same value as the requested_key

Return type:

str

lock_context(timeout: float | Literal['default'] = 'default', requested_key: str | None = 'exclusive') Iterator[str | None]

A context that locks

Parameters:
  • timeout (Union[float, Literal["default"]], optional) – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. Defaults to “default” which means use self.timeout.

  • requested_key (Optional[str], optional) – When using default of ‘exclusive’ the lock is an exclusive lock. Otherwise it is the access key for the shared lock or None to generate a new shared access key.

Yields:

Optional[str] – The access_key if applicable.

lock_excl(timeout: float | Literal['default'] = 'default') None

Establish an exclusive lock to the resource.

Parameters:

timeout (Union[float, Literal["default"]], optional) – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. Defaults to “default” which means use self.timeout.

lock_state: Attribute[constants.AccessModes]

Current locking state of the resource.

manufacturer_id: Attribute[int]

Manufacturer identification number of the device.

manufacturer_name: Attribute[str]

Manufacturer name.

maximum_interrupt_size: Attribute[int]

Maximum size of data that will be stored by any given USB interrupt.

model_code: Attribute[int]

Model code for the device.

model_name: Attribute[str]

Model name of the device.

open(access_mode: AccessModes = AccessModes.no_lock, open_timeout: int = 5000) None

Opens a session to the specified resource.

Parameters:
  • access_mode (constants.AccessModes, optional) – Specifies the mode by which the resource is to be accessed. Defaults to constants.AccessModes.no_lock.

  • open_timeout (int, optional) – If the access_mode parameter requests a lock, then this parameter specifies the absolute time period (in milliseconds) that the resource waits to get unlocked before this operation returns an error. Defaults to 5000.

query(message: str, delay: float | None = None) str

A combination of write(message) and read()

Parameters:
  • message (str) – The message to send.

  • delay (Optional[float], optional) – Delay in seconds between write and read operations. If None, defaults to self.query_delay.

Returns:

Answer from the device.

Return type:

str

query_ascii_values(message: str, converter: ~typing.Literal['s', 'b', 'c', 'd', 'o', 'x', 'X', 'e', 'E', 'f', 'F', 'g', 'G'] | ~typing.Callable[[str], ~typing.Any] = 'f', separator: str | ~typing.Callable[[str], ~typing.Iterable[str]] = ',', container: ~typing.Type | ~typing.Callable[[~typing.Iterable], ~typing.Sequence] = <class 'list'>, delay: float | None = None) Sequence[Any]

Query the device for values in ascii format returning an iterable of values.

Parameters:
  • message (str) – The message to send.

  • converter (ASCII_CONVERTER, optional) – Str format of function to convert each value. Default to “f”.

  • separator (Union[str, Callable[[str], Iterable[str]]]) – str or callable used to split the data into individual elements. If a str is given, data.split(separator) is used. Default to “,”.

  • container (Union[Type, Callable[[Iterable], Sequence]], optional) – Container type to use for the output data. Possible values are: list, tuple, np.ndarray, etc, Default to list.

  • delay (Optional[float], optional) – Delay in seconds between write and read operations. If None, defaults to self.query_delay.

Returns:

Parsed data.

Return type:

Sequence

query_binary_values(message: str, datatype: ~typing.Literal['s', 'b', 'B', 'h', 'H', 'i', 'I', 'l', 'L', 'q', 'Q', 'f', 'd'] = 'f', is_big_endian: bool = False, container: ~typing.Type | ~typing.Callable[[~typing.Iterable], ~typing.Sequence] = <class 'list'>, delay: float | None = None, header_fmt: ~typing.Literal['ieee', 'hp', 'empty'] = 'ieee', expect_termination: bool = True, data_points: int = 0, chunk_size: int | None = None) Sequence[int | float]

Query the device for values in binary format returning an iterable of values.

Parameters:
  • message (str) – The message to send.

  • datatype (BINARY_DATATYPES, optional) – Format string for a single element. See struct module. ‘f’ by default.

  • is_big_endian (bool, optional) – Are the data in big or little endian order. Defaults to False.

  • container (Union[Type, Callable[[Iterable], Sequence]], optional) – Container type to use for the output data. Possible values are: list, tuple, np.ndarray, etc, Default to list.

  • delay (Optional[float], optional) – Delay in seconds between write and read operations. If None, defaults to self.query_delay.

  • header_fmt (util.BINARY_HEADERS, optional) – Format of the header prefixing the data. Defaults to ‘ieee’.

  • expect_termination (bool, optional) – When set to False, the expected length of the binary values block does not account for the final termination character (the read termination). Defaults to True.

  • data_points (int, optional) – Number of points expected in the block. This is used only if the instrument does not report it itself. This will be converted in a number of bytes based on the datatype. Defaults to 0.

  • chunk_size (int, optional) – Size of the chunks to read from the device. Using larger chunks may be faster for large amount of data.

Returns:

Data read from the device.

Return type:

Sequence[Union[int, float]]

query_delay: float = 0.0

Delay in s to sleep between the write and read occuring in a query

read(termination: str | None = None, encoding: str | None = None) str

Read a string from the device.

Reading stops when the device stops sending (e.g. by setting appropriate bus lines), or the termination characters sequence was detected. Attention: Only the last character of the termination characters is really used to stop reading, however, the whole sequence is compared to the ending of the read string message. If they don’t match, a warning is issued.

Parameters:
  • termination (Optional[str], optional) – Alternative character termination to use. If None, the value of read_termination is used. Defaults to None.

  • encoding (Optional[str], optional) – Alternative encoding to use to turn bytes into str. If None, the value of encoding is used. Defaults to None.

Returns:

Message read from the instrument and decoded.

Return type:

str

read_ascii_values(converter: ~typing.Literal['s', 'b', 'c', 'd', 'o', 'x', 'X', 'e', 'E', 'f', 'F', 'g', 'G'] | ~typing.Callable[[str], ~typing.Any] = 'f', separator: str | ~typing.Callable[[str], ~typing.Iterable[str]] = ',', container: ~typing.Type | ~typing.Callable[[~typing.Iterable], ~typing.Sequence] = <class 'list'>) Sequence

Read values from the device in ascii format returning an iterable of values.

Parameters:

converter (ASCII_CONVERTER, optional) – Str format of function to convert each value. Default to “f”.

separatorUnion[str, Callable[[str], Iterable[str]]]

str or callable used to split the data into individual elements. If a str is given, data.split(separator) is used. Default to “,”.

containerUnion[Type, Callable[[Iterable], Sequence]], optional

Container type to use for the output data. Possible values are: list, tuple, np.ndarray, etc, Default to list.

Returns:

Parsed data.

Return type:

Sequence

read_binary_values(datatype: ~typing.Literal['s', 'b', 'B', 'h', 'H', 'i', 'I', 'l', 'L', 'q', 'Q', 'f', 'd'] = 'f', is_big_endian: bool = False, container: ~typing.Type | ~typing.Callable[[~typing.Iterable], ~typing.Sequence] = <class 'list'>, header_fmt: ~typing.Literal['ieee', 'hp', 'empty'] = 'ieee', expect_termination: bool = True, data_points: int = -1, chunk_size: int | None = None) Sequence[int | float]

Read values from the device in binary format returning an iterable of values.

Parameters:
  • datatype (BINARY_DATATYPES, optional) – Format string for a single element. See struct module. ‘f’ by default.

  • is_big_endian (bool, optional) – Are the data in big or little endian order. Defaults to False.

  • container (Union[Type, Callable[[Iterable], Sequence]], optional) – Container type to use for the output data. Possible values are: list, tuple, np.ndarray, etc, Default to list.

  • header_fmt (util.BINARY_HEADERS, optional) – Format of the header prefixing the data. Defaults to ‘ieee’.

  • expect_termination (bool, optional) – When set to False, the expected length of the binary values block does not account for the final termination character (the read termination). Defaults to True.

  • data_points (int, optional) – Number of points expected in the block. This is used only if the instrument does not report it itself. This will be converted in a number of bytes based on the datatype. Defaults to 0.

  • chunk_size (int, optional) – Size of the chunks to read from the device. Using larger chunks may be faster for large amount of data.

Returns:

Data read from the device.

Return type:

Sequence[Union[int, float]]

read_bytes(count: int, chunk_size: int | None = None, break_on_termchar: bool = False) bytes

Read a certain number of bytes from the instrument.

Parameters:
  • count (int) – The number of bytes to read from the instrument.

  • chunk_size (Optional[int], optional) – The chunk size to use to perform the reading. If count > chunk_size multiple low level operations will be performed. Defaults to None, meaning the resource wide set value is set.

  • break_on_termchar (bool, optional) – Should the reading stop when a termination character is encountered or when the message ends. Defaults to False.

Returns:

Bytes read from the instrument.

Return type:

bytes

read_raw(size: int | None = None) bytes

Read the unmodified string sent from the instrument to the computer.

In contrast to read(), no termination characters are stripped.

Parameters:

size (Optional[int], optional) – The chunk size to use to perform the reading. Defaults to None, meaning the resource wide set value is set.

Returns:

Bytes read from the instrument.

Return type:

bytes

read_stb() int

Service request status register.

property read_termination: str | None

Read termination character.

read_termination_context(new_termination: str) Iterator
classmethod register(interface_type: InterfaceType, resource_class: str) Callable[[Type[T]], Type[T]]

Create a decorator to register a class.

The class is associated to an interface type, resource class pair.

Parameters:
  • interface_type (constants.InterfaceType) – Interface type for which to register a wrapper class.

  • resource_class (str) – Resource class for which to register a wrapper class.

Returns:

Decorator registering the class. Raises TypeError if some VISA attributes are missing on the registered class.

Return type:

Callable[[Type[T]], Type[T]]

resource_class: Attribute[str]

Resource class (for example, “INSTR”) as defined by the canonical resource name.

property resource_info: ResourceInfo

Get the extended information of this resource.

resource_manager: highlevel.ResourceManager

Reference to the resource manager used by this resource

resource_manufacturer_name: Attribute[str]

Manufacturer name of the vendor that implemented the VISA library.

resource_name: Attribute[str]

Unique identifier for a resource compliant with the address structure.

send_end: Attribute[bool]

Should END be asserted during the transfer of the last byte of the buffer.

serial_number: Attribute[str]

USB serial number of this device.

property session: VISASession

Resource session handle.

Raises:

errors.InvalidSession – Raised if session is closed.

set_visa_attribute(name: ResourceAttribute, state: Any) StatusCode

Set the state of an attribute.

One should prefer the dedicated descriptor for often used attributes since those perform checks and automatic conversion on the value.

Parameters:
  • name (constants.ResourceAttribute) – Attribute for which the state is to be modified.

  • state (Any) – The state of the attribute to be set for the specified object.

Returns:

Return value of the library call.

Return type:

constants.StatusCode

spec_version: Attribute[int]

Version of the VISA specification to which the implementation is compliant.

property stb: int

Service request status register.

timeout: Attribute[float]

Timeout in milliseconds for all resource I/O operations.

uninstall_handler(event_type: EventType, handler: Callable[[VISASession, EventType, VISAEventContext, Any], None], user_handle=None) None

Uninstalls handlers for events in this resource.

Parameters:
  • event_type (constants.EventType) – Logical event identifier.

  • handler (VISAHandler) – Handler function to be uninstalled by a client application.

  • user_handle (Any) – The user handle returned by install_handler.

unlock() None

Relinquishes a lock for the specified resource.

usb_protocol: Attribute[int]

USB protocol used by this USB interface.

visa_attributes_classes: ClassVar[Set[Type[attributes.Attribute]]] = {<class 'pyvisa.attributes.AttrVI_ATTR_DMA_ALLOW_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_FILE_APPEND_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_INST_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_TYPE'>, <class 'pyvisa.attributes.AttrVI_ATTR_IO_PROT'>, <class 'pyvisa.attributes.AttrVI_ATTR_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_MAX_QUEUE_LENGTH'>, <class 'pyvisa.attributes.AttrVI_ATTR_MODEL_CODE'>, <class 'pyvisa.attributes.AttrVI_ATTR_MODEL_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RD_BUF_OPER_MODE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RD_BUF_SIZE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RM_SESSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_CLASS'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_IMPL_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_LOCK_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_SPEC_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_SEND_END_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_SUPPRESS_END_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_TERMCHAR'>, <class 'pyvisa.attributes.AttrVI_ATTR_TERMCHAR_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_TMO_VALUE'>, <class 'pyvisa.attributes.AttrVI_ATTR_USB_ALT_SETTING'>, <class 'pyvisa.attributes.AttrVI_ATTR_USB_BULK_IN_PIPE'>, <class 'pyvisa.attributes.AttrVI_ATTR_USB_BULK_IN_STATUS'>, <class 'pyvisa.attributes.AttrVI_ATTR_USB_BULK_OUT_PIPE'>, <class 'pyvisa.attributes.AttrVI_ATTR_USB_BULK_OUT_STATUS'>, <class 'pyvisa.attributes.AttrVI_ATTR_USB_CLASS'>, <class 'pyvisa.attributes.AttrVI_ATTR_USB_CTRL_PIPE'>, <class 'pyvisa.attributes.AttrVI_ATTR_USB_END_IN'>, <class 'pyvisa.attributes.AttrVI_ATTR_USB_INTFC_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_USB_INTR_IN_PIPE'>, <class 'pyvisa.attributes.AttrVI_ATTR_USB_INTR_IN_STATUS'>, <class 'pyvisa.attributes.AttrVI_ATTR_USB_MAX_INTR_SIZE'>, <class 'pyvisa.attributes.AttrVI_ATTR_USB_NUM_INTFCS'>, <class 'pyvisa.attributes.AttrVI_ATTR_USB_NUM_PIPES'>, <class 'pyvisa.attributes.AttrVI_ATTR_USB_PROTOCOL'>, <class 'pyvisa.attributes.AttrVI_ATTR_USB_SERIAL_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_USB_SUBCLASS'>, <class 'pyvisa.attributes.AttrVI_ATTR_USER_DATA'>, <class 'pyvisa.attributes.AttrVI_ATTR_WR_BUF_OPER_MODE'>, <class 'pyvisa.attributes.AttrVI_ATTR_WR_BUF_SIZE'>}

VISA attribute descriptor classes that can be used to introspect the supported attributes and the possible values. The “often used” ones are generally directly available on the resource.

visalib: highlevel.VisaLibraryBase

Reference to the VISA library instance used by the resource

wait_on_event(in_event_type: EventType, timeout: int, capture_timeout: bool = False) WaitResponse

Waits for an occurrence of the specified event in this resource.

in_event_typeconstants.EventType

Logical identifier of the event(s) to wait for.

timeoutint

Absolute time period in time units that the resource shall wait for a specified event to occur before returning the time elapsed error. The time unit is in milliseconds. None means waiting forever if necessary.

capture_timeoutbool, optional

When True will not produce a VisaIOError(VI_ERROR_TMO) but instead return a WaitResponse with timed_out=True.

Returns:

Object that contains event_type, context and ret value.

Return type:

WaitResponse

wrap_handler(callable: Callable[[Resource, Event, Any], None]) Callable[[VISASession, EventType, VISAEventContext, Any], None]

Wrap an event handler to provide the signature expected by VISA.

The handler is expected to have the following signature: handler(resource: Resource, event: Event, user_handle: Any) -> None.

The wrapped handler should be used only to handle events on the resource used to wrap the handler.

write(message: str, termination: str | None = None, encoding: str | None = None) int

Write a string message to the device.

The write_termination is always appended to it.

Parameters:
  • message (str) – The message to be sent.

  • termination (Optional[str], optional) – Alternative character termination to use. If None, the value of write_termination is used. Defaults to None.

  • encoding (Optional[str], optional) – Alternative encoding to use to turn str into bytes. If None, the value of encoding is used. Defaults to None.

Returns:

Number of bytes written.

Return type:

int

write_ascii_values(message: str, values: Sequence[Any], converter: Literal['s', 'b', 'c', 'd', 'o', 'x', 'X', 'e', 'E', 'f', 'F', 'g', 'G'] | Callable[[str], Any] = 'f', separator: str | Callable[[Iterable[str]], str] = ',', termination: str | None = None, encoding: str | None = None)

Write a string message to the device followed by values in ascii format.

The write_termination is always appended to it.

Parameters:
  • message (str) – Header of the message to be sent.

  • values (Sequence[Any]) – Data to be writen to the device.

  • converter (Union[str, Callable[[Any], str]], optional) – Str formatting codes or function used to convert each value. Defaults to “f”.

  • separator (Union[str, Callable[[Iterable[str]], str]], optional) – Str or callable that join the values in a single str. If a str is given, separator.join(values) is used. Defaults to ‘,’

  • termination (Optional[str], optional) – Alternative character termination to use. If None, the value of write_termination is used. Defaults to None.

  • encoding (Optional[str], optional) – Alternative encoding to use to turn str into bytes. If None, the value of encoding is used. Defaults to None.

Returns:

Number of bytes written.

Return type:

int

write_binary_values(message: str, values: Sequence[Any], datatype: Literal['s', 'b', 'B', 'h', 'H', 'i', 'I', 'l', 'L', 'q', 'Q', 'f', 'd'] = 'f', is_big_endian: bool = False, termination: str | None = None, encoding: str | None = None, header_fmt: Literal['ieee', 'hp', 'empty'] = 'ieee')

Write a string message to the device followed by values in binary format.

The write_termination is always appended to it.

Parameters:
  • message (str) – The header of the message to be sent.

  • values (Sequence[Any]) – Data to be written to the device.

  • datatype (util.BINARY_DATATYPES, optional) – The format string for a single element. See struct module.

  • is_big_endian (bool, optional) – Are the data in big or little endian order.

  • termination (Optional[str], optional) – Alternative character termination to use. If None, the value of write_termination is used. Defaults to None.

  • encoding (Optional[str], optional) – Alternative encoding to use to turn str into bytes. If None, the value of encoding is used. Defaults to None.

  • header_fmt (util.BINARY_HEADERS) – Format of the header prefixing the data.

Returns:

Number of bytes written.

Return type:

int

write_raw(message: bytes) int

Write a byte message to the device.

Parameters:

message (bytes) – The message to be sent.

Returns:

Number of bytes written

Return type:

int

property write_termination: str

Write termination character.

class pyvisa.resources.GPIBInstrument(resource_manager: ResourceManager, resource_name: str)[source]

Communicates with to devices of type GPIB::<primary address>[::INSTR]

More complex resource names can be specified with the following grammar:

GPIB[board]::primary address[::secondary address][::INSTR]

Do not instantiate directly, use pyvisa.highlevel.ResourceManager.open_resource().

CR: str = '\r'
LF: str = '\n'
allow_dma: Attribute[bool]

Should I/O accesses use DMA (True) or Programmed I/O (False).

assert_trigger() None

Sends a software trigger to the device.

before_close() None

Called just before closing an instrument.

chunk_size: int = 20480

Number of bytes to read at a time. Some resources (serial) may not support large chunk sizes.

clear() None

Clear this resource.

close() None

Closes the VISA session and marks the handle as invalid.

control_ren(mode: RENLineOperation) StatusCode

Controls the state of the GPIB Remote Enable (REN) interface line.

The remote/local state of the device can also be controlled optionally.

Corresponds to viGpibControlREN function of the VISA library.

Parameters:

mode (constants.RENLineOperation) – Specifies the state of the REN line and optionally the device remote/local state.

Returns:

Return value of the library call.

Return type:

constants.StatusCode

disable_event(event_type: EventType, mechanism: EventMechanism) None

Disable notification for an event type(s) via the specified mechanism(s).

Parameters:
  • event_type (constants.EventType) – Logical event identifier.

  • mechanism (constants.EventMechanism) – Specifies event handling mechanisms to be disabled.

discard_events(event_type: EventType, mechanism: EventMechanism) None

Discards event occurrences for an event type and mechanism in this resource.

Parameters:
  • event_type (constants.EventType) – Logical event identifier.

  • mechanism (constants.EventMechanism) – Specifies event handling mechanisms to be disabled.

enable_event(event_type: EventType, mechanism: EventMechanism, context: None = None) None

Enable event occurrences for specified event types and mechanisms in this resource.

Parameters:
  • event_type (constants.EventType) – Logical event identifier.

  • mechanism (constants.EventMechanism) – Specifies event handling mechanisms to be enabled

  • context (None) – Not currently used, leave as None.

enable_repeat_addressing: Attribute[bool]

Whether to use repeat addressing before each read or write operation.

enable_unaddressing: Attribute[bool]

Whether to unaddress the device (UNT and UNL) after each read or write operation.

property encoding: str

Encoding used for read and write operations.

flush(mask: BufferOperation) None

Manually clears the specified buffers.

Depending on the value of the mask this can cause the buffer data to be written to the device.

Parameters:

mask (constants.BufferOperation) – Specifies the action to be taken with flushing the buffer. See highlevel.VisaLibraryBase.flush for a detailed description.

get_visa_attribute(name: ResourceAttribute) Any

Retrieves the state of an attribute in this resource.

One should prefer the dedicated descriptor for often used attributes since those perform checks and automatic conversion on the value.

Parameters:

name (constants.ResourceAttribute) – Resource attribute for which the state query is made.

Returns:

The state of the queried attribute for a specified resource.

Return type:

Any

ignore_warning(*warnings_constants: StatusCode) ContextManager

Ignoring warnings context manager for the current resource.

Parameters:

warnings_constants (constants.StatusCode) – Constants identifying the warnings to ignore.

implementation_version: Attribute[int]

Resource version that identifies the revisions or implementations of a resource.

install_handler(event_type: EventType, handler: Callable[[VISASession, EventType, VISAEventContext, Any], None], user_handle=None) Any

Install handlers for event callbacks in this resource.

Parameters:
  • event_type (constants.EventType) – Logical event identifier.

  • handler (VISAHandler) – Handler function to be installed by a client application.

  • user_handle – A value specified by an application that can be used for identifying handlers uniquely for an event type. Depending on the backend they may be restriction on the possible values. Look at the backend install_visa_handler for more details.

Returns:

User handle in a format amenable to the backend. This is this representation of the handle that should be used when unistalling a handler.

Return type:

Any

interface_number: Attribute[int]

Board number for the given interface.

interface_type: Attribute[constants.InterfaceType]

Interface type of the given session.

io_protocol: Attribute[constants.IOProtocol]

IO protocol to use. See the attribute definition for more details.

property last_status: StatusCode

Last status code for this session.

lock(timeout: float | Literal['default'] = 'default', requested_key: str | None = None) str

Establish a shared lock to the resource.

Parameters:
  • timeout (Union[float, Literal["default"]], optional) – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. Defaults to “default” which means use self.timeout.

  • requested_key (Optional[str], optional) – Access key used by another session with which you want your session to share a lock or None to generate a new shared access key.

Returns:

A new shared access key if requested_key is None, otherwise, same value as the requested_key

Return type:

str

lock_context(timeout: float | Literal['default'] = 'default', requested_key: str | None = 'exclusive') Iterator[str | None]

A context that locks

Parameters:
  • timeout (Union[float, Literal["default"]], optional) – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. Defaults to “default” which means use self.timeout.

  • requested_key (Optional[str], optional) – When using default of ‘exclusive’ the lock is an exclusive lock. Otherwise it is the access key for the shared lock or None to generate a new shared access key.

Yields:

Optional[str] – The access_key if applicable.

lock_excl(timeout: float | Literal['default'] = 'default') None

Establish an exclusive lock to the resource.

Parameters:

timeout (Union[float, Literal["default"]], optional) – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. Defaults to “default” which means use self.timeout.

lock_state: Attribute[constants.AccessModes]

Current locking state of the resource.

open(access_mode: AccessModes = AccessModes.no_lock, open_timeout: int = 5000) None

Opens a session to the specified resource.

Parameters:
  • access_mode (constants.AccessModes, optional) – Specifies the mode by which the resource is to be accessed. Defaults to constants.AccessModes.no_lock.

  • open_timeout (int, optional) – If the access_mode parameter requests a lock, then this parameter specifies the absolute time period (in milliseconds) that the resource waits to get unlocked before this operation returns an error. Defaults to 5000.

primary_address: Attribute[int]

Primary address of the GPIB device used by the given session.

query(message: str, delay: float | None = None) str

A combination of write(message) and read()

Parameters:
  • message (str) – The message to send.

  • delay (Optional[float], optional) – Delay in seconds between write and read operations. If None, defaults to self.query_delay.

Returns:

Answer from the device.

Return type:

str

query_ascii_values(message: str, converter: ~typing.Literal['s', 'b', 'c', 'd', 'o', 'x', 'X', 'e', 'E', 'f', 'F', 'g', 'G'] | ~typing.Callable[[str], ~typing.Any] = 'f', separator: str | ~typing.Callable[[str], ~typing.Iterable[str]] = ',', container: ~typing.Type | ~typing.Callable[[~typing.Iterable], ~typing.Sequence] = <class 'list'>, delay: float | None = None) Sequence[Any]

Query the device for values in ascii format returning an iterable of values.

Parameters:
  • message (str) – The message to send.

  • converter (ASCII_CONVERTER, optional) – Str format of function to convert each value. Default to “f”.

  • separator (Union[str, Callable[[str], Iterable[str]]]) – str or callable used to split the data into individual elements. If a str is given, data.split(separator) is used. Default to “,”.

  • container (Union[Type, Callable[[Iterable], Sequence]], optional) – Container type to use for the output data. Possible values are: list, tuple, np.ndarray, etc, Default to list.

  • delay (Optional[float], optional) – Delay in seconds between write and read operations. If None, defaults to self.query_delay.

Returns:

Parsed data.

Return type:

Sequence

query_binary_values(message: str, datatype: ~typing.Literal['s', 'b', 'B', 'h', 'H', 'i', 'I', 'l', 'L', 'q', 'Q', 'f', 'd'] = 'f', is_big_endian: bool = False, container: ~typing.Type | ~typing.Callable[[~typing.Iterable], ~typing.Sequence] = <class 'list'>, delay: float | None = None, header_fmt: ~typing.Literal['ieee', 'hp', 'empty'] = 'ieee', expect_termination: bool = True, data_points: int = 0, chunk_size: int | None = None) Sequence[int | float]

Query the device for values in binary format returning an iterable of values.

Parameters:
  • message (str) – The message to send.

  • datatype (BINARY_DATATYPES, optional) – Format string for a single element. See struct module. ‘f’ by default.

  • is_big_endian (bool, optional) – Are the data in big or little endian order. Defaults to False.

  • container (Union[Type, Callable[[Iterable], Sequence]], optional) – Container type to use for the output data. Possible values are: list, tuple, np.ndarray, etc, Default to list.

  • delay (Optional[float], optional) – Delay in seconds between write and read operations. If None, defaults to self.query_delay.

  • header_fmt (util.BINARY_HEADERS, optional) – Format of the header prefixing the data. Defaults to ‘ieee’.

  • expect_termination (bool, optional) – When set to False, the expected length of the binary values block does not account for the final termination character (the read termination). Defaults to True.

  • data_points (int, optional) – Number of points expected in the block. This is used only if the instrument does not report it itself. This will be converted in a number of bytes based on the datatype. Defaults to 0.

  • chunk_size (int, optional) – Size of the chunks to read from the device. Using larger chunks may be faster for large amount of data.

Returns:

Data read from the device.

Return type:

Sequence[Union[int, float]]

query_delay: float = 0.0

Delay in s to sleep between the write and read occuring in a query

read(termination: str | None = None, encoding: str | None = None) str

Read a string from the device.

Reading stops when the device stops sending (e.g. by setting appropriate bus lines), or the termination characters sequence was detected. Attention: Only the last character of the termination characters is really used to stop reading, however, the whole sequence is compared to the ending of the read string message. If they don’t match, a warning is issued.

Parameters:
  • termination (Optional[str], optional) – Alternative character termination to use. If None, the value of read_termination is used. Defaults to None.

  • encoding (Optional[str], optional) – Alternative encoding to use to turn bytes into str. If None, the value of encoding is used. Defaults to None.

Returns:

Message read from the instrument and decoded.

Return type:

str

read_ascii_values(converter: ~typing.Literal['s', 'b', 'c', 'd', 'o', 'x', 'X', 'e', 'E', 'f', 'F', 'g', 'G'] | ~typing.Callable[[str], ~typing.Any] = 'f', separator: str | ~typing.Callable[[str], ~typing.Iterable[str]] = ',', container: ~typing.Type | ~typing.Callable[[~typing.Iterable], ~typing.Sequence] = <class 'list'>) Sequence

Read values from the device in ascii format returning an iterable of values.

Parameters:

converter (ASCII_CONVERTER, optional) – Str format of function to convert each value. Default to “f”.

separatorUnion[str, Callable[[str], Iterable[str]]]

str or callable used to split the data into individual elements. If a str is given, data.split(separator) is used. Default to “,”.

containerUnion[Type, Callable[[Iterable], Sequence]], optional

Container type to use for the output data. Possible values are: list, tuple, np.ndarray, etc, Default to list.

Returns:

Parsed data.

Return type:

Sequence

read_binary_values(datatype: ~typing.Literal['s', 'b', 'B', 'h', 'H', 'i', 'I', 'l', 'L', 'q', 'Q', 'f', 'd'] = 'f', is_big_endian: bool = False, container: ~typing.Type | ~typing.Callable[[~typing.Iterable], ~typing.Sequence] = <class 'list'>, header_fmt: ~typing.Literal['ieee', 'hp', 'empty'] = 'ieee', expect_termination: bool = True, data_points: int = -1, chunk_size: int | None = None) Sequence[int | float]

Read values from the device in binary format returning an iterable of values.

Parameters:
  • datatype (BINARY_DATATYPES, optional) – Format string for a single element. See struct module. ‘f’ by default.

  • is_big_endian (bool, optional) – Are the data in big or little endian order. Defaults to False.

  • container (Union[Type, Callable[[Iterable], Sequence]], optional) – Container type to use for the output data. Possible values are: list, tuple, np.ndarray, etc, Default to list.

  • header_fmt (util.BINARY_HEADERS, optional) – Format of the header prefixing the data. Defaults to ‘ieee’.

  • expect_termination (bool, optional) – When set to False, the expected length of the binary values block does not account for the final termination character (the read termination). Defaults to True.

  • data_points (int, optional) – Number of points expected in the block. This is used only if the instrument does not report it itself. This will be converted in a number of bytes based on the datatype. Defaults to 0.

  • chunk_size (int, optional) – Size of the chunks to read from the device. Using larger chunks may be faster for large amount of data.

Returns:

Data read from the device.

Return type:

Sequence[Union[int, float]]

read_bytes(count: int, chunk_size: int | None = None, break_on_termchar: bool = False) bytes

Read a certain number of bytes from the instrument.

Parameters:
  • count (int) – The number of bytes to read from the instrument.

  • chunk_size (Optional[int], optional) – The chunk size to use to perform the reading. If count > chunk_size multiple low level operations will be performed. Defaults to None, meaning the resource wide set value is set.

  • break_on_termchar (bool, optional) – Should the reading stop when a termination character is encountered or when the message ends. Defaults to False.

Returns:

Bytes read from the instrument.

Return type:

bytes

read_raw(size: int | None = None) bytes

Read the unmodified string sent from the instrument to the computer.

In contrast to read(), no termination characters are stripped.

Parameters:

size (Optional[int], optional) – The chunk size to use to perform the reading. Defaults to None, meaning the resource wide set value is set.

Returns:

Bytes read from the instrument.

Return type:

bytes

read_stb() int

Service request status register.

property read_termination: str | None

Read termination character.

read_termination_context(new_termination: str) Iterator
classmethod register(interface_type: InterfaceType, resource_class: str) Callable[[Type[T]], Type[T]]

Create a decorator to register a class.

The class is associated to an interface type, resource class pair.

Parameters:
  • interface_type (constants.InterfaceType) – Interface type for which to register a wrapper class.

  • resource_class (str) – Resource class for which to register a wrapper class.

Returns:

Decorator registering the class. Raises TypeError if some VISA attributes are missing on the registered class.

Return type:

Callable[[Type[T]], Type[T]]

remote_enabled: Attribute[constants.LineState]

Current state of the GPIB REN (Remote ENable) interface line.

resource_class: Attribute[str]

Resource class (for example, “INSTR”) as defined by the canonical resource name.

property resource_info: ResourceInfo

Get the extended information of this resource.

resource_manager: highlevel.ResourceManager

Reference to the resource manager used by this resource

resource_manufacturer_name: Attribute[str]

Manufacturer name of the vendor that implemented the VISA library.

resource_name: Attribute[str]

Unique identifier for a resource compliant with the address structure.

secondary_address: Attribute[int]

Secondary address of the GPIB device used by the given session.

send_end: Attribute[bool]

Should END be asserted during the transfer of the last byte of the buffer.

property session: VISASession

Resource session handle.

Raises:

errors.InvalidSession – Raised if session is closed.

set_visa_attribute(name: ResourceAttribute, state: Any) StatusCode

Set the state of an attribute.

One should prefer the dedicated descriptor for often used attributes since those perform checks and automatic conversion on the value.

Parameters:
  • name (constants.ResourceAttribute) – Attribute for which the state is to be modified.

  • state (Any) – The state of the attribute to be set for the specified object.

Returns:

Return value of the library call.

Return type:

constants.StatusCode

spec_version: Attribute[int]

Version of the VISA specification to which the implementation is compliant.

property stb: int

Service request status register.

timeout: Attribute[float]

Timeout in milliseconds for all resource I/O operations.

uninstall_handler(event_type: EventType, handler: Callable[[VISASession, EventType, VISAEventContext, Any], None], user_handle=None) None

Uninstalls handlers for events in this resource.

Parameters:
  • event_type (constants.EventType) – Logical event identifier.

  • handler (VISAHandler) – Handler function to be uninstalled by a client application.