pymeasure.adapters¶
The adapter classes allow the instruments to be independent of the communication method used.
Adapters for specific instruments should be grouped in an adapters.py file in the corresponding manufacturer’s folder of pymeasure.instruments. For example, the adapter for communicating with LakeShore instruments over USB, LakeShoreUSBAdapter, is found in pymeasure.instruments.lakeshore.adapters.
Adapter base class¶
-
class
pymeasure.adapters.Adapter¶ 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 inhereted from.
-
ask(command)¶ Writes the command to the instrument and returns the resulting ASCII response
- Parameters
command – SCPI command string to be sent to the instrument
- Returns
String ASCII response of the instrument
-
binary_values(command, header_bytes=0, dtype=<class 'numpy.float32'>)¶ Returns a numpy array from a query for binary data
- Parameters
command – SCPI command to be sent to the instrument
header_bytes – Integer number of bytes to ignore in header
dtype – The NumPy data type to format the values with
- Returns
NumPy array of values
-
read()¶ Reads until the buffer is empty and returns the resulting ASCII respone
- Returns
String ASCII response of the instrument.
-
values(command, separator=', ', cast=<class 'float'>)¶ Writes a command to the instrument and returns a list of formatted values from the result
- Parameters
command – SCPI command to be sent to the instrument
separator – A separator character to split the string into a list
cast – A type to cast the result
- Returns
A list of the desired type, or strings where the casting fails
-
write(command)¶ Writes a command to the instrument
- Parameters
command – SCPI command string to be sent to the instrument
-
Fake adapter¶
-
class
pymeasure.adapters.FakeAdapter¶ Bases:
pymeasure.adapters.adapter.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]
-
ask(command)¶ Writes the command to the instrument and returns the resulting ASCII response
- Parameters
command – SCPI command string to be sent to the instrument
- Returns
String ASCII response of the instrument
-
binary_values(command, header_bytes=0, dtype=<class 'numpy.float32'>)¶ Returns a numpy array from a query for binary data
- Parameters
command – SCPI command to be sent to the instrument
header_bytes – Integer number of bytes to ignore in header
dtype – The NumPy data type to format the values with
- Returns
NumPy array of values
-
read()¶ Returns the last commands given after the last read call.
-
values(command, separator=', ', cast=<class 'float'>)¶ Writes a command to the instrument and returns a list of formatted values from the result
- Parameters
command – SCPI command to be sent to the instrument
separator – A separator character to split the string into a list
cast – A type to cast the result
- Returns
A list of the desired type, or strings where the casting fails
-
write(command)¶ Writes the command to a buffer, so that it can be read back.
-
Serial adapter¶
-
class
pymeasure.adapters.SerialAdapter(port, **kwargs)¶ Bases:
pymeasure.adapters.adapter.AdapterAdapter class for using the Python Serial package to allow serial communication to instrument
- Parameters
port – Serial port
kwargs – Any valid key-word argument for serial.Serial
-
ask(command)¶ Writes the command to the instrument and returns the resulting ASCII response
- Parameters
command – SCPI command string to be sent to the instrument
- Returns
String ASCII response of the instrument
-
binary_values(command, header_bytes=0, dtype=<class 'numpy.float32'>)¶ Returns a numpy array from a query for binary data
- Parameters
command – SCPI command to be sent to the instrument
header_bytes – Integer number of bytes to ignore in header
dtype – The NumPy data type to format the values with
- Returns
NumPy array of values
-
read()¶ Reads until the buffer is empty and returns the resulting ASCII respone
- Returns
String ASCII response of the instrument.
-
values(command, separator=', ', cast=<class 'float'>)¶ Writes a command to the instrument and returns a list of formatted values from the result
- Parameters
command – SCPI command to be sent to the instrument
separator – A separator character to split the string into a list
cast – A type to cast the result
- Returns
A list of the desired type, or strings where the casting fails
-
write(command)¶ Writes a command to the instrument
- Parameters
command – SCPI command string to be sent to the instrument
Prologix adapter¶
-
class
pymeasure.adapters.PrologixAdapter(port, address=None, rw_delay=None, serial_timeout=0.5, **kwargs)¶ Bases:
pymeasure.adapters.serial.SerialAdapterEncapsulates the additional commands necessary to communicate over a Prologix GPIB-USB Adapter, using the SerialAdapter.
Each PrologixAdapter is constructed based on a serial port or connection and the GPIB address to be communicated to. Serial connection sharing is achieved by using the
gpib()method to spawn new PrologixAdapters for different GPIB addresses.- Parameters
port – The Serial port name or a serial.Serial object
address – Integer GPIB address of the desired instrument
rw_delay – An optional delay to set between a write and read call for slow to respond instruments.
kwargs – Key-word arguments if constructing a new serial object
- Variables
address – Integer GPIB address of the desired instrument
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
-
ask(command)¶ Ask the Prologix controller, include a forced delay for some instruments.
- Parameters
command – SCPI command string to be sent to instrument
-
binary_values(command, header_bytes=0, dtype=<class 'numpy.float32'>)¶ Returns a numpy array from a query for binary data
- Parameters
command – SCPI command to be sent to the instrument
header_bytes – Integer number of bytes to ignore in header
dtype – The NumPy data type to format the values with
- Returns
NumPy array of values
-
gpib(address, rw_delay=None)¶ Returns and 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
rw_delay – Set a custom Read/Write delay for the instrument
- Returns
PrologixAdapter for specific GPIB address
-
read()¶ Reads the response of the instrument until timeout
- Returns
String ASCII response of the instrument
-
set_defaults()¶ Sets up the default behavior of the Prologix-GPIB adapter
-
values(command, separator=', ', cast=<class 'float'>)¶ Writes a command to the instrument and returns a list of formatted values from the result
- Parameters
command – SCPI command to be sent to the instrument
separator – A separator character to split the string into a list
cast – A type to cast the result
- Returns
A list of the desired type, or strings where the casting fails
-
wait_for_srq(timeout=25, delay=0.1)¶ Blocks until a SRQ, and leaves the bit high
- Parameters
timeout – Timeout duration in seconds
delay – Time delay between checking SRQ in seconds
-
write(command)¶ Writes the command to the GPIB address stored in the
address- Parameters
command – SCPI command string to be sent to the instrument
VISA adapter¶
-
class
pymeasure.adapters.VISAAdapter(resourceName, visa_library='', **kwargs)¶ Bases:
pymeasure.adapters.adapter.AdapterAdapter class for the VISA library using PyVISA to communicate with instruments.
- Parameters
resource – VISA resource name that identifies the address
visa_library – VisaLibrary Instance, path of the VISA library or VisaLibrary spec string (@py or @ni). if not given, the default for the platform will be used.
kwargs – Any valid key-word arguments for constructing a PyVISA instrument
-
ask(command)¶ Writes the command to the instrument and returns the resulting ASCII response
- Parameters
command – SCPI command string to be sent to the instrument
- Returns
String ASCII response of the instrument
-
ask_values(command)¶ Writes a command to the instrument and returns a list of formatted values from the result. The format of the return is configurated by self.config().
- Parameters
command – SCPI command to be sent to the instrument
- Returns
Formatted response of the instrument.
-
binary_values(command, header_bytes=0, dtype=<class 'numpy.float32'>)¶ Returns a numpy array from a query for binary data
- Parameters
command – SCPI command to be sent to the instrument
header_bytes – Integer number of bytes to ignore in header
dtype – The NumPy data type to format the values with
- Returns
NumPy array of values
-
config(is_binary=False, datatype='str', container=<built-in function array>, converter='s', separator=', ', is_big_endian=False)¶ Configurate the format of data transfer to and from the instrument.
- Parameters
is_binary – If True, data is in binary format, otherwise ASCII.
datatype – Data type.
container – Return format. Any callable/type that takes an iterable.
converter – String converter, used in dealing with ASCII data.
separator – Delimiter of a series of data in ASCII.
is_big_endian – Endianness.
-
static
has_supported_version()¶ Returns True if the PyVISA version is greater than 1.8
-
read()¶ Reads until the buffer is empty and returns the resulting ASCII response
- Returns
String ASCII response of the instrument.
-
read_bytes(size)¶ Reads specified number of bytes from the buffer and returns the resulting ASCII response
- Parameters
size – Number of bytes to read from the buffer
- Returns
String ASCII response of the instrument.
-
values(command, separator=', ', cast=<class 'float'>)¶ Writes a command to the instrument and returns a list of formatted values from the result
- Parameters
command – SCPI command to be sent to the instrument
separator – A separator character to split the string into a list
cast – A type to cast the result
- Returns
A list of the desired type, or strings where the casting fails
-
wait_for_srq(timeout=25, delay=0.1)¶ Blocks until a SRQ, and leaves the bit high
- Parameters
timeout – Timeout duration in seconds
delay – Time delay between checking SRQ in seconds
-
write(command)¶ Writes a command to the instrument
- Parameters
command – SCPI command string to be sent to the instrument
VXI-11 adapter¶
-
class
pymeasure.adapters.VXI11Adapter(host, **kwargs)¶ Bases:
pymeasure.adapters.adapter.Adapter- VXI11 Adapter class. Provides a adapter object that
wraps around the read, write and ask functionality of the vxi11 library.
- Parameters
host – string containing the visa connection information.
-
ask(command)¶ Wrapper function for the ask command using the vx11 interface.
- Parameters
command – string with the command that will be transmitted to the instrument.
:returns string containing a response from the device.
-
ask_raw(command)¶ Wrapper function for the ask_raw command using the vx11 interface.
- Parameters
command – binary string with the command that will be transmitted to the instrument
:returns binary string containing the response from the device.
-
binary_values(command, header_bytes=0, dtype=<class 'numpy.float32'>)¶ Returns a numpy array from a query for binary data
- Parameters
command – SCPI command to be sent to the instrument
header_bytes – Integer number of bytes to ignore in header
dtype – The NumPy data type to format the values with
- Returns
NumPy array of values
-
read()¶ Wrapper function for the read command using the vx11 interface.
:return string containing a response from the device.
-
read_raw()¶ Wrapper function for the read_raw command using the vx11 interface.
:returns binary string containing the response from the device.
-
values(command, separator=', ', cast=<class 'float'>)¶ Writes a command to the instrument and returns a list of formatted values from the result
- Parameters
command – SCPI command to be sent to the instrument
separator – A separator character to split the string into a list
cast – A type to cast the result
- Returns
A list of the desired type, or strings where the casting fails
-
write(command)¶ Wrapper function for the write command using the vxi11 interface.
- Parameters
command – string with command the that will be transmitted to the instrument.
-
write_raw(command)¶ Wrapper function for the write_raw command using the vxi11 interface.
- Parameters
command – binary string with the command that will be transmitted to the instrument