Visa Library

class pyvisa.highlevel.VisaLibraryBase(library_path: str | LibraryPath = '')[source]

Base for VISA library classes.

A class derived from VisaLibraryBase library provides the low-level communication to the underlying devices providing Pythonic wrappers to VISA functions. But not all derived class must/will implement all methods. Even if methods are expected to return the status code they are expected to raise the appropriate exception when an error occurred since this is more Pythonic.

The default VisaLibrary class is pyvisa.ctwrapper.highlevel.IVIVisaLibrary, which implements a ctypes wrapper around the IVI-VISA library. Certainly, IVI-VISA can be NI-VISA, Keysight VISA, R&S VISA, tekVISA etc.

In general, you should not instantiate it directly. The object exposed to the user is the pyvisa.highlevel.ResourceManager. If needed, you can access the VISA library from it:

>>> import pyvisa
>>> rm = pyvisa.ResourceManager("/path/to/my/libvisa.so.7")
>>> lib = rm.visalib
assert_interrupt_signal(session: VISASession, mode: AssertSignalInterrupt, status_id: int) StatusCode[source]

Asserts the specified interrupt or signal.

Corresponds to viAssertIntrSignal function of the VISA library.

Parameters:
  • session (VISASession) – Unique logical identifier to a session.

  • mode (constants.AssertSignalInterrupt) – How to assert the interrupt.

  • status_id (int) – Status value to be presented during an interrupt acknowledge cycle.

Returns:

Return value of the library call.

Return type:

StatusCode

assert_trigger(session: VISASession, protocol: TriggerProtocol) StatusCode[source]

Assert software or hardware trigger.

Corresponds to viAssertTrigger function of the VISA library.

Parameters:
  • session (VISASession) – Unique logical identifier to a session.

  • protocol (constants.TriggerProtocol) – Trigger protocol to use during assertion.

Returns:

Return value of the library call.

Return type:

StatusCode

assert_utility_signal(session: VISASession, line: UtilityBusSignal) StatusCode[source]

Assert or deassert the specified utility bus signal.

Corresponds to viAssertUtilSignal function of the VISA library.

Parameters:
  • session (VISASession) – Unique logical identifier to a session.

  • line (constants.UtilityBusSignal) – Specifies the utility bus signal to assert.

Returns:

Return value of the library call.

Return type:

StatusCode

buffer_read(session: VISASession, count: int) Tuple[bytes, StatusCode][source]

Reads data through the use of a formatted I/O read buffer.

The data can be read from a device or an interface.

Corresponds to viBufRead function of the VISA library.

Parameters:
  • session (VISASession Unique logical identifier to a session.) –

  • count (int) – Number of bytes to be read.

Returns:

  • dbytes – Data read

  • StatusCode – Return value of the library call.

buffer_write(session: VISASession, data: bytes) Tuple[int, StatusCode][source]

Writes data to a formatted I/O write buffer synchronously.

Corresponds to viBufWrite function of the VISA library.

Parameters:
  • session (VISASession) – Unique logical identifier to a session.

  • data (bytes) – Data to be written.

Returns:

  • int – number of written bytes

  • StatusCode – return value of the library call.

clear(session: VISASession) StatusCode[source]

Clears a device.

Corresponds to viClear function of the VISA library.

Parameters:

session (VISASession) – Unique logical identifier to a session.

Returns:

Return value of the library call.

Return type:

StatusCode

close(session: VISASession | VISAEventContext | VISARMSession) StatusCode[source]

Closes the specified session, event, or find list.

Corresponds to viClose function of the VISA library.

Parameters:

session (Union[VISASession, VISAEventContext, VISARMSession]) – Unique logical identifier to a session, event, resource manager.

Returns:

Return value of the library call.

Return type:

StatusCode

disable_event(session: VISASession, event_type: EventType, mechanism: EventMechanism) StatusCode[source]

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

Corresponds to viDisableEvent function of the VISA library.

Parameters:
  • session (VISASession) – Unique logical identifier to a session.

  • event_type (constants.EventType) – Event type.

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

Returns:

Return value of the library call.

Return type:

StatusCode

discard_events(session: VISASession, event_type: EventType, mechanism: EventMechanism) StatusCode[source]

Discard event occurrences for a given type and mechanisms in a session.

Corresponds to viDiscardEvents function of the VISA library.

Parameters:
  • session (VISASession) – Unique logical identifier to a session.

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

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

Returns:

Return value of the library call.

Return type:

StatusCode

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

Enable event occurrences for specified event types and mechanisms in a session.

Corresponds to viEnableEvent function of the VISA library.

Parameters:
  • session (VISASession) – Unique logical identifier to a session.

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

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

  • context (None, optional) – Unused parameter…

Returns:

Return value of the library call.

Return type:

StatusCode

flush(session: VISASession, mask: BufferOperation) StatusCode[source]

Flush the specified buffers.

