5. instrument_control_auxiliary

Example can be found here Controlling an Instrument.

5.1. Instrument Control Auxiliary

module

instrument_control

synopsis

provide a simple interface to control instruments using SCPI protocol.

The functionalities provided in this package may be used directly inside ITF tests using the corresponding auxiliary, but also using a CLI.

Warning

This auxiliary can only be used with the cc_visa or cc_tcp_ip connector.
It is not intended to be used with a proxy connector.
One instrument is bound to one auxiliary even if the instrument has multiple channels.

pykiso.lib.auxiliaries.instrument_control_auxiliary.instrument_control_auxiliary

Instrument Control Auxiliary

pykiso.lib.auxiliaries.instrument_control_auxiliary.instrument_control_cli

Instrument Control CLI

pykiso.lib.auxiliaries.instrument_control_auxiliary.lib_scpi_commands

Library of SCPI commands

pykiso.lib.auxiliaries.instrument_control_auxiliary.lib_instruments

Library of instruments communicating via VISA

5.1.1. Instrument Control Auxiliary

module

instrument_control_auxiliary

synopsis

Auxiliary used to communicate via a VISA connector using the SCPI protocol.

class pykiso.lib.auxiliaries.instrument_control_auxiliary.instrument_control_auxiliary.InstrumentControlAuxiliary(com, instrument='', write_termination='\\n', output_channel=None, **kwargs)[source]

Auxiliary used to communicate via a VISA connector using the SCPI protocol.

Constructor.

Parameters
  • com (CChannel) – VISAChannel that supports VISA communication

  • instrument – name of the instrument currently in use (will be used to adapt the SCPI commands)

  • write_termination – write termination character

  • output_channel (Optional[int]) – output channel to use on the instrument currently in use (if more than one)

handle_query(query_command)[source]
Send a query request to the instrument. Uses the ‘query’ method of the

channel if available, uses ‘cc_send’ and ‘cc_receive’ otherwise.

Parameters

query_command (str) – query command to send

Return type

str

Returns

Response message, None if the request expired with a timeout.

handle_read()[source]

Handle read command by calling associated connector cc_receive.

Return type

str

Returns

received response from instrument otherwise empty string

handle_write(write_command, validation=None)[source]

Send a write request to the instrument and then returns if the value was successfully written. A query is sent immediately after the writing and the answer is compared to the expected one.

Parameters
  • write_command (str) – write command to send

  • validation (Optional[Tuple[str, Union[str, List[str]]]]) – tuple of the form (validation command (str), expected output (str or list of str))

Return type

str

Returns

status message depending on the command validation: SUCCESS, FAILURE or NO_VALIDATION

query(query_command)[source]
Send a query request to the instrument. Uses the ‘query’ method of the

channel if available, uses ‘cc_send’ and ‘cc_receive’ otherwise.

Parameters

query_command (str) – query command to send

Return type

Union[bytes, str]

Returns

Response message, None if the request expired with a timeout.

read()[source]

Send a read request to the instrument.

Return type

Union[str, bool]

Returns

received response from instrument otherwise empty string

write(write_command, validation=None)[source]

Send a write request to the instrument.

Parameters
  • write_command (str) – command to send

  • validation (Optional[Tuple[str, Union[str, List[str]]]]) – contain validation criteria apply on the response

Return type

str

5.1.2. Instrument Control CLI

module

instrument_control_cli

synopsis

Command Line Interface used to communicate with an instrument using the SCPI protocol.

class pykiso.lib.auxiliaries.instrument_control_auxiliary.instrument_control_cli.ExitCode(value)[source]

List of possible exit codes

class pykiso.lib.auxiliaries.instrument_control_auxiliary.instrument_control_cli.Interface(value)[source]

List of available interfaces

pykiso.lib.auxiliaries.instrument_control_auxiliary.instrument_control_cli.initialize_logging(log_level)[source]

Initialize the logging by setting the general log level

Parameters

