Commit 6b9f1b19 authored by Henrik Menne's avatar Henrik Menne
Browse files

AInRange as Enum

parent eb719d42
Pipeline #53058 failed with stages
in 3 minutes and 47 seconds
......@@ -118,6 +118,12 @@ class LabJack(SingleCommDevice):
return float(self.com.read_name(f"SBUS{number}_RH"))
class AInRange(Enum):
TEN = 10
ONE = 1
ONE_TENTH = 0.1
ONE_HUNDREDTH = 0.01
def get_ain(self, *channels: int) -> float:
"""
Read currently measured value (voltage, resistance, ...) from one or more
......@@ -135,25 +141,17 @@ class LabJack(SingleCommDevice):
return tuple(float(val) for val in ret_val)
return float(ret_val)
def set_ain_range(self, channel: int, ain_range: float) -> None:
r"""
def set_ain_range(self, channel: int, ain_range: AInRange) -> None:
"""
Set the range of an analog input port.
Possible values for ``ain_range`` are:
* 10 => +- 10 V
* 1 => +- 1 V
* 0.1 => +- 0.1 V
* 0.01 => +- 0.01 V
:param channel: is the AIN number (0..254)
:param ain_range: is the range specifier
"""
if not isinstance(ain_range, self.AInRange):
raise LabJackError(f"Not supported type: {ain_range}")
if ain_range not in (10, 1, 0.1, 0.01):
raise LabJackError(f"Not supported range: {ain_range}")
self.com.write_name(f"AIN{channel}_RANGE", ain_range)
self.com.write_name(f"AIN{channel}_RANGE", ain_range.value)
def set_ain_resolution(self, channel: int, resolution: int) -> None:
"""
......@@ -240,7 +238,7 @@ class LabJack(SingleCommDevice):
thermocouple: Union[None, str, ThermocoupleType],
cjc_address: int = 60050,
cjc_type: Union[str, CjcType] = CjcType.internal,
vrange: float = 0.01,
vrange: AInRange = AInRange.ONE_HUNDREDTH,
resolution: int = 10,
unit: Union[str, TemperatureUnit] = TemperatureUnit.K,
) -> None:
......@@ -253,7 +251,7 @@ class LabJack(SingleCommDevice):
the thermocouple type
:param cjc_address: modbus register address to read the CJC temperature
:param cjc_type: determines cjc slope and offset, 'internal' or 'lm34'
:param vrange: measurement voltage range (10, 1, 0.1, 0.01)
:param vrange: measurement voltage range
:param resolution: resolution index (T7-Pro: 0-12)
:param unit: is the temperature unit to be returned ('K', 'C' or 'F')
:raises LabJackError: if parameters are unsupported
......@@ -417,13 +415,13 @@ class LabJack(SingleCommDevice):
"""
return self.get_product_type(force_query_id=force_query_id).name
def set_ain_resistance(self, channel: int, vrange: float, resolution: int) -> None:
def set_ain_resistance(self, channel: int, vrange: AInRange, resolution: int) -> None:
"""
Set the specified channel to resistance mode. It utilized the 200uA current
source of the LabJack.
:param channel: channel that should measure the resistance
:param vrange: voltage range of the channel (10, 1, 0.1, 0.01)
:param vrange: voltage range of the channel
:param resolution: resolution index of the channel T4: 0-5, T7: 0-8, T7-Pro 0-12
"""
self.set_ain_range(channel, vrange)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment