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.Adapter
Provides 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.Adapter
Adapter 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, **kwargs)¶ Bases:
pymeasure.adapters.serial.SerialAdapter
Encapsulates 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, **kwargs)¶ Bases:
pymeasure.adapters.adapter.Adapter
Adapter class for the VISA library using PyVISA to communicate to instruments. Inherit from either class VISAAdapter14 or VISAAdapter15.
Parameters: - resource – VISA resource name that identifies the address
- 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.
-
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
-
version
¶ The string of the PyVISA version in use
-
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