The buffers can be associated with formatted I/O operations and/or serial communication.

Corresponds to viFlush function of the VISA library.

Parameters:
  • session (VISASession) – Unique logical identifier to a session.

  • mask (constants.BufferOperation) – Specifies the action to be taken with flushing the buffer. The values can be combined using the | operator. However multiple operations on a single buffer cannot be combined.

Returns:

Return value of the library call.

Return type:

StatusCode

get_attribute(session: VISASession | VISAEventContext | VISARMSession, attribute: ResourceAttribute | EventAttribute) Tuple[Any, StatusCode][source]

Retrieves the state of an attribute.

Corresponds to viGetAttribute function of the VISA library.

Parameters:
  • session (Union[VISASession, VISAEventContext]) – Unique logical identifier to a session, event, or find list.

  • attribute (Union[constants.ResourceAttribute, constants.EventAttribute]) – Resource or event attribute for which the state query is made.

Returns:

  • Any – State of the queried attribute for a specified resource

  • StatusCode – Return value of the library call.

get_buffer_from_id(job_id: VISAJobID) SupportsBytes | None[source]

Retrieve the buffer associated with a job id created in read_asynchronously

Parameters:

job_id (VISAJobID) – Id of the job for which to retrieve the buffer.

Returns:

Buffer in which the data are stored or None if the job id is not associated with any job.

Return type:

Optional[SupportsBytes]

static get_debug_info() List[str] | Dict[str, Any][source]

Override to return an iterable of lines with the backend debug details.

get_last_status_in_session(session: VISASession | VISARMSession) StatusCode[source]

Last status in session.

Helper function to be called by resources properties.

static get_library_paths() Iterable[LibraryPath][source]

Override to list the possible library_paths if no path is specified.

gpib_command(session: VISASession, data: bytes) Tuple[int, StatusCode][source]

Write GPIB command bytes on the bus.

Corresponds to viGpibCommand function of the VISA library.

Parameters:
  • session (VISASession) – Unique logical identifier to a session.

  • data (bytes) – Data to write.

Returns:

  • int – Number of written bytes

  • StatusCode – Return value of the library call.

gpib_control_atn(session: VISASession, mode: ATNLineOperation) StatusCode[source]

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

Corresponds to viGpibControlATN function of the VISA library.

Parameters:
  • session (VISASession) – Unique logical identifier to a session.

  • mode (constants.ATNLineOperation) – State of the ATN line and optionally the local active controller state.

Returns:

Return value of the library call.

Return type:

StatusCode

gpib_control_ren(session: VISASession, mode: RENLineOperation) StatusCode[source]

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

Optionally the remote/local state of the device can also be set.

Corresponds to viGpibControlREN function of the VISA library.

Parameters:
  • session (VISASession) – Unique logical identifier to a session.

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

Returns:

Return value of the library call.

Return type:

StatusCode

gpib_pass_control(session: VISASession, primary_address: int, secondary_address: int) StatusCode[source]

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

Corresponds to viGpibPassControl function of the VISA library.

Parameters:
  • session (VISASession) – Unique logical identifier to a session.

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

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

Returns:

Return value of the library call.

Return type:

StatusCode

gpib_send_ifc(session: VISASession) StatusCode[source]

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

Corresponds to viGpibSendIFC function of the VISA library.

Parameters:

session (VISASession) – Unique logical identifier to a session.

Returns:

Return value of the library call.

Return type:

StatusCode

handle_return_value(session: VISAEventContext | VISARMSession | VISASession | None, status_code: int) StatusCode[source]

Helper function handling the return code of a low-level operation.

Used when implementing concrete subclasses of VISALibraryBase.

handlers: DefaultDict[VISASession, List[Tuple[Callable[[VISASession, EventType, VISAEventContext, Any], None], Any, Any, Any]]]

Contains all installed event handlers. Its elements are tuples with four elements: The handler itself (a Python callable), the user handle (in any format making sense to the lower level implementation, ie as a ctypes object for the ctypes backend) and the handler again, this time in a format meaningful to the backend (ie as a ctypes object created with CFUNCTYPE for the ctypes backend) and the event type.

ignore_warning(session: VISASession | VISARMSession, *warnings_constants: StatusCode) Iterator[source]

Ignore warnings for a session for the duration of the context.

Parameters:
  • session (Union[VISASession, VISARMSession]) – Unique logical identifier to a session.

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

in_16(session: VISASession, space: AddressSpace, offset: int, extended: bool = False) Tuple[int, StatusCode][source]

Reads in an 16-bit value from the specified memory space and offset.

Corresponds to viIn16* function of the VISA library.

Parameters:
  • session (VISASession) – Unique logical identifier to a session.

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

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

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

Returns:

  • int – Data read from memory

  • StatusCode – Return value of the library call.

in_32(session: VISASession, space: AddressSpace, offset: int, extended: bool = False) Tuple[int, StatusCode][source]

