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: pyvisa.highlevel.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: pyvisa.constants.EventType, mechanism: pyvisa.constants.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: pyvisa.constants.EventType, mechanism: pyvisa.constants.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: pyvisa.constants.EventType, mechanism: pyvisa.constants.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: pyvisa.constants.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: pyvisa.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: pyvisa.attributes.Attribute[int]

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

install_handler(event_type: pyvisa.constants.EventType, handler: Callable[[VISASession, pyvisa.constants.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: pyvisa.attributes.Attribute[int]

Board number for the given interface.

interface_type: pyvisa.attributes.Attribute[pyvisa.constants.InterfaceType]

Interface type of the given session.

property last_status: pyvisa.constants.StatusCode

Last status code for this session.

lock(timeout: Union[float, Literal['default']] = 'default', requested_key: Optional[str] = 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: Union[float, Literal['default']] = 'default', requested_key: Optional[str] = 'exclusive') Iterator[Optional[str]][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: Union[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: pyvisa.attributes.Attribute[pyvisa.constants.AccessModes]

Current locking state of the resource.

open(access_mode: pyvisa.constants.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: pyvisa.constants.InterfaceType, resource_class: str) Callable[[Type[pyvisa.resources.resource.T]], Type[pyvisa.resources.resource.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: pyvisa.attributes.Attribute[str]

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

property resource_info: pyvisa.highlevel.ResourceInfo

Get the extended information of this resource.

resource_manager: pyvisa.highlevel.ResourceManager

Reference to the resource manager used by this resource

resource_manufacturer_name: pyvisa.attributes.Attribute[str]

Manufacturer name of the vendor that implemented the VISA library.

resource_name: pyvisa.attributes.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: pyvisa.constants.ResourceAttribute, state: Any) pyvisa.constants.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: pyvisa.attributes.Attribute[int]

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

timeout: pyvisa.attributes.Attribute[float]

Timeout in milliseconds for all resource I/O operations.

uninstall_handler(event_type: pyvisa.constants.EventType, handler: Callable[[VISASession, pyvisa.constants.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[pyvisa.attributes.Attribute]]] = {<class 'pyvisa.attributes.AttrVI_ATTR_TMO_VALUE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_SPEC_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_LOCK_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_MAX_QUEUE_LENGTH'>, <class 'pyvisa.attributes.AttrVI_ATTR_USER_DATA'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_INST_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_CLASS'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_IMPL_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_TYPE'>}

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: pyvisa.highlevel.VisaLibraryBase

Reference to the VISA library instance used by the resource

wait_on_event(in_event_type: pyvisa.constants.EventType, timeout: int, capture_timeout: bool = False) pyvisa.resources.resource.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[[pyvisa.resources.resource.Resource, pyvisa.events.Event, Any], None]) Callable[[VISASession, pyvisa.constants.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: pyvisa.highlevel.ResourceManager, resource_name: str)[source]

Base class for resources that use message based communication.

CR: str = '\r'
LF: str = '\n'
allow_dma: pyvisa.attributes.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: pyvisa.constants.EventType, mechanism: pyvisa.constants.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: pyvisa.constants.EventType, mechanism: pyvisa.constants.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: pyvisa.constants.EventType, mechanism: pyvisa.constants.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: pyvisa.constants.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: pyvisa.constants.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: pyvisa.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: pyvisa.constants.EventType, handler: Callable[[VISASession, pyvisa.constants.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: pyvisa.attributes.Attribute[pyvisa.constants.IOProtocol]

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

property last_status: pyvisa.constants.StatusCode

Last status code for this session.

lock(timeout: Union[float, Literal['default']] = 'default', requested_key: Optional[str] = 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: Union[float, Literal['default']] = 'default', requested_key: Optional[str] = 'exclusive') Iterator[Optional[str]]

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: Union[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: pyvisa.constants.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: Optional[float] = 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.Union[typing.Literal['s', 'b', 'c', 'd', 'o', 'x', 'X', 'e', 'E', 'f', 'F', 'g', 'G'], typing.Callable[[str], typing.Any]] = 'f', separator: typing.Union[str, typing.Callable[[str], typing.Iterable[str]]] = ',', container: typing.Union[typing.Type, typing.Callable[[typing.Iterable], typing.Sequence]] = <class 'list'>, delay: typing.Optional[float] = 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.Union[typing.Type, typing.Callable[[typing.Iterable], typing.Sequence]] = <class 'list'>, delay: typing.Optional[float] = None, header_fmt: typing.Literal['ieee', 'hp', 'empty'] = 'ieee', expect_termination: bool = True, data_points: int = 0, chunk_size: typing.Optional[int] = None) Sequence[Union[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: Optional[str] = None, encoding: Optional[str] = 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 write_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.Union[typing.Literal['s', 'b', 'c', 'd', 'o', 'x', 'X', 'e', 'E', 'f', 'F', 'g', 'G'], typing.Callable[[str], typing.Any]] = 'f', separator: typing.Union[str, typing.Callable[[str], typing.Iterable[str]]] = ',', container: typing.Union[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.Union[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: typing.Optional[int] = None) Sequence[Union[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: Optional[int] = 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: Optional[int] = 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: Optional[str]

Read termination character.

read_termination_context(new_termination: str) Iterator[source]
classmethod register(interface_type: pyvisa.constants.InterfaceType, resource_class: str) Callable[[Type[pyvisa.resources.resource.T]], Type[pyvisa.resources.resource.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: pyvisa.highlevel.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: pyvisa.attributes.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: pyvisa.constants.ResourceAttribute, state: Any) pyvisa.constants.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: pyvisa.constants.EventType, handler: Callable[[VISASession, pyvisa.constants.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_TMO_VALUE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_SPEC_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_LOCK_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_MAX_QUEUE_LENGTH'>, <class 'pyvisa.attributes.AttrVI_ATTR_USER_DATA'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_INST_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_CLASS'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_IMPL_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_TYPE'>}

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: pyvisa.constants.EventType, timeout: int, capture_timeout: bool = False) pyvisa.resources.resource.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[[pyvisa.resources.resource.Resource, pyvisa.events.Event, Any], None]) Callable[[VISASession, pyvisa.constants.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: Optional[str] = None, encoding: Optional[str] = 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: Union[Literal['s', 'b', 'c', 'd', 'o', 'x', 'X', 'e', 'E', 'f', 'F', 'g', 'G'], Callable[[str], Any]] = 'f', separator: Union[str, Callable[[Iterable[str]], str]] = ',', termination: Optional[str] = None, encoding: Optional[str] = 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: Optional[str] = None, encoding: Optional[str] = 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: pyvisa.highlevel.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: pyvisa.constants.EventType, mechanism: pyvisa.constants.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: pyvisa.constants.EventType, mechanism: pyvisa.constants.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: pyvisa.constants.EventType, mechanism: pyvisa.constants.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: pyvisa.constants.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: pyvisa.constants.StatusCode) ContextManager

Ignoring warnings context manager for the current resource.

Parameters

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

implementation_version: pyvisa.attributes.Attribute[int]

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

install_handler(event_type: pyvisa.constants.EventType, handler: Callable[[VISASession, pyvisa.constants.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: pyvisa.attributes.Attribute[int]

Board number for the given interface.

interface_type: pyvisa.attributes.Attribute[pyvisa.constants.InterfaceType]

Interface type of the given session.

property last_status: pyvisa.constants.StatusCode

Last status code for this session.

lock(timeout: Union[float, Literal['default']] = 'default', requested_key: Optional[str] = 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: Union[float, Literal['default']] = 'default', requested_key: Optional[str] = 'exclusive') Iterator[Optional[str]]

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: Union[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: pyvisa.attributes.Attribute[pyvisa.constants.AccessModes]

Current locking state of the resource.

move_in(space: pyvisa.constants.AddressSpace, offset: int, length: int, width: pyvisa.constants.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: pyvisa.constants.AddressSpace, offset: int, length: int, data: Iterable[int], width: pyvisa.constants.DataWidth, extended: bool = False) pyvisa.constants.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: pyvisa.constants.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: pyvisa.constants.AddressSpace, offset: int, width: pyvisa.constants.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: pyvisa.constants.InterfaceType, resource_class: str) Callable[[Type[pyvisa.resources.resource.T]], Type[pyvisa.resources.resource.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: pyvisa.attributes.Attribute[str]

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

property resource_info: pyvisa.highlevel.ResourceInfo

Get the extended information of this resource.

resource_manager: pyvisa.highlevel.ResourceManager

Reference to the resource manager used by this resource

resource_manufacturer_name: pyvisa.attributes.Attribute[str]

Manufacturer name of the vendor that implemented the VISA library.

resource_name: pyvisa.attributes.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: pyvisa.constants.ResourceAttribute, state: Any) pyvisa.constants.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: pyvisa.attributes.Attribute[int]

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

timeout: pyvisa.attributes.Attribute[float]

Timeout in milliseconds for all resource I/O operations.

uninstall_handler(event_type: pyvisa.constants.EventType, handler: Callable[[VISASession, pyvisa.constants.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[pyvisa.attributes.Attribute]]] = {<class 'pyvisa.attributes.AttrVI_ATTR_TMO_VALUE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_SPEC_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_LOCK_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_MAX_QUEUE_LENGTH'>, <class 'pyvisa.attributes.AttrVI_ATTR_USER_DATA'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_INST_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_CLASS'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_IMPL_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_TYPE'>}

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: pyvisa.highlevel.VisaLibraryBase

Reference to the VISA library instance used by the resource

wait_on_event(in_event_type: pyvisa.constants.EventType, timeout: int, capture_timeout: bool = False) pyvisa.resources.resource.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[[pyvisa.resources.resource.Resource, pyvisa.events.Event, Any], None]) Callable[[VISASession, pyvisa.constants.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: pyvisa.constants.AddressSpace, offset: int, data: int, width: pyvisa.constants.DataWidth, extended: bool = False) pyvisa.constants.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: pyvisa.highlevel.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: pyvisa.attributes.Attribute[bool]

Manually control transmission. The default value is True.

assert_trigger() None

Sends a software trigger to the device.

baud_rate: pyvisa.attributes.Attribute[int]

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

before_close() None

Called just before closing an instrument.

break_length: pyvisa.attributes.Attribute[int]

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

break_state: pyvisa.attributes.Attribute[pyvisa.constants.LineState]

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

bytes_in_buffer: pyvisa.attributes.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: pyvisa.attributes.Attribute[int]

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

disable_event(event_type: pyvisa.constants.EventType, mechanism: pyvisa.constants.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: pyvisa.constants.EventType, mechanism: pyvisa.constants.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: pyvisa.attributes.Attribute[bool]

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

enable_event(event_type: pyvisa.constants.EventType, mechanism: pyvisa.constants.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: pyvisa.attributes.Attribute[pyvisa.constants.SerialTermination]

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

end_output: pyvisa.attributes.Attribute[pyvisa.constants.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: pyvisa.attributes.Attribute[pyvisa.constants.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: pyvisa.constants.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: pyvisa.constants.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: pyvisa.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: pyvisa.constants.EventType, handler: Callable[[VISASession, pyvisa.constants.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: pyvisa.constants.StatusCode

Last status code for this session.

lock(timeout: Union[float, Literal['default']] = 'default', requested_key: Optional[str] = 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: Union[float, Literal['default']] = 'default', requested_key: Optional[str] = 'exclusive') Iterator[Optional[str]]

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: Union[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: pyvisa.constants.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: pyvisa.attributes.Attribute[pyvisa.constants.Parity]

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

query(message: str, delay: Optional[float] = 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.Union[typing.Literal['s', 'b', 'c', 'd', 'o', 'x', 'X', 'e', 'E', 'f', 'F', 'g', 'G'], typing.Callable[[str], typing.Any]] = 'f', separator: typing.Union[str, typing.Callable[[str], typing.Iterable[str]]] = ',', container: typing.Union[typing.Type, typing.Callable[[typing.Iterable], typing.Sequence]] = <class 'list'>, delay: typing.Optional[float] = 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.Union[typing.Type, typing.Callable[[typing.Iterable], typing.Sequence]] = <class 'list'>, delay: typing.Optional[float] = None, header_fmt: typing.Literal['ieee', 'hp', 'empty'] = 'ieee', expect_termination: bool = True, data_points: int = 0, chunk_size: typing.Optional[int] = None) Sequence[Union[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: Optional[str] = None, encoding: Optional[str] = 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 write_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.Union[typing.Literal['s', 'b', 'c', 'd', 'o', 'x', 'X', 'e', 'E', 'f', 'F', 'g', 'G'], typing.Callable[[str], typing.Any]] = 'f', separator: typing.Union[str, typing.Callable[[str], typing.Iterable[str]]] = ',', container: typing.Union[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.Union[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: typing.Optional[int] = None) Sequence[Union[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: Optional[int] = 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: Optional[int] = 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: Optional[str]

Read termination character.

read_termination_context(new_termination: str) Iterator
classmethod register(interface_type: pyvisa.constants.InterfaceType, resource_class: str) Callable[[Type[pyvisa.resources.resource.T]], Type[pyvisa.resources.resource.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: pyvisa.attributes.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: pyvisa.highlevel.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: pyvisa.constants.ResourceAttribute, state: Any) pyvisa.constants.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: pyvisa.attributes.Attribute[pyvisa.constants.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: pyvisa.constants.EventType, handler: Callable[[VISASession, pyvisa.constants.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_RSRC_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_TRIG_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_IO_PROT'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_PARITY'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_BREAK_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_ALLOW_TRANSMIT'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_REPLACE_CHAR'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_DSR_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_INST_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_USER_DATA'>, <class 'pyvisa.attributes.AttrVI_ATTR_TERMCHAR'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_DATA_BITS'>, <class 'pyvisa.attributes.AttrVI_ATTR_RD_BUF_SIZE'>, <class 'pyvisa.attributes.AttrVI_ATTR_WR_BUF_SIZE'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_CONNECTED'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_BREAK_LEN'>, <class 'pyvisa.attributes.AttrVI_ATTR_DMA_ALLOW_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_CTS_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_WIRE_MODE'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_IMPL_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_DCD_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_SPEC_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_RI_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_XOFF_CHAR'>, <class 'pyvisa.attributes.AttrVI_ATTR_MAX_QUEUE_LENGTH'>, <class 'pyvisa.attributes.AttrVI_ATTR_TERMCHAR_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_BAUD'>, <class 'pyvisa.attributes.AttrVI_ATTR_RD_BUF_OPER_MODE'>, <class 'pyvisa.attributes.AttrVI_ATTR_WR_BUF_OPER_MODE'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_DISCARD_NULL'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_END_OUT'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_XON_CHAR'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_RTS_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_TYPE'>, <class 'pyvisa.attributes.AttrVI_ATTR_TMO_VALUE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_LOCK_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_SEND_END_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_SUPPRESS_END_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_STOP_BITS'>, <class 'pyvisa.attributes.AttrVI_ATTR_FILE_APPEND_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_AVAIL_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_FLOW_CNTRL'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_END_IN'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_DTR_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_CLASS'>}

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: pyvisa.constants.EventType, timeout: int, capture_timeout: bool = False) pyvisa.resources.resource.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[[pyvisa.resources.resource.Resource, pyvisa.events.Event, Any], None]) Callable[[VISASession, pyvisa.constants.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: Optional[str] = None, encoding: Optional[str] = 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: Union[Literal['s', 'b', 'c', 'd', 'o', 'x', 'X', 'e', 'E', 'f', 'F', 'g', 'G'], Callable[[str], Any]] = 'f', separator: Union[str, Callable[[Iterable[str]], str]] = ',', termination: Optional[str] = None, encoding: Optional[str] = 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: Optional[str] = None, encoding: Optional[str] = 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: pyvisa.attributes.Attribute[str]

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

xon_char: pyvisa.attributes.Attribute[str]

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

class pyvisa.resources.TCPIPInstrument(resource_manager: pyvisa.highlevel.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: pyvisa.constants.RENLineOperation) pyvisa.constants.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: pyvisa.constants.EventType, mechanism: pyvisa.constants.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: pyvisa.constants.EventType, mechanism: pyvisa.constants.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: pyvisa.constants.EventType, mechanism: pyvisa.constants.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: pyvisa.constants.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: pyvisa.constants.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: pyvisa.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: pyvisa.constants.EventType, handler: Callable[[VISASession, pyvisa.constants.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: pyvisa.constants.StatusCode

Last status code for this session.

lock(timeout: Union[float, Literal['default']] = 'default', requested_key: Optional[str] = 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: Union[float, Literal['default']] = 'default', requested_key: Optional[str] = 'exclusive') Iterator[Optional[str]]

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: Union[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: pyvisa.constants.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: Optional[float] = 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.Union[typing.Literal['s', 'b', 'c', 'd', 'o', 'x', 'X', 'e', 'E', 'f', 'F', 'g', 'G'], typing.Callable[[str], typing.Any]] = 'f', separator: typing.Union[str, typing.Callable[[str], typing.Iterable[str]]] = ',', container: typing.Union[typing.Type, typing.Callable[[typing.Iterable], typing.Sequence]] = <class 'list'>, delay: typing.Optional[float] = 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.Union[typing.Type, typing.Callable[[typing.Iterable], typing.Sequence]] = <class 'list'>, delay: typing.Optional[float] = None, header_fmt: typing.Literal['ieee', 'hp', 'empty'] = 'ieee', expect_termination: bool = True, data_points: int = 0, chunk_size: typing.Optional[int] = None) Sequence[Union[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: Optional[str] = None, encoding: Optional[str] = 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 write_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.Union[typing.Literal['s', 'b', 'c', 'd', 'o', 'x', 'X', 'e', 'E', 'f', 'F', 'g', 'G'], typing.Callable[[str], typing.Any]] = 'f', separator: typing.Union[str, typing.Callable[[str], typing.Iterable[str]]] = ',', container: typing.Union[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.Union[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: typing.Optional[int] = None) Sequence[Union[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: Optional[int] = 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: Optional[int] = 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: Optional[str]

Read termination character.

read_termination_context(new_termination: str) Iterator
classmethod register(interface_type: pyvisa.constants.InterfaceType, resource_class: str) Callable[[Type[pyvisa.resources.resource.T]], Type[pyvisa.resources.resource.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: pyvisa.highlevel.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: pyvisa.constants.ResourceAttribute, state: Any) pyvisa.constants.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: pyvisa.constants.EventType, handler: Callable[[VISASession, pyvisa.constants.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_RSRC_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_TRIG_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_IO_PROT'>, <class 'pyvisa.attributes.AttrVI_ATTR_TCPIP_IS_HISLIP'>, <class 'pyvisa.attributes.AttrVI_ATTR_TCPIP_ADDR'>, <class 'pyvisa.attributes.AttrVI_ATTR_TCPIP_HOSTNAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_INST_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_USER_DATA'>, <class 'pyvisa.attributes.AttrVI_ATTR_TERMCHAR'>, <class 'pyvisa.attributes.AttrVI_ATTR_RD_BUF_SIZE'>, <class 'pyvisa.attributes.AttrVI_ATTR_WR_BUF_SIZE'>, <class 'pyvisa.attributes.AttrVI_ATTR_DMA_ALLOW_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_IMPL_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_TCPIP_HISLIP_OVERLAP_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_SPEC_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_MAX_QUEUE_LENGTH'>, <class 'pyvisa.attributes.AttrVI_ATTR_TERMCHAR_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_RD_BUF_OPER_MODE'>, <class 'pyvisa.attributes.AttrVI_ATTR_WR_BUF_OPER_MODE'>, <class 'pyvisa.attributes.AttrVI_ATTR_TCPIP_HISLIP_MAX_MESSAGE_KB'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_TYPE'>, <class 'pyvisa.attributes.AttrVI_ATTR_TCPIP_HISLIP_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_TCPIP_DEVICE_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_TMO_VALUE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_LOCK_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_SEND_END_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_SUPPRESS_END_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_FILE_APPEND_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_CLASS'>}

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: pyvisa.highlevel.VisaLibraryBase

Will be present when used as a mixin with Resource

wait_on_event(in_event_type: pyvisa.constants.EventType, timeout: int, capture_timeout: bool = False) pyvisa.resources.resource.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[[pyvisa.resources.resource.Resource, pyvisa.events.Event, Any], None]) Callable[[VISASession, pyvisa.constants.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: Optional[str] = None, encoding: Optional[str] = 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: Union[Literal['s', 'b', 'c', 'd', 'o', 'x', 'X', 'e', 'E', 'f', 'F', 'g', 'G'], Callable[[str], Any]] = 'f', separator: Union[str, Callable[[Iterable[str]], str]] = ',', termination: Optional[str] = None, encoding: Optional[str] = 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: Optional[str] = None, encoding: Optional[str] = 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: pyvisa.highlevel.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: pyvisa.attributes.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: pyvisa.constants.EventType, mechanism: pyvisa.constants.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: pyvisa.constants.EventType, mechanism: pyvisa.constants.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: pyvisa.constants.EventType, mechanism: pyvisa.constants.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: pyvisa.constants.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: pyvisa.constants.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: pyvisa.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: pyvisa.constants.EventType, handler: Callable[[VISASession, pyvisa.constants.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: pyvisa.attributes.Attribute[pyvisa.constants.IOProtocol]

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

property last_status: pyvisa.constants.StatusCode

Last status code for this session.

lock(timeout: Union[float, Literal['default']] = 'default', requested_key: Optional[str] = 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: Union[float, Literal['default']] = 'default', requested_key: Optional[str] = 'exclusive') Iterator[Optional[str]]

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: Union[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: pyvisa.constants.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: Optional[float] = 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.Union[typing.Literal['s', 'b', 'c', 'd', 'o', 'x', 'X', 'e', 'E', 'f', 'F', 'g', 'G'], typing.Callable[[str], typing.Any]] = 'f', separator: typing.Union[str, typing.Callable[[str], typing.Iterable[str]]] = ',', container: typing.Union[typing.Type, typing.Callable[[typing.Iterable], typing.Sequence]] = <class 'list'>, delay: typing.Optional[float] = 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.Union[typing.Type, typing.Callable[[typing.Iterable], typing.Sequence]] = <class 'list'>, delay: typing.Optional[float] = None, header_fmt: typing.Literal['ieee', 'hp', 'empty'] = 'ieee', expect_termination: bool = True, data_points: int = 0, chunk_size: typing.Optional[int] = None) Sequence[Union[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: Optional[str] = None, encoding: Optional[str] = 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 write_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.Union[typing.Literal['s', 'b', 'c', 'd', 'o', 'x', 'X', 'e', 'E', 'f', 'F', 'g', 'G'], typing.Callable[[str], typing.Any]] = 'f', separator: typing.Union[str, typing.Callable[[str], typing.Iterable[str]]] = ',', container: typing.Union[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.Union[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: typing.Optional[int] = None) Sequence[Union[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: Optional[int] = 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: Optional[int] = 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: Optional[str]

Read termination character.

read_termination_context(new_termination: str) Iterator
classmethod register(interface_type: pyvisa.constants.InterfaceType, resource_class: str) Callable[[Type[pyvisa.resources.resource.T]], Type[pyvisa.resources.resource.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: pyvisa.highlevel.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: pyvisa.attributes.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: pyvisa.constants.ResourceAttribute, state: Any) pyvisa.constants.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: pyvisa.constants.EventType, handler: Callable[[VISASession, pyvisa.constants.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_RSRC_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_IO_PROT'>, <class 'pyvisa.attributes.AttrVI_ATTR_TCPIP_ADDR'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_INST_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_TCPIP_KEEPALIVE'>, <class 'pyvisa.attributes.AttrVI_ATTR_TCPIP_HOSTNAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_USER_DATA'>, <class 'pyvisa.attributes.AttrVI_ATTR_TERMCHAR'>, <class 'pyvisa.attributes.AttrVI_ATTR_RD_BUF_SIZE'>, <class 'pyvisa.attributes.AttrVI_ATTR_WR_BUF_SIZE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_CLASS'>, <class 'pyvisa.attributes.AttrVI_ATTR_DMA_ALLOW_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_IMPL_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_TCPIP_NODELAY'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_SPEC_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_MAX_QUEUE_LENGTH'>, <class 'pyvisa.attributes.AttrVI_ATTR_TERMCHAR_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_RD_BUF_OPER_MODE'>, <class 'pyvisa.attributes.AttrVI_ATTR_WR_BUF_OPER_MODE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_TYPE'>, <class 'pyvisa.attributes.AttrVI_ATTR_TMO_VALUE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_LOCK_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_SEND_END_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_SUPPRESS_END_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_FILE_APPEND_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_TCPIP_PORT'>}

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: pyvisa.constants.EventType, timeout: int, capture_timeout: bool = False) pyvisa.resources.resource.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[[pyvisa.resources.resource.Resource, pyvisa.events.Event, Any], None]) Callable[[VISASession, pyvisa.constants.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: Optional[str] = None, encoding: Optional[str] = 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: Union[Literal['s', 'b', 'c', 'd', 'o', 'x', 'X', 'e', 'E', 'f', 'F', 'g', 'G'], Callable[[str], Any]] = 'f', separator: Union[str, Callable[[Iterable[str]], str]] = ',', termination: Optional[str] = None, encoding: Optional[str] = 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: Optional[str] = None, encoding: Optional[str] = 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: pyvisa.highlevel.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: pyvisa.constants.RENLineOperation) pyvisa.constants.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: pyvisa.constants.EventType, mechanism: pyvisa.constants.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: pyvisa.constants.EventType, mechanism: pyvisa.constants.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: pyvisa.constants.EventType, mechanism: pyvisa.constants.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: pyvisa.constants.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: pyvisa.constants.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: pyvisa.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: pyvisa.constants.EventType, handler: Callable[[VISASession, pyvisa.constants.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: pyvisa.attributes.Attribute[bool]

Whether the device is 488.2 compliant.

property last_status: pyvisa.constants.StatusCode

Last status code for this session.

lock(timeout: Union[float, Literal['default']] = 'default', requested_key: Optional[str] = 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: Union[float, Literal['default']] = 'default', requested_key: Optional[str] = 'exclusive') Iterator[Optional[str]]

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: Union[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: pyvisa.constants.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: Optional[float] = 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.Union[typing.Literal['s', 'b', 'c', 'd', 'o', 'x', 'X', 'e', 'E', 'f', 'F', 'g', 'G'], typing.Callable[[str], typing.Any]] = 'f', separator: typing.Union[str, typing.Callable[[str], typing.Iterable[str]]] = ',', container: typing.Union[typing.Type, typing.Callable[[typing.Iterable], typing.Sequence]] = <class 'list'>, delay: typing.Optional[float] = 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.Union[typing.Type, typing.Callable[[typing.Iterable], typing.Sequence]] = <class 'list'>, delay: typing.Optional[float] = None, header_fmt: typing.Literal['ieee', 'hp', 'empty'] = 'ieee', expect_termination: bool = True, data_points: int = 0, chunk_size: typing.Optional[int] = None) Sequence[Union[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: Optional[str] = None, encoding: Optional[str] = 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 write_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.Union[typing.Literal['s', 'b', 'c', 'd', 'o', 'x', 'X', 'e', 'E', 'f', 'F', 'g', 'G'], typing.Callable[[str], typing.Any]] = 'f', separator: typing.Union[str, typing.Callable[[str], typing.Iterable[str]]] = ',', container: typing.Union[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.Union[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: typing.Optional[int] = None) Sequence[Union[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: Optional[int] = 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: Optional[int] = 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: Optional[str]

Read termination character.

read_termination_context(new_termination: str) Iterator
classmethod register(interface_type: pyvisa.constants.InterfaceType, resource_class: str) Callable[[Type[pyvisa.resources.resource.T]], Type[pyvisa.resources.resource.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: pyvisa.highlevel.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: pyvisa.constants.ResourceAttribute, state: Any) pyvisa.constants.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: pyvisa.constants.EventType, handler: Callable[[VISASession, pyvisa.constants.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_MODEL_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_USB_PROTOCOL'>, <class 'pyvisa.attributes.AttrVI_ATTR_IO_PROT'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_INST_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_4882_COMPLIANT'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_USB_INTFC_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_USB_SERIAL_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_USER_DATA'>, <class 'pyvisa.attributes.AttrVI_ATTR_TERMCHAR'>, <class 'pyvisa.attributes.AttrVI_ATTR_RD_BUF_SIZE'>, <class 'pyvisa.attributes.AttrVI_ATTR_WR_BUF_SIZE'>, <class 'pyvisa.attributes.AttrVI_ATTR_DMA_ALLOW_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_IMPL_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_SPEC_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_MAX_QUEUE_LENGTH'>, <class 'pyvisa.attributes.AttrVI_ATTR_TERMCHAR_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_RD_BUF_OPER_MODE'>, <class 'pyvisa.attributes.AttrVI_ATTR_WR_BUF_OPER_MODE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_TYPE'>, <class 'pyvisa.attributes.AttrVI_ATTR_MODEL_CODE'>, <class 'pyvisa.attributes.AttrVI_ATTR_TMO_VALUE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_LOCK_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_USB_MAX_INTR_SIZE'>, <class 'pyvisa.attributes.AttrVI_ATTR_SEND_END_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_SUPPRESS_END_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_FILE_APPEND_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_CLASS'>}

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: pyvisa.constants.EventType, timeout: int, capture_timeout: bool = False) pyvisa.resources.resource.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[[pyvisa.resources.resource.Resource, pyvisa.events.Event, Any], None]) Callable[[VISASession, pyvisa.constants.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: Optional[str] = None, encoding: Optional[str] = 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: Union[Literal['s', 'b', 'c', 'd', 'o', 'x', 'X', 'e', 'E', 'f', 'F', 'g', 'G'], Callable[[str], Any]] = 'f', separator: Union[str, Callable[[Iterable[str]], str]] = ',', termination: Optional[str] = None, encoding: Optional[str] = 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: Optional[str] = None, encoding: Optional[str] = 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: pyvisa.highlevel.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: pyvisa.constants.EventType, mechanism: pyvisa.constants.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: pyvisa.constants.EventType, mechanism: pyvisa.constants.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: pyvisa.constants.EventType, mechanism: pyvisa.constants.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: pyvisa.constants.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: pyvisa.constants.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: pyvisa.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: pyvisa.constants.EventType, handler: Callable[[VISASession, pyvisa.constants.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: pyvisa.attributes.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: pyvisa.constants.StatusCode

Last status code for this session.

lock(timeout: Union[float, Literal['default']] = 'default', requested_key: Optional[str] = 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: Union[float, Literal['default']] = 'default', requested_key: Optional[str] = 'exclusive') Iterator[Optional[str]]

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: Union[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: pyvisa.attributes.Attribute[int]

Manufacturer identification number of the device.

manufacturer_name: pyvisa.attributes.Attribute[str]

Manufacturer name.

maximum_interrupt_size: pyvisa.attributes.Attribute[int]

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

model_code: pyvisa.attributes.Attribute[int]

Model code for the device.

model_name: pyvisa.attributes.Attribute[str]

Model name of the device.

open(access_mode: pyvisa.constants.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: Optional[float] = 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.Union[typing.Literal['s', 'b', 'c', 'd', 'o', 'x', 'X', 'e', 'E', 'f', 'F', 'g', 'G'], typing.Callable[[str], typing.Any]] = 'f', separator: typing.Union[str, typing.Callable[[str], typing.Iterable[str]]] = ',', container: typing.Union[typing.Type, typing.Callable[[typing.Iterable], typing.Sequence]] = <class 'list'>, delay: typing.Optional[float] = 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.Union[typing.Type, typing.Callable[[typing.Iterable], typing.Sequence]] = <class 'list'>, delay: typing.Optional[float] = None, header_fmt: typing.Literal['ieee', 'hp', 'empty'] = 'ieee', expect_termination: bool = True, data_points: int = 0, chunk_size: typing.Optional[int] = None) Sequence[Union[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: Optional[str] = None, encoding: Optional[str] = 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 write_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.Union[typing.Literal['s', 'b', 'c', 'd', 'o', 'x', 'X', 'e', 'E', 'f', 'F', 'g', 'G'], typing.Callable[[str], typing.Any]] = 'f', separator: typing.Union[str, typing.Callable[[str], typing.Iterable[str]]] = ',', container: typing.Union[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.Union[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: typing.Optional[int] = None) Sequence[Union[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: Optional[int] = 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: Optional[int] = 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: Optional[str]

Read termination character.

read_termination_context(new_termination: str) Iterator
classmethod register(interface_type: pyvisa.constants.InterfaceType, resource_class: str) Callable[[Type[pyvisa.resources.resource.T]], Type[pyvisa.resources.resource.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: pyvisa.highlevel.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: pyvisa.attributes.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: pyvisa.constants.ResourceAttribute, state: Any) pyvisa.constants.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: pyvisa.constants.EventType, handler: Callable[[VISASession, pyvisa.constants.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: pyvisa.attributes.Attribute[int]

USB protocol used by this USB interface.

visa_attributes_classes: ClassVar[Set[Type[attributes.Attribute]]] = {<class 'pyvisa.attributes.AttrVI_ATTR_MODEL_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_USB_CTRL_PIPE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_USB_NUM_PIPES'>, <class 'pyvisa.attributes.AttrVI_ATTR_USB_PROTOCOL'>, <class 'pyvisa.attributes.AttrVI_ATTR_USB_BULK_IN_STATUS'>, <class 'pyvisa.attributes.AttrVI_ATTR_IO_PROT'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_INST_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_USB_END_IN'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_USB_NUM_INTFCS'>, <class 'pyvisa.attributes.AttrVI_ATTR_USB_INTFC_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_USB_SERIAL_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_USB_SUBCLASS'>, <class 'pyvisa.attributes.AttrVI_ATTR_USB_BULK_OUT_PIPE'>, <class 'pyvisa.attributes.AttrVI_ATTR_USER_DATA'>, <class 'pyvisa.attributes.AttrVI_ATTR_TERMCHAR'>, <class 'pyvisa.attributes.AttrVI_ATTR_RD_BUF_SIZE'>, <class 'pyvisa.attributes.AttrVI_ATTR_WR_BUF_SIZE'>, <class 'pyvisa.attributes.AttrVI_ATTR_DMA_ALLOW_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_IMPL_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_USB_ALT_SETTING'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_SPEC_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_USB_CLASS'>, <class 'pyvisa.attributes.AttrVI_ATTR_USB_BULK_OUT_STATUS'>, <class 'pyvisa.attributes.AttrVI_ATTR_MAX_QUEUE_LENGTH'>, <class 'pyvisa.attributes.AttrVI_ATTR_TERMCHAR_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_RD_BUF_OPER_MODE'>, <class 'pyvisa.attributes.AttrVI_ATTR_WR_BUF_OPER_MODE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_TYPE'>, <class 'pyvisa.attributes.AttrVI_ATTR_MODEL_CODE'>, <class 'pyvisa.attributes.AttrVI_ATTR_USB_INTR_IN_PIPE'>, <class 'pyvisa.attributes.AttrVI_ATTR_TMO_VALUE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_LOCK_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_USB_INTR_IN_STATUS'>, <class 'pyvisa.attributes.AttrVI_ATTR_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_USB_MAX_INTR_SIZE'>, <class 'pyvisa.attributes.AttrVI_ATTR_USB_BULK_IN_PIPE'>, <class 'pyvisa.attributes.AttrVI_ATTR_SEND_END_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_SUPPRESS_END_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_FILE_APPEND_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_CLASS'>}

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: pyvisa.constants.EventType, timeout: int, capture_timeout: bool = False) pyvisa.resources.resource.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[[pyvisa.resources.resource.Resource, pyvisa.events.Event, Any], None]) Callable[[VISASession, pyvisa.constants.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: Optional[str] = None, encoding: Optional[str] = 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: Union[Literal['s', 'b', 'c', 'd', 'o', 'x', 'X', 'e', 'E', 'f', 'F', 'g', 'G'], Callable[[str], Any]] = 'f', separator: Union[str, Callable[[Iterable[str]], str]] = ',', termination: Optional[str] = None, encoding: Optional[str] = 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: Optional[str] = None, encoding: Optional[str] = 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: pyvisa.highlevel.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: pyvisa.constants.RENLineOperation) pyvisa.constants.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: pyvisa.constants.EventType, mechanism: pyvisa.constants.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: pyvisa.constants.EventType, mechanism: pyvisa.constants.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: pyvisa.constants.EventType, mechanism: pyvisa.constants.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: pyvisa.attributes.Attribute[bool]

Whether to use repeat addressing before each read or write operation.

enable_unaddressing: pyvisa.attributes.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: pyvisa.constants.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: pyvisa.constants.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: pyvisa.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: pyvisa.constants.EventType, handler: Callable[[VISASession, pyvisa.constants.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: pyvisa.constants.StatusCode

Last status code for this session.

lock(timeout: Union[float, Literal['default']] = 'default', requested_key: Optional[str] = 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: Union[float, Literal['default']] = 'default', requested_key: Optional[str] = 'exclusive') Iterator[Optional[str]]

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: Union[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: pyvisa.constants.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: Optional[float] = 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.Union[typing.Literal['s', 'b', 'c', 'd', 'o', 'x', 'X', 'e', 'E', 'f', 'F', 'g', 'G'], typing.Callable[[str], typing.Any]] = 'f', separator: typing.Union[str, typing.Callable[[str], typing.Iterable[str]]] = ',', container: typing.Union[typing.Type, typing.Callable[[typing.Iterable], typing.Sequence]] = <class 'list'>, delay: typing.Optional[float] = 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.Union[typing.Type, typing.Callable[[typing.Iterable], typing.Sequence]] = <class 'list'>, delay: typing.Optional[float] = None, header_fmt: typing.Literal['ieee', 'hp', 'empty'] = 'ieee', expect_termination: bool = True, data_points: int = 0, chunk_size: typing.Optional[int] = None) Sequence[Union[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: Optional[str] = None, encoding: Optional[str] = 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 write_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.Union[typing.Literal['s', 'b', 'c', 'd', 'o', 'x', 'X', 'e', 'E', 'f', 'F', 'g', 'G'], typing.Callable[[str], typing.Any]] = 'f', separator: typing.Union[str, typing.Callable[[str], typing.Iterable[str]]] = ',', container: typing.Union[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.Union[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: typing.Optional[int] = None) Sequence[Union[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: Optional[int] = 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: Optional[int] = 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: Optional[str]

Read termination character.

read_termination_context(new_termination: str) Iterator
classmethod register(interface_type: pyvisa.constants.InterfaceType, resource_class: str) Callable[[Type[pyvisa.resources.resource.T]], Type[pyvisa.resources.resource.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: pyvisa.highlevel.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: pyvisa.constants.ResourceAttribute, state: Any) pyvisa.constants.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: pyvisa.constants.EventType, handler: Callable[[VISASession, pyvisa.constants.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_RSRC_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_TRIG_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_IO_PROT'>, <class 'pyvisa.attributes.AttrVI_ATTR_GPIB_SECONDARY_ADDR'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_INST_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_USER_DATA'>, <class 'pyvisa.attributes.AttrVI_ATTR_TERMCHAR'>, <class 'pyvisa.attributes.AttrVI_ATTR_RD_BUF_SIZE'>, <class 'pyvisa.attributes.AttrVI_ATTR_GPIB_READDR_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_WR_BUF_SIZE'>, <class 'pyvisa.attributes.AttrVI_ATTR_DMA_ALLOW_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_IMPL_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_GPIB_PRIMARY_ADDR'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_SPEC_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_MAX_QUEUE_LENGTH'>, <class 'pyvisa.attributes.AttrVI_ATTR_TERMCHAR_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_RD_BUF_OPER_MODE'>, <class 'pyvisa.attributes.AttrVI_ATTR_WR_BUF_OPER_MODE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_TYPE'>, <class 'pyvisa.attributes.AttrVI_ATTR_GPIB_REN_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_TMO_VALUE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_LOCK_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_SEND_END_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_SUPPRESS_END_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_FILE_APPEND_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_GPIB_UNADDR_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_CLASS'>}

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_for_srq(timeout: int = 25000) None[source]

Wait for a serial request (SRQ) coming from the instrument.

Note that this method is not ended when another instrument signals an SRQ, only this instrument.

Parameters

timeout (int) – Maximum waiting time in milliseconds. Defaul: 25000 (milliseconds). None means waiting forever if necessary.

wait_on_event(in_event_type: pyvisa.constants.EventType, timeout: int, capture_timeout: bool = False) pyvisa.resources.resource.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[[pyvisa.resources.resource.Resource, pyvisa.events.Event, Any], None]) Callable[[VISASession, pyvisa.constants.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: Optional[str] = None, encoding: Optional[str] = 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: Union[Literal['s', 'b', 'c', 'd', 'o', 'x', 'X', 'e', 'E', 'f', 'F', 'g', 'G'], Callable[[str], Any]] = 'f', separator: Union[str, Callable[[Iterable[str]], str]] = ',', termination: Optional[str] = None, encoding: Optional[str] = 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: Optional[str] = None, encoding: Optional[str] = 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.GPIBInterface(resource_manager: pyvisa.highlevel.ResourceManager, resource_name: str)[source]

Communicates with to devices of type GPIB::INTFC

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

GPIB[board]::INTFC

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

CR: str = '\r'
LF: str = '\n'
address_state: pyvisa.attributes.Attribute[pyvisa.constants.LineState]

Is the GPIB interface currently addressed to talk or listen, or is not addressed.

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.

atn_state: pyvisa.attributes.Attribute[pyvisa.constants.LineState]

Current state of the GPIB ATN (ATtentioN) interface line.

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_atn(mode: pyvisa.constants.ATNLineOperation) pyvisa.constants.StatusCode[source]

Specifies the state of the ATN line and the local active controller state.

Corresponds to viGpibControlATN function of the VISA library.

Parameters

mode (constants.ATNLineOperation) –

Specifies the state of the ATN line and optionally the local active

controller state.

Returns

Return value of the library call.

Return type

constants.StatusCode

control_ren(mode: pyvisa.constants.RENLineOperation) pyvisa.constants.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: pyvisa.constants.EventType, mechanism: pyvisa.constants.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: pyvisa.constants.EventType, mechanism: pyvisa.constants.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: pyvisa.constants.EventType, mechanism: pyvisa.constants.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: pyvisa.constants.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: pyvisa.constants.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

group_execute_trigger(*resources: pyvisa.resources.gpib.GPIBInstrument) Tuple[int, pyvisa.constants.StatusCode][source]
Parameters

resources (GPIBInstrument) – GPIB resources to which to send the group trigger.

Returns

  • int – Number of bytes written as part of sending the GPIB commands.

  • constants.StatusCode – Return value of the library call.

ignore_warning(*warnings_constants: pyvisa.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: pyvisa.constants.EventType, handler: Callable[[VISASession, pyvisa.constants.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.

is_controller_in_charge: pyvisa.attributes.Attribute[bool]

Is the specified GPIB interface currently CIC (Controller In Charge).

is_system_controller: pyvisa.attributes.Attribute[bool]

Is the specified GPIB interface currently the system controller.

property last_status: pyvisa.constants.StatusCode

Last status code for this session.

lock(timeout: Union[float, Literal['default']] = 'default', requested_key: Optional[str] = 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: Union[float, Literal['default']] = 'default', requested_key: Optional[str] = 'exclusive') Iterator[Optional[str]]

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: Union[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.

ndac_state: pyvisa.attributes.Attribute[pyvisa.constants.LineState]

Current state of the GPIB NDAC (Not Data ACcepted) interface line.

open(access_mode: pyvisa.constants.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.

pass_control(primary_address: int, secondary_address: int) pyvisa.constants.StatusCode[source]

Tell a GPIB device to become controller in charge (CIC).

Corresponds to viGpibPassControl function of the VISA library.

Parameters
  • primary_address (int) – Primary address of the GPIB device to which you want to pass control.

  • secondary_address (int) – Secondary address of the targeted GPIB device. If the targeted device does not have a secondary address, this parameter should contain the value Constants.NO_SEC_ADDR.

Returns

Return value of the library call.

Return type

constants.StatusCode

primary_address: Attribute[int]

Primary address of the GPIB device used by the given session.

query(message: str, delay: Optional[float] = 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.Union[typing.Literal['s', 'b', 'c', 'd', 'o', 'x', 'X', 'e', 'E', 'f', 'F', 'g', 'G'], typing.Callable[[str], typing.Any]] = 'f', separator: typing.Union[str, typing.Callable[[str], typing.Iterable[str]]] = ',', container: typing.Union[typing.Type, typing.Callable[[typing.Iterable], typing.Sequence]] = <class 'list'>, delay: typing.Optional[float] = 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.Union[typing.Type, typing.Callable[[typing.Iterable], typing.Sequence]] = <class 'list'>, delay: typing.Optional[float] = None, header_fmt: typing.Literal['ieee', 'hp', 'empty'] = 'ieee', expect_termination: bool = True, data_points: int = 0, chunk_size: typing.Optional[int] = None) Sequence[Union[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: Optional[str] = None, encoding: Optional[str] = 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 write_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.Union[typing.Literal['s', 'b', 'c', 'd', 'o', 'x', 'X', 'e', 'E', 'f', 'F', 'g', 'G'], typing.Callable[[str], typing.Any]] = 'f', separator: typing.Union[str, typing.Callable[[str], typing.Iterable[str]]] = ',', container: typing.Union[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.Union[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: typing.Optional[int] = None) Sequence[Union[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: Optional[int] = 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: Optional[int] = 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: Optional[str]

Read termination character.

read_termination_context(new_termination: str) Iterator
classmethod register(interface_type: pyvisa.constants.InterfaceType, resource_class: str) Callable[[Type[pyvisa.resources.resource.T]], Type[pyvisa.resources.resource.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: pyvisa.highlevel.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_command(data: bytes) Tuple[int, pyvisa.constants.StatusCode][source]

Write GPIB command bytes on the bus.

Corresponds to viGpibCommand function of the VISA library.

Parameters

data (bytes) – Command to write.

Returns

  • int – Number of bytes written

  • constants.StatusCode – Return value of the library call.

send_end: Attribute[bool]

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

send_ifc() pyvisa.constants.StatusCode[source]

Pulse the interface clear line (IFC) for at least 100 microseconds.

Corresponds to viGpibSendIFC function of the VISA library.

property session: VISASession

Resource session handle.

Raises

errors.InvalidSession – Raised if session is closed.

set_visa_attribute(name: pyvisa.constants.ResourceAttribute, state: Any) pyvisa.constants.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: pyvisa.constants.EventType, handler: Callable[[VISASession, pyvisa.constants.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_RSRC_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_TRIG_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_IO_PROT'>, <class 'pyvisa.attributes.AttrVI_ATTR_GPIB_ADDR_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_GPIB_HS488_CBL_LEN'>, <class 'pyvisa.attributes.AttrVI_ATTR_GPIB_SECONDARY_ADDR'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_INST_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_GPIB_SRQ_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_GPIB_NDAC_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_USER_DATA'>, <class 'pyvisa.attributes.AttrVI_ATTR_GPIB_SYS_CNTRL_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_TERMCHAR'>, <class 'pyvisa.attributes.AttrVI_ATTR_RD_BUF_SIZE'>, <class 'pyvisa.attributes.AttrVI_ATTR_WR_BUF_SIZE'>, <class 'pyvisa.attributes.AttrVI_ATTR_DMA_ALLOW_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_IMPL_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_GPIB_PRIMARY_ADDR'>, <class 'pyvisa.attributes.AttrVI_ATTR_DEV_STATUS_BYTE'>, <class 'pyvisa.attributes.AttrVI_ATTR_GPIB_ATN_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_SPEC_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_MAX_QUEUE_LENGTH'>, <class 'pyvisa.attributes.AttrVI_ATTR_TERMCHAR_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_RD_BUF_OPER_MODE'>, <class 'pyvisa.attributes.AttrVI_ATTR_WR_BUF_OPER_MODE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_TYPE'>, <class 'pyvisa.attributes.AttrVI_ATTR_GPIB_CIC_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_GPIB_REN_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_TMO_VALUE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_LOCK_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_SEND_END_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_FILE_APPEND_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_CLASS'>}

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: pyvisa.constants.EventType, timeout: int, capture_timeout: bool = False) pyvisa.resources.resource.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[[pyvisa.resources.resource.Resource, pyvisa.events.Event, Any], None]) Callable[[VISASession, pyvisa.constants.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: Optional[str] = None, encoding: Optional[str] = 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: Union[Literal['s', 'b', 'c', 'd', 'o', 'x', 'X', 'e', 'E', 'f', 'F', 'g', 'G'], Callable[[str], Any]] = 'f', separator: Union[str, Callable[[Iterable[str]], str]] = ',', termination: Optional[str] = None, encoding: Optional[str] = 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: Optional[str] = None, encoding: Optional[str] = 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.FirewireInstrument(resource_manager: pyvisa.highlevel.ResourceManager, resource_name: str)[source]

Communicates with devices of type VXI::VXI logical address[::INSTR]

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

VXI[board]::VXI logical address[::INSTR]

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

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: pyvisa.constants.EventType, mechanism: pyvisa.constants.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: pyvisa.constants.EventType, mechanism: pyvisa.constants.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: pyvisa.constants.EventType, mechanism: pyvisa.constants.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: pyvisa.constants.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: pyvisa.constants.StatusCode) ContextManager

Ignoring warnings context manager for the current resource.

Parameters

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

implementation_version: pyvisa.attributes.Attribute[int]

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

install_handler(event_type: pyvisa.constants.EventType, handler: Callable[[VISASession, pyvisa.constants.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: pyvisa.attributes.Attribute[int]

Board number for the given interface.

interface_type: pyvisa.attributes.Attribute[pyvisa.constants.InterfaceType]

Interface type of the given session.

property last_status: pyvisa.constants.StatusCode

Last status code for this session.

lock(timeout: Union[float, Literal['default']] = 'default', requested_key: Optional[str] = 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: Union[float, Literal['default']] = 'default', requested_key: Optional[str] = 'exclusive') Iterator[Optional[str]]

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: Union[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: pyvisa.attributes.Attribute[pyvisa.constants.AccessModes]

Current locking state of the resource.

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

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: pyvisa.constants.AddressSpace, offset: int, length: int, data: Iterable[int], width: pyvisa.constants.DataWidth, extended: bool = False) pyvisa.constants.StatusCode

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: pyvisa.constants.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: pyvisa.constants.AddressSpace, offset: int, width: pyvisa.constants.DataWidth, extended: bool = False) int

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: pyvisa.constants.InterfaceType, resource_class: str) Callable[[Type[pyvisa.resources.resource.T]], Type[pyvisa.resources.resource.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: pyvisa.attributes.Attribute[str]

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

property resource_info: pyvisa.highlevel.ResourceInfo

Get the extended information of this resource.

resource_manager: pyvisa.highlevel.ResourceManager

Reference to the resource manager used by this resource

resource_manufacturer_name: pyvisa.attributes.Attribute[str]

Manufacturer name of the vendor that implemented the VISA library.

resource_name: pyvisa.attributes.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: pyvisa.constants.ResourceAttribute, state: Any) pyvisa.constants.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: pyvisa.attributes.Attribute[int]

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

timeout: pyvisa.attributes.Attribute[float]

Timeout in milliseconds for all resource I/O operations.

uninstall_handler(event_type: pyvisa.constants.EventType, handler: Callable[[VISASession, pyvisa.constants.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[pyvisa.attributes.Attribute]]] = {<class 'pyvisa.attributes.AttrVI_ATTR_TMO_VALUE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_SPEC_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_LOCK_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_MAX_QUEUE_LENGTH'>, <class 'pyvisa.attributes.AttrVI_ATTR_USER_DATA'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_INST_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_CLASS'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_IMPL_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_TYPE'>}

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: pyvisa.highlevel.VisaLibraryBase

Reference to the VISA library instance used by the resource

wait_on_event(in_event_type: pyvisa.constants.EventType, timeout: int, capture_timeout: bool = False) pyvisa.resources.resource.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[[pyvisa.resources.resource.Resource, pyvisa.events.Event, Any], None]) Callable[[VISASession, pyvisa.constants.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: pyvisa.constants.AddressSpace, offset: int, data: int, width: pyvisa.constants.DataWidth, extended: bool = False) pyvisa.constants.StatusCode

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.PXIInstrument(resource_manager: pyvisa.highlevel.ResourceManager, resource_name: str)[source]

Communicates with to devices of type PXI::<device>[::INSTR]

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

PXI[bus]::device[::function][::INSTR]

or:

PXI[interface]::bus-device[.function][::INSTR]

or:

PXI[interface]::CHASSISchassis number::SLOTslot number[::FUNCfunction][::INSTR]

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

allow_dma: Attribute[bool]

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

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.

destination_increment: Attribute[int]

Number of elements by which to increment the destination offset after a transfer.

disable_event(event_type: pyvisa.constants.EventType, mechanism: pyvisa.constants.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: pyvisa.constants.EventType, mechanism: pyvisa.constants.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: pyvisa.constants.EventType, mechanism: pyvisa.constants.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: pyvisa.constants.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: pyvisa.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: pyvisa.constants.EventType, handler: Callable[[VISASession, pyvisa.constants.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: pyvisa.constants.StatusCode

Last status code for this session.

lock(timeout: Union[float, Literal['default']] = 'default', requested_key: Optional[str] = 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: Union[float, Literal['default']] = 'default', requested_key: Optional[str] = 'exclusive') Iterator[Optional[str]]

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: Union[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: pyvisa.attributes.Attribute[int]

Manufacturer identification number of the device.

manufacturer_name: pyvisa.attributes.Attribute[str]

Manufacturer name.

model_code: pyvisa.attributes.Attribute[int]

Model code for the device.

model_name: pyvisa.attributes.Attribute[str]

Model name of the device.

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

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: pyvisa.constants.AddressSpace, offset: int, length: int, data: Iterable[int], width: pyvisa.constants.DataWidth, extended: bool = False) pyvisa.constants.StatusCode

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: pyvisa.constants.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: pyvisa.constants.AddressSpace, offset: int, width: pyvisa.constants.DataWidth, extended: bool = False) int

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: pyvisa.constants.InterfaceType, resource_class: str) Callable[[Type[pyvisa.resources.resource.T]], Type[pyvisa.resources.resource.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: pyvisa.highlevel.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: pyvisa.constants.ResourceAttribute, state: Any) pyvisa.constants.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

source_increment: Attribute[int]

Number of elements by which to increment the source offset after a transfer.

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: pyvisa.constants.EventType, handler: Callable[[VISASession, pyvisa.constants.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_PXI_DSTAR_SET'>, <class 'pyvisa.attributes.AttrVI_ATTR_MODEL_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_SLOT'>, <class 'pyvisa.attributes.AttrVI_ATTR_SRC_INCREMENT'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_PXI_MEM_SIZE_BAR1'>, <class 'pyvisa.attributes.AttrVI_ATTR_PXI_SLOT_LBUS_LEFT'>, <class 'pyvisa.attributes.AttrVI_ATTR_TRIG_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_PXI_MEM_TYPE_BAR1'>, <class 'pyvisa.attributes.AttrVI_ATTR_PXI_DEV_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_PXI_SLOTPATH'>, <class 'pyvisa.attributes.AttrVI_ATTR_PXI_MEM_SIZE_BAR4'>, <class 'pyvisa.attributes.AttrVI_ATTR_PXI_MEM_BASE_BAR0'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_INST_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_PXI_ACTUAL_LWIDTH'>, <class 'pyvisa.attributes.AttrVI_ATTR_PXI_STAR_TRIG_LINE'>, <class 'pyvisa.attributes.AttrVI_ATTR_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_WIN_SIZE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_PXI_MEM_TYPE_BAR4'>, <class 'pyvisa.attributes.AttrVI_ATTR_USER_DATA'>, <class 'pyvisa.attributes.AttrVI_ATTR_PXI_MEM_BASE_BAR3'>, <class 'pyvisa.attributes.AttrVI_ATTR_PXI_CHASSIS'>, <class 'pyvisa.attributes.AttrVI_ATTR_DMA_ALLOW_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_PXI_MEM_SIZE_BAR2'>, <class 'pyvisa.attributes.AttrVI_ATTR_PXI_SLOT_LWIDTH'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_IMPL_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_PXI_MAX_LWIDTH'>, <class 'pyvisa.attributes.AttrVI_ATTR_PXI_STAR_TRIG_BUS'>, <class 'pyvisa.attributes.AttrVI_ATTR_PXI_MEM_TYPE_BAR2'>, <class 'pyvisa.attributes.AttrVI_ATTR_WIN_BASE_ADDR'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_SPEC_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_PXI_IS_EXPRESS'>, <class 'pyvisa.attributes.AttrVI_ATTR_MAX_QUEUE_LENGTH'>, <class 'pyvisa.attributes.AttrVI_ATTR_PXI_MEM_BASE_BAR1'>, <class 'pyvisa.attributes.AttrVI_ATTR_PXI_MEM_SIZE_BAR0'>, <class 'pyvisa.attributes.AttrVI_ATTR_PXI_BUS_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_TYPE'>, <class 'pyvisa.attributes.AttrVI_ATTR_PXI_MEM_BASE_BAR4'>, <class 'pyvisa.attributes.AttrVI_ATTR_PXI_TRIG_BUS'>, <class 'pyvisa.attributes.AttrVI_ATTR_MODEL_CODE'>, <class 'pyvisa.attributes.AttrVI_ATTR_WIN_ACCESS'>, <class 'pyvisa.attributes.AttrVI_ATTR_TMO_VALUE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_LOCK_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_PXI_MEM_TYPE_BAR0'>, <class 'pyvisa.attributes.AttrVI_ATTR_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_PXI_SLOT_LBUS_RIGHT'>, <class 'pyvisa.attributes.AttrVI_ATTR_PXI_MEM_SIZE_BAR3'>, <class 'pyvisa.attributes.AttrVI_ATTR_DEST_INCREMENT'>, <class 'pyvisa.attributes.AttrVI_ATTR_PXI_DSTAR_BUS'>, <class 'pyvisa.attributes.AttrVI_ATTR_PXI_MEM_TYPE_BAR3'>, <class 'pyvisa.attributes.AttrVI_ATTR_PXI_FUNC_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_PXI_MEM_BASE_BAR2'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_CLASS'>}

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: pyvisa.constants.EventType, timeout: int, capture_timeout: bool = False) pyvisa.resources.resource.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[[pyvisa.resources.resource.Resource, pyvisa.events.Event, Any], None]) Callable[[VISASession, pyvisa.constants.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: pyvisa.constants.AddressSpace, offset: int, data: int, width: pyvisa.constants.DataWidth, extended: bool = False) pyvisa.constants.StatusCode

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.PXIMemory(resource_manager: pyvisa.highlevel.ResourceManager, resource_name: str)[source]

Communicates with to devices of type PXI[interface]::MEMACC

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

allow_dma: pyvisa.attributes.Attribute[bool]

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

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.

destination_increment: pyvisa.attributes.Attribute[int]

Number of elements by which to increment the destination offset after a transfer.

disable_event(event_type: pyvisa.constants.EventType, mechanism: pyvisa.constants.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: pyvisa.constants.EventType, mechanism: pyvisa.constants.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: pyvisa.constants.EventType, mechanism: pyvisa.constants.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: pyvisa.constants.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: pyvisa.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: pyvisa.constants.EventType, handler: Callable[[VISASession, pyvisa.constants.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: pyvisa.constants.StatusCode

Last status code for this session.

lock(timeout: Union[float, Literal['default']] = 'default', requested_key: Optional[str] = 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: Union[float, Literal['default']] = 'default', requested_key: Optional[str] = 'exclusive') Iterator[Optional[str]]

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: Union[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: pyvisa.constants.AddressSpace, offset: int, length: int, width: pyvisa.constants.DataWidth, extended: bool = False) List[int]

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: pyvisa.constants.AddressSpace, offset: int, length: int, data: Iterable[int], width: pyvisa.constants.DataWidth, extended: bool = False) pyvisa.constants.StatusCode

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: pyvisa.constants.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: pyvisa.constants.AddressSpace, offset: int, width: pyvisa.constants.DataWidth, extended: bool = False) int

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: pyvisa.constants.InterfaceType, resource_class: str) Callable[[Type[pyvisa.resources.resource.T]], Type[pyvisa.resources.resource.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: pyvisa.highlevel.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: pyvisa.constants.ResourceAttribute, state: Any) pyvisa.constants.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

source_increment: pyvisa.attributes.Attribute[int]

Number of elements by which to increment the source offset after a transfer.

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: pyvisa.constants.EventType, handler: Callable[[VISASession, pyvisa.constants.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_WIN_ACCESS'>, <class 'pyvisa.attributes.AttrVI_ATTR_WIN_SIZE'>, <class 'pyvisa.attributes.AttrVI_ATTR_TMO_VALUE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_SPEC_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_LOCK_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_WIN_BASE_ADDR'>, <class 'pyvisa.attributes.AttrVI_ATTR_MAX_QUEUE_LENGTH'>, <class 'pyvisa.attributes.AttrVI_ATTR_USER_DATA'>, <class 'pyvisa.attributes.AttrVI_ATTR_SRC_INCREMENT'>, <class 'pyvisa.attributes.AttrVI_ATTR_DEST_INCREMENT'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_INST_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_CLASS'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_IMPL_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_TYPE'>}

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: pyvisa.constants.EventType, timeout: int, capture_timeout: bool = False) pyvisa.resources.resource.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[[pyvisa.resources.resource.Resource, pyvisa.events.Event, Any], None]) Callable[[VISASession, pyvisa.constants.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: pyvisa.constants.AddressSpace, offset: int, data: int, width: pyvisa.constants.DataWidth, extended: bool = False) pyvisa.constants.StatusCode

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.VXIInstrument(resource_manager: pyvisa.highlevel.ResourceManager, resource_name: str)[source]

Communicates with to devices of type VXI::VXI logical address[::INSTR]

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

VXI[board]::VXI logical address[::INSTR]

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

allow_dma: Attribute[bool]

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

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.

destination_increment: Attribute[int]

Number of elements by which to increment the destination offset after a transfer.

disable_event(event_type: pyvisa.constants.EventType, mechanism: pyvisa.constants.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: pyvisa.constants.EventType, mechanism: pyvisa.constants.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: pyvisa.constants.EventType, mechanism: pyvisa.constants.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: pyvisa.constants.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: pyvisa.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: pyvisa.constants.EventType, handler: Callable[[VISASession, pyvisa.constants.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: pyvisa.attributes.Attribute[pyvisa.constants.IOProtocol]

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

is_4882_compliant: pyvisa.attributes.Attribute[bool]

Whether the device is 488.2 compliant.

property last_status: pyvisa.constants.StatusCode

Last status code for this session.

lock(timeout: Union[float, Literal['default']] = 'default', requested_key: Optional[str] = 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: Union[float, Literal['default']] = 'default', requested_key: Optional[str] = 'exclusive') Iterator[Optional[str]]

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: Union[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: pyvisa.attributes.Attribute[int]

Manufacturer identification number of the device.

manufacturer_name: pyvisa.attributes.Attribute[str]

Manufacturer name.

model_code: pyvisa.attributes.Attribute[int]

Model code for the device.

model_name: pyvisa.attributes.Attribute[str]

Model name of the device.

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

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: pyvisa.constants.AddressSpace, offset: int, length: int, data: Iterable[int], width: pyvisa.constants.DataWidth, extended: bool = False) pyvisa.constants.StatusCode

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: pyvisa.constants.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: pyvisa.constants.AddressSpace, offset: int, width: pyvisa.constants.DataWidth, extended: bool = False) int

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: pyvisa.constants.InterfaceType, resource_class: str) Callable[[Type[pyvisa.resources.resource.T]], Type[pyvisa.resources.resource.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: pyvisa.highlevel.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: pyvisa.attributes.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: pyvisa.constants.ResourceAttribute, state: Any) pyvisa.constants.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

source_increment: Attribute[int]

Number of elements by which to increment the source offset after a transfer.

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: pyvisa.constants.EventType, handler: Callable[[VISASession, pyvisa.constants.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_MODEL_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_SLOT'>, <class 'pyvisa.attributes.AttrVI_ATTR_SRC_INCREMENT'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_TRIG_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_IO_PROT'>, <class 'pyvisa.attributes.AttrVI_ATTR_FDC_USE_PAIR'>, <class 'pyvisa.attributes.AttrVI_ATTR_MEM_SPACE'>, <class 'pyvisa.attributes.AttrVI_ATTR_DEST_ACCESS_PRIV'>, <class 'pyvisa.attributes.AttrVI_ATTR_WIN_ACCESS_PRIV'>, <class 'pyvisa.attributes.AttrVI_ATTR_VXI_TRIG_LINES_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_INST_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_4882_COMPLIANT'>, <class 'pyvisa.attributes.AttrVI_ATTR_WIN_SIZE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_USER_DATA'>, <class 'pyvisa.attributes.AttrVI_ATTR_TERMCHAR'>, <class 'pyvisa.attributes.AttrVI_ATTR_RD_BUF_SIZE'>, <class 'pyvisa.attributes.AttrVI_ATTR_CMDR_LA'>, <class 'pyvisa.attributes.AttrVI_ATTR_IMMEDIATE_SERV'>, <class 'pyvisa.attributes.AttrVI_ATTR_WR_BUF_SIZE'>, <class 'pyvisa.attributes.AttrVI_ATTR_SRC_BYTE_ORDER'>, <class 'pyvisa.attributes.AttrVI_ATTR_VXI_TRIG_DIR'>, <class 'pyvisa.attributes.AttrVI_ATTR_DMA_ALLOW_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_IMPL_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_WIN_BASE_ADDR'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_SPEC_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_MAX_QUEUE_LENGTH'>, <class 'pyvisa.attributes.AttrVI_ATTR_TERMCHAR_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_RD_BUF_OPER_MODE'>, <class 'pyvisa.attributes.AttrVI_ATTR_FDC_MODE'>, <class 'pyvisa.attributes.AttrVI_ATTR_VXI_LA'>, <class 'pyvisa.attributes.AttrVI_ATTR_MEM_BASE'>, <class 'pyvisa.attributes.AttrVI_ATTR_WR_BUF_OPER_MODE'>, <class 'pyvisa.attributes.AttrVI_ATTR_SRC_ACCESS_PRIV'>, <class 'pyvisa.attributes.AttrVI_ATTR_VXI_TRIG_SUPPORT'>, <class 'pyvisa.attributes.AttrVI_ATTR_VXI_DEV_CLASS'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_TYPE'>, <class 'pyvisa.attributes.AttrVI_ATTR_MODEL_CODE'>, <class 'pyvisa.attributes.AttrVI_ATTR_WIN_ACCESS'>, <class 'pyvisa.attributes.AttrVI_ATTR_TMO_VALUE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_LOCK_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_SEND_END_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_DEST_INCREMENT'>, <class 'pyvisa.attributes.AttrVI_ATTR_SUPPRESS_END_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_FILE_APPEND_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_FDC_CHNL'>, <class 'pyvisa.attributes.AttrVI_ATTR_MAINFRAME_LA'>, <class 'pyvisa.attributes.AttrVI_ATTR_MEM_SIZE'>, <class 'pyvisa.attributes.AttrVI_ATTR_DEST_BYTE_ORDER'>, <class 'pyvisa.attributes.AttrVI_ATTR_WIN_BYTE_ORDER'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_CLASS'>}

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: pyvisa.constants.EventType, timeout: int, capture_timeout: bool = False) pyvisa.resources.resource.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[[pyvisa.resources.resource.Resource, pyvisa.events.Event, Any], None]) Callable[[VISASession, pyvisa.constants.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: pyvisa.constants.AddressSpace, offset: int, data: int, width: pyvisa.constants.DataWidth, extended: bool = False) pyvisa.constants.StatusCode

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.VXIMemory(resource_manager: pyvisa.highlevel.ResourceManager, resource_name: str)[source]

Communicates with to devices of type VXI[board]::MEMACC

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

VXI[board]::MEMACC

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

allow_dma: pyvisa.attributes.Attribute[bool]

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

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.

destination_increment: pyvisa.attributes.Attribute[int]

Number of elements by which to increment the destination offset after a transfer.

disable_event(event_type: pyvisa.constants.EventType, mechanism: pyvisa.constants.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: pyvisa.constants.EventType, mechanism: pyvisa.constants.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: pyvisa.constants.EventType, mechanism: pyvisa.constants.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: pyvisa.constants.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: pyvisa.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: pyvisa.constants.EventType, handler: Callable[[VISASession, pyvisa.constants.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: pyvisa.constants.StatusCode

Last status code for this session.

lock(timeout: Union[float, Literal['default']] = 'default', requested_key: Optional[str] = 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: Union[float, Literal['default']] = 'default', requested_key: Optional[str] = 'exclusive') Iterator[Optional[str]]

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: Union[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: pyvisa.constants.AddressSpace, offset: int, length: int, width: pyvisa.constants.DataWidth, extended: bool = False) List[int]

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: pyvisa.constants.AddressSpace, offset: int, length: int, data: Iterable[int], width: pyvisa.constants.DataWidth, extended: bool = False) pyvisa.constants.StatusCode

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: pyvisa.constants.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: pyvisa.constants.AddressSpace, offset: int, width: pyvisa.constants.DataWidth, extended: bool = False) int

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: pyvisa.constants.InterfaceType, resource_class: str) Callable[[Type[pyvisa.resources.resource.T]], Type[pyvisa.resources.resource.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: pyvisa.highlevel.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: pyvisa.constants.ResourceAttribute, state: Any) pyvisa.constants.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

source_increment: pyvisa.attributes.Attribute[int]

Number of elements by which to increment the source offset after a transfer.

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: pyvisa.constants.EventType, handler: Callable[[VISASession, pyvisa.constants.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_SRC_INCREMENT'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_DEST_ACCESS_PRIV'>, <class 'pyvisa.attributes.AttrVI_ATTR_WIN_ACCESS_PRIV'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_INST_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_WIN_SIZE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_USER_DATA'>, <class 'pyvisa.attributes.AttrVI_ATTR_SRC_BYTE_ORDER'>, <class 'pyvisa.attributes.AttrVI_ATTR_DMA_ALLOW_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_IMPL_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_WIN_BASE_ADDR'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_SPEC_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_MAX_QUEUE_LENGTH'>, <class 'pyvisa.attributes.AttrVI_ATTR_VXI_LA'>, <class 'pyvisa.attributes.AttrVI_ATTR_SRC_ACCESS_PRIV'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_TYPE'>, <class 'pyvisa.attributes.AttrVI_ATTR_WIN_ACCESS'>, <class 'pyvisa.attributes.AttrVI_ATTR_TMO_VALUE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_LOCK_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_DEST_INCREMENT'>, <class 'pyvisa.attributes.AttrVI_ATTR_DEST_BYTE_ORDER'>, <class 'pyvisa.attributes.AttrVI_ATTR_WIN_BYTE_ORDER'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_CLASS'>}

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: pyvisa.constants.EventType, timeout: int, capture_timeout: bool = False) pyvisa.resources.resource.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[[pyvisa.resources.resource.Resource, pyvisa.events.Event, Any], None]) Callable[[VISASession, pyvisa.constants.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: pyvisa.constants.AddressSpace, offset: int, data: int, width: pyvisa.constants.DataWidth, extended: bool = False) pyvisa.constants.StatusCode

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.VXIBackplane(resource_manager: pyvisa.highlevel.ResourceManager, resource_name: str)[source]

Communicates with to devices of type VXI::BACKPLANE

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

VXI[board][::VXI logical address]::BACKPLANE

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

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: pyvisa.constants.EventType, mechanism: pyvisa.constants.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: pyvisa.constants.EventType, mechanism: pyvisa.constants.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: pyvisa.constants.EventType, mechanism: pyvisa.constants.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: pyvisa.constants.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: pyvisa.constants.StatusCode) ContextManager

Ignoring warnings context manager for the current resource.

Parameters

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

implementation_version: pyvisa.attributes.Attribute[int]

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

install_handler(event_type: pyvisa.constants.EventType, handler: Callable[[VISASession, pyvisa.constants.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: pyvisa.attributes.Attribute[int]

Board number for the given interface.

interface_type: pyvisa.attributes.Attribute[pyvisa.constants.InterfaceType]

Interface type of the given session.

property last_status: pyvisa.constants.StatusCode

Last status code for this session.

lock(timeout: Union[float, Literal['default']] = 'default', requested_key: Optional[str] = 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: Union[float, Literal['default']] = 'default', requested_key: Optional[str] = 'exclusive') Iterator[Optional[str]]

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: Union[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: pyvisa.attributes.Attribute[pyvisa.constants.AccessModes]

Current locking state of the resource.

open(access_mode: pyvisa.constants.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.

classmethod register(interface_type: pyvisa.constants.InterfaceType, resource_class: str) Callable[[Type[pyvisa.resources.resource.T]], Type[pyvisa.resources.resource.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: pyvisa.attributes.Attribute[str]

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

property resource_info: pyvisa.highlevel.ResourceInfo

Get the extended information of this resource.

resource_manager: pyvisa.highlevel.ResourceManager

Reference to the resource manager used by this resource

resource_manufacturer_name: pyvisa.attributes.Attribute[str]

Manufacturer name of the vendor that implemented the VISA library.

resource_name: pyvisa.attributes.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: pyvisa.constants.ResourceAttribute, state: Any) pyvisa.constants.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: pyvisa.attributes.Attribute[int]

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

timeout: pyvisa.attributes.Attribute[float]

Timeout in milliseconds for all resource I/O operations.

uninstall_handler(event_type: pyvisa.constants.EventType, handler: Callable[[VISASession, pyvisa.constants.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[pyvisa.attributes.Attribute]]] = {<class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_TRIG_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_INST_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_USER_DATA'>, <class 'pyvisa.attributes.AttrVI_ATTR_VXI_VME_SYSFAIL_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_IMPL_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_SPEC_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_MAX_QUEUE_LENGTH'>, <class 'pyvisa.attributes.AttrVI_ATTR_VXI_TRIG_SUPPORT'>, <class 'pyvisa.attributes.AttrVI_ATTR_VXI_TRIG_STATUS'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_TYPE'>, <class 'pyvisa.attributes.AttrVI_ATTR_TMO_VALUE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_LOCK_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_MAINFRAME_LA'>, <class 'pyvisa.attributes.AttrVI_ATTR_VXI_VME_INTR_STATUS'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_CLASS'>}

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: pyvisa.highlevel.VisaLibraryBase

Reference to the VISA library instance used by the resource

wait_on_event(in_event_type: pyvisa.constants.EventType, timeout: int, capture_timeout: bool = False) pyvisa.resources.resource.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[[pyvisa.resources.resource.Resource, pyvisa.events.Event, Any], None]) Callable[[VISASession, pyvisa.constants.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.