hvl_ccb.comm.visa
Communication protocol for VISA. Makes use of the pyvisa library. The backend can be NI-Visa or pyvisa-py.
Information on how to install a VISA backend can be found here: https://pyvisa.readthedocs.io/en/master/getting_nivisa.html
So far only TCPIP SOCKET and TCPIP INSTR interfaces are supported.
- class VisaCommunication(configuration)[source]
Bases:
CommunicationProtocol
Implements the Communication Protocol for VISA / SCPI.
- MULTI_COMMANDS_MAX = 5
The maximum of commands that can be sent in one round is 5 according to the VISA standard.
- MULTI_COMMANDS_SEPARATOR = ';'
The character to separate two commands is ; according to the VISA standard.
- WAIT_AFTER_WRITE = 0.08
Small pause in seconds to wait after write operations, allowing devices to really do what we tell them before continuing with further tasks.
- static config_cls() type[VisaCommunicationConfig] [source]
Return the default configdataclass class.
- Returns:
a reference to the default configdataclass class
- query(*commands: str) str | tuple[str, ...] [source]
A combination of write(message) and read.
- Parameters:
commands – list of commands
- Returns:
list of values
- Raises:
VisaCommunicationError – when connection was not started, or when trying to issue too many commands at once.
- spoll() int [source]
Execute serial poll on the device. Reads the status byte register STB. This is a fast function that can be executed periodically in a polling fashion.
- Returns:
integer representation of the status byte
- Raises:
VisaCommunicationError – when connection was not started
- write(*commands: str) None [source]
Write commands. No answer is read or expected.
- Parameters:
commands – one or more commands to send
- Raises:
VisaCommunicationError – when connection was not started
- class VisaCommunicationConfig(host: str | IPv4Address | IPv6Address, interface_type: str | InterfaceType, board: int = 0, port: int = 5025, timeout: int = 5000, chunk_size: int = 204800, open_timeout: int = 1000, write_termination: str = '\n', read_termination: str = '\n', visa_backend: str = '')[source]
Bases:
object
VisaCommunication configuration dataclass.
- class InterfaceType(value=<no_arg>, names=None, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Bases:
AutoNumberNameEnum
Supported VISA Interface types.
- TCPIP_INSTR = 2
VXI-11 protocol
- TCPIP_SOCKET = 1
VISA-RAW protocol
- property address: str
Address string depending on the VISA protocol’s configuration.
- Returns:
address string corresponding to current configuration
- board: int = 0
Board number is typically 0 and comes from old bus systems.
- chunk_size: int = 204800
Chunk size is the allocated memory for read operations. The standard is 20kB, and is increased per default here to 200kB. It is specified in bytes.
- force_value(fieldname, value)
Forces a value to a dataclass field despite the class being frozen.
NOTE: you can define post_force_value method with same signature as this method to do extra processing after value has been forced on fieldname.
- Parameters:
fieldname – name of the field
value – value to assign
- host: str | IPv4Address | IPv6Address
- interface_type: str | InterfaceType
Interface type of the VISA connection, being one of
InterfaceType
.
- is_configdataclass = True
- classmethod keys() Sequence[str]
Returns a list of all configdataclass fields key-names.
- Returns:
a list of strings containing all keys.
- open_timeout: int = 1000
Timeout for opening the connection, in milli seconds.
- classmethod optional_defaults() dict[str, object]
Returns a list of all configdataclass fields, that have a default value assigned and may be optionally specified on instantiation.
- Returns:
a list of strings containing all optional keys.
- port: int = 5025
TCP port, standard is 5025.
- read_termination: str = '\n'
Read termination character.
- classmethod required_keys() Sequence[str]
Returns a list of all configdataclass fields, that have no default value assigned and need to be specified on instantiation.
- Returns:
a list of strings containing all required keys.
- timeout: int = 5000
Timeout for commands in milli seconds.
- visa_backend: str = ''
Specifies the path to the library to be used with PyVISA as a backend. Defaults to None, which is NI-VISA (if installed), or pyvisa-py (if NI-VISA is not found). To force the use of pyvisa-py, specify ‘@py’ here.
- write_termination: str = '\n'
Write termination character.
- exception VisaCommunicationError[source]
Bases:
OSError
,CommunicationError
Base class for VisaCommunication errors.