constants_and_dataclasses
¶
Module containing constants and dataclasses for the tm_devices package.
KEITHLEY_USBTMC_VENDOR_ID
module-attribute
¶
The USBTMC Vendor ID for Keithley devices.
LOAD_IMPEDANCE_LOOKUP
module-attribute
¶
LOAD_IMPEDANCE_LOOKUP: Final[Mapping[float | str, LoadImpedanceAFG]] = MappingProxyType(
{9.97e37: HIGHZ, 1000000.0: HIGHZ, "HIGHZ": HIGHZ, 50.0: FIFTY, "FIFTY": FIFTY}
)
Conversions of literal values representing impedances to Enum values representing impedances.
TEKTRONIX_USBTMC_VENDOR_ID
module-attribute
¶
The USBTMC Vendor ID for Tektronix devices.
USB_MODEL_ID_LOOKUP
module-attribute
¶
USB_MODEL_ID_LOOKUP: Final[Mapping[SupportedModels, USBTMCConfiguration]] = MappingProxyType(
{
MDO3: USBTMCConfiguration(vendor_id=TEKTRONIX_USBTMC_VENDOR_ID, model_id="0x052C"),
MDO3K: USBTMCConfiguration(vendor_id=TEKTRONIX_USBTMC_VENDOR_ID, model_id="0x0408"),
MSO2: USBTMCConfiguration(vendor_id=TEKTRONIX_USBTMC_VENDOR_ID, model_id="0x0105"),
MSO2KB: USBTMCConfiguration(vendor_id=TEKTRONIX_USBTMC_VENDOR_ID, model_id="0x03A4"),
MSO4: USBTMCConfiguration(vendor_id=TEKTRONIX_USBTMC_VENDOR_ID, model_id="0x0527"),
MSO4B: USBTMCConfiguration(vendor_id=TEKTRONIX_USBTMC_VENDOR_ID, model_id="0x0527"),
MSO5: USBTMCConfiguration(vendor_id=TEKTRONIX_USBTMC_VENDOR_ID, model_id="0x0522"),
MSO5B: USBTMCConfiguration(vendor_id=TEKTRONIX_USBTMC_VENDOR_ID, model_id="0x0522"),
MSO5LP: USBTMCConfiguration(vendor_id=TEKTRONIX_USBTMC_VENDOR_ID, model_id="0x0529"),
MSO6: USBTMCConfiguration(vendor_id=TEKTRONIX_USBTMC_VENDOR_ID, model_id="0x0528"),
MSO6B: USBTMCConfiguration(vendor_id=TEKTRONIX_USBTMC_VENDOR_ID, model_id="0x0530"),
LPD6: USBTMCConfiguration(vendor_id=TEKTRONIX_USBTMC_VENDOR_ID, model_id="0x052F"),
DPO7AX: USBTMCConfiguration(vendor_id=TEKTRONIX_USBTMC_VENDOR_ID, model_id="0x0532"),
AFG3K: USBTMCConfiguration(vendor_id=TEKTRONIX_USBTMC_VENDOR_ID, model_id="0x0345"),
AFG31K: USBTMCConfiguration(vendor_id=TEKTRONIX_USBTMC_VENDOR_ID, model_id="0x035E"),
SMU2450: USBTMCConfiguration(vendor_id=KEITHLEY_USBTMC_VENDOR_ID, model_id="0x2450"),
SMU2460: USBTMCConfiguration(vendor_id=KEITHLEY_USBTMC_VENDOR_ID, model_id="0x2460"),
SMU2461: USBTMCConfiguration(vendor_id=KEITHLEY_USBTMC_VENDOR_ID, model_id="0x2461"),
SMU2470: USBTMCConfiguration(vendor_id=KEITHLEY_USBTMC_VENDOR_ID, model_id="0x2470"),
SMU2601A: USBTMCConfiguration(vendor_id=KEITHLEY_USBTMC_VENDOR_ID, model_id="0x2601"),
SMU2602A: USBTMCConfiguration(vendor_id=KEITHLEY_USBTMC_VENDOR_ID, model_id="0x2602"),
SMU2604A: USBTMCConfiguration(vendor_id=KEITHLEY_USBTMC_VENDOR_ID, model_id="0x2604"),
SMU2611A: USBTMCConfiguration(vendor_id=KEITHLEY_USBTMC_VENDOR_ID, model_id="0x2611"),
SMU2612A: USBTMCConfiguration(vendor_id=KEITHLEY_USBTMC_VENDOR_ID, model_id="0x2612"),
SMU2614A: USBTMCConfiguration(vendor_id=KEITHLEY_USBTMC_VENDOR_ID, model_id="0x2614"),
SMU2634A: USBTMCConfiguration(vendor_id=KEITHLEY_USBTMC_VENDOR_ID, model_id="0x2634"),
SMU2635A: USBTMCConfiguration(vendor_id=KEITHLEY_USBTMC_VENDOR_ID, model_id="0x2635"),
SMU2636A: USBTMCConfiguration(vendor_id=KEITHLEY_USBTMC_VENDOR_ID, model_id="0x2636"),
SMU2601B: USBTMCConfiguration(vendor_id=KEITHLEY_USBTMC_VENDOR_ID, model_id="0x2601"),
SMU2602B: USBTMCConfiguration(vendor_id=KEITHLEY_USBTMC_VENDOR_ID, model_id="0x2602"),
SMU2604B: USBTMCConfiguration(vendor_id=KEITHLEY_USBTMC_VENDOR_ID, model_id="0x2604"),
SMU2606B: USBTMCConfiguration(vendor_id=KEITHLEY_USBTMC_VENDOR_ID, model_id="0x2606"),
SMU2611B: USBTMCConfiguration(vendor_id=KEITHLEY_USBTMC_VENDOR_ID, model_id="0x2611"),
SMU2612B: USBTMCConfiguration(vendor_id=KEITHLEY_USBTMC_VENDOR_ID, model_id="0x2612"),
SMU2614B: USBTMCConfiguration(vendor_id=KEITHLEY_USBTMC_VENDOR_ID, model_id="0x2614"),
SMU2634B: USBTMCConfiguration(vendor_id=KEITHLEY_USBTMC_VENDOR_ID, model_id="0x2634"),
SMU2635B: USBTMCConfiguration(vendor_id=KEITHLEY_USBTMC_VENDOR_ID, model_id="0x2635"),
SMU2636B: USBTMCConfiguration(vendor_id=KEITHLEY_USBTMC_VENDOR_ID, model_id="0x2636"),
PSU2200: USBTMCConfiguration(vendor_id=KEITHLEY_USBTMC_VENDOR_ID, model_id="0x2200"),
PSU2220: USBTMCConfiguration(vendor_id=KEITHLEY_USBTMC_VENDOR_ID, model_id="0x2220"),
PSU2230: USBTMCConfiguration(vendor_id=KEITHLEY_USBTMC_VENDOR_ID, model_id="0x2230"),
PSU2231: USBTMCConfiguration(vendor_id=KEITHLEY_USBTMC_VENDOR_ID, model_id="0x2231"),
PSU2231A: USBTMCConfiguration(vendor_id=KEITHLEY_USBTMC_VENDOR_ID, model_id="0x2231"),
PSU2280: USBTMCConfiguration(vendor_id=KEITHLEY_USBTMC_VENDOR_ID, model_id="0x2280"),
PSU2281: USBTMCConfiguration(vendor_id=KEITHLEY_USBTMC_VENDOR_ID, model_id="0x2281"),
AWG5200: USBTMCConfiguration(vendor_id=TEKTRONIX_USBTMC_VENDOR_ID, model_id="0x0503"),
AWG70KA: USBTMCConfiguration(vendor_id=TEKTRONIX_USBTMC_VENDOR_ID, model_id="0x0503"),
AWG70KB: USBTMCConfiguration(vendor_id=TEKTRONIX_USBTMC_VENDOR_ID, model_id="0x0503"),
SS3706A: USBTMCConfiguration(vendor_id=KEITHLEY_USBTMC_VENDOR_ID, model_id="0x3706"),
MP5103: USBTMCConfiguration(vendor_id=TEKTRONIX_USBTMC_VENDOR_ID, model_id="0x5103"),
}
)
A mapping of device model series to their USBTMC connection information.
This lists the natively supported USBTMC connections of tm_devices, use
register_additional_usbtmc_model_series()
to register USBTMC connection information for devices not listed here.
VALID_DEVICE_CONNECTION_TYPES
module-attribute
¶
VALID_DEVICE_CONNECTION_TYPES: Final[Mapping[DeviceTypes, tuple[ConnectionTypes, ...]]] = (
MappingProxyType(
{
AFG: (TCPIP, USB, SOCKET, SERIAL, GPIB),
AWG: (TCPIP, USB, SOCKET, SERIAL, GPIB),
DAQ: (TCPIP, USB, GPIB, SERIAL),
DMM: (TCPIP, USB, SOCKET, SERIAL, GPIB),
MF: (TCPIP, USB, SOCKET),
MT: (REST_API,),
PSU: (TCPIP, USB, SOCKET, SERIAL, GPIB),
SCOPE: (TCPIP, USB, SOCKET, SERIAL, GPIB, MOCK),
SMU: (TCPIP, USB, SOCKET, SERIAL, GPIB),
SS: (TCPIP, USB, SOCKET, GPIB),
UNSUPPORTED: tuple(ConnectionTypes),
}
)
)
Mapping of each device type to its supported connection types.
Any additions to this class need to be added to the tm_devices.helpers.enums.DeviceTypes enum
as well.
DMConfigOptions
dataclass
¶
DMConfigOptions(
standalone: bool | None = None,
setup_cleanup: bool | None = None,
teardown_cleanup: bool | None = None,
verbose_mode: bool | None = None,
disable_command_verification: bool | None = None,
verbose_visa: bool | None = None,
retry_visa_connection: bool | None = None,
default_visa_timeout: int | None = None,
check_for_updates: bool | None = None,
log_console_level: str | None = None,
log_file_level: str | None = None,
log_file_directory: str | None = None,
log_file_name: str | None = None,
log_colored_output: bool | None = None,
log_pyvisa_messages: bool | None = None,
log_uncaught_exceptions: bool | None = None,
)
Bases: AsDictionaryMixin
Device Management Configuration options.
check_for_updates
class-attribute
instance-attribute
¶
check_for_updates: bool | None = None
A flag indicating if a check for updates for the package should be performed on creation of the DeviceManager.
default_visa_timeout
class-attribute
instance-attribute
¶
default_visa_timeout: int | None = None
A default VISA timeout value (in milliseconds) to use when creating VISA connections.
When this option is not set, a default value of 5000 milliseconds (5 seconds) is used.
disable_command_verification
class-attribute
instance-attribute
¶
disable_command_verification: bool | None = None
A flag that disables command verification for all devices.
This can have the effect of speeding up automation scripts by no longer checking each command
after it is sent via the .set_and_check() method.
log_colored_output
class-attribute
instance-attribute
¶
log_colored_output: bool | None = None
Whether to use colored output from the colorlog package for the console.
Defaults to False. See the configure_logging()
function for more information and default values.
log_console_level
class-attribute
instance-attribute
¶
log_console_level: str | None = None
The logging level to set for the console.
One of ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL", "NONE"], see the
LoggingLevels enum for details.
Defaults to "INFO". See the
configure_logging() function for more
information.
log_file_directory
class-attribute
instance-attribute
¶
log_file_directory: str | None = None
The directory to save log files to.
Defaults to “./logs”. See the
configure_logging() function for more
information and default values.
log_file_level
class-attribute
instance-attribute
¶
log_file_level: str | None = None
The logging level to set for the log file.
One of ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL", "NONE"], see the
LoggingLevels enum for details.
Defaults to "DEBUG". See the
configure_logging() function for more
information.
log_file_name
class-attribute
instance-attribute
¶
log_file_name: str | None = None
The name of the log file to save the logs to.
Defaults to a timestamped filename with the .log extension. See the
configure_logging() function for more
information and default values.
log_pyvisa_messages
class-attribute
instance-attribute
¶
log_pyvisa_messages: bool | None = None
Whether to include logs from the pyvisa package in the log file.
Defaults to False. See the configure_logging()
function for more information and default values.
log_uncaught_exceptions
class-attribute
instance-attribute
¶
log_uncaught_exceptions: bool | None = None
Whether to log uncaught exceptions to the log file with full tracebacks.
This behavior also reduces the traceback size of exceptions in the console. Setting
log_file_level
to "NONE" will disable this feature regardless of the value of
log_uncaught_exceptions.
Defaults to True. See the configure_logging()
function for more information and default values.
retry_visa_connection
class-attribute
instance-attribute
¶
retry_visa_connection: bool | None = None
A flag to enable retrying the first VISA connection attempt.
setup_cleanup
class-attribute
instance-attribute
¶
setup_cleanup: bool | None = None
An option indicating to run a device’s cleanup() method when opening the connection.
standalone
class-attribute
instance-attribute
¶
standalone: bool | None = None
An option indicating to use PyVISA-py’s pure Python VISA backend.
teardown_cleanup
class-attribute
instance-attribute
¶
teardown_cleanup: bool | None = None
An option indicating to run a device’s cleanup() method when closing the connection.
verbose_mode
class-attribute
instance-attribute
¶
verbose_mode: bool | None = None
A verbosity flag to turn on more printouts to stdout.
verbose_visa
class-attribute
instance-attribute
¶
verbose_visa: bool | None = None
A verbosity flag to enable extremely verbose VISA logging to stdout.
to_dict
¶
Transform public attributes of this class to dictionary.
Examples:
>>> import dataclasses
>>> from tm_devices.helpers.dataclass_mixins import AsDictionaryMixin
>>> ClassA = dataclasses.make_dataclass("A",["a","_b", "c"], bases=(AsDictionaryMixin,))
>>> foo = ClassA("public", "secret", 5)
>>> foo.to_dict()
{'a': 'public', 'c': 5}
>>> vars(foo) # see how this differs from the builtin function vars
{'a': 'public', '_b': 'secret', 'c': 5}
DeviceConfigEntry
dataclass
¶
DeviceConfigEntry(
device_type: DeviceTypes,
address: str,
connection_type: ConnectionTypes = TCPIP,
alias: str | None = None,
lan_port: int | None = None,
lan_device_endpoint: str | None = None,
serial_config: SerialConfig | None = None,
device_driver: str | None = None,
gpib_board_number: int | None = None,
)
Bases: AsDictionaryUseEnumNameUseCustEnumStrValueMixin, _ConfigEntryEnvStrMixin
Dataclass for holding configuration information for a single device.
address
instance-attribute
¶
address: str
The address used to connect to the device.
Notes
- TCPIP: IP address or the hostname.
- SOCKET: IP address or the hostname (must define
lan_portfield). - REST_API: IP address or the hostname (must define
lan_portfield). - SERIAL/ASRL: serial COM port number (as a string).
- GPIB: the GPIB address number (as a string).
- USB: use expression format
f"{model}-{serial_number}"(ex:"MSO24-ABC0123").
alias
class-attribute
instance-attribute
¶
alias: str | None = None
An optional key/name used to retrieve this devices from the DeviceManager.
connection_type
class-attribute
instance-attribute
¶
connection_type: ConnectionTypes = TCPIP
The specific type of connection defined in the config entry.
device_driver
class-attribute
instance-attribute
¶
device_driver: str | None = None
The name of the Python driver to use for the device (required for connection_type=REST_API, ignored otherwise).
device_type
instance-attribute
¶
device_type: DeviceTypes
The specific device type defined in the config entry.
gpib_board_number
class-attribute
instance-attribute
¶
gpib_board_number: int | None = None
The GPIB board number (also referred to as a controller) to be used when making a GPIB connection (defaults to 0).
lan_device_endpoint
class-attribute
instance-attribute
¶
lan_device_endpoint: str | None = None
The LAN device endpoint to connect on, used for TCPIP connections (defaults to ‘inst0’).
lan_port
class-attribute
instance-attribute
¶
lan_port: int | None = None
The port number to connect on, used for SOCKET/REST_API connections.
serial_config
class-attribute
instance-attribute
¶
serial_config: SerialConfig | None = None
Serial configuration properties for connecting to a device over SERIAL (ASRL).
get_address_expression
¶
get_address_expression() -> str
Return an address expression.
This is not the resource expression, it is used to help catch duplicate addresses.
get_visa_resource_expression
¶
get_visa_resource_expression() -> str
Construct the VISA resource expression for the device.
Example visa expressions:
- TCPIP0::MSO58-3000260::instr0::INSTR
- USB0::0x0699::0x0522::3000260::INSTR
- TCPIP0::192.168.0.1::4000::SOCKET
- ASRL3::INSTR (serial on COM port 3)
| Returns: |
|
|---|
| Raises: |
|
|---|
to_dict
¶
Transform public attributes of this class to dictionary.
Examples:
>>> import dataclasses
>>> from tm_devices.helpers.dataclass_mixins import AsDictionaryMixin
>>> ClassA = dataclasses.make_dataclass("A",["a","_b", "c"], bases=(AsDictionaryMixin,))
>>> foo = ClassA("public", "secret", 5)
>>> foo.to_dict()
{'a': 'public', 'c': 5}
>>> vars(foo) # see how this differs from the builtin function vars
{'a': 'public', '_b': 'secret', 'c': 5}
SerialConfig
dataclass
¶
SerialConfig(
baud_rate: int | None = None,
data_bits: Literal[5, 6, 7, 8] | None = None,
flow_control: FlowControl | Literal["none", "xon_xoff", "dtr_dsr", "rts_cts"] | None = None,
parity: Parity | Literal["none", "odd", "even", "mark", "space"] | None = None,
stop_bits: StopBits | Literal["one", "one_and_a_half", "two"] | None = None,
end_input: (
Termination | Literal["termination_break", "termination_char", "last_bit", "none"] | None
) = None,
)
Bases: AsDictionaryUseEnumNameUseCustEnumStrValueMixin, _ConfigEntryEnvStrMixin
Serial configuration properties for connecting to a device over SERIAL (ASRL).
Notes
baud_rate: The baud rate controls the communication frequency. e.g. 9600data_bits: The number of data bits in each character. One of [5, 6, 7, 8].flow_control: Control for pausing/resuming data stream between slower devices. One ofSerialConfig.FlowControl.[none|xon_xoff|dtr_dsr|rts_cts].parity: Parity controls checksum bit (added to each data character) behavior. One ofSerialConfig.Parity.[none|odd|even|mark|space].stop_bits: Number of bits to use to indicate end of a character. One ofSerialConfig.StopBits.[one|one_and_a_half|two].end_input: Character(s) to indicate the end of a message transmission. One ofSerialConfig.Termination.[termination_break|termination_char|last_bit|none].
FlowControl
class-attribute
instance-attribute
¶
FlowControl = ControlFlow
A convenience enumeration listing the options for control flow for a serial device.
It is used to set the
flow_control
attribute when creating a
SerialConfig object.
Parity
class-attribute
instance-attribute
¶
Parity = Parity
A convenience enumeration listing the options for parity for a serial device.
It is used to set the
parity
attribute when creating a
SerialConfig object.
StopBits
class-attribute
instance-attribute
¶
StopBits = StopBits
A convenience enumeration listing the options for stop bits for a serial device.
It is used to set the
stop_bits
attribute when creating a
SerialConfig object.
Termination
class-attribute
instance-attribute
¶
Termination = SerialTermination
A convenience enumeration listing the available methods for terminating a serial transfer.
It is used to set the
end_input
attribute when creating a
SerialConfig object.
baud_rate
class-attribute
instance-attribute
¶
baud_rate: int | None = None
The baud rate controls the communication frequency.
This is a list of common baud rates:
[115200, 57600, 38400, 19200, 9600, 4800, 2400, 1200, 600, 300]
data_bits
class-attribute
instance-attribute
¶
data_bits: Literal[5, 6, 7, 8] | None = None
The number of data bits in each character.
One of [5, 6, 7, 8].
end_input
class-attribute
instance-attribute
¶
end_input: (
Termination | Literal["termination_break", "termination_char", "last_bit", "none"] | None
) = None
Character(s) to indicate the end of a message transmission.
One of SerialConfig.Termination.[termination_break|termination_char|last_bit|none].
flow_control
class-attribute
instance-attribute
¶
flow_control: FlowControl | Literal['none', 'xon_xoff', 'dtr_dsr', 'rts_cts'] | None = None
Control for pausing/resuming data stream between slower devices.
One of SerialConfig.FlowControl.[none|xon_xoff|dtr_dsr|rts_cts].
parity
class-attribute
instance-attribute
¶
Parity adds a checksum bit to each data character.
This checksum bit enables the target device to determine whether the data was received correctly. The parity is used with every frame transmitted and received on a serial session.
One of SerialConfig.Parity.[none|odd|even|mark|space].
stop_bits
class-attribute
instance-attribute
¶
Number of bits to use to indicate end of a character.
The number of stop bits that indicate the end of a frame on a serial resource.
One of SerialConfig.StopBits.[one|one_and_a_half|two].
to_dict
¶
Transform public attributes of this class to dictionary.
Examples:
>>> import dataclasses
>>> from tm_devices.helpers.dataclass_mixins import AsDictionaryMixin
>>> ClassA = dataclasses.make_dataclass("A",["a","_b", "c"], bases=(AsDictionaryMixin,))
>>> foo = ClassA("public", "secret", 5)
>>> foo.to_dict()
{'a': 'public', 'c': 5}
>>> vars(foo) # see how this differs from the builtin function vars
{'a': 'public', '_b': 'secret', 'c': 5}
TMDevicesConfigFileSchema
dataclass
¶
TMDevicesConfigFileSchema(
devices: list[DeviceConfigEntry] = list[DeviceConfigEntry](),
options: DMConfigOptions = DMConfigOptions(),
)
Configuration file schema for the tm_devices package.
devices
class-attribute
instance-attribute
¶
devices: list[DeviceConfigEntry] = field(default_factory=list[DeviceConfigEntry])
A list of devices for the DeviceManager to connect to.
options
class-attribute
instance-attribute
¶
options: DMConfigOptions = field(default_factory=DMConfigOptions)
The options controlling the behavior of the tm_devices package.
USBTMCConfiguration
dataclass
¶
Dataclass for holding USBTMC configuration information.
Each instance of the dataclass holds a Vendor ID and a Model ID to allow easier creation of USBTMC VISA resource expressions.