device_client package

This package implements a socketio client that can be used to connect to the server as a device. Devices register their command interface, execute commands when requested by frontend and emit data to frontend.

Submodules

device_client.client_camera module

device_client.client_camera.connect(name, password, server, device)[source]

device_client.client_interfer_motors module

device_client.client_interfer_motors.connect(name, password, server)[source]

device_client.client_interfer_oscope module

device_client.client_interfer_oscope.connect(name, password, server)[source]

device_client.client_langmuir_gauge module

device_client.client_langmuir_gauge.connect(name, password, server)[source]

device_client.client_langmuir_hotprobe module

device_client.client_langmuir_hotprobe.connect(name, password, server)[source]

device_client.client_langmuir_motors module

device_client.client_langmuir_motors.connect(name, password, server, serial1, serial2, serial3, serial4)[source]

device_client.client_langmuir_probe module

device_client.client_langmuir_probe.connect(name, password, server, serial)[source]
device_client.client_langmuir_probe.description = '\nMeasure the I-V characteristic of a Langmuir probe using the *Sweep I-V*\ncommand.\n\n#### Sweep I-V\nStart the probe measurement. The probe voltage is swept with an approximation\nof a triangle wave.\n\n- *frequency* = frequency of the triangle wave\n- *amplitude* = amplitude of the triangle wave in percentage of max (0-100%)\n\n#### Needle valve (0-100%)\nThis device also controls the valve between the recipient and the gas source\n(ValveBoard). Leaving it closed (0%) helps to achieve higher vacuum.\n'

#### Gas valve (off=closed) This device also controls the valve between the recipient and the gas source (ValveBoard). Leaving it closed helps to achieve higher vacuum.

device_client.client_langmuir_ps module

device_client.client_langmuir_ps.connect(name, password, server, serial)[source]

device_client.client_langmuir_sourcemeter module

device_client.client_langmuir_sourcemeter.connect(name, password, server, serial)[source]

device_client.client_magnets_motors module

device_client.client_magnets_motors.connect(name, password, server, serial_probe, serial_wire)[source]

device_client.client_magnets_probes module

device_client.client_magnets_probes.connect(name, password, server)[source]

device_client.client_magnets_psbig module

device_client.client_magnets_psbig.connect(name, password, server, serial)[source]

device_client.client_magnets_pssmall module

device_client.client_magnets_pssmall.connect(name, password, server, serial)[source]

device_client.client_magnets_psswitch module

device_client.client_magnets_psswitch.connect(name, password, server, serial)[source]

device_client.client_oscope_ds1074z module

device_client.client_oscope_ds1074z.connect(name, password, server)[source]

device_client.client_paschen_gauge module

device_client.client_paschen_gauge.connect(name, password, server)[source]

device_client.client_paschen_motor module

device_client.client_paschen_motor.connect(name, password, server)[source]

device_client.client_paschen_powersupply module

device_client.client_paschen_powersupply.connect(name, password, server)[source]

device_client.client_resonance_controller module

device_client.client_resonance_controller.connect(name, password, server)[source]

device_client.client_resonance_spectanalyser module

device_client.client_resonance_spectanalyser.connect(name, password, server)[source]

device_client.client_test module

device_client.client_test.connect(name, password, server)[source]

device_client.client_trap_cathode module

device_client.client_trap_cathode.connect(name, password, server, serial)[source]

device_client.client_trap_diagnostics module

device_client.client_trap_diagnostics.connect(name, password, server, serial, serial_switch)[source]

device_client.client_trap_hvsupply module

device_client.client_trap_hvsupply.connect(name, password, server, serial)[source]

device_client.client_trap_probe module

device_client.client_trap_probe.connect(name, password, server, serial)[source]

device_client.client_trap_pscoils module

device_client.client_trap_pscoils.connect(name, password, server, serial)[source]

device_client.client_valveboard module

device_client.client_valveboard.connect(name, password, server)[source]

device_client.device_client module

class device_client.device_client.DeviceClient(name, password, title='N/A', description='N/A', sio=None, logger='main')[source]

Bases: object

Device client handles the communication between device and a server.

property connected
disconnect_and_stop()[source]

Signalize the client to stop and exit. This will terminate the main loop in keep_server_updated() and any other related threads.

emit(entity, data)[source]

Emit data for a new entity or updated data for existing one.

Parameters:
  • entity (str) – events: ‘log’, ‘value’, ‘graph’, …

  • data (dict) – json-like object with data

emit_command_state(command, state)[source]

Update the default values of command parameters shown to the user. Also used to report a new state of a type=”toggle” command.

Parameters:
  • command (str) – id name of the command

  • state (list) – list of the new default arguments

emit_datafile(file, filename=None)[source]

Emit text file with measured data to server.

Parameters:
  • file (str) – absolute path to the text file or text file object as returned by open()

  • filename (str) – (optional) use this to specify a different filename that will be attached to the event

emit_log(record)[source]

Convenience method that accepts logging.LogRecord objects and emits them as a ‘log’ entity via DeviceClient.emit() method. Use this method to implement a custom logging.Handler. Info-event types are assigned according to logging levels with two exceptions:

  • ‘DEBUG’ => ignored

  • ‘INFO’ && text ends with ‘!’ => ‘success’

Parameters:

record – object of type logging.LogRecord

keep_server_updated(check_readiness, check_readiness_interval, server_address, retry_on_error=False, blocking=True)[source]

Connect to the server and periodically check if device is ready. Based on the ready check, device is registered or unregistered. When device is unregistered, it is not visible to frontend and all its data history is deleted.

This method exits when server disconnects the device. Alternatively, a KeyboardInterrupt (CTRL-C) can be issued to break the connection. Also exceptions from socketio may be raised on connection failure.

Parameters:
  • check_readiness (callable) – function with 0 parameters that returns True/False stating if device is ready

  • check_readiness_interval – time interval in seconds

  • server_address – eg. ‘localhost:5000’

  • retry_on_error – set True to ignore errors during connection attempts and automatically retry (only use when you know that the connection should work)

  • blocking – if False, method is run as non-bloking and exits as soon as the connection to server is established. The client keeps running in a background thread. Use method disconnect_and_stop() to terminate it.

on_connect(func)[source]
on_disconnect(func)[source]
register_background_task(func)[source]

Add a recurring task, time interval = check_readiness_interval. Task is only run when the device is ready.

Parameters:

func (callable) – the task, receives this object as its parameter

register_command(command, label=None, group=None, inputs=None, pass_self=False)[source]

Register a new command. The order of registration is conserved.

Parameters:
  • command (callable) – function with any number of parameters

  • label (str) – human readable name of the command

  • group (str) – human readable name of group (title of accordion panel)

  • inputs (list) – specify which input elements will be used for each of callable’s parameters, default: text input

  • bool (pass_self) – if True, the DeviceClient object will be passed as the first parameter to the callable

property registered