from device_client import DeviceClient
from device.valve_board import ValveBoard
description = """
Valve Board controls standard open/closed valves and regulated needle valves,
make sure to check the board schematic for details. There is a logic in place
that should prevent most of the unsafe valve combinations, but be careful.
If a valve combination was reject, an errors appears in the message log.
Note that presently there is no feedback showing which valves are open and
they need to be tracked manually. When in doubt, start with **Close all**.
#### Open valve + Close valve
Open or close a single valve. Any valves that were open are kept open.
- *name* = name of the valve as specified on the board schematic.
There is a small exception related to the gas 0 and 1 valves, which share a
common feed. Use **Switch gas 0/1** command to specify, which of them is used.
#### Open path + Close path
Instead of opening valves one by one, a set of valves can be opened at once.
Use **Close path** before opening a new one.
- *path* = valve names as in **Open valve** separated by comma, for example:
```
gas2_bus3, bus3_chamber
```
#### Needle puff
Open a needle valve for a fixed time to send a gas puff.
- *which* = needle valve number, corresponds to chamber number.
- *percent* = how much to open the valve, numbers in range 0-100.
- *duration* = time in seconds.
"""
[docs]
def connect(name, password, server):
client = DeviceClient(name, password,
title="Valve Board", description=description)
hw = ValveBoard(log_callback=client.emit_log, testrun=False)
# client.register_command(hw.stop, "Stop") # Nothing to stop in case of ValveBoard
valves = [v for v in hw.valves if "switch" not in v]
valve_param = {"type": "select", "options": valves, "search": True}
client.register_command(hw.open_valve,"Open valve", group="Valves", inputs=[valve_param])
client.register_command(hw.close_valve, "Close valve", group="Valves", inputs=[valve_param])
client.register_command(hw.open_path, "Open path", group="Valves", inputs=[{"type": "textArea"}])
client.register_command(hw.switch_gas01, "Switch gas 0/1",
inputs=[{"type": "select", "options": ["0", "1"]}])
client.register_command(hw.set_needle, "Set needle", inputs=[
{"type": "select", "options": hw.needles},
{"type": "text", "unit": "%"},
])
client.register_command(hw.set_needle_for, "Needle puff", inputs=[
{"type": "select", "options": hw.needles},
{"type": "select", "options": [25, 50, 60, 70, 80, 90, 100], "unit": "%"},
{"type": "select", "options": [0.1, 0.2, 0.5, 1.0, 2.0], "unit": "s"},
])
client.register_command(hw.close_all, "Close all")
client.register_command(hw.close_path, "Close path")
client.register_background_task(hw.update_frontend)
client.keep_server_updated(
check_readiness=hw.is_ready,
check_readiness_interval=1,
server_address=server,
retry_on_error=True
)