Reads in an 32-bit value from the specified memory space and offset.

Corresponds to viIn32* function of the VISA library.

Parameters:
  • session (VISASession) – Unique logical identifier to a session.

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

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

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

Returns:

  • int – Data read from memory

  • StatusCode – Return value of the library call.

in_64(session: VISASession, space: AddressSpace, offset: int, extended: bool = False) Tuple[int, StatusCode][source]

Reads in an 64-bit value from the specified memory space and offset.

Corresponds to viIn64* function of the VISA library.

Parameters:
  • session (VISASession) – Unique logical identifier to a session.

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

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

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

Returns:

  • int – Data read from memory

  • StatusCode – Return value of the library call.

in_8(session: VISASession, space: AddressSpace, offset: int, extended: bool = False) Tuple[int, StatusCode][source]

Reads in an 8-bit value from the specified memory space and offset.

Corresponds to viIn8* function of the VISA library.

Parameters:
  • session (VISASession) – Unique logical identifier to a session.

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

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

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

Returns:

  • int – Data read from memory

  • StatusCode – Return value of the library call.

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

Install handlers for event callbacks.

Corresponds to viInstallHandler function of the VISA library.

Parameters:
  • session (VISASession) – Unique logical identifier to a session.

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

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

  • user_handle (Any) – Value specified by an application that can be used for identifying handlers uniquely for an event type.

Returns:

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

  • converted_user_handle – Converted user handle to match the underlying library. This version of the handle should be used in further call to the library.

  • converted_handler – Converted version of the handler satisfying to backend library.

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

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

Installs handlers for event callbacks.

Parameters:
  • session (VISASession) – Unique logical identifier to a session.

  • event_type (constants.EventType,) – Logical event identifier.

  • handler (VISAHandler) – Handler 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.

Returns:

Converted user handle to match the underlying library. This version of the handle should be used in further call to the library.

Return type:

converted_user_handle

issue_warning_on: Set[StatusCode]

Set error codes on which to issue a warning.

property last_status: StatusCode

Last return value of the library.

library_path: LibraryPath

Path to the VISA library used by this instance

list_resources(session: VISARMSession, query: str = '?*::INSTR') Tuple[str, ...][source]

Return a tuple of all connected devices matching query.

Parameters:
  • session (VISARMSession) – Unique logical identifier to the resource manager session.

  • query (str) – Regular expression used to match devices.

Returns:

Resource names of all the connected devices matching the query.

Return type:

Tuple[str, …]

lock(session: VISASession, lock_type: Lock, timeout: int, requested_key: str | None = None) Tuple[str, StatusCode][source]

Establishes an access mode to the specified resources.

Corresponds to viLock function of the VISA library.

Parameters:
  • session (VISASession) – Unique logical identifier to a session.

  • lock_type (constants.Lock) – Specifies the type of lock requested.

  • timeout (int) – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error.

  • requested_key (Optional[str], optional) – Requested locking key in the case of a shared lock. For an exclusive lock it should be None.

Returns:

  • Optional[str] – Key that can then be passed to other sessions to share the lock, or None for an exclusive lock.

  • StatusCode – Return value of the library call.

map_address(session: VISASession, map_space: AddressSpace, map_base: int, map_size: int, access: Literal[False] = False, suggested: int | None = None) Tuple[int, StatusCode][source]

Maps the specified memory space into the process’s address space.

Corresponds to viMapAddress function of the VISA library.

Parameters:
  • session (VISASession) – Unique logical identifier to a session.

  • map_space (constants.AddressSpace) – Specifies the address space to map.

  • map_base (int) – Offset (in bytes) of the memory to be mapped.

  • map_size (int) – Amount of memory to map (in bytes).

  • access (False) – Unused parameter.

  • suggested (Optional[int], optional) – If not None, the operating system attempts to map the memory to the address specified. There is no guarantee, however, that the memory will be mapped to that address. This operation may map the memory into an address region different from the suggested one.

Returns:

  • int – Address in your process space where the memory was mapped

  • StatusCode – Return value of the library call.

map_trigger(session: VISASession, trigger_source: InputTriggerLine, trigger_destination: OutputTriggerLine, mode: None = None) StatusCode[source]

Map the specified trigger source line to the specified destination line.

Corresponds to viMapTrigger function of the VISA library.

Parameters:
  • session (VISASession) – Unique logical identifier to a session.

  • trigger_source (constants.InputTriggerLine) – Source line from which to map.

  • trigger_destination (constants.OutputTriggerLine) – Destination line to which to map.

  • mode (None, optional) – Always None for this version of the VISA specification.

Returns:

Return value of the library call.

Return type:

StatusCode

memory_allocation(session: VISASession, size: int, extended: bool = False) Tuple[int, StatusCode][source]

Allocate memory from a resource’s memory region.

Corresponds to viMemAlloc* functions of the VISA library.

