Skip to content

Commit a5d9760

Browse files
committed
feat: add function to check library version
1 parent d0bbc51 commit a5d9760

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

absscpi/client.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
LOCAL_MODEL_INPUT_COUNT = 8
2121
MODEL_OUTPUT_COUNT = 36
2222

23+
def libver_to_str(libver: int) -> str:
24+
return f"{libver // 10000}.{(libver % 10000) // 100}.{libver % 100}"
25+
2326
class AbsCellFault(IntEnum):
2427
"""ABS cell faulting mode."""
2528
NONE = 0
@@ -219,6 +222,29 @@ def __check_err(self, err: int):
219222
if err < 0:
220223
raise ScpiClientError(self.__err_msg(err))
221224

225+
def __ensure_ver(self, req_maj: int, req_min: int, req_patch: int):
226+
"""Ensure that the low-level library's version is high enough to support
227+
a command.
228+
229+
Args:
230+
req_maj: The required major library version. For example, if v1.2.3
231+
is required, this value should be 1.
232+
req_min: The required minimum library version. For example, if
233+
v1.2.3 is required, this value should be 2.
234+
req_patch: The required patch library version. For example, if
235+
v1.2.3 is required, this value should be 3.
236+
237+
Raises:
238+
ScpiClientError: The required version is not met.
239+
"""
240+
required_ver = req_maj * 10000 + req_min * 100 + req_patch
241+
if self.__lib_version < required_ver:
242+
req_str = libver_to_str(required_ver)
243+
found_str = libver_to_str(self.__lib_version)
244+
raise ScpiClientError("SCPI library is too old! " +
245+
f"Required version {req_str}, " +
246+
f"found version {found_str}.")
247+
222248
def init(self):
223249
"""Initialize the client handle.
224250
@@ -1059,6 +1085,7 @@ def measure_average_cell_voltage(self, cell: int) -> float:
10591085
Raises:
10601086
ScpiClientError: An error occurred while executing the query.
10611087
"""
1088+
self.__ensure_ver(1,1,0)
10621089
voltage = c_float()
10631090
res = self.__dll.AbsScpiClient_MeasureAverageCellVoltage(
10641091
self.__handle, c_uint(cell), byref(voltage))
@@ -1078,6 +1105,7 @@ def measure_all_average_cell_voltages(self) -> list[float]:
10781105
Raises:
10791106
ScpiClientError: An error occurred while executing the query.
10801107
"""
1108+
self.__ensure_ver(1,1,0)
10811109
voltages = (c_float * CELL_COUNT)()
10821110
res = self.__dll.AbsScpiClient_MeasureAllAverageCellVoltages(
10831111
self.__handle, byref(voltages), c_uint(CELL_COUNT))
@@ -1100,6 +1128,7 @@ def measure_average_cell_current(self, cell: int) -> float:
11001128
Raises:
11011129
ScpiClientError: An error occurred while executing the query.
11021130
"""
1131+
self.__ensure_ver(1,1,0)
11031132
current = c_float()
11041133
res = self.__dll.AbsScpiClient_MeasureAverageCellCurrent(
11051134
self.__handle, c_uint(cell), byref(current))
@@ -1119,6 +1148,7 @@ def measure_all_average_cell_currents(self) -> list[float]:
11191148
Raises:
11201149
ScpiClientError: An error occurred while executing the query.
11211150
"""
1151+
self.__ensure_ver(1,1,0)
11221152
currents = (c_float * CELL_COUNT)()
11231153
res = self.__dll.AbsScpiClient_MeasureAllAverageCellCurrents(
11241154
self.__handle, byref(currents), c_uint(CELL_COUNT))

0 commit comments

Comments
 (0)