Source code for device.power_supply_langmuir

from types import SimpleNamespace

from . import base


[docs] class PowerSupply_Langmuir(base.ArduinoBase): """Arduino controller that handles a power supply that generates plasma in the Langmuir probes experiment. Communication: - serial interface to Arduino """ def __init__(self, bus, **kwargs): """Constructor :param str bus: Name of serial bus where Arduino is connected, e.g. '/dev/ttyUSB0' """ super().__init__( serial_cfg=base.SerialConfig(bus, 9600, "START lagmuir VN zdroj"), **kwargs, ) self._last = SimpleNamespace( switched_on=False, voltage=0, current=0, current_limit=0, ) # ==== Commands ====
[docs] @base.base_command def switch_on(self): self._write("0") # Arduino does not give any response self._last.switched_on = True
[docs] @base.base_command def switch_off(self): self._write("0") # Arduino does not give any response self._last.switched_on = False
[docs] @base.base_command def is_switched_on(self): return self._last.switched_on
[docs] @base.base_command def voltage(self): """Return output voltage [V].""" self._write("u") self._last.voltage = float(self._readline()) return self._last.voltage
[docs] @base.base_command def current(self): """Return output current [mA].""" self._write("i") self._last.current = float(self._readline()) return self._last.current
[docs] @base.base_command def increment_max_current(self): """Increment max current by 1 step. Returns the value in %.""" self._write("+") # Arduino responds with arbitrary 0-31 value self._last.current_limit = float(self._readline()) / 31 * 100 return self._last.current_limit
[docs] @base.base_command def decrement_max_current(self): """Decrement max current by 1 step. Returns the value in %.""" self._write("-") # Arduino responds with arbitrary 0-31 value self._last.current_limit = float(self._readline()) / 31 * 100 return self._last.current_limit
# ==== Methods/commands related to DeviceClient ==== @base.idle_command def _idle_update_all(self): # Call to each of these methods updates self._last self.voltage() self.current()
[docs] def update_frontend(self, device_client): self._idle_update_all() for var, unit, max_ in zip( ["voltage", "current", "current_limit"], ["V", "mA", "%"], [900, 50, 100], ): value = getattr(self._last, var) device_client.emit("value", { "value": value, "formatted": "{:.0f} {}".format(value, unit), "label": var.capitalize().replace("_", " "), "min": 0, "max": max_, "id": var, })