Source code for device.langmuir_probe
from types import SimpleNamespace
from . import base
import time
[docs]
class LangmuirProbe(base.ArduinoProbeBase):
"""Arduino controller that handles a Langmuir probe (Langmuir probes).
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__(bus=bus, start_msg="START lagmuir ventil", **kwargs)
self._last = SimpleNamespace(
valve_open=False,
needle_percent=0.0,
)
# ==== Commands ====
[docs]
def is_valve_open(self):
"""Status of the valve."""
return self._last.valve_open
[docs]
@base.base_command
def set_needle(self, percent):
"""Change the state of the needle valve.
:param float precent: Percentage in range 0-100, where 0 is closed.
"""
percent = max(0.0, min(100.0, float(percent)))
self._write(f"p{int(percent*255/100)}\n")
self._last.needle_percent = percent
self._last.valve_open = (percent != 0)
return self._last.needle_percent
[docs]
@base.compound_command
def set_needle_for(self, percent, duration):
"""Open needle valve for a limited duration ("gas puff").
:param float percent: Percentage in range 0-100, where 0 is closed.
:param float duration: Time in seconds.
"""
self.set_needle(percent)
time.sleep(max(0, float(duration)))
self.set_needle(0)
[docs]
@base.base_command
def open_valve(self):
"""Open the valve."""
if not self._last.valve_open:
self._write("p100\n")
self._last.valve_open = True
[docs]
@base.base_command
def close_valve(self):
"""Close the valve."""
if self._last.valve_open:
self._write("p0\n")
self._last.valve_open = False