Resource classes

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

Specific Classes

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

Base class for resources.

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

before_close() → None[source]

Called just before closing an instrument.

clear() → None[source]

Clear this resource.

close() → None[source]

Closes the VISA session and marks the handle as invalid.

disable_event(event_type: pyvisa.constants.EventType, mechanism: pyvisa.constants.EventMechanism) → None[source]

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

Parameters:
  • event_type (constants.EventType) – Logical event identifier.
  • mechanism (constants.EventMechanism) – Specifies event handling mechanisms to be disabled.
discard_events(event_type: pyvisa.constants.EventType, mechanism: pyvisa.constants.EventMechanism) → None[source]

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

Parameters:
  • event_type (constants.EventType) – Logical event identifier.
  • mechanism (constants.EventMechanism) – Specifies event handling mechanisms to be disabled.
enable_event(event_type: pyvisa.constants.EventType, mechanism: pyvisa.constants.EventMechanism, context: None = None) → None[source]

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

Parameters:
  • event_type (constants.EventType) – Logical event identifier.
  • mechanism (constants.EventMechanism) – Specifies event handling mechanisms to be enabled
  • context (None) – Not currently used, leave as None.
get_visa_attribute(name: pyvisa.constants.ResourceAttribute) → Any[source]

Retrieves the state of an attribute in this resource.

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

Parameters:name (constants.ResourceAttribute) – Resource attribute for which the state query is made.
Returns:The state of the queried attribute for a specified resource.
Return type:Any
ignore_warning(*warnings_constants) → AbstractContextManager[T_co][source]

Ignoring warnings context manager for the current resource.

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

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

install_handler(event_type: pyvisa.constants.EventType, handler: Callable[[NewType.<locals>.new_type, pyvisa.constants.EventType, NewType.<locals>.new_type, Any], None], user_handle=None) → Any[source]

Install handlers for event callbacks in this resource.

Parameters:
  • event_type (constants.EventType) – Logical event identifier.
  • handler (VISAHandler) – Handler function to be installed by a client application.
  • user_handle – A value specified by an application that can be used for identifying handlers uniquely for an event type. Depending on the backend they may be restriction on the possible values. Look at the backend install_visa_handler for more details.
Returns:

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

Return type:

Any

interface_number

Board number for the given interface.

interface_type

Interface type of the given session.

last_status

Last status code for this session.

lock(timeout: Union[float, typing_extensions.Literal['default'][default]] = 'default', requested_key: Optional[str] = None) → str[source]

Establish a shared lock to the resource.

Parameters:
  • timeout (Union[float, Literal["default"]], optional) – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. Defaults to “default” which means use self.timeout.
  • requested_key (Optional[str], optional) – Access key used by another session with which you want your session to share a lock or None to generate a new shared access key.
Returns:

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

Return type:

str

lock_context(timeout: Union[float, typing_extensions.Literal['default'][default]] = 'default', requested_key: Optional[str] = 'exclusive') → Iterator[Optional[str]][source]

A context that locks

Parameters:
  • timeout (Union[float, Literal["default"]], optional) – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. Defaults to “default” which means use self.timeout.
  • requested_key (Optional[str], optional) – When using default of ‘exclusive’ the lock is an exclusive lock. Otherwise it is the access key for the shared lock or None to generate a new shared access key.
Yields:

Optional[str] – The access_key if applicable.

lock_excl(timeout: Union[float, typing_extensions.Literal['default'][default]] = 'default') → None[source]

Establish an exclusive lock to the resource.

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

Current locking state of the resource.

open(access_mode: pyvisa.constants.AccessModes = <AccessModes.no_lock: 0>, open_timeout: int = 5000) → None[source]

Opens a session to the specified resource.

Parameters:
  • access_mode (constants.AccessModes, optional) – Specifies the mode by which the resource is to be accessed. Defaults to constants.AccessModes.no_lock.
  • open_timeout (int, optional) – If the access_mode parameter requests a lock, then this parameter specifies the absolute time period (in milliseconds) that the resource waits to get unlocked before this operation returns an error. Defaults to 5000.
classmethod register(interface_type: pyvisa.constants.InterfaceType, resource_class: str) → Callable[[Type[T]], Type[T]][source]

Create a decorator to register a class.

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

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

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

Return type:

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

resource_class

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

resource_info

Get the extended information of this resource.

resource_manager = None

Reference to the resource manager used by this resource

resource_manufacturer_name

Manufacturer name of the vendor that implemented the VISA library.

resource_name

Unique identifier for a resource compliant with the address structure.

session

Resource session handle.

Raises:errors.InvalidSession – Raised if session is closed.
set_visa_attribute(name: pyvisa.constants.ResourceAttribute, state: Any) → pyvisa.constants.StatusCode[source]

Set the state of an attribute.

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

Parameters:
  • name (constants.ResourceAttribute) – Attribute for which the state is to be modified.
  • state (Any) – The state of the attribute to be set for the specified object.
Returns:

Return value of the library call.

Return type:

constants.StatusCode

spec_version

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

timeout

Timeout in milliseconds for all resource I/O operations.

uninstall_handler(event_type: pyvisa.constants.EventType, handler: Callable[[NewType.<locals>.new_type, pyvisa.constants.EventType, NewType.<locals>.new_type, Any], None], user_handle=None) → None[source]

Uninstalls handlers for events in this resource.

Parameters:
  • event_type (constants.EventType) – Logical event identifier.
  • handler (VISAHandler) – Handler function to be uninstalled by a client application.
  • user_handle (Any) – The user handle returned by install_handler.
unlock() → None[source]

Relinquishes a lock for the specified resource.

