|
20 | 20 | LOCAL_MODEL_INPUT_COUNT = 8 |
21 | 21 | MODEL_OUTPUT_COUNT = 36 |
22 | 22 |
|
| 23 | +def libver_to_str(libver: int) -> str: |
| 24 | + return f"{libver // 10000}.{(libver % 10000) // 100}.{libver % 100}" |
| 25 | + |
23 | 26 | class AbsCellFault(IntEnum): |
24 | 27 | """ABS cell faulting mode.""" |
25 | 28 | NONE = 0 |
@@ -219,6 +222,29 @@ def __check_err(self, err: int): |
219 | 222 | if err < 0: |
220 | 223 | raise ScpiClientError(self.__err_msg(err)) |
221 | 224 |
|
| 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 | + |
222 | 248 | def init(self): |
223 | 249 | """Initialize the client handle. |
224 | 250 |
|
@@ -1043,6 +1069,116 @@ def measure_all_cell_currents(self) -> list[float]: |
1043 | 1069 | self.__check_err(res) |
1044 | 1070 | return currents[:] |
1045 | 1071 |
|
| 1072 | + def measure_average_cell_voltage(self, cell: int) -> float: |
| 1073 | + """Retrieve the rolling average of the last 10 voltage measurements for |
| 1074 | + a single cell. |
| 1075 | +
|
| 1076 | + At the default sample rate, this is a 10ms window. With filtering on, |
| 1077 | + the length of this window will change. |
| 1078 | +
|
| 1079 | + .. note:: |
| 1080 | +
|
| 1081 | + This function requires ABS firmware version 1.2.0 or newer. |
| 1082 | +
|
| 1083 | + Args: |
| 1084 | + cell: Target cell index, 0-7. |
| 1085 | +
|
| 1086 | + Returns: |
| 1087 | + Average measured cell voltage. |
| 1088 | +
|
| 1089 | + Raises: |
| 1090 | + ScpiClientError: An error occurred while executing the query. |
| 1091 | +
|
| 1092 | + .. versionadded:: 1.1.0 |
| 1093 | + """ |
| 1094 | + self.__ensure_ver(1,1,0) |
| 1095 | + voltage = c_float() |
| 1096 | + res = self.__dll.AbsScpiClient_MeasureAverageCellVoltage( |
| 1097 | + self.__handle, c_uint(cell), byref(voltage)) |
| 1098 | + self.__check_err(res) |
| 1099 | + return voltage.value |
| 1100 | + |
| 1101 | + def measure_all_average_cell_voltages(self) -> list[float]: |
| 1102 | + """Retrieve the rolling average of the last 10 voltage measurements for |
| 1103 | + all cells. |
| 1104 | +
|
| 1105 | + At the default sample rate, this is a 10ms window. With filtering on, |
| 1106 | + the length of this window will change. |
| 1107 | +
|
| 1108 | + .. note:: |
| 1109 | +
|
| 1110 | + This function requires ABS firmware version 1.2.0 or newer. |
| 1111 | +
|
| 1112 | + Returns: |
| 1113 | + Array of average voltages, one per cell. |
| 1114 | +
|
| 1115 | + Raises: |
| 1116 | + ScpiClientError: An error occurred while executing the query. |
| 1117 | +
|
| 1118 | + .. versionadded:: 1.1.0 |
| 1119 | + """ |
| 1120 | + self.__ensure_ver(1,1,0) |
| 1121 | + voltages = (c_float * CELL_COUNT)() |
| 1122 | + res = self.__dll.AbsScpiClient_MeasureAllAverageCellVoltages( |
| 1123 | + self.__handle, byref(voltages), c_uint(CELL_COUNT)) |
| 1124 | + self.__check_err(res) |
| 1125 | + return voltages[:] |
| 1126 | + |
| 1127 | + def measure_average_cell_current(self, cell: int) -> float: |
| 1128 | + """Retrieve the rolling average of the last 10 current measurements for |
| 1129 | + a single cell. |
| 1130 | +
|
| 1131 | + At the default sample rate, this is a 10ms window. With filtering on, |
| 1132 | + the length of this window will change. |
| 1133 | +
|
| 1134 | + .. note:: |
| 1135 | +
|
| 1136 | + This function requires ABS firmware version 1.2.0 or newer. |
| 1137 | +
|
| 1138 | + Args: |
| 1139 | + cell: Target cell index, 0-7. |
| 1140 | +
|
| 1141 | + Returns: |
| 1142 | + Average measured cell current. |
| 1143 | +
|
| 1144 | + Raises: |
| 1145 | + ScpiClientError: An error occurred while executing the query. |
| 1146 | +
|
| 1147 | + .. versionadded:: 1.1.0 |
| 1148 | + """ |
| 1149 | + self.__ensure_ver(1,1,0) |
| 1150 | + current = c_float() |
| 1151 | + res = self.__dll.AbsScpiClient_MeasureAverageCellCurrent( |
| 1152 | + self.__handle, c_uint(cell), byref(current)) |
| 1153 | + self.__check_err(res) |
| 1154 | + return current.value |
| 1155 | + |
| 1156 | + def measure_all_average_cell_currents(self) -> list[float]: |
| 1157 | + """Retrieve the rolling average of the last 10 current measurements for |
| 1158 | + all cells. |
| 1159 | +
|
| 1160 | + At the default sample rate, this is a 10ms window. With filtering on, |
| 1161 | + the length of this window will change. |
| 1162 | +
|
| 1163 | + .. note:: |
| 1164 | +
|
| 1165 | + This function requires ABS firmware version 1.2.0 or newer. |
| 1166 | +
|
| 1167 | + Returns: |
| 1168 | + Array of average currents, one per cell. |
| 1169 | +
|
| 1170 | + Raises: |
| 1171 | + ScpiClientError: An error occurred while executing the query. |
| 1172 | +
|
| 1173 | + .. versionadded:: 1.1.0 |
| 1174 | + """ |
| 1175 | + self.__ensure_ver(1,1,0) |
| 1176 | + currents = (c_float * CELL_COUNT)() |
| 1177 | + res = self.__dll.AbsScpiClient_MeasureAllAverageCellCurrents( |
| 1178 | + self.__handle, byref(currents), c_uint(CELL_COUNT)) |
| 1179 | + self.__check_err(res) |
| 1180 | + return currents[:] |
| 1181 | + |
1046 | 1182 | def get_cell_operating_mode(self, cell: int) -> AbsCellMode: |
1047 | 1183 | """Query a single cell's operating mode (constant voltage or current |
1048 | 1184 | limited). |
|
0 commit comments