Highlevel module

class pyvisa.highlevel.VisaLibrary[source]

High level VISA Library wrapper.

The easiest way to instantiate the library is to let pyvisa find the right one for you. This looks first in your configuration file (~/.pyvisarc). If it fails, it uses ctypes.util.find_library to try to locate a library in a way similar to what the compiler does:

>>> visa_library = VisaLibrary()

But you can also specify the path:

>>> visa_library = VisaLibrary('/my/path/visa.so')

Or use the from_paths constructor if you want to try multiple paths:

>>> visa_library = VisaLibrary.from_paths(['/my/path/visa.so', '/maybe/this/visa.so'])
Parameters:library_path – path of the VISA library.
assert_interrupt_signal(library, session, mode, status_id)

Asserts the specified interrupt or signal.

Parameters:
  • library – the visa library wrapped by ctypes.
  • 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.
assert_trigger(library, session, protocol)

Asserts software or hardware trigger.

Parameters:
  • library – the visa library wrapped by ctypes.
  • session – Unique logical identifier to a session.
  • protocol – Trigger protocol to use during assertion. (Constants.PROT*)
assert_utility_signal(library, session, line)

Asserts or deasserts the specified utility bus signal.

Parameters:
  • library – the visa library wrapped by ctypes.
  • session – Unique logical identifier to a session.
  • line – specifies the utility bus signal to assert. (Constants.UTIL_ASSERT*)
buffer_read(library, session, count)

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

Parameters:
  • library – the visa library wrapped by ctypes.
  • session – Unique logical identifier to a session.
  • count – Number of bytes to be read.
Returns:

data read.

Return type:

bytes

buffer_write(library, session, data)

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

Parameters:
  • library – the visa library wrapped by ctypes.
  • session – Unique logical identifier to a session.
  • data (bytes) – data to be written.
Returns:

number of written bytes.

clear(library, session)

Clears a device.

Parameters:
  • library – the visa library wrapped by ctypes.
  • session – Unique logical identifier to a session.
close(library, session)

Closes the specified session, event, or find list.

Parameters:
  • library – the visa library wrapped by ctypes.
  • session – Unique logical identifier to a session, event, or find list.
disable_event(library, session, event_type, mechanism)

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

Parameters:
  • library – the visa library wrapped by ctypes.
  • session – Unique logical identifier to a session.
  • event_type – Logical event identifier.
  • mechanism – Specifies event handling mechanisms to be disabled. (Constants.QUEUE, .Handler, .SUSPEND_HNDLR, .ALL_MECH)
discard_events(library, session, event_type, mechanism)

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

Parameters:
  • library – the visa library wrapped by ctypes.
  • session – Unique logical identifier to a session.
  • event_type – Logical event identifier.
  • mechanism – Specifies event handling mechanisms to be disabled. (Constants.QUEUE, .Handler, .SUSPEND_HNDLR, .ALL_MECH)
enable_event(library, session, event_type, mechanism, context=0)

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

Parameters:
  • library – the visa library wrapped by ctypes.
  • session – Unique logical identifier to a session.
  • event_type – Logical event identifier.
  • mechanism – Specifies event handling mechanisms to be disabled. (Constants.QUEUE, .Handler, .SUSPEND_HNDLR)
  • context
find_next(library, find_list)

Returns the next resource from the list of resources found during a previous call to find_resources().

Parameters:
  • library – the visa library wrapped by ctypes.
  • find_list – Describes a find list. This parameter must be created by find_resources().
Returns:

Returns a string identifying the location of a device.

Return type:

unicode (Py2) or str (Py3)

find_resources(library, session, query)

Queries a VISA system to locate the resources associated with a specified interface.

Parameters:
  • library – the visa library wrapped by ctypes.
  • session – Unique logical identifier to a session (unused, just to uniform signatures).
  • query – A regular expression followed by an optional logical expression. Use ‘?*’ for all.
Returns:

find_list, return_counter, instrument_description

Return type:

ViFindList, int, unicode (Py2) or str (Py3)

flush(library, session, mask)

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

Parameters:
  • library – the visa library wrapped by ctypes.
  • session – Unique logical identifier to a session.
  • mask – Specifies the action to be taken with flushing the buffer. (Constants.READ*, .WRITE*, .IO*)
classmethod from_paths(*paths)[source]

Helper constructor that tries to instantiate VisaLibrary from an iterable of possible library paths.

get_attribute(library, session, attribute)

Retrieves the state of an attribute.