Parameters:
  • session (VISASession) – Unique logical identifier to a session.

  • size (int) – Specifies the size of the allocation.

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

Returns:

  • int – offset of the allocated memory

  • StatusCode – Return value of the library call.

memory_free(session: VISASession, offset: int, extended: bool = False) StatusCode[source]

Frees memory previously allocated using the memory_allocation() operation.

Corresponds to viMemFree* function of the VISA library.

Parameters:
  • session (VISASession) – Unique logical identifier to a session.

  • offset (int) – Offset of the memory to free.

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

Returns:

Return value of the library call.

Return type:

StatusCode

move(session: VISASession, source_space: AddressSpace, source_offset: int, source_width: DataWidth, destination_space: AddressSpace, destination_offset: int, destination_width: DataWidth, length: int) StatusCode[source]

Moves a block of data.

Corresponds to viMove function of the VISA library.

Parameters:
  • session (VISASession) – Unique logical identifier to a session.

  • source_space (constants.AddressSpace) – Specifies the address space of the source.

  • source_offset (int) – Offset of the starting address or register from which to read.

  • source_width (constants.DataWidth) – Specifies the data width of the source.

  • destination_space (constants.AddressSpace) – Specifies the address space of the destination.

  • destination_offset (int) – Offset of the starting address or register to which to write.

  • destination_width (constants.DataWidth) – Specifies the data width of the destination.

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

Returns:

Return value of the library call.

Return type:

StatusCode

move_asynchronously(session: VISASession, source_space: AddressSpace, source_offset: int, source_width: DataWidth, destination_space: AddressSpace, destination_offset: int, destination_width: DataWidth, length: int) Tuple[VISAJobID, StatusCode][source]

Moves a block of data asynchronously.

Corresponds to viMoveAsync function of the VISA library.

Parameters:
  • session (VISASession) – Unique logical identifier to a session.

  • source_space (constants.AddressSpace) – Specifies the address space of the source.

  • source_offset (int) – Offset of the starting address or register from which to read.

  • source_width (constants.DataWidth) – Specifies the data width of the source.

  • destination_space (constants.AddressSpace) – Specifies the address space of the destination.

  • destination_offset (int) – Offset of the starting address or register to which to write.

  • destination_width (constants.DataWidth) – Specifies the data width of the destination.

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

Returns:

  • VISAJobID – Job identifier of this asynchronous move operation

  • StatusCode – Return value of the library call.