visa_attributes_classes = {<class 'pyvisa.attributes.AttrVI_ATTR_RSRC_LOCK_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_SPEC_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_TMO_VALUE'>, <class 'pyvisa.attributes.AttrVI_ATTR_MAX_QUEUE_LENGTH'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_TYPE'>, <class 'pyvisa.attributes.AttrVI_ATTR_USER_DATA'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_CLASS'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_IMPL_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_INST_NAME'>}

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

visalib = None

Reference to the VISA library instance used by the resource

wait_on_event(in_event_type: pyvisa.constants.EventType, timeout: int, capture_timeout: bool = False) → pyvisa.resources.resource.WaitResponse[source]

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

in_event_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. None means waiting forever if necessary.
capture_timeout : bool, optional
When True will not produce a VisaIOError(VI_ERROR_TMO) but instead return a WaitResponse with timed_out=True.
Returns:Object that contains event_type, context and ret value.
Return type:WaitResponse
wrap_handler(callable: Callable[[Resource, pyvisa.events.Event, Any], None]) → Callable[[NewType.<locals>.new_type, pyvisa.constants.EventType, NewType.<locals>.new_type, Any], None][source]

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

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

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

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

Base class for resources that use message based communication.

CR = '\r'
LF = '\n'
allow_dma

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

assert_trigger() → None[source]

Sends a software trigger to the device.

before_close() → None

Called just before closing an instrument.

chunk_size = 20480

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

clear() → None

Clear this resource.

close() → None

Closes the VISA session and marks the handle as invalid.

disable_event(event_type: pyvisa.constants.EventType, mechanism: pyvisa.constants.EventMechanism) → None

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

Parameters:
  • event_type (constants.EventType) – Logical event identifier.
  • mechanism (constants.EventMechanism) – Specifies event handling mechanisms to be disabled.
discard_events(event_type: pyvisa.constants.EventType, mechanism: pyvisa.constants.EventMechanism) → None

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

Parameters:
  • event_type (constants.EventType) – Logical event identifier.
  • mechanism (constants.EventMechanism) – Specifies event handling mechanisms to be disabled.
enable_event(event_type: pyvisa.constants.EventType, mechanism: pyvisa.constants.EventMechanism, context: None = None) → None

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

Parameters:
  • event_type (constants.EventType) – Logical event identifier.
  • mechanism (constants.EventMechanism) – Specifies event handling mechanisms to be enabled
  • context (None) – Not currently used, leave as None.
encoding

Encoding used for read and write operations.

flush(mask: pyvisa.constants.BufferOperation) → None[source]

Manually clears the specified buffers.

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

Parameters:mask (constants.BufferOperation) – Specifies the action to be taken with flushing the buffer. See highlevel.VisaLibraryBase.flush for a detailed description.
get_visa_attribute(name: pyvisa.constants.ResourceAttribute) → Any

Retrieves the state of an attribute in this resource.

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

Parameters:name (constants.ResourceAttribute) – Resource attribute for which the state query is made.
Returns:The state of the queried attribute for a specified resource.
Return type:Any
ignore_warning(*warnings_constants) → AbstractContextManager[T_co]

Ignoring warnings context manager for the current resource.

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

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

This attribute value is defined by the individual manufacturer and increments with each new revision. The format of the value has the upper 12 bits as the major number of the version, the next lower 12 bits as the minor number of the version, and the lowest 8 bits as the sub-minor number of the version.
VISA Attribute:VI_ATTR_RSRC_IMPL_VERSION (1073676291)
Type:int
Range:0 <= value <= 4294967295
install_handler(event_type: pyvisa.constants.EventType, handler: Callable[[NewType.<locals>.new_type, pyvisa.constants.EventType, NewType.<locals>.new_type, Any], None], user_handle=None) → Any

Install handlers for event callbacks in this resource.

Parameters:
  • event_type (constants.EventType) – Logical event identifier.
  • handler (VISAHandler) – Handler function to be installed by a client application.
  • user_handle – A value specified by an application that can be used for identifying handlers uniquely for an event type. Depending on the backend they may be restriction on the possible values. Look at the backend install_visa_handler for more details.
Returns:

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

Return type:

Any

interface_number

Board number for the given interface. :VISA Attribute: VI_ATTR_INTF_NUM (1073676662) :type: int :range: 0 <= value <= 65535

interface_type

Interface type of the given session. :VISA Attribute: VI_ATTR_INTF_TYPE (1073676657) :type: :class:pyvisa.constants.InterfaceType

io_protocol

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

last_status

Last status code for this session.

lock(timeout: Union[float, typing_extensions.Literal['default'][default]] = 'default', requested_key: Optional[str] = None) → str

Establish a shared lock to the resource.

Parameters:
  • timeout (Union[float, Literal["default"]], optional) – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. Defaults to “default” which means use self.timeout.
  • requested_key (Optional[str], optional) – Access key used by another session with which you want your session to share a lock or None to generate a new shared access key.
Returns:

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

Return type:

str

lock_context(timeout: Union[float, typing_extensions.Literal['default'][default]] = 'default', requested_key: Optional[str] = 'exclusive') → Iterator[Optional[str]]

A context that locks

Parameters:
  • timeout (Union[float, Literal["default"]], optional) – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. Defaults to “default” which means use self.timeout.
  • requested_key (Optional[str], optional) – When using default of ‘exclusive’ the lock is an exclusive lock. Otherwise it is the access key for the shared lock or None to generate a new shared access key.
Yields:

Optional[str] – The access_key if applicable.

lock_excl(timeout: Union[float, typing_extensions.Literal['default'][default]] = 'default') → None

Establish an exclusive lock to the resource.

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

Current locking state of the resource.

The resource can be unlocked, locked with an exclusive lock, or locked with a shared lock.
VISA Attribute:VI_ATTR_RSRC_LOCK_STATE (1073676292)
Type::class:pyvisa.constants.AccessModes
open(access_mode: pyvisa.constants.AccessModes = <AccessModes.no_lock: 0>, open_timeout: int = 5000) → None

Opens a session to the specified resource.

Parameters:
  • access_mode (constants.AccessModes, optional) – Specifies the mode by which the resource is to be accessed. Defaults to constants.AccessModes.no_lock.
  • open_timeout (int, optional) – If the access_mode parameter requests a lock, then this parameter specifies the absolute time period (in milliseconds) that the resource waits to get unlocked before this operation returns an error. Defaults to 5000.
query(message: str, delay: Optional[float] = None) → str[source]

A combination of write(message) and read()

Parameters:
  • message (str) – The message to send.
  • delay (Optional[float], optional) – Delay in seconds between write and read operations. If None, defaults to self.query_delay.
Returns:

Answer from the device.

Return type:

str

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

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

Parameters:
  • message (str) – The message to send.
  • converter (ASCII_CONVERTER, optional) – Str format of function to convert each value. Default to “f”.
  • separator (Union[str, Callable[[str], Iterable[str]]]) – str or callable used to split the data into individual elements. If a str is given, data.split(separator) is used. Default to “,”.
  • container (Union[Type, Callable[[Iterable], Sequence]], optional) – Container type to use for the output data. Possible values are: list, tuple, np.ndarray, etc, Default to list.
  • delay (Optional[float], optional) – Delay in seconds between write and read operations. If None, defaults to self.query_delay.
Returns:

Parsed data.

Return type:

Sequence

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

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

Parameters:
  • message (str) – The message to send.
  • datatype (BINARY_DATATYPES, optional) – Format string for a single element. See struct module. ‘f’ by default.
  • is_big_endian (bool, optional) – Are the data in big or little endian order. Defaults to False.
  • container (Union[Type, Callable[[Iterable], Sequence]], optional) – Container type to use for the output data. Possible values are: list, tuple, np.ndarray, etc, Default to list.
  • delay (Optional[float], optional) – Delay in seconds between write and read operations. If None, defaults to self.query_delay.
  • header_fmt (util.BINARY_HEADERS, optional) – Format of the header prefixing the data. Defaults to ‘ieee’.
  • expect_termination (bool, optional) – When set to False, the expected length of the binary values block does not account for the final termination character (the read termination). Defaults to True.
  • data_points (int, optional) – Number of points expected in the block. This is used only if the instrument does not report it itself. This will be converted in a number of bytes based on the datatype. Defaults to 0.
  • chunk_size (int, optional) – Size of the chunks to read from the device. Using larger chunks may be faster for large amount of data.
Returns:

Data read from the device.

Return type:

Sequence[Union[int, float]]

query_delay = 0.0

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

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

Read a string from the device.

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

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

Message read from the instrument and decoded.

Return type:

str

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

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

Parameters:converter (ASCII_CONVERTER, optional) – Str format of function to convert each value. Default to “f”.
separator : Union[str, Callable[[str], Iterable[str]]]
str or callable used to split the data into individual elements. If a str is given, data.split(separator) is used. Default to “,”.
container : Union[Type, Callable[[Iterable], Sequence]], optional
Container type to use for the output data. Possible values are: list, tuple, np.ndarray, etc, Default to list.
Returns:Parsed data.
Return type:Sequence
read_binary_values(datatype: typing_extensions.Literal['s', 'b', 'B', 'h', 'H', 'i', 'I', 'l', 'L', 'q', 'Q', 'f', 'd'][s, b, B, h, H, i, I, l, L, q, Q, f, d] = 'f', is_big_endian: bool = False, container: Union[Type[CT_co], Callable[[Iterable[T_co]], Sequence[T_co]]] = <class 'list'>, header_fmt: typing_extensions.Literal['ieee', 'hp', 'empty'][ieee, hp, empty] = 'ieee', expect_termination: bool = True, data_points: int = 0, chunk_size: Optional[int] = None) → Sequence[Union[int, float]][source]

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

Parameters:
  • datatype (BINARY_DATATYPES, optional) – Format string for a single element. See struct module. ‘f’ by default.
  • is_big_endian (bool, optional) – Are the data in big or little endian order. Defaults to False.
  • container (Union[Type, Callable[[Iterable], Sequence]], optional) – Container type to use for the output data. Possible values are: list, tuple, np.ndarray, etc, Default to list.
  • header_fmt (util.BINARY_HEADERS, optional) – Format of the header prefixing the data. Defaults to ‘ieee’.
  • expect_termination (bool, optional) – When set to False, the expected length of the binary values block does not account for the final termination character (the read termination). Defaults to True.
  • data_points (int, optional) – Number of points expected in the block. This is used only if the instrument does not report it itself. This will be converted in a number of bytes based on the datatype. Defaults to 0.
  • chunk_size (int, optional) – Size of the chunks to read from the device. Using larger chunks may be faster for large amount of data.
Returns:

Data read from the device.

Return type:

Sequence[Union[int, float]]

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

Read a certain number of bytes from the instrument.

Parameters:
  • count (int) – The number of bytes to read from the instrument.
  • chunk_size (Optional[int], optional) – The chunk size to use to perform the reading. If count > chunk_size multiple low level operations will be performed. Defaults to None, meaning the resource wide set value is set.
  • break_on_termchar (bool, optional) – Should the reading stop when a termination character is encountered or when the message ends. Defaults to False.
Returns:

Bytes read from the instrument.

Return type:

bytes

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

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

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

Parameters:size (Optional[int], optional) – The chunk size to use to perform the reading. Defaults to None, meaning the resource wide set value is set.
Returns:Bytes read from the instrument.
Return type:bytes
read_stb() → int[source]

Service request status register.

read_termination

Read termination character.

read_termination_context(new_termination: str) → Iterator[T_co][source]
classmethod register(interface_type: pyvisa.constants.InterfaceType, resource_class: str) → Callable[[Type[T]], Type[T]]

Create a decorator to register a class.

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

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

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

Return type:

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

resource_class

Resource class as defined by the canonical resource name.

Possible values are: INSTR, INTFC, SOCKET, RAW…
VISA Attribute:VI_ATTR_RSRC_CLASS (3221159937)
resource_info

Get the extended information of this resource.

resource_manufacturer_name

Manufacturer name of the vendor that implemented the VISA library.

This attribute is not related to the device manufacturer attributes.

Note The value of this attribute is for display purposes only and not for programmatic decisions, as the value can differ between VISA implementations and/or revisions.

VISA Attribute:VI_ATTR_RSRC_MANF_NAME (3221160308)
resource_name

Unique identifier for a resource compliant with the address structure. :VISA Attribute: VI_ATTR_RSRC_NAME (3221159938)

send_end

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

session

Resource session handle.

Raises:errors.InvalidSession – Raised if session is closed.
set_visa_attribute(name: pyvisa.constants.ResourceAttribute, state: Any) → pyvisa.constants.StatusCode

Set the state of an attribute.

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

Parameters:
  • name (constants.ResourceAttribute) – Attribute for which the state is to be modified.
  • state (Any) – The state of the attribute to be set for the specified object.
Returns:

Return value of the library call.

Return type:

constants.StatusCode

spec_version

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

The format of the value has the upper 12 bits as the major number of the version, the next lower 12 bits as the minor number of the version, and the lowest 8 bits as the sub-minor number of the version. The current VISA specification defines the value to be 00300000h.
VISA Attribute:VI_ATTR_RSRC_SPEC_VERSION (1073676656)
Type:int
Range:0 <= value <= 4294967295
stb

Service request status register.

timeout

Timeout in milliseconds for all resource I/O operations.

This value is used when accessing the device associated with the given session.

Special values:

  • immediate (VI_TMO_IMMEDIATE): 0
    (for convenience, any value smaller than 1 is considered as 0)
  • infinite (VI_TMO_INFINITE): float('+inf')
    (for convenience, None is considered as float('+inf'))

To set an infinite timeout, you can also use:

>>> del instrument.timeout

A timeout value of VI_TMO_IMMEDIATE means that operations should never wait for the device to respond. A timeout value of VI_TMO_INFINITE disables the timeout mechanism.

VISA Attribute:VI_ATTR_TMO_VALUE (1073676314)
Type:int
Range:0 <= value <= 4294967295
uninstall_handler(event_type: pyvisa.constants.EventType, handler: Callable[[NewType.<locals>.new_type, pyvisa.constants.EventType, NewType.<locals>.new_type, Any], None], user_handle=None) → None

Uninstalls handlers for events in this resource.

Parameters:
  • event_type (constants.EventType) – Logical event identifier.
  • handler (VISAHandler) – Handler function to be uninstalled by a client application.
  • user_handle (Any) – The user handle returned by install_handler.
unlock() → None

Relinquishes a lock for the specified resource.

visa_attributes_classes = {<class 'pyvisa.attributes.AttrVI_ATTR_RSRC_LOCK_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_SPEC_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_TMO_VALUE'>, <class 'pyvisa.attributes.AttrVI_ATTR_MAX_QUEUE_LENGTH'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_TYPE'>, <class 'pyvisa.attributes.AttrVI_ATTR_USER_DATA'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_CLASS'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_IMPL_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_INST_NAME'>}
wait_on_event(in_event_type: pyvisa.constants.EventType, timeout: int, capture_timeout: bool = False) → pyvisa.resources.resource.WaitResponse

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

in_event_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. None means waiting forever if necessary.
capture_timeout : bool, optional
When True will not produce a VisaIOError(VI_ERROR_TMO) but instead return a WaitResponse with timed_out=True.
Returns:Object that contains event_type, context and ret value.
Return type:WaitResponse
wrap_handler(callable: Callable[[Resource, pyvisa.events.Event, Any], None]) → Callable[[NewType.<locals>.new_type, pyvisa.constants.EventType, NewType.<locals>.new_type, Any], None]

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

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

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

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

Write a string message to the device.

The write_termination is always appended to it.

Parameters:
  • message (str) – The message to be sent.
  • termination (Optional[str], optional) – Alternative character termination to use. If None, the value of write_termination is used. Defaults to None.
  • encoding (Optional[str], optional) – Alternative encoding to use to turn str into bytes. If None, the value of encoding is used. Defaults to None.
Returns:

Number of bytes written.

Return type:

int

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

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

The write_termination is always appended to it.

Parameters:
  • message (str) – Header of the message to be sent.
  • values (Sequence[Any]) – Data to be writen to the device.
  • converter (Union[str, Callable[[Any], str]], optional) – Str formatting codes or function used to convert each value. Defaults to “f”.
  • separator (Union[str, Callable[[Iterable[str]], str]], optional) – Str or callable that join the values in a single str. If a str is given, separator.join(values) is used. Defaults to ‘,’
  • termination (Optional[str], optional) – Alternative character termination to use. If None, the value of write_termination is used. Defaults to None.
  • encoding (Optional[str], optional) – Alternative encoding to use to turn str into bytes. If None, the value of encoding is used. Defaults to None.
Returns:

Number of bytes written.

Return type:

int

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

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

The write_termination is always appended to it.

Parameters:
  • message (str) – The header of the message to be sent.
  • values (Sequence[Any]) – Data to be written to the device.
  • datatype (util.BINARY_DATATYPES, optional) – The format string for a single element. See struct module.
  • is_big_endian (bool, optional) – Are the data in big or little endian order.
  • termination (Optional[str], optional) – Alternative character termination to use. If None, the value of write_termination is used. Defaults to None.
  • encoding (Optional[str], optional) – Alternative encoding to use to turn str into bytes. If None, the value of encoding is used. Defaults to None.
  • header_fmt (util.BINARY_HEADERS) – Format of the header prefixing the data.
Returns:

Number of bytes written.

Return type:

int

write_raw(message: bytes) → int[source]

Write a byte message to the device.

Parameters:message (bytes) – The message to be sent.
Returns:Number of bytes written
Return type:int
write_termination

Write termination character.

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

Base class for resources that use register based communication.

before_close() → None

Called just before closing an instrument.

clear() → None

Clear this resource.

close() → None

Closes the VISA session and marks the handle as invalid.

disable_event(event_type: pyvisa.constants.EventType, mechanism: pyvisa.constants.EventMechanism) → None

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

Parameters:
  • event_type (constants.EventType) – Logical event identifier.
  • mechanism (constants.EventMechanism) – Specifies event handling mechanisms to be disabled.
discard_events(event_type: pyvisa.constants.EventType, mechanism: pyvisa.constants.EventMechanism) → None

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

Parameters:
  • event_type (constants.EventType) – Logical event identifier.
  • mechanism (constants.EventMechanism) – Specifies event handling mechanisms to be disabled.
enable_event(event_type: pyvisa.constants.EventType, mechanism: pyvisa.constants.EventMechanism, context: None = None) → None

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

Parameters:
  • event_type (constants.EventType) – Logical event identifier.
  • mechanism (constants.EventMechanism) – Specifies event handling mechanisms to be enabled
  • context (None) – Not currently used, leave as None.
get_visa_attribute(name: pyvisa.constants.ResourceAttribute) → Any

Retrieves the state of an attribute in this resource.

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

Parameters:name (constants.ResourceAttribute) – Resource attribute for which the state query is made.
Returns:The state of the queried attribute for a specified resource.
Return type:Any
ignore_warning(*warnings_constants) → AbstractContextManager[T_co]

Ignoring warnings context manager for the current resource.

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

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

This attribute value is defined by the individual manufacturer and increments with each new revision. The format of the value has the upper 12 bits as the major number of the version, the next lower 12 bits as the minor number of the version, and the lowest 8 bits as the sub-minor number of the version.
VISA Attribute:VI_ATTR_RSRC_IMPL_VERSION (1073676291)
Type:int
Range:0 <= value <= 4294967295
install_handler(event_type: pyvisa.constants.EventType, handler: Callable[[NewType.<locals>.new_type, pyvisa.constants.EventType, NewType.<locals>.new_type, Any], None], user_handle=None) → Any

Install handlers for event callbacks in this resource.

Parameters:
  • event_type (constants.EventType) – Logical event identifier.
  • handler (VISAHandler) – Handler function to be installed by a client application.
  • user_handle – A value specified by an application that can be used for identifying handlers uniquely for an event type. Depending on the backend they may be restriction on the possible values. Look at the backend install_visa_handler for more details.
Returns:

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

Return type:

Any

interface_number

Board number for the given interface. :VISA Attribute: VI_ATTR_INTF_NUM (1073676662) :type: int :range: 0 <= value <= 65535

interface_type

Interface type of the given session. :VISA Attribute: VI_ATTR_INTF_TYPE (1073676657) :type: :class:pyvisa.constants.InterfaceType

last_status

Last status code for this session.

lock(timeout: Union[float, typing_extensions.Literal['default'][default]] = 'default', requested_key: Optional[str] = None) → str

Establish a shared lock to the resource.

Parameters:
  • timeout (Union[float, Literal["default"]], optional) – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. Defaults to “default” which means use self.timeout.
  • requested_key (Optional[str], optional) – Access key used by another session with which you want your session to share a lock or None to generate a new shared access key.
Returns:

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

Return type:

str

lock_context(timeout: Union[float, typing_extensions.Literal['default'][default]] = 'default', requested_key: Optional[str] = 'exclusive') → Iterator[Optional[str]]

A context that locks

Parameters:
  • timeout (Union[float, Literal["default"]], optional) – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. Defaults to “default” which means use self.timeout.
  • requested_key (Optional[str], optional) – When using default of ‘exclusive’ the lock is an exclusive lock. Otherwise it is the access key for the shared lock or None to generate a new shared access key.
Yields:

Optional[str] – The access_key if applicable.

lock_excl(timeout: Union[float, typing_extensions.Literal['default'][default]] = 'default') → None

Establish an exclusive lock to the resource.

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

Current locking state of the resource.

The resource can be unlocked, locked with an exclusive lock, or locked with a shared lock.
VISA Attribute:VI_ATTR_RSRC_LOCK_STATE (1073676292)
Type::class:pyvisa.constants.AccessModes
move_in(space: pyvisa.constants.AddressSpace, offset: int, length: int, width: pyvisa.constants.DataWidth, extended: bool = False) → List[int][source]

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

Corresponds to viMoveIn* functions of the VISA library.

Parameters:
  • space (constants.AddressSpace) – Address space from which to move the data.
  • offset (int) – Offset (in bytes) of the address or register from which to read.
  • length (int) – Number of elements to transfer, where the data width of the elements to transfer is identical to the source data width.
  • width (Union[Literal[8, 16, 32, 64], constants.DataWidth]) – Number of bits to read per element.
  • extended (bool, optional) – Use 64 bits offset independent of the platform, by default False.
Returns:

  • data (List[int]) – Data read from the bus
  • status_code (constants.StatusCode) – Return value of the library call.

Raises:

ValueError – Raised if an invalid width is specified.

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

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

Corresponds to viMoveOut* functions of the VISA library.

Parameters:
  • space (constants.AddressSpace) – Address space into which move the data.
  • offset (int) – Offset (in bytes) of the address or register from which to read.
  • length (int) – Number of elements to transfer, where the data width of the elements to transfer is identical to the source data width.
  • data (Iterable[int]) – Data to write to bus.
  • width (Union[Literal[8, 16, 32, 64], constants.DataWidth]) – Number of bits to per element.
  • extended (bool, optional) – Use 64 bits offset independent of the platform, by default False.
Returns:

Return value of the library call.

Return type:

constants.StatusCode

Raises:

ValueError – Raised if an invalid width is specified.

open(access_mode: pyvisa.constants.AccessModes = <AccessModes.no_lock: 0>, open_timeout: int = 5000) → None

Opens a session to the specified resource.

Parameters:
  • access_mode (constants.AccessModes, optional) – Specifies the mode by which the resource is to be accessed. Defaults to constants.AccessModes.no_lock.
  • open_timeout (int, optional) – If the access_mode parameter requests a lock, then this parameter specifies the absolute time period (in milliseconds) that the resource waits to get unlocked before this operation returns an error. Defaults to 5000.
read_memory(space: pyvisa.constants.AddressSpace, offset: int, width: pyvisa.constants.DataWidth, extended: bool = False) → int[source]

Read a value from the specified memory space and offset.

Parameters:
  • space (constants.AddressSpace) – Specifies the address space from which to read.
  • offset (int) – Offset (in bytes) of the address or register from which to read.
  • width (Union[Literal[8, 16, 32, 64], constants.DataWidth]) – Number of bits to read (8, 16, 32 or 64).
  • extended (bool, optional) – Use 64 bits offset independent of the platform.
Returns:

data – Data read from memory

Return type:

int

Raises:

ValueError – Raised if an invalid width is specified.

classmethod register(interface_type: pyvisa.constants.InterfaceType, resource_class: str) → Callable[[Type[T]], Type[T]]

Create a decorator to register a class.

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

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

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

Return type:

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

resource_class

Resource class as defined by the canonical resource name.

Possible values are: INSTR, INTFC, SOCKET, RAW…
VISA Attribute:VI_ATTR_RSRC_CLASS (3221159937)
resource_info

Get the extended information of this resource.

resource_manufacturer_name

Manufacturer name of the vendor that implemented the VISA library.

This attribute is not related to the device manufacturer attributes.

Note The value of this attribute is for display purposes only and not for programmatic decisions, as the value can differ between VISA implementations and/or revisions.

VISA Attribute:VI_ATTR_RSRC_MANF_NAME (3221160308)
resource_name

Unique identifier for a resource compliant with the address structure. :VISA Attribute: VI_ATTR_RSRC_NAME (3221159938)

session

Resource session handle.

Raises:errors.InvalidSession – Raised if session is closed.
set_visa_attribute(name: pyvisa.constants.ResourceAttribute, state: Any) → pyvisa.constants.StatusCode

Set the state of an attribute.

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

Parameters:
  • name (constants.ResourceAttribute) – Attribute for which the state is to be modified.
  • state (Any) – The state of the attribute to be set for the specified object.
Returns:

Return value of the library call.

Return type:

constants.StatusCode

spec_version

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

The format of the value has the upper 12 bits as the major number of the version, the next lower 12 bits as the minor number of the version, and the lowest 8 bits as the sub-minor number of the version. The current VISA specification defines the value to be 00300000h.
VISA Attribute:VI_ATTR_RSRC_SPEC_VERSION (1073676656)
Type:int
Range:0 <= value <= 4294967295
timeout

Timeout in milliseconds for all resource I/O operations.

This value is used when accessing the device associated with the given session.

Special values:

  • immediate (VI_TMO_IMMEDIATE): 0
    (for convenience, any value smaller than 1 is considered as 0)
  • infinite (VI_TMO_INFINITE): float('+inf')
    (for convenience, None is considered as float('+inf'))

To set an infinite timeout, you can also use:

>>> del instrument.timeout

A timeout value of VI_TMO_IMMEDIATE means that operations should never wait for the device to respond. A timeout value of VI_TMO_INFINITE disables the timeout mechanism.

VISA Attribute:VI_ATTR_TMO_VALUE (1073676314)
Type:int
Range:0 <= value <= 4294967295
uninstall_handler(event_type: pyvisa.constants.EventType, handler: Callable[[NewType.<locals>.new_type, pyvisa.constants.EventType, NewType.<locals>.new_type, Any], None], user_handle=None) → None

Uninstalls handlers for events in this resource.

Parameters:
  • event_type (constants.EventType) – Logical event identifier.
  • handler (VISAHandler) – Handler function to be uninstalled by a client application.
  • user_handle (Any) – The user handle returned by install_handler.
unlock() → None

Relinquishes a lock for the specified resource.

visa_attributes_classes = {<class 'pyvisa.attributes.AttrVI_ATTR_RSRC_LOCK_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_SPEC_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_TMO_VALUE'>, <class 'pyvisa.attributes.AttrVI_ATTR_MAX_QUEUE_LENGTH'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_TYPE'>, <class 'pyvisa.attributes.AttrVI_ATTR_USER_DATA'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_CLASS'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_IMPL_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_INST_NAME'>}
wait_on_event(in_event_type: pyvisa.constants.EventType, timeout: int, capture_timeout: bool = False) → pyvisa.resources.resource.WaitResponse

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

in_event_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. None means waiting forever if necessary.
capture_timeout : bool, optional
When True will not produce a VisaIOError(VI_ERROR_TMO) but instead return a WaitResponse with timed_out=True.
Returns:Object that contains event_type, context and ret value.
Return type:WaitResponse
wrap_handler(callable: Callable[[Resource, pyvisa.events.Event, Any], None]) → Callable[[NewType.<locals>.new_type, pyvisa.constants.EventType, NewType.<locals>.new_type, Any], None]

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

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

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

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

Write a value to the specified memory space and offset.

Parameters:
  • space (constants.AddressSpace) – Specifies the address space.
  • offset (int) – Offset (in bytes) of the address or register from which to read.
  • data (int) – Data to write to bus.
  • width (Union[Literal[8, 16, 32, 64], constants.DataWidth]) – Number of bits to read.
  • extended (bool, optional) – Use 64 bits offset independent of the platform, by default False.
Returns:

Return value of the library call.

Return type:

constants.StatusCode

Raises:

ValueError – Raised if an invalid width is specified.

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

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

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

CR = '\r'
LF = '\n'
allow_dma

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

In some implementations, this attribute may have global effects even though it is documented to be a local attribute. Since this affects performance and not functionality, that behavior is acceptable.
VISA Attribute:VI_ATTR_DMA_ALLOW_EN (1073676318)
Type:bool
allow_transmit

Manually control transmission.

assert_trigger() → None

Sends a software trigger to the device.

baud_rate

Baud rate of the interface.

before_close() → None

Called just before closing an instrument.

break_length

Duration (in milliseconds) of the break signal.

break_state

Manually control the assertion state of the break signal.

bytes_in_buffer

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

chunk_size = 20480
clear() → None

Clear this resource.

close() → None

Closes the VISA session and marks the handle as invalid.

data_bits

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

disable_event(event_type: pyvisa.constants.EventType, mechanism: pyvisa.constants.EventMechanism) → None

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

Parameters:
  • event_type (constants.EventType) – Logical event identifier.
  • mechanism (constants.EventMechanism) – Specifies event handling mechanisms to be disabled.
discard_events(event_type: pyvisa.constants.EventType, mechanism: pyvisa.constants.EventMechanism) → None

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

Parameters:
  • event_type (constants.EventType) – Logical event identifier.
  • mechanism (constants.EventMechanism) – Specifies event handling mechanisms to be disabled.
discard_null

If set to True, NUL characters are discarded.

enable_event(event_type: pyvisa.constants.EventType, mechanism: pyvisa.constants.EventMechanism, context: None = None) → None

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

Parameters:
  • event_type (constants.EventType) – Logical event identifier.
  • mechanism (constants.EventMechanism) – Specifies event handling mechanisms to be enabled
  • context (None) – Not currently used, leave as None.
encoding

Encoding used for read and write operations.

end_input

Method used to terminate read operations.

end_output

Method used to terminate write operations.

flow_control

Indicates the type of flow control used by the transfer mechanism.

flush(mask: pyvisa.constants.BufferOperation) → None

Manually clears the specified buffers.

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

Parameters:mask (constants.BufferOperation) – Specifies the action to be taken with flushing the buffer. See highlevel.VisaLibraryBase.flush for a detailed description.
get_visa_attribute(name: pyvisa.constants.ResourceAttribute) → Any

Retrieves the state of an attribute in this resource.

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

Parameters:name (constants.ResourceAttribute) – Resource attribute for which the state query is made.
Returns:The state of the queried attribute for a specified resource.
Return type:Any
ignore_warning(*warnings_constants) → AbstractContextManager[T_co]

Ignoring warnings context manager for the current resource.

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

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

This attribute value is defined by the individual manufacturer and increments with each new revision. The format of the value has the upper 12 bits as the major number of the version, the next lower 12 bits as the minor number of the version, and the lowest 8 bits as the sub-minor number of the version.
VISA Attribute:VI_ATTR_RSRC_IMPL_VERSION (1073676291)
Type:int
Range:0 <= value <= 4294967295
install_handler(event_type: pyvisa.constants.EventType, handler: Callable[[NewType.<locals>.new_type, pyvisa.constants.EventType, NewType.<locals>.new_type, Any], None], user_handle=None) → Any

Install handlers for event callbacks in this resource.

Parameters:
  • event_type (constants.EventType) – Logical event identifier.
  • handler (VISAHandler) – Handler function to be installed by a client application.
  • user_handle – A value specified by an application that can be used for identifying handlers uniquely for an event type. Depending on the backend they may be restriction on the possible values. Look at the backend install_visa_handler for more details.
Returns:

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

Return type:

Any

interface_number

Board number for the given interface. :VISA Attribute: VI_ATTR_INTF_NUM (1073676662) :type: int :range: 0 <= value <= 65535

interface_type

Interface type of the given session. :VISA Attribute: VI_ATTR_INTF_TYPE (1073676657) :type: :class:pyvisa.constants.InterfaceType

io_protocol

IO protocol to use.

In VXI, you can choose normal word serial or fast data channel (FDC). In GPIB, you can choose normal or high-speed (HS-488) transfers. In serial, TCPIP, or USB RAW, you can choose normal transfers or 488.2-defined strings. In USB INSTR, you can choose normal or vendor-specific transfers.
VISA Attribute:VI_ATTR_IO_PROT (1073676316)
Type::class:pyvisa.constants.IOProtocol
last_status

Last status code for this session.

lock(timeout: Union[float, typing_extensions.Literal['default'][default]] = 'default', requested_key: Optional[str] = None) → str

Establish a shared lock to the resource.

Parameters:
  • timeout (Union[float, Literal["default"]], optional) – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. Defaults to “default” which means use self.timeout.
  • requested_key (Optional[str], optional) – Access key used by another session with which you want your session to share a lock or None to generate a new shared access key.
Returns:

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

Return type:

str

lock_context(timeout: Union[float, typing_extensions.Literal['default'][default]] = 'default', requested_key: Optional[str] = 'exclusive') → Iterator[Optional[str]]

A context that locks

Parameters:
  • timeout (Union[float, Literal["default"]], optional) – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. Defaults to “default” which means use self.timeout.
  • requested_key (Optional[str], optional) – When using default of ‘exclusive’ the lock is an exclusive lock. Otherwise it is the access key for the shared lock or None to generate a new shared access key.
Yields:

Optional[str] – The access_key if applicable.

lock_excl(timeout: Union[float, typing_extensions.Literal['default'][default]] = 'default') → None

Establish an exclusive lock to the resource.

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

Current locking state of the resource.

The resource can be unlocked, locked with an exclusive lock, or locked with a shared lock.
VISA Attribute:VI_ATTR_RSRC_LOCK_STATE (1073676292)
Type::class:pyvisa.constants.AccessModes
open(access_mode: pyvisa.constants.AccessModes = <AccessModes.no_lock: 0>, open_timeout: int = 5000) → None

Opens a session to the specified resource.

Parameters:
  • access_mode (constants.AccessModes, optional) – Specifies the mode by which the resource is to be accessed. Defaults to constants.AccessModes.no_lock.
  • open_timeout (int, optional) – If the access_mode parameter requests a lock, then this parameter specifies the absolute time period (in milliseconds) that the resource waits to get unlocked before this operation returns an error. Defaults to 5000.
parity

Parity used with every frame transmitted and received.

query(message: str, delay: Optional[float] = None) → str

A combination of write(message) and read()

Parameters:
  • message (str) – The message to send.
  • delay (Optional[float], optional) – Delay in seconds between write and read operations. If None, defaults to self.query_delay.
Returns:

Answer from the device.

Return type:

str

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

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

Parameters:
  • message (str) – The message to send.
  • converter (ASCII_CONVERTER, optional) – Str format of function to convert each value. Default to “f”.
  • separator (Union[str, Callable[[str], Iterable[str]]]) – str or callable used to split the data into individual elements. If a str is given, data.split(separator) is used. Default to “,”.
  • container (Union[Type, Callable[[Iterable], Sequence]], optional) – Container type to use for the output data. Possible values are: list, tuple, np.ndarray, etc, Default to list.
  • delay (Optional[float], optional) – Delay in seconds between write and read operations. If None, defaults to self.query_delay.
Returns:

Parsed data.

Return type:

Sequence

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

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

Parameters:
  • message (str) – The message to send.
  • datatype (BINARY_DATATYPES, optional) – Format string for a single element. See struct module. ‘f’ by default.
  • is_big_endian (bool, optional) – Are the data in big or little endian order. Defaults to False.
  • container (Union[Type, Callable[[Iterable], Sequence]], optional) – Container type to use for the output data. Possible values are: list, tuple, np.ndarray, etc, Default to list.
  • delay (Optional[float], optional) – Delay in seconds between write and read operations. If None, defaults to self.query_delay.
  • header_fmt (util.BINARY_HEADERS, optional) – Format of the header prefixing the data. Defaults to ‘ieee’.
  • expect_termination (bool, optional) – When set to False, the expected length of the binary values block does not account for the final termination character (the read termination). Defaults to True.
  • data_points (int, optional) – Number of points expected in the block. This is used only if the instrument does not report it itself. This will be converted in a number of bytes based on the datatype. Defaults to 0.
  • chunk_size (int, optional) – Size of the chunks to read from the device. Using larger chunks may be faster for large amount of data.
Returns:

Data read from the device.

Return type:

Sequence[Union[int, float]]

query_delay = 0.0
read(termination: Optional[str] = None, encoding: Optional[str] = None) → str

Read a string from the device.

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

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

Message read from the instrument and decoded.

Return type:

str

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

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

Parameters:converter (ASCII_CONVERTER, optional) – Str format of function to convert each value. Default to “f”.
separator : Union[str, Callable[[str], Iterable[str]]]
str or callable used to split the data into individual elements. If a str is given, data.split(separator) is used. Default to “,”.
container : Union[Type, Callable[[Iterable], Sequence]], optional
Container type to use for the output data. Possible values are: list, tuple, np.ndarray, etc, Default to list.
Returns:Parsed data.
Return type:Sequence
read_binary_values(datatype: typing_extensions.Literal['s', 'b', 'B', 'h', 'H', 'i', 'I', 'l', 'L', 'q', 'Q', 'f', 'd'][s, b, B, h, H, i, I, l, L, q, Q, f, d] = 'f', is_big_endian: bool = False, container: Union[Type[CT_co], Callable[[Iterable[T_co]], Sequence[T_co]]] = <class 'list'>, header_fmt: typing_extensions.Literal['ieee', 'hp', 'empty'][ieee, hp, empty] = 'ieee', expect_termination: bool = True, data_points: int = 0, chunk_size: Optional[int] = None) → Sequence[Union[int, float]]

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

Parameters:
  • datatype (BINARY_DATATYPES, optional) – Format string for a single element. See struct module. ‘f’ by default.
  • is_big_endian (bool, optional) – Are the data in big or little endian order. Defaults to False.
  • container (Union[Type, Callable[[Iterable], Sequence]], optional) – Container type to use for the output data. Possible values are: list, tuple, np.ndarray, etc, Default to list.
  • header_fmt (util.BINARY_HEADERS, optional) – Format of the header prefixing the data. Defaults to ‘ieee’.
  • expect_termination (bool, optional) – When set to False, the expected length of the binary values block does not account for the final termination character (the read termination). Defaults to True.
  • data_points (int, optional) – Number of points expected in the block. This is used only if the instrument does not report it itself. This will be converted in a number of bytes based on the datatype. Defaults to 0.
  • chunk_size (int, optional) – Size of the chunks to read from the device. Using larger chunks may be faster for large amount of data.
Returns:

Data read from the device.

Return type:

Sequence[Union[int, float]]

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

Read a certain number of bytes from the instrument.

Parameters:
  • count (int) – The number of bytes to read from the instrument.
  • chunk_size (Optional[int], optional) – The chunk size to use to perform the reading. If count > chunk_size multiple low level operations will be performed. Defaults to None, meaning the resource wide set value is set.
  • break_on_termchar (bool, optional) – Should the reading stop when a termination character is encountered or when the message ends. Defaults to False.
Returns:

Bytes read from the instrument.

Return type:

bytes

read_raw(size: Optional[int] = None) → bytes

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

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

Parameters:size (Optional[int], optional) – The chunk size to use to perform the reading. Defaults to None, meaning the resource wide set value is set.
Returns:Bytes read from the instrument.
Return type:bytes
read_stb() → int

Service request status register.

read_termination

Read termination character.

read_termination_context(new_termination: str) → Iterator[T_co]
classmethod register(interface_type: pyvisa.constants.InterfaceType, resource_class: str) → Callable[[Type[T]], Type[T]]

Create a decorator to register a class.

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

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

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

Return type:

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

replace_char

Character to be used to replace incoming characters that arrive with errors.

resource_class

Resource class as defined by the canonical resource name.

Possible values are: INSTR, INTFC, SOCKET, RAW…
VISA Attribute:VI_ATTR_RSRC_CLASS (3221159937)
resource_info

Get the extended information of this resource.

resource_manufacturer_name

Manufacturer name of the vendor that implemented the VISA library.

This attribute is not related to the device manufacturer attributes.

Note The value of this attribute is for display purposes only and not for programmatic decisions, as the value can differ between VISA implementations and/or revisions.

VISA Attribute:VI_ATTR_RSRC_MANF_NAME (3221160308)
resource_name

Unique identifier for a resource compliant with the address structure. :VISA Attribute: VI_ATTR_RSRC_NAME (3221159938)

send_end

Should END be asserted during the transfer of the last byte of the buffer. :VISA Attribute: VI_ATTR_SEND_END_EN (1073676310) :type: bool

session

Resource session handle.

Raises:errors.InvalidSession – Raised if session is closed.
set_visa_attribute(name: pyvisa.constants.ResourceAttribute, state: Any) → pyvisa.constants.StatusCode

Set the state of an attribute.

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

Parameters:
  • name (constants.ResourceAttribute) – Attribute for which the state is to be modified.
  • state (Any) – The state of the attribute to be set for the specified object.
Returns:

Return value of the library call.

Return type:

constants.StatusCode

spec_version

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

The format of the value has the upper 12 bits as the major number of the version, the next lower 12 bits as the minor number of the version, and the lowest 8 bits as the sub-minor number of the version. The current VISA specification defines the value to be 00300000h.
VISA Attribute:VI_ATTR_RSRC_SPEC_VERSION (1073676656)
Type:int
Range:0 <= value <= 4294967295
stb

Service request status register.

stop_bits

Number of stop bits used to indicate the end of a frame.

timeout

Timeout in milliseconds for all resource I/O operations.

This value is used when accessing the device associated with the given session.

Special values:

  • immediate (VI_TMO_IMMEDIATE): 0
    (for convenience, any value smaller than 1 is considered as 0)
  • infinite (VI_TMO_INFINITE): float('+inf')
    (for convenience, None is considered as float('+inf'))

To set an infinite timeout, you can also use:

>>> del instrument.timeout

A timeout value of VI_TMO_IMMEDIATE means that operations should never wait for the device to respond. A timeout value of VI_TMO_INFINITE disables the timeout mechanism.

VISA Attribute:VI_ATTR_TMO_VALUE (1073676314)
Type:int
Range:0 <= value <= 4294967295
uninstall_handler(event_type: pyvisa.constants.EventType, handler: Callable[[NewType.<locals>.new_type, pyvisa.constants.EventType, NewType.<locals>.new_type, Any], None], user_handle=None) → None

Uninstalls handlers for events in this resource.

Parameters:
  • event_type (constants.EventType) – Logical event identifier.
  • handler (VISAHandler) – Handler function to be uninstalled by a client application.
  • user_handle (Any) – The user handle returned by install_handler.
unlock() → None

Relinquishes a lock for the specified resource.

visa_attributes_classes = {<class 'pyvisa.attributes.AttrVI_ATTR_RSRC_LOCK_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_BAUD'>, <class 'pyvisa.attributes.AttrVI_ATTR_TRIG_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_TYPE'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_DISCARD_NULL'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_END_OUT'>, <class 'pyvisa.attributes.AttrVI_ATTR_IO_PROT'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_XON_CHAR'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_RTS_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_INST_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_SPEC_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_AVAIL_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_STOP_BITS'>, <class 'pyvisa.attributes.AttrVI_ATTR_USER_DATA'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_FLOW_CNTRL'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_END_IN'>, <class 'pyvisa.attributes.AttrVI_ATTR_TERMCHAR'>, <class 'pyvisa.attributes.AttrVI_ATTR_RD_BUF_SIZE'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_XOFF_CHAR'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_DTR_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_IMPL_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_TMO_VALUE'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_PARITY'>, <class 'pyvisa.attributes.AttrVI_ATTR_MAX_QUEUE_LENGTH'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_ALLOW_TRANSMIT'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_BREAK_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_TERMCHAR_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_RD_BUF_OPER_MODE'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_REPLACE_CHAR'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_DSR_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_WR_BUF_OPER_MODE'>, <class 'pyvisa.attributes.AttrVI_ATTR_WR_BUF_SIZE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_DMA_ALLOW_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_DATA_BITS'>, <class 'pyvisa.attributes.AttrVI_ATTR_SEND_END_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_CONNECTED'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_BREAK_LEN'>, <class 'pyvisa.attributes.AttrVI_ATTR_SUPPRESS_END_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_FILE_APPEND_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_CTS_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_WIRE_MODE'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_DCD_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_CLASS'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_RI_STATE'>}
wait_on_event(in_event_type: pyvisa.constants.EventType, timeout: int, capture_timeout: bool = False) → pyvisa.resources.resource.WaitResponse

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

in_event_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. None means waiting forever if necessary.
capture_timeout : bool, optional
When True will not produce a VisaIOError(VI_ERROR_TMO) but instead return a WaitResponse with timed_out=True.
Returns:Object that contains event_type, context and ret value.
Return type:WaitResponse
wrap_handler(callable: Callable[[Resource, pyvisa.events.Event, Any], None]) → Callable[[NewType.<locals>.new_type, pyvisa.constants.EventType, NewType.<locals>.new_type, Any], None]

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

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

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

write(message: str, termination: Optional[str] = None, encoding: Optional[str] = None) → int

Write a string message to the device.

The write_termination is always appended to it.

Parameters:
  • message (str) – The message to be sent.
  • termination (Optional[str], optional) – Alternative character termination to use. If None, the value of write_termination is used. Defaults to None.
  • encoding (Optional[str], optional) – Alternative encoding to use to turn str into bytes. If None, the value of encoding is used. Defaults to None.
Returns:

Number of bytes written.

Return type:

int

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

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

The write_termination is always appended to it.

Parameters:
  • message (str) – Header of the message to be sent.
  • values (Sequence[Any]) – Data to be writen to the device.
  • converter (Union[str, Callable[[Any], str]], optional) – Str formatting codes or function used to convert each value. Defaults to “f”.
  • separator (Union[str, Callable[[Iterable[str]], str]], optional) – Str or callable that join the values in a single str. If a str is given, separator.join(values) is used. Defaults to ‘,’
  • termination (Optional[str], optional) – Alternative character termination to use. If None, the value of write_termination is used. Defaults to None.
  • encoding (Optional[str], optional) – Alternative encoding to use to turn str into bytes. If None, the value of encoding is used. Defaults to None.
Returns:

Number of bytes written.

Return type:

int

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

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

The write_termination is always appended to it.

Parameters:
  • message (str) – The header of the message to be sent.
  • values (Sequence[Any]) – Data to be written to the device.
  • datatype (util.BINARY_DATATYPES, optional) – The format string for a single element. See struct module.
  • is_big_endian (bool, optional) – Are the data in big or little endian order.
  • termination (Optional[str], optional) – Alternative character termination to use. If None, the value of write_termination is used. Defaults to None.
  • encoding (Optional[str], optional) – Alternative encoding to use to turn str into bytes. If None, the value of encoding is used. Defaults to None.
  • header_fmt (util.BINARY_HEADERS) – Format of the header prefixing the data.
Returns:

Number of bytes written.

Return type:

int

write_raw(message: bytes) → int

Write a byte message to the device.

Parameters:message (bytes) – The message to be sent.
Returns:Number of bytes written
Return type:int
write_termination

Write termination character.

xoff_char

XOFF character used for XON/XOFF flow control (both directions).

xon_char

XON character used for XON/XOFF flow control (both directions).

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

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

More complex resource names can be specified with the following grammar:
TCPIP[board]::host address[::LAN device name][::INSTR]

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

CR = '\r'
LF = '\n'
allow_dma

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

In some implementations, this attribute may have global effects even though it is documented to be a local attribute. Since this affects performance and not functionality, that behavior is acceptable.
VISA Attribute:VI_ATTR_DMA_ALLOW_EN (1073676318)
Type:bool
assert_trigger() → None

Sends a software trigger to the device.

before_close() → None

Called just before closing an instrument.

chunk_size = 20480
clear() → None

Clear this resource.

close() → None

Closes the VISA session and marks the handle as invalid.

control_ren(mode: pyvisa.constants.RENLineOperation) → pyvisa.constants.StatusCode

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

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

Corresponds to viGpibControlREN function of the VISA library.

Parameters:mode (constants.RENLineOperation) – Specifies the state of the REN line and optionally the device remote/local state.
Returns:Return value of the library call.
Return type:constants.StatusCode
disable_event(event_type: pyvisa.constants.EventType, mechanism: pyvisa.constants.EventMechanism) → None

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

Parameters:
  • event_type (constants.EventType) – Logical event identifier.
  • mechanism (constants.EventMechanism) – Specifies event handling mechanisms to be disabled.
discard_events(event_type: pyvisa.constants.EventType, mechanism: pyvisa.constants.EventMechanism) → None

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

Parameters:
  • event_type (constants.EventType) – Logical event identifier.
  • mechanism (constants.EventMechanism) – Specifies event handling mechanisms to be disabled.
enable_event(event_type: pyvisa.constants.EventType, mechanism: pyvisa.constants.EventMechanism, context: None = None) → None

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

Parameters:
  • event_type (constants.EventType) – Logical event identifier.
  • mechanism (constants.EventMechanism) – Specifies event handling mechanisms to be enabled
  • context (None) – Not currently used, leave as None.
encoding

Encoding used for read and write operations.

flush(mask: pyvisa.constants.BufferOperation) → None

Manually clears the specified buffers.

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

Parameters:mask (constants.BufferOperation) – Specifies the action to be taken with flushing the buffer. See highlevel.VisaLibraryBase.flush for a detailed description.
get_visa_attribute(name: pyvisa.constants.ResourceAttribute) → Any

Retrieves the state of an attribute in this resource.

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

Parameters:name (constants.ResourceAttribute) – Resource attribute for which the state query is made.
Returns:The state of the queried attribute for a specified resource.
Return type:Any
ignore_warning(*warnings_constants) → AbstractContextManager[T_co]

Ignoring warnings context manager for the current resource.

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

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

This attribute value is defined by the individual manufacturer and increments with each new revision. The format of the value has the upper 12 bits as the major number of the version, the next lower 12 bits as the minor number of the version, and the lowest 8 bits as the sub-minor number of the version.
VISA Attribute:VI_ATTR_RSRC_IMPL_VERSION (1073676291)
Type:int
Range:0 <= value <= 4294967295
install_handler(event_type: pyvisa.constants.EventType, handler: Callable[[NewType.<locals>.new_type, pyvisa.constants.EventType, NewType.<locals>.new_type, Any], None], user_handle=None) → Any

Install handlers for event callbacks in this resource.

Parameters:
  • event_type (constants.EventType) – Logical event identifier.
  • handler (VISAHandler) – Handler function to be installed by a client application.
  • user_handle – A value specified by an application that can be used for identifying handlers uniquely for an event type. Depending on the backend they may be restriction on the possible values. Look at the backend install_visa_handler for more details.
Returns:

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

Return type:

Any

interface_number

Board number for the given interface. :VISA Attribute: VI_ATTR_INTF_NUM (1073676662) :type: int :range: 0 <= value <= 65535

interface_type

Interface type of the given session. :VISA Attribute: VI_ATTR_INTF_TYPE (1073676657) :type: :class:pyvisa.constants.InterfaceType

io_protocol

IO protocol to use.

In VXI, you can choose normal word serial or fast data channel (FDC). In GPIB, you can choose normal or high-speed (HS-488) transfers. In serial, TCPIP, or USB RAW, you can choose normal transfers or 488.2-defined strings. In USB INSTR, you can choose normal or vendor-specific transfers.
VISA Attribute:VI_ATTR_IO_PROT (1073676316)
Type::class:pyvisa.constants.IOProtocol
last_status

Last status code for this session.

lock(timeout: Union[float, typing_extensions.Literal['default'][default]] = 'default', requested_key: Optional[str] = None) → str

Establish a shared lock to the resource.

Parameters:
  • timeout (Union[float, Literal["default"]], optional) – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. Defaults to “default” which means use self.timeout.
  • requested_key (Optional[str], optional) – Access key used by another session with which you want your session to share a lock or None to generate a new shared access key.
Returns:

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

Return type:

str

lock_context(timeout: Union[float, typing_extensions.Literal['default'][default]] = 'default', requested_key: Optional[str] = 'exclusive') → Iterator[Optional[str]]

A context that locks

Parameters:
  • timeout (Union[float, Literal["default"]], optional) – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. Defaults to “default” which means use self.timeout.
  • requested_key (Optional[str], optional) – When using default of ‘exclusive’ the lock is an exclusive lock. Otherwise it is the access key for the shared lock or None to generate a new shared access key.
Yields:

Optional[str] – The access_key if applicable.

lock_excl(timeout: Union[float, typing_extensions.Literal['default'][default]] = 'default') → None

Establish an exclusive lock to the resource.

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

Current locking state of the resource.

The resource can be unlocked, locked with an exclusive lock, or locked with a shared lock.
VISA Attribute:VI_ATTR_RSRC_LOCK_STATE (1073676292)
Type::class:pyvisa.constants.AccessModes
open(access_mode: pyvisa.constants.AccessModes = <AccessModes.no_lock: 0>, open_timeout: int = 5000) → None

Opens a session to the specified resource.

Parameters:
  • access_mode (constants.AccessModes, optional) – Specifies the mode by which the resource is to be accessed. Defaults to constants.AccessModes.no_lock.
  • open_timeout (int, optional) – If the access_mode parameter requests a lock, then this parameter specifies the absolute time period (in milliseconds) that the resource waits to get unlocked before this operation returns an error. Defaults to 5000.
query(message: str, delay: Optional[float] = None) → str

A combination of write(message) and read()

Parameters:
  • message (str) – The message to send.
  • delay (Optional[float], optional) – Delay in seconds between write and read operations. If None, defaults to self.query_delay.
Returns:

Answer from the device.

Return type:

str

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

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

Parameters:
  • message (str) – The message to send.
  • converter (ASCII_CONVERTER, optional) – Str format of function to convert each value. Default to “f”.
  • separator (Union[str, Callable[[str], Iterable[str]]]) – str or callable used to split the data into individual elements. If a str is given, data.split(separator) is used. Default to “,”.
  • container (Union[Type, Callable[[Iterable], Sequence]], optional) – Container type to use for the output data. Possible values are: list, tuple, np.ndarray, etc, Default to list.
  • delay (Optional[float], optional) – Delay in seconds between write and read operations. If None, defaults to self.query_delay.
Returns:

Parsed data.

Return type:

Sequence

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

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

Parameters:
  • message (str) – The message to send.
  • datatype (BINARY_DATATYPES, optional) – Format string for a single element. See struct module. ‘f’ by default.
  • is_big_endian (bool, optional) – Are the data in big or little endian order. Defaults to False.
  • container (Union[Type, Callable[[Iterable], Sequence]], optional) – Container type to use for the output data. Possible values are: list, tuple, np.ndarray, etc, Default to list.
  • delay (Optional[float], optional) – Delay in seconds between write and read operations. If None, defaults to self.query_delay.
  • header_fmt (util.BINARY_HEADERS, optional) – Format of the header prefixing the data. Defaults to ‘ieee’.
  • expect_termination (bool, optional) – When set to False, the expected length of the binary values block does not account for the final termination character (the read termination). Defaults to True.
  • data_points (int, optional) – Number of points expected in the block. This is used only if the instrument does not report it itself. This will be converted in a number of bytes based on the datatype. Defaults to 0.
  • chunk_size (int, optional) – Size of the chunks to read from the device. Using larger chunks may be faster for large amount of data.
Returns:

Data read from the device.

Return type:

Sequence[Union[int, float]]

query_delay = 0.0
read(termination: Optional[str] = None, encoding: Optional[str] = None) → str

Read a string from the device.

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

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

Message read from the instrument and decoded.

Return type:

str

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

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

Parameters:converter (ASCII_CONVERTER, optional) – Str format of function to convert each value. Default to “f”.
separator : Union[str, Callable[[str], Iterable[str]]]
str or callable used to split the data into individual elements. If a str is given, data.split(separator) is used. Default to “,”.
container : Union[Type, Callable[[Iterable], Sequence]], optional
Container type to use for the output data. Possible values are: list, tuple, np.ndarray, etc, Default to list.
Returns:Parsed data.
Return type:Sequence
read_binary_values(datatype: typing_extensions.Literal['s', 'b', 'B', 'h', 'H', 'i', 'I', 'l', 'L', 'q', 'Q', 'f', 'd'][s, b, B, h, H, i, I, l, L, q, Q, f, d] = 'f', is_big_endian: bool = False, container: Union[Type[CT_co], Callable[[Iterable[T_co]], Sequence[T_co]]] = <class 'list'>, header_fmt: typing_extensions.Literal['ieee', 'hp', 'empty'][ieee, hp, empty] = 'ieee', expect_termination: bool = True, data_points: int = 0, chunk_size: Optional[int] = None) → Sequence[Union[int, float]]

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

Parameters:
  • datatype (BINARY_DATATYPES, optional) – Format string for a single element. See struct module. ‘f’ by default.
  • is_big_endian (bool, optional) – Are the data in big or little endian order. Defaults to False.
  • container (Union[Type, Callable[[Iterable], Sequence]], optional) – Container type to use for the output data. Possible values are: list, tuple, np.ndarray, etc, Default to list.
  • header_fmt (util.BINARY_HEADERS, optional) – Format of the header prefixing the data. Defaults to ‘ieee’.
  • expect_termination (bool, optional) – When set to False, the expected length of the binary values block does not account for the final termination character (the read termination). Defaults to True.
  • data_points (int, optional) – Number of points expected in the block. This is used only if the instrument does not report it itself. This will be converted in a number of bytes based on the datatype. Defaults to 0.
  • chunk_size (int, optional) – Size of the chunks to read from the device. Using larger chunks may be faster for large amount of data.
Returns:

Data read from the device.

Return type:

Sequence[Union[int, float]]

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

Read a certain number of bytes from the instrument.

Parameters:
  • count (int) – The number of bytes to read from the instrument.
  • chunk_size (Optional[int], optional) – The chunk size to use to perform the reading. If count > chunk_size multiple low level operations will be performed. Defaults to None, meaning the resource wide set value is set.
  • break_on_termchar (bool, optional) – Should the reading stop when a termination character is encountered or when the message ends. Defaults to False.
Returns:

Bytes read from the instrument.

Return type:

bytes

read_raw(size: Optional[int] = None) → bytes

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

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

Parameters:size (Optional[int], optional) – The chunk size to use to perform the reading. Defaults to None, meaning the resource wide set value is set.
Returns:Bytes read from the instrument.
Return type:bytes
read_stb() → int

Service request status register.

read_termination

Read termination character.

read_termination_context(new_termination: str) → Iterator[T_co]
classmethod register(interface_type: pyvisa.constants.InterfaceType, resource_class: str) → Callable[[Type[T]], Type[T]]

Create a decorator to register a class.

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

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

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

Return type:

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

resource_class

Resource class as defined by the canonical resource name.

Possible values are: INSTR, INTFC, SOCKET, RAW…
VISA Attribute:VI_ATTR_RSRC_CLASS (3221159937)
resource_info

Get the extended information of this resource.

resource_manufacturer_name

Manufacturer name of the vendor that implemented the VISA library.

This attribute is not related to the device manufacturer attributes.

Note The value of this attribute is for display purposes only and not for programmatic decisions, as the value can differ between VISA implementations and/or revisions.

VISA Attribute:VI_ATTR_RSRC_MANF_NAME (3221160308)
resource_name

Unique identifier for a resource compliant with the address structure. :VISA Attribute: VI_ATTR_RSRC_NAME (3221159938)

send_end

Should END be asserted during the transfer of the last byte of the buffer. :VISA Attribute: VI_ATTR_SEND_END_EN (1073676310) :type: bool

session

Resource session handle.

Raises:errors.InvalidSession – Raised if session is closed.
set_visa_attribute(name: pyvisa.constants.ResourceAttribute, state: Any) → pyvisa.constants.StatusCode

Set the state of an attribute.

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

Parameters:
  • name (constants.ResourceAttribute) – Attribute for which the state is to be modified.
  • state (Any) – The state of the attribute to be set for the specified object.
Returns:

Return value of the library call.

Return type:

constants.StatusCode

spec_version

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

The format of the value has the upper 12 bits as the major number of the version, the next lower 12 bits as the minor number of the version, and the lowest 8 bits as the sub-minor number of the version. The current VISA specification defines the value to be 00300000h.
VISA Attribute:VI_ATTR_RSRC_SPEC_VERSION (1073676656)
Type:int
Range:0 <= value <= 4294967295
stb

Service request status register.

timeout

Timeout in milliseconds for all resource I/O operations.

This value is used when accessing the device associated with the given session.

Special values:

  • immediate (VI_TMO_IMMEDIATE): 0
    (for convenience, any value smaller than 1 is considered as 0)
  • infinite (VI_TMO_INFINITE): float('+inf')
    (for convenience, None is considered as float('+inf'))

To set an infinite timeout, you can also use:

>>> del instrument.timeout

A timeout value of VI_TMO_IMMEDIATE means that operations should never wait for the device to respond. A timeout value of VI_TMO_INFINITE disables the timeout mechanism.

VISA Attribute:VI_ATTR_TMO_VALUE (1073676314)
Type:int
Range:0 <= value <= 4294967295
uninstall_handler(event_type: pyvisa.constants.EventType, handler: Callable[[NewType.<locals>.new_type, pyvisa.constants.EventType, NewType.<locals>.new_type, Any], None], user_handle=None) → None

Uninstalls handlers for events in this resource.

Parameters:
  • event_type (constants.EventType) – Logical event identifier.
  • handler (VISAHandler) – Handler function to be uninstalled by a client application.
  • user_handle (Any) – The user handle returned by install_handler.
unlock() → None

Relinquishes a lock for the specified resource.

visa_attributes_classes = {<class 'pyvisa.attributes.AttrVI_ATTR_RSRC_LOCK_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_TRIG_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_TYPE'>, <class 'pyvisa.attributes.AttrVI_ATTR_TCPIP_HISLIP_MAX_MESSAGE_KB'>, <class 'pyvisa.attributes.AttrVI_ATTR_IO_PROT'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_INST_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_TCPIP_HOSTNAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_TCPIP_IS_HISLIP'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_SPEC_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_USER_DATA'>, <class 'pyvisa.attributes.AttrVI_ATTR_TERMCHAR'>, <class 'pyvisa.attributes.AttrVI_ATTR_RD_BUF_SIZE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_IMPL_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_TCPIP_ADDR'>, <class 'pyvisa.attributes.AttrVI_ATTR_TMO_VALUE'>, <class 'pyvisa.attributes.AttrVI_ATTR_MAX_QUEUE_LENGTH'>, <class 'pyvisa.attributes.AttrVI_ATTR_TERMCHAR_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_RD_BUF_OPER_MODE'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_WR_BUF_OPER_MODE'>, <class 'pyvisa.attributes.AttrVI_ATTR_WR_BUF_SIZE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_DMA_ALLOW_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_TCPIP_HISLIP_OVERLAP_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_TCPIP_HISLIP_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_SEND_END_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_SUPPRESS_END_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_FILE_APPEND_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_CLASS'>, <class 'pyvisa.attributes.AttrVI_ATTR_TCPIP_DEVICE_NAME'>}
wait_on_event(in_event_type: pyvisa.constants.EventType, timeout: int, capture_timeout: bool = False) → pyvisa.resources.resource.WaitResponse

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

in_event_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. None means waiting forever if necessary.
capture_timeout : bool, optional
When True will not produce a VisaIOError(VI_ERROR_TMO) but instead return a WaitResponse with timed_out=True.
Returns:Object that contains event_type, context and ret value.
Return type:WaitResponse
wrap_handler(callable: Callable[[Resource, pyvisa.events.Event, Any], None]) → Callable[[NewType.<locals>.new_type, pyvisa.constants.EventType, NewType.<locals>.new_type, Any], None]

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

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

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

write(message: str, termination: Optional[str] = None, encoding: Optional[str] = None) → int

Write a string message to the device.

The write_termination is always appended to it.

Parameters:
  • message (str) – The message to be sent.
  • termination (Optional[str], optional) – Alternative character termination to use. If None, the value of write_termination is used. Defaults to None.
  • encoding (Optional[str], optional) – Alternative encoding to use to turn str into bytes. If None, the value of encoding is used. Defaults to None.
Returns:

Number of bytes written.

Return type:

int

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

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

The write_termination is always appended to it.

Parameters:
  • message (str) – Header of the message to be sent.
  • values (Sequence[Any]) – Data to be writen to the device.
  • converter (Union[str, Callable[[Any], str]], optional) – Str formatting codes or function used to convert each value. Defaults to “f”.
  • separator (Union[str, Callable[[Iterable[str]], str]], optional) – Str or callable that join the values in a single str. If a str is given, separator.join(values) is used. Defaults to ‘,’
  • termination (Optional[str], optional) – Alternative character termination to use. If None, the value of write_termination is used. Defaults to None.
  • encoding (Optional[str], optional) – Alternative encoding to use to turn str into bytes. If None, the value of encoding is used. Defaults to None.
Returns:

Number of bytes written.

Return type:

int

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

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

The write_termination is always appended to it.

Parameters:
  • message (str) – The header of the message to be sent.
  • values (Sequence[Any]) – Data to be written to the device.
  • datatype (util.BINARY_DATATYPES, optional) – The format string for a single element. See struct module.
  • is_big_endian (bool, optional) – Are the data in big or little endian order.
  • termination (Optional[str], optional) – Alternative character termination to use. If None, the value of write_termination is used. Defaults to None.
  • encoding (Optional[str], optional) – Alternative encoding to use to turn str into bytes. If None, the value of encoding is used. Defaults to None.
  • header_fmt (util.BINARY_HEADERS) – Format of the header prefixing the data.
Returns:

Number of bytes written.

Return type:

int

write_raw(message: bytes) → int

Write a byte message to the device.

Parameters:message (bytes) – The message to be sent.
Returns:Number of bytes written
Return type:int
write_termination

Write termination character.

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

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

More complex resource names can be specified with the following grammar:
TCPIP[board]::host address::port::SOCKET

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

CR = '\r'
LF = '\n'
allow_dma

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

In some implementations, this attribute may have global effects even though it is documented to be a local attribute. Since this affects performance and not functionality, that behavior is acceptable.
VISA Attribute:VI_ATTR_DMA_ALLOW_EN (1073676318)
Type:bool
assert_trigger() → None

Sends a software trigger to the device.

before_close() → None

Called just before closing an instrument.

chunk_size = 20480
clear() → None

Clear this resource.

close() → None

Closes the VISA session and marks the handle as invalid.

disable_event(event_type: pyvisa.constants.EventType, mechanism: pyvisa.constants.EventMechanism) → None

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

Parameters:
  • event_type (constants.EventType) – Logical event identifier.
  • mechanism (constants.EventMechanism) – Specifies event handling mechanisms to be disabled.
discard_events(event_type: pyvisa.constants.EventType, mechanism: pyvisa.constants.EventMechanism) → None

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

Parameters:
  • event_type (constants.EventType) – Logical event identifier.
  • mechanism (constants.EventMechanism) – Specifies event handling mechanisms to be disabled.
enable_event(event_type: pyvisa.constants.EventType, mechanism: pyvisa.constants.EventMechanism, context: None = None) → None

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

Parameters:
  • event_type (constants.EventType) – Logical event identifier.
  • mechanism (constants.EventMechanism) – Specifies event handling mechanisms to be enabled
  • context (None) – Not currently used, leave as None.
encoding

Encoding used for read and write operations.

flush(mask: pyvisa.constants.BufferOperation) → None

Manually clears the specified buffers.

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

Parameters:mask (constants.BufferOperation) – Specifies the action to be taken with flushing the buffer. See highlevel.VisaLibraryBase.flush for a detailed description.
get_visa_attribute(name: pyvisa.constants.ResourceAttribute) → Any

Retrieves the state of an attribute in this resource.

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

Parameters:name (constants.ResourceAttribute) – Resource attribute for which the state query is made.
Returns:The state of the queried attribute for a specified resource.
Return type:Any
ignore_warning(*warnings_constants) → AbstractContextManager[T_co]

Ignoring warnings context manager for the current resource.

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

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

This attribute value is defined by the individual manufacturer and increments with each new revision. The format of the value has the upper 12 bits as the major number of the version, the next lower 12 bits as the minor number of the version, and the lowest 8 bits as the sub-minor number of the version.
VISA Attribute:VI_ATTR_RSRC_IMPL_VERSION (1073676291)
Type:int
Range:0 <= value <= 4294967295
install_handler(event_type: pyvisa.constants.EventType, handler: Callable[[NewType.<locals>.new_type, pyvisa.constants.EventType, NewType.<locals>.new_type, Any], None], user_handle=None) → Any

Install handlers for event callbacks in this resource.

Parameters:
  • event_type (constants.EventType) – Logical event identifier.
  • handler (VISAHandler) – Handler function to be installed by a client application.
  • user_handle – A value specified by an application that can be used for identifying handlers uniquely for an event type. Depending on the backend they may be restriction on the possible values. Look at the backend install_visa_handler for more details.
Returns:

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

Return type:

Any

interface_number

Board number for the given interface. :VISA Attribute: VI_ATTR_INTF_NUM (1073676662) :type: int :range: 0 <= value <= 65535

interface_type

Interface type of the given session. :VISA Attribute: VI_ATTR_INTF_TYPE (1073676657) :type: :class:pyvisa.constants.InterfaceType

io_protocol

IO protocol to use.

In VXI, you can choose normal word serial or fast data channel (FDC). In GPIB, you can choose normal or high-speed (HS-488) transfers. In serial, TCPIP, or USB RAW, you can choose normal transfers or 488.2-defined strings. In USB INSTR, you can choose normal or vendor-specific transfers.
VISA Attribute:VI_ATTR_IO_PROT (1073676316)
Type::class:pyvisa.constants.IOProtocol
last_status

Last status code for this session.

lock(timeout: Union[float, typing_extensions.Literal['default'][default]] = 'default', requested_key: Optional[str] = None) → str

Establish a shared lock to the resource.

Parameters:
  • timeout (Union[float, Literal["default"]], optional) – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. Defaults to “default” which means use self.timeout.
  • requested_key (Optional[str], optional) – Access key used by another session with which you want your session to share a lock or None to generate a new shared access key.
Returns:

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

Return type:

str

lock_context(timeout: Union[float, typing_extensions.Literal['default'][default]] = 'default', requested_key: Optional[str] = 'exclusive') → Iterator[Optional[str]]

A context that locks

Parameters:
  • timeout (Union[float, Literal["default"]], optional) – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. Defaults to “default” which means use self.timeout.
  • requested_key (Optional[str], optional) – When using default of ‘exclusive’ the lock is an exclusive lock. Otherwise it is the access key for the shared lock or None to generate a new shared access key.
Yields:

Optional[str] – The access_key if applicable.

lock_excl(timeout: Union[float, typing_extensions.Literal['default'][default]] = 'default') → None

Establish an exclusive lock to the resource.

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

Current locking state of the resource.

The resource can be unlocked, locked with an exclusive lock, or locked with a shared lock.
VISA Attribute:VI_ATTR_RSRC_LOCK_STATE (1073676292)
Type::class:pyvisa.constants.AccessModes
open(access_mode: pyvisa.constants.AccessModes = <AccessModes.no_lock: 0>, open_timeout: int = 5000) → None

Opens a session to the specified resource.

Parameters:
  • access_mode (constants.AccessModes, optional) – Specifies the mode by which the resource is to be accessed. Defaults to constants.AccessModes.no_lock.
  • open_timeout (int, optional) – If the access_mode parameter requests a lock, then this parameter specifies the absolute time period (in milliseconds) that the resource waits to get unlocked before this operation returns an error. Defaults to 5000.
query(message: str, delay: Optional[float] = None) → str

A combination of write(message) and read()

Parameters:
  • message (str) – The message to send.
  • delay (Optional[float], optional) – Delay in seconds between write and read operations. If None, defaults to self.query_delay.
Returns:

Answer from the device.

Return type:

str

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

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

Parameters:
  • message (str) – The message to send.
  • converter (ASCII_CONVERTER, optional) – Str format of function to convert each value. Default to “f”.
  • separator (Union[str, Callable[[str], Iterable[str]]]) – str or callable used to split the data into individual elements. If a str is given, data.split(separator) is used. Default to “,”.
  • container (Union[Type, Callable[[Iterable], Sequence]], optional) – Container type to use for the output data. Possible values are: list, tuple, np.ndarray, etc, Default to list.
  • delay (Optional[float], optional) – Delay in seconds between write and read operations. If None, defaults to self.query_delay.
Returns:

Parsed data.

Return type:

Sequence

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

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

Parameters:
  • message (str) – The message to send.
  • datatype (BINARY_DATATYPES, optional) – Format string for a single element. See struct module. ‘f’ by default.
  • is_big_endian (bool, optional) – Are the data in big or little endian order. Defaults to False.
  • container (Union[Type, Callable[[Iterable], Sequence]], optional) – Container type to use for the output data. Possible values are: list, tuple, np.ndarray, etc, Default to list.
  • delay (Optional[float], optional) – Delay in seconds between write and read operations. If None, defaults to self.query_delay.
  • header_fmt (util.BINARY_HEADERS, optional) – Format of the header prefixing the data. Defaults to ‘ieee’.
  • expect_termination (bool, optional) – When set to False, the expected length of the binary values block does not account for the final termination character (the read termination). Defaults to True.
  • data_points (int, optional) – Number of points expected in the block. This is used only if the instrument does not report it itself. This will be converted in a number of bytes based on the datatype. Defaults to 0.
  • chunk_size (int, optional) – Size of the chunks to read from the device. Using larger chunks may be faster for large amount of data.
Returns:

Data read from the device.

Return type:

Sequence[Union[int, float]]

query_delay = 0.0
read(termination: Optional[str] = None, encoding: Optional[str] = None) → str

Read a string from the device.

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

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

Message read from the instrument and decoded.

Return type:

str

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

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

Parameters:converter (ASCII_CONVERTER, optional) – Str format of function to convert each value. Default to “f”.
separator : Union[str, Callable[[str], Iterable[str]]]
str or callable used to split the data into individual elements. If a str is given, data.split(separator) is used. Default to “,”.
container : Union[Type, Callable[[Iterable], Sequence]], optional
Container type to use for the output data. Possible values are: list, tuple, np.ndarray, etc, Default to list.
Returns:Parsed data.
Return type:Sequence
read_binary_values(datatype: typing_extensions.Literal['s', 'b', 'B', 'h', 'H', 'i', 'I', 'l', 'L', 'q', 'Q', 'f', 'd'][s, b, B, h, H, i, I, l, L, q, Q, f, d] = 'f', is_big_endian: bool = False, container: Union[Type[CT_co], Callable[[Iterable[T_co]], Sequence[T_co]]] = <class 'list'>, header_fmt: typing_extensions.Literal['ieee', 'hp', 'empty'][ieee, hp, empty] = 'ieee', expect_termination: bool = True, data_points: int = 0, chunk_size: Optional[int] = None) → Sequence[Union[int, float]]

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

Parameters:
  • datatype (BINARY_DATATYPES, optional) – Format string for a single element. See struct module. ‘f’ by default.
  • is_big_endian (bool, optional) – Are the data in big or little endian order. Defaults to False.
  • container (Union[Type, Callable[[Iterable], Sequence]], optional) – Container type to use for the output data. Possible values are: list, tuple, np.ndarray, etc, Default to list.
  • header_fmt (util.BINARY_HEADERS, optional) – Format of the header prefixing the data. Defaults to ‘ieee’.
  • expect_termination (bool, optional) – When set to False, the expected length of the binary values block does not account for the final termination character (the read termination). Defaults to True.
  • data_points (int, optional) – Number of points expected in the block. This is used only if the instrument does not report it itself. This will be converted in a number of bytes based on the datatype. Defaults to 0.
  • chunk_size (int, optional) – Size of the chunks to read from the device. Using larger chunks may be faster for large amount of data.
Returns:

Data read from the device.

Return type:

Sequence[Union[int, float]]

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

Read a certain number of bytes from the instrument.

Parameters:
  • count (int) – The number of bytes to read from the instrument.
  • chunk_size (Optional[int], optional) – The chunk size to use to perform the reading. If count > chunk_size multiple low level operations will be performed. Defaults to None, meaning the resource wide set value is set.
  • break_on_termchar (bool, optional) – Should the reading stop when a termination character is encountered or when the message ends. Defaults to False.
Returns:

Bytes read from the instrument.

Return type:

bytes

read_raw(size: Optional[int] = None) → bytes

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

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

Parameters:size (Optional[int], optional) – The chunk size to use to perform the reading. Defaults to None, meaning the resource wide set value is set.
Returns:Bytes read from the instrument.
Return type:bytes
read_stb() → int

Service request status register.

read_termination

Read termination character.

read_termination_context(new_termination: str) → Iterator[T_co]
classmethod register(interface_type: pyvisa.constants.InterfaceType, resource_class: str) → Callable[[Type[T]], Type[T]]

Create a decorator to register a class.

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

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

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

Return type:

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

resource_class

Resource class as defined by the canonical resource name.

Possible values are: INSTR, INTFC, SOCKET, RAW…
VISA Attribute:VI_ATTR_RSRC_CLASS (3221159937)
resource_info

Get the extended information of this resource.

resource_manufacturer_name

Manufacturer name of the vendor that implemented the VISA library.

This attribute is not related to the device manufacturer attributes.

Note The value of this attribute is for display purposes only and not for programmatic decisions, as the value can differ between VISA implementations and/or revisions.

VISA Attribute:VI_ATTR_RSRC_MANF_NAME (3221160308)
resource_name

Unique identifier for a resource compliant with the address structure. :VISA Attribute: VI_ATTR_RSRC_NAME (3221159938)

send_end

Should END be asserted during the transfer of the last byte of the buffer. :VISA Attribute: VI_ATTR_SEND_END_EN (1073676310) :type: bool

session

Resource session handle.

Raises:errors.InvalidSession – Raised if session is closed.
set_visa_attribute(name: pyvisa.constants.ResourceAttribute, state: Any) → pyvisa.constants.StatusCode

Set the state of an attribute.

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

Parameters:
  • name (constants.ResourceAttribute) – Attribute for which the state is to be modified.
  • state (Any) – The state of the attribute to be set for the specified object.
Returns:

Return value of the library call.

Return type:

constants.StatusCode

spec_version

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

The format of the value has the upper 12 bits as the major number of the version, the next lower 12 bits as the minor number of the version, and the lowest 8 bits as the sub-minor number of the version. The current VISA specification defines the value to be 00300000h.
VISA Attribute:VI_ATTR_RSRC_SPEC_VERSION (1073676656)
Type:int
Range:0 <= value <= 4294967295
stb

Service request status register.

timeout

Timeout in milliseconds for all resource I/O operations.

This value is used when accessing the device associated with the given session.

Special values:

  • immediate (VI_TMO_IMMEDIATE): 0
    (for convenience, any value smaller than 1 is considered as 0)
  • infinite (VI_TMO_INFINITE): float('+inf')
    (for convenience, None is considered as float('+inf'))

To set an infinite timeout, you can also use:

>>> del instrument.timeout

A timeout value of VI_TMO_IMMEDIATE means that operations should never wait for the device to respond. A timeout value of VI_TMO_INFINITE disables the timeout mechanism.

VISA Attribute:VI_ATTR_TMO_VALUE (1073676314)
Type:int
Range:0 <= value <= 4294967295
uninstall_handler(event_type: pyvisa.constants.EventType, handler: Callable[[NewType.<locals>.new_type, pyvisa.constants.EventType, NewType.<locals>.new_type, Any], None], user_handle=None) → None

Uninstalls handlers for events in this resource.

Parameters:
  • event_type (constants.EventType) – Logical event identifier.
  • handler (VISAHandler) – Handler function to be uninstalled by a client application.
  • user_handle (Any) – The user handle returned by install_handler.
unlock() → None

Relinquishes a lock for the specified resource.

visa_attributes_classes = {<class 'pyvisa.attributes.AttrVI_ATTR_RSRC_LOCK_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_TYPE'>, <class 'pyvisa.attributes.AttrVI_ATTR_IO_PROT'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_INST_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_TCPIP_HOSTNAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_TCPIP_PORT'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_SPEC_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_USER_DATA'>, <class 'pyvisa.attributes.AttrVI_ATTR_TERMCHAR'>, <class 'pyvisa.attributes.AttrVI_ATTR_RD_BUF_SIZE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_IMPL_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_TCPIP_ADDR'>, <class 'pyvisa.attributes.AttrVI_ATTR_TCPIP_KEEPALIVE'>, <class 'pyvisa.attributes.AttrVI_ATTR_TMO_VALUE'>, <class 'pyvisa.attributes.AttrVI_ATTR_MAX_QUEUE_LENGTH'>, <class 'pyvisa.attributes.AttrVI_ATTR_TERMCHAR_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_RD_BUF_OPER_MODE'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_WR_BUF_OPER_MODE'>, <class 'pyvisa.attributes.AttrVI_ATTR_WR_BUF_SIZE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_DMA_ALLOW_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_TCPIP_NODELAY'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_SEND_END_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_SUPPRESS_END_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_FILE_APPEND_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_CLASS'>}
wait_on_event(in_event_type: pyvisa.constants.EventType, timeout: int, capture_timeout: bool = False) → pyvisa.resources.resource.WaitResponse

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

in_event_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. None means waiting forever if necessary.
capture_timeout : bool, optional
When True will not produce a VisaIOError(VI_ERROR_TMO) but instead return a WaitResponse with timed_out=True.
Returns:Object that contains event_type, context and ret value.
Return type:WaitResponse
wrap_handler(callable: Callable[[Resource, pyvisa.events.Event, Any], None]) → Callable[[NewType.<locals>.new_type, pyvisa.constants.EventType, NewType.<locals>.new_type, Any], None]

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

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

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

write(message: str, termination: Optional[str] = None, encoding: Optional[str] = None) → int

Write a string message to the device.

The write_termination is always appended to it.

Parameters:
  • message (str) – The message to be sent.
  • termination (Optional[str], optional) – Alternative character termination to use. If None, the value of write_termination is used. Defaults to None.
  • encoding (Optional[str], optional) – Alternative encoding to use to turn str into bytes. If None, the value of encoding is used. Defaults to None.
Returns:

Number of bytes written.

Return type:

int

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

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

The write_termination is always appended to it.

Parameters:
  • message (str) – Header of the message to be sent.
  • values (Sequence[Any]) – Data to be writen to the device.
  • converter (Union[str, Callable[[Any], str]], optional) – Str formatting codes or function used to convert each value. Defaults to “f”.
  • separator (Union[str, Callable[[Iterable[str]], str]], optional) – Str or callable that join the values in a single str. If a str is given, separator.join(values) is used. Defaults to ‘,’
  • termination (Optional[str], optional) – Alternative character termination to use. If None, the value of write_termination is used. Defaults to None.
  • encoding (Optional[str], optional) – Alternative encoding to use to turn str into bytes. If None, the value of encoding is used. Defaults to None.
Returns:

Number of bytes written.

Return type:

int

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

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

The write_termination is always appended to it.

Parameters:
  • message (str) – The header of the message to be sent.
  • values (Sequence[Any]) – Data to be written to the device.
  • datatype (util.BINARY_DATATYPES, optional) – The format string for a single element. See struct module.
  • is_big_endian (bool, optional) – Are the data in big or little endian order.
  • termination (Optional[str], optional) – Alternative character termination to use. If None, the value of write_termination is used. Defaults to None.
  • encoding (Optional[str], optional) – Alternative encoding to use to turn str into bytes. If None, the value of encoding is used. Defaults to None.
  • header_fmt (util.BINARY_HEADERS) – Format of the header prefixing the data.
Returns:

Number of bytes written.

Return type:

int

write_raw(message: bytes) → int

Write a byte message to the device.

Parameters:message (bytes) – The message to be sent.
Returns:Number of bytes written
Return type:int
write_termination

Write termination character.

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

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

More complex resource names can be specified with the following grammar:
USB[board]::manufacturer ID::model code::serial number[::USB interface number][::INSTR]

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

CR = '\r'
LF = '\n'
allow_dma

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

In some implementations, this attribute may have global effects even though it is documented to be a local attribute. Since this affects performance and not functionality, that behavior is acceptable.
VISA Attribute:VI_ATTR_DMA_ALLOW_EN (1073676318)
Type:bool
assert_trigger() → None

Sends a software trigger to the device.

before_close() → None

Called just before closing an instrument.

chunk_size = 20480
clear() → None

Clear this resource.

close() → None

Closes the VISA session and marks the handle as invalid.

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

Performs a USB control pipe transfer from the device.

Parameters:
  • request_type_bitmap_field (int) – bmRequestType parameter of the setup stage of a USB control transfer.
  • request_id (int) – bRequest parameter of the setup stage of a USB control transfer.
  • request_value (int) – wValue parameter of the setup stage of a USB control transfer.
  • index (int) – wIndex parameter of the setup stage of a USB control transfer. This is usually the index of the interface or endpoint.
  • length (int) – wLength parameter of the setup stage of a USB control transfer. This value also specifies the size of the data buffer to receive the data from the optional data stage of the control transfer.
Returns:

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

Return type:

bytes

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

Performs a USB control pipe transfer to the device.

Parameters:
  • request_type_bitmap_field (int) – bmRequestType parameter of the setup stage of a USB control transfer.
  • request_id (int) – bRequest parameter of the setup stage of a USB control transfer.
  • request_value (int) – wValue parameter of the setup stage of a USB control transfer.
  • index (int) – wIndex parameter of the setup stage of a USB control transfer. This is usually the index of the interface or endpoint.
  • data (str) – The data buffer that sends the data in the optional data stage of the control transfer.
control_ren(mode: pyvisa.constants.RENLineOperation) → pyvisa.constants.StatusCode

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

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

Corresponds to viGpibControlREN function of the VISA library.

Parameters:mode (constants.RENLineOperation) – Specifies the state of the REN line and optionally the device remote/local state.
Returns:Return value of the library call.
Return type:constants.StatusCode
disable_event(event_type: pyvisa.constants.EventType, mechanism: pyvisa.constants.EventMechanism) → None

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

Parameters:
  • event_type (constants.EventType) – Logical event identifier.
  • mechanism (constants.EventMechanism) – Specifies event handling mechanisms to be disabled.
discard_events(event_type: pyvisa.constants.EventType, mechanism: pyvisa.constants.EventMechanism) → None

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

Parameters:
  • event_type (constants.EventType) – Logical event identifier.
  • mechanism (constants.EventMechanism) – Specifies event handling mechanisms to be disabled.
enable_event(event_type: pyvisa.constants.EventType, mechanism: pyvisa.constants.EventMechanism, context: None = None) → None

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

Parameters:
  • event_type (constants.EventType) – Logical event identifier.
  • mechanism (constants.EventMechanism) – Specifies event handling mechanisms to be enabled
  • context (None) – Not currently used, leave as None.
encoding

Encoding used for read and write operations.

flush(mask: pyvisa.constants.BufferOperation) → None

Manually clears the specified buffers.

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

Parameters:mask (constants.BufferOperation) – Specifies the action to be taken with flushing the buffer. See highlevel.VisaLibraryBase.flush for a detailed description.
get_visa_attribute(name: pyvisa.constants.ResourceAttribute) → Any

Retrieves the state of an attribute in this resource.

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

Parameters:name (constants.ResourceAttribute) – Resource attribute for which the state query is made.
Returns:The state of the queried attribute for a specified resource.
Return type:Any
ignore_warning(*warnings_constants) → AbstractContextManager[T_co]

Ignoring warnings context manager for the current resource.

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

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

This attribute value is defined by the individual manufacturer and increments with each new revision. The format of the value has the upper 12 bits as the major number of the version, the next lower 12 bits as the minor number of the version, and the lowest 8 bits as the sub-minor number of the version.
VISA Attribute:VI_ATTR_RSRC_IMPL_VERSION (1073676291)
Type:int
Range:0 <= value <= 4294967295
install_handler(event_type: pyvisa.constants.EventType, handler: Callable[[NewType.<locals>.new_type, pyvisa.constants.EventType, NewType.<locals>.new_type, Any], None], user_handle=None) → Any

Install handlers for event callbacks in this resource.

Parameters:
  • event_type (constants.EventType) – Logical event identifier.
  • handler (VISAHandler) – Handler function to be installed by a client application.
  • user_handle – A value specified by an application that can be used for identifying handlers uniquely for an event type. Depending on the backend they may be restriction on the possible values. Look at the backend install_visa_handler for more details.
Returns:

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

Return type:

Any

interface_number

USB interface number used by the given session. :VISA Attribute: VI_ATTR_USB_INTFC_NUM (1073676705) :type: int :range: 0 <= value <= 254

interface_type

Interface type of the given session. :VISA Attribute: VI_ATTR_INTF_TYPE (1073676657) :type: :class:pyvisa.constants.InterfaceType

io_protocol

IO protocol to use.

In VXI, you can choose normal word serial or fast data channel (FDC). In GPIB, you can choose normal or high-speed (HS-488) transfers. In serial, TCPIP, or USB RAW, you can choose normal transfers or 488.2-defined strings. In USB INSTR, you can choose normal or vendor-specific transfers.
VISA Attribute:VI_ATTR_IO_PROT (1073676316)
Type::class:pyvisa.constants.IOProtocol
is_4882_compliant

Whether the device is 488.2 compliant.

last_status

Last status code for this session.

lock(timeout: Union[float, typing_extensions.Literal['default'][default]] = 'default', requested_key: Optional[str] = None) → str

Establish a shared lock to the resource.

Parameters:
  • timeout (Union[float, Literal["default"]], optional) – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. Defaults to “default” which means use self.timeout.
  • requested_key (Optional[str], optional) – Access key used by another session with which you want your session to share a lock or None to generate a new shared access key.
Returns:

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

Return type:

str

lock_context(timeout: Union[float, typing_extensions.Literal['default'][default]] = 'default', requested_key: Optional[str] = 'exclusive') → Iterator[Optional[str]]

A context that locks

Parameters:
  • timeout (Union[float, Literal["default"]], optional) – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. Defaults to “default” which means use self.timeout.
  • requested_key (Optional[str], optional) – When using default of ‘exclusive’ the lock is an exclusive lock. Otherwise it is the access key for the shared lock or None to generate a new shared access key.
Yields:

Optional[str] – The access_key if applicable.

lock_excl(timeout: Union[float, typing_extensions.Literal['default'][default]] = 'default') → None

Establish an exclusive lock to the resource.

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

Current locking state of the resource.

The resource can be unlocked, locked with an exclusive lock, or locked with a shared lock.
VISA Attribute:VI_ATTR_RSRC_LOCK_STATE (1073676292)
Type::class:pyvisa.constants.AccessModes
manufacturer_id

Manufacturer identification number of the device. :VISA Attribute: VI_ATTR_MANF_ID (1073676505) :type: int :range: 0 <= value <= 65535

manufacturer_name

Manufacturer name. :VISA Attribute: VI_ATTR_MANF_NAME (3221160050)

maximum_interrupt_size

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

If a USB interrupt contains more data than this size, the data in excess of this size will be lost.
VISA Attribute:VI_ATTR_USB_MAX_INTR_SIZE (1073676719)
Type:int
Range:0 <= value <= 65535
model_code

Model code for the device. :VISA Attribute: VI_ATTR_MODEL_CODE (1073676511) :type: int :range: 0 <= value <= 65535

model_name

Model name of the device. :VISA Attribute: VI_ATTR_MODEL_NAME (3221160055)

open(access_mode: pyvisa.constants.AccessModes = <AccessModes.no_lock: 0>, open_timeout: int = 5000) → None

Opens a session to the specified resource.

Parameters:
  • access_mode (constants.AccessModes, optional) – Specifies the mode by which the resource is to be accessed. Defaults to constants.AccessModes.no_lock.
  • open_timeout (int, optional) – If the access_mode parameter requests a lock, then this parameter specifies the absolute time period (in milliseconds) that the resource waits to get unlocked before this operation returns an error. Defaults to 5000.
query(message: str, delay: Optional[float] = None) → str

A combination of write(message) and read()

Parameters:
  • message (str) – The message to send.
  • delay (Optional[float], optional) – Delay in seconds between write and read operations. If None, defaults to self.query_delay.
Returns:

Answer from the device.

Return type:

str

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

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

Parameters:
  • message (str) – The message to send.
  • converter (ASCII_CONVERTER, optional) – Str format of function to convert each value. Default to “f”.
  • separator (Union[str, Callable[[str], Iterable[str]]]) – str or callable used to split the data into individual elements. If a str is given, data.split(separator) is used. Default to “,”.
  • container (Union[Type, Callable[[Iterable], Sequence]], optional) – Container type to use for the output data. Possible values are: list, tuple, np.ndarray, etc, Default to list.
  • delay (Optional[float], optional) – Delay in seconds between write and read operations. If None, defaults to self.query_delay.
Returns:

Parsed data.

Return type:

Sequence

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

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

Parameters:
  • message (str) – The message to send.
  • datatype (BINARY_DATATYPES, optional) – Format string for a single element. See struct module. ‘f’ by default.
  • is_big_endian (bool, optional) – Are the data in big or little endian order. Defaults to False.
  • container (Union[Type, Callable[[Iterable], Sequence]], optional) – Container type to use for the output data. Possible values are: list, tuple, np.ndarray, etc, Default to list.
  • delay (Optional[float], optional) – Delay in seconds between write and read operations. If None, defaults to self.query_delay.
  • header_fmt (util.BINARY_HEADERS, optional) – Format of the header prefixing the data. Defaults to ‘ieee’.
  • expect_termination (bool, optional) – When set to False, the expected length of the binary values block does not account for the final termination character (the read termination). Defaults to True.
  • data_points (int, optional) – Number of points expected in the block. This is used only if the instrument does not report it itself. This will be converted in a number of bytes based on the datatype. Defaults to 0.
  • chunk_size (int, optional) – Size of the chunks to read from the device. Using larger chunks may be faster for large amount of data.
Returns:

Data read from the device.

Return type:

Sequence[Union[int, float]]

query_delay = 0.0
read(termination: Optional[str] = None, encoding: Optional[str] = None) → str

Read a string from the device.

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

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

Message read from the instrument and decoded.

Return type:

str

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

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

Parameters:converter (ASCII_CONVERTER, optional) – Str format of function to convert each value. Default to “f”.
separator : Union[str, Callable[[str], Iterable[str]]]
str or callable used to split the data into individual elements. If a str is given, data.split(separator) is used. Default to “,”.
container : Union[Type, Callable[[Iterable], Sequence]], optional
Container type to use for the output data. Possible values are: list, tuple, np.ndarray, etc, Default to list.
Returns:Parsed data.
Return type:Sequence
read_binary_values(datatype: typing_extensions.Literal['s', 'b', 'B', 'h', 'H', 'i', 'I', 'l', 'L', 'q', 'Q', 'f', 'd'][s, b, B, h, H, i, I, l, L, q, Q, f, d] = 'f', is_big_endian: bool = False, container: Union[Type[CT_co], Callable[[Iterable[T_co]], Sequence[T_co]]] = <class 'list'>, header_fmt: typing_extensions.Literal['ieee', 'hp', 'empty'][ieee, hp, empty] = 'ieee', expect_termination: bool = True, data_points: int = 0, chunk_size: Optional[int] = None) → Sequence[Union[int, float]]

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

Parameters:
  • datatype (BINARY_DATATYPES, optional) – Format string for a single element. See struct module. ‘f’ by default.
  • is_big_endian (bool, optional) – Are the data in big or little endian order. Defaults to False.
  • container (Union[Type, Callable[[Iterable], Sequence]], optional) – Container type to use for the output data. Possible values are: list, tuple, np.ndarray, etc, Default to list.
  • header_fmt (util.BINARY_HEADERS, optional) – Format of the header prefixing the data. Defaults to ‘ieee’.
  • expect_termination (bool, optional) – When set to False, the expected length of the binary values block does not account for the final termination character (the read termination). Defaults to True.
  • data_points (int, optional) – Number of points expected in the block. This is used only if the instrument does not report it itself. This will be converted in a number of bytes based on the datatype. Defaults to 0.
  • chunk_size (int, optional) – Size of the chunks to read from the device. Using larger chunks may be faster for large amount of data.
Returns:

Data read from the device.

Return type:

Sequence[Union[int, float]]

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

Read a certain number of bytes from the instrument.

Parameters:
  • count (int) – The number of bytes to read from the instrument.
  • chunk_size (Optional[int], optional) – The chunk size to use to perform the reading. If count > chunk_size multiple low level operations will be performed. Defaults to None, meaning the resource wide set value is set.
  • break_on_termchar (bool, optional) – Should the reading stop when a termination character is encountered or when the message ends. Defaults to False.
Returns:

Bytes read from the instrument.

Return type:

bytes

read_raw(size: Optional[int] = None) → bytes

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

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

Parameters:size (Optional[int], optional) – The chunk size to use to perform the reading. Defaults to None, meaning the resource wide set value is set.
Returns:Bytes read from the instrument.
Return type:bytes
read_stb() → int

Service request status register.

read_termination

Read termination character.

read_termination_context(new_termination: str) → Iterator[T_co]
classmethod register(interface_type: pyvisa.constants.InterfaceType, resource_class: str) → Callable[[Type[T]], Type[T]]

Create a decorator to register a class.

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

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

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

Return type:

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

resource_class

Resource class as defined by the canonical resource name.

Possible values are: INSTR, INTFC, SOCKET, RAW…
VISA Attribute:VI_ATTR_RSRC_CLASS (3221159937)
resource_info

Get the extended information of this resource.

resource_manufacturer_name

Manufacturer name of the vendor that implemented the VISA library.

This attribute is not related to the device manufacturer attributes.

Note The value of this attribute is for display purposes only and not for programmatic decisions, as the value can differ between VISA implementations and/or revisions.

VISA Attribute:VI_ATTR_RSRC_MANF_NAME (3221160308)
resource_name

Unique identifier for a resource compliant with the address structure. :VISA Attribute: VI_ATTR_RSRC_NAME (3221159938)

send_end

Should END be asserted during the transfer of the last byte of the buffer. :VISA Attribute: VI_ATTR_SEND_END_EN (1073676310) :type: bool

serial_number

USB serial number of this device. :VISA Attribute: VI_ATTR_USB_SERIAL_NUM (3221160352)

session

Resource session handle.

Raises:errors.InvalidSession – Raised if session is closed.
set_visa_attribute(name: pyvisa.constants.ResourceAttribute, state: Any) → pyvisa.constants.StatusCode

Set the state of an attribute.

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

Parameters:
  • name (constants.ResourceAttribute) – Attribute for which the state is to be modified.
  • state (Any) – The state of the attribute to be set for the specified object.
Returns:

Return value of the library call.

Return type:

constants.StatusCode

spec_version

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

The format of the value has the upper 12 bits as the major number of the version, the next lower 12 bits as the minor number of the version, and the lowest 8 bits as the sub-minor number of the version. The current VISA specification defines the value to be 00300000h.
VISA Attribute:VI_ATTR_RSRC_SPEC_VERSION (1073676656)
Type:int
Range:0 <= value <= 4294967295
stb

Service request status register.

timeout

Timeout in milliseconds for all resource I/O operations.

This value is used when accessing the device associated with the given session.

Special values:

  • immediate (VI_TMO_IMMEDIATE): 0
    (for convenience, any value smaller than 1 is considered as 0)
  • infinite (VI_TMO_INFINITE): float('+inf')
    (for convenience, None is considered as float('+inf'))

To set an infinite timeout, you can also use:

>>> del instrument.timeout

A timeout value of VI_TMO_IMMEDIATE means that operations should never wait for the device to respond. A timeout value of VI_TMO_INFINITE disables the timeout mechanism.

VISA Attribute:VI_ATTR_TMO_VALUE (1073676314)
Type:int
Range:0 <= value <= 4294967295
uninstall_handler(event_type: pyvisa.constants.EventType, handler: Callable[[NewType.<locals>.new_type, pyvisa.constants.EventType, NewType.<locals>.new_type, Any], None], user_handle=None) → None

Uninstalls handlers for events in this resource.

Parameters:
  • event_type (constants.EventType) – Logical event identifier.
  • handler (VISAHandler) – Handler function to be uninstalled by a client application.
  • user_handle (Any) – The user handle returned by install_handler.
unlock() → None

Relinquishes a lock for the specified resource.

usb_protocol

USB protocol used by this USB interface. :VISA Attribute: VI_ATTR_USB_PROTOCOL (1073676711) :type: int :range: 0 <= value <= 255

visa_attributes_classes = {<class 'pyvisa.attributes.AttrVI_ATTR_RSRC_LOCK_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_TYPE'>, <class 'pyvisa.attributes.AttrVI_ATTR_IO_PROT'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_INST_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_SPEC_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_USER_DATA'>, <class 'pyvisa.attributes.AttrVI_ATTR_TERMCHAR'>, <class 'pyvisa.attributes.AttrVI_ATTR_RD_BUF_SIZE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_IMPL_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_MODEL_CODE'>, <class 'pyvisa.attributes.AttrVI_ATTR_USB_MAX_INTR_SIZE'>, <class 'pyvisa.attributes.AttrVI_ATTR_TMO_VALUE'>, <class 'pyvisa.attributes.AttrVI_ATTR_MAX_QUEUE_LENGTH'>, <class 'pyvisa.attributes.AttrVI_ATTR_TERMCHAR_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_RD_BUF_OPER_MODE'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_WR_BUF_OPER_MODE'>, <class 'pyvisa.attributes.AttrVI_ATTR_WR_BUF_SIZE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_MODEL_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_DMA_ALLOW_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_USB_PROTOCOL'>, <class 'pyvisa.attributes.AttrVI_ATTR_USB_INTFC_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_SEND_END_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_SUPPRESS_END_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_FILE_APPEND_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_CLASS'>, <class 'pyvisa.attributes.AttrVI_ATTR_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_4882_COMPLIANT'>, <class 'pyvisa.attributes.AttrVI_ATTR_USB_SERIAL_NUM'>}
wait_on_event(in_event_type: pyvisa.constants.EventType, timeout: int, capture_timeout: bool = False) → pyvisa.resources.resource.WaitResponse

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

in_event_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. None means waiting forever if necessary.
capture_timeout : bool, optional
When True will not produce a VisaIOError(VI_ERROR_TMO) but instead return a WaitResponse with timed_out=True.
Returns:Object that contains event_type, context and ret value.
Return type:WaitResponse
wrap_handler(callable: Callable[[Resource, pyvisa.events.Event, Any], None]) → Callable[[NewType.<locals>.new_type, pyvisa.constants.EventType, NewType.<locals>.new_type, Any], None]

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

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

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

write(message: str, termination: Optional[str] = None, encoding: Optional[str] = None) → int

Write a string message to the device.

The write_termination is always appended to it.

Parameters:
  • message (str) – The message to be sent.
  • termination (Optional[str], optional) – Alternative character termination to use. If None, the value of write_termination is used. Defaults to None.
  • encoding (Optional[str], optional) – Alternative encoding to use to turn str into bytes. If None, the value of encoding is used. Defaults to None.
Returns:

Number of bytes written.

Return type:

int

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

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

The write_termination is always appended to it.

Parameters:
  • message (str) – Header of the message to be sent.
  • values (Sequence[Any]) – Data to be writen to the device.
  • converter (Union[str, Callable[[Any], str]], optional) – Str formatting codes or function used to convert each value. Defaults to “f”.
  • separator (Union[str, Callable[[Iterable[str]], str]], optional) – Str or callable that join the values in a single str. If a str is given, separator.join(values) is used. Defaults to ‘,’
  • termination (Optional[str], optional) – Alternative character termination to use. If None, the value of write_termination is used. Defaults to None.
  • encoding (Optional[str], optional) – Alternative encoding to use to turn str into bytes. If None, the value of encoding is used. Defaults to None.
Returns:

Number of bytes written.

Return type:

int

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

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

The write_termination is always appended to it.

Parameters:
  • message (str) – The header of the message to be sent.
  • values (Sequence[Any]) – Data to be written to the device.
  • datatype (util.BINARY_DATATYPES, optional) – The format string for a single element. See struct module.
  • is_big_endian (bool, optional) – Are the data in big or little endian order.
  • termination (Optional[str], optional) – Alternative character termination to use. If None, the value of write_termination is used. Defaults to None.
  • encoding (Optional[str], optional) – Alternative encoding to use to turn str into bytes. If None, the value of encoding is used. Defaults to None.
  • header_fmt (util.BINARY_HEADERS) – Format of the header prefixing the data.
Returns:

Number of bytes written.

Return type:

int

write_raw(message: bytes) → int

Write a byte message to the device.

Parameters:message (bytes) – The message to be sent.
Returns:Number of bytes written
Return type:int
write_termination

Write termination character.

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

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

More complex resource names can be specified with the following grammar:
USB[board]::manufacturer ID::model code::serial number[::USB interface number]::RAW

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

CR = '\r'
LF = '\n'
allow_dma

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

In some implementations, this attribute may have global effects even though it is documented to be a local attribute. Since this affects performance and not functionality, that behavior is acceptable.
VISA Attribute:VI_ATTR_DMA_ALLOW_EN (1073676318)
Type:bool
assert_trigger() → None

Sends a software trigger to the device.

before_close() → None

Called just before closing an instrument.

chunk_size = 20480
clear() → None

Clear this resource.

close() → None

Closes the VISA session and marks the handle as invalid.

disable_event(event_type: pyvisa.constants.EventType, mechanism: pyvisa.constants.EventMechanism) → None

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

Parameters:
  • event_type (constants.EventType) – Logical event identifier.
  • mechanism (constants.EventMechanism) – Specifies event handling mechanisms to be disabled.
discard_events(event_type: pyvisa.constants.EventType, mechanism: pyvisa.constants.EventMechanism) → None

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

Parameters:
  • event_type (constants.EventType) – Logical event identifier.
  • mechanism (constants.EventMechanism) – Specifies event handling mechanisms to be disabled.
enable_event(event_type: pyvisa.constants.EventType, mechanism: pyvisa.constants.EventMechanism, context: None = None) → None

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

Parameters:
  • event_type (constants.EventType) – Logical event identifier.
  • mechanism (constants.EventMechanism) – Specifies event handling mechanisms to be enabled
  • context (None) – Not currently used, leave as None.
encoding

Encoding used for read and write operations.

flush(mask: pyvisa.constants.BufferOperation) → None

Manually clears the specified buffers.

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

Parameters:mask (constants.BufferOperation) – Specifies the action to be taken with flushing the buffer. See highlevel.VisaLibraryBase.flush for a detailed description.
get_visa_attribute(name: pyvisa.constants.ResourceAttribute) → Any

Retrieves the state of an attribute in this resource.

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

Parameters:name (constants.ResourceAttribute) – Resource attribute for which the state query is made.
Returns:The state of the queried attribute for a specified resource.
Return type:Any
ignore_warning(*warnings_constants) → AbstractContextManager[T_co]

Ignoring warnings context manager for the current resource.

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

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

This attribute value is defined by the individual manufacturer and increments with each new revision. The format of the value has the upper 12 bits as the major number of the version, the next lower 12 bits as the minor number of the version, and the lowest 8 bits as the sub-minor number of the version.
VISA Attribute:VI_ATTR_RSRC_IMPL_VERSION (1073676291)
Type:int
Range:0 <= value <= 4294967295
install_handler(event_type: pyvisa.constants.EventType, handler: Callable[[NewType.<locals>.new_type, pyvisa.constants.EventType, NewType.<locals>.new_type, Any], None], user_handle=None) → Any

Install handlers for event callbacks in this resource.

Parameters:
  • event_type (constants.EventType) – Logical event identifier.
  • handler (VISAHandler) – Handler function to be installed by a client application.
  • user_handle – A value specified by an application that can be used for identifying handlers uniquely for an event type. Depending on the backend they may be restriction on the possible values. Look at the backend install_visa_handler for more details.
Returns:

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

Return type:

Any

interface_number

USB interface number used by the given session. :VISA Attribute: VI_ATTR_USB_INTFC_NUM (1073676705) :type: int :range: 0 <= value <= 254

interface_type

Interface type of the given session. :VISA Attribute: VI_ATTR_INTF_TYPE (1073676657) :type: :class:pyvisa.constants.InterfaceType

io_protocol

IO protocol to use.

In VXI, you can choose normal word serial or fast data channel (FDC). In GPIB, you can choose normal or high-speed (HS-488) transfers. In serial, TCPIP, or USB RAW, you can choose normal transfers or 488.2-defined strings. In USB INSTR, you can choose normal or vendor-specific transfers.
VISA Attribute:VI_ATTR_IO_PROT (1073676316)
Type::class:pyvisa.constants.IOProtocol
last_status

Last status code for this session.

lock(timeout: Union[float, typing_extensions.Literal['default'][default]] = 'default', requested_key: Optional[str] = None) → str

Establish a shared lock to the resource.

Parameters:
  • timeout (Union[float, Literal["default"]], optional) – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. Defaults to “default” which means use self.timeout.
  • requested_key (Optional[str], optional) – Access key used by another session with which you want your session to share a lock or None to generate a new shared access key.
Returns:

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

Return type:

str

lock_context(timeout: Union[float, typing_extensions.Literal['default'][default]] = 'default', requested_key: Optional[str] = 'exclusive') → Iterator[Optional[str]]

A context that locks

Parameters:
  • timeout (Union[float, Literal["default"]], optional) – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. Defaults to “default” which means use self.timeout.
  • requested_key (Optional[str], optional) – When using default of ‘exclusive’ the lock is an exclusive lock. Otherwise it is the access key for the shared lock or None to generate a new shared access key.
Yields:

Optional[str] – The access_key if applicable.

lock_excl(timeout: Union[float, typing_extensions.Literal['default'][default]] = 'default') → None

Establish an exclusive lock to the resource.

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

Current locking state of the resource.

The resource can be unlocked, locked with an exclusive lock, or locked with a shared lock.
VISA Attribute:VI_ATTR_RSRC_LOCK_STATE (1073676292)
Type::class:pyvisa.constants.AccessModes
manufacturer_id

Manufacturer identification number of the device. :VISA Attribute: VI_ATTR_MANF_ID (1073676505) :type: int :range: 0 <= value <= 65535

manufacturer_name

Manufacturer name. :VISA Attribute: VI_ATTR_MANF_NAME (3221160050)

maximum_interrupt_size

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

If a USB interrupt contains more data than this size, the data in excess of this size will be lost.
VISA Attribute:VI_ATTR_USB_MAX_INTR_SIZE (1073676719)
Type:int
Range:0 <= value <= 65535
model_code

Model code for the device. :VISA Attribute: VI_ATTR_MODEL_CODE (1073676511) :type: int :range: 0 <= value <= 65535

model_name

Model name of the device. :VISA Attribute: VI_ATTR_MODEL_NAME (3221160055)

open(access_mode: pyvisa.constants.AccessModes = <AccessModes.no_lock: 0>, open_timeout: int = 5000) → None

Opens a session to the specified resource.

Parameters:
  • access_mode (constants.AccessModes, optional) – Specifies the mode by which the resource is to be accessed. Defaults to constants.AccessModes.no_lock.
  • open_timeout (int, optional) – If the access_mode parameter requests a lock, then this parameter specifies the absolute time period (in milliseconds) that the resource waits to get unlocked before this operation returns an error. Defaults to 5000.
query(message: str, delay: Optional[float] = None) → str

A combination of write(message) and read()

Parameters:
  • message (str) – The message to send.
  • delay (Optional[float], optional) – Delay in seconds between write and read operations. If None, defaults to self.query_delay.
Returns:

Answer from the device.

Return type:

str

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

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

Parameters:
  • message (str) – The message to send.
  • converter (ASCII_CONVERTER, optional) – Str format of function to convert each value. Default to “f”.
  • separator (Union[str, Callable[[str], Iterable[str]]]) – str or callable used to split the data into individual elements. If a str is given, data.split(separator) is used. Default to “,”.
  • container (Union[Type, Callable[[Iterable], Sequence]], optional) – Container type to use for the output data. Possible values are: list, tuple, np.ndarray, etc, Default to list.
  • delay (Optional[float], optional) – Delay in seconds between write and read operations. If None, defaults to self.query_delay.
Returns:

Parsed data.

Return type:

Sequence

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

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

Parameters:
  • message (str) – The message to send.
  • datatype (BINARY_DATATYPES, optional) – Format string for a single element. See struct module. ‘f’ by default.
  • is_big_endian (bool, optional) – Are the data in big or little endian order. Defaults to False.
  • container (Union[Type, Callable[[Iterable], Sequence]], optional) – Container type to use for the output data. Possible values are: list, tuple, np.ndarray, etc, Default to list.
  • delay (Optional[float], optional) – Delay in seconds between write and read operations. If None, defaults to self.query_delay.
  • header_fmt (util.BINARY_HEADERS, optional) – Format of the header prefixing the data. Defaults to ‘ieee’.
  • expect_termination (bool, optional) – When set to False, the expected length of the binary values block does not account for the final termination character (the read termination). Defaults to True.
  • data_points (int, optional) – Number of points expected in the block. This is used only if the instrument does not report it itself. This will be converted in a number of bytes based on the datatype. Defaults to 0.
  • chunk_size (int, optional) – Size of the chunks to read from the device. Using larger chunks may be faster for large amount of data.
Returns:

Data read from the device.

Return type:

Sequence[Union[int, float]]

query_delay = 0.0
read(termination: Optional[str] = None, encoding: Optional[str] = None) → str

Read a string from the device.

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

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

Message read from the instrument and decoded.

Return type:

str

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

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

Parameters:converter (ASCII_CONVERTER, optional) – Str format of function to convert each value. Default to “f”.
separator : Union[str, Callable[[str], Iterable[str]]]
str or callable used to split the data into individual elements. If a str is given, data.split(separator) is used. Default to “,”.
container : Union[Type, Callable[[Iterable], Sequence]], optional
Container type to use for the output data. Possible values are: list, tuple, np.ndarray, etc, Default to list.
Returns:Parsed data.
Return type:Sequence
read_binary_values(datatype: typing_extensions.Literal['s', 'b', 'B', 'h', 'H', 'i', 'I', 'l', 'L', 'q', 'Q', 'f', 'd'][s, b, B, h, H, i, I, l, L, q, Q, f, d] = 'f', is_big_endian: bool = False, container: Union[Type[CT_co], Callable[[Iterable[T_co]], Sequence[T_co]]] = <class 'list'>, header_fmt: typing_extensions.Literal['ieee', 'hp', 'empty'][ieee, hp, empty] = 'ieee', expect_termination: bool = True, data_points: int = 0, chunk_size: Optional[int] = None) → Sequence[Union[int, float]]

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

Parameters:
  • datatype (BINARY_DATATYPES, optional) – Format string for a single element. See struct module. ‘f’ by default.
  • is_big_endian (bool, optional) – Are the data in big or little endian order. Defaults to False.
  • container (Union[Type, Callable[[Iterable], Sequence]], optional) – Container type to use for the output data. Possible values are: list, tuple, np.ndarray, etc, Default to list.
  • header_fmt (util.BINARY_HEADERS, optional) – Format of the header prefixing the data. Defaults to ‘ieee’.
  • expect_termination (bool, optional) – When set to False, the expected length of the binary values block does not account for the final termination character (the read termination). Defaults to True.
  • data_points (int, optional) – Number of points expected in the block. This is used only if the instrument does not report it itself. This will be converted in a number of bytes based on the datatype. Defaults to 0.
  • chunk_size (int, optional) – Size of the chunks to read from the device. Using larger chunks may be faster for large amount of data.
Returns:

Data read from the device.

Return type:

Sequence[Union[int, float]]

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

Read a certain number of bytes from the instrument.

Parameters:
  • count (int) – The number of bytes to read from the instrument.
  • chunk_size (Optional[int], optional) – The chunk size to use to perform the reading. If count > chunk_size multiple low level operations will be performed. Defaults to None, meaning the resource wide set value is set.
  • break_on_termchar (bool, optional) – Should the reading stop when a termination character is encountered or when the message ends. Defaults to False.
Returns:

Bytes read from the instrument.

Return type:

bytes

read_raw(size: Optional[int] = None) → bytes

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

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

Parameters:size (Optional[int], optional) – The chunk size to use to perform the reading. Defaults to None, meaning the resource wide set value is set.
Returns:Bytes read from the instrument.
Return type:bytes
read_stb() → int

Service request status register.

read_termination

Read termination character.

read_termination_context(new_termination: str) → Iterator[T_co]
classmethod register(interface_type: pyvisa.constants.InterfaceType, resource_class: str) → Callable[[Type[T]], Type[T]]

Create a decorator to register a class.

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

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

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

Return type:

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

resource_class

Resource class as defined by the canonical resource name.

Possible values are: INSTR, INTFC, SOCKET, RAW…
VISA Attribute:VI_ATTR_RSRC_CLASS (3221159937)
resource_info

Get the extended information of this resource.

resource_manufacturer_name

Manufacturer name of the vendor that implemented the VISA library.

This attribute is not related to the device manufacturer attributes.

Note The value of this attribute is for display purposes only and not for programmatic decisions, as the value can differ between VISA implementations and/or revisions.

VISA Attribute:VI_ATTR_RSRC_MANF_NAME (3221160308)
resource_name

Unique identifier for a resource compliant with the address structure. :VISA Attribute: VI_ATTR_RSRC_NAME (3221159938)

send_end

Should END be asserted during the transfer of the last byte of the buffer. :VISA Attribute: VI_ATTR_SEND_END_EN (1073676310) :type: bool

serial_number

USB serial number of this device. :VISA Attribute: VI_ATTR_USB_SERIAL_NUM (3221160352)

session

Resource session handle.

Raises:errors.InvalidSession – Raised if session is closed.
set_visa_attribute(name: pyvisa.constants.ResourceAttribute, state: Any) → pyvisa.constants.StatusCode

Set the state of an attribute.

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

Parameters:
  • name (constants.ResourceAttribute) – Attribute for which the state is to be modified.
  • state (Any) – The state of the attribute to be set for the specified object.
Returns:

Return value of the library call.

Return type:

constants.StatusCode

spec_version

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

The format of the value has the upper 12 bits as the major number of the version, the next lower 12 bits as the minor number of the version, and the lowest 8 bits as the sub-minor number of the version. The current VISA specification defines the value to be 00300000h.
VISA Attribute:VI_ATTR_RSRC_SPEC_VERSION (1073676656)
Type:int
Range:0 <= value <= 4294967295
stb

Service request status register.

timeout

Timeout in milliseconds for all resource I/O operations.

This value is used when accessing the device associated with the given session.

Special values:

  • immediate (VI_TMO_IMMEDIATE): 0
    (for convenience, any value smaller than 1 is considered as 0)
  • infinite (VI_TMO_INFINITE): float('+inf')
    (for convenience, None is considered as float('+inf'))

To set an infinite timeout, you can also use:

>>> del instrument.timeout

A timeout value of VI_TMO_IMMEDIATE means that operations should never wait for the device to respond. A timeout value of VI_TMO_INFINITE disables the timeout mechanism.

VISA Attribute:VI_ATTR_TMO_VALUE (1073676314)
Type:int
Range:0 <= value <= 4294967295
uninstall_handler(event_type: pyvisa.constants.EventType, handler: Callable[[NewType.<locals>.new_type, pyvisa.constants.EventType, NewType.<locals>.new_type, Any], None], user_handle=None) → None

Uninstalls handlers for events in this resource.

Parameters:
  • event_type (constants.EventType) – Logical event identifier.
  • handler (VISAHandler) – Handler function to be uninstalled by a client application.
  • user_handle (Any) – The user handle returned by install_handler.
unlock() → None

Relinquishes a lock for the specified resource.

usb_protocol

USB protocol used by this USB interface. :VISA Attribute: VI_ATTR_USB_PROTOCOL (1073676711) :type: int :range: 0 <= value <= 255

visa_attributes_classes = {<class 'pyvisa.attributes.AttrVI_ATTR_RSRC_LOCK_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_TYPE'>, <class 'pyvisa.attributes.AttrVI_ATTR_IO_PROT'>, <class 'pyvisa.attributes.AttrVI_ATTR_USB_CTRL_PIPE'>, <class 'pyvisa.attributes.AttrVI_ATTR_USB_ALT_SETTING'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_INST_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_USB_INTR_IN_STATUS'>, <class 'pyvisa.attributes.AttrVI_ATTR_USB_CLASS'>, <class 'pyvisa.attributes.AttrVI_ATTR_USB_BULK_OUT_STATUS'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_SPEC_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_USER_DATA'>, <class 'pyvisa.attributes.AttrVI_ATTR_TERMCHAR'>, <class 'pyvisa.attributes.AttrVI_ATTR_RD_BUF_SIZE'>, <class 'pyvisa.attributes.AttrVI_ATTR_USB_INTR_IN_PIPE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_IMPL_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_USB_NUM_PIPES'>, <class 'pyvisa.attributes.AttrVI_ATTR_MODEL_CODE'>, <class 'pyvisa.attributes.AttrVI_ATTR_USB_MAX_INTR_SIZE'>, <class 'pyvisa.attributes.AttrVI_ATTR_USB_BULK_IN_PIPE'>, <class 'pyvisa.attributes.AttrVI_ATTR_TMO_VALUE'>, <class 'pyvisa.attributes.AttrVI_ATTR_MAX_QUEUE_LENGTH'>, <class 'pyvisa.attributes.AttrVI_ATTR_TERMCHAR_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_RD_BUF_OPER_MODE'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_WR_BUF_OPER_MODE'>, <class 'pyvisa.attributes.AttrVI_ATTR_WR_BUF_SIZE'>, <class 'pyvisa.attributes.AttrVI_ATTR_USB_NUM_INTFCS'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_DMA_ALLOW_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_MODEL_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_USB_PROTOCOL'>, <class 'pyvisa.attributes.AttrVI_ATTR_USB_BULK_IN_STATUS'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_SEND_END_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_SUPPRESS_END_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_FILE_APPEND_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_USB_SUBCLASS'>, <class 'pyvisa.attributes.AttrVI_ATTR_USB_END_IN'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_CLASS'>, <class 'pyvisa.attributes.AttrVI_ATTR_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_USB_INTFC_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_USB_SERIAL_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_USB_BULK_OUT_PIPE'>}
wait_on_event(in_event_type: pyvisa.constants.EventType, timeout: int, capture_timeout: bool = False) → pyvisa.resources.resource.WaitResponse

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

in_event_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. None means waiting forever if necessary.
capture_timeout : bool, optional
When True will not produce a VisaIOError(VI_ERROR_TMO) but instead return a WaitResponse with timed_out=True.
Returns:Object that contains event_type, context and ret value.
Return type:WaitResponse
wrap_handler(callable: Callable[[Resource, pyvisa.events.Event, Any], None]) → Callable[[NewType.<locals>.new_type, pyvisa.constants.EventType, NewType.<locals>.new_type, Any], None]

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

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

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

write(message: str, termination: Optional[str] = None, encoding: Optional[str] = None) → int

Write a string message to the device.

The write_termination is always appended to it.

Parameters:
  • message (str) – The message to be sent.
  • termination (Optional[str], optional) – Alternative character termination to use. If None, the value of write_termination is used. Defaults to None.
  • encoding (Optional[str], optional) – Alternative encoding to use to turn str into bytes. If None, the value of encoding is used. Defaults to None.
Returns:

Number of bytes written.

Return type:

int

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

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

The write_termination is always appended to it.

Parameters:
  • message (str) – Header of the message to be sent.
  • values (Sequence[Any]) – Data to be writen to the device.
  • converter (Union[str, Callable[[Any], str]], optional) – Str formatting codes or function used to convert each value. Defaults to “f”.
  • separator (Union[str, Callable[[Iterable[str]], str]], optional) – Str or callable that join the values in a single str. If a str is given, separator.join(values) is used. Defaults to ‘,’
  • termination (Optional[str], optional) – Alternative character termination to use. If None, the value of write_termination is used. Defaults to None.
  • encoding (Optional[str], optional) – Alternative encoding to use to turn str into bytes. If None, the value of encoding is used. Defaults to None.
Returns:

Number of bytes written.

Return type:

int

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

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

The write_termination is always appended to it.

Parameters:
  • message (str) – The header of the message to be sent.
  • values (Sequence[Any]) – Data to be written to the device.
  • datatype (util.BINARY_DATATYPES, optional) – The format string for a single element. See struct module.
  • is_big_endian (bool, optional) – Are the data in big or little endian order.
  • termination (Optional[str], optional) – Alternative character termination to use. If None, the value of write_termination is used. Defaults to None.
  • encoding (Optional[str], optional) – Alternative encoding to use to turn str into bytes. If None, the value of encoding is used. Defaults to None.
  • header_fmt (util.BINARY_HEADERS) – Format of the header prefixing the data.
Returns:

Number of bytes written.

Return type:

int

write_raw(message: bytes) → int

Write a byte message to the device.

Parameters:message (bytes) – The message to be sent.
Returns:Number of bytes written
Return type:int
write_termination

Write termination character.

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

Communicates with to devices of type GPIB::<primary address>[::INSTR]

More complex resource names can be specified with the following grammar:
GPIB[board]::primary address[::secondary address][::INSTR]

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

CR = '\r'
LF = '\n'
allow_dma

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

In some implementations, this attribute may have global effects even though it is documented to be a local attribute. Since this affects performance and not functionality, that behavior is acceptable.
VISA Attribute:VI_ATTR_DMA_ALLOW_EN (1073676318)
Type:bool
assert_trigger() → None

Sends a software trigger to the device.

before_close() → None

Called just before closing an instrument.

chunk_size = 20480
clear() → None

Clear this resource.

close() → None

Closes the VISA session and marks the handle as invalid.

control_atn(mode: pyvisa.constants.ATNLineOperation) → pyvisa.constants.StatusCode

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

Corresponds to viGpibControlATN function of the VISA library.

Parameters:mode (constants.ATNLineOperation) –
Specifies the state of the ATN line and optionally the local active
controller state.
Returns:Return value of the library call.
Return type:constants.StatusCode
control_ren(mode: pyvisa.constants.RENLineOperation) → pyvisa.constants.StatusCode

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

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

Corresponds to viGpibControlREN function of the VISA library.

Parameters:mode (constants.RENLineOperation) – Specifies the state of the REN line and optionally the device remote/local state.
Returns:Return value of the library call.
Return type:constants.StatusCode
disable_event(event_type: pyvisa.constants.EventType, mechanism: pyvisa.constants.EventMechanism) → None

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

Parameters:
  • event_type (constants.EventType) – Logical event identifier.
  • mechanism (constants.EventMechanism) – Specifies event handling mechanisms to be disabled.
discard_events(event_type: pyvisa.constants.EventType, mechanism: pyvisa.constants.EventMechanism) → None

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

Parameters:
  • event_type (constants.EventType) – Logical event identifier.
  • mechanism (constants.EventMechanism) – Specifies event handling mechanisms to be disabled.
enable_event(event_type: pyvisa.constants.EventType, mechanism: pyvisa.constants.EventMechanism, context: None = None) → None

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

Parameters:
  • event_type (constants.EventType) – Logical event identifier.
  • mechanism (constants.EventMechanism) – Specifies event handling mechanisms to be enabled
  • context (None) – Not currently used, leave as None.
enable_repeat_addressing

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

enable_unaddressing

Whether to unaddress the device (UNT and UNL) after each read or write operation.

encoding

Encoding used for read and write operations.

flush(mask: pyvisa.constants.BufferOperation) → None

Manually clears the specified buffers.

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

Parameters:mask (constants.BufferOperation) – Specifies the action to be taken with flushing the buffer. See highlevel.VisaLibraryBase.flush for a detailed description.
get_visa_attribute(name: pyvisa.constants.ResourceAttribute) → Any

Retrieves the state of an attribute in this resource.

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

Parameters:name (constants.ResourceAttribute) – Resource attribute for which the state query is made.
Returns:The state of the queried attribute for a specified resource.
Return type:Any
ignore_warning(*warnings_constants) → AbstractContextManager[T_co]

Ignoring warnings context manager for the current resource.

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

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

This attribute value is defined by the individual manufacturer and increments with each new revision. The format of the value has the upper 12 bits as the major number of the version, the next lower 12 bits as the minor number of the version, and the lowest 8 bits as the sub-minor number of the version.
VISA Attribute:VI_ATTR_RSRC_IMPL_VERSION (1073676291)
Type:int
Range:0 <= value <= 4294967295
install_handler(event_type: pyvisa.constants.EventType, handler: Callable[[NewType.<locals>.new_type, pyvisa.constants.EventType, NewType.<locals>.new_type, Any], None], user_handle=None) → Any

Install handlers for event callbacks in this resource.

Parameters:
  • event_type (constants.EventType) – Logical event identifier.
  • handler (VISAHandler) – Handler function to be installed by a client application.
  • user_handle – A value specified by an application that can be used for identifying handlers uniquely for an event type. Depending on the backend they may be restriction on the possible values. Look at the backend install_visa_handler for more details.
Returns:

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

Return type:

Any

interface_number

Board number for the given interface. :VISA Attribute: VI_ATTR_INTF_NUM (1073676662) :type: int :range: 0 <= value <= 65535

interface_type

Interface type of the given session. :VISA Attribute: VI_ATTR_INTF_TYPE (1073676657) :type: :class:pyvisa.constants.InterfaceType

io_protocol

IO protocol to use.

In VXI, you can choose normal word serial or fast data channel (FDC). In GPIB, you can choose normal or high-speed (HS-488) transfers. In serial, TCPIP, or USB RAW, you can choose normal transfers or 488.2-defined strings. In USB INSTR, you can choose normal or vendor-specific transfers.
VISA Attribute:VI_ATTR_IO_PROT (1073676316)
Type::class:pyvisa.constants.IOProtocol
last_status

Last status code for this session.

lock(timeout: Union[float, typing_extensions.Literal['default'][default]] = 'default', requested_key: Optional[str] = None) → str

Establish a shared lock to the resource.

Parameters:
  • timeout (Union[float, Literal["default"]], optional) – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. Defaults to “default” which means use self.timeout.
  • requested_key (Optional[str], optional) – Access key used by another session with which you want your session to share a lock or None to generate a new shared access key.
Returns:

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

Return type:

str

lock_context(timeout: Union[float, typing_extensions.Literal['default'][default]] = 'default', requested_key: Optional[str] = 'exclusive') → Iterator[Optional[str]]

A context that locks

Parameters:
  • timeout (Union[float, Literal["default"]], optional) – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. Defaults to “default” which means use self.timeout.
  • requested_key (Optional[str], optional) – When using default of ‘exclusive’ the lock is an exclusive lock. Otherwise it is the access key for the shared lock or None to generate a new shared access key.
Yields:

Optional[str] – The access_key if applicable.

lock_excl(timeout: Union[float, typing_extensions.Literal['default'][default]] = 'default') → None

Establish an exclusive lock to the resource.

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

Current locking state of the resource.

The resource can be unlocked, locked with an exclusive lock, or locked with a shared lock.
VISA Attribute:VI_ATTR_RSRC_LOCK_STATE (1073676292)
Type::class:pyvisa.constants.AccessModes
open(access_mode: pyvisa.constants.AccessModes = <AccessModes.no_lock: 0>, open_timeout: int = 5000) → None

Opens a session to the specified resource.

Parameters:
  • access_mode (constants.AccessModes, optional) – Specifies the mode by which the resource is to be accessed. Defaults to constants.AccessModes.no_lock.
  • open_timeout (int, optional) – If the access_mode parameter requests a lock, then this parameter specifies the absolute time period (in milliseconds) that the resource waits to get unlocked before this operation returns an error. Defaults to 5000.
pass_control(primary_address: int, secondary_address: int) → pyvisa.constants.StatusCode

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

Corresponds to viGpibPassControl function of the VISA library.

Parameters:
  • primary_address (int) – Primary address of the GPIB device to which you want to pass control.
  • secondary_address (int) – Secondary address of the targeted GPIB device. If the targeted device does not have a secondary address, this parameter should contain the value Constants.NO_SEC_ADDR.
Returns:

Return value of the library call.

Return type:

constants.StatusCode

primary_address

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

For the GPIB INTFC Resource, this attribute is Read-Write.
VISA Attribute:VI_ATTR_GPIB_PRIMARY_ADDR (1073676658)
Type:int
Range:0 <= value <= 30
query(message: str, delay: Optional[float] = None) → str

A combination of write(message) and read()

Parameters:
  • message (str) – The message to send.
  • delay (Optional[float], optional) – Delay in seconds between write and read operations. If None, defaults to self.query_delay.
Returns:

Answer from the device.

Return type:

str

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

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

Parameters:
  • message (str) – The message to send.
  • converter (ASCII_CONVERTER, optional) – Str format of function to convert each value. Default to “f”.
  • separator (Union[str, Callable[[str], Iterable[str]]]) – str or callable used to split the data into individual elements. If a str is given, data.split(separator) is used. Default to “,”.
  • container (Union[Type, Callable[[Iterable], Sequence]], optional) – Container type to use for the output data. Possible values are: list, tuple, np.ndarray, etc, Default to list.
  • delay (Optional[float], optional) – Delay in seconds between write and read operations. If None, defaults to self.query_delay.
Returns:

Parsed data.

Return type:

Sequence

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

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

Parameters:
  • message (str) – The message to send.
  • datatype (BINARY_DATATYPES, optional) – Format string for a single element. See struct module. ‘f’ by default.
  • is_big_endian (bool, optional) – Are the data in big or little endian order. Defaults to False.
  • container (Union[Type, Callable[[Iterable], Sequence]], optional) – Container type to use for the output data. Possible values are: list, tuple, np.ndarray, etc, Default to list.
  • delay (Optional[float], optional) – Delay in seconds between write and read operations. If None, defaults to self.query_delay.
  • header_fmt (util.BINARY_HEADERS, optional) – Format of the header prefixing the data. Defaults to ‘ieee’.
  • expect_termination (bool, optional) – When set to False, the expected length of the binary values block does not account for the final termination character (the read termination). Defaults to True.
  • data_points (int, optional) – Number of points expected in the block. This is used only if the instrument does not report it itself. This will be converted in a number of bytes based on the datatype. Defaults to 0.
  • chunk_size (int, optional) – Size of the chunks to read from the device. Using larger chunks may be faster for large amount of data.
Returns:

Data read from the device.

Return type:

Sequence[Union[int, float]]

query_delay = 0.0
read(termination: Optional[str] = None, encoding: Optional[str] = None) → str

Read a string from the device.

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

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

Message read from the instrument and decoded.

Return type:

str

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

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

Parameters:converter (ASCII_CONVERTER, optional) – Str format of function to convert each value. Default to “f”.
separator : Union[str, Callable[[str], Iterable[str]]]
str or callable used to split the data into individual elements. If a str is given, data.split(separator) is used. Default to “,”.
container : Union[Type, Callable[[Iterable], Sequence]], optional
Container type to use for the output data. Possible values are: list, tuple, np.ndarray, etc, Default to list.
Returns:Parsed data.
Return type:Sequence
read_binary_values(datatype: typing_extensions.Literal['s', 'b', 'B', 'h', 'H', 'i', 'I', 'l', 'L', 'q', 'Q', 'f', 'd'][s, b, B, h, H, i, I, l, L, q, Q, f, d] = 'f', is_big_endian: bool = False, container: Union[Type[CT_co], Callable[[Iterable[T_co]], Sequence[T_co]]] = <class 'list'>, header_fmt: typing_extensions.Literal['ieee', 'hp', 'empty'][ieee, hp, empty] = 'ieee', expect_termination: bool = True, data_points: int = 0, chunk_size: Optional[int] = None) → Sequence[Union[int, float]]

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

Parameters:
  • datatype (BINARY_DATATYPES, optional) – Format string for a single element. See struct module. ‘f’ by default.
  • is_big_endian (bool, optional) – Are the data in big or little endian order. Defaults to False.
  • container (Union[Type, Callable[[Iterable], Sequence]], optional) – Container type to use for the output data. Possible values are: list, tuple, np.ndarray, etc, Default to list.
  • header_fmt (util.BINARY_HEADERS, optional) – Format of the header prefixing the data. Defaults to ‘ieee’.
  • expect_termination (bool, optional) – When set to False, the expected length of the binary values block does not account for the final termination character (the read termination). Defaults to True.
  • data_points (int, optional) – Number of points expected in the block. This is used only if the instrument does not report it itself. This will be converted in a number of bytes based on the datatype. Defaults to 0.
  • chunk_size (int, optional) – Size of the chunks to read from the device. Using larger chunks may be faster for large amount of data.
Returns:

Data read from the device.

Return type:

Sequence[Union[int, float]]

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

Read a certain number of bytes from the instrument.

Parameters:
  • count (int) – The number of bytes to read from the instrument.
  • chunk_size (Optional[int], optional) – The chunk size to use to perform the reading. If count > chunk_size multiple low level operations will be performed. Defaults to None, meaning the resource wide set value is set.
  • break_on_termchar (bool, optional) – Should the reading stop when a termination character is encountered or when the message ends. Defaults to False.
Returns:

Bytes read from the instrument.

Return type:

bytes

read_raw(size: Optional[int] = None) → bytes

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

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

Parameters:size (Optional[int], optional) – The chunk size to use to perform the reading. Defaults to None, meaning the resource wide set value is set.
Returns:Bytes read from the instrument.
Return type:bytes
read_stb() → int

Service request status register.

read_termination

Read termination character.

read_termination_context(new_termination: str) → Iterator[T_co]
classmethod register(interface_type: pyvisa.constants.InterfaceType, resource_class: str) → Callable[[Type[T]], Type[T]]

Create a decorator to register a class.

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

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

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

Return type:

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

remote_enabled

Current state of the GPIB REN (Remote ENable) interface line. :VISA Attribute: VI_ATTR_GPIB_REN_STATE (1073676673) :type: :class:pyvisa.constants.LineState

resource_class

Resource class as defined by the canonical resource name.

Possible values are: INSTR, INTFC, SOCKET, RAW…
VISA Attribute:VI_ATTR_RSRC_CLASS (3221159937)
resource_info

Get the extended information of this resource.

resource_manufacturer_name

Manufacturer name of the vendor that implemented the VISA library.

This attribute is not related to the device manufacturer attributes.

Note The value of this attribute is for display purposes only and not for programmatic decisions, as the value can differ between VISA implementations and/or revisions.

VISA Attribute:VI_ATTR_RSRC_MANF_NAME (3221160308)
resource_name

Unique identifier for a resource compliant with the address structure. :VISA Attribute: VI_ATTR_RSRC_NAME (3221159938)

secondary_address

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

For the GPIB INTFC Resource, this attribute is Read-Write.
VISA Attribute:VI_ATTR_GPIB_SECONDARY_ADDR (1073676659)
Type:int
Range:0 <= value <= 30 or in [65535]
send_command(data: bytes) → Tuple[int, pyvisa.constants.StatusCode]

Write GPIB command bytes on the bus.

Corresponds to viGpibCommand function of the VISA library.

Parameters:data (bytes) – Command to write.
Returns:
  • int – Number of bytes written
  • constants.StatusCode – Return value of the library call.
send_end

Should END be asserted during the transfer of the last byte of the buffer. :VISA Attribute: VI_ATTR_SEND_END_EN (1073676310) :type: bool

send_ifc() → pyvisa.constants.StatusCode

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

Corresponds to viGpibSendIFC function of the VISA library.

session

Resource session handle.

Raises:errors.InvalidSession – Raised if session is closed.
set_visa_attribute(name: pyvisa.constants.ResourceAttribute, state: Any) → pyvisa.constants.StatusCode

Set the state of an attribute.

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

Parameters:
  • name (constants.ResourceAttribute) – Attribute for which the state is to be modified.
  • state (Any) – The state of the attribute to be set for the specified object.
Returns:

Return value of the library call.

Return type:

constants.StatusCode

spec_version

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

The format of the value has the upper 12 bits as the major number of the version, the next lower 12 bits as the minor number of the version, and the lowest 8 bits as the sub-minor number of the version. The current VISA specification defines the value to be 00300000h.
VISA Attribute:VI_ATTR_RSRC_SPEC_VERSION (1073676656)
Type:int
Range:0 <= value <= 4294967295
stb

Service request status register.

timeout

Timeout in milliseconds for all resource I/O operations.

This value is used when accessing the device associated with the given session.

Special values:

  • immediate (VI_TMO_IMMEDIATE): 0
    (for convenience, any value smaller than 1 is considered as 0)
  • infinite (VI_TMO_INFINITE): float('+inf')
    (for convenience, None is considered as float('+inf'))

To set an infinite timeout, you can also use:

>>> del instrument.timeout

A timeout value of VI_TMO_IMMEDIATE means that operations should never wait for the device to respond. A timeout value of VI_TMO_INFINITE disables the timeout mechanism.

VISA Attribute:VI_ATTR_TMO_VALUE (1073676314)
Type:int
Range:0 <= value <= 4294967295
uninstall_handler(event_type: pyvisa.constants.EventType, handler: Callable[[NewType.<locals>.new_type, pyvisa.constants.EventType, NewType.<locals>.new_type, Any], None], user_handle=None) → None

Uninstalls handlers for events in this resource.

Parameters:
  • event_type (constants.EventType) – Logical event identifier.
  • handler (VISAHandler) – Handler function to be uninstalled by a client application.
  • user_handle (Any) – The user handle returned by install_handler.
unlock() → None

Relinquishes a lock for the specified resource.

visa_attributes_classes = {<class 'pyvisa.attributes.AttrVI_ATTR_RSRC_LOCK_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_TRIG_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_TYPE'>, <class 'pyvisa.attributes.AttrVI_ATTR_IO_PROT'>, <class 'pyvisa.attributes.AttrVI_ATTR_GPIB_REN_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_INST_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_SPEC_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_USER_DATA'>, <class 'pyvisa.attributes.AttrVI_ATTR_TERMCHAR'>, <class 'pyvisa.attributes.AttrVI_ATTR_RD_BUF_SIZE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_IMPL_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_TMO_VALUE'>, <class 'pyvisa.attributes.AttrVI_ATTR_MAX_QUEUE_LENGTH'>, <class 'pyvisa.attributes.AttrVI_ATTR_GPIB_SECONDARY_ADDR'>, <class 'pyvisa.attributes.AttrVI_ATTR_TERMCHAR_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_RD_BUF_OPER_MODE'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_WR_BUF_OPER_MODE'>, <class 'pyvisa.attributes.AttrVI_ATTR_WR_BUF_SIZE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_DMA_ALLOW_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_GPIB_READDR_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_SEND_END_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_GPIB_UNADDR_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_GPIB_PRIMARY_ADDR'>, <class 'pyvisa.attributes.AttrVI_ATTR_SUPPRESS_END_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_FILE_APPEND_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_CLASS'>}
wait_for_srq(timeout: int = 25000) → None[source]

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

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

Parameters:timeout (int) – Maximum waiting time in milliseconds. Defaul: 25000 (milliseconds). None means waiting forever if necessary.
wait_on_event(in_event_type: pyvisa.constants.EventType, timeout: int, capture_timeout: bool = False) → pyvisa.resources.resource.WaitResponse

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

in_event_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. None means waiting forever if necessary.
capture_timeout : bool, optional
When True will not produce a VisaIOError(VI_ERROR_TMO) but instead return a WaitResponse with timed_out=True.
Returns:Object that contains event_type, context and ret value.
Return type:WaitResponse
wrap_handler(callable: Callable[[Resource, pyvisa.events.Event, Any], None]) → Callable[[NewType.<locals>.new_type, pyvisa.constants.EventType, NewType.<locals>.new_type, Any], None]

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

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

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

write(message: str, termination: Optional[str] = None, encoding: Optional[str] = None) → int

Write a string message to the device.

The write_termination is always appended to it.

Parameters:
  • message (str) – The message to be sent.
  • termination (Optional[str], optional) – Alternative character termination to use. If None, the value of write_termination is used. Defaults to None.
  • encoding (Optional[str], optional) – Alternative encoding to use to turn str into bytes. If None, the value of encoding is used. Defaults to None.
Returns:

Number of bytes written.

Return type:

int

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

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

The write_termination is always appended to it.

Parameters:
  • message (str) – Header of the message to be sent.
  • values (Sequence[Any]) – Data to be writen to the device.
  • converter (Union[str, Callable[[Any], str]], optional) – Str formatting codes or function used to convert each value. Defaults to “f”.
  • separator (Union[str, Callable[[Iterable[str]], str]], optional) – Str or callable that join the values in a single str. If a str is given, separator.join(values) is used. Defaults to ‘,’
  • termination (Optional[str], optional) – Alternative character termination to use. If None, the value of write_termination is used. Defaults to None.
  • encoding (Optional[str], optional) – Alternative encoding to use to turn str into bytes. If None, the value of encoding is used. Defaults to None.
Returns:

Number of bytes written.

Return type:

int

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

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

The write_termination is always appended to it.

Parameters:
  • message (str) – The header of the message to be sent.
  • values (Sequence[Any]) – Data to be written to the device.
  • datatype (util.BINARY_DATATYPES, optional) – The format string for a single element. See struct module.
  • is_big_endian (bool, optional) – Are the data in big or little endian order.
  • termination (Optional[str], optional) – Alternative character termination to use. If None, the value of write_termination is used. Defaults to None.
  • encoding (Optional[str], optional) – Alternative encoding to use to turn str into bytes. If None, the value of encoding is used. Defaults to None.
  • header_fmt (util.BINARY_HEADERS) – Format of the header prefixing the data.
Returns:

Number of bytes written.

Return type:

int

write_raw(message: bytes) → int

Write a byte message to the device.

Parameters:message (bytes) – The message to be sent.
Returns:Number of bytes written
Return type:int
write_termination

Write termination character.

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

Communicates with to devices of type GPIB::INTFC

More complex resource names can be specified with the following grammar:
GPIB[board]::INTFC

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

CR = '\r'
LF = '\n'
address_state

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

allow_dma

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

In some implementations, this attribute may have global effects even though it is documented to be a local attribute. Since this affects performance and not functionality, that behavior is acceptable.
VISA Attribute:VI_ATTR_DMA_ALLOW_EN (1073676318)
Type:bool
assert_trigger() → None

Sends a software trigger to the device.

atn_state

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

before_close() → None

Called just before closing an instrument.

chunk_size = 20480
clear() → None

Clear this resource.

close() → None

Closes the VISA session and marks the handle as invalid.

control_atn(mode: pyvisa.constants.ATNLineOperation) → pyvisa.constants.StatusCode

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

Corresponds to viGpibControlATN function of the VISA library.

Parameters:mode (constants.ATNLineOperation) –
Specifies the state of the ATN line and optionally the local active
controller state.
Returns:Return value of the library call.
Return type:constants.StatusCode
control_ren(mode: pyvisa.constants.RENLineOperation) → pyvisa.constants.StatusCode

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

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

Corresponds to viGpibControlREN function of the VISA library.

Parameters:mode (constants.RENLineOperation) – Specifies the state of the REN line and optionally the device remote/local state.
Returns:Return value of the library call.
Return type:constants.StatusCode
disable_event(event_type: pyvisa.constants.EventType, mechanism: pyvisa.constants.EventMechanism) → None

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

Parameters:
  • event_type (constants.EventType) – Logical event identifier.
  • mechanism (constants.EventMechanism) – Specifies event handling mechanisms to be disabled.
discard_events(event_type: pyvisa.constants.EventType, mechanism: pyvisa.constants.EventMechanism) → None

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

Parameters:
  • event_type (constants.EventType) – Logical event identifier.
  • mechanism (constants.EventMechanism) – Specifies event handling mechanisms to be disabled.
enable_event(event_type: pyvisa.constants.EventType, mechanism: pyvisa.constants.EventMechanism, context: None = None) → None

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

Parameters:
  • event_type (constants.EventType) – Logical event identifier.
  • mechanism (constants.EventMechanism) – Specifies event handling mechanisms to be enabled
  • context (None) – Not currently used, leave as None.
encoding

Encoding used for read and write operations.

flush(mask: pyvisa.constants.BufferOperation) → None

Manually clears the specified buffers.

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

Parameters:mask (constants.BufferOperation) – Specifies the action to be taken with flushing the buffer. See highlevel.VisaLibraryBase.flush for a detailed description.
get_visa_attribute(name: pyvisa.constants.ResourceAttribute) → Any

Retrieves the state of an attribute in this resource.

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

Parameters:name (constants.ResourceAttribute) – Resource attribute for which the state query is made.
Returns:The state of the queried attribute for a specified resource.
Return type:Any
group_execute_trigger(*resources) → Tuple[int, pyvisa.constants.StatusCode][source]
Parameters:resources (GPIBInstrument) – GPIB resources to which to send the group trigger.
Returns:
  • int – Number of bytes written as part of sending the GPIB commands.
  • constants.StatusCode – Return value of the library call.
ignore_warning(*warnings_constants) → AbstractContextManager[T_co]

Ignoring warnings context manager for the current resource.

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

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

This attribute value is defined by the individual manufacturer and increments with each new revision. The format of the value has the upper 12 bits as the major number of the version, the next lower 12 bits as the minor number of the version, and the lowest 8 bits as the sub-minor number of the version.
VISA Attribute:VI_ATTR_RSRC_IMPL_VERSION (1073676291)
Type:int
Range:0 <= value <= 4294967295
install_handler(event_type: pyvisa.constants.EventType, handler: Callable[[NewType.<locals>.new_type, pyvisa.constants.EventType, NewType.<locals>.new_type, Any], None], user_handle=None) → Any

Install handlers for event callbacks in this resource.

Parameters:
  • event_type (constants.EventType) – Logical event identifier.
  • handler (VISAHandler) – Handler function to be installed by a client application.
  • user_handle – A value specified by an application that can be used for identifying handlers uniquely for an event type. Depending on the backend they may be restriction on the possible values. Look at the backend install_visa_handler for more details.
Returns:

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

Return type:

Any

interface_number

Board number for the given interface. :VISA Attribute: VI_ATTR_INTF_NUM (1073676662) :type: int :range: 0 <= value <= 65535

interface_type

Interface type of the given session. :VISA Attribute: VI_ATTR_INTF_TYPE (1073676657) :type: :class:pyvisa.constants.InterfaceType

io_protocol

IO protocol to use.

In VXI, you can choose normal word serial or fast data channel (FDC). In GPIB, you can choose normal or high-speed (HS-488) transfers. In serial, TCPIP, or USB RAW, you can choose normal transfers or 488.2-defined strings. In USB INSTR, you can choose normal or vendor-specific transfers.
VISA Attribute:VI_ATTR_IO_PROT (1073676316)
Type::class:pyvisa.constants.IOProtocol
is_controller_in_charge

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

is_system_controller

Is the specified GPIB interface currently the system controller.

last_status

Last status code for this session.

lock(timeout: Union[float, typing_extensions.Literal['default'][default]] = 'default', requested_key: Optional[str] = None) → str

Establish a shared lock to the resource.

Parameters:
  • timeout (Union[float, Literal["default"]], optional) – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. Defaults to “default” which means use self.timeout.
  • requested_key (Optional[str], optional) – Access key used by another session with which you want your session to share a lock or None to generate a new shared access key.
Returns:

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

Return type:

str

lock_context(timeout: Union[float, typing_extensions.Literal['default'][default]] = 'default', requested_key: Optional[str] = 'exclusive') → Iterator[Optional[str]]

A context that locks

Parameters:
  • timeout (Union[float, Literal["default"]], optional) – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. Defaults to “default” which means use self.timeout.
  • requested_key (Optional[str], optional) – When using default of ‘exclusive’ the lock is an exclusive lock. Otherwise it is the access key for the shared lock or None to generate a new shared access key.
Yields:

Optional[str] – The access_key if applicable.

lock_excl(timeout: Union[float, typing_extensions.Literal['default'][default]] = 'default') → None

Establish an exclusive lock to the resource.

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

Current locking state of the resource.

The resource can be unlocked, locked with an exclusive lock, or locked with a shared lock.
VISA Attribute:VI_ATTR_RSRC_LOCK_STATE (1073676292)
Type::class:pyvisa.constants.AccessModes
ndac_state

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

open(access_mode: pyvisa.constants.AccessModes = <AccessModes.no_lock: 0>, open_timeout: int = 5000) → None

Opens a session to the specified resource.

Parameters:
  • access_mode (constants.AccessModes, optional) – Specifies the mode by which the resource is to be accessed. Defaults to constants.AccessModes.no_lock.
  • open_timeout (int, optional) – If the access_mode parameter requests a lock, then this parameter specifies the absolute time period (in milliseconds) that the resource waits to get unlocked before this operation returns an error. Defaults to 5000.
pass_control(primary_address: int, secondary_address: int) → pyvisa.constants.StatusCode

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

Corresponds to viGpibPassControl function of the VISA library.

Parameters:
  • primary_address (int) – Primary address of the GPIB device to which you want to pass control.
  • secondary_address (int) – Secondary address of the targeted GPIB device. If the targeted device does not have a secondary address, this parameter should contain the value Constants.NO_SEC_ADDR.
Returns:

Return value of the library call.

Return type:

constants.StatusCode

primary_address

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

For the GPIB INTFC Resource, this attribute is Read-Write.
VISA Attribute:VI_ATTR_GPIB_PRIMARY_ADDR (1073676658)
Type:int
Range:0 <= value <= 30
query(message: str, delay: Optional[float] = None) → str

A combination of write(message) and read()

Parameters:
  • message (str) – The message to send.
  • delay (Optional[float], optional) – Delay in seconds between write and read operations. If None, defaults to self.query_delay.
Returns:

Answer from the device.

Return type:

str

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

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

Parameters:
  • message (str) – The message to send.
  • converter (ASCII_CONVERTER, optional) – Str format of function to convert each value. Default to “f”.
  • separator (Union[str, Callable[[str], Iterable[str]]]) – str or callable used to split the data into individual elements. If a str is given, data.split(separator) is used. Default to “,”.
  • container (Union[Type, Callable[[Iterable], Sequence]], optional) – Container type to use for the output data. Possible values are: list, tuple, np.ndarray, etc, Default to list.
  • delay (Optional[float], optional) – Delay in seconds between write and read operations. If None, defaults to self.query_delay.
Returns:

Parsed data.

Return type:

Sequence

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

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

Parameters:
  • message (str) – The message to send.
  • datatype (BINARY_DATATYPES, optional) – Format string for a single element. See struct module. ‘f’ by default.
  • is_big_endian (bool, optional) – Are the data in big or little endian order. Defaults to False.
  • container (Union[Type, Callable[[Iterable], Sequence]], optional) – Container type to use for the output data. Possible values are: list, tuple, np.ndarray, etc, Default to list.
  • delay (Optional[float], optional) – Delay in seconds between write and read operations. If None, defaults to self.query_delay.
  • header_fmt (util.BINARY_HEADERS, optional) – Format of the header prefixing the data. Defaults to ‘ieee’.
  • expect_termination (bool, optional) – When set to False, the expected length of the binary values block does not account for the final termination character (the read termination). Defaults to True.
  • data_points (int, optional) – Number of points expected in the block. This is used only if the instrument does not report it itself. This will be converted in a number of bytes based on the datatype. Defaults to 0.
  • chunk_size (int, optional) – Size of the chunks to read from the device. Using larger chunks may be faster for large amount of data.
Returns:

Data read from the device.

Return type:

Sequence[Union[int, float]]

query_delay = 0.0
read(termination: Optional[str] = None, encoding: Optional[str] = None) → str

Read a string from the device.

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

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

Message read from the instrument and decoded.

Return type:

str

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

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

Parameters:converter (ASCII_CONVERTER, optional) – Str format of function to convert each value. Default to “f”.
separator : Union[str, Callable[[str], Iterable[str]]]
str or callable used to split the data into individual elements. If a str is given, data.split(separator) is used. Default to “,”.
container : Union[Type, Callable[[Iterable], Sequence]], optional
Container type to use for the output data. Possible values are: list, tuple, np.ndarray, etc, Default to list.
Returns:Parsed data.
Return type:Sequence
read_binary_values(datatype: typing_extensions.Literal['s', 'b', 'B', 'h', 'H', 'i', 'I', 'l', 'L', 'q', 'Q', 'f', 'd'][s, b, B, h, H, i, I, l, L, q, Q, f, d] = 'f', is_big_endian: bool = False, container: Union[Type[CT_co], Callable[[Iterable[T_co]], Sequence[T_co]]] = <class 'list'>, header_fmt: typing_extensions.Literal['ieee', 'hp', 'empty'][ieee, hp, empty] = 'ieee', expect_termination: bool = True, data_points: int = 0, chunk_size: Optional[int] = None) → Sequence[Union[int, float]]

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

Parameters:
  • datatype (BINARY_DATATYPES, optional) – Format string for a single element. See struct module. ‘f’ by default.
  • is_big_endian (bool, optional) – Are the data in big or little endian order. Defaults to False.
  • container (Union[Type, Callable[[Iterable], Sequence]], optional) – Container type to use for the output data. Possible values are: list, tuple, np.ndarray, etc, Default to list.
  • header_fmt (util.BINARY_HEADERS, optional) – Format of the header prefixing the data. Defaults to ‘ieee’.
  • expect_termination (bool, optional) – When set to False, the expected length of the binary values block does not account for the final termination character (the read termination). Defaults to True.
  • data_points (int, optional) – Number of points expected in the block. This is used only if the instrument does not report it itself. This will be converted in a number of bytes based on the datatype. Defaults to 0.
  • chunk_size (int, optional) – Size of the chunks to read from the device. Using larger chunks may be faster for large amount of data.
Returns:

Data read from the device.

Return type:

Sequence[Union[int, float]]

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

Read a certain number of bytes from the instrument.

Parameters:
  • count (int) – The number of bytes to read from the instrument.
  • chunk_size (Optional[int], optional) – The chunk size to use to perform the reading. If count > chunk_size multiple low level operations will be performed. Defaults to None, meaning the resource wide set value is set.
  • break_on_termchar (bool, optional) – Should the reading stop when a termination character is encountered or when the message ends. Defaults to False.
Returns:

Bytes read from the instrument.

Return type:

bytes

read_raw(size: Optional[int] = None) → bytes

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

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

Parameters:size (Optional[int], optional) – The chunk size to use to perform the reading. Defaults to None, meaning the resource wide set value is set.
Returns:Bytes read from the instrument.
Return type:bytes
read_stb() → int

Service request status register.

read_termination

Read termination character.

read_termination_context(new_termination: str) → Iterator[T_co]
classmethod register(interface_type: pyvisa.constants.InterfaceType, resource_class: str) → Callable[[Type[T]], Type[T]]

Create a decorator to register a class.

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

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

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

Return type:

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

remote_enabled

Current state of the GPIB REN (Remote ENable) interface line. :VISA Attribute: VI_ATTR_GPIB_REN_STATE (1073676673) :type: :class:pyvisa.constants.LineState

resource_class

Resource class as defined by the canonical resource name.

Possible values are: INSTR, INTFC, SOCKET, RAW…
VISA Attribute:VI_ATTR_RSRC_CLASS (3221159937)
resource_info

Get the extended information of this resource.

resource_manufacturer_name

Manufacturer name of the vendor that implemented the VISA library.

This attribute is not related to the device manufacturer attributes.

Note The value of this attribute is for display purposes only and not for programmatic decisions, as the value can differ between VISA implementations and/or revisions.

VISA Attribute:VI_ATTR_RSRC_MANF_NAME (3221160308)
resource_name

Unique identifier for a resource compliant with the address structure. :VISA Attribute: VI_ATTR_RSRC_NAME (3221159938)

secondary_address

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

For the GPIB INTFC Resource, this attribute is Read-Write.
VISA Attribute:VI_ATTR_GPIB_SECONDARY_ADDR (1073676659)
Type:int
Range:0 <= value <= 30 or in [65535]
send_command(data: bytes) → Tuple[int, pyvisa.constants.StatusCode]

Write GPIB command bytes on the bus.

Corresponds to viGpibCommand function of the VISA library.

Parameters:data (bytes) – Command to write.
Returns:
  • int – Number of bytes written
  • constants.StatusCode – Return value of the library call.
send_end

Should END be asserted during the transfer of the last byte of the buffer. :VISA Attribute: VI_ATTR_SEND_END_EN (1073676310) :type: bool

send_ifc() → pyvisa.constants.StatusCode

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

Corresponds to viGpibSendIFC function of the VISA library.

session

Resource session handle.

Raises:errors.InvalidSession – Raised if session is closed.
set_visa_attribute(name: pyvisa.constants.ResourceAttribute, state: Any) → pyvisa.constants.StatusCode

Set the state of an attribute.

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

Parameters:
  • name (constants.ResourceAttribute) – Attribute for which the state is to be modified.
  • state (Any) – The state of the attribute to be set for the specified object.
Returns:

Return value of the library call.

Return type:

constants.StatusCode

spec_version

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

The format of the value has the upper 12 bits as the major number of the version, the next lower 12 bits as the minor number of the version, and the lowest 8 bits as the sub-minor number of the version. The current VISA specification defines the value to be 00300000h.
VISA Attribute:VI_ATTR_RSRC_SPEC_VERSION (1073676656)
Type:int
Range:0 <= value <= 4294967295
stb

Service request status register.

timeout

Timeout in milliseconds for all resource I/O operations.

This value is used when accessing the device associated with the given session.

Special values:

  • immediate (VI_TMO_IMMEDIATE): 0
    (for convenience, any value smaller than 1 is considered as 0)
  • infinite (VI_TMO_INFINITE): float('+inf')
    (for convenience, None is considered as float('+inf'))

To set an infinite timeout, you can also use:

>>> del instrument.timeout

A timeout value of VI_TMO_IMMEDIATE means that operations should never wait for the device to respond. A timeout value of VI_TMO_INFINITE disables the timeout mechanism.

VISA Attribute:VI_ATTR_TMO_VALUE (1073676314)
Type:int
Range:0 <= value <= 4294967295
uninstall_handler(event_type: pyvisa.constants.EventType, handler: Callable[[NewType.<locals>.new_type, pyvisa.constants.EventType, NewType.<locals>.new_type, Any], None], user_handle=None) → None

Uninstalls handlers for events in this resource.

Parameters:
  • event_type (constants.EventType) – Logical event identifier.
  • handler (VISAHandler) – Handler function to be uninstalled by a client application.
  • user_handle (Any) – The user handle returned by install_handler.
unlock() → None

Relinquishes a lock for the specified resource.

visa_attributes_classes = {<class 'pyvisa.attributes.AttrVI_ATTR_RSRC_LOCK_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_TRIG_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_TYPE'>, <class 'pyvisa.attributes.AttrVI_ATTR_GPIB_CIC_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_IO_PROT'>, <class 'pyvisa.attributes.AttrVI_ATTR_GPIB_ADDR_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_GPIB_REN_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_INST_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_DEV_STATUS_BYTE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_SPEC_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_USER_DATA'>, <class 'pyvisa.attributes.AttrVI_ATTR_GPIB_SYS_CNTRL_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_TERMCHAR'>, <class 'pyvisa.attributes.AttrVI_ATTR_RD_BUF_SIZE'>, <class 'pyvisa.attributes.AttrVI_ATTR_GPIB_SRQ_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_IMPL_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_TMO_VALUE'>, <class 'pyvisa.attributes.AttrVI_ATTR_GPIB_HS488_CBL_LEN'>, <class 'pyvisa.attributes.AttrVI_ATTR_MAX_QUEUE_LENGTH'>, <class 'pyvisa.attributes.AttrVI_ATTR_GPIB_SECONDARY_ADDR'>, <class 'pyvisa.attributes.AttrVI_ATTR_TERMCHAR_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_RD_BUF_OPER_MODE'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_GPIB_NDAC_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_WR_BUF_OPER_MODE'>, <class 'pyvisa.attributes.AttrVI_ATTR_WR_BUF_SIZE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_DMA_ALLOW_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_SEND_END_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_GPIB_PRIMARY_ADDR'>, <class 'pyvisa.attributes.AttrVI_ATTR_FILE_APPEND_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_GPIB_ATN_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_CLASS'>}
wait_on_event(in_event_type: pyvisa.constants.EventType, timeout: int, capture_timeout: bool = False) → pyvisa.resources.resource.WaitResponse

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

in_event_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. None means waiting forever if necessary.
capture_timeout : bool, optional
When True will not produce a VisaIOError(VI_ERROR_TMO) but instead return a WaitResponse with timed_out=True.
Returns:Object that contains event_type, context and ret value.
Return type:WaitResponse
wrap_handler(callable: Callable[[Resource, pyvisa.events.Event, Any], None]) → Callable[[NewType.<locals>.new_type, pyvisa.constants.EventType, NewType.<locals>.new_type, Any], None]

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

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

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

write(message: str, termination: Optional[str] = None, encoding: Optional[str] = None) → int

Write a string message to the device.

The write_termination is always appended to it.

Parameters:
  • message (str) – The message to be sent.
  • termination (Optional[str], optional) – Alternative character termination to use. If None, the value of write_termination is used. Defaults to None.
  • encoding (Optional[str], optional) – Alternative encoding to use to turn str into bytes. If None, the value of encoding is used. Defaults to None.
Returns:

Number of bytes written.

Return type:

int

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

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

The write_termination is always appended to it.

Parameters:
  • message (str) – Header of the message to be sent.
  • values (Sequence[Any]) – Data to be writen to the device.
  • converter (Union[str, Callable[[Any], str]], optional) – Str formatting codes or function used to convert each value. Defaults to “f”.
  • separator (Union[str, Callable[[Iterable[str]], str]], optional) – Str or callable that join the values in a single str. If a str is given, separator.join(values) is used. Defaults to ‘,’
  • termination (Optional[str], optional) – Alternative character termination to use. If None, the value of write_termination is used. Defaults to None.
  • encoding (Optional[str], optional) – Alternative encoding to use to turn str into bytes. If None, the value of encoding is used. Defaults to None.
Returns:

Number of bytes written.

Return type:

int

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

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

The write_termination is always appended to it.

Parameters:
  • message (str) – The header of the message to be sent.
  • values (Sequence[Any]) – Data to be written to the device.
  • datatype (util.BINARY_DATATYPES, optional) – The format string for a single element. See struct module.
  • is_big_endian (bool, optional) – Are the data in big or little endian order.
  • termination (Optional[str], optional) – Alternative character termination to use. If None, the value of write_termination is used. Defaults to None.
  • encoding (Optional[str], optional) – Alternative encoding to use to turn str into bytes. If None, the value of encoding is used. Defaults to None.
  • header_fmt (util.BINARY_HEADERS) – Format of the header prefixing the data.
Returns:

Number of bytes written.

Return type:

int

write_raw(message: bytes) → int

Write a byte message to the device.

Parameters:message (bytes) – The message to be sent.
Returns:Number of bytes written
Return type:int
write_termination

Write termination character.

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

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

More complex resource names can be specified with the following grammar:
VXI[board]::VXI logical address[::INSTR]

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

before_close() → None

Called just before closing an instrument.

clear() → None

Clear this resource.

close() → None

Closes the VISA session and marks the handle as invalid.

disable_event(event_type: pyvisa.constants.EventType, mechanism: pyvisa.constants.EventMechanism) → None

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

Parameters:
  • event_type (constants.EventType) – Logical event identifier.
  • mechanism (constants.EventMechanism) – Specifies event handling mechanisms to be disabled.
discard_events(event_type: pyvisa.constants.EventType, mechanism: pyvisa.constants.EventMechanism) → None

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

Parameters:
  • event_type (constants.EventType) – Logical event identifier.
  • mechanism (constants.EventMechanism) – Specifies event handling mechanisms to be disabled.
enable_event(event_type: pyvisa.constants.EventType, mechanism: pyvisa.constants.EventMechanism, context: None = None) → None

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

Parameters:
  • event_type (constants.EventType) – Logical event identifier.
  • mechanism (constants.EventMechanism) – Specifies event handling mechanisms to be enabled
  • context (None) – Not currently used, leave as None.
get_visa_attribute(name: pyvisa.constants.ResourceAttribute) → Any

Retrieves the state of an attribute in this resource.

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

Parameters:name (constants.ResourceAttribute) – Resource attribute for which the state query is made.
Returns:The state of the queried attribute for a specified resource.
Return type:Any
ignore_warning(*warnings_constants) → AbstractContextManager[T_co]

Ignoring warnings context manager for the current resource.

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

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

This attribute value is defined by the individual manufacturer and increments with each new revision. The format of the value has the upper 12 bits as the major number of the version, the next lower 12 bits as the minor number of the version, and the lowest 8 bits as the sub-minor number of the version.
VISA Attribute:VI_ATTR_RSRC_IMPL_VERSION (1073676291)
Type:int
Range:0 <= value <= 4294967295
install_handler(event_type: pyvisa.constants.EventType, handler: Callable[[NewType.<locals>.new_type, pyvisa.constants.EventType, NewType.<locals>.new_type, Any], None], user_handle=None) → Any

Install handlers for event callbacks in this resource.

Parameters:
  • event_type (constants.EventType) – Logical event identifier.
  • handler (VISAHandler) – Handler function to be installed by a client application.
  • user_handle – A value specified by an application that can be used for identifying handlers uniquely for an event type. Depending on the backend they may be restriction on the possible values. Look at the backend install_visa_handler for more details.
Returns:

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

Return type:

Any

interface_number

Board number for the given interface. :VISA Attribute: VI_ATTR_INTF_NUM (1073676662) :type: int :range: 0 <= value <= 65535

interface_type

Interface type of the given session. :VISA Attribute: VI_ATTR_INTF_TYPE (1073676657) :type: :class:pyvisa.constants.InterfaceType

last_status

Last status code for this session.

lock(timeout: Union[float, typing_extensions.Literal['default'][default]] = 'default', requested_key: Optional[str] = None) → str

Establish a shared lock to the resource.

Parameters:
  • timeout (Union[float, Literal["default"]], optional) – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. Defaults to “default” which means use self.timeout.
  • requested_key (Optional[str], optional) – Access key used by another session with which you want your session to share a lock or None to generate a new shared access key.
Returns:

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

Return type:

str

lock_context(timeout: Union[float, typing_extensions.Literal['default'][default]] = 'default', requested_key: Optional[str] = 'exclusive') → Iterator[Optional[str]]

A context that locks

Parameters:
  • timeout (Union[float, Literal["default"]], optional) – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. Defaults to “default” which means use self.timeout.
  • requested_key (Optional[str], optional) – When using default of ‘exclusive’ the lock is an exclusive lock. Otherwise it is the access key for the shared lock or None to generate a new shared access key.
Yields:

Optional[str] – The access_key if applicable.

lock_excl(timeout: Union[float, typing_extensions.Literal['default'][default]] = 'default') → None

Establish an exclusive lock to the resource.

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

Current locking state of the resource.

The resource can be unlocked, locked with an exclusive lock, or locked with a shared lock.
VISA Attribute:VI_ATTR_RSRC_LOCK_STATE (1073676292)
Type::class:pyvisa.constants.AccessModes
move_in(space: pyvisa.constants.AddressSpace, offset: int, length: int, width: pyvisa.constants.DataWidth, extended: bool = False) → List[int]

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

Corresponds to viMoveIn* functions of the VISA library.

Parameters:
  • space (constants.AddressSpace) – Address space from which to move the data.
  • offset (int) – Offset (in bytes) of the address or register from which to read.
  • length (int) – Number of elements to transfer, where the data width of the elements to transfer is identical to the source data width.
  • width (Union[Literal[8, 16, 32, 64], constants.DataWidth]) – Number of bits to read per element.
  • extended (bool, optional) – Use 64 bits offset independent of the platform, by default False.
Returns:

  • data (List[int]) – Data read from the bus
  • status_code (constants.StatusCode) – Return value of the library call.

Raises:

ValueError – Raised if an invalid width is specified.

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

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

Corresponds to viMoveOut* functions of the VISA library.

Parameters:
  • space (constants.AddressSpace) – Address space into which move the data.
  • offset (int) – Offset (in bytes) of the address or register from which to read.
  • length (int) – Number of elements to transfer, where the data width of the elements to transfer is identical to the source data width.
  • data (Iterable[int]) – Data to write to bus.
  • width (Union[Literal[8, 16, 32, 64], constants.DataWidth]) – Number of bits to per element.
  • extended (bool, optional) – Use 64 bits offset independent of the platform, by default False.
Returns:

Return value of the library call.

Return type:

constants.StatusCode

Raises:

ValueError – Raised if an invalid width is specified.

open(access_mode: pyvisa.constants.AccessModes = <AccessModes.no_lock: 0>, open_timeout: int = 5000) → None

Opens a session to the specified resource.

Parameters:
  • access_mode (constants.AccessModes, optional) – Specifies the mode by which the resource is to be accessed. Defaults to constants.AccessModes.no_lock.
  • open_timeout (int, optional) – If the access_mode parameter requests a lock, then this parameter specifies the absolute time period (in milliseconds) that the resource waits to get unlocked before this operation returns an error. Defaults to 5000.
read_memory(space: pyvisa.constants.AddressSpace, offset: int, width: pyvisa.constants.DataWidth, extended: bool = False) → int

Read a value from the specified memory space and offset.

Parameters:
  • space (constants.AddressSpace) – Specifies the address space from which to read.
  • offset (int) – Offset (in bytes) of the address or register from which to read.
  • width (Union[Literal[8, 16, 32, 64], constants.DataWidth]) – Number of bits to read (8, 16, 32 or 64).
  • extended (bool, optional) – Use 64 bits offset independent of the platform.
Returns:

data – Data read from memory

Return type:

int

Raises:

ValueError – Raised if an invalid width is specified.

classmethod register(interface_type: pyvisa.constants.InterfaceType, resource_class: str) → Callable[[Type[T]], Type[T]]

Create a decorator to register a class.

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

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

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

Return type:

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

resource_class

Resource class as defined by the canonical resource name.

Possible values are: INSTR, INTFC, SOCKET, RAW…
VISA Attribute:VI_ATTR_RSRC_CLASS (3221159937)
resource_info

Get the extended information of this resource.

resource_manufacturer_name

Manufacturer name of the vendor that implemented the VISA library.

This attribute is not related to the device manufacturer attributes.

Note The value of this attribute is for display purposes only and not for programmatic decisions, as the value can differ between VISA implementations and/or revisions.

VISA Attribute:VI_ATTR_RSRC_MANF_NAME (3221160308)
resource_name

Unique identifier for a resource compliant with the address structure. :VISA Attribute: VI_ATTR_RSRC_NAME (3221159938)

session

Resource session handle.

Raises:errors.InvalidSession – Raised if session is closed.
set_visa_attribute(name: pyvisa.constants.ResourceAttribute, state: Any) → pyvisa.constants.StatusCode

Set the state of an attribute.

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

Parameters:
  • name (constants.ResourceAttribute) – Attribute for which the state is to be modified.
  • state (Any) – The state of the attribute to be set for the specified object.
Returns:

Return value of the library call.

Return type:

constants.StatusCode

spec_version

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

The format of the value has the upper 12 bits as the major number of the version, the next lower 12 bits as the minor number of the version, and the lowest 8 bits as the sub-minor number of the version. The current VISA specification defines the value to be 00300000h.
VISA Attribute:VI_ATTR_RSRC_SPEC_VERSION (1073676656)
Type:int
Range:0 <= value <= 4294967295
timeout

Timeout in milliseconds for all resource I/O operations.

This value is used when accessing the device associated with the given session.

Special values:

  • immediate (VI_TMO_IMMEDIATE): 0
    (for convenience, any value smaller than 1 is considered as 0)
  • infinite (VI_TMO_INFINITE): float('+inf')
    (for convenience, None is considered as float('+inf'))

To set an infinite timeout, you can also use:

>>> del instrument.timeout

A timeout value of VI_TMO_IMMEDIATE means that operations should never wait for the device to respond. A timeout value of VI_TMO_INFINITE disables the timeout mechanism.

VISA Attribute:VI_ATTR_TMO_VALUE (1073676314)
Type:int
Range:0 <= value <= 4294967295
uninstall_handler(event_type: pyvisa.constants.EventType, handler: Callable[[NewType.<locals>.new_type, pyvisa.constants.EventType, NewType.<locals>.new_type, Any], None], user_handle=None) → None

Uninstalls handlers for events in this resource.

Parameters:
  • event_type (constants.EventType) – Logical event identifier.
  • handler (VISAHandler) – Handler function to be uninstalled by a client application.
  • user_handle (Any) – The user handle returned by install_handler.
unlock() → None

Relinquishes a lock for the specified resource.

visa_attributes_classes = {<class 'pyvisa.attributes.AttrVI_ATTR_RSRC_LOCK_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_SPEC_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_TMO_VALUE'>, <class 'pyvisa.attributes.AttrVI_ATTR_MAX_QUEUE_LENGTH'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_TYPE'>, <class 'pyvisa.attributes.AttrVI_ATTR_USER_DATA'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_CLASS'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_IMPL_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_INST_NAME'>}
wait_on_event(in_event_type: pyvisa.constants.EventType, timeout: int, capture_timeout: bool = False) → pyvisa.resources.resource.WaitResponse

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

in_event_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. None means waiting forever if necessary.
capture_timeout : bool, optional
When True will not produce a VisaIOError(VI_ERROR_TMO) but instead return a WaitResponse with timed_out=True.
Returns:Object that contains event_type, context and ret value.
Return type:WaitResponse
wrap_handler(callable: Callable[[Resource, pyvisa.events.Event, Any], None]) → Callable[[NewType.<locals>.new_type, pyvisa.constants.EventType, NewType.<locals>.new_type, Any], None]

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

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

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

write_memory(space: pyvisa.constants.AddressSpace, offset: int, data: int, width: pyvisa.constants.DataWidth, extended: bool = False) → pyvisa.constants.StatusCode

Write a value to the specified memory space and offset.

Parameters:
  • space (constants.AddressSpace) – Specifies the address space.
  • offset (int) – Offset (in bytes) of the address or register from which to read.
  • data (int) – Data to write to bus.
  • width (Union[Literal[8, 16, 32, 64], constants.DataWidth]) – Number of bits to read.
  • extended (bool, optional) – Use 64 bits offset independent of the platform, by default False.
Returns:

Return value of the library call.

Return type:

constants.StatusCode

Raises:

ValueError – Raised if an invalid width is specified.

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

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

More complex resource names can be specified with the following grammar:
PXI[bus]::device[::function][::INSTR]
or:
PXI[interface]::bus-device[.function][::INSTR]
or:
PXI[interface]::CHASSISchassis number::SLOTslot number[::FUNCfunction][::INSTR]

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

allow_dma

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

In some implementations, this attribute may have global effects even though it is documented to be a local attribute. Since this affects performance and not functionality, that behavior is acceptable.
VISA Attribute:VI_ATTR_DMA_ALLOW_EN (1073676318)
Type:bool
before_close() → None

Called just before closing an instrument.

clear() → None

Clear this resource.

close() → None

Closes the VISA session and marks the handle as invalid.

destination_increment

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

The default value of this attribute is 1 (that is, the destination address will be incremented by 1 after each transfer), and the viMoveOutXX() operations move into consecutive elements. If this attribute is set to 0, the viMoveOutXX() operations will always write to the same element, essentially treating the destination as a FIFO register.
VISA Attribute:VI_ATTR_DEST_INCREMENT (1073676353)
Type:int
Range:0 <= value <= 1
disable_event(event_type: pyvisa.constants.EventType, mechanism: pyvisa.constants.EventMechanism) → None

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

Parameters:
  • event_type (constants.EventType) – Logical event identifier.
  • mechanism (constants.EventMechanism) – Specifies event handling mechanisms to be disabled.
discard_events(event_type: pyvisa.constants.EventType, mechanism: pyvisa.constants.EventMechanism) → None

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

Parameters:
  • event_type (constants.EventType) – Logical event identifier.
  • mechanism (constants.EventMechanism) – Specifies event handling mechanisms to be disabled.
enable_event(event_type: pyvisa.constants.EventType, mechanism: pyvisa.constants.EventMechanism, context: None = None) → None

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

Parameters:
  • event_type (constants.EventType) – Logical event identifier.
  • mechanism (constants.EventMechanism) – Specifies event handling mechanisms to be enabled
  • context (None) – Not currently used, leave as None.
get_visa_attribute(name: pyvisa.constants.ResourceAttribute) → Any

Retrieves the state of an attribute in this resource.

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

Parameters:name (constants.ResourceAttribute) – Resource attribute for which the state query is made.
Returns:The state of the queried attribute for a specified resource.
Return type:Any
ignore_warning(*warnings_constants) → AbstractContextManager[T_co]

Ignoring warnings context manager for the current resource.

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

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

This attribute value is defined by the individual manufacturer and increments with each new revision. The format of the value has the upper 12 bits as the major number of the version, the next lower 12 bits as the minor number of the version, and the lowest 8 bits as the sub-minor number of the version.
VISA Attribute:VI_ATTR_RSRC_IMPL_VERSION (1073676291)
Type:int
Range:0 <= value <= 4294967295
install_handler(event_type: pyvisa.constants.EventType, handler: Callable[[NewType.<locals>.new_type, pyvisa.constants.EventType, NewType.<locals>.new_type, Any], None], user_handle=None) → Any

Install handlers for event callbacks in this resource.

Parameters:
  • event_type (constants.EventType) – Logical event identifier.
  • handler (VISAHandler) – Handler function to be installed by a client application.
  • user_handle – A value specified by an application that can be used for identifying handlers uniquely for an event type. Depending on the backend they may be restriction on the possible values. Look at the backend install_visa_handler for more details.
Returns:

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

Return type:

Any

interface_number

Board number for the given interface. :VISA Attribute: VI_ATTR_INTF_NUM (1073676662) :type: int :range: 0 <= value <= 65535

interface_type

Interface type of the given session. :VISA Attribute: VI_ATTR_INTF_TYPE (1073676657) :type: :class:pyvisa.constants.InterfaceType

last_status

Last status code for this session.

lock(timeout: Union[float, typing_extensions.Literal['default'][default]] = 'default', requested_key: Optional[str] = None) → str

Establish a shared lock to the resource.

Parameters:
  • timeout (Union[float, Literal["default"]], optional) – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. Defaults to “default” which means use self.timeout.
  • requested_key (Optional[str], optional) – Access key used by another session with which you want your session to share a lock or None to generate a new shared access key.
Returns:

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

Return type:

str

lock_context(timeout: Union[float, typing_extensions.Literal['default'][default]] = 'default', requested_key: Optional[str] = 'exclusive') → Iterator[Optional[str]]

A context that locks

Parameters:
  • timeout (Union[float, Literal["default"]], optional) – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. Defaults to “default” which means use self.timeout.
  • requested_key (Optional[str], optional) – When using default of ‘exclusive’ the lock is an exclusive lock. Otherwise it is the access key for the shared lock or None to generate a new shared access key.
Yields:

Optional[str] – The access_key if applicable.

lock_excl(timeout: Union[float, typing_extensions.Literal['default'][default]] = 'default') → None

Establish an exclusive lock to the resource.

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

Current locking state of the resource.

The resource can be unlocked, locked with an exclusive lock, or locked with a shared lock.
VISA Attribute:VI_ATTR_RSRC_LOCK_STATE (1073676292)
Type::class:pyvisa.constants.AccessModes
manufacturer_id

Manufacturer identification number of the device.

manufacturer_name

Manufacturer name.

model_code

Model code for the device.

model_name

Model name of the device.

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

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

Corresponds to viMoveIn* functions of the VISA library.

Parameters:
  • space (constants.AddressSpace) – Address space from which to move the data.
  • offset (int) – Offset (in bytes) of the address or register from which to read.
  • length (int) – Number of elements to transfer, where the data width of the elements to transfer is identical to the source data width.
  • width (Union[Literal[8, 16, 32, 64], constants.DataWidth]) – Number of bits to read per element.
  • extended (bool, optional) – Use 64 bits offset independent of the platform, by default False.
Returns:

  • data (List[int]) – Data read from the bus
  • status_code (constants.StatusCode) – Return value of the library call.

Raises:

ValueError – Raised if an invalid width is specified.

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

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

Corresponds to viMoveOut* functions of the VISA library.

Parameters:
  • space (constants.AddressSpace) – Address space into which move the data.
  • offset (int) – Offset (in bytes) of the address or register from which to read.
  • length (int) – Number of elements to transfer, where the data width of the elements to transfer is identical to the source data width.
  • data (Iterable[int]) – Data to write to bus.
  • width (Union[Literal[8, 16, 32, 64], constants.DataWidth]) – Number of bits to per element.
  • extended (bool, optional) – Use 64 bits offset independent of the platform, by default False.
Returns:

Return value of the library call.

Return type:

constants.StatusCode

Raises:

ValueError – Raised if an invalid width is specified.

open(access_mode: pyvisa.constants.AccessModes = <AccessModes.no_lock: 0>, open_timeout: int = 5000) → None

Opens a session to the specified resource.

Parameters:
  • access_mode (constants.AccessModes, optional) – Specifies the mode by which the resource is to be accessed. Defaults to constants.AccessModes.no_lock.
  • open_timeout (int, optional) – If the access_mode parameter requests a lock, then this parameter specifies the absolute time period (in milliseconds) that the resource waits to get unlocked before this operation returns an error. Defaults to 5000.
read_memory(space: pyvisa.constants.AddressSpace, offset: int, width: pyvisa.constants.DataWidth, extended: bool = False) → int

Read a value from the specified memory space and offset.

Parameters:
  • space (constants.AddressSpace) – Specifies the address space from which to read.
  • offset (int) – Offset (in bytes) of the address or register from which to read.
  • width (Union[Literal[8, 16, 32, 64], constants.DataWidth]) – Number of bits to read (8, 16, 32 or 64).
  • extended (bool, optional) – Use 64 bits offset independent of the platform.
Returns:

data – Data read from memory

Return type:

int

Raises:

ValueError – Raised if an invalid width is specified.

classmethod register(interface_type: pyvisa.constants.InterfaceType, resource_class: str) → Callable[[Type[T]], Type[T]]

Create a decorator to register a class.

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

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

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

Return type:

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

resource_class

Resource class as defined by the canonical resource name.

Possible values are: INSTR, INTFC, SOCKET, RAW…
VISA Attribute:VI_ATTR_RSRC_CLASS (3221159937)
resource_info

Get the extended information of this resource.

resource_manufacturer_name

Manufacturer name of the vendor that implemented the VISA library.

This attribute is not related to the device manufacturer attributes.

Note The value of this attribute is for display purposes only and not for programmatic decisions, as the value can differ between VISA implementations and/or revisions.

VISA Attribute:VI_ATTR_RSRC_MANF_NAME (3221160308)
resource_name

Unique identifier for a resource compliant with the address structure. :VISA Attribute: VI_ATTR_RSRC_NAME (3221159938)

session

Resource session handle.

Raises:errors.InvalidSession – Raised if session is closed.
set_visa_attribute(name: pyvisa.constants.ResourceAttribute, state: Any) → pyvisa.constants.StatusCode

Set the state of an attribute.

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

Parameters:
  • name (constants.ResourceAttribute) – Attribute for which the state is to be modified.
  • state (Any) – The state of the attribute to be set for the specified object.
Returns:

Return value of the library call.

Return type:

constants.StatusCode

source_increment

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

The default value of this attribute is 1 (that is, the source address will be incremented by 1 after each transfer), and the viMoveInXX() operations move from consecutive elements. If this attribute is set to 0, the viMoveInXX() operations will always read from the same element, essentially treating the source as a FIFO register.
VISA Attribute:VI_ATTR_SRC_INCREMENT (1073676352)
Type:int
Range:0 <= value <= 1
spec_version

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

The format of the value has the upper 12 bits as the major number of the version, the next lower 12 bits as the minor number of the version, and the lowest 8 bits as the sub-minor number of the version. The current VISA specification defines the value to be 00300000h.
VISA Attribute:VI_ATTR_RSRC_SPEC_VERSION (1073676656)
Type:int
Range:0 <= value <= 4294967295
timeout

Timeout in milliseconds for all resource I/O operations.

This value is used when accessing the device associated with the given session.

Special values:

  • immediate (VI_TMO_IMMEDIATE): 0
    (for convenience, any value smaller than 1 is considered as 0)
  • infinite (VI_TMO_INFINITE): float('+inf')
    (for convenience, None is considered as float('+inf'))

To set an infinite timeout, you can also use:

>>> del instrument.timeout

A timeout value of VI_TMO_IMMEDIATE means that operations should never wait for the device to respond. A timeout value of VI_TMO_INFINITE disables the timeout mechanism.

VISA Attribute:VI_ATTR_TMO_VALUE (1073676314)
Type:int
Range:0 <= value <= 4294967295
uninstall_handler(event_type: pyvisa.constants.EventType, handler: Callable[[NewType.<locals>.new_type, pyvisa.constants.EventType, NewType.<locals>.new_type, Any], None], user_handle=None) → None

Uninstalls handlers for events in this resource.

Parameters:
  • event_type (constants.EventType) – Logical event identifier.
  • handler (VISAHandler) – Handler function to be uninstalled by a client application.
  • user_handle (Any) – The user handle returned by install_handler.
unlock() → None

Relinquishes a lock for the specified resource.

visa_attributes_classes = {<class 'pyvisa.attributes.AttrVI_ATTR_RSRC_LOCK_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_PXI_MEM_BASE_BAR2'>, <class 'pyvisa.attributes.AttrVI_ATTR_PXI_DSTAR_BUS'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_PXI_DSTAR_SET'>, <class 'pyvisa.attributes.AttrVI_ATTR_TRIG_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_TYPE'>, <class 'pyvisa.attributes.AttrVI_ATTR_PXI_MEM_SIZE_BAR1'>, <class 'pyvisa.attributes.AttrVI_ATTR_DEST_INCREMENT'>, <class 'pyvisa.attributes.AttrVI_ATTR_PXI_MEM_TYPE_BAR1'>, <class 'pyvisa.attributes.AttrVI_ATTR_PXI_SLOTPATH'>, <class 'pyvisa.attributes.AttrVI_ATTR_PXI_DEV_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_INST_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_WIN_BASE_ADDR'>, <class 'pyvisa.attributes.AttrVI_ATTR_PXI_MEM_SIZE_BAR4'>, <class 'pyvisa.attributes.AttrVI_ATTR_PXI_MEM_BASE_BAR0'>, <class 'pyvisa.attributes.AttrVI_ATTR_PXI_ACTUAL_LWIDTH'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_SPEC_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_PXI_IS_EXPRESS'>, <class 'pyvisa.attributes.AttrVI_ATTR_PXI_STAR_TRIG_LINE'>, <class 'pyvisa.attributes.AttrVI_ATTR_PXI_MEM_TYPE_BAR4'>, <class 'pyvisa.attributes.AttrVI_ATTR_USER_DATA'>, <class 'pyvisa.attributes.AttrVI_ATTR_PXI_MEM_BASE_BAR3'>, <class 'pyvisa.attributes.AttrVI_ATTR_PXI_CHASSIS'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_IMPL_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_MODEL_CODE'>, <class 'pyvisa.attributes.AttrVI_ATTR_WIN_ACCESS'>, <class 'pyvisa.attributes.AttrVI_ATTR_PXI_MEM_SIZE_BAR2'>, <class 'pyvisa.attributes.AttrVI_ATTR_PXI_FUNC_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_PXI_SLOT_LWIDTH'>, <class 'pyvisa.attributes.AttrVI_ATTR_PXI_MAX_LWIDTH'>, <class 'pyvisa.attributes.AttrVI_ATTR_PXI_SLOT_LBUS_RIGHT'>, <class 'pyvisa.attributes.AttrVI_ATTR_TMO_VALUE'>, <class 'pyvisa.attributes.AttrVI_ATTR_PXI_STAR_TRIG_BUS'>, <class 'pyvisa.attributes.AttrVI_ATTR_PXI_MEM_TYPE_BAR2'>, <class 'pyvisa.attributes.AttrVI_ATTR_MAX_QUEUE_LENGTH'>, <class 'pyvisa.attributes.AttrVI_ATTR_PXI_MEM_BASE_BAR1'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_PXI_BUS_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_PXI_MEM_SIZE_BAR0'>, <class 'pyvisa.attributes.AttrVI_ATTR_DMA_ALLOW_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_MODEL_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_SRC_INCREMENT'>, <class 'pyvisa.attributes.AttrVI_ATTR_SLOT'>, <class 'pyvisa.attributes.AttrVI_ATTR_PXI_MEM_BASE_BAR4'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_PXI_TRIG_BUS'>, <class 'pyvisa.attributes.AttrVI_ATTR_PXI_MEM_TYPE_BAR0'>, <class 'pyvisa.attributes.AttrVI_ATTR_PXI_MEM_SIZE_BAR3'>, <class 'pyvisa.attributes.AttrVI_ATTR_PXI_MEM_TYPE_BAR3'>, <class 'pyvisa.attributes.AttrVI_ATTR_PXI_SLOT_LBUS_LEFT'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_CLASS'>, <class 'pyvisa.attributes.AttrVI_ATTR_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_WIN_SIZE'>}
wait_on_event(in_event_type: pyvisa.constants.EventType, timeout: int, capture_timeout: bool = False) → pyvisa.resources.resource.WaitResponse

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

in_event_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. None means waiting forever if necessary.
capture_timeout : bool, optional
When True will not produce a VisaIOError(VI_ERROR_TMO) but instead return a WaitResponse with timed_out=True.
Returns:Object that contains event_type, context and ret value.
Return type:WaitResponse
wrap_handler(callable: Callable[[Resource, pyvisa.events.Event, Any], None]) → Callable[[NewType.<locals>.new_type, pyvisa.constants.EventType, NewType.<locals>.new_type, Any], None]

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

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

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

write_memory(space: pyvisa.constants.AddressSpace, offset: int, data: int, width: pyvisa.constants.DataWidth, extended: bool = False) → pyvisa.constants.StatusCode

Write a value to the specified memory space and offset.

Parameters:
  • space (constants.AddressSpace) – Specifies the address space.
  • offset (int) – Offset (in bytes) of the address or register from which to read.
  • data (int) – Data to write to bus.
  • width (Union[Literal[8, 16, 32, 64], constants.DataWidth]) – Number of bits to read.
  • extended (bool, optional) – Use 64 bits offset independent of the platform, by default False.
Returns:

Return value of the library call.

Return type:

constants.StatusCode

Raises:

ValueError – Raised if an invalid width is specified.

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

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

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

allow_dma

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

In some implementations, this attribute may have global effects even though it is documented to be a local attribute. Since this affects performance and not functionality, that behavior is acceptable.
VISA Attribute:VI_ATTR_DMA_ALLOW_EN (1073676318)
Type:bool
before_close() → None

Called just before closing an instrument.

clear() → None

Clear this resource.

close() → None

Closes the VISA session and marks the handle as invalid.

destination_increment

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

The default value of this attribute is 1 (that is, the destination address will be incremented by 1 after each transfer), and the viMoveOutXX() operations move into consecutive elements. If this attribute is set to 0, the viMoveOutXX() operations will always write to the same element, essentially treating the destination as a FIFO register.
VISA Attribute:VI_ATTR_DEST_INCREMENT (1073676353)
Type:int
Range:0 <= value <= 1
disable_event(event_type: pyvisa.constants.EventType, mechanism: pyvisa.constants.EventMechanism) → None

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

Parameters:
  • event_type (constants.EventType) – Logical event identifier.
  • mechanism (constants.EventMechanism) – Specifies event handling mechanisms to be disabled.
discard_events(event_type: pyvisa.constants.EventType, mechanism: pyvisa.constants.EventMechanism) → None

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

Parameters:
  • event_type (constants.EventType) – Logical event identifier.
  • mechanism (constants.EventMechanism) – Specifies event handling mechanisms to be disabled.
enable_event(event_type: pyvisa.constants.EventType, mechanism: pyvisa.constants.EventMechanism, context: None = None) → None

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

Parameters:
  • event_type (constants.EventType) – Logical event identifier.
  • mechanism (constants.EventMechanism) – Specifies event handling mechanisms to be enabled
  • context (None) – Not currently used, leave as None.
get_visa_attribute(name: pyvisa.constants.ResourceAttribute) → Any

Retrieves the state of an attribute in this resource.

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

Parameters:name (constants.ResourceAttribute) – Resource attribute for which the state query is made.
Returns:The state of the queried attribute for a specified resource.
Return type:Any
ignore_warning(*warnings_constants) → AbstractContextManager[T_co]

Ignoring warnings context manager for the current resource.

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

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

This attribute value is defined by the individual manufacturer and increments with each new revision. The format of the value has the upper 12 bits as the major number of the version, the next lower 12 bits as the minor number of the version, and the lowest 8 bits as the sub-minor number of the version.
VISA Attribute:VI_ATTR_RSRC_IMPL_VERSION (1073676291)
Type:int
Range:0 <= value <= 4294967295
install_handler(event_type: pyvisa.constants.EventType, handler: Callable[[NewType.<locals>.new_type, pyvisa.constants.EventType, NewType.<locals>.new_type, Any], None], user_handle=None) → Any

Install handlers for event callbacks in this resource.

Parameters:
  • event_type (constants.EventType) – Logical event identifier.
  • handler (VISAHandler) – Handler function to be installed by a client application.
  • user_handle – A value specified by an application that can be used for identifying handlers uniquely for an event type. Depending on the backend they may be restriction on the possible values. Look at the backend install_visa_handler for more details.
Returns:

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

Return type:

Any

interface_number

Board number for the given interface. :VISA Attribute: VI_ATTR_INTF_NUM (1073676662) :type: int :range: 0 <= value <= 65535

interface_type

Interface type of the given session. :VISA Attribute: VI_ATTR_INTF_TYPE (1073676657) :type: :class:pyvisa.constants.InterfaceType

last_status

Last status code for this session.

lock(timeout: Union[float, typing_extensions.Literal['default'][default]] = 'default', requested_key: Optional[str] = None) → str

Establish a shared lock to the resource.

Parameters:
  • timeout (Union[float, Literal["default"]], optional) – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. Defaults to “default” which means use self.timeout.
  • requested_key (Optional[str], optional) – Access key used by another session with which you want your session to share a lock or None to generate a new shared access key.
Returns:

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

Return type:

str

lock_context(timeout: Union[float, typing_extensions.Literal['default'][default]] = 'default', requested_key: Optional[str] = 'exclusive') → Iterator[Optional[str]]

A context that locks

Parameters:
  • timeout (Union[float, Literal["default"]], optional) – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. Defaults to “default” which means use self.timeout.
  • requested_key (Optional[str], optional) – When using default of ‘exclusive’ the lock is an exclusive lock. Otherwise it is the access key for the shared lock or None to generate a new shared access key.
Yields:

Optional[str] – The access_key if applicable.

lock_excl(timeout: Union[float, typing_extensions.Literal['default'][default]] = 'default') → None

Establish an exclusive lock to the resource.

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

Current locking state of the resource.

The resource can be unlocked, locked with an exclusive lock, or locked with a shared lock.
VISA Attribute:VI_ATTR_RSRC_LOCK_STATE (1073676292)
Type::class:pyvisa.constants.AccessModes
move_in(space: pyvisa.constants.AddressSpace, offset: int, length: int, width: pyvisa.constants.DataWidth, extended: bool = False) → List[int]

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

Corresponds to viMoveIn* functions of the VISA library.

Parameters:
  • space (constants.AddressSpace) – Address space from which to move the data.
  • offset (int) – Offset (in bytes) of the address or register from which to read.
  • length (int) – Number of elements to transfer, where the data width of the elements to transfer is identical to the source data width.
  • width (Union[Literal[8, 16, 32, 64], constants.DataWidth]) – Number of bits to read per element.
  • extended (bool, optional) – Use 64 bits offset independent of the platform, by default False.
Returns:

  • data (List[int]) – Data read from the bus
  • status_code (constants.StatusCode) – Return value of the library call.

Raises:

ValueError – Raised if an invalid width is specified.

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

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

Corresponds to viMoveOut* functions of the VISA library.

Parameters:
  • space (constants.AddressSpace) – Address space into which move the data.
  • offset (int) – Offset (in bytes) of the address or register from which to read.
  • length (int) – Number of elements to transfer, where the data width of the elements to transfer is identical to the source data width.
  • data (Iterable[int]) – Data to write to bus.
  • width (Union[Literal[8, 16, 32, 64], constants.DataWidth]) – Number of bits to per element.
  • extended (bool, optional) – Use 64 bits offset independent of the platform, by default False.
Returns:

Return value of the library call.

Return type:

constants.StatusCode

Raises:

ValueError – Raised if an invalid width is specified.

open(access_mode: pyvisa.constants.AccessModes = <AccessModes.no_lock: 0>, open_timeout: int = 5000) → None

Opens a session to the specified resource.

Parameters:
  • access_mode (constants.AccessModes, optional) – Specifies the mode by which the resource is to be accessed. Defaults to constants.AccessModes.no_lock.
  • open_timeout (int, optional) – If the access_mode parameter requests a lock, then this parameter specifies the absolute time period (in milliseconds) that the resource waits to get unlocked before this operation returns an error. Defaults to 5000.
read_memory(space: pyvisa.constants.AddressSpace, offset: int, width: pyvisa.constants.DataWidth, extended: bool = False) → int

Read a value from the specified memory space and offset.

Parameters:
  • space (constants.AddressSpace) – Specifies the address space from which to read.
  • offset (int) – Offset (in bytes) of the address or register from which to read.
  • width (Union[Literal[8, 16, 32, 64], constants.DataWidth]) – Number of bits to read (8, 16, 32 or 64).
  • extended (bool, optional) – Use 64 bits offset independent of the platform.
Returns:

data – Data read from memory

Return type:

int

Raises:

ValueError – Raised if an invalid width is specified.

classmethod register(interface_type: pyvisa.constants.InterfaceType, resource_class: str) → Callable[[Type[T]], Type[T]]

Create a decorator to register a class.

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

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

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

Return type:

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

resource_class

Resource class as defined by the canonical resource name.

Possible values are: INSTR, INTFC, SOCKET, RAW…
VISA Attribute:VI_ATTR_RSRC_CLASS (3221159937)
resource_info

Get the extended information of this resource.

resource_manufacturer_name

Manufacturer name of the vendor that implemented the VISA library.

This attribute is not related to the device manufacturer attributes.

Note The value of this attribute is for display purposes only and not for programmatic decisions, as the value can differ between VISA implementations and/or revisions.

VISA Attribute:VI_ATTR_RSRC_MANF_NAME (3221160308)
resource_name

Unique identifier for a resource compliant with the address structure. :VISA Attribute: VI_ATTR_RSRC_NAME (3221159938)

session

Resource session handle.

Raises:errors.InvalidSession – Raised if session is closed.
set_visa_attribute(name: pyvisa.constants.ResourceAttribute, state: Any) → pyvisa.constants.StatusCode

Set the state of an attribute.

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

Parameters:
  • name (constants.ResourceAttribute) – Attribute for which the state is to be modified.
  • state (Any) – The state of the attribute to be set for the specified object.
Returns:

Return value of the library call.

Return type:

constants.StatusCode

source_increment

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

The default value of this attribute is 1 (that is, the source address will be incremented by 1 after each transfer), and the viMoveInXX() operations move from consecutive elements. If this attribute is set to 0, the viMoveInXX() operations will always read from the same element, essentially treating the source as a FIFO register.
VISA Attribute:VI_ATTR_SRC_INCREMENT (1073676352)
Type:int
Range:0 <= value <= 1
spec_version

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

The format of the value has the upper 12 bits as the major number of the version, the next lower 12 bits as the minor number of the version, and the lowest 8 bits as the sub-minor number of the version. The current VISA specification defines the value to be 00300000h.
VISA Attribute:VI_ATTR_RSRC_SPEC_VERSION (1073676656)
Type:int
Range:0 <= value <= 4294967295
timeout

Timeout in milliseconds for all resource I/O operations.

This value is used when accessing the device associated with the given session.

Special values:

  • immediate (VI_TMO_IMMEDIATE): 0
    (for convenience, any value smaller than 1 is considered as 0)
  • infinite (VI_TMO_INFINITE): float('+inf')
    (for convenience, None is considered as float('+inf'))

To set an infinite timeout, you can also use:

>>> del instrument.timeout

A timeout value of VI_TMO_IMMEDIATE means that operations should never wait for the device to respond. A timeout value of VI_TMO_INFINITE disables the timeout mechanism.

VISA Attribute:VI_ATTR_TMO_VALUE (1073676314)
Type:int
Range:0 <= value <= 4294967295
uninstall_handler(event_type: pyvisa.constants.EventType, handler: Callable[[NewType.<locals>.new_type, pyvisa.constants.EventType, NewType.<locals>.new_type, Any], None], user_handle=None) → None

Uninstalls handlers for events in this resource.

Parameters:
  • event_type (constants.EventType) – Logical event identifier.
  • handler (VISAHandler) – Handler function to be uninstalled by a client application.
  • user_handle (Any) – The user handle returned by install_handler.
unlock() → None

Relinquishes a lock for the specified resource.

visa_attributes_classes = {<class 'pyvisa.attributes.AttrVI_ATTR_RSRC_LOCK_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_WIN_SIZE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_SPEC_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_TMO_VALUE'>, <class 'pyvisa.attributes.AttrVI_ATTR_MAX_QUEUE_LENGTH'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_TYPE'>, <class 'pyvisa.attributes.AttrVI_ATTR_USER_DATA'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_CLASS'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_IMPL_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_DEST_INCREMENT'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_INST_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_WIN_ACCESS'>, <class 'pyvisa.attributes.AttrVI_ATTR_SRC_INCREMENT'>, <class 'pyvisa.attributes.AttrVI_ATTR_WIN_BASE_ADDR'>}
wait_on_event(in_event_type: pyvisa.constants.EventType, timeout: int, capture_timeout: bool = False) → pyvisa.resources.resource.WaitResponse

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

in_event_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. None means waiting forever if necessary.
capture_timeout : bool, optional
When True will not produce a VisaIOError(VI_ERROR_TMO) but instead return a WaitResponse with timed_out=True.
Returns:Object that contains event_type, context and ret value.
Return type:WaitResponse
wrap_handler(callable: Callable[[Resource, pyvisa.events.Event, Any], None]) → Callable[[NewType.<locals>.new_type, pyvisa.constants.EventType, NewType.<locals>.new_type, Any], None]

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

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

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

write_memory(space: pyvisa.constants.AddressSpace, offset: int, data: int, width: pyvisa.constants.DataWidth, extended: bool = False) → pyvisa.constants.StatusCode

Write a value to the specified memory space and offset.

Parameters:
  • space (constants.AddressSpace) – Specifies the address space.
  • offset (int) – Offset (in bytes) of the address or register from which to read.
  • data (int) – Data to write to bus.
  • width (Union[Literal[8, 16, 32, 64], constants.DataWidth]) – Number of bits to read.
  • extended (bool, optional) – Use 64 bits offset independent of the platform, by default False.
Returns:

Return value of the library call.

Return type:

constants.StatusCode

Raises:

ValueError – Raised if an invalid width is specified.

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

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

More complex resource names can be specified with the following grammar:
VXI[board]::VXI logical address[::INSTR]

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

allow_dma

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

In some implementations, this attribute may have global effects even though it is documented to be a local attribute. Since this affects performance and not functionality, that behavior is acceptable.
VISA Attribute:VI_ATTR_DMA_ALLOW_EN (1073676318)
Type:bool
before_close() → None

Called just before closing an instrument.

clear() → None

Clear this resource.

close() → None

Closes the VISA session and marks the handle as invalid.

destination_increment

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

The default value of this attribute is 1 (that is, the destination address will be incremented by 1 after each transfer), and the viMoveOutXX() operations move into consecutive elements. If this attribute is set to 0, the viMoveOutXX() operations will always write to the same element, essentially treating the destination as a FIFO register.
VISA Attribute:VI_ATTR_DEST_INCREMENT (1073676353)
Type:int
Range:0 <= value <= 1
disable_event(event_type: pyvisa.constants.EventType, mechanism: pyvisa.constants.EventMechanism) → None

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

Parameters:
  • event_type (constants.EventType) – Logical event identifier.
  • mechanism (constants.EventMechanism) – Specifies event handling mechanisms to be disabled.
discard_events(event_type: pyvisa.constants.EventType, mechanism: pyvisa.constants.EventMechanism) → None

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

Parameters:
  • event_type (constants.EventType) – Logical event identifier.
  • mechanism (constants.EventMechanism) – Specifies event handling mechanisms to be disabled.
enable_event(event_type: pyvisa.constants.EventType, mechanism: pyvisa.constants.EventMechanism, context: None = None) → None

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

Parameters:
  • event_type (constants.EventType) – Logical event identifier.
  • mechanism (constants.EventMechanism) – Specifies event handling mechanisms to be enabled
  • context (None) – Not currently used, leave as None.
get_visa_attribute(name: pyvisa.constants.ResourceAttribute) → Any

Retrieves the state of an attribute in this resource.

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

Parameters:name (constants.ResourceAttribute) – Resource attribute for which the state query is made.
Returns:The state of the queried attribute for a specified resource.
Return type:Any
ignore_warning(*warnings_constants) → AbstractContextManager[T_co]

Ignoring warnings context manager for the current resource.

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

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

This attribute value is defined by the individual manufacturer and increments with each new revision. The format of the value has the upper 12 bits as the major number of the version, the next lower 12 bits as the minor number of the version, and the lowest 8 bits as the sub-minor number of the version.
VISA Attribute:VI_ATTR_RSRC_IMPL_VERSION (1073676291)
Type:int
Range:0 <= value <= 4294967295
install_handler(event_type: pyvisa.constants.EventType, handler: Callable[[NewType.<locals>.new_type, pyvisa.constants.EventType, NewType.<locals>.new_type, Any], None], user_handle=None) → Any

Install handlers for event callbacks in this resource.

Parameters:
  • event_type (constants.EventType) – Logical event identifier.
  • handler (VISAHandler) – Handler function to be installed by a client application.
  • user_handle – A value specified by an application that can be used for identifying handlers uniquely for an event type. Depending on the backend they may be restriction on the possible values. Look at the backend install_visa_handler for more details.
Returns:

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

Return type:

Any

interface_number

Board number for the given interface. :VISA Attribute: VI_ATTR_INTF_NUM (1073676662) :type: int :range: 0 <= value <= 65535

interface_type

Interface type of the given session. :VISA Attribute: VI_ATTR_INTF_TYPE (1073676657) :type: :class:pyvisa.constants.InterfaceType

io_protocol

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

is_4882_compliant

Whether the device is 488.2 compliant.

last_status

Last status code for this session.

lock(timeout: Union[float, typing_extensions.Literal['default'][default]] = 'default', requested_key: Optional[str] = None) → str

Establish a shared lock to the resource.

Parameters:
  • timeout (Union[float, Literal["default"]], optional) – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. Defaults to “default” which means use self.timeout.
  • requested_key (Optional[str], optional) – Access key used by another session with which you want your session to share a lock or None to generate a new shared access key.
Returns:

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

Return type:

str

lock_context(timeout: Union[float, typing_extensions.Literal['default'][default]] = 'default', requested_key: Optional[str] = 'exclusive') → Iterator[Optional[str]]

A context that locks

Parameters:
  • timeout (Union[float, Literal["default"]], optional) – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. Defaults to “default” which means use self.timeout.
  • requested_key (Optional[str], optional) – When using default of ‘exclusive’ the lock is an exclusive lock. Otherwise it is the access key for the shared lock or None to generate a new shared access key.
Yields:

Optional[str] – The access_key if applicable.

lock_excl(timeout: Union[float, typing_extensions.Literal['default'][default]] = 'default') → None

Establish an exclusive lock to the resource.

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

Current locking state of the resource.

The resource can be unlocked, locked with an exclusive lock, or locked with a shared lock.
VISA Attribute:VI_ATTR_RSRC_LOCK_STATE (1073676292)
Type::class:pyvisa.constants.AccessModes
manufacturer_id

Manufacturer identification number of the device.

manufacturer_name

Manufacturer name.

model_code

Model code for the device.

model_name

Model name of the device.

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

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

Corresponds to viMoveIn* functions of the VISA library.

Parameters:
  • space (constants.AddressSpace) – Address space from which to move the data.
  • offset (int) – Offset (in bytes) of the address or register from which to read.
  • length (int) – Number of elements to transfer, where the data width of the elements to transfer is identical to the source data width.
  • width (Union[Literal[8, 16, 32, 64], constants.DataWidth]) – Number of bits to read per element.
  • extended (bool, optional) – Use 64 bits offset independent of the platform, by default False.
Returns:

  • data (List[int]) – Data read from the bus
  • status_code (constants.StatusCode) – Return value of the library call.

Raises:

ValueError – Raised if an invalid width is specified.

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

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

Corresponds to viMoveOut* functions of the VISA library.

Parameters:
  • space (constants.AddressSpace) – Address space into which move the data.
  • offset (int) – Offset (in bytes) of the address or register from which to read.
  • length (int) – Number of elements to transfer, where the data width of the elements to transfer is identical to the source data width.
  • data (Iterable[int]) – Data to write to bus.
  • width (Union[Literal[8, 16, 32, 64], constants.DataWidth]) – Number of bits to per element.
  • extended (bool, optional) – Use 64 bits offset independent of the platform, by default False.
Returns:

Return value of the library call.

Return type:

constants.StatusCode

Raises:

ValueError – Raised if an invalid width is specified.

open(access_mode: pyvisa.constants.AccessModes = <AccessModes.no_lock: 0>, open_timeout: int = 5000) → None

Opens a session to the specified resource.

Parameters:
  • access_mode (constants.AccessModes, optional) – Specifies the mode by which the resource is to be accessed. Defaults to constants.AccessModes.no_lock.
  • open_timeout (int, optional) – If the access_mode parameter requests a lock, then this parameter specifies the absolute time period (in milliseconds) that the resource waits to get unlocked before this operation returns an error. Defaults to 5000.
read_memory(space: pyvisa.constants.AddressSpace, offset: int, width: pyvisa.constants.DataWidth, extended: bool = False) → int

Read a value from the specified memory space and offset.

Parameters:
  • space (constants.AddressSpace) – Specifies the address space from which to read.
  • offset (int) – Offset (in bytes) of the address or register from which to read.
  • width (Union[Literal[8, 16, 32, 64], constants.DataWidth]) – Number of bits to read (8, 16, 32 or 64).
  • extended (bool, optional) – Use 64 bits offset independent of the platform.
Returns:

data – Data read from memory

Return type:

int

Raises:

ValueError – Raised if an invalid width is specified.

classmethod register(interface_type: pyvisa.constants.InterfaceType, resource_class: str) → Callable[[Type[T]], Type[T]]

Create a decorator to register a class.

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

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

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

Return type:

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

resource_class

Resource class as defined by the canonical resource name.

Possible values are: INSTR, INTFC, SOCKET, RAW…
VISA Attribute:VI_ATTR_RSRC_CLASS (3221159937)
resource_info

Get the extended information of this resource.

resource_manufacturer_name

Manufacturer name of the vendor that implemented the VISA library.

This attribute is not related to the device manufacturer attributes.

Note The value of this attribute is for display purposes only and not for programmatic decisions, as the value can differ between VISA implementations and/or revisions.

VISA Attribute:VI_ATTR_RSRC_MANF_NAME (3221160308)
resource_name

Unique identifier for a resource compliant with the address structure. :VISA Attribute: VI_ATTR_RSRC_NAME (3221159938)

send_end

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

session

Resource session handle.

Raises:errors.InvalidSession – Raised if session is closed.
set_visa_attribute(name: pyvisa.constants.ResourceAttribute, state: Any) → pyvisa.constants.StatusCode

Set the state of an attribute.

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

Parameters:
  • name (constants.ResourceAttribute) – Attribute for which the state is to be modified.
  • state (Any) – The state of the attribute to be set for the specified object.
Returns:

Return value of the library call.

Return type:

constants.StatusCode

source_increment

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

The default value of this attribute is 1 (that is, the source address will be incremented by 1 after each transfer), and the viMoveInXX() operations move from consecutive elements. If this attribute is set to 0, the viMoveInXX() operations will always read from the same element, essentially treating the source as a FIFO register.
VISA Attribute:VI_ATTR_SRC_INCREMENT (1073676352)
Type:int
Range:0 <= value <= 1
spec_version

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

The format of the value has the upper 12 bits as the major number of the version, the next lower 12 bits as the minor number of the version, and the lowest 8 bits as the sub-minor number of the version. The current VISA specification defines the value to be 00300000h.
VISA Attribute:VI_ATTR_RSRC_SPEC_VERSION (1073676656)
Type:int
Range:0 <= value <= 4294967295
timeout

Timeout in milliseconds for all resource I/O operations.

This value is used when accessing the device associated with the given session.

Special values:

  • immediate (VI_TMO_IMMEDIATE): 0
    (for convenience, any value smaller than 1 is considered as 0)
  • infinite (VI_TMO_INFINITE): float('+inf')
    (for convenience, None is considered as float('+inf'))

To set an infinite timeout, you can also use:

>>> del instrument.timeout

A timeout value of VI_TMO_IMMEDIATE means that operations should never wait for the device to respond. A timeout value of VI_TMO_INFINITE disables the timeout mechanism.

VISA Attribute:VI_ATTR_TMO_VALUE (1073676314)
Type:int
Range:0 <= value <= 4294967295
uninstall_handler(event_type: pyvisa.constants.EventType, handler: Callable[[NewType.<locals>.new_type, pyvisa.constants.EventType, NewType.<locals>.new_type, Any], None], user_handle=None) → None

Uninstalls handlers for events in this resource.

Parameters:
  • event_type (constants.EventType) – Logical event identifier.
  • handler (VISAHandler) – Handler function to be uninstalled by a client application.
  • user_handle (Any) – The user handle returned by install_handler.
unlock() → None

Relinquishes a lock for the specified resource.

visa_attributes_classes = {<class 'pyvisa.attributes.AttrVI_ATTR_RSRC_LOCK_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_TRIG_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_TYPE'>, <class 'pyvisa.attributes.AttrVI_ATTR_IO_PROT'>, <class 'pyvisa.attributes.AttrVI_ATTR_DEST_INCREMENT'>, <class 'pyvisa.attributes.AttrVI_ATTR_FDC_CHNL'>, <class 'pyvisa.attributes.AttrVI_ATTR_MAINFRAME_LA'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_INST_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_MEM_SIZE'>, <class 'pyvisa.attributes.AttrVI_ATTR_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_DEST_BYTE_ORDER'>, <class 'pyvisa.attributes.AttrVI_ATTR_WIN_BASE_ADDR'>, <class 'pyvisa.attributes.AttrVI_ATTR_SRC_ACCESS_PRIV'>, <class 'pyvisa.attributes.AttrVI_ATTR_WIN_BYTE_ORDER'>, <class 'pyvisa.attributes.AttrVI_ATTR_VXI_TRIG_LINES_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_SPEC_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_VXI_TRIG_SUPPORT'>, <class 'pyvisa.attributes.AttrVI_ATTR_USER_DATA'>, <class 'pyvisa.attributes.AttrVI_ATTR_TERMCHAR'>, <class 'pyvisa.attributes.AttrVI_ATTR_RD_BUF_SIZE'>, <class 'pyvisa.attributes.AttrVI_ATTR_FDC_USE_PAIR'>, <class 'pyvisa.attributes.AttrVI_ATTR_MEM_SPACE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_IMPL_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_DEST_ACCESS_PRIV'>, <class 'pyvisa.attributes.AttrVI_ATTR_MODEL_CODE'>, <class 'pyvisa.attributes.AttrVI_ATTR_WIN_ACCESS'>, <class 'pyvisa.attributes.AttrVI_ATTR_WIN_ACCESS_PRIV'>, <class 'pyvisa.attributes.AttrVI_ATTR_VXI_TRIG_DIR'>, <class 'pyvisa.attributes.AttrVI_ATTR_TMO_VALUE'>, <class 'pyvisa.attributes.AttrVI_ATTR_MAX_QUEUE_LENGTH'>, <class 'pyvisa.attributes.AttrVI_ATTR_TERMCHAR_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_RD_BUF_OPER_MODE'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_WR_BUF_OPER_MODE'>, <class 'pyvisa.attributes.AttrVI_ATTR_WR_BUF_SIZE'>, <class 'pyvisa.attributes.AttrVI_ATTR_CMDR_LA'>, <class 'pyvisa.attributes.AttrVI_ATTR_IMMEDIATE_SERV'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_SRC_BYTE_ORDER'>, <class 'pyvisa.attributes.AttrVI_ATTR_MODEL_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_SLOT'>, <class 'pyvisa.attributes.AttrVI_ATTR_DMA_ALLOW_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_SRC_INCREMENT'>, <class 'pyvisa.attributes.AttrVI_ATTR_VXI_DEV_CLASS'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_SEND_END_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_SUPPRESS_END_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_FILE_APPEND_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_FDC_MODE'>, <class 'pyvisa.attributes.AttrVI_ATTR_MEM_BASE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_CLASS'>, <class 'pyvisa.attributes.AttrVI_ATTR_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_4882_COMPLIANT'>, <class 'pyvisa.attributes.AttrVI_ATTR_WIN_SIZE'>, <class 'pyvisa.attributes.AttrVI_ATTR_VXI_LA'>}
wait_on_event(in_event_type: pyvisa.constants.EventType, timeout: int, capture_timeout: bool = False) → pyvisa.resources.resource.WaitResponse

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

in_event_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. None means waiting forever if necessary.
capture_timeout : bool, optional
When True will not produce a VisaIOError(VI_ERROR_TMO) but instead return a WaitResponse with timed_out=True.
Returns:Object that contains event_type, context and ret value.
Return type:WaitResponse
wrap_handler(callable: Callable[[Resource, pyvisa.events.Event, Any], None]) → Callable[[NewType.<locals>.new_type, pyvisa.constants.EventType, NewType.<locals>.new_type, Any], None]

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

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

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

write_memory(space: pyvisa.constants.AddressSpace, offset: int, data: int, width: pyvisa.constants.DataWidth, extended: bool = False) → pyvisa.constants.StatusCode

Write a value to the specified memory space and offset.

Parameters:
  • space (constants.AddressSpace) – Specifies the address space.
  • offset (int) – Offset (in bytes) of the address or register from which to read.
  • data (int) – Data to write to bus.
  • width (Union[Literal[8, 16, 32, 64], constants.DataWidth]) – Number of bits to read.
  • extended (bool, optional) – Use 64 bits offset independent of the platform, by default False.
Returns:

Return value of the library call.

Return type:

constants.StatusCode

Raises:

ValueError – Raised if an invalid width is specified.

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

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

More complex resource names can be specified with the following grammar:
VXI[board]::MEMACC

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

allow_dma

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

In some implementations, this attribute may have global effects even though it is documented to be a local attribute. Since this affects performance and not functionality, that behavior is acceptable.
VISA Attribute:VI_ATTR_DMA_ALLOW_EN (1073676318)
Type:bool
before_close() → None

Called just before closing an instrument.

clear() → None

Clear this resource.

close() → None

Closes the VISA session and marks the handle as invalid.

destination_increment

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

The default value of this attribute is 1 (that is, the destination address will be incremented by 1 after each transfer), and the viMoveOutXX() operations move into consecutive elements. If this attribute is set to 0, the viMoveOutXX() operations will always write to the same element, essentially treating the destination as a FIFO register.
VISA Attribute:VI_ATTR_DEST_INCREMENT (1073676353)
Type:int
Range:0 <= value <= 1
disable_event(event_type: pyvisa.constants.EventType, mechanism: pyvisa.constants.EventMechanism) → None

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

Parameters:
  • event_type (constants.EventType) – Logical event identifier.
  • mechanism (constants.EventMechanism) – Specifies event handling mechanisms to be disabled.
discard_events(event_type: pyvisa.constants.EventType, mechanism: pyvisa.constants.EventMechanism) → None

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

Parameters:
  • event_type (constants.EventType) – Logical event identifier.
  • mechanism (constants.EventMechanism) – Specifies event handling mechanisms to be disabled.
enable_event(event_type: pyvisa.constants.EventType, mechanism: pyvisa.constants.EventMechanism, context: None = None) → None

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

Parameters:
  • event_type (constants.EventType) – Logical event identifier.
  • mechanism (constants.EventMechanism) – Specifies event handling mechanisms to be enabled
  • context (None) – Not currently used, leave as None.
get_visa_attribute(name: pyvisa.constants.ResourceAttribute) → Any

Retrieves the state of an attribute in this resource.

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

Parameters:name (constants.ResourceAttribute) – Resource attribute for which the state query is made.
Returns:The state of the queried attribute for a specified resource.
Return type:Any
ignore_warning(*warnings_constants) → AbstractContextManager[T_co]

Ignoring warnings context manager for the current resource.

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

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

This attribute value is defined by the individual manufacturer and increments with each new revision. The format of the value has the upper 12 bits as the major number of the version, the next lower 12 bits as the minor number of the version, and the lowest 8 bits as the sub-minor number of the version.
VISA Attribute:VI_ATTR_RSRC_IMPL_VERSION (1073676291)
Type:int
Range:0 <= value <= 4294967295
install_handler(event_type: pyvisa.constants.EventType, handler: Callable[[NewType.<locals>.new_type, pyvisa.constants.EventType, NewType.<locals>.new_type, Any], None], user_handle=None) → Any

Install handlers for event callbacks in this resource.

Parameters:
  • event_type (constants.EventType) – Logical event identifier.
  • handler (VISAHandler) – Handler function to be installed by a client application.
  • user_handle – A value specified by an application that can be used for identifying handlers uniquely for an event type. Depending on the backend they may be restriction on the possible values. Look at the backend install_visa_handler for more details.
Returns:

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

Return type:

Any

interface_number

Board number for the given interface. :VISA Attribute: VI_ATTR_INTF_NUM (1073676662) :type: int :range: 0 <= value <= 65535

interface_type

Interface type of the given session. :VISA Attribute: VI_ATTR_INTF_TYPE (1073676657) :type: :class:pyvisa.constants.InterfaceType

last_status

Last status code for this session.

lock(timeout: Union[float, typing_extensions.Literal['default'][default]] = 'default', requested_key: Optional[str] = None) → str

Establish a shared lock to the resource.

Parameters:
  • timeout (Union[float, Literal["default"]], optional) – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. Defaults to “default” which means use self.timeout.
  • requested_key (Optional[str], optional) – Access key used by another session with which you want your session to share a lock or None to generate a new shared access key.
Returns:

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

Return type:

str

lock_context(timeout: Union[float, typing_extensions.Literal['default'][default]] = 'default', requested_key: Optional[str] = 'exclusive') → Iterator[Optional[str]]

A context that locks

Parameters:
  • timeout (Union[float, Literal["default"]], optional) – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. Defaults to “default” which means use self.timeout.
  • requested_key (Optional[str], optional) – When using default of ‘exclusive’ the lock is an exclusive lock. Otherwise it is the access key for the shared lock or None to generate a new shared access key.
Yields:

Optional[str] – The access_key if applicable.

lock_excl(timeout: Union[float, typing_extensions.Literal['default'][default]] = 'default') → None

Establish an exclusive lock to the resource.

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

Current locking state of the resource.

The resource can be unlocked, locked with an exclusive lock, or locked with a shared lock.
VISA Attribute:VI_ATTR_RSRC_LOCK_STATE (1073676292)
Type::class:pyvisa.constants.AccessModes
move_in(space: pyvisa.constants.AddressSpace, offset: int, length: int, width: pyvisa.constants.DataWidth, extended: bool = False) → List[int]

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

Corresponds to viMoveIn* functions of the VISA library.

Parameters:
  • space (constants.AddressSpace) – Address space from which to move the data.
  • offset (int) – Offset (in bytes) of the address or register from which to read.
  • length (int) – Number of elements to transfer, where the data width of the elements to transfer is identical to the source data width.
  • width (Union[Literal[8, 16, 32, 64], constants.DataWidth]) – Number of bits to read per element.
  • extended (bool, optional) – Use 64 bits offset independent of the platform, by default False.
Returns:

  • data (List[int]) – Data read from the bus
  • status_code (constants.StatusCode) – Return value of the library call.

Raises:

ValueError – Raised if an invalid width is specified.

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

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

Corresponds to viMoveOut* functions of the VISA library.

Parameters:
  • space (constants.AddressSpace) – Address space into which move the data.
  • offset (int) – Offset (in bytes) of the address or register from which to read.
  • length (int) – Number of elements to transfer, where the data width of the elements to transfer is identical to the source data width.
  • data (Iterable[int]) – Data to write to bus.
  • width (Union[Literal[8, 16, 32, 64], constants.DataWidth]) – Number of bits to per element.
  • extended (bool, optional) – Use 64 bits offset independent of the platform, by default False.
Returns:

Return value of the library call.

Return type:

constants.StatusCode

Raises:

ValueError – Raised if an invalid width is specified.

open(access_mode: pyvisa.constants.AccessModes = <AccessModes.no_lock: 0>, open_timeout: int = 5000) → None

Opens a session to the specified resource.

Parameters:
  • access_mode (constants.AccessModes, optional) – Specifies the mode by which the resource is to be accessed. Defaults to constants.AccessModes.no_lock.
  • open_timeout (int, optional) – If the access_mode parameter requests a lock, then this parameter specifies the absolute time period (in milliseconds) that the resource waits to get unlocked before this operation returns an error. Defaults to 5000.
read_memory(space: pyvisa.constants.AddressSpace, offset: int, width: pyvisa.constants.DataWidth, extended: bool = False) → int

Read a value from the specified memory space and offset.

Parameters:
  • space (constants.AddressSpace) – Specifies the address space from which to read.
  • offset (int) – Offset (in bytes) of the address or register from which to read.
  • width (Union[Literal[8, 16, 32, 64], constants.DataWidth]) – Number of bits to read (8, 16, 32 or 64).
  • extended (bool, optional) – Use 64 bits offset independent of the platform.
Returns:

data – Data read from memory

Return type:

int

Raises:

ValueError – Raised if an invalid width is specified.

classmethod register(interface_type: pyvisa.constants.InterfaceType, resource_class: str) → Callable[[Type[T]], Type[T]]

Create a decorator to register a class.

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

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

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

Return type:

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

resource_class

Resource class as defined by the canonical resource name.

Possible values are: INSTR, INTFC, SOCKET, RAW…
VISA Attribute:VI_ATTR_RSRC_CLASS (3221159937)
resource_info

Get the extended information of this resource.

resource_manufacturer_name

Manufacturer name of the vendor that implemented the VISA library.

This attribute is not related to the device manufacturer attributes.

Note The value of this attribute is for display purposes only and not for programmatic decisions, as the value can differ between VISA implementations and/or revisions.

VISA Attribute:VI_ATTR_RSRC_MANF_NAME (3221160308)
resource_name

Unique identifier for a resource compliant with the address structure. :VISA Attribute: VI_ATTR_RSRC_NAME (3221159938)

session

Resource session handle.

Raises:errors.InvalidSession – Raised if session is closed.
set_visa_attribute(name: pyvisa.constants.ResourceAttribute, state: Any) → pyvisa.constants.StatusCode

Set the state of an attribute.

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

Parameters:
  • name (constants.ResourceAttribute) – Attribute for which the state is to be modified.
  • state (Any) – The state of the attribute to be set for the specified object.
Returns:

Return value of the library call.

Return type:

constants.StatusCode

source_increment

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

The default value of this attribute is 1 (that is, the source address will be incremented by 1 after each transfer), and the viMoveInXX() operations move from consecutive elements. If this attribute is set to 0, the viMoveInXX() operations will always read from the same element, essentially treating the source as a FIFO register.
VISA Attribute:VI_ATTR_SRC_INCREMENT (1073676352)
Type:int
Range:0 <= value <= 1
spec_version

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

The format of the value has the upper 12 bits as the major number of the version, the next lower 12 bits as the minor number of the version, and the lowest 8 bits as the sub-minor number of the version. The current VISA specification defines the value to be 00300000h.
VISA Attribute:VI_ATTR_RSRC_SPEC_VERSION (1073676656)
Type:int
Range:0 <= value <= 4294967295
timeout

Timeout in milliseconds for all resource I/O operations.

This value is used when accessing the device associated with the given session.

Special values:

  • immediate (VI_TMO_IMMEDIATE): 0
    (for convenience, any value smaller than 1 is considered as 0)
  • infinite (VI_TMO_INFINITE): float('+inf')
    (for convenience, None is considered as float('+inf'))

To set an infinite timeout, you can also use:

>>> del instrument.timeout

A timeout value of VI_TMO_IMMEDIATE means that operations should never wait for the device to respond. A timeout value of VI_TMO_INFINITE disables the timeout mechanism.

VISA Attribute:VI_ATTR_TMO_VALUE (1073676314)
Type:int
Range:0 <= value <= 4294967295
uninstall_handler(event_type: pyvisa.constants.EventType, handler: Callable[[NewType.<locals>.new_type, pyvisa.constants.EventType, NewType.<locals>.new_type, Any], None], user_handle=None) → None

Uninstalls handlers for events in this resource.

Parameters:
  • event_type (constants.EventType) – Logical event identifier.
  • handler (VISAHandler) – Handler function to be uninstalled by a client application.
  • user_handle (Any) – The user handle returned by install_handler.
unlock() → None

Relinquishes a lock for the specified resource.

visa_attributes_classes = {<class 'pyvisa.attributes.AttrVI_ATTR_RSRC_LOCK_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_TYPE'>, <class 'pyvisa.attributes.AttrVI_ATTR_DEST_INCREMENT'>, <class 'pyvisa.attributes.AttrVI_ATTR_WIN_BYTE_ORDER'>, <class 'pyvisa.attributes.AttrVI_ATTR_DEST_BYTE_ORDER'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_INST_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_WIN_BASE_ADDR'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_SPEC_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_USER_DATA'>, <class 'pyvisa.attributes.AttrVI_ATTR_DEST_ACCESS_PRIV'>, <class 'pyvisa.attributes.AttrVI_ATTR_WIN_ACCESS_PRIV'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_IMPL_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_WIN_ACCESS'>, <class 'pyvisa.attributes.AttrVI_ATTR_TMO_VALUE'>, <class 'pyvisa.attributes.AttrVI_ATTR_MAX_QUEUE_LENGTH'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_SRC_BYTE_ORDER'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_DMA_ALLOW_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_SRC_INCREMENT'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_SRC_ACCESS_PRIV'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_CLASS'>, <class 'pyvisa.attributes.AttrVI_ATTR_WIN_SIZE'>, <class 'pyvisa.attributes.AttrVI_ATTR_VXI_LA'>}
wait_on_event(in_event_type: pyvisa.constants.EventType, timeout: int, capture_timeout: bool = False) → pyvisa.resources.resource.WaitResponse

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

in_event_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. None means waiting forever if necessary.
capture_timeout : bool, optional
When True will not produce a VisaIOError(VI_ERROR_TMO) but instead return a WaitResponse with timed_out=True.
Returns:Object that contains event_type, context and ret value.
Return type:WaitResponse
wrap_handler(callable: Callable[[Resource, pyvisa.events.Event, Any], None]) → Callable[[NewType.<locals>.new_type, pyvisa.constants.EventType, NewType.<locals>.new_type, Any], None]

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

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

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

write_memory(space: pyvisa.constants.AddressSpace, offset: int, data: int, width: pyvisa.constants.DataWidth, extended: bool = False) → pyvisa.constants.StatusCode

Write a value to the specified memory space and offset.

Parameters:
  • space (constants.AddressSpace) – Specifies the address space.
  • offset (int) – Offset (in bytes) of the address or register from which to read.
  • data (int) – Data to write to bus.
  • width (Union[Literal[8, 16, 32, 64], constants.DataWidth]) – Number of bits to read.
  • extended (bool, optional) – Use 64 bits offset independent of the platform, by default False.
Returns:

Return value of the library call.

Return type:

constants.StatusCode

Raises:

ValueError – Raised if an invalid width is specified.

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

Communicates with to devices of type VXI::BACKPLANE

More complex resource names can be specified with the following grammar:
VXI[board][::VXI logical address]::BACKPLANE

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

before_close() → None

Called just before closing an instrument.

clear() → None

Clear this resource.

close() → None

Closes the VISA session and marks the handle as invalid.

disable_event(event_type: pyvisa.constants.EventType, mechanism: pyvisa.constants.EventMechanism) → None

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

Parameters:
  • event_type (constants.EventType) – Logical event identifier.
  • mechanism (constants.EventMechanism) – Specifies event handling mechanisms to be disabled.
discard_events(event_type: pyvisa.constants.EventType, mechanism: pyvisa.constants.EventMechanism) → None

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

Parameters:
  • event_type (constants.EventType) – Logical event identifier.
  • mechanism (constants.EventMechanism) – Specifies event handling mechanisms to be disabled.
enable_event(event_type: pyvisa.constants.EventType, mechanism: pyvisa.constants.EventMechanism, context: None = None) → None

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

Parameters:
  • event_type (constants.EventType) – Logical event identifier.
  • mechanism (constants.EventMechanism) – Specifies event handling mechanisms to be enabled
  • context (None) – Not currently used, leave as None.
get_visa_attribute(name: pyvisa.constants.ResourceAttribute) → Any

Retrieves the state of an attribute in this resource.

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

Parameters:name (constants.ResourceAttribute) – Resource attribute for which the state query is made.
Returns:The state of the queried attribute for a specified resource.
Return type:Any
ignore_warning(*warnings_constants) → AbstractContextManager[T_co]

Ignoring warnings context manager for the current resource.

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

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

This attribute value is defined by the individual manufacturer and increments with each new revision. The format of the value has the upper 12 bits as the major number of the version, the next lower 12 bits as the minor number of the version, and the lowest 8 bits as the sub-minor number of the version.
VISA Attribute:VI_ATTR_RSRC_IMPL_VERSION (1073676291)
Type:int
Range:0 <= value <= 4294967295
install_handler(event_type: pyvisa.constants.EventType, handler: Callable[[NewType.<locals>.new_type, pyvisa.constants.EventType, NewType.<locals>.new_type, Any], None], user_handle=None) → Any

Install handlers for event callbacks in this resource.

Parameters:
  • event_type (constants.EventType) – Logical event identifier.
  • handler (VISAHandler) – Handler function to be installed by a client application.
  • user_handle – A value specified by an application that can be used for identifying handlers uniquely for an event type. Depending on the backend they may be restriction on the possible values. Look at the backend install_visa_handler for more details.
Returns:

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

Return type:

Any

interface_number

Board number for the given interface. :VISA Attribute: VI_ATTR_INTF_NUM (1073676662) :type: int :range: 0 <= value <= 65535

interface_type

Interface type of the given session. :VISA Attribute: VI_ATTR_INTF_TYPE (1073676657) :type: :class:pyvisa.constants.InterfaceType

last_status

Last status code for this session.

lock(timeout: Union[float, typing_extensions.Literal['default'][default]] = 'default', requested_key: Optional[str] = None) → str

Establish a shared lock to the resource.

Parameters:
  • timeout (Union[float, Literal["default"]], optional) – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. Defaults to “default” which means use self.timeout.
  • requested_key (Optional[str], optional) – Access key used by another session with which you want your session to share a lock or None to generate a new shared access key.
Returns:

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

Return type:

str

lock_context(timeout: Union[float, typing_extensions.Literal['default'][default]] = 'default', requested_key: Optional[str] = 'exclusive') → Iterator[Optional[str]]

A context that locks

Parameters:
  • timeout (Union[float, Literal["default"]], optional) – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. Defaults to “default” which means use self.timeout.
  • requested_key (Optional[str], optional) – When using default of ‘exclusive’ the lock is an exclusive lock. Otherwise it is the access key for the shared lock or None to generate a new shared access key.
Yields:

Optional[str] – The access_key if applicable.

lock_excl(timeout: Union[float, typing_extensions.Literal['default'][default]] = 'default') → None

Establish an exclusive lock to the resource.

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

Current locking state of the resource.

The resource can be unlocked, locked with an exclusive lock, or locked with a shared lock.
VISA Attribute:VI_ATTR_RSRC_LOCK_STATE (1073676292)
Type::class:pyvisa.constants.AccessModes
open(access_mode: pyvisa.constants.AccessModes = <AccessModes.no_lock: 0>, open_timeout: int = 5000) → None

Opens a session to the specified resource.

Parameters:
  • access_mode (constants.AccessModes, optional) – Specifies the mode by which the resource is to be accessed. Defaults to constants.AccessModes.no_lock.
  • open_timeout (int, optional) – If the access_mode parameter requests a lock, then this parameter specifies the absolute time period (in milliseconds) that the resource waits to get unlocked before this operation returns an error. Defaults to 5000.
classmethod register(interface_type: pyvisa.constants.InterfaceType, resource_class: str) → Callable[[Type[T]], Type[T]]

Create a decorator to register a class.

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

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

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

Return type:

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

resource_class

Resource class as defined by the canonical resource name.

Possible values are: INSTR, INTFC, SOCKET, RAW…
VISA Attribute:VI_ATTR_RSRC_CLASS (3221159937)
resource_info

Get the extended information of this resource.

resource_manufacturer_name

Manufacturer name of the vendor that implemented the VISA library.

This attribute is not related to the device manufacturer attributes.

Note The value of this attribute is for display purposes only and not for programmatic decisions, as the value can differ between VISA implementations and/or revisions.

VISA Attribute:VI_ATTR_RSRC_MANF_NAME (3221160308)
resource_name

Unique identifier for a resource compliant with the address structure. :VISA Attribute: VI_ATTR_RSRC_NAME (3221159938)

session

Resource session handle.

Raises:errors.InvalidSession – Raised if session is closed.
set_visa_attribute(name: pyvisa.constants.ResourceAttribute, state: Any) → pyvisa.constants.StatusCode

Set the state of an attribute.

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

Parameters:
  • name (constants.ResourceAttribute) – Attribute for which the state is to be modified.
  • state (Any) – The state of the attribute to be set for the specified object.
Returns:

Return value of the library call.

Return type:

constants.StatusCode

spec_version

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

The format of the value has the upper 12 bits as the major number of the version, the next lower 12 bits as the minor number of the version, and the lowest 8 bits as the sub-minor number of the version. The current VISA specification defines the value to be 00300000h.
VISA Attribute:VI_ATTR_RSRC_SPEC_VERSION (1073676656)
Type:int
Range:0 <= value <= 4294967295
timeout

Timeout in milliseconds for all resource I/O operations.

This value is used when accessing the device associated with the given session.

Special values:

  • immediate (VI_TMO_IMMEDIATE): 0
    (for convenience, any value smaller than 1 is considered as 0)
  • infinite (VI_TMO_INFINITE): float('+inf')
    (for convenience, None is considered as float('+inf'))

To set an infinite timeout, you can also use:

>>> del instrument.timeout

A timeout value of VI_TMO_IMMEDIATE means that operations should never wait for the device to respond. A timeout value of VI_TMO_INFINITE disables the timeout mechanism.

VISA Attribute:VI_ATTR_TMO_VALUE (1073676314)
Type:int
Range:0 <= value <= 4294967295
uninstall_handler(event_type: pyvisa.constants.EventType, handler: Callable[[NewType.<locals>.new_type, pyvisa.constants.EventType, NewType.<locals>.new_type, Any], None], user_handle=None) → None

Uninstalls handlers for events in this resource.

Parameters:
  • event_type (constants.EventType) – Logical event identifier.
  • handler (VISAHandler) – Handler function to be uninstalled by a client application.
  • user_handle (Any) – The user handle returned by install_handler.
unlock() → None

Relinquishes a lock for the specified resource.

visa_attributes_classes = {<class 'pyvisa.attributes.AttrVI_ATTR_RSRC_LOCK_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_TRIG_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_TYPE'>, <class 'pyvisa.attributes.AttrVI_ATTR_MAINFRAME_LA'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_INST_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_SPEC_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_VXI_TRIG_SUPPORT'>, <class 'pyvisa.attributes.AttrVI_ATTR_USER_DATA'>, <class 'pyvisa.attributes.AttrVI_ATTR_VXI_VME_SYSFAIL_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_IMPL_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_TMO_VALUE'>, <class 'pyvisa.attributes.AttrVI_ATTR_MAX_QUEUE_LENGTH'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_VXI_TRIG_STATUS'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_VXI_VME_INTR_STATUS'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_CLASS'>}
wait_on_event(in_event_type: pyvisa.constants.EventType, timeout: int, capture_timeout: bool = False) → pyvisa.resources.resource.WaitResponse

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

in_event_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. None means waiting forever if necessary.
capture_timeout : bool, optional
When True will not produce a VisaIOError(VI_ERROR_TMO) but instead return a WaitResponse with timed_out=True.
Returns:Object that contains event_type, context and ret value.
Return type:WaitResponse
wrap_handler(callable: Callable[[Resource, pyvisa.events.Event, Any], None]) → Callable[[NewType.<locals>.new_type, pyvisa.constants.EventType, NewType.<locals>.new_type, Any], None]

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

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

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