pymeasure.adapters
The adapter classes allow the instruments to be independent of the communication method used.
The instrument implementation takes care of any potential quirks in its communication protocol (see Advanced communication protocols), and the adapter takes care of the details of the over-the-wire communication with the hardware device.
In the vast majority of cases, it will be sufficient to pass a connection string or integer to the instrument (see Connecting to an instrument), which uses the pymeasure.adapters.VISAAdapter in the background.
Adapter base class
- class pymeasure.adapters.Adapter(log=None, **kwargs)
Base class for Adapter child classes, which adapt between the Instrument object and the connection, to allow flexible use of different connection techniques.
This class should only be inherited from.
- Parameters:
log (
Optional[Logger]) – Parent logger of the ‘Adapter’ logger. (default:None)**kwargs – Keyword arguments just to be cooperative.
- close()
Close the connection.
- Return type:
None
-
connection:
ConnectionProtocol
- flush_read_buffer()
Flush and discard the input buffer. Implement in subclass.
- Return type:
None
- read(**kwargs)
Read up to (excluding) read_termination or the whole read buffer.
Do not override in a subclass!
- Parameters:
**kwargs – Keyword arguments for the connection itself.
- Returns str:
ASCII response of the instrument (excluding read_termination).
- Return type:
str
- read_binary_values(header_bytes=0, termination_bytes=None, dtype=<class 'numpy.float32'>, sep='', **kwargs)
Returns a numpy array from a query for binary data
- Parameters:
header_bytes (int) – Number of bytes to ignore in header.
termination_bytes (int) – Number of bytes to strip at end of message or None.
dtype – The NumPy data type to format the values with. (default:
<class 'numpy.float32'>)sep (string) – Separator between chars. If given, use fromstring, otherwise frombytes.
**kwargs – Further arguments for the NumPy fromstring / frombytes method.
- Returns:
NumPy array of values
- Raises:
ValueError – if the data buffer is empty or malformed
- read_bytes(count=-1, break_on_termchar=False, **kwargs)
Read a certain number of bytes from the instrument.
Do not override in a subclass!
- Parameters:
count (int) – Number of bytes to read. A value of -1 indicates to read from the whole read buffer.
break_on_termchar (bool) – Stop reading at a termination character.
**kwargs – Keyword arguments for the connection itself.
- Returns bytes:
Bytes response of the instrument (including termination).
- Return type:
bytes
- write(command, **kwargs)
Write a string command to the instrument appending write_termination.
Do not override in a subclass!
- Parameters:
command (str) – Command string to be sent to the instrument (without termination).
**kwargs – Keyword arguments for the connection itself.
- Return type:
None
- write_binary_values(command, values, termination='', **kwargs)
Write binary data to the instrument, e.g. waveform for signal generators
- Parameters:
command (
str) – command string to be sent to the instrumentvalues (
Sequence[Union[int,float]]) – iterable representing the binary valuestermination (
str) – String added afterwards to terminate the message. (default:'')**kwargs – Key-word arguments to pass onto
Adapter._format_binary_values()
- Returns:
int– number of bytes written
- write_bytes(content, **kwargs)
Write the bytes content to the instrument.
Do not override in a subclass!
- Parameters:
content (bytes) – The bytes to write to the instrument.
**kwargs – Keyword arguments for the connection itself.
- Return type:
None
VISA adapter
- class pymeasure.adapters.VISAAdapter(resource_name, visa_library='', log=None, **kwargs)
Bases:
AdapterAdapter class for the VISA library, using PyVISA to communicate with instruments.
The workhorse of our library, used by most instruments.
- Parameters:
resource_name (
Union[ProtocolAdapter,VISAAdapter,int,str]) – A VISA resource string or GPIB address integer that identifies the target of the connectionvisa_library (
str) – PyVISA VisaLibrary Instance, path of the VISA library or VisaLibrary spec string (@pyor@ivi). If not given, the default for the platform will be used. (default:'')log (
Optional[Logger]) – Parent logger of the ‘Adapter’ logger. (default:None)**kwargs – Keyword arguments for configuring the PyVISA connection.
- Kwargs:
Keyword arguments are used to configure the connection created by PyVISA. This is complicated by the fact that which arguments are valid depends on the interface (e.g. serial, GPIB, TCPI/IP, USB) determined by the current
resource_name.A flexible process is used to easily define reasonable default values for different instrument interfaces, but also enable the instrument user to override any setting if their situation demands it.
A kwarg that names a pyVISA interface type (most commonly
asrl,gpib,tcpip, orusb) is a dictionary with keyword arguments defining defaults specific to that interface. Example:asrl={'baud_rate': 4200}.All other kwargs are either generally valid (e.g.
timeout=500) or override any default settings from the interface-specific entries above. For example, passingbaud_rate=115200when connecting via a resource nameASRL1would override a default of 4200 defined as above.See Modifying connection settings for how to tweak settings when connecting to an instrument. See Defining default connection settings for how to best define default settings when implementing an instrument.
- close()
Close the connection. :rtype:
NoneNote
This closes the connection to the resource for all adapters using it currently (e.g. different adapters using the same GPIB line).
-
connection:
Union[ProtocolAdapter,MessageBasedResource]
- flush_read_buffer()
Flush and discard the input buffer
As detailed by pyvisa, discard the read and receivee buffer contents and if data was present in the read buffer and no END-indicator was present, read from the device until encountering an END indicator (which causes loss of data).
- Return type:
None
- read(**kwargs)
Read up to (excluding) read_termination or the whole read buffer.
Do not override in a subclass!
- Parameters:
**kwargs – Keyword arguments for the connection itself.
- Returns str:
ASCII response of the instrument (excluding read_termination).
- Return type:
str
- read_binary_values(header_bytes=0, termination_bytes=None, dtype=<class 'numpy.float32'>, sep='', **kwargs)
Returns a numpy array from a query for binary data
- Parameters:
header_bytes (int) – Number of bytes to ignore in header.
termination_bytes (int) – Number of bytes to strip at end of message or None.
dtype – The NumPy data type to format the values with. (default:
<class 'numpy.float32'>)sep (string) – Separator between chars. If given, use fromstring, otherwise frombytes.
**kwargs – Further arguments for the NumPy fromstring / frombytes method.
- Returns:
NumPy array of values
- Raises:
ValueError – if the data buffer is empty or malformed
- read_bytes(count=-1, break_on_termchar=False, **kwargs)
Read a certain number of bytes from the instrument.
Do not override in a subclass!
- Parameters:
count (int) – Number of bytes to read. A value of -1 indicates to read from the whole read buffer.
break_on_termchar (bool) – Stop reading at a termination character.
**kwargs – Keyword arguments for the connection itself.
- Returns bytes:
Bytes response of the instrument (including termination).
- Return type:
bytes
- wait_for_srq(timeout=25, delay=0.1)
Block until a SRQ, and leave the bit high
- Parameters:
timeout (
float) – Timeout duration in seconds (default:25)delay (
float) – Time delay between checking SRQ in seconds (default:0.1)
- Return type:
None
- write(command, **kwargs)
Write a string command to the instrument appending write_termination.
Do not override in a subclass!
- Parameters:
command (str) – Command string to be sent to the instrument (without termination).
**kwargs – Keyword arguments for the connection itself.
- Return type:
None
- write_binary_values(command, values, termination='', **kwargs)
Write binary data to the instrument, e.g. waveform for signal generators
- Parameters:
command (
str) – command string to be sent to the instrumentvalues (
Sequence[Union[int,float]]) – iterable representing the binary valuestermination (
str) – String added afterwards to terminate the message. (default:'')**kwargs – Key-word arguments to pass onto
Adapter._format_binary_values()
- Returns:
int– number of bytes written
- write_bytes(content, **kwargs)
Write the bytes content to the instrument.
Do not override in a subclass!
- Parameters:
content (bytes) – The bytes to write to the instrument.
**kwargs – Keyword arguments for the connection itself.
- Return type:
None
Serial adapter
- class pymeasure.adapters.SerialAdapter(port, write_termination='', read_termination='', **kwargs)
Bases:
AdapterAdapter class for using the Python Serial package to allow serial communication to instrument
- Parameters:
port (
Union[str,SerialBase]) – Serial portwrite_termination (
str) – String appended to messages before writing them. (default:'')read_termination (
str) – String expected at end of read message and removed. (default:'')**kwargs – Any valid key-word argument for serial.Serial
- _format_binary_values(values, datatype='f', is_big_endian=False, header_fmt='ieee')
Format values in binary format, used internally in
Adapter.write_binary_values().- Parameters:
values (
Sequence[Union[int,float]]) – data to be written to the device.datatype (
Literal['s','b','B','h','H','i','I','l','L','q','Q','f','d']) – format string for a single element (valid values: ‘b’, ‘B’, ‘h’, ‘H’, ‘i’, ‘I’, ‘l’, ‘L’, ‘q’, ‘Q’, ‘f’, ‘d’, ‘s’). (default:'f')is_big_endian (
bool) – boolean indicating endianness. (default:False)header_fmt (
str) – format of the header prefixing the data (“ieee”, “hp”, “empty”). (default:'ieee')
- Returns:
bytes– binary string.
- close()
Close the connection.
- Return type:
None
-
connection:
Serial
- flush_read_buffer()
Flush and discard the input buffer.
- Return type:
None
- read(**kwargs)
Read up to (excluding) read_termination or the whole read buffer.
Do not override in a subclass!
- Parameters:
**kwargs – Keyword arguments for the connection itself.
- Returns str:
ASCII response of the instrument (excluding read_termination).
- Return type:
str
- read_binary_values(header_bytes=0, termination_bytes=None, dtype=<class 'numpy.float32'>, sep='', **kwargs)
Returns a numpy array from a query for binary data
- Parameters:
header_bytes (int) – Number of bytes to ignore in header.
termination_bytes (int) – Number of bytes to strip at end of message or None.
dtype – The NumPy data type to format the values with. (default:
<class 'numpy.float32'>)sep (string) – Separator between chars. If given, use fromstring, otherwise frombytes.
**kwargs – Further arguments for the NumPy fromstring / frombytes method.
- Returns:
NumPy array of values
- Raises:
ValueError – if the data buffer is empty or malformed
- read_bytes(count=-1, break_on_termchar=False, **kwargs)
Read a certain number of bytes from the instrument.
Do not override in a subclass!
- Parameters:
count (int) – Number of bytes to read. A value of -1 indicates to read from the whole read buffer.
break_on_termchar (bool) – Stop reading at a termination character.
**kwargs – Keyword arguments for the connection itself.
- Returns bytes:
Bytes response of the instrument (including termination).
- Return type:
bytes
- write(command, **kwargs)
Write a string command to the instrument appending write_termination.
Do not override in a subclass!
- Parameters:
command (str) – Command string to be sent to the instrument (without termination).
**kwargs – Keyword arguments for the connection itself.
- Return type:
None
- write_binary_values(command, values, termination='', **kwargs)
Write binary data to the instrument, e.g. waveform for signal generators
- Parameters:
command (
str) – command string to be sent to the instrumentvalues (
Sequence[Union[int,float]]) – iterable representing the binary valuestermination (
str) – String added afterwards to terminate the message. (default:'')**kwargs – Key-word arguments to pass onto
Adapter._format_binary_values()
- Returns:
int– number of bytes written
- write_bytes(content, **kwargs)
Write the bytes content to the instrument.
Do not override in a subclass!
- Parameters:
content (bytes) – The bytes to write to the instrument.
**kwargs – Keyword arguments for the connection itself.
- Return type:
None
Prologix adapter
- class pymeasure.adapters.PrologixAdapter(resource_name, address=None, auto=False, eoi=True, eos='\n', gpib_read_timeout=None, **kwargs)
Bases:
VISAAdapterEncapsulates the additional commands necessary to communicate over a Prologix GPIB-USB Adapter, using the
VISAAdapter.Each PrologixAdapter is constructed based on a connection to the Prologix device itself and the GPIB address of the instrument to be communicated to. Connection sharing is achieved by using the
gpib()method to spawn new PrologixAdapters for different GPIB addresses.- Parameters:
resource_name – A VISA resource string that identifies the connection to the Prologix device itself, for example “ASRL5” for the 5th COM port.
address – Integer GPIB address of the desired instrument. (default:
None)auto – Enable or disable read-after-write and address instrument to listen. (default:
False)eoi – Enable or disable EOI assertion. (default:
True)eos – Set command termination string (CR+LF, CR, LF, or “”) (default:
'\\n')gpib_read_timeout – Set read timeout for GPIB communication in milliseconds from 1..3000 (default:
None)kwargs – Key-word arguments if constructing a new serial object
- Variables:
address – Integer GPIB address of the desired instrument.
Usage example:
adapter = PrologixAdapter("ASRL5::INSTR", 7) sourcemeter = Keithley2400(adapter) # at GPIB address 7 # generate another instance with a different GPIB address: adapter2 = adapter.gpib(9) multimeter = Keithley2000(adapter2) # at GPIB address 9
To allow user access to the Prologix adapter in Linux, create the file:
/etc/udev/rules.d/51-prologix.rules, with contents:SUBSYSTEMS=="usb",ATTRS{idVendor}=="0403",ATTRS{idProduct}=="6001",MODE="0666"
Then reload the udev rules with:
sudo udevadm control --reload-rules sudo udevadm trigger
Since the Prologix adapter uses the same communication channel (an USB CDC) for both, communication with the adapter itself, as well as communication over GPIB, certain things need to be kept in mind:
Operations that need to read from GPIB use the standard
read()method.Operations that just read responses from the Prologix itself need to add the parameter
prologix=Truetoread(); this avoids requesting data from GPIB. This is also necessary when the adapter is put into “listen-only” mode, where all GPIB traffic is automatically being passed up.Binary data must be passed to the bus using
write_binary_values(). This takes care of properly escaping those binary values that would otherwise be interpreted by the Prologix adapter. Note that the default forwrite_binary_values()are to assume floating-point binary data, and prepend IEEE headers. In order to pass just plain bytes to the adapter, tune thedatatypeandheader_fmtparameters:multimeter.write_binary_values('W', [addr], datatype='B', header_fmt='empty')
- _format_binary_values(values, datatype='f', is_big_endian=False, header_fmt='ieee')
Format values in binary format, used internally in
write_binary_values().- Parameters:
values – data to be written to the device.
datatype – the format string for a single element. See struct module. (default:
'f')is_big_endian – boolean indicating endianess. (default:
False)header_fmt – Format of the header prefixing the data (“ieee”, “hp”, “empty”). (default:
'ieee')
- Returns:
binary string.
- Return type:
bytes
- property auto
Control whether to address instruments to talk after sending them a command (bool).
Configure Prologix GPIB controller to automatically address instruments to talk after sending them a command in order to read their response. The feature called, Read-After-Write, saves the user from having to issue read commands repeatedly. This property enables (True) or disables (False) this feature.
- close()
Close the connection. :rtype:
NoneNote
This closes the connection to the resource for all adapters using it currently (e.g. different adapters using the same GPIB line).
- connection: Union[ProtocolAdapter, pyvisa.resources.MessageBasedResource]
- property eoi
Control whether to assert the EOI signal with the last character of any command sent over GPIB port (bool).
Some instruments require EOI signal to be asserted in order to properly detect the end of a command.
- property eos
Control GPIB termination characters (str).
- possible values:
CR+LF
CR
LF
empty string
When data from host is received, all non-escaped LF, CR and ESC characters are removed and GPIB terminators, as specified by this command, are appended before sending the data to instruments. This command does not affect data from instruments received over GPIB port.
- flush_read_buffer()
Flush and discard the input buffer
As detailed by pyvisa, discard the read and receivee buffer contents and if data was present in the read buffer and no END-indicator was present, read from the device until encountering an END indicator (which causes loss of data).
- Return type:
None
- gpib(address, **kwargs)
Return a PrologixAdapter object that references the GPIB address specified, while sharing the Serial connection with other calls of this function
- Parameters:
address – Integer GPIB address of the desired instrument
kwargs – Arguments for the initialization
- Returns:
PrologixAdapter for specific GPIB address
- property gpib_read_timeout
Control the timeout value for the GPIB communication in milliseconds
possible values: 1 - 3000
- read(**kwargs)
Read up to (excluding) read_termination or the whole read buffer.
Do not override in a subclass!
- Parameters:
**kwargs – Keyword arguments for the connection itself.
- Returns str:
ASCII response of the instrument (excluding read_termination).
- Return type:
str
- read_binary_values(header_bytes=0, termination_bytes=None, dtype=<class 'numpy.float32'>, sep='', **kwargs)
Returns a numpy array from a query for binary data
- Parameters:
header_bytes (int) – Number of bytes to ignore in header.
termination_bytes (int) – Number of bytes to strip at end of message or None.
dtype – The NumPy data type to format the values with. (default:
<class 'numpy.float32'>)sep (string) – Separator between chars. If given, use fromstring, otherwise frombytes.
**kwargs – Further arguments for the NumPy fromstring / frombytes method.
- Returns:
NumPy array of values
- Raises:
ValueError – if the data buffer is empty or malformed
- read_bytes(count=-1, break_on_termchar=False, **kwargs)
Read a certain number of bytes from the instrument.
Do not override in a subclass!
- Parameters:
count (int) – Number of bytes to read. A value of -1 indicates to read from the whole read buffer.
break_on_termchar (bool) – Stop reading at a termination character.
**kwargs – Keyword arguments for the connection itself.
- Returns bytes:
Bytes response of the instrument (including termination).
- Return type:
bytes
- reset()
Perform a power-on reset of the controller.
The process takes about 5 seconds. All input received during this time is ignored and the connection is closed.
- property version
Get the version string of the Prologix controller.
- wait_for_srq(timeout=25, delay=0.1)
Blocks until a SRQ, and leaves the bit high
- Parameters:
timeout – Timeout duration in seconds. (default:
25)delay – Time delay between checking SRQ in seconds. (default:
0.1)
- Raises:
TimeoutError – “Waiting for SRQ timed out.”
- write(command, **kwargs)
Write a string command to the instrument appending write_termination.
If the GPIB address in
addressis defined, it is sent first.- Parameters:
command (str) – Command string to be sent to the instrument (without termination).
kwargs – Keyword arguments for the connection itself.
- write_binary_values(command, values, **kwargs)
Write binary data to the instrument, e.g. waveform for signal generators.
values are encoded in a binary format according to IEEE 488.2 Definite Length Arbitrary Block Response Data block.
- Parameters:
command – SCPI command to be sent to the instrument
values – iterable representing the binary values
kwargs – Key-word arguments to pass onto
_format_binary_values()
- Returns:
number of bytes written
- write_bytes(content, **kwargs)
Write the bytes content to the instrument.
Do not override in a subclass!
- Parameters:
content (bytes) – The bytes to write to the instrument.
**kwargs – Keyword arguments for the connection itself.
- Return type:
None
Test adapters
These pieces are useful when writing tests.
- pymeasure.test.expected_protocol(instrument_cls, comm_pairs, connection_attributes=None, connection_methods=None, **kwargs)
Context manager that checks sent/received instrument commands without a device connected.
Given an instrument class and a list of command-response pairs, this context manager confirms that the code in the context manager block produces the expected messages.
Terminators are excluded from the protocol definition, as those are typically a detail of the communication method (i.e. Adapter), and not the protocol itself.
- Parameters:
instrument_cls (pymeasure.Instrument) –
Instrumentsubclass to instantiate.comm_pairs (list[2-tuples[str]]) – List of command-response pairs, i.e. 2-tuples like (‘VOLT?’, ‘3.14’). ‘None’ indicates that a pair member (command or response) does not exist, e.g. (None, ‘RESP1’). Commands and responses are without termination characters.
connection_attributes (
Optional[dict[str,Any]]) – Dictionary of connection attributes and their values. (default:None)connection_methods (
Optional[dict[str,Any]]) – Dictionary of method names of the connection and their return values. (default:None)**kwargs – Keyword arguments for the instantiation of the instrument.
- Return type:
Generator[TypeVar(Inst, bound=Instrument),Any,None]
- class pymeasure.adapters.ProtocolAdapter(comm_pairs=None, connection_attributes=None, connection_methods=None, **kwargs)
Bases:
AdapterAdapter class for testing the command exchange protocol without instrument hardware.
This adapter is primarily meant for use within
pymeasure.test.expected_protocol().The
connectionattribute is aunittest.mock.MagicMocksuch that every call returns. If you want to set a return value, you can useadapter.connection.some_method.return_value = 7, such that a call toadapter.connection.some_method()will return 7. Similarly, you can verify that this call to the connection method happened withassert adapter.connection.some_method.called is True. You can specify dictionaries with return values of attributes and methods.- Parameters:
comm_pairs (list) – List of “reference” message pair tuples. The first element is what is sent to the instrument, the second one is the returned message. ‘None’ indicates that a pair member (write or read) does not exist. The messages do not include the termination characters.
connection_attributes (
Optional[dict]) – Dictionary of connection attributes and their values. (default:None)connection_methods (
Optional[dict]) – Dictionary of method names of the connection and their return values. (default:None)
-
connection:
MagicMock
- flush_read_buffer()
Flush and discard the input buffer
As detailed by pyvisa, discard the read buffer contents and if data was present in the read buffer and no END-indicator was present, read from the device until encountering an END indicator (which causes loss of data).
- Return type:
None
- class pymeasure.adapters.FakeAdapter(log=None, **kwargs)
Bases:
AdapterProvides a fake adapter for debugging purposes, which bounces back the command so that arbitrary values testing is possible.
a = FakeAdapter() assert a.read() == "" a.write("5") assert a.read() == "5" assert a.read() == "" assert a.ask("10") == "10" assert a.values("10") == [10]
- close()
Close the connection.
- Return type:
None
-
connection:
ConnectionProtocol
- flush_read_buffer()
Flush and discard the input buffer. Implement in subclass.
- Return type:
None
- read(**kwargs)
Read up to (excluding) read_termination or the whole read buffer.
Do not override in a subclass!
- Parameters:
**kwargs – Keyword arguments for the connection itself.
- Returns str:
ASCII response of the instrument (excluding read_termination).
- Return type:
str
- read_binary_values(header_bytes=0, termination_bytes=None, dtype=<class 'numpy.float32'>, sep='', **kwargs)
Returns a numpy array from a query for binary data
- Parameters:
header_bytes (int) – Number of bytes to ignore in header.
termination_bytes (int) – Number of bytes to strip at end of message or None.
dtype – The NumPy data type to format the values with. (default:
<class 'numpy.float32'>)sep (string) – Separator between chars. If given, use fromstring, otherwise frombytes.
**kwargs – Further arguments for the NumPy fromstring / frombytes method.
- Returns:
NumPy array of values
- Raises:
ValueError – if the data buffer is empty or malformed
- read_bytes(count=-1, break_on_termchar=False, **kwargs)
Read a certain number of bytes from the instrument.
Do not override in a subclass!
- Parameters:
count (int) – Number of bytes to read. A value of -1 indicates to read from the whole read buffer.
break_on_termchar (bool) – Stop reading at a termination character.
**kwargs – Keyword arguments for the connection itself.
- Returns bytes:
Bytes response of the instrument (including termination).
- Return type:
bytes
- write(command, **kwargs)
Write a string command to the instrument appending write_termination.
Do not override in a subclass!
- Parameters:
command (str) – Command string to be sent to the instrument (without termination).
**kwargs – Keyword arguments for the connection itself.
- Return type:
None
- write_binary_values(command, values, termination='', **kwargs)
Write binary data to the instrument, e.g. waveform for signal generators
- Parameters:
command (
str) – command string to be sent to the instrumentvalues (
Sequence[Union[int,float]]) – iterable representing the binary valuestermination (
str) – String added afterwards to terminate the message. (default:'')**kwargs – Key-word arguments to pass onto
Adapter._format_binary_values()
- Returns:
int– number of bytes written
- write_bytes(content, **kwargs)
Write the bytes content to the instrument.
Do not override in a subclass!
- Parameters:
content (bytes) – The bytes to write to the instrument.
**kwargs – Keyword arguments for the connection itself.
- Return type:
None
- class pymeasure.generator.Generator
Generates tests from the communication with an instrument.
Example usage:
g = Generator() inst = g.instantiate(TC038, "COM5", 'hcp', adapter_kwargs={'baud_rate': 9600}) inst.information # returns the 'information' property and adds it to the tests inst.setpoint = 20 inst.setpoint == 20 # should be True g.write_file("test_tc038.py") # write the tests to a file
- instantiate(instrument_class, adapter, manufacturer, adapter_kwargs=None, **kwargs)
Instantiate the instrument and store the instantiation communication.
..note:
You have to give all keyword arguments necessary for adapter instantiation in `adapter_kwargs`, even those, which are defined somewhere in the instrument's ``__init__`` method, be it as a default value, be it directly in the ``Instrument.__init__()`` call.
- Parameters:
instrument_class – Class of the instrument to test.
adapter – Adapter (instance or str) for the instrument instantiation.
manufacturer – Module from which to import the instrument, e.g. ‘hcp’ if instrument_class is ‘pymeasure.hcp.tc038’.
adapter_kwargs – Keyword arguments for the adapter instantiation (see note above). (default:
None)**kwargs – Keyword arguments for the instrument instantiation.
- Returns:
A man-in-the-middle instrument, which can be used like a normal instrument.
- parse_stream()
Parse the stream not yet read.
- test_method(method_name, *args, **kwargs)
Test calling the method_name of the instruments with args and kwargs.
- test_property_getter(property)
Test getting the property of the instrument, adding it to the list.
- test_property_setter(property, value)
Test setting the property of the instrument to value, adding it to the list.
- test_property_setter_batch(property, values)
Test setting property to each element in values.
- write_file(filename='tests.py')
Write the tests into the file.
- Parameters:
filename – Name to save the tests to, may contain the path, e.g. “/tests/test_abc.py”. (default:
'tests.py')
- write_getter_test(file, property, parameters)
Write a getter test.
- write_init_test(file)
Write the header and init test.
- write_method_test(file, method, parameters)
Write a test for a method.
- write_method_tests(file)
Write all parametrized method tests in alphabetic order.
- write_property_tests(file)
Write tests for properties in alphabetic order.
If getter and setter exist, the setter is the first test.
- write_setter_test(file, property, parameters)
Write a setter test.