Reference Manual¶
base_classes module¶
-
class
microlab_instruments.base_classes.AardvarkInstrument[source]¶ Bases:
objectInitialize an Aardvark.
Raises: Exception – Upon instantiation, SPI communication is tested. A 25-long array of bytes is sent twice to the Aardvark (and subsequently to the FPGA). After the second attempt, a response identical to the array must be received. If not, an Exception is raised. In this case, it may be likely that the FPGA did not respond properly. -
I2C_STATUS_CODES= {1: 'AA_I2C_STATUS_BUS_ERROR', 2: 'AA_I2C_STATUS_SLA_ACK', 3: 'AA_I2C_STATUS_SLA_NACK', 4: 'AA_I2C_STATUS_DATA_NACK', 5: 'AA_I2C_STATUS_ARB_LOST', 6: 'AA_I2C_STATUS_BUS_LOCKED', 7: 'AA_I2C_STATUS_LAST_DATA_ACK'}¶ These are the status codes used by
i2c_write(),i2c_read(), andi2c_write_read()when raising Exceptions.
-
i2c_read(address, bufsize)[source]¶ Read
bufsizenumber of bytes from the I2C slave withaddress.Parameters: - address (int) – Slave address from which to receive response.
- bufsize (int) – Size in bytes of expected response from slave.
Returns out: Response from slave. A
bufsize-length list of ints.Return type: list
Raises: Exception – if the status response is not 0. See
I2C_STATUS_CODES.
-
i2c_write(address, bytecode)[source]¶ Write
bytecodeto the Aardvark output to be received by I2C slave withaddress.Parameters: - address (int) – Slave address to receive
bytecode. Limited to 8 bits. - bytecode (int) – Raw bytecode to send. Limited to 8 bits.
Returns out: Number of bytes sent.
Return type: int
Raises: Exception – if the status response is not 0. See
I2C_STATUS_CODES.- address (int) – Slave address to receive
-
i2c_write_read(address, bytecode, bufsize)[source]¶ Write
bytecodeto, and readbufsizebytes from, I2C slave withaddressin one fell swoop!Parameters: - address (int) – Slave address to receive
bytecode. Limited to 8 bits. - bytecode (int) – Raw bytecode to send. Limited to 8 bits.
- bufsize (int) – Size in bytes of expected response from slave.
Returns out: Response from slave. A
bufsize-length list of ints.Return type: list
Raises: Exception – if the status response is not 0. See
I2C_STATUS_CODES.- address (int) – Slave address to receive
-
spi_write(bytecode)[source]¶ Write
bytecodeto, and read 25 bytes from, the SPI channel in one fell swoop!Parameters: bytecode (list) – Raw bytecodes to send. Must be exactly 25-long list of bytes. Returns out: Response bytes. A 25-length list of ints. Return type: list Raises: Exception – if bytecodedoes not have exactly 25 8-bit elements.
-
-
class
microlab_instruments.base_classes.FPGAInstrument(aardvark)[source]¶ Bases:
objectAn abstraction layer for the FPGA.
-
class
microlab_instruments.base_classes.GPIBInstrument(nickname, reset=True)[source]¶ Bases:
microlab_instruments.base_classes.SCPIInstrumentInitialize a GPIB instrument
Parameters: nickname (str) – A nickname associated with a GPIB primary address and defined in /etc/gpib.conf.-
read(bufsize=4096)[source]¶ Read
bufsizebytes from instrument. Using this low-level function, there is no way to ensure that all the response data has been retrieved, or to make sense of binary data. It is strongly recommended to useread_ascii(),read_binary(), orread_ieee754().Parameters: bufsize (int) – Defaults to 4096 bytes. Expected size in bytes of the response from the instrument. Returns out: Response from the instrument. Return type: str
-
-
class
microlab_instruments.base_classes.I2CMuxInstrument(aardvark)[source]¶ Bases:
objectAn abstraction layer for the I2C multiplexer chip.
-
class
microlab_instruments.base_classes.SCPIInstrument[source]¶ Bases:
object-
ask_ascii(scpi_string)[source]¶ A convenience function for calling
write()andread_ascii()consecutively. Up to 4096 bytes are read from the ASCII response buffer.Parameters: scpi_string (str) – A valid SCPI query command. See the instrument’s SCPI command reference. Raises: Exception – If the SCPI command does not end with a ‘?’ (i.e. not a query command)
-
ask_binary(scpi_string)[source]¶ A convenience function for calling
write()andread_binary()consecutively.Parameters: scpi_string (str) – A valid SCPI query command. See the instrument’s SCPI command reference. Raises: Exception – If the SCPI command does not end with a ‘?’ (i.e. not a query command)
-
ask_ieee754(scpi_string)[source]¶ A convenience function for calling
write()andread_ieee754()consecutively.Parameters: scpi_string (str) – A valid SCPI query command. See the instrument’s SCPI command reference. Raises: Exception – If the SCPI command does not end with a ‘?’ (i.e. not a query command)
-
configure(config_file)[source]¶ Reads from a text file containing valid SCPI commands separated by newlines to configure the instrument. Only program commands are allowed. Configures the instrument by sending those commands consecutively. Automatically sends an
*OPC?command to await pending operations. Prints out those commands to standard output.Text written after a ‘#’ character are considered comments.
Commands in the configuration file are assumed to be valid for the instrument.
Parameters: config_file (str) – The filename of the configuration file. Raises: Exception – If any of the SCPI commands contain a ‘?’ (i.e. are query commands)
-
read_ascii(bufsize=4096)[source]¶ Read ASCII response from instrument in chunks of
bufsizebytes until a\nis encountered.Parameters: bufsize (int) – Defaults to 4096 bytes. Size of consecutive chunks of data to be read. Returns out: Response from the instrument. Return type: str
-
read_binary()[source]¶ Read raw binary data from instrument. It is the developer’s responsiblity to make sense of it.
Returns out: Response from the instrument. This is just a string of binary code. Return type: str A typical use case is obtaining a screenshot of the instrument panel. The following code is for the Agilent B2902A Precision Source Measure Unit, nicknamed ‘Yveltal’.
import microlab_instruments as mi yveltal = mi.Yveltal() yveltal.write(':DISP:ENAB ON') yveltal.write(':DISP:VIEW GRAP') yveltal.write(':HCOP:SDUM:FORM JPG') yveltal.ask_ascii('*OPC?') yveltal.write(':HCOP:SDUM:DATA?') image_data = yveltal.read_binary() file_handle = open('screendump.jpg', 'wb') file_handle.write(image_data) file_handle.close()
-
read_ieee754()[source]¶ A convenience function to read binary data known to be formatted in IEEE-754 floating-point. Internally calls
read_binary()and automatically determines half-, single-, or double-precision based on the instrument’s settings.Returns out: A list of floating-point numbers. Return type: list
-
-
class
microlab_instruments.base_classes.SerialInstrument(device_port)[source]¶ Bases:
objectInitialize an RS-232 instrument.
-
class
microlab_instruments.base_classes.TCPIPInstrument(socket_pair, reset=True)[source]¶ Bases:
microlab_instruments.base_classes.SCPIInstrumentInitialize TCP/IP instrument.
Parameters: socket_pair (tuple) – A 2-tuple of the form ('192.168.1.2', 5025).-
read(bufsize=4096)[source]¶ Read
bufsizebytes from instrument. Using this low-level function, there is no way to ensure that all the response data has been retrieved, or to make sense of binary data. It is strongly recommended to useread_ascii(),read_binary(), orread_ieee754().Parameters: bufsize (int) – Defaults to 4096 bytes. Expected size in bytes of the response from the instrument. Returns out: Response from the instrument. Return type: str
-
-
class
microlab_instruments.base_classes.TempSensorInstrument(aardvark, mux)[source]¶ Bases:
objectAn abstraction layer for the Sensirion STS21 temperature sensor with an I2C communication interface.
Initialize a Sensirion STS21 temperature sensor.
Parameters: - aardvark (Aardvark) – An Aardvark object through which I2C commands are relayed.
- mux (I2CMuxInstrument) – The I2C multiplexer through which I2C commands are relayed.
microlab_instruments module¶
-
class
microlab_instruments.microlab_instruments.Chen(aardvark)[source]¶ Bases:
microlab_instruments.base_classes.I2CMuxInstrumentInitialize the I2C multiplexer.
Parameters: aardvark (Aardvark) – An Aardvark object through which I2C commands are relayed. import microlab_instruments as mi aa = mi.Aardvark() chen = mi.Chen(aa)
-
class
microlab_instruments.microlab_instruments.Deoxys[source]¶ Bases:
microlab_instruments.base_classes.TCPIPInstrument-
ask_waveform_data()[source]¶ A convenience function to query the waveform preamble and waveform data in one call. Additionally, it also composes the (x,y) data list.
Returns out: A 2-column list. The first column holds the x values and the second column holds the y values. Return type: list
-
-
class
microlab_instruments.microlab_instruments.Kerrigan(aardvark)[source]¶ Bases:
microlab_instruments.base_classes.FPGAInstrumentInitialize the FPGA.
Parameters: aardvark (Aardvark) – An Aardvark object through which I2C commands are relayed. import microlab_instruments as mi aa = mi.Aardvark() kerrigan = mi.Kerrigan(aa)
-
class
microlab_instruments.microlab_instruments.Traxex(aardvark, mux)[source]¶ Bases:
microlab_instruments.base_classes.TempSensorInstrumentInitialize a Sensirion STS21 temperature sensor.
Parameters: aardvark (Aardvark) – An Aardvark object through which I2C commands are relayed. import microlab_instruments as mi aa = mi.Aardvark() traxex = mi.Traxex(aa) print traxex.read_temp()
-
class
microlab_instruments.microlab_instruments.Xin(aardvark, mux)[source]¶ Bases:
microlab_instruments.base_classes.TempSensorInstrumentInitialize a Sensirion STS21 temperature sensor.
Parameters: aardvark (Aardvark) – An Aardvark object through which I2C commands are relayed. import microlab_instruments as mi aa = mi.Aardvark() xin = mi.Xin(aa) print xin.read_temp()