Parameters:
  • library – the visa library wrapped by ctypes.
  • 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 type:

unicode (Py2) or str (Py3), list or other type

get_default_resource_manager(library)

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

Parameters:library – the visa library wrapped by ctypes.
Returns:Unique logical identifier to a Default Resource Manager session.
gpib_command(library, session, data)

Write GPIB command bytes on the bus.

Parameters:
  • library – the visa library wrapped by ctypes.
  • session – Unique logical identifier to a session.
  • data (bytes) – data tor write.
Returns:

Number of written bytes.

gpib_control_atn(library, session, mode)

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

Parameters:
  • library – the visa library wrapped by ctypes.
  • session – Unique logical identifier to a session.
  • mode – Specifies the state of the ATN line and optionally the local active controller state. (Constants.GPIB_ATN*)
gpib_control_ren(library, session, mode)

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

Parameters:
  • library – the visa library wrapped by ctypes.
  • session – Unique logical identifier to a session.
  • mode – Specifies the state of the REN line and optionally the device remote/local state. (Constants.GPIB_REN*)
gpib_pass_control(library, session, primary_address, secondary_address)

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

Parameters:
  • library – the visa library wrapped by ctypes.
  • 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.NO_SEC_ADDR.
gpib_send_ifc(library, session)

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

Parameters:
  • library – the visa library wrapped by ctypes.
  • session – Unique logical identifier to a session.
in_16(library, session, space, offset, extended=False)

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

Parameters:
  • library – the visa library wrapped by ctypes.
  • 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.

in_32(library, session, space, offset, extended=False)

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

Parameters:
  • library – the visa library wrapped by ctypes.
  • 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.

in_8(library, session, space, offset, extended=False)

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

Parameters:
  • library – the visa library wrapped by ctypes.
  • 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.

install_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)

lock(library, session, lock_type, timeout, requested_key=None)

Establishes an access mode to the specified resources.

Parameters:
  • library – the visa library wrapped by ctypes.
  • 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.

map_address(library, session, map_space, map_base, map_size, access=0, suggested=0)

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

Parameters:
  • library – the visa library wrapped by ctypes.
  • 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.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.

map_trigger(library, session, trigger_source, trigger_destination, mode)

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

Parameters:
  • library – the visa library wrapped by ctypes.
  • session – Unique logical identifier to a session.
  • trigger_source – Source line from which to map. (Constants.TRIG*)
  • trigger_destination – Destination line to which to map. (Constants.TRIG*)
  • mode
memory_allocation(library, session, size, extended=False)

Allocates memory from a resource’s memory region.

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

Returns the offset of the allocated memory.

memory_free(library, session, offset, extended=False)

Frees memory previously allocated using the memory_allocation() operation.

Parameters:
  • library – the visa library wrapped by ctypes.
  • session – Unique logical identifier to a session.
  • offset – Offset of the memory to free.
  • extended – Use 64 bits offset independent of the platform.
move(library, session, source_space, source_offset, source_width, destination_space, destination_offset, destination_width, length)

Moves a block of data.

Parameters:
  • library – the visa library wrapped by ctypes.
  • 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.
move_asynchronously(library, session, source_space, source_offset, source_width, destination_space, destination_offset, destination_width, length)

Moves a block of data asynchronously.

Parameters:
  • library – the visa library wrapped by ctypes.
  • 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.

move_in_16(library, session, space, offset, length, extended=False)

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

Parameters:
  • library – the visa library wrapped by ctypes.
  • 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 bus.

Corresponds to viMoveIn16 functions of the visa library.

move_in_32(library, session, space, offset, length, extended=False)

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

Parameters:
  • library – the visa library wrapped by ctypes.
  • 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 bus.

Corresponds to viMoveIn32 functions of the visa library.

move_in_8(library, session, space, offset, length, extended=False)

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

Parameters:
  • library – the visa library wrapped by ctypes.
  • 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 bus.

Corresponds to viMoveIn8 functions of the visa library.

move_out_16(library, session, space, offset, length, data, extended=False)

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

Parameters:
  • library – the visa library wrapped by ctypes.
  • 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.

Corresponds to viMoveOut16 functions of the visa library.

move_out_32(library, session, space, offset, length, data, extended=False)

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

Parameters:
  • library – the visa library wrapped by ctypes.
  • 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.

Corresponds to viMoveOut32 functions of the visa library.

move_out_8(library, session, space, offset, length, data, extended=False)

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

Parameters:
  • library – the visa library wrapped by ctypes.
  • 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.

