2024-12-07 07:01:52 +01:00
|
|
|
import librtd, os
|
|
|
|
|
|
|
|
|
|
|
|
stacks = [int(h) for h in os.getenv("MODULE_RTD8_LEVELS", "")]
|
|
|
|
if not stacks:
|
|
|
|
print("MODULE_RTD8_LEVELS is not set or invalid")
|
|
|
|
|
2024-12-07 12:00:06 +01:00
|
|
|
for i in stacks:
|
|
|
|
print(f"Configured RTD8 card: {i}")
|
|
|
|
|
2024-12-07 07:01:52 +01:00
|
|
|
|
|
|
|
|
2024-12-10 16:54:43 +01:00
|
|
|
def read_temp(stack: int, channel: int) -> float:
|
2024-12-07 07:01:52 +01:00
|
|
|
"""
|
|
|
|
Read specified channel in Celsius
|
|
|
|
"""
|
|
|
|
if stack in stacks and 1 <= channel <= 8:
|
|
|
|
try:
|
|
|
|
return librtd.get(stack, channel)
|
|
|
|
except Exception as e:
|
2024-12-07 12:00:06 +01:00
|
|
|
return -512
|
2024-12-07 07:01:52 +01:00
|
|
|
|
|
|
|
return -512
|
|
|
|
|
2024-12-10 16:54:43 +01:00
|
|
|
def read_temp_stack(stack: int) -> dict[int, float]:
|
2024-12-07 07:01:52 +01:00
|
|
|
"""
|
|
|
|
Read all inputs data in Celsius
|
|
|
|
"""
|
|
|
|
return {ch: read_temp(stack=stack, channel=ch) for ch in range(1, 9)}
|
|
|
|
|
2024-12-10 16:54:43 +01:00
|
|
|
def read_temp_all() -> dict[int, dict[int, float]]:
|
2024-12-07 07:01:52 +01:00
|
|
|
"""
|
|
|
|
Read all RTD8 cards inputs in Celsius
|
|
|
|
"""
|
2024-12-09 08:27:10 +01:00
|
|
|
return {stack: read_temp_stack(stack=stack) for stack in stacks}
|
2024-12-07 07:01:52 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
2024-12-10 16:54:43 +01:00
|
|
|
def read_resistance(stack: int, channel: int) -> float:
|
2024-12-07 07:01:52 +01:00
|
|
|
"""
|
|
|
|
Read specified channel in Ohm
|
|
|
|
"""
|
|
|
|
if stack in stacks and 1 <= channel <= 8:
|
|
|
|
try:
|
|
|
|
return librtd.getRes(stack, channel)
|
|
|
|
except Exception as e:
|
2024-12-07 12:00:06 +01:00
|
|
|
return -512
|
2024-12-07 07:01:52 +01:00
|
|
|
|
|
|
|
return -512
|
|
|
|
|
2024-12-10 16:54:43 +01:00
|
|
|
def read_resistance_stack(stack: int) -> dict[int, float]:
|
2024-12-07 07:01:52 +01:00
|
|
|
"""
|
|
|
|
Read all inputs data in Ohm
|
|
|
|
"""
|
|
|
|
return {ch: read_resistance(stack=stack, channel=ch) for ch in range(1, 9)}
|
|
|
|
|
2024-12-10 16:54:43 +01:00
|
|
|
def read_resistance_all() -> dict[int, dict[int, float]]:
|
2024-12-07 07:01:52 +01:00
|
|
|
"""
|
|
|
|
Read all RTD8 cards inputs in Ohm
|
|
|
|
"""
|
|
|
|
return {stack: read_resistance_stack(stack=stack) for stack in stacks}
|