move_in(session: VISASession, space: AddressSpace, offset: int, length: int, width: Literal[8, 16, 32, 64] | DataWidth, extended: bool = False) Tuple[List[int], StatusCode][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:
  • session (VISASession) – Unique logical identifier to a session.

  • 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 (StatusCode) – Return value of the library call.

Raises:

ValueError – Raised if an invalid width is specified.

move_in_16(session: VISASession, space: AddressSpace, offset: int, length: int, extended: bool = False) Tuple[List[int], StatusCode][source]

Moves an 16-bit block of data to local memory.

Corresponds to viMoveIn816 functions of the VISA library.

Parameters:
  • session (VISASession) – Unique logical identifier to a session.

  • 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.

  • 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 (StatusCode) – Return value of the library call.

move_in_32(session: VISASession, space: AddressSpace, offset: int, length: int, extended: bool = False) Tuple[List][source]

Moves an 32-bit block of data to local memory.

Corresponds to viMoveIn32* functions of the VISA library.

Parameters:
  • session (VISASession) – Unique logical identifier to a session.

  • 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.

  • 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 (StatusCode) – Return value of the library call.

move_in_64(session: VISASession, space: AddressSpace, offset: int, length: int, extended: bool = False) Tuple[List[int], StatusCode][source]

Moves an 64-bit block of data to local memory.

Corresponds to viMoveIn8* functions of the VISA library.

Parameters:
  • session (VISASession) – Unique logical identifier to a session.

  • 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.

  • 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 (StatusCode) – Return value of the library call.

move_in_8(session: VISASession, space: AddressSpace, offset: int, length: int, extended: bool = False) Tuple[List[int], StatusCode][source]

Moves an 8-bit block of data to local memory.

Corresponds to viMoveIn8* functions of the VISA library.

Parameters:
  • session (VISASession) – Unique logical identifier to a session.

  • 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.

  • 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 (StatusCode) – Return value of the library call.

move_out(session: VISASession, space: AddressSpace, offset: int, length: int, data: Iterable[int], width: Literal[8, 16, 32, 64] | DataWidth, extended: bool = False) StatusCode[source]

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

Corresponds to viMoveOut* functions of the VISA library.

Parameters:
  • session (VISASession) – Unique logical identifier to a session.

  • 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:

StatusCode

Raises:

ValueError – Raised if an invalid width is specified.

move_out_16(session: VISASession, space: AddressSpace, offset: int, length: int, data: Iterable[int], extended: bool = False) StatusCode[source]

Moves an 16-bit block of data from local memory.

Corresponds to viMoveOut16* functions of the VISA library.

Parameters:
  • session (VISASession) – Unique logical identifier to a session.

  • 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.

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

Returns:

Return value of the library call.

Return type:

StatusCode

move_out_32(session: VISASession, space: AddressSpace, offset: int, length: int, data: Iterable[int], extended: bool = False) StatusCode[source]

Moves an 32-bit block of data from local memory.

Corresponds to viMoveOut32* functions of the VISA library.

Parameters:
  • session (VISASession) – Unique logical identifier to a session.

  • 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.

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

Returns:

Return value of the library call.

Return type:

StatusCode

move_out_64(session: VISASession, space: AddressSpace, offset: int, length: int, data: Iterable[int], extended: bool = False) StatusCode[source]

Moves an 64-bit block of data from local memory.

Corresponds to viMoveOut64* functions of the VISA library.

Parameters:
  • session (VISASession) – Unique logical identifier to a session.

  • 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.

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

Returns:

Return value of the library call.

Return type:

StatusCode

move_out_8(session: VISASession, space: AddressSpace, offset: int, length: int, data: Iterable[int], extended: bool = False) StatusCode[source]

Moves an 8-bit block of data from local memory.

Corresponds to viMoveOut8* functions of the VISA library.

Parameters:
  • session (VISASession) – Unique logical identifier to a session.

  • 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.

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

Returns:

Return value of the library call.

Return type:

StatusCode

open(session: VISARMSession, resource_name: str, access_mode: AccessModes = AccessModes.no_lock, open_timeout: int = 0) Tuple[VISASession, StatusCode][source]

Opens a session to the specified resource.

Corresponds to viOpen function of the VISA library.

Parameters:
  • session (VISARMSession) – Resource Manager session (should always be a session returned from open_default_resource_manager()).

  • resource_name (str) – Unique symbolic name of a resource.

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

  • open_timeout (int) – 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.

Returns:

  • VISASession – Unique logical identifier reference to a session

  • StatusCode – Return value of the library call.

open_default_resource_manager() Tuple[VISARMSession, StatusCode][source]

This function returns a session to the Default Resource Manager resource.

Corresponds to viOpenDefaultRM function of the VISA library.

Returns:

  • VISARMSession – Unique logical identifier to a Default Resource Manager session

  • StatusCode – Return value of the library call.

out_16(session: VISASession, space: AddressSpace, offset: int, data: int, extended: bool = False) StatusCode[source]

Write a 16-bit value to the specified memory space and offset.

Corresponds to viOut16* functions of the VISA library.

Parameters:
  • session (VISASession) – Unique logical identifier to a session.

  • space (constants.AddressSpace) – Address space into which to write.

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

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

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

Returns:

Return value of the library call.

Return type:

StatusCode

out_32(session: VISASession, space: AddressSpace, offset: int, data: Iterable[int], extended: bool = False) StatusCode[source]

Write a 32-bit value to the specified memory space and offset.

Corresponds to viOut32* functions of the VISA library.

Parameters:
  • session (VISASession) – Unique logical identifier to a session.

  • space (constants.AddressSpace) – Address space into which to write.

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

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

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

Returns:

Return value of the library call.

Return type:

StatusCode

out_64(session: VISASession, space: AddressSpace, offset: int, data: Iterable[int], extended: bool = False) StatusCode[source]

Write a 64-bit value to the specified memory space and offset.

Corresponds to viOut64* functions of the VISA library.

Parameters:
  • session (VISASession) – Unique logical identifier to a session.

  • space (constants.AddressSpace) – Address space into which to write.

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

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

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

Returns:

Return value of the library call.

Return type:

StatusCode

out_8(session: VISASession, space: AddressSpace, offset: int, data: int, extended: bool = False) StatusCode[source]

Write an 8-bit value to the specified memory space and offset.

Corresponds to viOut8* functions of the VISA library.

Parameters:
  • session (VISASession) – Unique logical identifier to a session.

  • space (constants.AddressSpace) – Address space into which to write.

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

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

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

Returns:

Return value of the library call.

Return type:

StatusCode

parse_resource(session: VISARMSession, resource_name: str) Tuple[ResourceInfo, StatusCode][source]

Parse a resource string to get the interface information.

Corresponds to viParseRsrc function of the VISA library.

Parameters:
  • session (VISARMSession) – Resource Manager session (should always be the Default Resource Manager for VISA returned from open_default_resource_manager()).

  • resource_name (str) – Unique symbolic name of a resource.

Returns:

  • ResourceInfo – Resource information with interface type and board number

  • StatusCode – Return value of the library call.

parse_resource_extended(session: VISARMSession, resource_name: str) Tuple[ResourceInfo, StatusCode][source]

Parse a resource string to get extended interface information.

Corresponds to viParseRsrcEx function of the VISA library.

Parameters:
  • session (VISARMSession) – Resource Manager session (should always be the Default Resource Manager for VISA returned from open_default_resource_manager()).

  • resource_name (str) – Unique symbolic name of a resource.

Returns:

  • ResourceInfo – Resource information with interface type and board number

  • StatusCode – Return value of the library call.

peek(session: VISASession, address: VISAMemoryAddress, width: Literal[8, 16, 32, 64] | DataWidth) Tuple[int, StatusCode][source]

Read an 8, 16, 32, or 64-bit value from the specified address.

Corresponds to viPeek* functions of the VISA library.

Parameters:
  • session (VISASession) – Unique logical identifier to a session.

  • address (VISAMemoryAddress) – Source address to read the value.

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

Returns:

  • data (int) – Data read from bus

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

Raises:

ValueError – Raised if an invalid width is specified.

peek_16(session: VISASession, address: VISAMemoryAddress) Tuple[int, StatusCode][source]

Read an 16-bit value from the specified address.

Corresponds to viPeek16 function of the VISA library.

Parameters:
  • session (VISASession) – Unique logical identifier to a session.

  • address (VISAMemoryAddress) – Source address to read the value.

Returns:

  • int – Data read from bus

  • StatusCode – Return value of the library call.

peek_32(session: VISASession, address: VISAMemoryAddress) Tuple[int, StatusCode][source]

Read an 32-bit value from the specified address.

Corresponds to viPeek32 function of the VISA library.

Parameters:
  • session (VISASession) – Unique logical identifier to a session.

  • address (VISAMemoryAddress) – Source address to read the value.

Returns:

  • int – Data read from bus

  • StatusCode – Return value of the library call.

peek_64(session: VISASession, address: VISAMemoryAddress) Tuple[int, StatusCode][source]

Read an 64-bit value from the specified address.

Corresponds to viPeek64 function of the VISA library.

Parameters:
  • session (VISASession) – Unique logical identifier to a session.

  • address (VISAMemoryAddress) – Source address to read the value.

Returns:

  • int – Data read from bus

  • StatusCode – Return value of the library call.

peek_8(session: VISASession, address: VISAMemoryAddress) Tuple[int, StatusCode][source]

Read an 8-bit value from the specified address.

Corresponds to viPeek8 function of the VISA library.

Parameters:
  • session (VISASession) – Unique logical identifier to a session.

  • address (VISAMemoryAddress) – Source address to read the value.

Returns:

  • int – Data read from bus

  • StatusCode – Return value of the library call.

poke(session: VISASession, address: VISAMemoryAddress, width: Literal[8, 16, 32, 64] | DataWidth, data: int) StatusCode[source]

Writes an 8, 16, 32, or 64-bit value from the specified address.

Corresponds to viPoke* functions of the VISA library.

Parameters:
  • session (VISASession) – Unique logical identifier to a session.

  • address (VISAMemoryAddress) – Source address to read the value.

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

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

Returns:

status_code – Return value of the library call.

Return type:

StatusCode

Raises:

ValueError – Raised if an invalid width is specified.

poke_16(session: VISASession, address: VISAMemoryAddress, data: int) StatusCode[source]

Write an 16-bit value to the specified address.

Corresponds to viPoke16 function of the VISA library.

Parameters:
  • session (VISASession) – Unique logical identifier to a session.

  • address (VISAMemoryAddress) – Source address to read the value.

  • data (int) – Data to write.

Returns:

Return value of the library call.

Return type:

StatusCode

poke_32(session: VISASession, address: VISAMemoryAddress, data: int) StatusCode[source]

Write an 32-bit value to the specified address.

Corresponds to viPoke32 function of the VISA library.

Parameters:
  • session (VISASession) – Unique logical identifier to a session.

  • address (VISAMemoryAddress) – Source address to read the value.

  • data (int) – Data to write.

Returns:

Return value of the library call.

Return type:

StatusCode

poke_64(session: VISASession, address: VISAMemoryAddress, data: int) StatusCode[source]

Write an 64-bit value to the specified address.

Corresponds to viPoke64 function of the VISA library.

Parameters:
  • session (VISASession) – Unique logical identifier to a session.

  • address (VISAMemoryAddress) – Source address to read the value.

  • data (int) – Data to write.

Returns:

Return value of the library call.

Return type:

StatusCode

poke_8(session: VISASession, address: VISAMemoryAddress, data: int) StatusCode[source]

Write an 8-bit value to the specified address.

Corresponds to viPoke8 function of the VISA library.

Parameters:
  • session (VISASession) – Unique logical identifier to a session.

  • address (VISAMemoryAddress) – Source address to read the value.

  • data (int) – Data to write.

Returns:

Return value of the library call.

Return type:

StatusCode

read(session: VISASession, count: int) Tuple[bytes, StatusCode][source]

Reads data from device or interface synchronously.

Corresponds to viRead function of the VISA library.

Parameters:
  • session (VISASession) – Unique logical identifier to a session.

  • count (int) – Number of bytes to be read.

Returns:

  • bytes – Date read

  • StatusCode – Return value of the library call.

read_asynchronously(session: VISASession, count: int) Tuple[SupportsBytes, VISAJobID, StatusCode][source]

Reads data from device or interface asynchronously.

Corresponds to viReadAsync function of the VISA library. Since the asynchronous operation may complete before the function call return implementation should make sure that get_buffer_from_id will be able to return the proper buffer before this method returns.

Parameters:
  • session (VISASession) – Unique logical identifier to a session.

  • count (int) – Number of bytes to be read.

Returns:

  • SupportsBytes – Buffer that will be filled during the asynchronous operation.

  • VISAJobID – Id of the asynchronous job

  • StatusCode – Return value of the library call.

read_memory(session: VISASession, space: AddressSpace, offset: int, width: Literal[8, 16, 32, 64] | DataWidth, extended: bool = False) Tuple[int, StatusCode][source]

Read a value from the specified memory space and offset.

Corresponds to viIn* functions of the VISA library.

Parameters:
  • session (VISASession) – Unique logical identifier to a session.

  • 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 (int) – Data read from memory

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

Raises:

ValueError – Raised if an invalid width is specified.

read_stb(session: VISASession) Tuple[int, StatusCode][source]

Reads a status byte of the service request.

Corresponds to viReadSTB function of the VISA library.

Parameters:

session (VISASession) – Unique logical identifier to a session.

Returns:

  • int – Service request status byte

  • StatusCode – Return value of the library call.

read_to_file(session: VISASession, filename: str, count: int) Tuple[int, StatusCode][source]

Read data synchronously, and store the transferred data in a file.

Corresponds to viReadToFile function of the VISA library.

Parameters:
  • session (VISASession) – Unique logical identifier to a session.

  • filename (str) – Name of file to which data will be written.

  • count (int) – Number of bytes to be read.

Returns:

  • int – Number of bytes actually transferred

  • StatusCode – Return value of the library call.

resource_manager: ResourceManager | None

Default ResourceManager instance for this library.

set_attribute(session: VISASession, attribute: ResourceAttribute, attribute_state: Any) StatusCode[source]

Set the state of an attribute.

Corresponds to viSetAttribute function of the VISA library.

Parameters:
  • session (VISASession) – Unique logical identifier to a session.

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

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

Returns:

Return value of the library call.

Return type:

StatusCode

set_buffer(session: VISASession, mask: BufferType, size: int) StatusCode[source]

Set the size for the formatted I/O and/or low-level I/O communication buffer(s).

Corresponds to viSetBuf function of the VISA library.

Parameters:
  • session (VISASession) – Unique logical identifier to a session.

  • mask (constants.BufferType) – Specifies the type of buffer.

  • size (int) – The size to be set for the specified buffer(s).

Returns:

Return value of the library call.

Return type:

StatusCode

status_description(session: VISASession, status: StatusCode) Tuple[str, StatusCode][source]

Return a user-readable description of the status code passed to the operation.

Corresponds to viStatusDesc function of the VISA library.

Parameters:
  • session (VISASession) – Unique logical identifier to a session.

  • status (StatusCode) – Status code to interpret.

Returns:

  • str – User-readable string interpretation of the status code.

  • StatusCode – Return value of the library call.

terminate(session: VISASession, degree: None, job_id: VISAJobID) StatusCode[source]

Request a VISA session to terminate normal execution of an operation.

Corresponds to viTerminate function of the VISA library.

Parameters:
  • session (VISASession) – Unique logical identifier to a session.

  • degree (None) – Not used in this version of the VISA specification.

  • job_id (VISAJobId) – Specifies an operation identifier. If a user passes None as the job_id value to viTerminate(), a VISA implementation should abort any calls in the current process executing on the specified vi. Any call that is terminated this way should return VI_ERROR_ABORT.

Returns:

Return value of the library call.

Return type:

StatusCode

uninstall_all_visa_handlers(session: VISASession | None) None[source]

Uninstalls all previously installed handlers for a particular session.

Parameters:

session (VISASession | None) – Unique logical identifier to a session. If None, operates on all sessions.

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

Uninstall handlers for events.

Corresponds to viUninstallHandler function of the VISA library.

Parameters:
  • session (VISASession) – Unique logical identifier to a session.

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

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

  • user_handle – A value specified by an application that can be used for identifying handlers uniquely in a session for an event. The modified value of the user_handle as returned by install_handler should be used instead of the original value.

Returns:

Return value of the library call.

Return type:

StatusCode

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

Uninstalls handlers for events.

Parameters:
  • session (VISASession) – Unique logical identifier to a session.

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

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

  • user_handle – The user handle returned by install_visa_handler.

unlock(session: VISASession) StatusCode[source]

Relinquish a lock for the specified resource.

Corresponds to viUnlock function of the VISA library.

Parameters:

session (VISASession) – Unique logical identifier to a session.

Returns:

Return value of the library call.

Return type:

StatusCode

unmap_address(session: VISASession) StatusCode[source]

Unmap memory space previously mapped by map_address().

Corresponds to viUnmapAddress function of the VISA library.

Parameters:

session (VISASession) – Unique logical identifier to a session.

Returns:

Return value of the library call.

Return type:

StatusCode

unmap_trigger(session: VISASession, trigger_source: InputTriggerLine, trigger_destination: OutputTriggerLine) StatusCode[source]

Undo a previous map between a trigger source line and a destination line.

Corresponds to viUnmapTrigger function of the VISA library.

Parameters:
  • session (VISASession) – Unique logical identifier to a session.

  • trigger_source (constants.InputTriggerLine) – Source line used in previous map.

  • trigger_destination (constants.OutputTriggerLine) – Destination line used in previous map.

Returns:

Return value of the library call.

Return type:

StatusCode

usb_control_in(session: VISASession, request_type_bitmap_field: int, request_id: int, request_value: int, index: int, length: int = 0) Tuple[bytes, StatusCode][source]

Perform a USB control pipe transfer from the device.

Corresponds to viUsbControlIn function of the VISA library.

Parameters:
  • session (VISASession) – Unique logical identifier to a session.

  • 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, optional) – 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:

  • bytes – The data buffer that receives the data from the optional data stage of the control transfer

  • StatusCode – Return value of the library call.

