Visa Library

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

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, mode, status_id)[source]

Asserts the specified interrupt or signal.

Corresponds to viAssertIntrSignal function of the VISA library.

Parameters:
  • session – Unique logical identifier to a session.
  • mode – How to assert the interrupt. (Constants.ASSERT*)
  • status_id – This is the status value to be presented during an interrupt acknowledge cycle.
Returns:

return value of the library call.

Return type:

pyvisa.constants.StatusCode

assert_trigger(session, protocol)[source]

Asserts software or hardware trigger.

Corresponds to viAssertTrigger function of the VISA library.

Parameters:
  • session – Unique logical identifier to a session.
  • protocol – Trigger protocol to use during assertion. (Constants.PROT*)
Returns:

return value of the library call.

Return type:

pyvisa.constants.StatusCode

assert_utility_signal(session, line)[source]

Asserts or deasserts the specified utility bus signal.

Corresponds to viAssertUtilSignal function of the VISA library.

Parameters:
  • session – Unique logical identifier to a session.
  • line – specifies the utility bus signal to assert. (Constants.VI_UTIL_ASSERT*)
Returns:

return value of the library call.

Return type:

pyvisa.constants.StatusCode

buffer_read(session, count)[source]

Reads data from device or interface through the use of a formatted I/O read buffer.

Corresponds to viBufRead function of the VISA library.

Parameters:
  • session – Unique logical identifier to a session.
  • count – Number of bytes to be read.
Returns:

data read, return value of the library call.

Return type:

bytes, pyvisa.constants.StatusCode

buffer_write(session, data)[source]

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

Corresponds to viBufWrite function of the VISA library.

Parameters:
  • session – Unique logical identifier to a session.
  • data (bytes) – data to be written.
Returns:

number of written bytes, return value of the library call.

Return type:

int, pyvisa.constants.StatusCode

clear(session)[source]

Clears a device.

Corresponds to viClear function of the VISA library.

Parameters:session – Unique logical identifier to a session.
Returns:return value of the library call.
Return type:pyvisa.constants.StatusCode
close(session)[source]

Closes the specified session, event, or find list.

Corresponds to viClose function of the VISA library.

Parameters:session – Unique logical identifier to a session, event, or find list.
Returns:return value of the library call.
Return type:pyvisa.constants.StatusCode
disable_event(session, event_type, mechanism)[source]

Disables notification of the specified event type(s) via the specified mechanism(s).

Corresponds to viDisableEvent function of the VISA library.

Parameters:
  • session – Unique logical identifier to a session.
  • event_type – Logical event identifier.
  • mechanism – Specifies event handling mechanisms to be disabled. (Constants.VI_QUEUE, .VI_HNDLR, .VI_SUSPEND_HNDLR, .VI_ALL_MECH)
Returns:

return value of the library call.

Return type:

pyvisa.constants.StatusCode

discard_events(session, event_type, mechanism)[source]

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

Corresponds to viDiscardEvents function of the VISA library.

Parameters:
  • session – Unique logical identifier to a session.
  • event_type – Logical event identifier.
  • mechanism – Specifies event handling mechanisms to be discarded. (Constants.VI_QUEUE, .VI_HNDLR, .VI_SUSPEND_HNDLR, .VI_ALL_MECH)
Returns:

return value of the library call.

Return type:

pyvisa.constants.StatusCode

enable_event(session, event_type, mechanism, context=None)[source]

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

Corresponds to viEnableEvent function of the VISA library.

Parameters:
  • session – Unique logical identifier to a session.
  • event_type – Logical event identifier.
  • mechanism – Specifies event handling mechanisms to be enabled. (Constants.VI_QUEUE, .VI_HNDLR, .VI_SUSPEND_HNDLR)
  • context
Returns:

return value of the library call.

Return type:

pyvisa.constants.StatusCode

flush(session, mask)[source]

Manually flushes the specified buffers associated with formatted I/O operations and/or serial communication.

Corresponds to viFlush function of the VISA library.