Corresponds to viMoveOut8 functions of the visa library.

open(library, session, resource_name, access_mode=0, open_timeout=0)

Opens a session to the specified resource.

Parameters:
  • library – the visa library wrapped by ctypes.
  • 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 – Specifies the mode by which the resource is to be accessed. (Constants.NULL or Constants.*LOCK*)
  • open_timeout – Specifies the maximum time period (in milliseconds) that this operation waits before returning an error.
Returns:

Unique logical identifier reference to a session.

open_default_resource_manager(library)

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

Parameters:library – the visa library wrapped by ctypes.
Returns:Unique logical identifier to a Default Resource Manager session.
out_16(library, session, space, offset, data, extended=False)

Write in an 16-bit value from the specified memory space and offset. :param library: the visa library wrapped by ctypes. :param session: Unique logical identifier to a session. :param space: Specifies the address space. (Constants.*SPACE*) :param offset: Offset (in bytes) of the address or register from which to read. :param data: Data to write to bus. :param extended: Use 64 bits offset independent of the platform.

Corresponds to viOut16 functions of the visa library.

out_32(library, session, space, offset, data, extended=False)

Write in an 32-bit value from the specified memory space and offset. :param library: the visa library wrapped by ctypes. :param session: Unique logical identifier to a session. :param space: Specifies the address space. (Constants.*SPACE*) :param offset: Offset (in bytes) of the address or register from which to read. :param data: Data to write to bus. :param extended: Use 64 bits offset independent of the platform.

Corresponds to viOut32 functions of the visa library.

out_8(library, session, space, offset, data, extended=False)

Write in an 8-bit value from the specified memory space and offset. :param library: the visa library wrapped by ctypes. :param session: Unique logical identifier to a session. :param space: Specifies the address space. (Constants.*SPACE*) :param offset: Offset (in bytes) of the address or register from which to read. :param data: Data to write to bus. :param extended: Use 64 bits offset independent of the platform.

Corresponds to viOut8 functions of the visa library.

parse_resource(library, session, resource_name)

Parse a resource string to get the interface information.

Parameters:
  • library – the visa library wrapped by ctypes.
  • 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 type:

:class:ResourceInfo

parse_resource_extended(library, session, resource_name)

Parse a resource string to get extended interface information.

Parameters:
  • library – the visa library wrapped by ctypes.
  • 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 type:

:class:ResourceInfo

peek_16(library, session, address)

Read an 16-bit value from the specified address.

Parameters:
  • library – the visa library wrapped by ctypes.
  • session – Unique logical identifier to a session.
  • address – Source address to read the value.
Returns:

Data read from bus.

Return type:

bytes

peek_32(library, session, address)

Read an 32-bit value from the specified address.

Parameters:
  • library – the visa library wrapped by ctypes.
  • session – Unique logical identifier to a session.
  • address – Source address to read the value.
Returns:

Data read from bus.

Return type:

bytes

peek_8(library, session, address)

Read an 8-bit value from the specified address.

Parameters:
  • library – the visa library wrapped by ctypes.
  • session – Unique logical identifier to a session.
  • address – Source address to read the value.
Returns:

Data read from bus.

Return type:

bytes

poke_16(library, session, address, data)

Write an 16-bit value from the specified address.

Parameters:
  • library – the visa library wrapped by ctypes.
  • 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.

poke_32(library, session, address, data)

Write an 32-bit value from the specified address.

Parameters:
  • library – the visa library wrapped by ctypes.
  • 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.

poke_8(library, session, address, data)

Write an 8-bit value from the specified address.

Parameters:
  • library – the visa library wrapped by ctypes.
  • 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.

read(library, session, count)

Reads data from device or interface synchronously.

Parameters:
  • library – the visa library wrapped by ctypes.
  • session – Unique logical identifier to a session.
  • count – Number of bytes to be read.
Returns:

data read.

Return type:

bytes

read_asynchronously(library, session, count)

Reads data from device or interface asynchronously.

Parameters:
  • library – the visa library wrapped by ctypes.
  • session – Unique logical identifier to a session.
  • count – Number of bytes to be read.
Returns:

(ctypes buffer with result, jobid)

read_stb(library, session)

Reads a status byte of the service request.

Parameters:
  • library – the visa library wrapped by ctypes.
  • session – Unique logical identifier to a session.
Returns:

Service request status byte.

read_to_file(library, session, filename, count)

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

Parameters:
  • library – the visa library wrapped by ctypes.
  • 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.