usb_control_out(session: VISASession, request_type_bitmap_field: int, request_id: int, request_value: int, index: int, data: bytes = b'') StatusCode[source]

Perform a USB control pipe transfer to the device.

Corresponds to viUsbControlOut function of the VISA library.

Parameters:
  • session (VISASession) – Unique logical identifier to a session.

  • 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, optional) – The data buffer that sends the data in the optional data stage of the control transfer.

Returns:

Return value of the library call.

Return type:

StatusCode

vxi_command_query(session: VISASession, mode: VXICommands, command: int) Tuple[int, StatusCode][source]

Send the device a miscellaneous command or query and/or retrieves the response to a previous query.

Corresponds to viVxiCommandQuery function of the VISA library.

Parameters:
  • session (VISASession) – Unique logical identifier to a session.

  • mode (constants.VXICommands) – Specifies whether to issue a command and/or retrieve a response.

  • command (int) – The miscellaneous command to send.

Returns:

  • int – The response retrieved from the device

  • StatusCode – Return value of the library call.

wait_on_event(session: VISASession, in_event_type: EventType, timeout: int) Tuple[EventType, VISAEventContext, StatusCode][source]

Wait for an occurrence of the specified event for a given session.

Corresponds to viWaitOnEvent function of the VISA library.

Parameters:
  • session (VISASession) – Unique logical identifier to a session.

  • in_event_type (constants.EventType) – Logical identifier of the event(s) to wait for.

  • timeout (int) – 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.

