pytec: Add hardware testing script

Eases the process of testing the hardware.

See #143.
This commit is contained in:
atse 2024-11-11 16:54:06 +08:00
parent 52e35d2a98
commit 53c2f804d0
1 changed files with 79 additions and 0 deletions

79
pytec/test.py Normal file
View File

@ -0,0 +1,79 @@
import argparse
from contextlib import contextmanager
from pytec.client import Client
CHANNELS = 2
def get_argparser():
parser = argparse.ArgumentParser(description="Sinara 8451 Thermostat hardware testing script")
parser.add_argument("HOST", metavar="host", default="192.168.1.26", nargs="?")
parser.add_argument("PORT", metavar="port", default=23, nargs="?")
parser.add_argument(
"-r",
"--testing_resistance",
default=10_000,
help="Testing resistance value through SENS pin in Ohms",
)
parser.add_argument(
"-d",
"--deviation",
default=100,
help="Allowed deviation of resistance in Ohms",
)
return parser
def main():
args = get_argparser().parse_args()
min_allowed_resistance = args.testing_resistance - args.deviation
max_allowed_resistance = args.testing_resistance + args.deviation
thermostat = Client(args.HOST, args.PORT)
for channel in range(CHANNELS):
print(f"Channel {channel} is active")
print("Checking resistance through SENS pins ....", end=" ")
sens_resistance = thermostat.get_report()[channel]["sens"]
if sens_resistance is not None:
print(sens_resistance, "Ω")
if min_allowed_resistance < sens_resistance < max_allowed_resistance:
print("PASSED")
else:
print("FAILED")
else:
print("Floating SENS pin(s) detected! Is the channel connected?")
with preserve_thermostat_output_settings(thermostat, channel):
test_output_settings = {
"max_i_pos": 2,
"max_i_neg": 2,
"max_v": 4,
"i_set": 0.1,
"polarity": "normal",
}
for field, value in test_output_settings.items():
thermostat.set_param("output", channel, field, value)
input(f"Check if the channel {channel} current output = 0.1 A, and press ENTER...")
input(f"Channel {channel} testing done, press ENTER to continue.")
print()
print("Testing complete.")
@contextmanager
def preserve_thermostat_output_settings(client, channel):
original_output_settings = client.get_output()[channel]
yield original_output_settings
for setting in "max_i_pos", "max_i_neg", "max_v", "i_set", "polarity":
client.set_param("output", channel, setting, original_output_settings[setting])
if __name__ == "__main__":
main()