resource_manager[source]

Default resource manager object for this library.

set_attribute(library, session, attribute, attribute_state)

Sets the state of an attribute.

Parameters:
  • library – the visa library wrapped by ctypes.
  • 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.
set_buffer(library, session, mask, size)

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

Parameters:
  • library – the visa library wrapped by ctypes.
  • session – Unique logical identifier to a session.
  • mask – Specifies the type of buffer. (Constants.READ_BUF, .WRITE_BUF, .IO_IN_BUF, .IO_OUT_BUF)
  • size – The size to be set for the specified buffer(s).
status[source]

Last return value of the library.

status_description(library, session, status)

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

Parameters:
  • library – the visa library wrapped by ctypes.
  • 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 type:

unicode (Py2) or str (Py3)

terminate(library, session, degree, job_id)

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

Parameters:
  • library – the visa library wrapped by ctypes.
  • session – Unique logical identifier to a session.
  • degree – Constants.NULL
  • job_id – Specifies an operation identifier.
uninstall_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 – A value specified by an application that can be used for identifying handlers uniquely in a session for an event.
unlock(library, session)

Relinquishes a lock for the specified resource.

Parameters:
  • library – the visa library wrapped by ctypes.
  • session – Unique logical identifier to a session.
unmap_address(library, session)

Unmaps memory space previously mapped by map_address().

Parameters:
  • library – the visa library wrapped by ctypes.
  • session – Unique logical identifier to a session.
unmap_trigger(library, session, trigger_source, trigger_destination)

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

Parameters:
  • library – the visa library wrapped by ctypes.
  • session – Unique logical identifier to a session.
  • trigger_source – Source line used in previous map. (Constants.TRIG*)
  • trigger_destination – Destination line used in previous map. (Constants.TRIG*)
usb_control_in(library, session, request_type_bitmap_field, request_id, request_value, index, length=0)

Performs a USB control pipe transfer from the device.

Parameters:
  • library – the visa library wrapped by ctypes.
  • 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 type:

bytes

usb_control_out(library, session, request_type_bitmap_field, request_id, request_value, index, data=u'')

Performs a USB control pipe transfer to the device.

Parameters:
  • library – the visa library wrapped by ctypes.
  • 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.
vxi_command_query(library, session, mode, command)

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

Parameters:
  • library – the visa library wrapped by ctypes.
  • session – Unique logical identifier to a session.
  • mode – Specifies whether to issue a command and/or retrieve a response. (Constants.VXI_CMD*, .VXI_RESP*)
  • command – The miscellaneous command to send.
Returns:

The response retrieved from the device.

wait_on_event(library, session, in_event_type, timeout)

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

Parameters:
  • library – the visa library wrapped by ctypes.
  • 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.

write(library, session, data)

Writes data to device or interface synchronously.

Parameters:
  • library – the visa library wrapped by ctypes.
  • session – Unique logical identifier to a session.
  • data (str) – data to be written.
Returns:

Number of bytes actually transferred.

write_asynchronously(library, session, data)

Writes data to device or interface asynchronously.

Parameters:
  • library – the visa library wrapped by ctypes.
  • session – Unique logical identifier to a session.
  • data – data to be written.
Returns:

Job ID of this asynchronous write operation.

write_from_file(library, session, filename, count)

Take data from a file and write it out synchronously.

Parameters:
  • library – the visa library wrapped by ctypes.
  • 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.

class pyvisa.highlevel.ResourceManager[source]

VISA Resource Manager

Parameters:visa_library – VisaLibrary Instance or path of the VISA library (if not given, the default for the platform will be used).
get_instrument(resource_name, **kwargs)[source]

Return an instrument for the resource name.

Parameters:
  • resource_name – name or alias of the resource to open.
  • kwargs – keyword arguments to be passed to the instrument constructor.
list_resources(query='?*::INSTR')[source]

Returns a tuple of all connected devices matching query.

Parameters:query – regular expression used to match devices.
list_resources_info(query='?*::INSTR')[source]

Returns a dictionary mapping resource names to resource extended information of all connected devices matching query.

Parameters:query – regular expression used to match devices.
Returns:Mapping of resource name to ResourceInfo
Return type:dict
open_resource(resource_name, access_mode=0, open_timeout=0)[source]

Open the specified resources.

Parameters:
  • resource_name – name or alias of the resource to open.
  • access_mode – access mode.
  • open_timeout – time out to open.
Returns:

Unique logical identifier reference to a session.

resource_info(resource_name)[source]