Parameters:
  • session – Unique logical identifier to a session.
  • mask

    Specifies the action to be taken with flushing the buffer. The following values (defined in the constants module can be combined using the | operator. However multiple operations on a single buffer cannot be combined.

    • VI_READ_BUF: Discard the read buffer contents and if data was present in the read buffer and no END-indicator was present, read from the device until encountering an END indicator (which causes the loss of data).
    • VI_READ_BUF_DISCARD: Discard the read buffer contents (does not perform any I/O to the device).
    • VI_WRITE_BUF: Flush the write buffer by writing all buffered data to the device.
    • VI_WRITE_BUF_DISCARD: Discard the write buffer contents (does not perform any I/O to the device).
    • VI_IO_IN_BUF: Discards the receive buffer contents (same as VI_IO_IN_BUF_DISCARD).
    • VI_IO_IN_BUF_DISCARD: Discard the receive buffer contents (does not perform any I/O to the device).
    • VI_IO_OUT_BUF: Flush the transmit buffer by writing all buffered data to the device.
    • VI_IO_OUT_BUF_DISCARD: Discard the transmit buffer contents (does not perform any I/O to the device).
Returns:

return value of the library call.

Return type:

pyvisa.constants.StatusCode

get_attribute(session, attribute)[source]

Retrieves the state of an attribute.

Corresponds to viGetAttribute function of the VISA library.

Parameters:
  • session – Unique logical identifier to a session, event, or find list.
  • attribute – Resource attribute for which the state query is made (see Attributes.*)
Returns:

The state of the queried attribute for a specified resource, return value of the library call.

Return type:

unicode (Py2) or str (Py3), list or other type, pyvisa.constants.StatusCode

static get_debug_info()[source]

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

get_last_status_in_session(session)[source]

Last status in session.

Helper function to be called by resources properties.

static get_library_paths()[source]

Override this method to return an iterable of possible library_paths to try in case that no argument is given.

gpib_command(session, data)[source]

Write GPIB command bytes on the bus.

Corresponds to viGpibCommand function of the VISA library.

Parameters:
  • session – Unique logical identifier to a session.
  • data (bytes) – data tor write.
Returns:

Number of written bytes, return value of the library call.

Return type:

int, pyvisa.constants.StatusCode

gpib_control_atn(session, mode)[source]

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

Corresponds to viGpibControlATN function of the VISA library.

Parameters:
  • session – Unique logical identifier to a session.
  • mode – Specifies the state of the ATN line and optionally the local active controller state. (Constants.VI_GPIB_ATN*)
Returns:

return value of the library call.

Return type:

pyvisa.constants.StatusCode

gpib_control_ren(session, mode)[source]

Controls the state of the GPIB Remote Enable (REN) interface line, and optionally the remote/local state of the device.

Corresponds to viGpibControlREN function of the VISA library.

Parameters:
  • session – Unique logical identifier to a session.
  • mode – Specifies the state of the REN line and optionally the device remote/local state. (Constants.VI_GPIB_REN*)
Returns:

return value of the library call.

Return type:

pyvisa.constants.StatusCode

gpib_pass_control(session, primary_address, secondary_address)[source]

Tell the GPIB device at the specified address to become controller in charge (CIC).

Corresponds to viGpibPassControl function of the VISA library.

Parameters:
  • session – Unique logical identifier to a session.
  • primary_address – Primary address of the GPIB device to which you want to pass control.
  • secondary_address – Secondary address of the targeted GPIB device. If the targeted device does not have a secondary address, this parameter should contain the value Constants.VI_NO_SEC_ADDR.
Returns:

return value of the library call.

Return type:

pyvisa.constants.StatusCode

gpib_send_ifc(session)[source]

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

Corresponds to viGpibSendIFC function of the VISA library.

Parameters:session – Unique logical identifier to a session.
Returns:return value of the library call.
Return type:pyvisa.constants.StatusCode
handlers = None

Contains all installed event handlers. Its elements are tuples with three elements: The handler itself (a Python callable), the user handle (as a ct object) and the handler again, this time as a ct object created with CFUNCTYPE.

ignore_warning(session, *warnings_constants)[source]

A session dependent context for ignoring warnings

Parameters:
  • session – Unique logical identifier to a session.
  • warnings_constants – constants identifying the warnings to ignore.
in_16(session, space, offset, extended=False)[source]

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

Corresponds to viIn16* function of the VISA library.

Parameters:
  • session – Unique logical identifier to a session.
  • space – Specifies the address space. (Constants.*SPACE*)
  • offset – Offset (in bytes) of the address or register from which to read.
  • extended – Use 64 bits offset independent of the platform.
Returns:

Data read from memory, return value of the library call.

Return type:

int, pyvisa.constants.StatusCode

in_32(session, space, offset, extended=False)[source]

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

Corresponds to viIn32* function of the VISA library.

Parameters:
  • session – Unique logical identifier to a session.
  • space – Specifies the address space. (Constants.*SPACE*)
  • offset – Offset (in bytes) of the address or register from which to read.
  • extended – Use 64 bits offset independent of the platform.
Returns:

Data read from memory, return value of the library call.

Return type:

int, pyvisa.constants.StatusCode

in_64(session, space, offset, extended=False)[source]

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

Corresponds to viIn64* function of the VISA library.

Parameters:
  • session – Unique logical identifier to a session.
  • space – Specifies the address space. (Constants.*SPACE*)
  • offset – Offset (in bytes) of the address or register from which to read.
  • extended – Use 64 bits offset independent of the platform.
Returns:

Data read from memory, return value of the library call.

Return type:

int, pyvisa.constants.StatusCode

in_8(session, space, offset, extended=False)[source]

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

Corresponds to viIn8* function of the VISA library.

Parameters:
  • session – Unique logical identifier to a session.
  • space – Specifies the address space. (Constants.*SPACE*)
  • offset – Offset (in bytes) of the address or register from which to read.
  • extended – Use 64 bits offset independent of the platform.
Returns:

Data read from memory, return value of the library call.

Return type:

int, pyvisa.constants.StatusCode

install_handler(session, event_type, handler, user_handle)[source]

Installs handlers for event callbacks.

Corresponds to viInstallHandler function of the VISA library.

Parameters:
  • session – Unique logical identifier to a session.
  • event_type – Logical event identifier.
  • handler – Interpreted as a valid reference to a 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:

a handler descriptor which consists of three elements: - handler (a python callable) - user handle (a ctypes object) - ctypes handler (ctypes object wrapping handler) and return value of the library call.

Return type:

int, pyvisa.constants.StatusCode

install_visa_handler(session, event_type, handler, user_handle=None)[source]

Installs handlers for event callbacks.

Parameters:
  • session – Unique logical identifier to a session.
  • event_type – Logical event identifier.
  • handler – Interpreted as a valid reference to a 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:

user handle (a ctypes object)

issue_warning_on = None

Set error codes on which to issue a warning. set

last_status

Last return value of the library.

list_resources(session, query='?*::INSTR')[source]

Returns a tuple of all connected devices matching query.

Parameters:query – regular expression used to match devices.
lock(session, lock_type, timeout, requested_key=None)[source]

Establishes an access mode to the specified resources.

Corresponds to viLock function of the VISA library.

Parameters:
  • session – Unique logical identifier to a session.
  • lock_type – Specifies the type of lock requested, either Constants.EXCLUSIVE_LOCK or Constants.SHARED_LOCK.
  • timeout – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error.
  • requested_key – This parameter is not used and should be set to VI_NULL when lockType is VI_EXCLUSIVE_LOCK.
Returns:

access_key that can then be passed to other sessions to share the lock, return value of the library call.

Return type:

str, pyvisa.constants.StatusCode

map_address(session, map_space, map_base, map_size, access=False, suggested=None)[source]

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

Corresponds to viMapAddress function of the VISA library.

Parameters:
  • session – Unique logical identifier to a session.
  • map_space – Specifies the address space to map. (Constants.*SPACE*)
  • map_base – Offset (in bytes) of the memory to be mapped.
  • map_size – Amount of memory to map (in bytes).
  • access
  • suggested – If not Constants.VI_NULL (0), the operating system attempts to map the memory to the address specified in suggested. 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 suggested.
Returns:

address in your process space where the memory was mapped, return value of the library call.

Return type:

address, pyvisa.constants.StatusCode

map_trigger(session, trigger_source, trigger_destination, mode)[source]

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

Corresponds to viMapTrigger function of the VISA library.

Parameters:
  • session – Unique logical identifier to a session.
  • trigger_source – Source line from which to map. (Constants.VI_TRIG*)
  • trigger_destination – Destination line to which to map. (Constants.VI_TRIG*)
  • mode
Returns:

return value of the library call.

Return type:

pyvisa.constants.StatusCode

memory_allocation(session, size, extended=False)[source]

Allocates memory from a resource’s memory region.

Corresponds to viMemAlloc* functions of the VISA library.

Parameters:
  • session – Unique logical identifier to a session.
  • size – Specifies the size of the allocation.
  • extended – Use 64 bits offset independent of the platform.
Returns:

offset of the allocated memory, return value of the library call.

Return type:

offset, pyvisa.constants.StatusCode

memory_free(session, offset, extended=False)[source]

Frees memory previously allocated using the memory_allocation() operation.

Corresponds to viMemFree* function of the VISA library.

Parameters:
  • session – Unique logical identifier to a session.
  • offset – Offset of the memory to free.
  • extended – Use 64 bits offset independent of the platform.
Returns:

return value of the library call.

Return type:

pyvisa.constants.StatusCode

move(session, source_space, source_offset, source_width, destination_space, destination_offset, destination_width, length)[source]

Moves a block of data.

Corresponds to viMove function of the VISA library.

Parameters:
  • session – Unique logical identifier to a session.
  • source_space – Specifies the address space of the source.
  • source_offset – Offset of the starting address or register from which to read.
  • source_width – Specifies the data width of the source.
  • destination_space – Specifies the address space of the destination.
  • destination_offset – Offset of the starting address or register to which to write.
  • destination_width – Specifies the data width of the destination.
  • length – 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:

pyvisa.constants.StatusCode

move_asynchronously(session, source_space, source_offset, source_width, destination_space, destination_offset, destination_width, length)[source]

Moves a block of data asynchronously.

Corresponds to viMoveAsync function of the VISA library.

Parameters:
  • session – Unique logical identifier to a session.
  • source_space – Specifies the address space of the source.
  • source_offset – Offset of the starting address or register from which to read.
  • source_width – Specifies the data width of the source.
  • destination_space – Specifies the address space of the destination.
  • destination_offset – Offset of the starting address or register to which to write.
  • destination_width – Specifies the data width of the destination.
  • length – Number of elements to transfer, where the data width of the elements to transfer is identical to the source data width.
Returns:

Job identifier of this asynchronous move operation, return value of the library call.

Return type:

jobid, pyvisa.constants.StatusCode

move_in(session, space, offset, length, width, extended=False)[source]

Moves a block of data to local memory from the specified address space and offset.

Corresponds to viMoveIn* functions of the VISA library.

Parameters:
  • session – Unique logical identifier to a session.
  • space – Specifies the address space. (Constants.*SPACE*)
  • offset – Offset (in bytes) of the address or register from which to read.
  • length – Number of elements to transfer, where the data width of the elements to transfer is identical to the source data width.
  • width – Number of bits to read per element.
  • extended – Use 64 bits offset independent of the platform.
Returns:

Data read from the bus, return value of the library call.

Return type:

list, pyvisa.constants.StatusCode

move_in_16(session, space, offset, length, extended=False)[source]

Moves an 16-bit block of data from the specified address space and offset to local memory.

Corresponds to viMoveIn16* functions of the VISA library.

Parameters:
  • session – Unique logical identifier to a session.
  • space – Specifies the address space. (Constants.*SPACE*)
  • offset – Offset (in bytes) of the address or register from which to read.
  • length – Number of elements to transfer, where the data width of the elements to transfer is identical to the source data width.
  • extended – Use 64 bits offset independent of the platform.
Returns:

Data read from the bus, return value of the library call.

Return type:

list, pyvisa.constants.StatusCode

move_in_32(session, space, offset, length, extended=False)[source]

Moves an 32-bit block of data from the specified address space and offset to local memory.

Corresponds to viMoveIn32* functions of the VISA library.

Parameters:
  • session – Unique logical identifier to a session.
  • space – Specifies the address space. (Constants.*SPACE*)
  • offset – Offset (in bytes) of the address or register from which to read.
  • length – Number of elements to transfer, where the data width of the elements to transfer is identical to the source data width.
  • extended – Use 64 bits offset independent of the platform.
Returns:

Data read from the bus, return value of the library call.

Return type:

list, pyvisa.constants.StatusCode

move_in_64(session, space, offset, length, extended=False)[source]

Moves an 64-bit block of data from the specified address space and offset to local memory.

Corresponds to viMoveIn64* functions of the VISA library.

Parameters:
  • session – Unique logical identifier to a session.
  • space – Specifies the address space. (Constants.*SPACE*)
  • offset – Offset (in bytes) of the address or register from which to read.
  • length – Number of elements to transfer, where the data width of the elements to transfer is identical to the source data width.
  • extended – Use 64 bits offset independent of the platform.
Returns:

Data read from the bus, return value of the library call.

Return type:

list, pyvisa.constants.StatusCode

move_in_8(session, space, offset, length, extended=False)[source]

Moves an 8-bit block of data from the specified address space and offset to local memory.

Corresponds to viMoveIn8* functions of the VISA library.

Parameters:
  • session – Unique logical identifier to a session.
  • space – Specifies the address space. (Constants.*SPACE*)
  • offset – Offset (in bytes) of the address or register from which to read.
  • length – Number of elements to transfer, where the data width of the elements to transfer is identical to the source data width.
  • extended – Use 64 bits offset independent of the platform.
Returns:

Data read from the bus, return value of the library call.

Return type:

list, pyvisa.constants.StatusCode

move_out(session, space, offset, length, data, width, extended=False)[source]

Moves a block of data from local memory to the specified address space and offset.

Corresponds to viMoveOut* functions of the VISA library.

Parameters:
  • session – Unique logical identifier to a session.
  • space – Specifies the address space. (Constants.*SPACE*)
  • offset – Offset (in bytes) of the address or register from which to read.
  • length – Number of elements to transfer, where the data width of the elements to transfer is identical to the source data width.
  • data – Data to write to bus.
  • width – Number of bits to read per element.
  • extended – Use 64 bits offset independent of the platform.
Returns:

return value of the library call.

Return type:

pyvisa.constants.StatusCode

move_out_16(session, space, offset, length, data, extended=False)[source]

Moves an 16-bit block of data from local memory to the specified address space and offset.

Corresponds to viMoveOut16* functions of the VISA library.

Parameters:
  • session – Unique logical identifier to a session.
  • space – Specifies the address space. (Constants.*SPACE*)
  • offset – Offset (in bytes) of the address or register from which to read.
  • length – Number of elements to transfer, where the data width of the elements to transfer is identical to the source data width.
  • data – Data to write to bus.
  • extended – Use 64 bits offset independent of the platform.
Returns:

return value of the library call.

Return type:

pyvisa.constants.StatusCode

move_out_32(session, space, offset, length, data, extended=False)[source]

Moves an 32-bit block of data from local memory to the specified address space and offset.

Corresponds to viMoveOut32* functions of the VISA library.

Parameters:
  • session – Unique logical identifier to a session.
  • space – Specifies the address space. (Constants.*SPACE*)
  • offset – Offset (in bytes) of the address or register from which to read.
  • length – Number of elements to transfer, where the data width of the elements to transfer is identical to the source data width.
  • data – Data to write to bus.
  • extended – Use 64 bits offset independent of the platform.
Returns:

return value of the library call.

Return type:

pyvisa.constants.StatusCode

move_out_64(session, space, offset, length, data, extended=False)[source]

Moves an 64-bit block of data from local memory to the specified address space and offset.

Corresponds to viMoveOut64* functions of the VISA library.

Parameters:
  • session – Unique logical identifier to a session.
  • space – Specifies the address space. (Constants.*SPACE*)
  • offset – Offset (in bytes) of the address or register from which to read.
  • length – Number of elements to transfer, where the data width of the elements to transfer is identical to the source data width.
  • data – Data to write to bus.
  • extended – Use 64 bits offset independent of the platform.
Returns:

return value of the library call.

Return type:

pyvisa.constants.StatusCode

move_out_8(session, space, offset, length, data, extended=False)[source]

Moves an 8-bit block of data from local memory to the specified address space and offset.

Corresponds to viMoveOut8* functions of the VISA library.

Parameters:
  • session – Unique logical identifier to a session.
  • space – Specifies the address space. (Constants.*SPACE*)
  • offset – Offset (in bytes) of the address or register from which to read.
  • length – Number of elements to transfer, where the data width of the elements to transfer is identical to the source data width.
  • data – Data to write to bus.
  • extended – Use 64 bits offset independent of the platform.
Returns:

return value of the library call.

Return type:

pyvisa.constants.StatusCode

Corresponds to viMoveOut8 function of the VISA library.

open(session, resource_name, access_mode=<AccessModes.no_lock: 0>, open_timeout=0)[source]

Opens a session to the specified resource.

Corresponds to viOpen function of the VISA library.

Parameters:
  • session – Resource Manager session (should always be a session returned from open_default_resource_manager()).
  • resource_name – Unique symbolic name of a resource.
  • access_mode (pyvisa.constants.AccessModes) – 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:

Unique logical identifier reference to a session, return value of the library call.

Return type:

session, pyvisa.constants.StatusCode

open_default_resource_manager()[source]

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

Corresponds to viOpenDefaultRM function of the VISA library.

Returns:Unique logical identifier to a Default Resource Manager session, return value of the library call.
Return type:session, pyvisa.constants.StatusCode
out_16(session, space, offset, data, extended=False)[source]

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

Corresponds to viOut16* functions of the VISA library.

Parameters:
  • session – Unique logical identifier to a session.
  • space – Specifies the address space. (Constants.*SPACE*)
  • offset – Offset (in bytes) of the address or register from which to read.
  • data – Data to write to bus.
  • extended – Use 64 bits offset independent of the platform.
Returns:

return value of the library call.

Return type:

pyvisa.constants.StatusCode

out_32(session, space, offset, data, extended=False)[source]

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

Corresponds to viOut32* functions of the VISA library.

Parameters:
  • session – Unique logical identifier to a session.
  • space – Specifies the address space. (Constants.*SPACE*)
  • offset – Offset (in bytes) of the address or register from which to read.
  • data – Data to write to bus.
  • extended – Use 64 bits offset independent of the platform.
Returns:

return value of the library call.

Return type:

pyvisa.constants.StatusCode

out_64(session, space, offset, data, extended=False)[source]

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

Corresponds to viOut64* functions of the VISA library.

Parameters:
  • session – Unique logical identifier to a session.
  • space – Specifies the address space. (Constants.*SPACE*)
  • offset – Offset (in bytes) of the address or register from which to read.
  • data – Data to write to bus.
  • extended – Use 64 bits offset independent of the platform.
Returns:

return value of the library call.

Return type:

pyvisa.constants.StatusCode

out_8(session, space, offset, data, extended=False)[source]

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

Corresponds to viOut8* functions of the VISA library.

Parameters:
  • session – Unique logical identifier to a session.
  • space – Specifies the address space. (Constants.*SPACE*)
  • offset – Offset (in bytes) of the address or register from which to read.
  • data – Data to write to bus.
  • extended – Use 64 bits offset independent of the platform.
Returns:

return value of the library call.

Return type:

pyvisa.constants.StatusCode

parse_resource(session, resource_name)[source]

Parse a resource string to get the interface information.

Corresponds to viParseRsrc function of the VISA library.

Parameters:
  • session – Resource Manager session (should always be the Default Resource Manager for VISA returned from open_default_resource_manager()).
  • resource_name – Unique symbolic name of a resource.
Returns:

Resource information with interface type and board number, return value of the library call.

Return type:

pyvisa.highlevel.ResourceInfo, pyvisa.constants.StatusCode

parse_resource_extended(session, resource_name)[source]

Parse a resource string to get extended interface information.

Corresponds to viParseRsrcEx function of the VISA library.

Parameters:
  • session – Resource Manager session (should always be the Default Resource Manager for VISA returned from open_default_resource_manager()).
  • resource_name – Unique symbolic name of a resource.
Returns:

Resource information, return value of the library call.

Return type:

pyvisa.highlevel.ResourceInfo, pyvisa.constants.StatusCode

peek(session, address, width)[source]

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

Corresponds to viPeek* functions of the VISA library.

Parameters:
  • session – Unique logical identifier to a session.
  • address – Source address to read the value.
  • width – Number of bits to read.
Returns:

Data read from bus, return value of the library call.

Return type:

bytes, pyvisa.constants.StatusCode

peek_16(session, address)[source]

Read an 16-bit value from the specified address.

Corresponds to viPeek16 function of the VISA library.

Parameters:
  • session – Unique logical identifier to a session.
  • address – Source address to read the value.
Returns:

Data read from bus, return value of the library call.

Return type:

bytes, pyvisa.constants.StatusCode

peek_32(session, address)[source]

Read an 32-bit value from the specified address.

Corresponds to viPeek32 function of the VISA library.

Parameters:
  • session – Unique logical identifier to a session.
  • address – Source address to read the value.
Returns:

Data read from bus, return value of the library call.

Return type:

bytes, pyvisa.constants.StatusCode

peek_64(session, address)[source]

Read an 64-bit value from the specified address.

Corresponds to viPeek64 function of the VISA library.

Parameters:
  • session – Unique logical identifier to a session.
  • address – Source address to read the value.
Returns:

Data read from bus, return value of the library call.

Return type:

bytes, pyvisa.constants.StatusCode

peek_8(session, address)[source]

Read an 8-bit value from the specified address.

Corresponds to viPeek8 function of the VISA library.

Parameters:
  • session – Unique logical identifier to a session.
  • address – Source address to read the value.
Returns:

Data read from bus, return value of the library call.

Return type:

bytes, pyvisa.constants.StatusCode

poke(session, address, width, data)[source]

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

Corresponds to viPoke* functions of the VISA library.

Parameters:
  • session – Unique logical identifier to a session.
  • address – Source address to read the value.
  • width – Number of bits to read.
  • data – Data to be written to the bus.
Returns:

return value of the library call.

Return type:

pyvisa.constants.StatusCode

poke_16(session, address, data)[source]

Write an 16-bit value from the specified address.

Corresponds to viPoke16 function of the VISA library.

Parameters:
  • session – Unique logical identifier to a session.
  • address – Source address to read the value.
  • data – value to be written to the bus.
Returns:

return value of the library call.

Return type:

pyvisa.constants.StatusCode

poke_32(session, address, data)[source]

Write an 32-bit value from the specified address.

Corresponds to viPoke32 function of the VISA library.

Parameters:
  • session – Unique logical identifier to a session.
  • address – Source address to read the value.
  • data – value to be written to the bus.
Returns:

return value of the library call.

Return type:

pyvisa.constants.StatusCode

poke_64(session, address, data)[source]

Write an 64-bit value from the specified address.

Corresponds to viPoke64 function of the VISA library.

Parameters:
  • session – Unique logical identifier to a session.
  • address – Source address to read the value.
  • data – value to be written to the bus.
Returns:

return value of the library call.

Return type:

pyvisa.constants.StatusCode

poke_8(session, address, data)[source]

Write an 8-bit value from the specified address.

Corresponds to viPoke8 function of the VISA library.

Parameters:
  • session – Unique logical identifier to a session.
  • address – Source address to read the value.
  • data – value to be written to the bus.
Returns:

Data read from bus.

Returns:

return value of the library call.

Return type:

pyvisa.constants.StatusCode

read(session, count)[source]

Reads data from device or interface synchronously.

Corresponds to viRead function of the VISA library.

Parameters:
  • session – Unique logical identifier to a session.
  • count – Number of bytes to be read.
Returns:

data read, return value of the library call.

Return type:

bytes, pyvisa.constants.StatusCode

read_asynchronously(session, count)[source]

Reads data from device or interface asynchronously.

Corresponds to viReadAsync function of the VISA library.

Parameters:
  • session – Unique logical identifier to a session.
  • count – Number of bytes to be read.
Returns:

result, jobid, return value of the library call.

Return type:

ctypes buffer, jobid, pyvisa.constants.StatusCode

read_memory(session, space, offset, width, extended=False)[source]

Reads in an 8-bit, 16-bit, 32-bit, or 64-bit value from the specified memory space and offset.

Corresponds to viIn* functions of the VISA library.

Parameters:
  • session – Unique logical identifier to a session.
  • space – Specifies the address space. (Constants.*SPACE*)
  • offset – Offset (in bytes) of the address or register from which to read.
  • width – Number of bits to read.
  • extended – Use 64 bits offset independent of the platform.
Returns:

Data read from memory, return value of the library call.

Return type:

int, pyvisa.constants.StatusCode

read_stb(session)[source]

Reads a status byte of the service request.

Corresponds to viReadSTB function of the VISA library.

Parameters:session – Unique logical identifier to a session.
Returns:Service request status byte, return value of the library call.
Return type:int, pyvisa.constants.StatusCode
read_to_file(session, filename, count)[source]

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

Corresponds to viReadToFile function of the VISA library.

Parameters:
  • session – Unique logical identifier to a session.
  • filename – Name of file to which data will be written.
  • count – Number of bytes to be read.
Returns:

Number of bytes actually transferred, return value of the library call.

Return type:

int, pyvisa.constants.StatusCode

resource_manager = None

Default ResourceManager instance for this library.

set_attribute(session, attribute, attribute_state)[source]

Sets the state of an attribute.

Corresponds to viSetAttribute function of the VISA library.

Parameters:
  • session – Unique logical identifier to a session.
  • attribute – Attribute for which the state is to be modified. (Attributes.*)
  • attribute_state – The state of the attribute to be set for the specified object.
Returns:

return value of the library call.

Return type:

pyvisa.constants.StatusCode

set_buffer(session, mask, size)[source]

Sets 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 – Unique logical identifier to a session.
  • mask – Specifies the type of buffer. (Constants.VI_READ_BUF, .VI_WRITE_BUF, .VI_IO_IN_BUF, .VI_IO_OUT_BUF)
  • size – The size to be set for the specified buffer(s).
Returns:

return value of the library call.

Return type:

pyvisa.constants.StatusCode

status_description(session, status)[source]

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

Corresponds to viStatusDesc function of the VISA library.

Parameters:
  • session – Unique logical identifier to a session.
  • status – Status code to interpret.
Returns:

  • The user-readable string interpretation of the status code passed to the operation,
  • return value of the library call.

Return type:

terminate(session, degree, job_id)[source]

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

Corresponds to viTerminate function of the VISA library.

Parameters:
  • session – Unique logical identifier to a session.
  • degree – Constants.NULL
  • job_id – Specifies an operation identifier.
Returns:

return value of the library call.

Return type:

pyvisa.constants.StatusCode

uninstall_all_visa_handlers(session)[source]

Uninstalls all previously installed handlers for a particular session.

Parameters:session – Unique logical identifier to a session. If None, operates on all sessions.
uninstall_handler(session, event_type, handler, user_handle=None)[source]

Uninstalls handlers for events.

Corresponds to viUninstallHandler function of the VISA library.

Parameters:
  • session – Unique logical identifier to a session.
  • event_type – Logical event identifier.
  • handler – Interpreted as a valid reference to a 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.
Returns:

return value of the library call.

Return type:

pyvisa.constants.StatusCode

uninstall_visa_handler(session, event_type, handler, user_handle=None)[source]

Uninstalls handlers for events.

Parameters:
  • session – Unique logical identifier to a session.
  • event_type – Logical event identifier.
  • handler – Interpreted as a valid reference to a handler to be uninstalled by a client application.
  • user_handle – The user handle (ctypes object or None) returned by install_visa_handler.
unlock(session)[source]

Relinquishes a lock for the specified resource.

Corresponds to viUnlock function of the VISA library.

Parameters:session – Unique logical identifier to a session.
Returns:return value of the library call.
Return type:pyvisa.constants.StatusCode
unmap_address(session)[source]

Unmaps memory space previously mapped by map_address().

Corresponds to viUnmapAddress function of the VISA library.

Parameters:session – Unique logical identifier to a session.
Returns:return value of the library call.
Return type:pyvisa.constants.StatusCode
unmap_trigger(session, trigger_source, trigger_destination)[source]

Undo a previous map from the specified trigger source line to the specified destination line.

Corresponds to viUnmapTrigger function of the VISA library.

Parameters:
  • session – Unique logical identifier to a session.
  • trigger_source – Source line used in previous map. (Constants.VI_TRIG*)
  • trigger_destination – Destination line used in previous map. (Constants.VI_TRIG*)
Returns:

return value of the library call.

Return type:

pyvisa.constants.StatusCode

usb_control_in(session, request_type_bitmap_field, request_id, request_value, index, length=0)[source]

Performs a USB control pipe transfer from the device.

Corresponds to viUsbControlIn function of the VISA library.

Parameters:
  • session – Unique logical identifier to a session.
  • request_type_bitmap_field – bmRequestType parameter of the setup stage of a USB control transfer.
  • request_id – bRequest parameter of the setup stage of a USB control transfer.
  • request_value – wValue parameter of the setup stage of a USB control transfer.
  • index – wIndex parameter of the setup stage of a USB control transfer. This is usually the index of the interface or endpoint.
  • length – 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 value of the library call.

Return type:

usb_control_out(session, request_type_bitmap_field, request_id, request_value, index, data='')[source]

Performs a USB control pipe transfer to the device.

Corresponds to viUsbControlOut function of the VISA library.

Parameters:
  • session – Unique logical identifier to a session.
  • request_type_bitmap_field – bmRequestType parameter of the setup stage of a USB control transfer.
  • request_id – bRequest parameter of the setup stage of a USB control transfer.
  • request_value – wValue parameter of the setup stage of a USB control transfer.
  • index – wIndex parameter of the setup stage of a USB control transfer. This is usually the index of the interface or endpoint.
  • data – 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:

pyvisa.constants.StatusCode

vxi_command_query(session, mode, command)[source]

Sends 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 – Unique logical identifier to a session.
  • mode – Specifies whether to issue a command and/or retrieve a response. (Constants.VI_VXI_CMD*, .VI_VXI_RESP*)
  • command – The miscellaneous command to send.
Returns:

The response retrieved from the device, return value of the library call.

Return type:

int, pyvisa.constants.StatusCode

wait_on_event(session, in_event_type, timeout)[source]

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

Corresponds to viWaitOnEvent function of the VISA library.

Parameters:
  • session – Unique logical identifier to a session.
  • in_event_type – Logical identifier of the event(s) to wait for.
  • timeout – 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:

  • Logical identifier of the event actually received
  • A handle specifying the unique occurrence of an event
  • return value of the library call.

Return type:

write(session, data)[source]

Writes data to device or interface synchronously.

Corresponds to viWrite function of the VISA library.

Parameters:
  • session – Unique logical identifier to a session.
  • data (str) – data to be written.
Returns:

Number of bytes actually transferred, return value of the library call.

Return type:

int, pyvisa.constants.StatusCode

write_asynchronously(session, data)[source]

Writes data to device or interface asynchronously.

Corresponds to viWriteAsync function of the VISA library.

Parameters:
  • session – Unique logical identifier to a session.
  • data – data to be written.
Returns:

Job ID of this asynchronous write operation, return value of the library call.

Return type:

jobid, pyvisa.constants.StatusCode

write_from_file(session, filename, count)[source]

Take data from a file and write it out synchronously.

Corresponds to viWriteFromFile function of the VISA library.

Parameters:
  • session – Unique logical identifier to a session.
  • filename – Name of file from which data will be read.
  • count – Number of bytes to be written.
Returns:

Number of bytes actually transferred, return value of the library call.

Return type:

int, pyvisa.constants.StatusCode

write_memory(session, space, offset, data, width, extended=False)[source]

Write in an 8-bit, 16-bit, 32-bit, 64-bit value to the specified memory space and offset.

Corresponds to viOut* functions of the VISA library.

Parameters:
  • session – Unique logical identifier to a session.
  • space – Specifies the address space. (Constants.*SPACE*)
  • offset – Offset (in bytes) of the address or register from which to read.
  • data – Data to write to bus.
  • width – Number of bits to read.
  • extended – Use 64 bits offset independent of the platform.
Returns:

return value of the library call.

Return type:

pyvisa.constants.StatusCode