log_level (str) – any of DEBUG, INFO, WARNING, ERROR

Return type

getLogger

Returns

configured Logger

pykiso.lib.auxiliaries.instrument_control_auxiliary.instrument_control_cli.parse_user_command(user_cmd)[source]

Parses the command from user input in interactive mode

Parameters

user_cmd (str) – command provided by the user in interactive mode

Return type

dict

Returns

a single-item dictionary containing the parsed command as key the the corresponding payload as value

pykiso.lib.auxiliaries.instrument_control_auxiliary.instrument_control_cli.perform_actions(instr_aux, actions)[source]

Performs the desired actions from the CLI arguments

Parameters
  • instr_aux (InstrumentControlAuxiliary) – instrument on which to perform the actions

  • actions (dict) – dictionary containing the parsed argument and the corresponding value.

Return type

None

pykiso.lib.auxiliaries.instrument_control_auxiliary.instrument_control_cli.setup_interface(interface, baud_rate=None, ip_address=None, port=None, protocol=None, name=None)[source]

Set up the instrument auxiliary with the appropriate interface settings. The ip address must be provided in the case of TCPIP interfaces, as must the serial port for VISA_SERIAL interface. The baud rate and the output channel to use are optional.

Parameters
  • interface (str) – interface to use

  • baud_rate (Optional[int]) – baud rate to use

  • ip_address (Optional[str]) – ip address of the remote instrument (used for remote control only)

  • port (Optional[int]) – the port of the device to connect to. This is either a serial port for a VISA_SERIAL interface or an IP port in case of an TCPIP interfaces.

  • protocol (Optional[str]) – The protocol to use for VISA_TCPIP interfaces.

  • name (Optional[str]) – instrument name used to adapt the SCPI commands to be sent to the instrument

Return type

InstrumentControlAuxiliary

Returns

The created instrument auxiliary.

5.1.3. Library of SCPI commands

module

lib_scpi_commands

synopsis

Library of helper functions used to send requests to instruments with SCPI protocol. This library can be used with any VISA instance having a write and a query method.

class pykiso.lib.auxiliaries.instrument_control_auxiliary.lib_scpi_commands.LibSCPI(visa_object, instrument='')[source]

Class containing common SCPI commands for write and query requests.

Constructor.

Parameters
  • visa_object – any visa object having a write and a query method

  • instrument (str) – name of the instrument in use. If registered, the commands adapted to this instrument’s capabilities are used instead of the default ones.

disable_output()[source]

Disable output on the currently selected output channel of an instrument.

Return type

str

Returns

the writing operation’s status code

enable_output()[source]

Enable output on the currently selected output channel of an instrument.

Return type

str

Returns

the writing operation’s status code

get_all_errors()[source]

Get all errors of an instrument.

return: list of off errors

get_command(cmd_tag, cmd_type, cmd_validation=None)[source]

Return the pre-defined command.

Parameters
  • cmd_tag (str) – command tag corresponding to the command to execute

  • cmd_type (str) – either ‘write’ or ‘query’

  • cmd_validation (Optional[tuple]) – expected output after validation (only used in write commands)

Return type

Tuple

Returns

the associated command plus a tuple containing the associated query and the expected response (if cmd_validation is not none) otherwise None

get_current_limit_high()[source]

Returns the current upper limit (in V) of an instrument.

Return type

str

Returns

the query’s response message

get_current_limit_low()[source]

Returns the current lower limit (in V) of an instrument.

Return type

str

Returns

the query’s response message

get_identification()[source]

Get the identification information of an instrument.

Returns

the instrument’s identification information

get_nominal_current()[source]

Query the nominal current of an instrument on the selected channel (in A).

Return type

str

Returns

the nominal current

get_nominal_power()[source]

Query the nominal power of an instrument on the selected channel (in W).

Return type

str

Returns

the nominal power

get_nominal_voltage()[source]

Query the nominal voltage of an instrument on the selected channel (in V).

Return type

str

Returns