Get the extended information of a particular resource

Parameters:resource_name – Unique symbolic name of a resource.
Return type:ResourceInfo
class pyvisa.highlevel.Instrument(resource_name, resource_manager=None, **kwargs)[source]

Class for all kinds of Instruments.

It can be instantiated, however, if you want to use special features of a certain interface system (GPIB, USB, RS232, etc), you must instantiate one of its child classes.

Parameters:
  • resource_name – the instrument’s resource name or an alias, may be taken from the list from list_resources method from a ResourceManager.
  • timeout – the VISA timeout for each low-level operation in milliseconds.
  • term_chars – the termination characters for this device.
  • chunk_size – size of data packets in bytes that are read from the device.
  • lock – whether you want to have exclusive access to the device. Default: VI_NO_LOCK
  • ask_delay – waiting time in seconds after each write command. Default: 0.0
  • send_end – whether to assert end line after each write command. Default: True
  • values_format – floating point data value format. Default: ascii (0)
ask(message, delay=None)[source]

A combination of write(message) and read()

Parameters:
  • message (str) – the message to send.
  • delay – delay in seconds between write and read operations. if None, defaults to self.ask_delay
Returns:

the answer from the device.

Return type:

str

ask_for_values(message, format=None, delay=None)[source]

A combination of write(message) and read_values()

Parameters:
  • message (str) – the message to send.
  • delay – delay in seconds between write and read operations. if None, defaults to self.ask_delay
Returns:

the answer from the device.

Return type:

list

encoding[source]

Encoding used for read and write operations.

read(termination=None, encoding=None)[source]

Read a string from the device.

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

All line-ending characters are stripped from the end of the string.

Return type:str
read_raw(size=None)[source]

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

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

Return type:bytes
read_termination[source]

Read termination character.

read_values(fmt=None)[source]

Read a list of floating point values from the device.

Parameters:fmt – the format of the values. If given, it overrides the class attribute “values_format”. Possible values are bitwise disjunctions of the above constants ascii, single, double, and big_endian. Default is ascii.
Returns:the list of read values
Return type:list
send_end[source]

Whether or not to assert EOI (or something equivalent after each write operation.

term_chars[source]

Set or read a new termination character sequence (property).

Normally, you just give the new termination sequence, which is appended to each write operation (unless it’s already there), and expected as the ending mark during each read operation. A typical example is CR+LF or just CR. If you assign “” to this property, the termination sequence is deleted.

The default is None, which means that CR + LF is appended to each write operation but not expected after each read operation (but stripped if present).

trigger()[source]

Sends a software trigger to the device.

write(message, termination=None, encoding=None)[source]

Write a string message to the device.

The term_chars are appended to it, unless they are already.

Parameters:message (unicode (Py2) or str (Py3)) – the message to be sent.
Returns:number of bytes written.
Return type:int
write_raw(message)[source]

Write a string message to the device.

The term_chars are appended to it, unless they are already.

Parameters:message (bytes) – the message to be sent.
Returns:number of bytes written.
Return type:int
write_termination[source]

Writer termination character.

class pyvisa.highlevel.SerialInstrument(resource_name, resource_manager=None, **keyw)[source]

Class for serial (RS232 or parallel port) instruments. Not USB!

This class extents the Instrument class with special operations and properties of serial instruments.

Parameters:resource_name – the instrument’s resource name or an alias, may be taken from the list from list_resources method from a ResourceManager.

Further keyword arguments are passed to the constructor of class Instrument.

baud_rate[source]

The baud rate of the serial instrument.

data_bits[source]

Number of data bits contained in each frame (from 5 to 8).

end_input[source]

indicates the method used to terminate read operations

parity[source]

The parity used with every frame transmitted and received.

stop_bits[source]

Number of stop bits contained in each frame (1, 1.5, or 2).

class pyvisa.highlevel.GpibInstrument(gpib_identifier, board_number=0, resource_manager=None, **keyw)[source]

Class for GPIB instruments.

This class extents the Instrument class with special operations and properties of GPIB instruments.

Parameters:
  • gpib_identifier – strings are interpreted as instrument’s VISA resource name. Numbers are interpreted as GPIB number.
  • board_number – the number of the GPIB bus.

Further keyword arguments are passed to the constructor of class Instrument.

stb[source]

Service request status register.

wait_for_srq(timeout=25)[source]

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

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

Parameters:timeout – the maximum waiting time in seconds. Defaul: 25 (seconds). None means waiting forever if necessary.