Skip to content

Commit

Permalink
Totalizer Batch Volume functionality (#113)
Browse files Browse the repository at this point in the history
Add functions to get and set the totalizer batch volume on controllers.

---------

Co-authored-by: Alex Ruddick <[email protected]>
  • Loading branch information
avichalk and alexrudd2 authored Apr 2, 2024
1 parent 23865c6 commit bd69bcb
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions alicat/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,51 @@ async def set_pressure(self, pressure: float) -> None:
await self._set_control_point('abs pressure')
await self._set_setpoint(pressure)

async def get_totalizer_batch(self, batch: int = 1) -> str:
"""Get the totalizer batch volume.
Args:
batch: Which of the two totalizer batches to query.
Default is 1; some devices have 2
Returns:
line: Current value of totalizer batch
"""
command = f'{self.unit}$$TB {batch}'
line = await self._write_and_read(command)

if line == '?':
raise OSError("Unable to read totalizer batch volume.")
else:
values = line.split(" ") # type: ignore[union-attr]
return f'{values[2]} {values[4]}' # returns 'batch vol' 'units'

async def set_totalizer_batch(self, batch_volume: float, batch: int = 1, units: str = 'default') -> None:
"""Set the totalizer batch volume.
Args:
batch: Which of the two totalizer batches to set.
Default is 1; some devices have 2
batch_volume: Target batch volume, in same units as units
on device
units: Units of the volume being provided. Default
is 0, so device returns default engineering units.
"""
engineering_units_table = {"default":0, "SμL":2, "SmL":3, "SL":4, \
"Scm3":6, "Sm3":7, "Sin3":8, "Sft3":9, "kSft3":10, "NμL":32, \
"NmL":33, "NL":34, "Ncm3":36, "Nm3":37}

if units in engineering_units_table:
units_no = engineering_units_table[units]
else:
raise ValueError("Units not in unit list. Please consult Appendix B-3 of the Alicat Serial Primer.")

command = f'{self.unit}$$TB {batch} {batch_volume} {units_no}'
line = await self._write_and_read(command)

if line == '?':
raise OSError("Unable to set totalizer batch volume. Check if volume is out of range for device.")

async def hold(self) -> None:
"""Override command to issue a valve hold.
Expand Down

0 comments on commit bd69bcb

Please sign in to comment.