SequentMicrosystems_API/src/modules/RTD8/service.py

61 lines
No EOL
1.5 KiB
Python

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")
for i in stacks:
print(f"Configured RTD8 card: {i}")
def read_temp(stack: int, channel: int) -> float:
"""
Read specified channel in Celsius
"""
if stack in stacks and 1 <= channel <= 8:
try:
return librtd.get(stack, channel)
except Exception as e:
return -512
return -512
def read_temp_stack(stack: int) -> dict[int, float]:
"""
Read all inputs data in Celsius
"""
return {ch: read_temp(stack=stack, channel=ch) for ch in range(1, 9)}
def read_temp_all() -> dict[int, dict[int, float]]:
"""
Read all RTD8 cards inputs in Celsius
"""
return {stack: read_temp_stack(stack=stack) for stack in stacks}
def read_resistance(stack: int, channel: int) -> float:
"""
Read specified channel in Ohm
"""
if stack in stacks and 1 <= channel <= 8:
try:
return librtd.getRes(stack, channel)
except Exception as e:
return -512
return -512
def read_resistance_stack(stack: int) -> dict[int, float]:
"""
Read all inputs data in Ohm
"""
return {ch: read_resistance(stack=stack, channel=ch) for ch in range(1, 9)}
def read_resistance_all() -> dict[int, dict[int, float]]:
"""
Read all RTD8 cards inputs in Ohm
"""
return {stack: read_resistance_stack(stack=stack) for stack in stacks}