Skip to content

Commit

Permalink
Fix call to read_input_registers
Browse files Browse the repository at this point in the history
  • Loading branch information
albireox committed Dec 21, 2024
1 parent 8438d4e commit 82033d5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
10 changes: 6 additions & 4 deletions src/lvmopstools/devices/ion.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import asyncio
import warnings

from typing import TypedDict
from typing import TypedDict, cast

from drift import Drift
from drift.convert import data_to_float32
Expand Down Expand Up @@ -61,10 +61,12 @@ async def _read_one_ion_controller(ion_config: dict) -> dict[str, IonPumpDict]:
signal_address = camera_config["signal_address"]
# on_off_address = camera_config["on_off_address"]

signal = await drift.client.read_input_registers(signal_address, 2)
# onoff = await drift.client.read_input_registers(on_off_address, 1)
signal = await drift.client.read_input_registers(signal_address, count=2)
# onoff = await drift.client.read_input_registers(on_off_address, count=1)

diff_volt = data_to_float32(tuple(signal.registers))
registers = cast(tuple[int, int], tuple(signal.registers))

diff_volt = data_to_float32(registers)
pressure = convert_pressure(diff_volt)

# onoff_status = bool(onoff.registers[0])
Expand Down
9 changes: 6 additions & 3 deletions tests/test_devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,16 @@ async def test_toggle_ion_pump(ion_pump_server):
on_off_address = b2_config["on_off_address"]

async with drift:
register_z2 = await drift.client.read_holding_registers(on_off_address, 1)
register_z2 = await drift.client.read_holding_registers(
on_off_address,
count=1,
)
assert register_z2.registers[0] == 0

await toggle_ion_pump("b2", True)

async with drift:
register_z2 = await drift.client.read_holding_registers(0, 50)
register_z2 = await drift.client.read_holding_registers(0, count=50)
assert sum([reg > 0 for reg in register_z2.registers]) == 1


Expand All @@ -106,5 +109,5 @@ async def test_toggle_ion_pump_all(ion_pump_server):
await toggle_ion_pump(ALL, True)

async with drift:
register_z2 = await drift.client.read_holding_registers(0, 50)
register_z2 = await drift.client.read_holding_registers(0, count=50)
assert sum([reg > 0 for reg in register_z2.registers]) == 3

0 comments on commit 82033d5

Please sign in to comment.