Resource classes¶
Resources are high level abstractions to managing specific sessions. An instance
of one of these classes is returned by the open_resource()
depending on the resource type.
Generic classes¶
Specific Classes¶
-
class
pyvisa.resources.
Resource
(resource_manager, resource_name)[source]¶ Base class for resources.
Do not instantiate directly, use
pyvisa.highlevel.ResourceManager.open_resource()
.Parameters: - resource_manager – A resource manager instance.
- resource_name – the VISA name for the resource (eg. “GPIB::10”)
-
disable_event
(event_type, mechanism)[source]¶ Disables notification of the specified event type(s) via the specified mechanism(s).
Parameters: - event_type – Logical event identifier.
- mechanism – Specifies event handling mechanisms to be disabled. (Constants.VI_QUEUE, .VI_HNDLR, .VI_SUSPEND_HNDLR, .VI_ALL_MECH)
-
discard_events
(event_type, mechanism)[source]¶ Discards event occurrences for specified event types and mechanisms in this resource.
Parameters: - event_type – Logical event identifier.
- mechanism – Specifies event handling mechanisms to be dicarded. (Constants.VI_QUEUE, .VI_HNDLR, .VI_SUSPEND_HNDLR, .VI_ALL_MECH)
-
enable_event
(event_type, mechanism, context=None)[source]¶ Enable event occurrences for specified event types and mechanisms in this resource.
Parameters: - event_type – Logical event identifier.
- mechanism – Specifies event handling mechanisms to be enabled. (Constants.VI_QUEUE, .VI_HNDLR, .VI_SUSPEND_HNDLR)
- context – Not currently used, leave as None.
-
get_visa_attribute
(name)[source]¶ Retrieves the state of an attribute in this resource.
Parameters: name – Resource attribute for which the state query is made (see Attributes.*) Returns: The state of the queried attribute for a specified resource. Return type: unicode (Py2) or str (Py3), list or other type
-
ignore_warning
(*warnings_constants)[source]¶ Ignoring warnings context manager for the current resource.
Parameters: warnings_constants – constants identifying the warnings to ignore.
-
implementation_version
¶ - VI_ATTR_RSRC_IMPL_VERSION is the resource version that uniquely identifies
- each of the different 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, handler, user_handle=None)[source]¶ Installs handlers for event callbacks in this resource.
Parameters: - event_type – Logical event identifier.
- handler – Interpreted as a valid reference to a handler to be installed by a client application.
- user_handle – A value specified by an application that can be used for identifying handlers uniquely for an event type.
Returns: user handle (a ctypes object)
-
interface_number
¶ VI_ATTR_INTF_NUM specifies the board number for the given interface.
VISA Attribute: VI_ATTR_INTF_NUM (1073676662) Type: int Range: 0 <= value <= 65535
-
interface_type
¶ The interface type of the resource as a number.
-
last_status
¶ Last status code for this session.
Return type: pyvisa.constants.StatusCode
-
lock
(timeout='default', requested_key=None)[source]¶ Establish a shared lock to the resource.
Parameters: - timeout – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. (Defaults to self.timeout)
- requested_key – 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
-
lock_context
(timeout='default', requested_key='exclusive')[source]¶ A context that locks
Parameters: - timeout – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. (Defaults to self.timeout)
- requested_key – 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.
The returned context is the access_key if applicable.
-
lock_excl
(timeout='default')[source]¶ Establish an exclusive lock to the resource.
Parameters: timeout – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. (Defaults to self.timeout)
-
lock_state
¶ - VI_ATTR_RSRC_LOCK_STATE indicates the 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=<AccessModes.no_lock: 0>, open_timeout=5000)[source]¶ Opens a session to the specified resource.
Parameters: - access_mode (
pyvisa.constants.AccessModes
) – Specifies the mode by which the resource is to be accessed. - open_timeout (int) – If the
access_mode
parameter requests a lock, then this parameter specifies the absolute time period (in milliseconds) that the resource waits to get unlocked before this operation returns an error.
- access_mode (
-
resource_class
¶ - VI_ATTR_RSRC_CLASS specifies the resource class (for example, “INSTR”)
- as defined by the canonical resource name.
VISA Attribute: VI_ATTR_RSRC_CLASS (3221159937)
-
resource_info
¶ Get the extended information of this resource.
Parameters: resource_name – Unique symbolic name of a resource. Return type: pyvisa.highlevel.ResourceInfo
-
resource_manufacturer_name
¶ - VI_ATTR_RSRC_MANF_NAME is a string that corresponds to the 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
¶ - VI_ATTR_RSRC_MANF_NAME is a string that corresponds to the 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_NAME (3221159938)
-
session
¶ Resource session handle.
Raises: pyvisa.errors.InvalidSession
if session is closed.
-
set_visa_attribute
(name, state)[source]¶ Sets the state of an attribute.
Parameters: - name – Attribute for which the state is to be modified. (Attributes.*)
- state – The state of the attribute to be set for the specified object.
Returns: return value of the library call.
Return type:
-
spec_version
¶ - VI_ATTR_RSRC_SPEC_VERSION is the resource version that uniquely identifies
- the 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
¶ The timeout in milliseconds for all resource I/O operations.
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 asfloat('+inf')
)
To set an infinite timeout, you can also use:
>>> del instrument.timeout
- immediate (
-
uninstall_handler
(event_type, handler, user_handle=None)[source]¶ Uninstalls handlers for events in this resource.
Parameters: - event_type – Logical event identifier.
- handler – Interpreted as a valid reference to a handler to be uninstalled by a client application.
- user_handle – The user handle (ctypes object or None) returned by install_handler.
-
visa_attributes_classes
= [<class 'pyvisa.attributes.AttrVI_ATTR_INTF_INST_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_MAX_QUEUE_LENGTH'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_TYPE'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_RM_SESSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_CLASS'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_IMPL_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_LOCK_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_SPEC_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_TMO_VALUE'>]¶
-
wait_on_event
(in_event_type, timeout, capture_timeout=False)[source]¶ Waits for an occurrence of the specified event in this resource.
Parameters: - in_event_type – Logical identifier of the event(s) to wait for.
- timeout – Absolute time period in time units that the resource shall wait for a specified event to occur before returning the time elapsed error. The time unit is in milliseconds. None means waiting forever if necessary.
- capture_timeout – When True will not produce a VisaIOError(VI_ERROR_TMO) but instead return a WaitResponse with timed_out=True
Returns: A WaitResponse object that contains event_type, context and ret value.
-
class
pyvisa.resources.
MessageBasedResource
(*args, **kwargs)[source]¶ Base class for resources that use message based communication.
-
CR
= '\r'¶
-
LF
= '\n'¶
-
before_close
()¶ Called just before closing an instrument.
-
chunk_size
= 20480¶
-
clear
()¶ Clears this resource
-
close
()¶ Closes the VISA session and marks the handle as invalid.
-
disable_event
(event_type, mechanism)¶ Disables notification of the specified event type(s) via the specified mechanism(s).
Parameters: - event_type – Logical event identifier.
- mechanism – Specifies event handling mechanisms to be disabled. (Constants.VI_QUEUE, .VI_HNDLR, .VI_SUSPEND_HNDLR, .VI_ALL_MECH)
-
discard_events
(event_type, mechanism)¶ Discards event occurrences for specified event types and mechanisms in this resource.
Parameters: - event_type – Logical event identifier.
- mechanism – Specifies event handling mechanisms to be dicarded. (Constants.VI_QUEUE, .VI_HNDLR, .VI_SUSPEND_HNDLR, .VI_ALL_MECH)
-
enable_event
(event_type, mechanism, context=None)¶ Enable event occurrences for specified event types and mechanisms in this resource.
Parameters: - event_type – Logical event identifier.
- mechanism – Specifies event handling mechanisms to be enabled. (Constants.VI_QUEUE, .VI_HNDLR, .VI_SUSPEND_HNDLR)
- context – Not currently used, leave as None.
-
encoding
¶ Encoding used for read and write operations.
-
flush
(mask)[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 – Specifies the action to be taken with flushing the buffer. See highlevel.VisaLibraryBase.flush for a detailed description.
-
get_visa_attribute
(name)¶ Retrieves the state of an attribute in this resource.
Parameters: name – Resource attribute for which the state query is made (see Attributes.*) Returns: The state of the queried attribute for a specified resource. Return type: unicode (Py2) or str (Py3), list or other type
-
ignore_warning
(*warnings_constants)¶ Ignoring warnings context manager for the current resource.
Parameters: warnings_constants – constants identifying the warnings to ignore.
-
implementation_version
¶ - VI_ATTR_RSRC_IMPL_VERSION is the resource version that uniquely identifies
- each of the different 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, handler, user_handle=None)¶ Installs handlers for event callbacks in this resource.
Parameters: - event_type – Logical event identifier.
- handler – Interpreted as a valid reference to a handler to be installed by a client application.
- user_handle – A value specified by an application that can be used for identifying handlers uniquely for an event type.
Returns: user handle (a ctypes object)
-
interface_number
¶ VI_ATTR_INTF_NUM specifies the board number for the given interface.
VISA Attribute: VI_ATTR_INTF_NUM (1073676662) Type: int Range: 0 <= value <= 65535
-
interface_type
¶ The interface type of the resource as a number.
-
last_status
¶ Last status code for this session.
Return type: pyvisa.constants.StatusCode
-
lock
(timeout='default', requested_key=None)¶ Establish a shared lock to the resource.
Parameters: - timeout – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. (Defaults to self.timeout)
- requested_key – 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
-
lock_context
(timeout='default', requested_key='exclusive')¶ A context that locks
Parameters: - timeout – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. (Defaults to self.timeout)
- requested_key – 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.
The returned context is the access_key if applicable.
-
lock_excl
(timeout='default')¶ Establish an exclusive lock to the resource.
Parameters: timeout – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. (Defaults to self.timeout)
-
lock_state
¶ - VI_ATTR_RSRC_LOCK_STATE indicates the 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=<AccessModes.no_lock: 0>, open_timeout=5000)¶ Opens a session to the specified resource.
Parameters: - access_mode (
pyvisa.constants.AccessModes
) – Specifies the mode by which the resource is to be accessed. - open_timeout (int) – If the
access_mode
parameter requests a lock, then this parameter specifies the absolute time period (in milliseconds) that the resource waits to get unlocked before this operation returns an error.
- access_mode (
-
query
(message, delay=None)[source]¶ A combination of write(message) and read()
Parameters: - message (str) – the message to send.
- delay – delay in seconds between write and read operations. if None, defaults to self.query_delay
Returns: the answer from the device.
Return type:
-
query_ascii_values
(message, converter='f', separator=', ', container=<class 'list'>, delay=None)[source]¶ Query the device for values in ascii format returning an iterable of values.
Parameters: - message (str) – the message to send.
- delay – delay in seconds between write and read operations. if None, defaults to self.query_delay
- converter (callable) – function used to convert each element. Defaults to float
- separator – a callable that split the str into individual elements. If a str is given, data.split(separator) is used.
- container – container type to use for the output data.
Type: Returns: the answer from the device.
Return type:
-
query_binary_values
(message, datatype='f', is_big_endian=False, container=<class 'list'>, delay=None, header_fmt='ieee', expect_termination=True, data_points=0, chunk_size=None)[source]¶ Query the device for values in binary format returning an iterable of values.
Parameters: - message – the message to send to the instrument.
- datatype – the format string for a single element. See struct module.
- is_big_endian – boolean indicating endianess. Defaults to False.
- container – container type to use for the output data.
- delay – delay in seconds between write and read operations. if None, defaults to self.query_delay
- expect_termination – when set to False, the expected length of the binary values block does not account for the final termination character (the read termination)
- data_points – 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.
- chunk_size – Size of the chunks to read from the device. Using larger chunks may be faster for large amount of data.
Returns: the answer from the device.
Return type:
-
query_delay
= 0.0¶
-
query_values
(message, delay=None)[source]¶ Query the device for values returning an iterable of values.
The datatype expected is obtained from values_format
Parameters: - message (str) – the message to send.
- delay – delay in seconds between write and read operations. if None, defaults to self.query_delay
Returns: the answer from the device.
Return type:
-
read
(termination=None, encoding=None)[source]¶ Read a string from the device.
Reading stops when the device stops sending (e.g. by setting appropriate bus lines), or the termination characters sequence was detected. Attention: Only the last character of the termination characters is really used to stop reading, however, the whole sequence is compared to the ending of the read string message. If they don’t match, a warning is issued.
All line-ending characters are stripped from the end of the string.
Return type: str
-
read_ascii_values
(converter='f', separator=', ', container=<class 'list'>)[source]¶ Read values from the device in ascii format returning an iterable of values.
Parameters: - delay – delay in seconds between write and read operations. if None, defaults to self.query_delay
- converter (callable) – function used to convert each element. Defaults to float
- separator – a callable that split the str into individual elements. If a str is given, data.split(separator) is used.
- container – container type to use for the output data.
Type: Returns: the answer from the device.
Return type:
-
read_binary_values
(datatype='f', is_big_endian=False, container=<class 'list'>, header_fmt='ieee', expect_termination=True, data_points=0, chunk_size=None)[source]¶ Read values from the device in binary format returning an iterable of values.
Parameters: - datatype – the format string for a single element. See struct module.
- is_big_endian – boolean indicating endianess. Defaults to False.
- container – container type to use for the output data.
- header_fmt – format of the header prefixing the data. Possible values are: ‘ieee’, ‘hp’, ‘empty’
- expect_termination – when set to False, the expected length of the binary values block does not account for the final termination character (the read termination)
- data_points – 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.
- chunk_size – Size of the chunks to read from the device. Using larger chunks may be faster for large amount of data.
Returns: the answer from the device.
Return type: type(container)
-
read_bytes
(count, chunk_size=None, break_on_termchar=False)[source]¶ Read a certain number of bytes from the instrument.
Parameters: Return type:
-
read_raw
(size=None)[source]¶ Read the unmodified string sent from the instrument to the computer.
In contrast to read(), no termination characters are stripped.
Parameters: size – The chunk size to use when reading the data. Return type: bytes
-
read_termination
¶ Read termination character.
-
read_values
(fmt=None, container=<class 'list'>)[source]¶ Read a list of floating point values from the device.
Parameters: - fmt – the format of the values. If given, it overrides the class attribute “values_format”. Possible values are bitwise disjunctions of the above constants ascii, single, double, and big_endian. Default is ascii.
- container – the output datatype
Returns: the list of read values
Return type:
-
classmethod
register
(interface_type, resource_class)¶
-
resource_class
¶ - VI_ATTR_RSRC_CLASS specifies the resource class (for example, “INSTR”)
- as defined by the canonical resource name.
VISA Attribute: VI_ATTR_RSRC_CLASS (3221159937)
-
resource_info
¶ Get the extended information of this resource.
Parameters: resource_name – Unique symbolic name of a resource. Return type: pyvisa.highlevel.ResourceInfo
-
resource_manufacturer_name
¶ - VI_ATTR_RSRC_MANF_NAME is a string that corresponds to the 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
¶ - VI_ATTR_RSRC_MANF_NAME is a string that corresponds to the 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_NAME (3221159938)
-
session
¶ Resource session handle.
Raises: pyvisa.errors.InvalidSession
if session is closed.
-
set_visa_attribute
(name, state)¶ Sets the state of an attribute.
Parameters: - name – Attribute for which the state is to be modified. (Attributes.*)
- state – The state of the attribute to be set for the specified object.
Returns: return value of the library call.
Return type:
-
spec_version
¶ - VI_ATTR_RSRC_SPEC_VERSION is the resource version that uniquely identifies
- the 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
¶ The timeout in milliseconds for all resource I/O operations.
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 asfloat('+inf')
)
To set an infinite timeout, you can also use:
>>> del instrument.timeout
- immediate (
-
uninstall_handler
(event_type, handler, user_handle=None)¶ Uninstalls handlers for events in this resource.
Parameters: - event_type – Logical event identifier.
- handler – Interpreted as a valid reference to a handler to be uninstalled by a client application.
- user_handle – The user handle (ctypes object or None) returned by install_handler.
-
unlock
()¶ Relinquishes a lock for the specified resource.
-
values_format
¶
-
visa_attributes_classes
= [<class 'pyvisa.attributes.AttrVI_ATTR_INTF_INST_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_MAX_QUEUE_LENGTH'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_TYPE'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_RM_SESSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_CLASS'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_IMPL_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_LOCK_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_SPEC_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_TMO_VALUE'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_INST_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_MAX_QUEUE_LENGTH'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_TYPE'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_RM_SESSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_CLASS'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_IMPL_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_LOCK_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_SPEC_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_TMO_VALUE'>]¶
-
wait_on_event
(in_event_type, timeout, capture_timeout=False)¶ Waits for an occurrence of the specified event in this resource.
Parameters: - in_event_type – Logical identifier of the event(s) to wait for.
- timeout – Absolute time period in time units that the resource shall wait for a specified event to occur before returning the time elapsed error. The time unit is in milliseconds. None means waiting forever if necessary.
- capture_timeout – When True will not produce a VisaIOError(VI_ERROR_TMO) but instead return a WaitResponse with timed_out=True
Returns: A WaitResponse object that contains event_type, context and ret value.
-
write
(message, termination=None, encoding=None)[source]¶ Write a string message to the device.
The write_termination is always appended to it.
Parameters: Returns: number of bytes written.
Return type:
-
write_ascii_values
(message, values, converter='f', separator=', ', termination=None, encoding=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 (unicode (Py2) or str (Py3)) – the message to be sent.
- values – data to be writen to the device.
- converter (callable | str) – function used to convert each value. String formatting codes are also accepted. Defaults to ‘f’.
- separator – a callable that join the values in a single str. If a str is given, separator.join(values) is used.
Type: separator: (collections.Iterable[T]) -> str | str
Returns: number of bytes written.
Return type:
-
write_binary_values
(message, values, datatype='f', is_big_endian=False, termination=None, encoding=None, header_fmt='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 (unicode (Py2) or str (Py3)) – the message to be sent.
- values – data to be writen to the device.
- datatype – the format string for a single element. See struct module.
- is_big_endian – boolean indicating endianess.
- header_fmt – format of the header prefixing the data. Possible values are: ‘ieee’, ‘hp’, ‘empty’
Returns: number of bytes written.
Return type:
-
write_raw
(message)[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
¶ Writer termination character.
-
-
class
pyvisa.resources.
RegisterBasedResource
(resource_manager, resource_name)[source]¶ Base class for resources that use register based communication.
-
before_close
()¶ Called just before closing an instrument.
-
clear
()¶ Clears this resource
-
close
()¶ Closes the VISA session and marks the handle as invalid.
-
disable_event
(event_type, mechanism)¶ Disables notification of the specified event type(s) via the specified mechanism(s).
Parameters: - event_type – Logical event identifier.
- mechanism – Specifies event handling mechanisms to be disabled. (Constants.VI_QUEUE, .VI_HNDLR, .VI_SUSPEND_HNDLR, .VI_ALL_MECH)
-
discard_events
(event_type, mechanism)¶ Discards event occurrences for specified event types and mechanisms in this resource.
Parameters: - event_type – Logical event identifier.
- mechanism – Specifies event handling mechanisms to be dicarded. (Constants.VI_QUEUE, .VI_HNDLR, .VI_SUSPEND_HNDLR, .VI_ALL_MECH)
-
enable_event
(event_type, mechanism, context=None)¶ Enable event occurrences for specified event types and mechanisms in this resource.
Parameters: - event_type – Logical event identifier.
- mechanism – Specifies event handling mechanisms to be enabled. (Constants.VI_QUEUE, .VI_HNDLR, .VI_SUSPEND_HNDLR)
- context – Not currently used, leave as None.
-
get_visa_attribute
(name)¶ Retrieves the state of an attribute in this resource.
Parameters: name – Resource attribute for which the state query is made (see Attributes.*) Returns: The state of the queried attribute for a specified resource. Return type: unicode (Py2) or str (Py3), list or other type
-
ignore_warning
(*warnings_constants)¶ Ignoring warnings context manager for the current resource.
Parameters: warnings_constants – constants identifying the warnings to ignore.
-
implementation_version
¶ - VI_ATTR_RSRC_IMPL_VERSION is the resource version that uniquely identifies
- each of the different 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, handler, user_handle=None)¶ Installs handlers for event callbacks in this resource.
Parameters: - event_type – Logical event identifier.
- handler – Interpreted as a valid reference to a handler to be installed by a client application.
- user_handle – A value specified by an application that can be used for identifying handlers uniquely for an event type.
Returns: user handle (a ctypes object)
-
interface_number
¶ VI_ATTR_INTF_NUM specifies the board number for the given interface.
VISA Attribute: VI_ATTR_INTF_NUM (1073676662) Type: int Range: 0 <= value <= 65535
-
interface_type
¶ The interface type of the resource as a number.
-
last_status
¶ Last status code for this session.
Return type: pyvisa.constants.StatusCode
-
lock
(timeout='default', requested_key=None)¶ Establish a shared lock to the resource.
Parameters: - timeout – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. (Defaults to self.timeout)
- requested_key – 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
-
lock_context
(timeout='default', requested_key='exclusive')¶ A context that locks
Parameters: - timeout – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. (Defaults to self.timeout)
- requested_key – 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.
The returned context is the access_key if applicable.
-
lock_excl
(timeout='default')¶ Establish an exclusive lock to the resource.
Parameters: timeout – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. (Defaults to self.timeout)
-
lock_state
¶ - VI_ATTR_RSRC_LOCK_STATE indicates the 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, offset, length, width, extended=False)[source]¶ Moves a block of data to local memory from the specified address space and offset.
Parameters: - space – Specifies the address space. (Constants.*SPACE*)
- offset – Offset (in bytes) of the address or register from which to read.
- length – Number of elements to transfer, where the data width of the elements to transfer is identical to the source data width.
- width – Number of bits to read per element.
- extended – Use 64 bits offset independent of the platform.
-
move_out
(space, offset, length, data, width, extended=False)[source]¶ Moves a block of data from local memory to the specified address space and offset.
Parameters: - space – Specifies the address space. (Constants.*SPACE*)
- offset – Offset (in bytes) of the address or register from which to read.
- length – Number of elements to transfer, where the data width of the elements to transfer is identical to the source data width.
- data – Data to write to bus.
- width – Number of bits to read per element.
- extended – Use 64 bits offset independent of the platform.
-
open
(access_mode=<AccessModes.no_lock: 0>, open_timeout=5000)¶ Opens a session to the specified resource.
Parameters: - access_mode (
pyvisa.constants.AccessModes
) – Specifies the mode by which the resource is to be accessed. - open_timeout (int) – If the
access_mode
parameter requests a lock, then this parameter specifies the absolute time period (in milliseconds) that the resource waits to get unlocked before this operation returns an error.
- access_mode (
-
read_memory
(space, offset, width, extended=False)[source]¶ Reads in an 8-bit, 16-bit, 32-bit, or 64-bit value from the specified memory space and offset.
Parameters: - space – Specifies the address space. (Constants.*SPACE*)
- offset – Offset (in bytes) of the address or register from which to read.
- width – Number of bits to read.
- extended – Use 64 bits offset independent of the platform.
Returns: Data read from memory.
Corresponds to viIn* functions of the visa library.
-
classmethod
register
(interface_type, resource_class)¶
-
resource_class
¶ - VI_ATTR_RSRC_CLASS specifies the resource class (for example, “INSTR”)
- as defined by the canonical resource name.
VISA Attribute: VI_ATTR_RSRC_CLASS (3221159937)
-
resource_info
¶ Get the extended information of this resource.
Parameters: resource_name – Unique symbolic name of a resource. Return type: pyvisa.highlevel.ResourceInfo
-
resource_manufacturer_name
¶ - VI_ATTR_RSRC_MANF_NAME is a string that corresponds to the 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
¶ - VI_ATTR_RSRC_MANF_NAME is a string that corresponds to the 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_NAME (3221159938)
-
session
¶ Resource session handle.
Raises: pyvisa.errors.InvalidSession
if session is closed.
-
set_visa_attribute
(name, state)¶ Sets the state of an attribute.
Parameters: - name – Attribute for which the state is to be modified. (Attributes.*)
- state – The state of the attribute to be set for the specified object.
Returns: return value of the library call.
Return type:
-
spec_version
¶ - VI_ATTR_RSRC_SPEC_VERSION is the resource version that uniquely identifies
- the 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
¶ The timeout in milliseconds for all resource I/O operations.
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 asfloat('+inf')
)
To set an infinite timeout, you can also use:
>>> del instrument.timeout
- immediate (
-
uninstall_handler
(event_type, handler, user_handle=None)¶ Uninstalls handlers for events in this resource.
Parameters: - event_type – Logical event identifier.
- handler – Interpreted as a valid reference to a handler to be uninstalled by a client application.
- user_handle – The user handle (ctypes object or None) returned by install_handler.
-
unlock
()¶ Relinquishes a lock for the specified resource.
-
visa_attributes_classes
= [<class 'pyvisa.attributes.AttrVI_ATTR_INTF_INST_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_MAX_QUEUE_LENGTH'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_TYPE'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_RM_SESSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_CLASS'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_IMPL_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_LOCK_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_SPEC_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_TMO_VALUE'>]¶
-
wait_on_event
(in_event_type, timeout, capture_timeout=False)¶ Waits for an occurrence of the specified event in this resource.
Parameters: - in_event_type – Logical identifier of the event(s) to wait for.
- timeout – Absolute time period in time units that the resource shall wait for a specified event to occur before returning the time elapsed error. The time unit is in milliseconds. None means waiting forever if necessary.
- capture_timeout – When True will not produce a VisaIOError(VI_ERROR_TMO) but instead return a WaitResponse with timed_out=True
Returns: A WaitResponse object that contains event_type, context and ret value.
-
write_memory
(space, offset, data, width, extended=False)[source]¶ Write in an 8-bit, 16-bit, 32-bit, value to the specified memory space and offset.
Parameters: - space – Specifies the address space. (Constants.*SPACE*)
- offset – Offset (in bytes) of the address or register from which to read.
- data – Data to write to bus.
- width – Number of bits to read.
- extended – Use 64 bits offset independent of the platform.
Corresponds to viOut* functions of the visa library.
-
-
class
pyvisa.resources.
SerialInstrument
(*args, **kwargs)[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
¶ - This attribute specifies whether I/O accesses should use DMA (VI_TRUE)
- or Programmed I/O (VI_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
¶ - If set to VI_FALSE, it suspends transmission as if an XOFF character
- has been received. If set to VI_TRUE, it resumes transmission as if an XON character has been received.
VISA Attribute: VI_ATTR_ASRL_ALLOW_TRANSMIT (1073676734) Type: bool
-
assert_trigger
()¶ Sends a software trigger to the device.
-
baud_rate
¶ - VI_ATTR_ASRL_BAUD is the baud rate of the interface. It is represented
- as an unsigned 32-bit integer so that any baud rate can be used, but it usually requires a commonly used rate such as 300, 1200, 2400, or 9600 baud.
VISA Attribute: VI_ATTR_ASRL_BAUD (1073676321) Type: int Range: 0 <= value <= 4294967295
-
before_close
()¶ Called just before closing an instrument.
-
break_length
¶ - This controls the duration (in milliseconds) of the break signal
- asserted when VI_ATTR_ASRL_END_OUT is set to VI_ASRL_END_BREAK. If you want to control the assertion state and length of a break signal manually, use the VI_ATTR_ASRL_BREAK_STATE attribute instead.
VISA Attribute: VI_ATTR_ASRL_BREAK_LEN (1073676733) Type: int Range: -32768 <= value <= 32767
-
break_state
¶ - If set to VI_STATE_ASSERTED, it suspends character transmission and
- places the transmission line in a break state until this attribute is reset to VI_STATE_UNASSERTED. This attribute lets you manually control the assertion state and length of a break signal. If you want VISA to send a break signal after each write operation automatically, use the VI_ATTR_ASRL_BREAK_LEN and VI_ATTR_ASRL_END_OUT attributes instead.
VISA Attribute: VI_ATTR_ASRL_BREAK_STATE (1073676732) Type: :class:pyvisa.constants.LineState
-
bytes_in_buffer
¶ - VI_ATTR_ASRL_AVAIL_NUM shows the number of bytes available in the low-
- level I/O receive buffer.
VISA Attribute: VI_ATTR_ASRL_AVAIL_NUM (1073676460) Type: int Range: 0 <= value <= 4294967295
-
chunk_size
= 20480¶
-
clear
()¶ Clears this resource
-
close
()¶ Closes the VISA session and marks the handle as invalid.
-
data_bits
¶ - VI_ATTR_ASRL_DATA_BITS is the number of data bits contained in each
- frame (from 5 to 8). The data bits for each frame are located in the low-order bits of every byte stored in memory.
VISA Attribute: VI_ATTR_ASRL_DATA_BITS (1073676322) Type: int Range: 5 <= value <= 8
-
disable_event
(event_type, mechanism)¶ Disables notification of the specified event type(s) via the specified mechanism(s).
Parameters: - event_type – Logical event identifier.
- mechanism – Specifies event handling mechanisms to be disabled. (Constants.VI_QUEUE, .VI_HNDLR, .VI_SUSPEND_HNDLR, .VI_ALL_MECH)
-
discard_events
(event_type, mechanism)¶ Discards event occurrences for specified event types and mechanisms in this resource.
Parameters: - event_type – Logical event identifier.
- mechanism – Specifies event handling mechanisms to be dicarded. (Constants.VI_QUEUE, .VI_HNDLR, .VI_SUSPEND_HNDLR, .VI_ALL_MECH)
-
discard_null
¶ - If set to VI_TRUE, NUL characters are discarded. Otherwise, they are
- treated as normal data characters. For binary transfers, set this attribute to VI_FALSE.
VISA Attribute: VI_ATTR_ASRL_DISCARD_NULL (1073676464) Type: bool
-
enable_event
(event_type, mechanism, context=None)¶ Enable event occurrences for specified event types and mechanisms in this resource.
Parameters: - event_type – Logical event identifier.
- mechanism – Specifies event handling mechanisms to be enabled. (Constants.VI_QUEUE, .VI_HNDLR, .VI_SUSPEND_HNDLR)
- context – Not currently used, leave as None.
-
encoding
¶ Encoding used for read and write operations.
-
end_input
¶ - VI_ATTR_ASRL_END_IN indicates the method used to terminate read
- operations.
VISA Attribute: VI_ATTR_ASRL_END_IN (1073676467) Type: :class:pyvisa.constants.SerialTermination
-
flow_control
¶ - VI_ATTR_ASRL_FLOW_CNTRL indicates the type of flow control used by the
- transfer mechanism.
VISA Attribute: VI_ATTR_ASRL_FLOW_CNTRL (1073676325) Type: int Range: 0 <= value <= 65535
-
flush
(mask)¶ 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 – Specifies the action to be taken with flushing the buffer. See highlevel.VisaLibraryBase.flush for a detailed description.
-
get_visa_attribute
(name)¶ Retrieves the state of an attribute in this resource.
Parameters: name – Resource attribute for which the state query is made (see Attributes.*) Returns: The state of the queried attribute for a specified resource. Return type: unicode (Py2) or str (Py3), list or other type
-
ignore_warning
(*warnings_constants)¶ Ignoring warnings context manager for the current resource.
Parameters: warnings_constants – constants identifying the warnings to ignore.
-
implementation_version
¶ - VI_ATTR_RSRC_IMPL_VERSION is the resource version that uniquely identifies
- each of the different 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, handler, user_handle=None)¶ Installs handlers for event callbacks in this resource.
Parameters: - event_type – Logical event identifier.
- handler – Interpreted as a valid reference to a handler to be installed by a client application.
- user_handle – A value specified by an application that can be used for identifying handlers uniquely for an event type.
Returns: user handle (a ctypes object)
-
interface_number
¶ VI_ATTR_INTF_NUM specifies the board number for the given interface.
VISA Attribute: VI_ATTR_INTF_NUM (1073676662) Type: int Range: 0 <= value <= 65535
-
interface_type
¶ The interface type of the resource as a number.
-
io_protocol
¶ - VI_ATTR_IO_PROT specifies which 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: int Range: 0 <= value <= 65535
-
last_status
¶ Last status code for this session.
Return type: pyvisa.constants.StatusCode
-
lock
(timeout='default', requested_key=None)¶ Establish a shared lock to the resource.
Parameters: - timeout – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. (Defaults to self.timeout)
- requested_key – 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
-
lock_context
(timeout='default', requested_key='exclusive')¶ A context that locks
Parameters: - timeout – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. (Defaults to self.timeout)
- requested_key – 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.
The returned context is the access_key if applicable.
-
lock_excl
(timeout='default')¶ Establish an exclusive lock to the resource.
Parameters: timeout – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. (Defaults to self.timeout)
-
lock_state
¶ - VI_ATTR_RSRC_LOCK_STATE indicates the 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=<AccessModes.no_lock: 0>, open_timeout=5000)¶ Opens a session to the specified resource.
Parameters: - access_mode (
pyvisa.constants.AccessModes
) – Specifies the mode by which the resource is to be accessed. - open_timeout (int) – If the
access_mode
parameter requests a lock, then this parameter specifies the absolute time period (in milliseconds) that the resource waits to get unlocked before this operation returns an error.
- access_mode (
-
parity
¶ - VI_ATTR_ASRL_PARITY is the parity used with every frame transmitted
- and received.
VISA Attribute: VI_ATTR_ASRL_PARITY (1073676323) Type: :class:pyvisa.constants.Parity
-
query
(message, delay=None)¶ A combination of write(message) and read()
Parameters: - message (str) – the message to send.
- delay – delay in seconds between write and read operations. if None, defaults to self.query_delay
Returns: the answer from the device.
Return type:
-
query_ascii_values
(message, converter='f', separator=', ', container=<class 'list'>, delay=None)¶ Query the device for values in ascii format returning an iterable of values.
Parameters: - message (str) – the message to send.
- delay – delay in seconds between write and read operations. if None, defaults to self.query_delay
- converter (callable) – function used to convert each element. Defaults to float
- separator – a callable that split the str into individual elements. If a str is given, data.split(separator) is used.
- container – container type to use for the output data.
Type: Returns: the answer from the device.
Return type:
-
query_binary_values
(message, datatype='f', is_big_endian=False, container=<class 'list'>, delay=None, header_fmt='ieee', expect_termination=True, data_points=0, chunk_size=None)¶ Query the device for values in binary format returning an iterable of values.
Parameters: - message – the message to send to the instrument.
- datatype – the format string for a single element. See struct module.
- is_big_endian – boolean indicating endianess. Defaults to False.
- container – container type to use for the output data.
- delay – delay in seconds between write and read operations. if None, defaults to self.query_delay
- expect_termination – when set to False, the expected length of the binary values block does not account for the final termination character (the read termination)
- data_points – 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.
- chunk_size – Size of the chunks to read from the device. Using larger chunks may be faster for large amount of data.
Returns: the answer from the device.
Return type:
-
query_delay
= 0.0¶
-
query_values
(message, delay=None)¶ Query the device for values returning an iterable of values.
The datatype expected is obtained from values_format
Parameters: - message (str) – the message to send.
- delay – delay in seconds between write and read operations. if None, defaults to self.query_delay
Returns: the answer from the device.
Return type:
-
read
(termination=None, encoding=None)¶ Read a string from the device.
Reading stops when the device stops sending (e.g. by setting appropriate bus lines), or the termination characters sequence was detected. Attention: Only the last character of the termination characters is really used to stop reading, however, the whole sequence is compared to the ending of the read string message. If they don’t match, a warning is issued.
All line-ending characters are stripped from the end of the string.
Return type: str
-
read_ascii_values
(converter='f', separator=', ', container=<class 'list'>)¶ Read values from the device in ascii format returning an iterable of values.
Parameters: - delay – delay in seconds between write and read operations. if None, defaults to self.query_delay
- converter (callable) – function used to convert each element. Defaults to float
- separator – a callable that split the str into individual elements. If a str is given, data.split(separator) is used.
- container – container type to use for the output data.
Type: Returns: the answer from the device.
Return type:
-
read_binary_values
(datatype='f', is_big_endian=False, container=<class 'list'>, header_fmt='ieee', expect_termination=True, data_points=0, chunk_size=None)¶ Read values from the device in binary format returning an iterable of values.
Parameters: - datatype – the format string for a single element. See struct module.
- is_big_endian – boolean indicating endianess. Defaults to False.
- container – container type to use for the output data.
- header_fmt – format of the header prefixing the data. Possible values are: ‘ieee’, ‘hp’, ‘empty’
- expect_termination – when set to False, the expected length of the binary values block does not account for the final termination character (the read termination)
- data_points – 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.
- chunk_size – Size of the chunks to read from the device. Using larger chunks may be faster for large amount of data.
Returns: the answer from the device.
Return type: type(container)
-
read_bytes
(count, chunk_size=None, break_on_termchar=False)¶ Read a certain number of bytes from the instrument.
Parameters: Return type:
-
read_raw
(size=None)¶ Read the unmodified string sent from the instrument to the computer.
In contrast to read(), no termination characters are stripped.
Parameters: size – The chunk size to use when reading the data. Return type: bytes
-
read_stb
()¶ Service request status register.
-
read_termination
¶ Read termination character.
-
read_termination_context
(new_termination)¶
-
read_values
(fmt=None, container=<class 'list'>)¶ Read a list of floating point values from the device.
Parameters: - fmt – the format of the values. If given, it overrides the class attribute “values_format”. Possible values are bitwise disjunctions of the above constants ascii, single, double, and big_endian. Default is ascii.
- container – the output datatype
Returns: the list of read values
Return type:
-
classmethod
register
(interface_type, resource_class)¶
-
replace_char
¶ - VI_ATTR_ASRL_REPLACE_CHAR specifies the character to be used to
- replace incoming characters that arrive with errors (such as parity error).
VISA Attribute: VI_ATTR_ASRL_REPLACE_CHAR (1073676478) Type: int Range: 0 <= value <= 255
-
resource_class
¶ - VI_ATTR_RSRC_CLASS specifies the resource class (for example, “INSTR”)
- as defined by the canonical resource name.
VISA Attribute: VI_ATTR_RSRC_CLASS (3221159937)
-
resource_info
¶ Get the extended information of this resource.
Parameters: resource_name – Unique symbolic name of a resource. Return type: pyvisa.highlevel.ResourceInfo
-
resource_manufacturer_name
¶ - VI_ATTR_RSRC_MANF_NAME is a string that corresponds to the 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
¶ - VI_ATTR_RSRC_MANF_NAME is a string that corresponds to the 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_NAME (3221159938)
-
send_end
¶ - VI_ATTR_SEND_END_EN specifies whether to assert END 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: pyvisa.errors.InvalidSession
if session is closed.
-
set_visa_attribute
(name, state)¶ Sets the state of an attribute.
Parameters: - name – Attribute for which the state is to be modified. (Attributes.*)
- state – The state of the attribute to be set for the specified object.
Returns: return value of the library call.
Return type:
-
spec_version
¶ - VI_ATTR_RSRC_SPEC_VERSION is the resource version that uniquely identifies
- the 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
¶ - VI_ATTR_ASRL_STOP_BITS is the number of stop bits used to indicate the
- end of a frame. The value VI_ASRL_STOP_ONE5 indicates one-and-one- half (1.5) stop bits.
VISA Attribute: VI_ATTR_ASRL_STOP_BITS (1073676324) Type: :class:pyvisa.constants.StopBits
-
timeout
¶ The timeout in milliseconds for all resource I/O operations.
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 asfloat('+inf')
)
To set an infinite timeout, you can also use:
>>> del instrument.timeout
- immediate (
-
uninstall_handler
(event_type, handler, user_handle=None)¶ Uninstalls handlers for events in this resource.
Parameters: - event_type – Logical event identifier.
- handler – Interpreted as a valid reference to a handler to be uninstalled by a client application.
- user_handle – The user handle (ctypes object or None) returned by install_handler.
-
unlock
()¶ Relinquishes a lock for the specified resource.
-
values_format
¶
-
visa_attributes_classes
= [<class 'pyvisa.attributes.AttrVI_ATTR_INTF_INST_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_MAX_QUEUE_LENGTH'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_TYPE'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_RM_SESSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_CLASS'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_IMPL_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_LOCK_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_SPEC_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_TMO_VALUE'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_INST_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_MAX_QUEUE_LENGTH'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_TYPE'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_RM_SESSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_CLASS'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_IMPL_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_LOCK_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_SPEC_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_TMO_VALUE'>, <class 'pyvisa.attributes.AttrVI_ATTR_WR_BUF_SIZE'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_BAUD'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_REPLACE_CHAR'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_DATA_BITS'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_XON_CHAR'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_END_OUT'>, <class 'pyvisa.attributes.AttrVI_ATTR_TRIG_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_PARITY'>, <class 'pyvisa.attributes.AttrVI_ATTR_IO_PROT'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_AVAIL_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_STOP_BITS'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_CTS_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_WIRE_MODE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RD_BUF_SIZE'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_END_IN'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_BREAK_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_ALLOW_TRANSMIT'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_RTS_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_CONNECTED'>, <class 'pyvisa.attributes.AttrVI_ATTR_RD_BUF_OPER_MODE'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_XOFF_CHAR'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_DTR_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_SUPPRESS_END_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_TERMCHAR_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_WR_BUF_OPER_MODE'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_BREAK_LEN'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_RI_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_DCD_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_DISCARD_NULL'>, <class 'pyvisa.attributes.AttrVI_ATTR_DMA_ALLOW_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_DSR_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_ASRL_FLOW_CNTRL'>, <class 'pyvisa.attributes.AttrVI_ATTR_SEND_END_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_TERMCHAR'>, <class 'pyvisa.attributes.AttrVI_ATTR_FILE_APPEND_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_INST_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_MAX_QUEUE_LENGTH'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_TYPE'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_RM_SESSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_CLASS'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_IMPL_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_LOCK_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_SPEC_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_TMO_VALUE'>]¶
-
wait_on_event
(in_event_type, timeout, capture_timeout=False)¶ Waits for an occurrence of the specified event in this resource.
Parameters: - in_event_type – Logical identifier of the event(s) to wait for.
- timeout – Absolute time period in time units that the resource shall wait for a specified event to occur before returning the time elapsed error. The time unit is in milliseconds. None means waiting forever if necessary.
- capture_timeout – When True will not produce a VisaIOError(VI_ERROR_TMO) but instead return a WaitResponse with timed_out=True
Returns: A WaitResponse object that contains event_type, context and ret value.
-
write
(message, termination=None, encoding=None)¶ Write a string message to the device.
The write_termination is always appended to it.
Parameters: Returns: number of bytes written.
Return type:
-
write_ascii_values
(message, values, converter='f', separator=', ', termination=None, encoding=None)¶ Write a string message to the device followed by values in ascii format.
The write_termination is always appended to it.
Parameters: - message (unicode (Py2) or str (Py3)) – the message to be sent.
- values – data to be writen to the device.
- converter (callable | str) – function used to convert each value. String formatting codes are also accepted. Defaults to ‘f’.
- separator – a callable that join the values in a single str. If a str is given, separator.join(values) is used.
Type: separator: (collections.Iterable[T]) -> str | str
Returns: number of bytes written.
Return type:
-
write_binary_values
(message, values, datatype='f', is_big_endian=False, termination=None, encoding=None, header_fmt='ieee')¶ Write a string message to the device followed by values in binary format.
The write_termination is always appended to it.
Parameters: - message (unicode (Py2) or str (Py3)) – the message to be sent.
- values – data to be writen to the device.
- datatype – the format string for a single element. See struct module.
- is_big_endian – boolean indicating endianess.
- header_fmt – format of the header prefixing the data. Possible values are: ‘ieee’, ‘hp’, ‘empty’
Returns: number of bytes written.
Return type:
-
write_raw
(message)¶ 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
¶ Writer termination character.
-
write_values
(message, values, termination=None, encoding=None)¶
-
xoff_char
¶ - VI_ATTR_ASRL_XOFF_CHAR specifies the value of the XOFF character used
- for XON/XOFF flow control (both directions). If XON/XOFF flow control (software handshaking) is not being used, the value of this attribute is ignored.
VISA Attribute: VI_ATTR_ASRL_XOFF_CHAR (1073676482) Type: int Range: 0 <= value <= 255
-
xon_char
¶ - VI_ATTR_ASRL_XON_CHAR specifies the value of the XON character used
- for XON/XOFF flow control (both directions). If XON/XOFF flow control (software handshaking) is not being used, the value of this attribute is ignored.
VISA Attribute: VI_ATTR_ASRL_XON_CHAR (1073676481) Type: int Range: 0 <= value <= 255
-
-
class
pyvisa.resources.
TCPIPInstrument
(*args, **kwargs)[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
¶ - This attribute specifies whether I/O accesses should use DMA (VI_TRUE)
- or Programmed I/O (VI_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
()¶ Sends a software trigger to the device.
-
before_close
()¶ Called just before closing an instrument.
-
chunk_size
= 20480¶
-
clear
()¶ Clears this resource
-
close
()¶ Closes the VISA session and marks the handle as invalid.
-
control_ren
(mode)¶ Controls the state of the GPIB Remote Enable (REN) interface line, and optionally the remote/local state of the device.
Corresponds to viGpibControlREN function of the VISA library.
Parameters: mode – Specifies the state of the REN line and optionally the device remote/local state. (Constants.GPIB_REN*) Returns: return value of the library call. Return type: VISAStatus
-
disable_event
(event_type, mechanism)¶ Disables notification of the specified event type(s) via the specified mechanism(s).
Parameters: - event_type – Logical event identifier.
- mechanism – Specifies event handling mechanisms to be disabled. (Constants.VI_QUEUE, .VI_HNDLR, .VI_SUSPEND_HNDLR, .VI_ALL_MECH)
-
discard_events
(event_type, mechanism)¶ Discards event occurrences for specified event types and mechanisms in this resource.
Parameters: - event_type – Logical event identifier.
- mechanism – Specifies event handling mechanisms to be dicarded. (Constants.VI_QUEUE, .VI_HNDLR, .VI_SUSPEND_HNDLR, .VI_ALL_MECH)
-
enable_event
(event_type, mechanism, context=None)¶ Enable event occurrences for specified event types and mechanisms in this resource.
Parameters: - event_type – Logical event identifier.
- mechanism – Specifies event handling mechanisms to be enabled. (Constants.VI_QUEUE, .VI_HNDLR, .VI_SUSPEND_HNDLR)
- context – Not currently used, leave as None.
-
encoding
¶ Encoding used for read and write operations.
-
flush
(mask)¶ 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 – Specifies the action to be taken with flushing the buffer. See highlevel.VisaLibraryBase.flush for a detailed description.
-
get_visa_attribute
(name)¶ Retrieves the state of an attribute in this resource.
Parameters: name – Resource attribute for which the state query is made (see Attributes.*) Returns: The state of the queried attribute for a specified resource. Return type: unicode (Py2) or str (Py3), list or other type
-
ignore_warning
(*warnings_constants)¶ Ignoring warnings context manager for the current resource.
Parameters: warnings_constants – constants identifying the warnings to ignore.
-
implementation_version
¶ - VI_ATTR_RSRC_IMPL_VERSION is the resource version that uniquely identifies
- each of the different 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, handler, user_handle=None)¶ Installs handlers for event callbacks in this resource.
Parameters: - event_type – Logical event identifier.
- handler – Interpreted as a valid reference to a handler to be installed by a client application.
- user_handle – A value specified by an application that can be used for identifying handlers uniquely for an event type.
Returns: user handle (a ctypes object)
-
interface_number
¶ VI_ATTR_INTF_NUM specifies the board number for the given interface.
VISA Attribute: VI_ATTR_INTF_NUM (1073676662) Type: int Range: 0 <= value <= 65535
-
interface_type
¶ The interface type of the resource as a number.
-
last_status
¶ Last status code for this session.
Return type: pyvisa.constants.StatusCode
-
lock
(timeout='default', requested_key=None)¶ Establish a shared lock to the resource.
Parameters: - timeout – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. (Defaults to self.timeout)
- requested_key – 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
-
lock_context
(timeout='default', requested_key='exclusive')¶ A context that locks
Parameters: - timeout – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. (Defaults to self.timeout)
- requested_key – 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.
The returned context is the access_key if applicable.
-
lock_excl
(timeout='default')¶ Establish an exclusive lock to the resource.
Parameters: timeout – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. (Defaults to self.timeout)
-
lock_state
¶ - VI_ATTR_RSRC_LOCK_STATE indicates the 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=<AccessModes.no_lock: 0>, open_timeout=5000)¶ Opens a session to the specified resource.
Parameters: - access_mode (
pyvisa.constants.AccessModes
) – Specifies the mode by which the resource is to be accessed. - open_timeout (int) – If the
access_mode
parameter requests a lock, then this parameter specifies the absolute time period (in milliseconds) that the resource waits to get unlocked before this operation returns an error.
- access_mode (
-
query
(message, delay=None)¶ A combination of write(message) and read()
Parameters: - message (str) – the message to send.
- delay – delay in seconds between write and read operations. if None, defaults to self.query_delay
Returns: the answer from the device.
Return type:
-
query_ascii_values
(message, converter='f', separator=', ', container=<class 'list'>, delay=None)¶ Query the device for values in ascii format returning an iterable of values.
Parameters: - message (str) – the message to send.
- delay – delay in seconds between write and read operations. if None, defaults to self.query_delay
- converter (callable) – function used to convert each element. Defaults to float
- separator – a callable that split the str into individual elements. If a str is given, data.split(separator) is used.
- container – container type to use for the output data.
Type: Returns: the answer from the device.
Return type:
-
query_binary_values
(message, datatype='f', is_big_endian=False, container=<class 'list'>, delay=None, header_fmt='ieee', expect_termination=True, data_points=0, chunk_size=None)¶ Query the device for values in binary format returning an iterable of values.
Parameters: - message – the message to send to the instrument.
- datatype – the format string for a single element. See struct module.
- is_big_endian – boolean indicating endianess. Defaults to False.
- container – container type to use for the output data.
- delay – delay in seconds between write and read operations. if None, defaults to self.query_delay
- expect_termination – when set to False, the expected length of the binary values block does not account for the final termination character (the read termination)
- data_points – 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.
- chunk_size – Size of the chunks to read from the device. Using larger chunks may be faster for large amount of data.
Returns: the answer from the device.
Return type:
-
query_delay
= 0.0¶
-
query_values
(message, delay=None)¶ Query the device for values returning an iterable of values.
The datatype expected is obtained from values_format
Parameters: - message (str) – the message to send.
- delay – delay in seconds between write and read operations. if None, defaults to self.query_delay
Returns: the answer from the device.
Return type:
-
read
(termination=None, encoding=None)¶ Read a string from the device.
Reading stops when the device stops sending (e.g. by setting appropriate bus lines), or the termination characters sequence was detected. Attention: Only the last character of the termination characters is really used to stop reading, however, the whole sequence is compared to the ending of the read string message. If they don’t match, a warning is issued.
All line-ending characters are stripped from the end of the string.
Return type: str
-
read_ascii_values
(converter='f', separator=', ', container=<class 'list'>)¶ Read values from the device in ascii format returning an iterable of values.
Parameters: - delay – delay in seconds between write and read operations. if None, defaults to self.query_delay
- converter (callable) – function used to convert each element. Defaults to float
- separator – a callable that split the str into individual elements. If a str is given, data.split(separator) is used.
- container – container type to use for the output data.
Type: Returns: the answer from the device.
Return type:
-
read_binary_values
(datatype='f', is_big_endian=False, container=<class 'list'>, header_fmt='ieee', expect_termination=True, data_points=0, chunk_size=None)¶ Read values from the device in binary format returning an iterable of values.
Parameters: - datatype – the format string for a single element. See struct module.
- is_big_endian – boolean indicating endianess. Defaults to False.
- container – container type to use for the output data.
- header_fmt – format of the header prefixing the data. Possible values are: ‘ieee’, ‘hp’, ‘empty’
- expect_termination – when set to False, the expected length of the binary values block does not account for the final termination character (the read termination)
- data_points – 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.
- chunk_size – Size of the chunks to read from the device. Using larger chunks may be faster for large amount of data.
Returns: the answer from the device.
Return type: type(container)
-
read_bytes
(count, chunk_size=None, break_on_termchar=False)¶ Read a certain number of bytes from the instrument.
Parameters: Return type:
-
read_raw
(size=None)¶ Read the unmodified string sent from the instrument to the computer.
In contrast to read(), no termination characters are stripped.
Parameters: size – The chunk size to use when reading the data. Return type: bytes
-
read_stb
()¶ Service request status register.
-
read_termination
¶ Read termination character.
-
read_termination_context
(new_termination)¶
-
read_values
(fmt=None, container=<class 'list'>)¶ Read a list of floating point values from the device.
Parameters: - fmt – the format of the values. If given, it overrides the class attribute “values_format”. Possible values are bitwise disjunctions of the above constants ascii, single, double, and big_endian. Default is ascii.
- container – the output datatype
Returns: the list of read values
Return type:
-
classmethod
register
(interface_type, resource_class)¶
-
resource_class
¶ - VI_ATTR_RSRC_CLASS specifies the resource class (for example, “INSTR”)
- as defined by the canonical resource name.
VISA Attribute: VI_ATTR_RSRC_CLASS (3221159937)
-
resource_info
¶ Get the extended information of this resource.
Parameters: resource_name – Unique symbolic name of a resource. Return type: pyvisa.highlevel.ResourceInfo
-
resource_manufacturer_name
¶ - VI_ATTR_RSRC_MANF_NAME is a string that corresponds to the 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
¶ - VI_ATTR_RSRC_MANF_NAME is a string that corresponds to the 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_NAME (3221159938)
-
send_end
¶ - VI_ATTR_SEND_END_EN specifies whether to assert END 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: pyvisa.errors.InvalidSession
if session is closed.
-
set_visa_attribute
(name, state)¶ Sets the state of an attribute.
Parameters: - name – Attribute for which the state is to be modified. (Attributes.*)
- state – The state of the attribute to be set for the specified object.
Returns: return value of the library call.
Return type:
-
spec_version
¶ - VI_ATTR_RSRC_SPEC_VERSION is the resource version that uniquely identifies
- the 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
¶ The timeout in milliseconds for all resource I/O operations.
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 asfloat('+inf')
)
To set an infinite timeout, you can also use:
>>> del instrument.timeout
- immediate (
-
uninstall_handler
(event_type, handler, user_handle=None)¶ Uninstalls handlers for events in this resource.
Parameters: - event_type – Logical event identifier.
- handler – Interpreted as a valid reference to a handler to be uninstalled by a client application.
- user_handle – The user handle (ctypes object or None) returned by install_handler.
-
unlock
()¶ Relinquishes a lock for the specified resource.
-
values_format
¶
-
visa_attributes_classes
= [<class 'pyvisa.attributes.AttrVI_ATTR_INTF_INST_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_MAX_QUEUE_LENGTH'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_TYPE'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_RM_SESSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_CLASS'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_IMPL_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_LOCK_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_SPEC_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_TMO_VALUE'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_INST_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_MAX_QUEUE_LENGTH'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_TYPE'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_RM_SESSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_CLASS'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_IMPL_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_LOCK_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_SPEC_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_TMO_VALUE'>, <class 'pyvisa.attributes.AttrVI_ATTR_TCPIP_HOSTNAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_WR_BUF_SIZE'>, <class 'pyvisa.attributes.AttrVI_ATTR_TERMCHAR'>, <class 'pyvisa.attributes.AttrVI_ATTR_RD_BUF_OPER_MODE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RD_BUF_SIZE'>, <class 'pyvisa.attributes.AttrVI_ATTR_DMA_ALLOW_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_TERMCHAR_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_SEND_END_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_TCPIP_ADDR'>, <class 'pyvisa.attributes.AttrVI_ATTR_TRIG_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_FILE_APPEND_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_TCPIP_DEVICE_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_WR_BUF_OPER_MODE'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_INST_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_MAX_QUEUE_LENGTH'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_TYPE'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_RM_SESSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_CLASS'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_IMPL_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_LOCK_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_SPEC_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_TMO_VALUE'>]¶
-
wait_on_event
(in_event_type, timeout, capture_timeout=False)¶ Waits for an occurrence of the specified event in this resource.
Parameters: - in_event_type – Logical identifier of the event(s) to wait for.
- timeout – Absolute time period in time units that the resource shall wait for a specified event to occur before returning the time elapsed error. The time unit is in milliseconds. None means waiting forever if necessary.
- capture_timeout – When True will not produce a VisaIOError(VI_ERROR_TMO) but instead return a WaitResponse with timed_out=True
Returns: A WaitResponse object that contains event_type, context and ret value.
-
write
(message, termination=None, encoding=None)¶ Write a string message to the device.
The write_termination is always appended to it.
Parameters: Returns: number of bytes written.
Return type:
-
write_ascii_values
(message, values, converter='f', separator=', ', termination=None, encoding=None)¶ Write a string message to the device followed by values in ascii format.
The write_termination is always appended to it.
Parameters: - message (unicode (Py2) or str (Py3)) – the message to be sent.
- values – data to be writen to the device.
- converter (callable | str) – function used to convert each value. String formatting codes are also accepted. Defaults to ‘f’.
- separator – a callable that join the values in a single str. If a str is given, separator.join(values) is used.
Type: separator: (collections.Iterable[T]) -> str | str
Returns: number of bytes written.
Return type:
-
write_binary_values
(message, values, datatype='f', is_big_endian=False, termination=None, encoding=None, header_fmt='ieee')¶ Write a string message to the device followed by values in binary format.
The write_termination is always appended to it.
Parameters: - message (unicode (Py2) or str (Py3)) – the message to be sent.
- values – data to be writen to the device.
- datatype – the format string for a single element. See struct module.
- is_big_endian – boolean indicating endianess.
- header_fmt – format of the header prefixing the data. Possible values are: ‘ieee’, ‘hp’, ‘empty’
Returns: number of bytes written.
Return type:
-
write_raw
(message)¶ 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
¶ Writer termination character.
-
write_values
(message, values, termination=None, encoding=None)¶
-
class
pyvisa.resources.
TCPIPSocket
(*args, **kwargs)[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'¶
-
assert_trigger
()¶ Sends a software trigger to the device.
-
before_close
()¶ Called just before closing an instrument.
-
chunk_size
= 20480¶
-
clear
()¶ Clears this resource
-
close
()¶ Closes the VISA session and marks the handle as invalid.
-
disable_event
(event_type, mechanism)¶ Disables notification of the specified event type(s) via the specified mechanism(s).
Parameters: - event_type – Logical event identifier.
- mechanism – Specifies event handling mechanisms to be disabled. (Constants.VI_QUEUE, .VI_HNDLR, .VI_SUSPEND_HNDLR, .VI_ALL_MECH)
-
discard_events
(event_type, mechanism)¶ Discards event occurrences for specified event types and mechanisms in this resource.
Parameters: - event_type – Logical event identifier.
- mechanism – Specifies event handling mechanisms to be dicarded. (Constants.VI_QUEUE, .VI_HNDLR, .VI_SUSPEND_HNDLR, .VI_ALL_MECH)
-
enable_event
(event_type, mechanism, context=None)¶ Enable event occurrences for specified event types and mechanisms in this resource.
Parameters: - event_type – Logical event identifier.
- mechanism – Specifies event handling mechanisms to be enabled. (Constants.VI_QUEUE, .VI_HNDLR, .VI_SUSPEND_HNDLR)
- context – Not currently used, leave as None.
-
encoding
¶ Encoding used for read and write operations.
-
flush
(mask)¶ 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 – Specifies the action to be taken with flushing the buffer. See highlevel.VisaLibraryBase.flush for a detailed description.
-
get_visa_attribute
(name)¶ Retrieves the state of an attribute in this resource.
Parameters: name – Resource attribute for which the state query is made (see Attributes.*) Returns: The state of the queried attribute for a specified resource. Return type: unicode (Py2) or str (Py3), list or other type
-
ignore_warning
(*warnings_constants)¶ Ignoring warnings context manager for the current resource.
Parameters: warnings_constants – constants identifying the warnings to ignore.
-
implementation_version
¶ - VI_ATTR_RSRC_IMPL_VERSION is the resource version that uniquely identifies
- each of the different 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, handler, user_handle=None)¶ Installs handlers for event callbacks in this resource.
Parameters: - event_type – Logical event identifier.
- handler – Interpreted as a valid reference to a handler to be installed by a client application.
- user_handle – A value specified by an application that can be used for identifying handlers uniquely for an event type.
Returns: user handle (a ctypes object)
-
interface_number
¶ VI_ATTR_INTF_NUM specifies the board number for the given interface.
VISA Attribute: VI_ATTR_INTF_NUM (1073676662) Type: int Range: 0 <= value <= 65535
-
interface_type
¶ The interface type of the resource as a number.
-
io_protocol
¶ - VI_ATTR_IO_PROT specifies which 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: int Range: 0 <= value <= 65535
-
last_status
¶ Last status code for this session.
Return type: pyvisa.constants.StatusCode
-
lock
(timeout='default', requested_key=None)¶ Establish a shared lock to the resource.
Parameters: - timeout – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. (Defaults to self.timeout)
- requested_key – 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
-
lock_context
(timeout='default', requested_key='exclusive')¶ A context that locks
Parameters: - timeout – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. (Defaults to self.timeout)
- requested_key – 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.
The returned context is the access_key if applicable.
-
lock_excl
(timeout='default')¶ Establish an exclusive lock to the resource.
Parameters: timeout – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. (Defaults to self.timeout)
-
lock_state
¶ - VI_ATTR_RSRC_LOCK_STATE indicates the 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=<AccessModes.no_lock: 0>, open_timeout=5000)¶ Opens a session to the specified resource.
Parameters: - access_mode (
pyvisa.constants.AccessModes
) – Specifies the mode by which the resource is to be accessed. - open_timeout (int) – If the
access_mode
parameter requests a lock, then this parameter specifies the absolute time period (in milliseconds) that the resource waits to get unlocked before this operation returns an error.
- access_mode (
-
query
(message, delay=None)¶ A combination of write(message) and read()
Parameters: - message (str) – the message to send.
- delay – delay in seconds between write and read operations. if None, defaults to self.query_delay
Returns: the answer from the device.
Return type:
-
query_ascii_values
(message, converter='f', separator=', ', container=<class 'list'>, delay=None)¶ Query the device for values in ascii format returning an iterable of values.
Parameters: - message (str) – the message to send.
- delay – delay in seconds between write and read operations. if None, defaults to self.query_delay
- converter (callable) – function used to convert each element. Defaults to float
- separator – a callable that split the str into individual elements. If a str is given, data.split(separator) is used.
- container – container type to use for the output data.
Type: Returns: the answer from the device.
Return type:
-
query_binary_values
(message, datatype='f', is_big_endian=False, container=<class 'list'>, delay=None, header_fmt='ieee', expect_termination=True, data_points=0, chunk_size=None)¶ Query the device for values in binary format returning an iterable of values.
Parameters: - message – the message to send to the instrument.
- datatype – the format string for a single element. See struct module.
- is_big_endian – boolean indicating endianess. Defaults to False.
- container – container type to use for the output data.
- delay – delay in seconds between write and read operations. if None, defaults to self.query_delay
- expect_termination – when set to False, the expected length of the binary values block does not account for the final termination character (the read termination)
- data_points – 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.
- chunk_size – Size of the chunks to read from the device. Using larger chunks may be faster for large amount of data.
Returns: the answer from the device.
Return type:
-
query_delay
= 0.0¶
-
query_values
(message, delay=None)¶ Query the device for values returning an iterable of values.
The datatype expected is obtained from values_format
Parameters: - message (str) – the message to send.
- delay – delay in seconds between write and read operations. if None, defaults to self.query_delay
Returns: the answer from the device.
Return type:
-
read
(termination=None, encoding=None)¶ Read a string from the device.
Reading stops when the device stops sending (e.g. by setting appropriate bus lines), or the termination characters sequence was detected. Attention: Only the last character of the termination characters is really used to stop reading, however, the whole sequence is compared to the ending of the read string message. If they don’t match, a warning is issued.
All line-ending characters are stripped from the end of the string.
Return type: str
-
read_ascii_values
(converter='f', separator=', ', container=<class 'list'>)¶ Read values from the device in ascii format returning an iterable of values.
Parameters: - delay – delay in seconds between write and read operations. if None, defaults to self.query_delay
- converter (callable) – function used to convert each element. Defaults to float
- separator – a callable that split the str into individual elements. If a str is given, data.split(separator) is used.
- container – container type to use for the output data.
Type: Returns: the answer from the device.
Return type:
-
read_binary_values
(datatype='f', is_big_endian=False, container=<class 'list'>, header_fmt='ieee', expect_termination=True, data_points=0, chunk_size=None)¶ Read values from the device in binary format returning an iterable of values.
Parameters: - datatype – the format string for a single element. See struct module.
- is_big_endian – boolean indicating endianess. Defaults to False.
- container – container type to use for the output data.
- header_fmt – format of the header prefixing the data. Possible values are: ‘ieee’, ‘hp’, ‘empty’
- expect_termination – when set to False, the expected length of the binary values block does not account for the final termination character (the read termination)
- data_points – 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.
- chunk_size – Size of the chunks to read from the device. Using larger chunks may be faster for large amount of data.
Returns: the answer from the device.
Return type: type(container)
-
read_bytes
(count, chunk_size=None, break_on_termchar=False)¶ Read a certain number of bytes from the instrument.
Parameters: Return type:
-
read_raw
(size=None)¶ Read the unmodified string sent from the instrument to the computer.
In contrast to read(), no termination characters are stripped.
Parameters: size – The chunk size to use when reading the data. Return type: bytes
-
read_stb
()¶ Service request status register.
-
read_termination
¶ Read termination character.
-
read_termination_context
(new_termination)¶
-
read_values
(fmt=None, container=<class 'list'>)¶ Read a list of floating point values from the device.
Parameters: - fmt – the format of the values. If given, it overrides the class attribute “values_format”. Possible values are bitwise disjunctions of the above constants ascii, single, double, and big_endian. Default is ascii.
- container – the output datatype
Returns: the list of read values
Return type:
-
classmethod
register
(interface_type, resource_class)¶
-
resource_class
¶ - VI_ATTR_RSRC_CLASS specifies the resource class (for example, “INSTR”)
- as defined by the canonical resource name.
VISA Attribute: VI_ATTR_RSRC_CLASS (3221159937)
-
resource_info
¶ Get the extended information of this resource.
Parameters: resource_name – Unique symbolic name of a resource. Return type: pyvisa.highlevel.ResourceInfo
-
resource_manufacturer_name
¶ - VI_ATTR_RSRC_MANF_NAME is a string that corresponds to the 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
¶ - VI_ATTR_RSRC_MANF_NAME is a string that corresponds to the 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_NAME (3221159938)
-
session
¶ Resource session handle.
Raises: pyvisa.errors.InvalidSession
if session is closed.
-
set_visa_attribute
(name, state)¶ Sets the state of an attribute.
Parameters: - name – Attribute for which the state is to be modified. (Attributes.*)
- state – The state of the attribute to be set for the specified object.
Returns: return value of the library call.
Return type:
-
spec_version
¶ - VI_ATTR_RSRC_SPEC_VERSION is the resource version that uniquely identifies
- the 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
¶ The timeout in milliseconds for all resource I/O operations.
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 asfloat('+inf')
)
To set an infinite timeout, you can also use:
>>> del instrument.timeout
- immediate (
-
uninstall_handler
(event_type, handler, user_handle=None)¶ Uninstalls handlers for events in this resource.
Parameters: - event_type – Logical event identifier.
- handler – Interpreted as a valid reference to a handler to be uninstalled by a client application.
- user_handle – The user handle (ctypes object or None) returned by install_handler.
-
unlock
()¶ Relinquishes a lock for the specified resource.
-
values_format
¶
-
visa_attributes_classes
= [<class 'pyvisa.attributes.AttrVI_ATTR_INTF_INST_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_MAX_QUEUE_LENGTH'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_TYPE'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_RM_SESSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_CLASS'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_IMPL_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_LOCK_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_SPEC_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_TMO_VALUE'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_INST_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_MAX_QUEUE_LENGTH'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_TYPE'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_RM_SESSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_CLASS'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_IMPL_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_LOCK_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_SPEC_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_TMO_VALUE'>, <class 'pyvisa.attributes.AttrVI_ATTR_TCPIP_HOSTNAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_IO_PROT'>, <class 'pyvisa.attributes.AttrVI_ATTR_WR_BUF_SIZE'>, <class 'pyvisa.attributes.AttrVI_ATTR_TCPIP_KEEPALIVE'>, <class 'pyvisa.attributes.AttrVI_ATTR_TCPIP_NODELAY'>, <class 'pyvisa.attributes.AttrVI_ATTR_TCPIP_PORT'>, <class 'pyvisa.attributes.AttrVI_ATTR_TERMCHAR'>, <class 'pyvisa.attributes.AttrVI_ATTR_RD_BUF_OPER_MODE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RD_BUF_SIZE'>, <class 'pyvisa.attributes.AttrVI_ATTR_TERMCHAR_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_WR_BUF_OPER_MODE'>, <class 'pyvisa.attributes.AttrVI_ATTR_SUPPRESS_END_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_FILE_APPEND_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_TCPIP_ADDR'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_INST_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_MAX_QUEUE_LENGTH'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_TYPE'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_RM_SESSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_CLASS'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_IMPL_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_LOCK_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_SPEC_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_TMO_VALUE'>]¶
-
wait_on_event
(in_event_type, timeout, capture_timeout=False)¶ Waits for an occurrence of the specified event in this resource.
Parameters: - in_event_type – Logical identifier of the event(s) to wait for.
- timeout – Absolute time period in time units that the resource shall wait for a specified event to occur before returning the time elapsed error. The time unit is in milliseconds. None means waiting forever if necessary.
- capture_timeout – When True will not produce a VisaIOError(VI_ERROR_TMO) but instead return a WaitResponse with timed_out=True
Returns: A WaitResponse object that contains event_type, context and ret value.
-
write
(message, termination=None, encoding=None)¶ Write a string message to the device.
The write_termination is always appended to it.
Parameters: Returns: number of bytes written.
Return type:
-
write_ascii_values
(message, values, converter='f', separator=', ', termination=None, encoding=None)¶ Write a string message to the device followed by values in ascii format.
The write_termination is always appended to it.
Parameters: - message (unicode (Py2) or str (Py3)) – the message to be sent.
- values – data to be writen to the device.
- converter (callable | str) – function used to convert each value. String formatting codes are also accepted. Defaults to ‘f’.
- separator – a callable that join the values in a single str. If a str is given, separator.join(values) is used.
Type: separator: (collections.Iterable[T]) -> str | str
Returns: number of bytes written.
Return type:
-
write_binary_values
(message, values, datatype='f', is_big_endian=False, termination=None, encoding=None, header_fmt='ieee')¶ Write a string message to the device followed by values in binary format.
The write_termination is always appended to it.
Parameters: - message (unicode (Py2) or str (Py3)) – the message to be sent.
- values – data to be writen to the device.
- datatype – the format string for a single element. See struct module.
- is_big_endian – boolean indicating endianess.
- header_fmt – format of the header prefixing the data. Possible values are: ‘ieee’, ‘hp’, ‘empty’
Returns: number of bytes written.
Return type:
-
write_raw
(message)¶ 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
¶ Writer termination character.
-
write_values
(message, values, termination=None, encoding=None)¶
-
class
pyvisa.resources.
USBInstrument
(*args, **kwargs)[source]¶ Communicates with devices of type 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'¶
-
assert_trigger
()¶ Sends a software trigger to the device.
-
before_close
()¶ Called just before closing an instrument.
-
chunk_size
= 20480¶
-
clear
()¶ Clears this resource
-
close
()¶ Closes the VISA session and marks the handle as invalid.
-
control_in
(request_type_bitmap_field, request_id, request_value, index, length=0)[source]¶ Performs a USB control pipe transfer from the device.
Parameters: - request_type_bitmap_field – bmRequestType parameter of the setup stage of a USB control transfer.
- request_id – bRequest parameter of the setup stage of a USB control transfer.
- request_value – wValue parameter of the setup stage of a USB control transfer.
- index – wIndex parameter of the setup stage of a USB control transfer. This is usually the index of the interface or endpoint.
- length – wLength parameter of the setup stage of a USB control transfer. This value also specifies the size of the data buffer to receive the data from the optional data stage of the control transfer.
Returns: The data buffer that receives the data from the optional data stage of the control transfer.
Return type:
-
control_out
(request_type_bitmap_field, request_id, request_value, index, data='')[source]¶ Performs a USB control pipe transfer to the device.
Parameters: - request_type_bitmap_field – bmRequestType parameter of the setup stage of a USB control transfer.
- request_id – bRequest parameter of the setup stage of a USB control transfer.
- request_value – wValue parameter of the setup stage of a USB control transfer.
- index – wIndex parameter of the setup stage of a USB control transfer. This is usually the index of the interface or endpoint.
- data – The data buffer that sends the data in the optional data stage of the control transfer.
-
control_ren
(mode)¶ Controls the state of the GPIB Remote Enable (REN) interface line, and optionally the remote/local state of the device.
Corresponds to viGpibControlREN function of the VISA library.
Parameters: mode – Specifies the state of the REN line and optionally the device remote/local state. (Constants.GPIB_REN*) Returns: return value of the library call. Return type: VISAStatus
-
disable_event
(event_type, mechanism)¶ Disables notification of the specified event type(s) via the specified mechanism(s).
Parameters: - event_type – Logical event identifier.
- mechanism – Specifies event handling mechanisms to be disabled. (Constants.VI_QUEUE, .VI_HNDLR, .VI_SUSPEND_HNDLR, .VI_ALL_MECH)
-
discard_events
(event_type, mechanism)¶ Discards event occurrences for specified event types and mechanisms in this resource.
Parameters: - event_type – Logical event identifier.
- mechanism – Specifies event handling mechanisms to be dicarded. (Constants.VI_QUEUE, .VI_HNDLR, .VI_SUSPEND_HNDLR, .VI_ALL_MECH)
-
enable_event
(event_type, mechanism, context=None)¶ Enable event occurrences for specified event types and mechanisms in this resource.
Parameters: - event_type – Logical event identifier.
- mechanism – Specifies event handling mechanisms to be enabled. (Constants.VI_QUEUE, .VI_HNDLR, .VI_SUSPEND_HNDLR)
- context – Not currently used, leave as None.
-
encoding
¶ Encoding used for read and write operations.
-
flush
(mask)¶ 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 – Specifies the action to be taken with flushing the buffer. See highlevel.VisaLibraryBase.flush for a detailed description.
-
get_visa_attribute
(name)¶ Retrieves the state of an attribute in this resource.
Parameters: name – Resource attribute for which the state query is made (see Attributes.*) Returns: The state of the queried attribute for a specified resource. Return type: unicode (Py2) or str (Py3), list or other type
-
ignore_warning
(*warnings_constants)¶ Ignoring warnings context manager for the current resource.
Parameters: warnings_constants – constants identifying the warnings to ignore.
-
implementation_version
¶ - VI_ATTR_RSRC_IMPL_VERSION is the resource version that uniquely identifies
- each of the different 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, handler, user_handle=None)¶ Installs handlers for event callbacks in this resource.
Parameters: - event_type – Logical event identifier.
- handler – Interpreted as a valid reference to a handler to be installed by a client application.
- user_handle – A value specified by an application that can be used for identifying handlers uniquely for an event type.
Returns: user handle (a ctypes object)
-
interface_number
¶ VI_ATTR_INTF_NUM specifies the board number for the given interface.
VISA Attribute: VI_ATTR_INTF_NUM (1073676662) Type: int Range: 0 <= value <= 65535
-
interface_type
¶ The interface type of the resource as a number.
-
io_protocol
¶ - VI_ATTR_IO_PROT specifies which 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: int Range: 0 <= value <= 65535
-
is_4882_compliant
¶ - VI_ATTR_4882_COMPLIANT specifies whether the device is 488.2
- compliant.
VISA Attribute: VI_ATTR_4882_COMPLIANT (1073676703) Type: bool
-
last_status
¶ Last status code for this session.
Return type: pyvisa.constants.StatusCode
-
lock
(timeout='default', requested_key=None)¶ Establish a shared lock to the resource.
Parameters: - timeout – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. (Defaults to self.timeout)
- requested_key – 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
-
lock_context
(timeout='default', requested_key='exclusive')¶ A context that locks
Parameters: - timeout – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. (Defaults to self.timeout)
- requested_key – 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.
The returned context is the access_key if applicable.
-
lock_excl
(timeout='default')¶ Establish an exclusive lock to the resource.
Parameters: timeout – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. (Defaults to self.timeout)
-
lock_state
¶ - VI_ATTR_RSRC_LOCK_STATE indicates the 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
¶ - VI_ATTR_MANF_ID is the manufacturer identification number of the
- device.
VISA Attribute: VI_ATTR_MANF_ID (1073676505) Type: int Range: 0 <= value <= 65535
-
manufacturer_name
¶ This string attribute is the manufacturer name.
VISA Attribute: VI_ATTR_MANF_NAME (3221160050)
-
maximum_interrupt_size
¶ - VI_ATTR_USB_MAX_INTR_SIZE specifies the 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
¶ VI_ATTR_MODEL_CODE specifies the model code for the device.
VISA Attribute: VI_ATTR_MODEL_CODE (1073676511) Type: int Range: 0 <= value <= 65535
-
model_name
¶ This string attribute is the model name of the device.
VISA Attribute: VI_ATTR_MODEL_NAME (3221160055)
-
open
(access_mode=<AccessModes.no_lock: 0>, open_timeout=5000)¶ Opens a session to the specified resource.
Parameters: - access_mode (
pyvisa.constants.AccessModes
) – Specifies the mode by which the resource is to be accessed. - open_timeout (int) – If the
access_mode
parameter requests a lock, then this parameter specifies the absolute time period (in milliseconds) that the resource waits to get unlocked before this operation returns an error.
- access_mode (
-
query
(message, delay=None)¶ A combination of write(message) and read()
Parameters: - message (str) – the message to send.
- delay – delay in seconds between write and read operations. if None, defaults to self.query_delay
Returns: the answer from the device.
Return type:
-
query_ascii_values
(message, converter='f', separator=', ', container=<class 'list'>, delay=None)¶ Query the device for values in ascii format returning an iterable of values.
Parameters: - message (str) – the message to send.
- delay – delay in seconds between write and read operations. if None, defaults to self.query_delay
- converter (callable) – function used to convert each element. Defaults to float
- separator – a callable that split the str into individual elements. If a str is given, data.split(separator) is used.
- container – container type to use for the output data.
Type: Returns: the answer from the device.
Return type:
-
query_binary_values
(message, datatype='f', is_big_endian=False, container=<class 'list'>, delay=None, header_fmt='ieee', expect_termination=True, data_points=0, chunk_size=None)¶ Query the device for values in binary format returning an iterable of values.
Parameters: - message – the message to send to the instrument.
- datatype – the format string for a single element. See struct module.
- is_big_endian – boolean indicating endianess. Defaults to False.
- container – container type to use for the output data.
- delay – delay in seconds between write and read operations. if None, defaults to self.query_delay
- expect_termination – when set to False, the expected length of the binary values block does not account for the final termination character (the read termination)
- data_points – 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.
- chunk_size – Size of the chunks to read from the device. Using larger chunks may be faster for large amount of data.
Returns: the answer from the device.
Return type:
-
query_delay
= 0.0¶
-
query_values
(message, delay=None)¶ Query the device for values returning an iterable of values.
The datatype expected is obtained from values_format
Parameters: - message (str) – the message to send.
- delay – delay in seconds between write and read operations. if None, defaults to self.query_delay
Returns: the answer from the device.
Return type:
-
read
(termination=None, encoding=None)¶ Read a string from the device.
Reading stops when the device stops sending (e.g. by setting appropriate bus lines), or the termination characters sequence was detected. Attention: Only the last character of the termination characters is really used to stop reading, however, the whole sequence is compared to the ending of the read string message. If they don’t match, a warning is issued.
All line-ending characters are stripped from the end of the string.
Return type: str
-
read_ascii_values
(converter='f', separator=', ', container=<class 'list'>)¶ Read values from the device in ascii format returning an iterable of values.
Parameters: - delay – delay in seconds between write and read operations. if None, defaults to self.query_delay
- converter (callable) – function used to convert each element. Defaults to float
- separator – a callable that split the str into individual elements. If a str is given, data.split(separator) is used.
- container – container type to use for the output data.
Type: Returns: the answer from the device.
Return type:
-
read_binary_values
(datatype='f', is_big_endian=False, container=<class 'list'>, header_fmt='ieee', expect_termination=True, data_points=0, chunk_size=None)¶ Read values from the device in binary format returning an iterable of values.
Parameters: - datatype – the format string for a single element. See struct module.
- is_big_endian – boolean indicating endianess. Defaults to False.
- container – container type to use for the output data.
- header_fmt – format of the header prefixing the data. Possible values are: ‘ieee’, ‘hp’, ‘empty’
- expect_termination – when set to False, the expected length of the binary values block does not account for the final termination character (the read termination)
- data_points – 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.
- chunk_size – Size of the chunks to read from the device. Using larger chunks may be faster for large amount of data.
Returns: the answer from the device.
Return type: type(container)
-
read_bytes
(count, chunk_size=None, break_on_termchar=False)¶ Read a certain number of bytes from the instrument.
Parameters: Return type:
-
read_raw
(size=None)¶ Read the unmodified string sent from the instrument to the computer.
In contrast to read(), no termination characters are stripped.
Parameters: size – The chunk size to use when reading the data. Return type: bytes
-
read_stb
()¶ Service request status register.
-
read_termination
¶ Read termination character.
-
read_termination_context
(new_termination)¶
-
read_values
(fmt=None, container=<class 'list'>)¶ Read a list of floating point values from the device.
Parameters: - fmt – the format of the values. If given, it overrides the class attribute “values_format”. Possible values are bitwise disjunctions of the above constants ascii, single, double, and big_endian. Default is ascii.
- container – the output datatype
Returns: the list of read values
Return type:
-
classmethod
register
(interface_type, resource_class)¶
-
resource_class
¶ - VI_ATTR_RSRC_CLASS specifies the resource class (for example, “INSTR”)
- as defined by the canonical resource name.
VISA Attribute: VI_ATTR_RSRC_CLASS (3221159937)
-
resource_info
¶ Get the extended information of this resource.
Parameters: resource_name – Unique symbolic name of a resource. Return type: pyvisa.highlevel.ResourceInfo
-
resource_manufacturer_name
¶ - VI_ATTR_RSRC_MANF_NAME is a string that corresponds to the 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
¶ - VI_ATTR_RSRC_MANF_NAME is a string that corresponds to the 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_NAME (3221159938)
-
send_end
¶ - VI_ATTR_SEND_END_EN specifies whether to assert END during the
- transfer of the last byte of the buffer.
VISA Attribute: VI_ATTR_SEND_END_EN (1073676310) Type: bool
-
serial_number
¶ VI_ATTR_USB_SERIAL_NUM specifies the USB serial number of this device.
VISA Attribute: VI_ATTR_USB_SERIAL_NUM (3221160352)
-
session
¶ Resource session handle.
Raises: pyvisa.errors.InvalidSession
if session is closed.
-
set_visa_attribute
(name, state)¶ Sets the state of an attribute.
Parameters: - name – Attribute for which the state is to be modified. (Attributes.*)
- state – The state of the attribute to be set for the specified object.
Returns: return value of the library call.
Return type:
-
spec_version
¶ - VI_ATTR_RSRC_SPEC_VERSION is the resource version that uniquely identifies
- the 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
¶ The timeout in milliseconds for all resource I/O operations.
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 asfloat('+inf')
)
To set an infinite timeout, you can also use:
>>> del instrument.timeout
- immediate (
-
uninstall_handler
(event_type, handler, user_handle=None)¶ Uninstalls handlers for events in this resource.
Parameters: - event_type – Logical event identifier.
- handler – Interpreted as a valid reference to a handler to be uninstalled by a client application.
- user_handle – The user handle (ctypes object or None) returned by install_handler.
-
unlock
()¶ Relinquishes a lock for the specified resource.
-
usb_control_out
(request_type_bitmap_field, request_id, request_value, index, data='')[source]¶ Performs a USB control pipe transfer to the device. (Deprecated)
Parameters: - request_type_bitmap_field – bmRequestType parameter of the setup stage of a USB control transfer.
- request_id – bRequest parameter of the setup stage of a USB control transfer.
- request_value – wValue parameter of the setup stage of a USB control transfer.
- index – wIndex parameter of the setup stage of a USB control transfer. This is usually the index of the interface or endpoint.
- data – The data buffer that sends the data in the optional data stage of the control transfer.
-
usb_protocol
¶ - VI_ATTR_USB_PROTOCOL specifies the USB protocol used by this USB
- interface.
VISA Attribute: VI_ATTR_USB_PROTOCOL (1073676711) Type: int Range: 0 <= value <= 255
-
values_format
¶
-
visa_attributes_classes
= [<class 'pyvisa.attributes.AttrVI_ATTR_INTF_INST_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_MAX_QUEUE_LENGTH'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_TYPE'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_RM_SESSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_CLASS'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_IMPL_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_LOCK_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_SPEC_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_TMO_VALUE'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_INST_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_MAX_QUEUE_LENGTH'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_TYPE'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_RM_SESSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_CLASS'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_IMPL_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_LOCK_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_SPEC_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_TMO_VALUE'>, <class 'pyvisa.attributes.AttrVI_ATTR_IO_PROT'>, <class 'pyvisa.attributes.AttrVI_ATTR_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_MODEL_CODE'>, <class 'pyvisa.attributes.AttrVI_ATTR_MODEL_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_USB_INTFC_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_4882_COMPLIANT'>, <class 'pyvisa.attributes.AttrVI_ATTR_WR_BUF_SIZE'>, <class 'pyvisa.attributes.AttrVI_ATTR_USB_MAX_INTR_SIZE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RD_BUF_OPER_MODE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RD_BUF_SIZE'>, <class 'pyvisa.attributes.AttrVI_ATTR_TERMCHAR_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_USB_PROTOCOL'>, <class 'pyvisa.attributes.AttrVI_ATTR_SEND_END_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_USB_SERIAL_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_TERMCHAR'>, <class 'pyvisa.attributes.AttrVI_ATTR_FILE_APPEND_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_WR_BUF_OPER_MODE'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_INST_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_MAX_QUEUE_LENGTH'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_TYPE'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_RM_SESSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_CLASS'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_IMPL_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_LOCK_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_SPEC_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_TMO_VALUE'>]¶
-
wait_on_event
(in_event_type, timeout, capture_timeout=False)¶ Waits for an occurrence of the specified event in this resource.
Parameters: - in_event_type – Logical identifier of the event(s) to wait for.
- timeout – Absolute time period in time units that the resource shall wait for a specified event to occur before returning the time elapsed error. The time unit is in milliseconds. None means waiting forever if necessary.
- capture_timeout – When True will not produce a VisaIOError(VI_ERROR_TMO) but instead return a WaitResponse with timed_out=True
Returns: A WaitResponse object that contains event_type, context and ret value.
-
write
(message, termination=None, encoding=None)¶ Write a string message to the device.
The write_termination is always appended to it.
Parameters: Returns: number of bytes written.
Return type:
-
write_ascii_values
(message, values, converter='f', separator=', ', termination=None, encoding=None)¶ Write a string message to the device followed by values in ascii format.
The write_termination is always appended to it.
Parameters: - message (unicode (Py2) or str (Py3)) – the message to be sent.
- values – data to be writen to the device.
- converter (callable | str) – function used to convert each value. String formatting codes are also accepted. Defaults to ‘f’.
- separator – a callable that join the values in a single str. If a str is given, separator.join(values) is used.
Type: separator: (collections.Iterable[T]) -> str | str
Returns: number of bytes written.
Return type:
-
write_binary_values
(message, values, datatype='f', is_big_endian=False, termination=None, encoding=None, header_fmt='ieee')¶ Write a string message to the device followed by values in binary format.
The write_termination is always appended to it.
Parameters: - message (unicode (Py2) or str (Py3)) – the message to be sent.
- values – data to be writen to the device.
- datatype – the format string for a single element. See struct module.
- is_big_endian – boolean indicating endianess.
- header_fmt – format of the header prefixing the data. Possible values are: ‘ieee’, ‘hp’, ‘empty’
Returns: number of bytes written.
Return type:
-
write_raw
(message)¶ 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
¶ Writer termination character.
-
write_values
(message, values, termination=None, encoding=None)¶
-
class
pyvisa.resources.
USBRaw
(*args, **kwargs)[source]¶ Communicates with to devices of type 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'¶
-
assert_trigger
()¶ Sends a software trigger to the device.
-
before_close
()¶ Called just before closing an instrument.
-
chunk_size
= 20480¶
-
clear
()¶ Clears this resource
-
close
()¶ Closes the VISA session and marks the handle as invalid.
-
disable_event
(event_type, mechanism)¶ Disables notification of the specified event type(s) via the specified mechanism(s).
Parameters: - event_type – Logical event identifier.
- mechanism – Specifies event handling mechanisms to be disabled. (Constants.VI_QUEUE, .VI_HNDLR, .VI_SUSPEND_HNDLR, .VI_ALL_MECH)
-
discard_events
(event_type, mechanism)¶ Discards event occurrences for specified event types and mechanisms in this resource.
Parameters: - event_type – Logical event identifier.
- mechanism – Specifies event handling mechanisms to be dicarded. (Constants.VI_QUEUE, .VI_HNDLR, .VI_SUSPEND_HNDLR, .VI_ALL_MECH)
-
enable_event
(event_type, mechanism, context=None)¶ Enable event occurrences for specified event types and mechanisms in this resource.
Parameters: - event_type – Logical event identifier.
- mechanism – Specifies event handling mechanisms to be enabled. (Constants.VI_QUEUE, .VI_HNDLR, .VI_SUSPEND_HNDLR)
- context – Not currently used, leave as None.
-
encoding
¶ Encoding used for read and write operations.
-
flush
(mask)¶ 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 – Specifies the action to be taken with flushing the buffer. See highlevel.VisaLibraryBase.flush for a detailed description.
-
get_visa_attribute
(name)¶ Retrieves the state of an attribute in this resource.
Parameters: name – Resource attribute for which the state query is made (see Attributes.*) Returns: The state of the queried attribute for a specified resource. Return type: unicode (Py2) or str (Py3), list or other type
-
ignore_warning
(*warnings_constants)¶ Ignoring warnings context manager for the current resource.
Parameters: warnings_constants – constants identifying the warnings to ignore.
-
implementation_version
¶ - VI_ATTR_RSRC_IMPL_VERSION is the resource version that uniquely identifies
- each of the different 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, handler, user_handle=None)¶ Installs handlers for event callbacks in this resource.
Parameters: - event_type – Logical event identifier.
- handler – Interpreted as a valid reference to a handler to be installed by a client application.
- user_handle – A value specified by an application that can be used for identifying handlers uniquely for an event type.
Returns: user handle (a ctypes object)
-
interface_number
¶ VI_ATTR_INTF_NUM specifies the board number for the given interface.
VISA Attribute: VI_ATTR_INTF_NUM (1073676662) Type: int Range: 0 <= value <= 65535
-
interface_type
¶ The interface type of the resource as a number.
-
io_protocol
¶ - VI_ATTR_IO_PROT specifies which 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: int Range: 0 <= value <= 65535
-
last_status
¶ Last status code for this session.
Return type: pyvisa.constants.StatusCode
-
lock
(timeout='default', requested_key=None)¶ Establish a shared lock to the resource.
Parameters: - timeout – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. (Defaults to self.timeout)
- requested_key – 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
-
lock_context
(timeout='default', requested_key='exclusive')¶ A context that locks
Parameters: - timeout – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. (Defaults to self.timeout)
- requested_key – 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.
The returned context is the access_key if applicable.
-
lock_excl
(timeout='default')¶ Establish an exclusive lock to the resource.
Parameters: timeout – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. (Defaults to self.timeout)
-
lock_state
¶ - VI_ATTR_RSRC_LOCK_STATE indicates the 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
¶ - VI_ATTR_MANF_ID is the manufacturer identification number of the
- device.
VISA Attribute: VI_ATTR_MANF_ID (1073676505) Type: int Range: 0 <= value <= 65535
-
manufacturer_name
¶ This string attribute is the manufacturer name.
VISA Attribute: VI_ATTR_MANF_NAME (3221160050)
-
maximum_interrupt_size
¶ - VI_ATTR_USB_MAX_INTR_SIZE specifies the 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
¶ VI_ATTR_MODEL_CODE specifies the model code for the device.
VISA Attribute: VI_ATTR_MODEL_CODE (1073676511) Type: int Range: 0 <= value <= 65535
-
model_name
¶ This string attribute is the model name of the device.
VISA Attribute: VI_ATTR_MODEL_NAME (3221160055)
-
open
(access_mode=<AccessModes.no_lock: 0>, open_timeout=5000)¶ Opens a session to the specified resource.
Parameters: - access_mode (
pyvisa.constants.AccessModes
) – Specifies the mode by which the resource is to be accessed. - open_timeout (int) – If the
access_mode
parameter requests a lock, then this parameter specifies the absolute time period (in milliseconds) that the resource waits to get unlocked before this operation returns an error.
- access_mode (
-
query
(message, delay=None)¶ A combination of write(message) and read()
Parameters: - message (str) – the message to send.
- delay – delay in seconds between write and read operations. if None, defaults to self.query_delay
Returns: the answer from the device.
Return type:
-
query_ascii_values
(message, converter='f', separator=', ', container=<class 'list'>, delay=None)¶ Query the device for values in ascii format returning an iterable of values.
Parameters: - message (str) – the message to send.
- delay – delay in seconds between write and read operations. if None, defaults to self.query_delay
- converter (callable) – function used to convert each element. Defaults to float
- separator – a callable that split the str into individual elements. If a str is given, data.split(separator) is used.
- container – container type to use for the output data.
Type: Returns: the answer from the device.
Return type:
-
query_binary_values
(message, datatype='f', is_big_endian=False, container=<class 'list'>, delay=None, header_fmt='ieee', expect_termination=True, data_points=0, chunk_size=None)¶ Query the device for values in binary format returning an iterable of values.
Parameters: - message – the message to send to the instrument.
- datatype – the format string for a single element. See struct module.
- is_big_endian – boolean indicating endianess. Defaults to False.
- container – container type to use for the output data.
- delay – delay in seconds between write and read operations. if None, defaults to self.query_delay
- expect_termination – when set to False, the expected length of the binary values block does not account for the final termination character (the read termination)
- data_points – 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.
- chunk_size – Size of the chunks to read from the device. Using larger chunks may be faster for large amount of data.
Returns: the answer from the device.
Return type:
-
query_delay
= 0.0¶
-
query_values
(message, delay=None)¶ Query the device for values returning an iterable of values.
The datatype expected is obtained from values_format
Parameters: - message (str) – the message to send.
- delay – delay in seconds between write and read operations. if None, defaults to self.query_delay
Returns: the answer from the device.
Return type:
-
read
(termination=None, encoding=None)¶ Read a string from the device.
Reading stops when the device stops sending (e.g. by setting appropriate bus lines), or the termination characters sequence was detected. Attention: Only the last character of the termination characters is really used to stop reading, however, the whole sequence is compared to the ending of the read string message. If they don’t match, a warning is issued.
All line-ending characters are stripped from the end of the string.
Return type: str
-
read_ascii_values
(converter='f', separator=', ', container=<class 'list'>)¶ Read values from the device in ascii format returning an iterable of values.
Parameters: - delay – delay in seconds between write and read operations. if None, defaults to self.query_delay
- converter (callable) – function used to convert each element. Defaults to float
- separator – a callable that split the str into individual elements. If a str is given, data.split(separator) is used.
- container – container type to use for the output data.
Type: Returns: the answer from the device.
Return type:
-
read_binary_values
(datatype='f', is_big_endian=False, container=<class 'list'>, header_fmt='ieee', expect_termination=True, data_points=0, chunk_size=None)¶ Read values from the device in binary format returning an iterable of values.
Parameters: - datatype – the format string for a single element. See struct module.
- is_big_endian – boolean indicating endianess. Defaults to False.
- container – container type to use for the output data.
- header_fmt – format of the header prefixing the data. Possible values are: ‘ieee’, ‘hp’, ‘empty’
- expect_termination – when set to False, the expected length of the binary values block does not account for the final termination character (the read termination)
- data_points – 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.
- chunk_size – Size of the chunks to read from the device. Using larger chunks may be faster for large amount of data.
Returns: the answer from the device.
Return type: type(container)
-
read_bytes
(count, chunk_size=None, break_on_termchar=False)¶ Read a certain number of bytes from the instrument.
Parameters: Return type:
-
read_raw
(size=None)¶ Read the unmodified string sent from the instrument to the computer.
In contrast to read(), no termination characters are stripped.
Parameters: size – The chunk size to use when reading the data. Return type: bytes
-
read_stb
()¶ Service request status register.
-
read_termination
¶ Read termination character.
-
read_termination_context
(new_termination)¶
-
read_values
(fmt=None, container=<class 'list'>)¶ Read a list of floating point values from the device.
Parameters: - fmt – the format of the values. If given, it overrides the class attribute “values_format”. Possible values are bitwise disjunctions of the above constants ascii, single, double, and big_endian. Default is ascii.
- container – the output datatype
Returns: the list of read values
Return type:
-
classmethod
register
(interface_type, resource_class)¶
-
resource_class
¶ - VI_ATTR_RSRC_CLASS specifies the resource class (for example, “INSTR”)
- as defined by the canonical resource name.
VISA Attribute: VI_ATTR_RSRC_CLASS (3221159937)
-
resource_info
¶ Get the extended information of this resource.
Parameters: resource_name – Unique symbolic name of a resource. Return type: pyvisa.highlevel.ResourceInfo
-
resource_manufacturer_name
¶ - VI_ATTR_RSRC_MANF_NAME is a string that corresponds to the 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
¶ - VI_ATTR_RSRC_MANF_NAME is a string that corresponds to the 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_NAME (3221159938)
-
serial_number
¶ VI_ATTR_USB_SERIAL_NUM specifies the USB serial number of this device.
VISA Attribute: VI_ATTR_USB_SERIAL_NUM (3221160352)
-
session
¶ Resource session handle.
Raises: pyvisa.errors.InvalidSession
if session is closed.
-
set_visa_attribute
(name, state)¶ Sets the state of an attribute.
Parameters: - name – Attribute for which the state is to be modified. (Attributes.*)
- state – The state of the attribute to be set for the specified object.
Returns: return value of the library call.
Return type:
-
spec_version
¶ - VI_ATTR_RSRC_SPEC_VERSION is the resource version that uniquely identifies
- the 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
¶ The timeout in milliseconds for all resource I/O operations.
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 asfloat('+inf')
)
To set an infinite timeout, you can also use:
>>> del instrument.timeout
- immediate (
-
uninstall_handler
(event_type, handler, user_handle=None)¶ Uninstalls handlers for events in this resource.
Parameters: - event_type – Logical event identifier.
- handler – Interpreted as a valid reference to a handler to be uninstalled by a client application.
- user_handle – The user handle (ctypes object or None) returned by install_handler.
-
unlock
()¶ Relinquishes a lock for the specified resource.
-
usb_protocol
¶ - VI_ATTR_USB_PROTOCOL specifies the USB protocol used by this USB
- interface.
VISA Attribute: VI_ATTR_USB_PROTOCOL (1073676711) Type: int Range: 0 <= value <= 255
-
values_format
¶
-
visa_attributes_classes
= [<class 'pyvisa.attributes.AttrVI_ATTR_INTF_INST_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_MAX_QUEUE_LENGTH'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_TYPE'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_RM_SESSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_CLASS'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_IMPL_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_LOCK_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_SPEC_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_TMO_VALUE'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_INST_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_MAX_QUEUE_LENGTH'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_TYPE'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_RM_SESSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_CLASS'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_IMPL_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_LOCK_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_SPEC_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_TMO_VALUE'>, <class 'pyvisa.attributes.AttrVI_ATTR_USB_ALT_SETTING'>, <class 'pyvisa.attributes.AttrVI_ATTR_MODEL_CODE'>, <class 'pyvisa.attributes.AttrVI_ATTR_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_WR_BUF_SIZE'>, <class 'pyvisa.attributes.AttrVI_ATTR_USB_BULK_OUT_PIPE'>, <class 'pyvisa.attributes.AttrVI_ATTR_USB_END_IN'>, <class 'pyvisa.attributes.AttrVI_ATTR_USB_MAX_INTR_SIZE'>, <class 'pyvisa.attributes.AttrVI_ATTR_USB_SERIAL_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_IO_PROT'>, <class 'pyvisa.attributes.AttrVI_ATTR_USB_INTFC_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_RD_BUF_SIZE'>, <class 'pyvisa.attributes.AttrVI_ATTR_USB_NUM_INTFCS'>, <class 'pyvisa.attributes.AttrVI_ATTR_USB_BULK_IN_STATUS'>, <class 'pyvisa.attributes.AttrVI_ATTR_USB_CTRL_PIPE'>, <class 'pyvisa.attributes.AttrVI_ATTR_USB_INTR_IN_STATUS'>, <class 'pyvisa.attributes.AttrVI_ATTR_USB_PROTOCOL'>, <class 'pyvisa.attributes.AttrVI_ATTR_USB_SUBCLASS'>, <class 'pyvisa.attributes.AttrVI_ATTR_RD_BUF_OPER_MODE'>, <class 'pyvisa.attributes.AttrVI_ATTR_TERMCHAR_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_USB_BULK_IN_PIPE'>, <class 'pyvisa.attributes.AttrVI_ATTR_USB_CLASS'>, <class 'pyvisa.attributes.AttrVI_ATTR_SUPPRESS_END_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_USB_INTR_IN_PIPE'>, <class 'pyvisa.attributes.AttrVI_ATTR_USB_NUM_PIPES'>, <class 'pyvisa.attributes.AttrVI_ATTR_WR_BUF_OPER_MODE'>, <class 'pyvisa.attributes.AttrVI_ATTR_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_MODEL_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_TERMCHAR'>, <class 'pyvisa.attributes.AttrVI_ATTR_USB_BULK_OUT_STATUS'>, <class 'pyvisa.attributes.AttrVI_ATTR_FILE_APPEND_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_INST_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_MAX_QUEUE_LENGTH'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_TYPE'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_RM_SESSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_CLASS'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_IMPL_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_LOCK_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_SPEC_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_TMO_VALUE'>]¶
-
wait_on_event
(in_event_type, timeout, capture_timeout=False)¶ Waits for an occurrence of the specified event in this resource.
Parameters: - in_event_type – Logical identifier of the event(s) to wait for.
- timeout – Absolute time period in time units that the resource shall wait for a specified event to occur before returning the time elapsed error. The time unit is in milliseconds. None means waiting forever if necessary.
- capture_timeout – When True will not produce a VisaIOError(VI_ERROR_TMO) but instead return a WaitResponse with timed_out=True
Returns: A WaitResponse object that contains event_type, context and ret value.
-
write
(message, termination=None, encoding=None)¶ Write a string message to the device.
The write_termination is always appended to it.
Parameters: Returns: number of bytes written.
Return type:
-
write_ascii_values
(message, values, converter='f', separator=', ', termination=None, encoding=None)¶ Write a string message to the device followed by values in ascii format.
The write_termination is always appended to it.
Parameters: - message (unicode (Py2) or str (Py3)) – the message to be sent.
- values – data to be writen to the device.
- converter (callable | str) – function used to convert each value. String formatting codes are also accepted. Defaults to ‘f’.
- separator – a callable that join the values in a single str. If a str is given, separator.join(values) is used.
Type: separator: (collections.Iterable[T]) -> str | str
Returns: number of bytes written.
Return type:
-
write_binary_values
(message, values, datatype='f', is_big_endian=False, termination=None, encoding=None, header_fmt='ieee')¶ Write a string message to the device followed by values in binary format.
The write_termination is always appended to it.
Parameters: - message (unicode (Py2) or str (Py3)) – the message to be sent.
- values – data to be writen to the device.
- datatype – the format string for a single element. See struct module.
- is_big_endian – boolean indicating endianess.
- header_fmt – format of the header prefixing the data. Possible values are: ‘ieee’, ‘hp’, ‘empty’
Returns: number of bytes written.
Return type:
-
write_raw
(message)¶ 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
¶ Writer termination character.
-
write_values
(message, values, termination=None, encoding=None)¶
-
class
pyvisa.resources.
GPIBInstrument
(*args, **kwargs)[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
¶ - This attribute specifies whether I/O accesses should use DMA (VI_TRUE)
- or Programmed I/O (VI_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
()¶ Sends a software trigger to the device.
-
before_close
()¶ Called just before closing an instrument.
-
chunk_size
= 20480¶
-
clear
()¶ Clears this resource
-
close
()¶ Closes the VISA session and marks the handle as invalid.
-
control_atn
(mode)¶ Specifies the state of the ATN line and the local active controller state.
Corresponds to viGpibControlATN function of the VISA library.
Parameters: mode – Specifies the state of the ATN line and optionally the local active controller state. (Constants.GPIB_ATN*) Returns: return value of the library call. Return type: VISAStatus
-
control_ren
(mode)¶ Controls the state of the GPIB Remote Enable (REN) interface line, and optionally the remote/local state of the device.
Corresponds to viGpibControlREN function of the VISA library.
Parameters: mode – Specifies the state of the REN line and optionally the device remote/local state. (Constants.GPIB_REN*) Returns: return value of the library call. Return type: VISAStatus
-
disable_event
(event_type, mechanism)¶ Disables notification of the specified event type(s) via the specified mechanism(s).
Parameters: - event_type – Logical event identifier.
- mechanism – Specifies event handling mechanisms to be disabled. (Constants.VI_QUEUE, .VI_HNDLR, .VI_SUSPEND_HNDLR, .VI_ALL_MECH)
-
discard_events
(event_type, mechanism)¶ Discards event occurrences for specified event types and mechanisms in this resource.
Parameters: - event_type – Logical event identifier.
- mechanism – Specifies event handling mechanisms to be dicarded. (Constants.VI_QUEUE, .VI_HNDLR, .VI_SUSPEND_HNDLR, .VI_ALL_MECH)
-
enable_event
(event_type, mechanism, context=None)¶ Enable event occurrences for specified event types and mechanisms in this resource.
Parameters: - event_type – Logical event identifier.
- mechanism – Specifies event handling mechanisms to be enabled. (Constants.VI_QUEUE, .VI_HNDLR, .VI_SUSPEND_HNDLR)
- context – Not currently used, leave as None.
-
enable_repeat_addressing
¶ - VI_ATTR_GPIB_READDR_EN specifies whether to use repeat addressing
- before each read or write operation.
VISA Attribute: VI_ATTR_GPIB_READDR_EN (1073676315) Type: bool
-
enable_unaddressing
¶ - VI_ATTR_GPIB_UNADDR_EN specifies whether to unaddress the device (UNT
- and UNL) after each read or write operation.
VISA Attribute: VI_ATTR_GPIB_UNADDR_EN (1073676676) Type: bool
-
encoding
¶ Encoding used for read and write operations.
-
flush
(mask)¶ 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 – Specifies the action to be taken with flushing the buffer. See highlevel.VisaLibraryBase.flush for a detailed description.
-
get_visa_attribute
(name)¶ Retrieves the state of an attribute in this resource.
Parameters: name – Resource attribute for which the state query is made (see Attributes.*) Returns: The state of the queried attribute for a specified resource. Return type: unicode (Py2) or str (Py3), list or other type
-
ignore_warning
(*warnings_constants)¶ Ignoring warnings context manager for the current resource.
Parameters: warnings_constants – constants identifying the warnings to ignore.
-
implementation_version
¶ - VI_ATTR_RSRC_IMPL_VERSION is the resource version that uniquely identifies
- each of the different 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, handler, user_handle=None)¶ Installs handlers for event callbacks in this resource.
Parameters: - event_type – Logical event identifier.
- handler – Interpreted as a valid reference to a handler to be installed by a client application.
- user_handle – A value specified by an application that can be used for identifying handlers uniquely for an event type.
Returns: user handle (a ctypes object)
-
interface_number
¶ VI_ATTR_INTF_NUM specifies the board number for the given interface.
VISA Attribute: VI_ATTR_INTF_NUM (1073676662) Type: int Range: 0 <= value <= 65535
-
interface_type
¶ The interface type of the resource as a number.
-
io_protocol
¶ - VI_ATTR_IO_PROT specifies which 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: int Range: 0 <= value <= 65535
-
last_status
¶ Last status code for this session.
Return type: pyvisa.constants.StatusCode
-
lock
(timeout='default', requested_key=None)¶ Establish a shared lock to the resource.
Parameters: - timeout – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. (Defaults to self.timeout)
- requested_key – 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
-
lock_context
(timeout='default', requested_key='exclusive')¶ A context that locks
Parameters: - timeout – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. (Defaults to self.timeout)
- requested_key – 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.
The returned context is the access_key if applicable.
-
lock_excl
(timeout='default')¶ Establish an exclusive lock to the resource.
Parameters: timeout – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. (Defaults to self.timeout)
-
lock_state
¶ - VI_ATTR_RSRC_LOCK_STATE indicates the 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=<AccessModes.no_lock: 0>, open_timeout=5000)¶ Opens a session to the specified resource.
Parameters: - access_mode (
pyvisa.constants.AccessModes
) – Specifies the mode by which the resource is to be accessed. - open_timeout (int) – If the
access_mode
parameter requests a lock, then this parameter specifies the absolute time period (in milliseconds) that the resource waits to get unlocked before this operation returns an error.
- access_mode (
-
pass_control
(primary_address, secondary_address)¶ Tell the GPIB device at the specified address to become controller in charge (CIC).
Corresponds to viGpibPassControl function of the VISA library.
Parameters: - primary_address – Primary address of the GPIB device to which you want to pass control.
- secondary_address – Secondary address of the targeted GPIB device. If the targeted device does not have a secondary address, this parameter should contain the value Constants.NO_SEC_ADDR.
Returns: return value of the library call.
Return type: VISAStatus
-
primary_address
¶ - VI_ATTR_GPIB_PRIMARY_ADDR specifies the 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, delay=None)¶ A combination of write(message) and read()
Parameters: - message (str) – the message to send.
- delay – delay in seconds between write and read operations. if None, defaults to self.query_delay
Returns: the answer from the device.
Return type:
-
query_ascii_values
(message, converter='f', separator=', ', container=<class 'list'>, delay=None)¶ Query the device for values in ascii format returning an iterable of values.
Parameters: - message (str) – the message to send.
- delay – delay in seconds between write and read operations. if None, defaults to self.query_delay
- converter (callable) – function used to convert each element. Defaults to float
- separator – a callable that split the str into individual elements. If a str is given, data.split(separator) is used.
- container – container type to use for the output data.
Type: Returns: the answer from the device.
Return type:
-
query_binary_values
(message, datatype='f', is_big_endian=False, container=<class 'list'>, delay=None, header_fmt='ieee', expect_termination=True, data_points=0, chunk_size=None)¶ Query the device for values in binary format returning an iterable of values.
Parameters: - message – the message to send to the instrument.
- datatype – the format string for a single element. See struct module.
- is_big_endian – boolean indicating endianess. Defaults to False.
- container – container type to use for the output data.
- delay – delay in seconds between write and read operations. if None, defaults to self.query_delay
- expect_termination – when set to False, the expected length of the binary values block does not account for the final termination character (the read termination)
- data_points – 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.
- chunk_size – Size of the chunks to read from the device. Using larger chunks may be faster for large amount of data.
Returns: the answer from the device.
Return type:
-
query_delay
= 0.0¶
-
query_values
(message, delay=None)¶ Query the device for values returning an iterable of values.
The datatype expected is obtained from values_format
Parameters: - message (str) – the message to send.
- delay – delay in seconds between write and read operations. if None, defaults to self.query_delay
Returns: the answer from the device.
Return type:
-
read
(termination=None, encoding=None)¶ Read a string from the device.
Reading stops when the device stops sending (e.g. by setting appropriate bus lines), or the termination characters sequence was detected. Attention: Only the last character of the termination characters is really used to stop reading, however, the whole sequence is compared to the ending of the read string message. If they don’t match, a warning is issued.
All line-ending characters are stripped from the end of the string.
Return type: str
-
read_ascii_values
(converter='f', separator=', ', container=<class 'list'>)¶ Read values from the device in ascii format returning an iterable of values.
Parameters: - delay – delay in seconds between write and read operations. if None, defaults to self.query_delay
- converter (callable) – function used to convert each element. Defaults to float
- separator – a callable that split the str into individual elements. If a str is given, data.split(separator) is used.
- container – container type to use for the output data.
Type: Returns: the answer from the device.
Return type:
-
read_binary_values
(datatype='f', is_big_endian=False, container=<class 'list'>, header_fmt='ieee', expect_termination=True, data_points=0, chunk_size=None)¶ Read values from the device in binary format returning an iterable of values.
Parameters: - datatype – the format string for a single element. See struct module.
- is_big_endian – boolean indicating endianess. Defaults to False.
- container – container type to use for the output data.
- header_fmt – format of the header prefixing the data. Possible values are: ‘ieee’, ‘hp’, ‘empty’
- expect_termination – when set to False, the expected length of the binary values block does not account for the final termination character (the read termination)
- data_points – 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.
- chunk_size – Size of the chunks to read from the device. Using larger chunks may be faster for large amount of data.
Returns: the answer from the device.
Return type: type(container)
-
read_bytes
(count, chunk_size=None, break_on_termchar=False)¶ Read a certain number of bytes from the instrument.
Parameters: Return type:
-
read_raw
(size=None)¶ Read the unmodified string sent from the instrument to the computer.
In contrast to read(), no termination characters are stripped.
Parameters: size – The chunk size to use when reading the data. Return type: bytes
-
read_stb
()¶ Service request status register.
-
read_termination
¶ Read termination character.
-
read_termination_context
(new_termination)¶
-
read_values
(fmt=None, container=<class 'list'>)¶ Read a list of floating point values from the device.
Parameters: - fmt – the format of the values. If given, it overrides the class attribute “values_format”. Possible values are bitwise disjunctions of the above constants ascii, single, double, and big_endian. Default is ascii.
- container – the output datatype
Returns: the list of read values
Return type:
-
classmethod
register
(interface_type, resource_class)¶
-
remote_enabled
¶ - VI_ATTR_GPIB_REN_STATE returns the 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
¶ - VI_ATTR_RSRC_CLASS specifies the resource class (for example, “INSTR”)
- as defined by the canonical resource name.
VISA Attribute: VI_ATTR_RSRC_CLASS (3221159937)
-
resource_info
¶ Get the extended information of this resource.
Parameters: resource_name – Unique symbolic name of a resource. Return type: pyvisa.highlevel.ResourceInfo
-
resource_manufacturer_name
¶ - VI_ATTR_RSRC_MANF_NAME is a string that corresponds to the 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
¶ - VI_ATTR_RSRC_MANF_NAME is a string that corresponds to the 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_NAME (3221159938)
-
secondary_address
¶ - VI_ATTR_GPIB_SECONDARY_ADDR specifies the 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)¶ Write GPIB command bytes on the bus.
Corresponds to viGpibCommand function of the VISA library.
Parameters: data (bytes) – data tor write. Returns: Number of written bytes, return value of the library call. Return type: int, VISAStatus
-
send_end
¶ - VI_ATTR_SEND_END_EN specifies whether to assert END during the
- transfer of the last byte of the buffer.
VISA Attribute: VI_ATTR_SEND_END_EN (1073676310) Type: bool
-
send_ifc
()¶ Pulse the interface clear line (IFC) for at least 100 microseconds.
Corresponds to viGpibSendIFC function of the VISA library.
Returns: return value of the library call. Return type: VISAStatus
-
session
¶ Resource session handle.
Raises: pyvisa.errors.InvalidSession
if session is closed.
-
set_visa_attribute
(name, state)¶ Sets the state of an attribute.
Parameters: - name – Attribute for which the state is to be modified. (Attributes.*)
- state – The state of the attribute to be set for the specified object.
Returns: return value of the library call.
Return type:
-
spec_version
¶ - VI_ATTR_RSRC_SPEC_VERSION is the resource version that uniquely identifies
- the 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
¶ The timeout in milliseconds for all resource I/O operations.
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 asfloat('+inf')
)
To set an infinite timeout, you can also use:
>>> del instrument.timeout
- immediate (
-
uninstall_handler
(event_type, handler, user_handle=None)¶ Uninstalls handlers for events in this resource.
Parameters: - event_type – Logical event identifier.
- handler – Interpreted as a valid reference to a handler to be uninstalled by a client application.
- user_handle – The user handle (ctypes object or None) returned by install_handler.
-
unlock
()¶ Relinquishes a lock for the specified resource.
-
values_format
¶
-
visa_attributes_classes
= [<class 'pyvisa.attributes.AttrVI_ATTR_INTF_INST_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_MAX_QUEUE_LENGTH'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_TYPE'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_RM_SESSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_CLASS'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_IMPL_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_LOCK_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_SPEC_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_TMO_VALUE'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_INST_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_MAX_QUEUE_LENGTH'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_TYPE'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_RM_SESSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_CLASS'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_IMPL_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_LOCK_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_SPEC_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_TMO_VALUE'>, <class 'pyvisa.attributes.AttrVI_ATTR_IO_PROT'>, <class 'pyvisa.attributes.AttrVI_ATTR_WR_BUF_SIZE'>, <class 'pyvisa.attributes.AttrVI_ATTR_WR_BUF_OPER_MODE'>, <class 'pyvisa.attributes.AttrVI_ATTR_GPIB_PRIMARY_ADDR'>, <class 'pyvisa.attributes.AttrVI_ATTR_RD_BUF_OPER_MODE'>, <class 'pyvisa.attributes.AttrVI_ATTR_DMA_ALLOW_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_RD_BUF_SIZE'>, <class 'pyvisa.attributes.AttrVI_ATTR_TERMCHAR_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_GPIB_REN_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_SEND_END_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_GPIB_SECONDARY_ADDR'>, <class 'pyvisa.attributes.AttrVI_ATTR_TERMCHAR'>, <class 'pyvisa.attributes.AttrVI_ATTR_TRIG_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_FILE_APPEND_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_GPIB_UNADDR_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_GPIB_READDR_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_INST_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_MAX_QUEUE_LENGTH'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_TYPE'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_RM_SESSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_CLASS'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_IMPL_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_LOCK_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_SPEC_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_TMO_VALUE'>]¶
-
wait_for_srq
(timeout=25000)[source]¶ Wait for a serial request (SRQ) coming from the instrument.
Note that this method is not ended when another instrument signals an SRQ, only this instrument.
Parameters: timeout – the maximum waiting time in milliseconds. Defaul: 25000 (milliseconds). None means waiting forever if necessary.
-
wait_on_event
(in_event_type, timeout, capture_timeout=False)¶ Waits for an occurrence of the specified event in this resource.
Parameters: - in_event_type – Logical identifier of the event(s) to wait for.
- timeout – Absolute time period in time units that the resource shall wait for a specified event to occur before returning the time elapsed error. The time unit is in milliseconds. None means waiting forever if necessary.
- capture_timeout – When True will not produce a VisaIOError(VI_ERROR_TMO) but instead return a WaitResponse with timed_out=True
Returns: A WaitResponse object that contains event_type, context and ret value.
-
write
(message, termination=None, encoding=None)¶ Write a string message to the device.
The write_termination is always appended to it.
Parameters: Returns: number of bytes written.
Return type:
-
write_ascii_values
(message, values, converter='f', separator=', ', termination=None, encoding=None)¶ Write a string message to the device followed by values in ascii format.
The write_termination is always appended to it.
Parameters: - message (unicode (Py2) or str (Py3)) – the message to be sent.
- values – data to be writen to the device.
- converter (callable | str) – function used to convert each value. String formatting codes are also accepted. Defaults to ‘f’.
- separator – a callable that join the values in a single str. If a str is given, separator.join(values) is used.
Type: separator: (collections.Iterable[T]) -> str | str
Returns: number of bytes written.
Return type:
-
write_binary_values
(message, values, datatype='f', is_big_endian=False, termination=None, encoding=None, header_fmt='ieee')¶ Write a string message to the device followed by values in binary format.
The write_termination is always appended to it.
Parameters: - message (unicode (Py2) or str (Py3)) – the message to be sent.
- values – data to be writen to the device.
- datatype – the format string for a single element. See struct module.
- is_big_endian – boolean indicating endianess.
- header_fmt – format of the header prefixing the data. Possible values are: ‘ieee’, ‘hp’, ‘empty’
Returns: number of bytes written.
Return type:
-
write_raw
(message)¶ 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
¶ Writer termination character.
-
write_values
(message, values, termination=None, encoding=None)¶
-
class
pyvisa.resources.
GPIBInterface
(resource_manager, resource_name)[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()
.-
address_state
¶ - This attribute shows whether the specified GPIB interface is currently
- addressed to talk or listen, or is not addressed.
VISA Attribute: VI_ATTR_GPIB_ADDR_STATE (1073676380) Type: :class:pyvisa.constants.AddressState
-
allow_dma
¶ - This attribute specifies whether I/O accesses should use DMA (VI_TRUE)
- or Programmed I/O (VI_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
-
atn_state
¶ - This attribute shows the current state of the GPIB ATN (ATtentioN)
- interface line.
VISA Attribute: VI_ATTR_GPIB_ATN_STATE (1073676375) Type: :class:pyvisa.constants.LineState
-
before_close
()¶ Called just before closing an instrument.
-
clear
()¶ Clears this resource
-
close
()¶ Closes the VISA session and marks the handle as invalid.
-
control_atn
(mode)¶ Specifies the state of the ATN line and the local active controller state.
Corresponds to viGpibControlATN function of the VISA library.
Parameters: mode – Specifies the state of the ATN line and optionally the local active controller state. (Constants.GPIB_ATN*) Returns: return value of the library call. Return type: VISAStatus
-
control_ren
(mode)¶ Controls the state of the GPIB Remote Enable (REN) interface line, and optionally the remote/local state of the device.
Corresponds to viGpibControlREN function of the VISA library.
Parameters: mode – Specifies the state of the REN line and optionally the device remote/local state. (Constants.GPIB_REN*) Returns: return value of the library call. Return type: VISAStatus
-
disable_event
(event_type, mechanism)¶ Disables notification of the specified event type(s) via the specified mechanism(s).
Parameters: - event_type – Logical event identifier.
- mechanism – Specifies event handling mechanisms to be disabled. (Constants.VI_QUEUE, .VI_HNDLR, .VI_SUSPEND_HNDLR, .VI_ALL_MECH)
-
discard_events
(event_type, mechanism)¶ Discards event occurrences for specified event types and mechanisms in this resource.
Parameters: - event_type – Logical event identifier.
- mechanism – Specifies event handling mechanisms to be dicarded. (Constants.VI_QUEUE, .VI_HNDLR, .VI_SUSPEND_HNDLR, .VI_ALL_MECH)
-
enable_event
(event_type, mechanism, context=None)¶ Enable event occurrences for specified event types and mechanisms in this resource.
Parameters: - event_type – Logical event identifier.
- mechanism – Specifies event handling mechanisms to be enabled. (Constants.VI_QUEUE, .VI_HNDLR, .VI_SUSPEND_HNDLR)
- context – Not currently used, leave as None.
-
flush
(mask)[source]¶ Manually clears the specified buffers.
Depending on the mask this can cause the buffer data to be written to the device.
Parameters: mask – Specifies the action to be taken with flushing the buffer. See highlevel.VisaLibraryBase.flush for a detailed description.
-
get_visa_attribute
(name)¶ Retrieves the state of an attribute in this resource.
Parameters: name – Resource attribute for which the state query is made (see Attributes.*) Returns: The state of the queried attribute for a specified resource. Return type: unicode (Py2) or str (Py3), list or other type
-
ignore_warning
(*warnings_constants)¶ Ignoring warnings context manager for the current resource.
Parameters: warnings_constants – constants identifying the warnings to ignore.
-
implementation_version
¶ - VI_ATTR_RSRC_IMPL_VERSION is the resource version that uniquely identifies
- each of the different 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, handler, user_handle=None)¶ Installs handlers for event callbacks in this resource.
Parameters: - event_type – Logical event identifier.
- handler – Interpreted as a valid reference to a handler to be installed by a client application.
- user_handle – A value specified by an application that can be used for identifying handlers uniquely for an event type.
Returns: user handle (a ctypes object)
-
interface_number
¶ VI_ATTR_INTF_NUM specifies the board number for the given interface.
VISA Attribute: VI_ATTR_INTF_NUM (1073676662) Type: int Range: 0 <= value <= 65535
-
interface_type
¶ The interface type of the resource as a number.
-
io_protocol
¶ - VI_ATTR_IO_PROT specifies which 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: int Range: 0 <= value <= 65535
-
is_controller_in_charge
¶ - This attribute shows whether the specified GPIB interface is currently
- CIC (Controller In Charge).
VISA Attribute: VI_ATTR_GPIB_CIC_STATE (1073676382) Type: bool
-
is_system_controller
¶ - This attribute shows whether the specified GPIB interface is currently
- the system controller. In some implementations, this attribute may be modified only through a configuration utility. On these systems this attribute is read-only (RO).
VISA Attribute: VI_ATTR_GPIB_SYS_CNTRL_STATE (1073676392) Type: bool
-
last_status
¶ Last status code for this session.
Return type: pyvisa.constants.StatusCode
-
lock
(timeout='default', requested_key=None)¶ Establish a shared lock to the resource.
Parameters: - timeout – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. (Defaults to self.timeout)
- requested_key – 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
-
lock_context
(timeout='default', requested_key='exclusive')¶ A context that locks
Parameters: - timeout – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. (Defaults to self.timeout)
- requested_key – 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.
The returned context is the access_key if applicable.
-
lock_excl
(timeout='default')¶ Establish an exclusive lock to the resource.
Parameters: timeout – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. (Defaults to self.timeout)
-
lock_state
¶ - VI_ATTR_RSRC_LOCK_STATE indicates the 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
¶ - This attribute shows the current state of the GPIB NDAC (Not Data
- ACcepted) interface line.
VISA Attribute: VI_ATTR_GPIB_NDAC_STATE (1073676386) Type: :class:pyvisa.constants.LineState
-
open
(access_mode=<AccessModes.no_lock: 0>, open_timeout=5000)¶ Opens a session to the specified resource.
Parameters: - access_mode (
pyvisa.constants.AccessModes
) – Specifies the mode by which the resource is to be accessed. - open_timeout (int) – If the
access_mode
parameter requests a lock, then this parameter specifies the absolute time period (in milliseconds) that the resource waits to get unlocked before this operation returns an error.
- access_mode (
-
pass_control
(primary_address, secondary_address)¶ Tell the GPIB device at the specified address to become controller in charge (CIC).
Corresponds to viGpibPassControl function of the VISA library.
Parameters: - primary_address – Primary address of the GPIB device to which you want to pass control.
- secondary_address – Secondary address of the targeted GPIB device. If the targeted device does not have a secondary address, this parameter should contain the value Constants.NO_SEC_ADDR.
Returns: return value of the library call.
Return type: VISAStatus
-
primary_address
¶ - VI_ATTR_GPIB_PRIMARY_ADDR specifies the 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
-
classmethod
register
(interface_type, resource_class)¶
-
remote_enabled
¶ - VI_ATTR_GPIB_REN_STATE returns the 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
¶ - VI_ATTR_RSRC_CLASS specifies the resource class (for example, “INSTR”)
- as defined by the canonical resource name.
VISA Attribute: VI_ATTR_RSRC_CLASS (3221159937)
-
resource_info
¶ Get the extended information of this resource.
Parameters: resource_name – Unique symbolic name of a resource. Return type: pyvisa.highlevel.ResourceInfo
-
resource_manufacturer_name
¶ - VI_ATTR_RSRC_MANF_NAME is a string that corresponds to the 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
¶ - VI_ATTR_RSRC_MANF_NAME is a string that corresponds to the 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_NAME (3221159938)
-
secondary_address
¶ - VI_ATTR_GPIB_SECONDARY_ADDR specifies the 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)¶ Write GPIB command bytes on the bus.
Corresponds to viGpibCommand function of the VISA library.
Parameters: data (bytes) – data tor write. Returns: Number of written bytes, return value of the library call. Return type: int, VISAStatus
-
send_end
¶ - VI_ATTR_SEND_END_EN specifies whether to assert END during the
- transfer of the last byte of the buffer.
VISA Attribute: VI_ATTR_SEND_END_EN (1073676310) Type: bool
-
send_ifc
()¶ Pulse the interface clear line (IFC) for at least 100 microseconds.
Corresponds to viGpibSendIFC function of the VISA library.
Returns: return value of the library call. Return type: VISAStatus
-
session
¶ Resource session handle.
Raises: pyvisa.errors.InvalidSession
if session is closed.
-
set_visa_attribute
(name, state)¶ Sets the state of an attribute.
Parameters: - name – Attribute for which the state is to be modified. (Attributes.*)
- state – The state of the attribute to be set for the specified object.
Returns: return value of the library call.
Return type:
-
spec_version
¶ - VI_ATTR_RSRC_SPEC_VERSION is the resource version that uniquely identifies
- the 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
¶ The timeout in milliseconds for all resource I/O operations.
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 asfloat('+inf')
)
To set an infinite timeout, you can also use:
>>> del instrument.timeout
- immediate (
-
uninstall_handler
(event_type, handler, user_handle=None)¶ Uninstalls handlers for events in this resource.
Parameters: - event_type – Logical event identifier.
- handler – Interpreted as a valid reference to a handler to be uninstalled by a client application.
- user_handle – The user handle (ctypes object or None) returned by install_handler.
-
unlock
()¶ Relinquishes a lock for the specified resource.
-
visa_attributes_classes
= [<class 'pyvisa.attributes.AttrVI_ATTR_INTF_INST_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_MAX_QUEUE_LENGTH'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_TYPE'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_RM_SESSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_CLASS'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_IMPL_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_LOCK_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_SPEC_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_TMO_VALUE'>, <class 'pyvisa.attributes.AttrVI_ATTR_WR_BUF_SIZE'>, <class 'pyvisa.attributes.AttrVI_ATTR_DEV_STATUS_BYTE'>, <class 'pyvisa.attributes.AttrVI_ATTR_TRIG_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_GPIB_HS488_CBL_LEN'>, <class 'pyvisa.attributes.AttrVI_ATTR_GPIB_ADDR_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_GPIB_REN_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_IO_PROT'>, <class 'pyvisa.attributes.AttrVI_ATTR_RD_BUF_SIZE'>, <class 'pyvisa.attributes.AttrVI_ATTR_GPIB_SECONDARY_ADDR'>, <class 'pyvisa.attributes.AttrVI_ATTR_GPIB_SYS_CNTRL_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_GPIB_CIC_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RD_BUF_OPER_MODE'>, <class 'pyvisa.attributes.AttrVI_ATTR_TERMCHAR_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_GPIB_PRIMARY_ADDR'>, <class 'pyvisa.attributes.AttrVI_ATTR_GPIB_SRQ_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_GPIB_ATN_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_WR_BUF_OPER_MODE'>, <class 'pyvisa.attributes.AttrVI_ATTR_DMA_ALLOW_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_SEND_END_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_TERMCHAR'>, <class 'pyvisa.attributes.AttrVI_ATTR_FILE_APPEND_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_GPIB_NDAC_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_INST_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_MAX_QUEUE_LENGTH'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_TYPE'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_RM_SESSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_CLASS'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_IMPL_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_LOCK_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_SPEC_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_TMO_VALUE'>]¶
-
wait_on_event
(in_event_type, timeout, capture_timeout=False)¶ Waits for an occurrence of the specified event in this resource.
Parameters: - in_event_type – Logical identifier of the event(s) to wait for.
- timeout – Absolute time period in time units that the resource shall wait for a specified event to occur before returning the time elapsed error. The time unit is in milliseconds. None means waiting forever if necessary.
- capture_timeout – When True will not produce a VisaIOError(VI_ERROR_TMO) but instead return a WaitResponse with timed_out=True
Returns: A WaitResponse object that contains event_type, context and ret value.
-
class
pyvisa.resources.
FirewireInstrument
(resource_manager, resource_name)[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()
.-
before_close
()¶ Called just before closing an instrument.
-
clear
()¶ Clears this resource
-
close
()¶ Closes the VISA session and marks the handle as invalid.
-
disable_event
(event_type, mechanism)¶ Disables notification of the specified event type(s) via the specified mechanism(s).
Parameters: - event_type – Logical event identifier.
- mechanism – Specifies event handling mechanisms to be disabled. (Constants.VI_QUEUE, .VI_HNDLR, .VI_SUSPEND_HNDLR, .VI_ALL_MECH)
-
discard_events
(event_type, mechanism)¶ Discards event occurrences for specified event types and mechanisms in this resource.
Parameters: - event_type – Logical event identifier.
- mechanism – Specifies event handling mechanisms to be dicarded. (Constants.VI_QUEUE, .VI_HNDLR, .VI_SUSPEND_HNDLR, .VI_ALL_MECH)
-
enable_event
(event_type, mechanism, context=None)¶ Enable event occurrences for specified event types and mechanisms in this resource.
Parameters: - event_type – Logical event identifier.
- mechanism – Specifies event handling mechanisms to be enabled. (Constants.VI_QUEUE, .VI_HNDLR, .VI_SUSPEND_HNDLR)
- context – Not currently used, leave as None.
-
get_visa_attribute
(name)¶ Retrieves the state of an attribute in this resource.
Parameters: name – Resource attribute for which the state query is made (see Attributes.*) Returns: The state of the queried attribute for a specified resource. Return type: unicode (Py2) or str (Py3), list or other type
-
ignore_warning
(*warnings_constants)¶ Ignoring warnings context manager for the current resource.
Parameters: warnings_constants – constants identifying the warnings to ignore.
-
implementation_version
¶ - VI_ATTR_RSRC_IMPL_VERSION is the resource version that uniquely identifies
- each of the different 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, handler, user_handle=None)¶ Installs handlers for event callbacks in this resource.
Parameters: - event_type – Logical event identifier.
- handler – Interpreted as a valid reference to a handler to be installed by a client application.
- user_handle – A value specified by an application that can be used for identifying handlers uniquely for an event type.
Returns: user handle (a ctypes object)
-
interface_number
¶ VI_ATTR_INTF_NUM specifies the board number for the given interface.
VISA Attribute: VI_ATTR_INTF_NUM (1073676662) Type: int Range: 0 <= value <= 65535
-
interface_type
¶ The interface type of the resource as a number.
-
last_status
¶ Last status code for this session.
Return type: pyvisa.constants.StatusCode
-
lock
(timeout='default', requested_key=None)¶ Establish a shared lock to the resource.
Parameters: - timeout – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. (Defaults to self.timeout)
- requested_key – 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
-
lock_context
(timeout='default', requested_key='exclusive')¶ A context that locks
Parameters: - timeout – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. (Defaults to self.timeout)
- requested_key – 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.
The returned context is the access_key if applicable.
-
lock_excl
(timeout='default')¶ Establish an exclusive lock to the resource.
Parameters: timeout – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. (Defaults to self.timeout)
-
lock_state
¶ - VI_ATTR_RSRC_LOCK_STATE indicates the 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, offset, length, width, extended=False)¶ Moves a block of data to local memory from the specified address space and offset.
Parameters: - space – Specifies the address space. (Constants.*SPACE*)
- offset – Offset (in bytes) of the address or register from which to read.
- length – Number of elements to transfer, where the data width of the elements to transfer is identical to the source data width.
- width – Number of bits to read per element.
- extended – Use 64 bits offset independent of the platform.
-
move_out
(space, offset, length, data, width, extended=False)¶ Moves a block of data from local memory to the specified address space and offset.
Parameters: - space – Specifies the address space. (Constants.*SPACE*)
- offset – Offset (in bytes) of the address or register from which to read.
- length – Number of elements to transfer, where the data width of the elements to transfer is identical to the source data width.
- data – Data to write to bus.
- width – Number of bits to read per element.
- extended – Use 64 bits offset independent of the platform.
-
open
(access_mode=<AccessModes.no_lock: 0>, open_timeout=5000)¶ Opens a session to the specified resource.
Parameters: - access_mode (
pyvisa.constants.AccessModes
) – Specifies the mode by which the resource is to be accessed. - open_timeout (int) – If the
access_mode
parameter requests a lock, then this parameter specifies the absolute time period (in milliseconds) that the resource waits to get unlocked before this operation returns an error.
- access_mode (
-
read_memory
(space, offset, width, extended=False)¶ Reads in an 8-bit, 16-bit, 32-bit, or 64-bit value from the specified memory space and offset.
Parameters: - space – Specifies the address space. (Constants.*SPACE*)
- offset – Offset (in bytes) of the address or register from which to read.
- width – Number of bits to read.
- extended – Use 64 bits offset independent of the platform.
Returns: Data read from memory.
Corresponds to viIn* functions of the visa library.
-
classmethod
register
(interface_type, resource_class)¶
-
resource_class
¶ - VI_ATTR_RSRC_CLASS specifies the resource class (for example, “INSTR”)
- as defined by the canonical resource name.
VISA Attribute: VI_ATTR_RSRC_CLASS (3221159937)
-
resource_info
¶ Get the extended information of this resource.
Parameters: resource_name – Unique symbolic name of a resource. Return type: pyvisa.highlevel.ResourceInfo
-
resource_manufacturer_name
¶ - VI_ATTR_RSRC_MANF_NAME is a string that corresponds to the 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
¶ - VI_ATTR_RSRC_MANF_NAME is a string that corresponds to the 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_NAME (3221159938)
-
session
¶ Resource session handle.
Raises: pyvisa.errors.InvalidSession
if session is closed.
-
set_visa_attribute
(name, state)¶ Sets the state of an attribute.
Parameters: - name – Attribute for which the state is to be modified. (Attributes.*)
- state – The state of the attribute to be set for the specified object.
Returns: return value of the library call.
Return type:
-
spec_version
¶ - VI_ATTR_RSRC_SPEC_VERSION is the resource version that uniquely identifies
- the 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
¶ The timeout in milliseconds for all resource I/O operations.
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 asfloat('+inf')
)
To set an infinite timeout, you can also use:
>>> del instrument.timeout
- immediate (
-
uninstall_handler
(event_type, handler, user_handle=None)¶ Uninstalls handlers for events in this resource.
Parameters: - event_type – Logical event identifier.
- handler – Interpreted as a valid reference to a handler to be uninstalled by a client application.
- user_handle – The user handle (ctypes object or None) returned by install_handler.
-
unlock
()¶ Relinquishes a lock for the specified resource.
-
visa_attributes_classes
= [<class 'pyvisa.attributes.AttrVI_ATTR_INTF_INST_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_MAX_QUEUE_LENGTH'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_TYPE'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_RM_SESSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_CLASS'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_IMPL_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_LOCK_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_SPEC_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_TMO_VALUE'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_INST_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_MAX_QUEUE_LENGTH'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_TYPE'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_RM_SESSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_CLASS'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_IMPL_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_LOCK_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_SPEC_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_TMO_VALUE'>]¶
-
wait_on_event
(in_event_type, timeout, capture_timeout=False)¶ Waits for an occurrence of the specified event in this resource.
Parameters: - in_event_type – Logical identifier of the event(s) to wait for.
- timeout – Absolute time period in time units that the resource shall wait for a specified event to occur before returning the time elapsed error. The time unit is in milliseconds. None means waiting forever if necessary.
- capture_timeout – When True will not produce a VisaIOError(VI_ERROR_TMO) but instead return a WaitResponse with timed_out=True
Returns: A WaitResponse object that contains event_type, context and ret value.
-
write_memory
(space, offset, data, width, extended=False)¶ Write in an 8-bit, 16-bit, 32-bit, value to the specified memory space and offset.
Parameters: - space – Specifies the address space. (Constants.*SPACE*)
- offset – Offset (in bytes) of the address or register from which to read.
- data – Data to write to bus.
- width – Number of bits to read.
- extended – Use 64 bits offset independent of the platform.
Corresponds to viOut* functions of the visa library.
-
class
pyvisa.resources.
PXIInstrument
(resource_manager, resource_name)[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
¶ - This attribute specifies whether I/O accesses should use DMA (VI_TRUE)
- or Programmed I/O (VI_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
()¶ Called just before closing an instrument.
-
clear
()¶ Clears this resource
-
close
()¶ Closes the VISA session and marks the handle as invalid.
-
destination_increment
¶ - VI_ATTR_DEST_INCREMENT is used in the viMoveOutXX() operations to
- specify by how many elements the destination offset is to be incremented after every 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, mechanism)¶ Disables notification of the specified event type(s) via the specified mechanism(s).
Parameters: - event_type – Logical event identifier.
- mechanism – Specifies event handling mechanisms to be disabled. (Constants.VI_QUEUE, .VI_HNDLR, .VI_SUSPEND_HNDLR, .VI_ALL_MECH)
-
discard_events
(event_type, mechanism)¶ Discards event occurrences for specified event types and mechanisms in this resource.
Parameters: - event_type – Logical event identifier.
- mechanism – Specifies event handling mechanisms to be dicarded. (Constants.VI_QUEUE, .VI_HNDLR, .VI_SUSPEND_HNDLR, .VI_ALL_MECH)
-
enable_event
(event_type, mechanism, context=None)¶ Enable event occurrences for specified event types and mechanisms in this resource.
Parameters: - event_type – Logical event identifier.
- mechanism – Specifies event handling mechanisms to be enabled. (Constants.VI_QUEUE, .VI_HNDLR, .VI_SUSPEND_HNDLR)
- context – Not currently used, leave as None.
-
get_visa_attribute
(name)¶ Retrieves the state of an attribute in this resource.
Parameters: name – Resource attribute for which the state query is made (see Attributes.*) Returns: The state of the queried attribute for a specified resource. Return type: unicode (Py2) or str (Py3), list or other type
-
ignore_warning
(*warnings_constants)¶ Ignoring warnings context manager for the current resource.
Parameters: warnings_constants – constants identifying the warnings to ignore.
-
implementation_version
¶ - VI_ATTR_RSRC_IMPL_VERSION is the resource version that uniquely identifies
- each of the different 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, handler, user_handle=None)¶ Installs handlers for event callbacks in this resource.
Parameters: - event_type – Logical event identifier.
- handler – Interpreted as a valid reference to a handler to be installed by a client application.
- user_handle – A value specified by an application that can be used for identifying handlers uniquely for an event type.
Returns: user handle (a ctypes object)
-
interface_number
¶ VI_ATTR_INTF_NUM specifies the board number for the given interface.
VISA Attribute: VI_ATTR_INTF_NUM (1073676662) Type: int Range: 0 <= value <= 65535
-
interface_type
¶ The interface type of the resource as a number.
-
last_status
¶ Last status code for this session.
Return type: pyvisa.constants.StatusCode
-
lock
(timeout='default', requested_key=None)¶ Establish a shared lock to the resource.
Parameters: - timeout – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. (Defaults to self.timeout)
- requested_key – 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
-
lock_context
(timeout='default', requested_key='exclusive')¶ A context that locks
Parameters: - timeout – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. (Defaults to self.timeout)
- requested_key – 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.
The returned context is the access_key if applicable.
-
lock_excl
(timeout='default')¶ Establish an exclusive lock to the resource.
Parameters: timeout – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. (Defaults to self.timeout)
-
lock_state
¶ - VI_ATTR_RSRC_LOCK_STATE indicates the 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
¶ - VI_ATTR_MANF_ID is the manufacturer identification number of the
- device.
VISA Attribute: VI_ATTR_MANF_ID (1073676505) Type: int Range: 0 <= value <= 65535
-
manufacturer_name
¶ This string attribute is the manufacturer name.
VISA Attribute: VI_ATTR_MANF_NAME (3221160050)
-
model_code
¶ VI_ATTR_MODEL_CODE specifies the model code for the device.
VISA Attribute: VI_ATTR_MODEL_CODE (1073676511) Type: int Range: 0 <= value <= 65535
-
model_name
¶ This string attribute is the model name of the device.
VISA Attribute: VI_ATTR_MODEL_NAME (3221160055)
-
move_in
(space, offset, length, width, extended=False)¶ Moves a block of data to local memory from the specified address space and offset.
Parameters: - space – Specifies the address space. (Constants.*SPACE*)
- offset – Offset (in bytes) of the address or register from which to read.
- length – Number of elements to transfer, where the data width of the elements to transfer is identical to the source data width.
- width – Number of bits to read per element.
- extended – Use 64 bits offset independent of the platform.
-
move_out
(space, offset, length, data, width, extended=False)¶ Moves a block of data from local memory to the specified address space and offset.
Parameters: - space – Specifies the address space. (Constants.*SPACE*)
- offset – Offset (in bytes) of the address or register from which to read.
- length – Number of elements to transfer, where the data width of the elements to transfer is identical to the source data width.
- data – Data to write to bus.
- width – Number of bits to read per element.
- extended – Use 64 bits offset independent of the platform.
-
open
(access_mode=<AccessModes.no_lock: 0>, open_timeout=5000)¶ Opens a session to the specified resource.
Parameters: - access_mode (
pyvisa.constants.AccessModes
) – Specifies the mode by which the resource is to be accessed. - open_timeout (int) – If the
access_mode
parameter requests a lock, then this parameter specifies the absolute time period (in milliseconds) that the resource waits to get unlocked before this operation returns an error.
- access_mode (
-
read_memory
(space, offset, width, extended=False)¶ Reads in an 8-bit, 16-bit, 32-bit, or 64-bit value from the specified memory space and offset.
Parameters: - space – Specifies the address space. (Constants.*SPACE*)
- offset – Offset (in bytes) of the address or register from which to read.
- width – Number of bits to read.
- extended – Use 64 bits offset independent of the platform.
Returns: Data read from memory.
Corresponds to viIn* functions of the visa library.
-
classmethod
register
(interface_type, resource_class)¶
-
resource_class
¶ - VI_ATTR_RSRC_CLASS specifies the resource class (for example, “INSTR”)
- as defined by the canonical resource name.
VISA Attribute: VI_ATTR_RSRC_CLASS (3221159937)
-
resource_info
¶ Get the extended information of this resource.
Parameters: resource_name – Unique symbolic name of a resource. Return type: pyvisa.highlevel.ResourceInfo
-
resource_manufacturer_name
¶ - VI_ATTR_RSRC_MANF_NAME is a string that corresponds to the 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
¶ - VI_ATTR_RSRC_MANF_NAME is a string that corresponds to the 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_NAME (3221159938)
-
session
¶ Resource session handle.
Raises: pyvisa.errors.InvalidSession
if session is closed.
-
set_visa_attribute
(name, state)¶ Sets the state of an attribute.
Parameters: - name – Attribute for which the state is to be modified. (Attributes.*)
- state – The state of the attribute to be set for the specified object.
Returns: return value of the library call.
Return type:
-
source_increment
¶ - VI_ATTR_SRC_INCREMENT is used in the viMoveInXX() operations to
- specify by how many elements the source offset is to be incremented after every 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
¶ - VI_ATTR_RSRC_SPEC_VERSION is the resource version that uniquely identifies
- the 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
¶ The timeout in milliseconds for all resource I/O operations.
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 asfloat('+inf')
)
To set an infinite timeout, you can also use:
>>> del instrument.timeout
- immediate (
-
uninstall_handler
(event_type, handler, user_handle=None)¶ Uninstalls handlers for events in this resource.
Parameters: - event_type – Logical event identifier.
- handler – Interpreted as a valid reference to a handler to be uninstalled by a client application.
- user_handle – The user handle (ctypes object or None) returned by install_handler.
-
unlock
()¶ Relinquishes a lock for the specified resource.
-
visa_attributes_classes
= [<class 'pyvisa.attributes.AttrVI_ATTR_INTF_INST_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_MAX_QUEUE_LENGTH'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_TYPE'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_RM_SESSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_CLASS'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_IMPL_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_LOCK_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_SPEC_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_TMO_VALUE'>, <class 'pyvisa.attributes.AttrVI_ATTR_PXI_FUNC_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_MODEL_CODE'>, <class 'pyvisa.attributes.AttrVI_ATTR_PXI_MEM_TYPE_BARX'>, <class 'pyvisa.attributes.AttrVI_ATTR_PXI_SLOTPATH'>, <class 'pyvisa.attributes.AttrVI_ATTR_PXI_TRIG_BUS'>, <class 'pyvisa.attributes.AttrVI_ATTR_TRIG_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_PXI_DSTAR_BUS'>, <class 'pyvisa.attributes.AttrVI_ATTR_PXI_CHASSIS'>, <class 'pyvisa.attributes.AttrVI_ATTR_PXI_DSTAR_SET'>, <class 'pyvisa.attributes.AttrVI_ATTR_PXI_MEM_SIZE_BARX'>, <class 'pyvisa.attributes.AttrVI_ATTR_PXI_SLOT_LWIDTH'>, <class 'pyvisa.attributes.AttrVI_ATTR_PXI_STAR_TRIG_LINE'>, <class 'pyvisa.attributes.AttrVI_ATTR_DEST_INCREMENT'>, <class 'pyvisa.attributes.AttrVI_ATTR_SLOT'>, <class 'pyvisa.attributes.AttrVI_ATTR_PXI_DEV_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_PXI_MAX_LWIDTH'>, <class 'pyvisa.attributes.AttrVI_ATTR_PXI_ACTUAL_LWIDTH'>, <class 'pyvisa.attributes.AttrVI_ATTR_PXI_MEM_BASE_BARX'>, <class 'pyvisa.attributes.AttrVI_ATTR_PXI_SLOT_LBUS_RIGHT'>, <class 'pyvisa.attributes.AttrVI_ATTR_PXI_STAR_TRIG_BUS'>, <class 'pyvisa.attributes.AttrVI_ATTR_SRC_INCREMENT'>, <class 'pyvisa.attributes.AttrVI_ATTR_PXI_BUS_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_WIN_ACCESS'>, <class 'pyvisa.attributes.AttrVI_ATTR_PXI_IS_EXPRESS'>, <class 'pyvisa.attributes.AttrVI_ATTR_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_MODEL_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_PXI_SLOT_LBUS_LEFT'>, <class 'pyvisa.attributes.AttrVI_ATTR_DMA_ALLOW_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_INST_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_MAX_QUEUE_LENGTH'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_TYPE'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_RM_SESSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_CLASS'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_IMPL_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_LOCK_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_SPEC_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_TMO_VALUE'>]¶
-
wait_on_event
(in_event_type, timeout, capture_timeout=False)¶ Waits for an occurrence of the specified event in this resource.
Parameters: - in_event_type – Logical identifier of the event(s) to wait for.
- timeout – Absolute time period in time units that the resource shall wait for a specified event to occur before returning the time elapsed error. The time unit is in milliseconds. None means waiting forever if necessary.
- capture_timeout – When True will not produce a VisaIOError(VI_ERROR_TMO) but instead return a WaitResponse with timed_out=True
Returns: A WaitResponse object that contains event_type, context and ret value.
-
write_memory
(space, offset, data, width, extended=False)¶ Write in an 8-bit, 16-bit, 32-bit, value to the specified memory space and offset.
Parameters: - space – Specifies the address space. (Constants.*SPACE*)
- offset – Offset (in bytes) of the address or register from which to read.
- data – Data to write to bus.
- width – Number of bits to read.
- extended – Use 64 bits offset independent of the platform.
Corresponds to viOut* functions of the visa library.
-
class
pyvisa.resources.
PXIMemory
(resource_manager, resource_name)[source]¶ Communicates with to devices of type PXI[interface]::MEMACC
Do not instantiate directly, use
pyvisa.highlevel.ResourceManager.open_resource()
.-
before_close
()¶ Called just before closing an instrument.
-
clear
()¶ Clears this resource
-
close
()¶ Closes the VISA session and marks the handle as invalid.
-
destination_increment
¶ - VI_ATTR_DEST_INCREMENT is used in the viMoveOutXX() operations to
- specify by how many elements the destination offset is to be incremented after every 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, mechanism)¶ Disables notification of the specified event type(s) via the specified mechanism(s).
Parameters: - event_type – Logical event identifier.
- mechanism – Specifies event handling mechanisms to be disabled. (Constants.VI_QUEUE, .VI_HNDLR, .VI_SUSPEND_HNDLR, .VI_ALL_MECH)
-
discard_events
(event_type, mechanism)¶ Discards event occurrences for specified event types and mechanisms in this resource.
Parameters: - event_type – Logical event identifier.
- mechanism – Specifies event handling mechanisms to be dicarded. (Constants.VI_QUEUE, .VI_HNDLR, .VI_SUSPEND_HNDLR, .VI_ALL_MECH)
-
enable_event
(event_type, mechanism, context=None)¶ Enable event occurrences for specified event types and mechanisms in this resource.
Parameters: - event_type – Logical event identifier.
- mechanism – Specifies event handling mechanisms to be enabled. (Constants.VI_QUEUE, .VI_HNDLR, .VI_SUSPEND_HNDLR)
- context – Not currently used, leave as None.
-
get_visa_attribute
(name)¶ Retrieves the state of an attribute in this resource.
Parameters: name – Resource attribute for which the state query is made (see Attributes.*) Returns: The state of the queried attribute for a specified resource. Return type: unicode (Py2) or str (Py3), list or other type
-
ignore_warning
(*warnings_constants)¶ Ignoring warnings context manager for the current resource.
Parameters: warnings_constants – constants identifying the warnings to ignore.
-
implementation_version
¶ - VI_ATTR_RSRC_IMPL_VERSION is the resource version that uniquely identifies
- each of the different 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, handler, user_handle=None)¶ Installs handlers for event callbacks in this resource.
Parameters: - event_type – Logical event identifier.
- handler – Interpreted as a valid reference to a handler to be installed by a client application.
- user_handle – A value specified by an application that can be used for identifying handlers uniquely for an event type.
Returns: user handle (a ctypes object)
-
interface_number
¶ VI_ATTR_INTF_NUM specifies the board number for the given interface.
VISA Attribute: VI_ATTR_INTF_NUM (1073676662) Type: int Range: 0 <= value <= 65535
-
interface_type
¶ The interface type of the resource as a number.
-
last_status
¶ Last status code for this session.
Return type: pyvisa.constants.StatusCode
-
lock
(timeout='default', requested_key=None)¶ Establish a shared lock to the resource.
Parameters: - timeout – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. (Defaults to self.timeout)
- requested_key – 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
-
lock_context
(timeout='default', requested_key='exclusive')¶ A context that locks
Parameters: - timeout – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. (Defaults to self.timeout)
- requested_key – 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.
The returned context is the access_key if applicable.
-
lock_excl
(timeout='default')¶ Establish an exclusive lock to the resource.
Parameters: timeout – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. (Defaults to self.timeout)
-
lock_state
¶ - VI_ATTR_RSRC_LOCK_STATE indicates the 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, offset, length, width, extended=False)¶ Moves a block of data to local memory from the specified address space and offset.
Parameters: - space – Specifies the address space. (Constants.*SPACE*)
- offset – Offset (in bytes) of the address or register from which to read.
- length – Number of elements to transfer, where the data width of the elements to transfer is identical to the source data width.
- width – Number of bits to read per element.
- extended – Use 64 bits offset independent of the platform.
-
move_out
(space, offset, length, data, width, extended=False)¶ Moves a block of data from local memory to the specified address space and offset.
Parameters: - space – Specifies the address space. (Constants.*SPACE*)
- offset – Offset (in bytes) of the address or register from which to read.
- length – Number of elements to transfer, where the data width of the elements to transfer is identical to the source data width.
- data – Data to write to bus.
- width – Number of bits to read per element.
- extended – Use 64 bits offset independent of the platform.
-
open
(access_mode=<AccessModes.no_lock: 0>, open_timeout=5000)¶ Opens a session to the specified resource.
Parameters: - access_mode (
pyvisa.constants.AccessModes
) – Specifies the mode by which the resource is to be accessed. - open_timeout (int) – If the
access_mode
parameter requests a lock, then this parameter specifies the absolute time period (in milliseconds) that the resource waits to get unlocked before this operation returns an error.
- access_mode (
-
read_memory
(space, offset, width, extended=False)¶ Reads in an 8-bit, 16-bit, 32-bit, or 64-bit value from the specified memory space and offset.
Parameters: - space – Specifies the address space. (Constants.*SPACE*)
- offset – Offset (in bytes) of the address or register from which to read.
- width – Number of bits to read.
- extended – Use 64 bits offset independent of the platform.
Returns: Data read from memory.
Corresponds to viIn* functions of the visa library.
-
classmethod
register
(interface_type, resource_class)¶
-
resource_class
¶ - VI_ATTR_RSRC_CLASS specifies the resource class (for example, “INSTR”)
- as defined by the canonical resource name.
VISA Attribute: VI_ATTR_RSRC_CLASS (3221159937)
-
resource_info
¶ Get the extended information of this resource.
Parameters: resource_name – Unique symbolic name of a resource. Return type: pyvisa.highlevel.ResourceInfo
-
resource_manufacturer_name
¶ - VI_ATTR_RSRC_MANF_NAME is a string that corresponds to the 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
¶ - VI_ATTR_RSRC_MANF_NAME is a string that corresponds to the 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_NAME (3221159938)
-
session
¶ Resource session handle.
Raises: pyvisa.errors.InvalidSession
if session is closed.
-
set_visa_attribute
(name, state)¶ Sets the state of an attribute.
Parameters: - name – Attribute for which the state is to be modified. (Attributes.*)
- state – The state of the attribute to be set for the specified object.
Returns: return value of the library call.
Return type:
-
source_increment
¶ - VI_ATTR_SRC_INCREMENT is used in the viMoveInXX() operations to
- specify by how many elements the source offset is to be incremented after every 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
¶ - VI_ATTR_RSRC_SPEC_VERSION is the resource version that uniquely identifies
- the 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
¶ The timeout in milliseconds for all resource I/O operations.
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 asfloat('+inf')
)
To set an infinite timeout, you can also use:
>>> del instrument.timeout
- immediate (
-
uninstall_handler
(event_type, handler, user_handle=None)¶ Uninstalls handlers for events in this resource.
Parameters: - event_type – Logical event identifier.
- handler – Interpreted as a valid reference to a handler to be uninstalled by a client application.
- user_handle – The user handle (ctypes object or None) returned by install_handler.
-
unlock
()¶ Relinquishes a lock for the specified resource.
-
visa_attributes_classes
= [<class 'pyvisa.attributes.AttrVI_ATTR_INTF_INST_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_MAX_QUEUE_LENGTH'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_TYPE'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_RM_SESSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_CLASS'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_IMPL_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_LOCK_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_SPEC_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_TMO_VALUE'>, <class 'pyvisa.attributes.AttrVI_ATTR_DEST_INCREMENT'>, <class 'pyvisa.attributes.AttrVI_ATTR_SRC_INCREMENT'>, <class 'pyvisa.attributes.AttrVI_ATTR_WIN_ACCESS'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_INST_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_MAX_QUEUE_LENGTH'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_TYPE'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_RM_SESSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_CLASS'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_IMPL_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_LOCK_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_SPEC_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_TMO_VALUE'>]¶
-
wait_on_event
(in_event_type, timeout, capture_timeout=False)¶ Waits for an occurrence of the specified event in this resource.
Parameters: - in_event_type – Logical identifier of the event(s) to wait for.
- timeout – Absolute time period in time units that the resource shall wait for a specified event to occur before returning the time elapsed error. The time unit is in milliseconds. None means waiting forever if necessary.
- capture_timeout – When True will not produce a VisaIOError(VI_ERROR_TMO) but instead return a WaitResponse with timed_out=True
Returns: A WaitResponse object that contains event_type, context and ret value.
-
write_memory
(space, offset, data, width, extended=False)¶ Write in an 8-bit, 16-bit, 32-bit, value to the specified memory space and offset.
Parameters: - space – Specifies the address space. (Constants.*SPACE*)
- offset – Offset (in bytes) of the address or register from which to read.
- data – Data to write to bus.
- width – Number of bits to read.
- extended – Use 64 bits offset independent of the platform.
Corresponds to viOut* functions of the visa library.
-
-
class
pyvisa.resources.
VXIInstrument
(resource_manager, resource_name)[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
¶ - This attribute specifies whether I/O accesses should use DMA (VI_TRUE)
- or Programmed I/O (VI_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
()¶ Called just before closing an instrument.
-
clear
()¶ Clears this resource
-
close
()¶ Closes the VISA session and marks the handle as invalid.
-
destination_increment
¶ - VI_ATTR_DEST_INCREMENT is used in the viMoveOutXX() operations to
- specify by how many elements the destination offset is to be incremented after every 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, mechanism)¶ Disables notification of the specified event type(s) via the specified mechanism(s).
Parameters: - event_type – Logical event identifier.
- mechanism – Specifies event handling mechanisms to be disabled. (Constants.VI_QUEUE, .VI_HNDLR, .VI_SUSPEND_HNDLR, .VI_ALL_MECH)
-
discard_events
(event_type, mechanism)¶ Discards event occurrences for specified event types and mechanisms in this resource.
Parameters: - event_type – Logical event identifier.
- mechanism – Specifies event handling mechanisms to be dicarded. (Constants.VI_QUEUE, .VI_HNDLR, .VI_SUSPEND_HNDLR, .VI_ALL_MECH)
-
enable_event
(event_type, mechanism, context=None)¶ Enable event occurrences for specified event types and mechanisms in this resource.
Parameters: - event_type – Logical event identifier.
- mechanism – Specifies event handling mechanisms to be enabled. (Constants.VI_QUEUE, .VI_HNDLR, .VI_SUSPEND_HNDLR)
- context – Not currently used, leave as None.
-
get_visa_attribute
(name)¶ Retrieves the state of an attribute in this resource.
Parameters: name – Resource attribute for which the state query is made (see Attributes.*) Returns: The state of the queried attribute for a specified resource. Return type: unicode (Py2) or str (Py3), list or other type
-
ignore_warning
(*warnings_constants)¶ Ignoring warnings context manager for the current resource.
Parameters: warnings_constants – constants identifying the warnings to ignore.
-
implementation_version
¶ - VI_ATTR_RSRC_IMPL_VERSION is the resource version that uniquely identifies
- each of the different 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, handler, user_handle=None)¶ Installs handlers for event callbacks in this resource.
Parameters: - event_type – Logical event identifier.
- handler – Interpreted as a valid reference to a handler to be installed by a client application.
- user_handle – A value specified by an application that can be used for identifying handlers uniquely for an event type.
Returns: user handle (a ctypes object)
-
interface_number
¶ VI_ATTR_INTF_NUM specifies the board number for the given interface.
VISA Attribute: VI_ATTR_INTF_NUM (1073676662) Type: int Range: 0 <= value <= 65535
-
interface_type
¶ The interface type of the resource as a number.
-
io_protocol
¶ - VI_ATTR_IO_PROT specifies which 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: int Range: 0 <= value <= 65535
-
is_4882_compliant
¶ - VI_ATTR_4882_COMPLIANT specifies whether the device is 488.2
- compliant.
VISA Attribute: VI_ATTR_4882_COMPLIANT (1073676703) Type: bool
-
last_status
¶ Last status code for this session.
Return type: pyvisa.constants.StatusCode
-
lock
(timeout='default', requested_key=None)¶ Establish a shared lock to the resource.
Parameters: - timeout – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. (Defaults to self.timeout)
- requested_key – 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
-
lock_context
(timeout='default', requested_key='exclusive')¶ A context that locks
Parameters: - timeout – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. (Defaults to self.timeout)
- requested_key – 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.
The returned context is the access_key if applicable.
-
lock_excl
(timeout='default')¶ Establish an exclusive lock to the resource.
Parameters: timeout – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. (Defaults to self.timeout)
-
lock_state
¶ - VI_ATTR_RSRC_LOCK_STATE indicates the 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
¶ - VI_ATTR_MANF_ID is the manufacturer identification number of the
- device.
VISA Attribute: VI_ATTR_MANF_ID (1073676505) Type: int Range: 0 <= value <= 65535
-
manufacturer_name
¶ This string attribute is the manufacturer name.
VISA Attribute: VI_ATTR_MANF_NAME (3221160050)
-
model_code
¶ VI_ATTR_MODEL_CODE specifies the model code for the device.
VISA Attribute: VI_ATTR_MODEL_CODE (1073676511) Type: int Range: 0 <= value <= 65535
-
model_name
¶ This string attribute is the model name of the device.
VISA Attribute: VI_ATTR_MODEL_NAME (3221160055)
-
open
(access_mode=<AccessModes.no_lock: 0>, open_timeout=5000)¶ Opens a session to the specified resource.
Parameters: - access_mode (
pyvisa.constants.AccessModes
) – Specifies the mode by which the resource is to be accessed. - open_timeout (int) – If the
access_mode
parameter requests a lock, then this parameter specifies the absolute time period (in milliseconds) that the resource waits to get unlocked before this operation returns an error.
- access_mode (
-
classmethod
register
(interface_type, resource_class)¶
-
resource_class
¶ - VI_ATTR_RSRC_CLASS specifies the resource class (for example, “INSTR”)
- as defined by the canonical resource name.
VISA Attribute: VI_ATTR_RSRC_CLASS (3221159937)
-
resource_info
¶ Get the extended information of this resource.
Parameters: resource_name – Unique symbolic name of a resource. Return type: pyvisa.highlevel.ResourceInfo
-
resource_manufacturer_name
¶ - VI_ATTR_RSRC_MANF_NAME is a string that corresponds to the 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
¶ - VI_ATTR_RSRC_MANF_NAME is a string that corresponds to the 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_NAME (3221159938)
-
send_end
¶ - VI_ATTR_SEND_END_EN specifies whether to assert END 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: pyvisa.errors.InvalidSession
if session is closed.
-
set_visa_attribute
(name, state)¶ Sets the state of an attribute.
Parameters: - name – Attribute for which the state is to be modified. (Attributes.*)
- state – The state of the attribute to be set for the specified object.
Returns: return value of the library call.
Return type:
-
source_increment
¶ - VI_ATTR_SRC_INCREMENT is used in the viMoveInXX() operations to
- specify by how many elements the source offset is to be incremented after every 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
¶ - VI_ATTR_RSRC_SPEC_VERSION is the resource version that uniquely identifies
- the 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
¶ The timeout in milliseconds for all resource I/O operations.
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 asfloat('+inf')
)
To set an infinite timeout, you can also use:
>>> del instrument.timeout
- immediate (
-
uninstall_handler
(event_type, handler, user_handle=None)¶ Uninstalls handlers for events in this resource.
Parameters: - event_type – Logical event identifier.
- handler – Interpreted as a valid reference to a handler to be uninstalled by a client application.
- user_handle – The user handle (ctypes object or None) returned by install_handler.
-
unlock
()¶ Relinquishes a lock for the specified resource.
-
visa_attributes_classes
= [<class 'pyvisa.attributes.AttrVI_ATTR_INTF_INST_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_MAX_QUEUE_LENGTH'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_TYPE'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_RM_SESSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_CLASS'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_IMPL_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_LOCK_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_SPEC_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_TMO_VALUE'>, <class 'pyvisa.attributes.AttrVI_ATTR_WR_BUF_SIZE'>, <class 'pyvisa.attributes.AttrVI_ATTR_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_MODEL_CODE'>, <class 'pyvisa.attributes.AttrVI_ATTR_FDC_USE_PAIR'>, <class 'pyvisa.attributes.AttrVI_ATTR_4882_COMPLIANT'>, <class 'pyvisa.attributes.AttrVI_ATTR_SRC_ACCESS_PRIV'>, <class 'pyvisa.attributes.AttrVI_ATTR_TRIG_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_VXI_TRIG_DIR'>, <class 'pyvisa.attributes.AttrVI_ATTR_WIN_BYTE_ORDER'>, <class 'pyvisa.attributes.AttrVI_ATTR_IMMEDIATE_SERV'>, <class 'pyvisa.attributes.AttrVI_ATTR_IO_PROT'>, <class 'pyvisa.attributes.AttrVI_ATTR_MAINFRAME_LA'>, <class 'pyvisa.attributes.AttrVI_ATTR_MEM_SPACE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RD_BUF_SIZE'>, <class 'pyvisa.attributes.AttrVI_ATTR_DEST_INCREMENT'>, <class 'pyvisa.attributes.AttrVI_ATTR_FDC_MODE'>, <class 'pyvisa.attributes.AttrVI_ATTR_SLOT'>, <class 'pyvisa.attributes.AttrVI_ATTR_VXI_LA'>, <class 'pyvisa.attributes.AttrVI_ATTR_VXI_TRIG_SUPPORT'>, <class 'pyvisa.attributes.AttrVI_ATTR_WIN_ACCESS_PRIV'>, <class 'pyvisa.attributes.AttrVI_ATTR_VXI_TRIG_LINES_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_DEST_ACCESS_PRIV'>, <class 'pyvisa.attributes.AttrVI_ATTR_RD_BUF_OPER_MODE'>, <class 'pyvisa.attributes.AttrVI_ATTR_DEST_BYTE_ORDER'>, <class 'pyvisa.attributes.AttrVI_ATTR_FDC_CHNL'>, <class 'pyvisa.attributes.AttrVI_ATTR_SRC_INCREMENT'>, <class 'pyvisa.attributes.AttrVI_ATTR_SUPPRESS_END_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_TERMCHAR_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_VXI_DEV_CLASS'>, <class 'pyvisa.attributes.AttrVI_ATTR_WIN_ACCESS'>, <class 'pyvisa.attributes.AttrVI_ATTR_WR_BUF_OPER_MODE'>, <class 'pyvisa.attributes.AttrVI_ATTR_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_MODEL_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_CMDR_LA'>, <class 'pyvisa.attributes.AttrVI_ATTR_DMA_ALLOW_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_SRC_BYTE_ORDER'>, <class 'pyvisa.attributes.AttrVI_ATTR_SEND_END_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_TERMCHAR'>, <class 'pyvisa.attributes.AttrVI_ATTR_FILE_APPEND_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_INST_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_MAX_QUEUE_LENGTH'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_TYPE'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_RM_SESSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_CLASS'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_IMPL_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_LOCK_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_SPEC_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_TMO_VALUE'>]¶
-
wait_on_event
(in_event_type, timeout, capture_timeout=False)¶ Waits for an occurrence of the specified event in this resource.
Parameters: - in_event_type – Logical identifier of the event(s) to wait for.
- timeout – Absolute time period in time units that the resource shall wait for a specified event to occur before returning the time elapsed error. The time unit is in milliseconds. None means waiting forever if necessary.
- capture_timeout – When True will not produce a VisaIOError(VI_ERROR_TMO) but instead return a WaitResponse with timed_out=True
Returns: A WaitResponse object that contains event_type, context and ret value.
-
class
pyvisa.resources.
VXIMemory
(resource_manager, resource_name)[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
¶ - This attribute specifies whether I/O accesses should use DMA (VI_TRUE)
- or Programmed I/O (VI_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
()¶ Called just before closing an instrument.
-
clear
()¶ Clears this resource
-
close
()¶ Closes the VISA session and marks the handle as invalid.
-
destination_increment
¶ - VI_ATTR_DEST_INCREMENT is used in the viMoveOutXX() operations to
- specify by how many elements the destination offset is to be incremented after every 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, mechanism)¶ Disables notification of the specified event type(s) via the specified mechanism(s).
Parameters: - event_type – Logical event identifier.
- mechanism – Specifies event handling mechanisms to be disabled. (Constants.VI_QUEUE, .VI_HNDLR, .VI_SUSPEND_HNDLR, .VI_ALL_MECH)
-
discard_events
(event_type, mechanism)¶ Discards event occurrences for specified event types and mechanisms in this resource.
Parameters: - event_type – Logical event identifier.
- mechanism – Specifies event handling mechanisms to be dicarded. (Constants.VI_QUEUE, .VI_HNDLR, .VI_SUSPEND_HNDLR, .VI_ALL_MECH)
-
enable_event
(event_type, mechanism, context=None)¶ Enable event occurrences for specified event types and mechanisms in this resource.
Parameters: - event_type – Logical event identifier.
- mechanism – Specifies event handling mechanisms to be enabled. (Constants.VI_QUEUE, .VI_HNDLR, .VI_SUSPEND_HNDLR)
- context – Not currently used, leave as None.
-
get_visa_attribute
(name)¶ Retrieves the state of an attribute in this resource.
Parameters: name – Resource attribute for which the state query is made (see Attributes.*) Returns: The state of the queried attribute for a specified resource. Return type: unicode (Py2) or str (Py3), list or other type
-
ignore_warning
(*warnings_constants)¶ Ignoring warnings context manager for the current resource.
Parameters: warnings_constants – constants identifying the warnings to ignore.
-
implementation_version
¶ - VI_ATTR_RSRC_IMPL_VERSION is the resource version that uniquely identifies
- each of the different 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, handler, user_handle=None)¶ Installs handlers for event callbacks in this resource.
Parameters: - event_type – Logical event identifier.
- handler – Interpreted as a valid reference to a handler to be installed by a client application.
- user_handle – A value specified by an application that can be used for identifying handlers uniquely for an event type.
Returns: user handle (a ctypes object)
-
interface_number
¶ VI_ATTR_INTF_NUM specifies the board number for the given interface.
VISA Attribute: VI_ATTR_INTF_NUM (1073676662) Type: int Range: 0 <= value <= 65535
-
interface_type
¶ The interface type of the resource as a number.
-
last_status
¶ Last status code for this session.
Return type: pyvisa.constants.StatusCode
-
lock
(timeout='default', requested_key=None)¶ Establish a shared lock to the resource.
Parameters: - timeout – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. (Defaults to self.timeout)
- requested_key – 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
-
lock_context
(timeout='default', requested_key='exclusive')¶ A context that locks
Parameters: - timeout – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. (Defaults to self.timeout)
- requested_key – 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.
The returned context is the access_key if applicable.
-
lock_excl
(timeout='default')¶ Establish an exclusive lock to the resource.
Parameters: timeout – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. (Defaults to self.timeout)
-
lock_state
¶ - VI_ATTR_RSRC_LOCK_STATE indicates the 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, offset, length, width, extended=False)¶ Moves a block of data to local memory from the specified address space and offset.
Parameters: - space – Specifies the address space. (Constants.*SPACE*)
- offset – Offset (in bytes) of the address or register from which to read.
- length – Number of elements to transfer, where the data width of the elements to transfer is identical to the source data width.
- width – Number of bits to read per element.
- extended – Use 64 bits offset independent of the platform.
-
move_out
(space, offset, length, data, width, extended=False)¶ Moves a block of data from local memory to the specified address space and offset.
Parameters: - space – Specifies the address space. (Constants.*SPACE*)
- offset – Offset (in bytes) of the address or register from which to read.
- length – Number of elements to transfer, where the data width of the elements to transfer is identical to the source data width.
- data – Data to write to bus.
- width – Number of bits to read per element.
- extended – Use 64 bits offset independent of the platform.
-
open
(access_mode=<AccessModes.no_lock: 0>, open_timeout=5000)¶ Opens a session to the specified resource.
Parameters: - access_mode (
pyvisa.constants.AccessModes
) – Specifies the mode by which the resource is to be accessed. - open_timeout (int) – If the
access_mode
parameter requests a lock, then this parameter specifies the absolute time period (in milliseconds) that the resource waits to get unlocked before this operation returns an error.
- access_mode (
-
read_memory
(space, offset, width, extended=False)¶ Reads in an 8-bit, 16-bit, 32-bit, or 64-bit value from the specified memory space and offset.
Parameters: - space – Specifies the address space. (Constants.*SPACE*)
- offset – Offset (in bytes) of the address or register from which to read.
- width – Number of bits to read.
- extended – Use 64 bits offset independent of the platform.
Returns: Data read from memory.
Corresponds to viIn* functions of the visa library.
-
classmethod
register
(interface_type, resource_class)¶
-
resource_class
¶ - VI_ATTR_RSRC_CLASS specifies the resource class (for example, “INSTR”)
- as defined by the canonical resource name.
VISA Attribute: VI_ATTR_RSRC_CLASS (3221159937)
-
resource_info
¶ Get the extended information of this resource.
Parameters: resource_name – Unique symbolic name of a resource. Return type: pyvisa.highlevel.ResourceInfo
-
resource_manufacturer_name
¶ - VI_ATTR_RSRC_MANF_NAME is a string that corresponds to the 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
¶ - VI_ATTR_RSRC_MANF_NAME is a string that corresponds to the 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_NAME (3221159938)
-
session
¶ Resource session handle.
Raises: pyvisa.errors.InvalidSession
if session is closed.
-
set_visa_attribute
(name, state)¶ Sets the state of an attribute.
Parameters: - name – Attribute for which the state is to be modified. (Attributes.*)
- state – The state of the attribute to be set for the specified object.
Returns: return value of the library call.
Return type:
-
source_increment
¶ - VI_ATTR_SRC_INCREMENT is used in the viMoveInXX() operations to
- specify by how many elements the source offset is to be incremented after every 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
¶ - VI_ATTR_RSRC_SPEC_VERSION is the resource version that uniquely identifies
- the 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
¶ The timeout in milliseconds for all resource I/O operations.
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 asfloat('+inf')
)
To set an infinite timeout, you can also use:
>>> del instrument.timeout
- immediate (
-
uninstall_handler
(event_type, handler, user_handle=None)¶ Uninstalls handlers for events in this resource.
Parameters: - event_type – Logical event identifier.
- handler – Interpreted as a valid reference to a handler to be uninstalled by a client application.
- user_handle – The user handle (ctypes object or None) returned by install_handler.
-
unlock
()¶ Relinquishes a lock for the specified resource.
-
visa_attributes_classes
= [<class 'pyvisa.attributes.AttrVI_ATTR_INTF_INST_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_MAX_QUEUE_LENGTH'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_TYPE'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_RM_SESSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_CLASS'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_IMPL_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_LOCK_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_SPEC_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_TMO_VALUE'>, <class 'pyvisa.attributes.AttrVI_ATTR_DEST_ACCESS_PRIV'>, <class 'pyvisa.attributes.AttrVI_ATTR_DEST_BYTE_ORDER'>, <class 'pyvisa.attributes.AttrVI_ATTR_DMA_ALLOW_EN'>, <class 'pyvisa.attributes.AttrVI_ATTR_DEST_INCREMENT'>, <class 'pyvisa.attributes.AttrVI_ATTR_SRC_ACCESS_PRIV'>, <class 'pyvisa.attributes.AttrVI_ATTR_SRC_BYTE_ORDER'>, <class 'pyvisa.attributes.AttrVI_ATTR_SRC_INCREMENT'>, <class 'pyvisa.attributes.AttrVI_ATTR_WIN_ACCESS'>, <class 'pyvisa.attributes.AttrVI_ATTR_WIN_ACCESS_PRIV'>, <class 'pyvisa.attributes.AttrVI_ATTR_VXI_LA'>, <class 'pyvisa.attributes.AttrVI_ATTR_WIN_BYTE_ORDER'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_INST_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_MAX_QUEUE_LENGTH'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_TYPE'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_RM_SESSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_CLASS'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_IMPL_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_LOCK_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_SPEC_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_TMO_VALUE'>]¶
-
wait_on_event
(in_event_type, timeout, capture_timeout=False)¶ Waits for an occurrence of the specified event in this resource.
Parameters: - in_event_type – Logical identifier of the event(s) to wait for.
- timeout – Absolute time period in time units that the resource shall wait for a specified event to occur before returning the time elapsed error. The time unit is in milliseconds. None means waiting forever if necessary.
- capture_timeout – When True will not produce a VisaIOError(VI_ERROR_TMO) but instead return a WaitResponse with timed_out=True
Returns: A WaitResponse object that contains event_type, context and ret value.
-
write_memory
(space, offset, data, width, extended=False)¶ Write in an 8-bit, 16-bit, 32-bit, value to the specified memory space and offset.
Parameters: - space – Specifies the address space. (Constants.*SPACE*)
- offset – Offset (in bytes) of the address or register from which to read.
- data – Data to write to bus.
- width – Number of bits to read.
- extended – Use 64 bits offset independent of the platform.
Corresponds to viOut* functions of the visa library.
-
class
pyvisa.resources.
VXIBackplane
(resource_manager, resource_name)[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
()¶ Called just before closing an instrument.
-
clear
()¶ Clears this resource
-
close
()¶ Closes the VISA session and marks the handle as invalid.
-
disable_event
(event_type, mechanism)¶ Disables notification of the specified event type(s) via the specified mechanism(s).
Parameters: - event_type – Logical event identifier.
- mechanism – Specifies event handling mechanisms to be disabled. (Constants.VI_QUEUE, .VI_HNDLR, .VI_SUSPEND_HNDLR, .VI_ALL_MECH)
-
discard_events
(event_type, mechanism)¶ Discards event occurrences for specified event types and mechanisms in this resource.
Parameters: - event_type – Logical event identifier.
- mechanism – Specifies event handling mechanisms to be dicarded. (Constants.VI_QUEUE, .VI_HNDLR, .VI_SUSPEND_HNDLR, .VI_ALL_MECH)
-
enable_event
(event_type, mechanism, context=None)¶ Enable event occurrences for specified event types and mechanisms in this resource.
Parameters: - event_type – Logical event identifier.
- mechanism – Specifies event handling mechanisms to be enabled. (Constants.VI_QUEUE, .VI_HNDLR, .VI_SUSPEND_HNDLR)
- context – Not currently used, leave as None.
-
get_visa_attribute
(name)¶ Retrieves the state of an attribute in this resource.
Parameters: name – Resource attribute for which the state query is made (see Attributes.*) Returns: The state of the queried attribute for a specified resource. Return type: unicode (Py2) or str (Py3), list or other type
-
ignore_warning
(*warnings_constants)¶ Ignoring warnings context manager for the current resource.
Parameters: warnings_constants – constants identifying the warnings to ignore.
-
implementation_version
¶ - VI_ATTR_RSRC_IMPL_VERSION is the resource version that uniquely identifies
- each of the different 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, handler, user_handle=None)¶ Installs handlers for event callbacks in this resource.
Parameters: - event_type – Logical event identifier.
- handler – Interpreted as a valid reference to a handler to be installed by a client application.
- user_handle – A value specified by an application that can be used for identifying handlers uniquely for an event type.
Returns: user handle (a ctypes object)
-
interface_number
¶ VI_ATTR_INTF_NUM specifies the board number for the given interface.
VISA Attribute: VI_ATTR_INTF_NUM (1073676662) Type: int Range: 0 <= value <= 65535
-
interface_type
¶ The interface type of the resource as a number.
-
last_status
¶ Last status code for this session.
Return type: pyvisa.constants.StatusCode
-
lock
(timeout='default', requested_key=None)¶ Establish a shared lock to the resource.
Parameters: - timeout – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. (Defaults to self.timeout)
- requested_key – 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
-
lock_context
(timeout='default', requested_key='exclusive')¶ A context that locks
Parameters: - timeout – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. (Defaults to self.timeout)
- requested_key – 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.
The returned context is the access_key if applicable.
-
lock_excl
(timeout='default')¶ Establish an exclusive lock to the resource.
Parameters: timeout – Absolute time period (in milliseconds) that a resource waits to get unlocked by the locking session before returning an error. (Defaults to self.timeout)
-
lock_state
¶ - VI_ATTR_RSRC_LOCK_STATE indicates the 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=<AccessModes.no_lock: 0>, open_timeout=5000)¶ Opens a session to the specified resource.
Parameters: - access_mode (
pyvisa.constants.AccessModes
) – Specifies the mode by which the resource is to be accessed. - open_timeout (int) – If the
access_mode
parameter requests a lock, then this parameter specifies the absolute time period (in milliseconds) that the resource waits to get unlocked before this operation returns an error.
- access_mode (
-
classmethod
register
(interface_type, resource_class)¶
-
resource_class
¶ - VI_ATTR_RSRC_CLASS specifies the resource class (for example, “INSTR”)
- as defined by the canonical resource name.
VISA Attribute: VI_ATTR_RSRC_CLASS (3221159937)
-
resource_info
¶ Get the extended information of this resource.
Parameters: resource_name – Unique symbolic name of a resource. Return type: pyvisa.highlevel.ResourceInfo
-
resource_manufacturer_name
¶ - VI_ATTR_RSRC_MANF_NAME is a string that corresponds to the 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
¶ - VI_ATTR_RSRC_MANF_NAME is a string that corresponds to the 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_NAME (3221159938)
-
session
¶ Resource session handle.
Raises: pyvisa.errors.InvalidSession
if session is closed.
-
set_visa_attribute
(name, state)¶ Sets the state of an attribute.
Parameters: - name – Attribute for which the state is to be modified. (Attributes.*)
- state – The state of the attribute to be set for the specified object.
Returns: return value of the library call.
Return type:
-
spec_version
¶ - VI_ATTR_RSRC_SPEC_VERSION is the resource version that uniquely identifies
- the 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
¶ The timeout in milliseconds for all resource I/O operations.
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 asfloat('+inf')
)
To set an infinite timeout, you can also use:
>>> del instrument.timeout
- immediate (
-
uninstall_handler
(event_type, handler, user_handle=None)¶ Uninstalls handlers for events in this resource.
Parameters: - event_type – Logical event identifier.
- handler – Interpreted as a valid reference to a handler to be uninstalled by a client application.
- user_handle – The user handle (ctypes object or None) returned by install_handler.
-
unlock
()¶ Relinquishes a lock for the specified resource.
-
visa_attributes_classes
= [<class 'pyvisa.attributes.AttrVI_ATTR_INTF_INST_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_MAX_QUEUE_LENGTH'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_TYPE'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_RM_SESSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_CLASS'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_IMPL_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_LOCK_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_SPEC_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_TMO_VALUE'>, <class 'pyvisa.attributes.AttrVI_ATTR_MAINFRAME_LA'>, <class 'pyvisa.attributes.AttrVI_ATTR_VXI_TRIG_STATUS'>, <class 'pyvisa.attributes.AttrVI_ATTR_VXI_TRIG_SUPPORT'>, <class 'pyvisa.attributes.AttrVI_ATTR_VXI_VME_SYSFAIL_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_TRIG_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_VXI_VME_INTR_STATUS'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_INST_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_MAX_QUEUE_LENGTH'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_TYPE'>, <class 'pyvisa.attributes.AttrVI_ATTR_INTF_NUM'>, <class 'pyvisa.attributes.AttrVI_ATTR_RM_SESSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_CLASS'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_IMPL_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_LOCK_STATE'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_ID'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_MANF_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_NAME'>, <class 'pyvisa.attributes.AttrVI_ATTR_RSRC_SPEC_VERSION'>, <class 'pyvisa.attributes.AttrVI_ATTR_TMO_VALUE'>]¶
-
wait_on_event
(in_event_type, timeout, capture_timeout=False)¶ Waits for an occurrence of the specified event in this resource.
Parameters: - in_event_type – Logical identifier of the event(s) to wait for.
- timeout – Absolute time period in time units that the resource shall wait for a specified event to occur before returning the time elapsed error. The time unit is in milliseconds. None means waiting forever if necessary.
- capture_timeout – When True will not produce a VisaIOError(VI_ERROR_TMO) but instead return a WaitResponse with timed_out=True
Returns: A WaitResponse object that contains event_type, context and ret value.