From 53c2f804d0be50956ac9f24b7e701402ee656d9c Mon Sep 17 00:00:00 2001 From: atse Date: Mon, 11 Nov 2024 16:54:06 +0800 Subject: [PATCH] pytec: Add hardware testing script Eases the process of testing the hardware. See #143. --- pytec/test.py | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 pytec/test.py diff --git a/pytec/test.py b/pytec/test.py new file mode 100644 index 0000000..6caf81c --- /dev/null +++ b/pytec/test.py @@ -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()