pylab_ml.base_instrument.Instrument

class Instrument(**kwargs)[source]

Bases: ABC, Ident, mqtt_deviceattributes

This is the abstract Instrument class.

It cannot be used directly but provides a basic set of methods & properties to override with actual instruments

Initialization arguments of a derived class:
addrint or str

Interface address, hostname, IP-address, PXI-slot or other address required by interface

interfaceInterface

GPIB, USBSerial, TCPIP, PXIe, Generic.

backendstr

Backend could be path to a DLL, custom interface item or for PyVisa backend is either @ivi’ (or @ni’) for NI-Library or @py’ for pure python pyvisa-py backend. On default it uses @ivi’ (or @ni’) on win32 and @py’ on other platforms.

hostnamestr

Optional interface hostname or IP-address required by interface, when not addr, for TCPIP network instruments

portint

Optional interface port number, for TCPIP network instruments

instNamestr

Instrument object name passed as string for later reference in messages to user

debugbool

Debug information

Example: Initialization of a derived class
>>> vdd = DerivedInstrument (addr=24)  # GPIB or USB address
>>> vdd.init()                         # connect and initialize instrument if this method provided, otherwise implicitly
init()[source]

Connect and initialize instrument if this method overidden, otherwise implicitly initialize instrument when this method not locally implemented

setup_inst()[source]

Post init method to override with specific instrument interface initialisation

reset()[source]

Abstract reset

identify()[source]

Instrument message, reflect address & interface - if message() implemented

message("")[source]

Abstract instrument message (“string”) or ()

close()[source]

Terminate interface

inst.write('*RST')

Write directly to instrument, using underlying instruments command language

ask=inst.query('

READ?’) Write and read the answer, using underlying instruments command language

Properties:
id

Abstract get IDN string

Objects:
collation

A collate_instrument.CollateInstrument singleton cataloging instruments connected

budget

A TimeoutBudget singleton to accumulate timeout across all instrument transactions

com

An instrument resource to generate interface instances, a singleton of LocalInstrument, PXIeInstrument, NetworkInstrument or GenericInstrument

inst

An instance of instrument interface once a connection session to instrument is successful, i.e. a visa object with write(),read(),query() API

__init__(**kwargs)[source]

Methods

__init__(**kwargs)

close([force])

Close connection to instrument.

find_names()

find_names() returns list of identifiers strings, lhs of = assignments

help()

Print the docstring of the instrument class.

identify([showInstName])

Identify message.

init([identify])

Optional init for interlock startup after identification.

message([message])

Message display.

mqtt_add(client, instrument[, liste, qos])

Add the instrument to mqtt.

mqtt_disconnect()

Remove the instrument from mqtt.

publish(topic, value)

Publish topic as type='cmd' with payload=value.

publish_get(function_name, value)

Publish function_name as type='get' with paylad=value.

publish_set(function_name, value)

Publish function_name as type='set' with paylad=value.

reset()

Reset and switch beep off.

setup_inst()

Setup the instrument settings.

Attributes

command

id

Query IDN.

interchoices

Abstract for static class variable interchoices, to list interfaces statically.

mqtt_enable

mqtt_list

mqtt_status

Getter for the mqtt_status.

close(force=False)[source]

Close connection to instrument.

find_names()

find_names() returns list of identifiers strings, lhs of = assignments

Returns:

obj_names – List of identifier strings

Return type:

list of str

help()[source]

Print the docstring of the instrument class.

abstract property id

Query IDN.

identify(showInstName=False)[source]

Identify message.

init(identify=False)[source]

Optional init for interlock startup after identification.

abstract property interchoices

Abstract for static class variable interchoices, to list interfaces statically.

json = <module 'json' from '/home/runner/miniconda3/envs/test/lib/python3.9/json/__init__.py'>
abstract message(message=None)[source]

Message display.

mqtt_add(client, instrument, liste='#', qos=0)

Add the instrument to mqtt. Calling from base_instrument, after the instrument (device) has been create. Normally you have not to use this function, only base_instrument use it.

Parameters:
  • client (mqtt_init) – The MQTT client instance to which the instrument should be added.

  • instrument (object) – The instrument to be added to the MQTT client.

  • liste (list or str) – A list of attributes for which MQTT messages should be sent. If set to “#”, all attributes will be included (default: “#”).

  • qos (int) – The Quality of Service level for MQTT messages (default: 0).

Return type:

None

mqtt_disconnect()

Remove the instrument from mqtt. Calling from base_instrument, if the instrument are closing. Normally you have not to use this function, only base_instrument use it.

property mqtt_status

Getter for the mqtt_status.

publish(topic, value)

Publish topic as type=’cmd’ with payload=value.

Parameters:
  • topic (str) – The name of the topic to publish.

  • value (any) – The value to be published.

Return type:

None

publish_get(function_name, value)

Publish function_name as type=’get’ with paylad=value.

Parameters:
  • function_name (str) – The name of the function to be published as a ‘get’ command.

  • value (any) – The value to be published as the payload of the ‘get’ command.

Return type:

None

publish_set(function_name, value)

Publish function_name as type=’set’ with paylad=value.

Parameters:
  • function_name (str) – The name of the function to be published as a ‘set’ command.

  • value (any) – The value to be published as the payload of the ‘set’ command.

Return type:

None

abstract reset()[source]

Reset and switch beep off.

setup_inst()[source]

Setup the instrument settings.