From bd69bcb779d3545900b6baaf2431cda8a7058426 Mon Sep 17 00:00:00 2001 From: Avichal Kaul <60527565+avichalk@users.noreply.github.com> Date: Tue, 2 Apr 2024 08:00:23 -0700 Subject: [PATCH] Totalizer Batch Volume functionality (#113) Add functions to get and set the totalizer batch volume on controllers. --------- Co-authored-by: Alex Ruddick --- alicat/driver.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/alicat/driver.py b/alicat/driver.py index b181ccc..8d7ac13 100644 --- a/alicat/driver.py +++ b/alicat/driver.py @@ -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.