the nominal voltage

get_output_channel()[source]

Get the currently selected output channel of an instrument.

Return type

str

Returns

the currently selected output channel

get_output_state()[source]

Get the output status (ON or OFF, enabled or disabled) of the currently selected channel of an instrument.

Return type

str

Returns

the output state (ON or OFF)

get_power_limit_high()[source]

Returns the power upper limit (in W) of an instrument.

Return type

str

Returns

the query’s response message

get_remote_control_state()[source]

Get the remote control mode (ON or OFF) of an instrument.

Returns

the remote control state

get_status_byte()[source]

Get the status byte of an instrument.

Returns

the instrument’s status byte

get_target_current()[source]

Get the desired output current (in A) of an instrument.

Return type

str

Returns

the target current

get_target_power()[source]

Get the desired output power (in W) of an instrument.

Return type

str

Returns

the target power

get_target_voltage()[source]

Get the desired output voltage (in V) of an instrument.

Return type

str

Returns

the target voltage

get_voltage_limit_high()[source]

Returns the voltage upper limit (in V) of an instrument.

Return type

str

Returns

the query’s response message

get_voltage_limit_low()[source]

Returns the voltage lower limit (in V) of an instrument.

Return type

str

Returns

the query’s response message

measure_current()[source]

Return the measured output current of an instrument (in A).

Return type

str

Returns

the measured current

measure_power()[source]

Return the measured output power of an instrument (in W).

Return type

str

Returns

the measured power

measure_voltage()[source]

Return the measured output voltage of an instrument (in V).

Return type

str

Returns

the measured voltage

reset()[source]

Reset an instrument.

Returns

NO_VALIDATION status code

self_test()[source]

Performs a self-test of an instrument.

Returns

the query’s response message

set_current_limit_high(limit_value)[source]

Set the current upper limit (in A) of an instrument.

Parameters

limit_value (float) – limit value to be set on the instrument

Return type

str

Returns

the writing operation’s status code

set_current_limit_low(limit_value)[source]

Set the current lower limit (in A) of an instrument.

Parameters

limit_value (float) – limit value to be set on the instrument

Return type

str

Returns

the writing operation’s status code

set_output_channel(channel)[source]

Set the output channel of an instrument.

Parameters

channel (int) – the output channel to select on the instrument

Return type

str

Returns

the writing operation’s status code

set_power_limit_high(limit_value)[source]

Set the power upper limit (in W) of an instrument.

Parameters

limit_value (float) – limit value to be set on the instrument

Return type

str

Returns

the writing operation’s status code

set_remote_control_off()[source]

Disable the remote control of an instrument. The instrument will respond to query and read commands only.

Returns

the writing operation’s status code

set_remote_control_on()[source]

Enables the remote control of an instrument. The instrument will respond to all SCPI commands.

Returns

the writing operation’s status code

set_target_current(value)[source]

Set the desired output current (in A) of an instrument.

Parameters

value (float) – value to be set on the instrument

Return type

str

Returns

the writing operation’s status code

set_target_power(value)[source]

Set the desired output power (in W) of an instrument.

Parameters

value (float) – value to be set on the instrument

Return type

str

Returns

the writing operation’s status code

set_target_voltage(value)[source]

Set the desired output voltage (in V) of an instrument.

Parameters

value (float) – value to be set on the instrument

Return type

str

Returns

the writing operation’s status code

set_voltage_limit_high(limit_value)[source]

Set the voltage upper limit (in V) of an instrument.

Parameters

limit_value (float) – limit value to be set on the instrument

Return type

str

Returns

the writing operation’s status code

set_voltage_limit_low(limit_value)[source]

Set the voltage lower limit (in V) of an instrument.

Parameters

limit_value (float) – limit value to be set on the instrument

Return type

str

Returns

the writing operation’s status code

5.1.4. Library of instruments communicating via VISA

module

lib_instruments

synopsis

Dictionaries containing the appropriate SCPI commands for some instruments.