Returns:

  • constants.EventType – Logical identifier of the event actually received

  • VISAEventContext – A handle specifying the unique occurrence of an event

  • StatusCode – Return value of the library call.

write(session: VISASession, data: bytes) Tuple[int, StatusCode][source]

Write data to device or interface synchronously.

Corresponds to viWrite function of the VISA library.

Parameters:
  • session (VISASession) – Unique logical identifier to a session.

  • data (bytes) – Data to be written.

Returns:

  • int – Number of bytes actually transferred

  • StatusCode – Return value of the library call.

write_asynchronously(session: VISASession, data: bytes) Tuple[VISAJobID, StatusCode][source]

Write data to device or interface asynchronously.

Corresponds to viWriteAsync function of the VISA library.

Parameters:
  • session (VISASession) – Unique logical identifier to a session.

  • data (bytes) – Data to be written.

Returns:

  • VISAJobID – Job ID of this asynchronous write operation

  • StatusCode – Return value of the library call.

write_from_file(session: VISASession, filename: str, count: int) Tuple[int, StatusCode][source]

Take data from a file and write it out synchronously.

Corresponds to viWriteFromFile function of the VISA library.

Parameters:
  • session (VISASession) – Unique logical identifier to a session.

  • filename (str) – Name of file from which data will be read.

  • count (int) – Number of bytes to be written.

Returns:

  • int – Number of bytes actually transferred

  • StatusCode – Return value of the library call.

write_memory(session: VISASession, space: AddressSpace, offset: int, data: int, width: Literal[8, 16, 32, 64] | DataWidth, extended: bool = False) StatusCode[source]

Write a value to the specified memory space and offset.

Parameters:
  • session (VISASession) – Unique logical identifier to a session.

  • 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:

StatusCode

Raises:

ValueError – Raised if an invalid width is specified.