forked from M-Labs/thermostat
Compare commits
3 Commits
bc02819fca
...
adc25c9b2a
Author | SHA1 | Date | |
---|---|---|---|
adc25c9b2a | |||
9af86be674 | |||
eabc7f6a12 |
14
flake.nix
14
flake.nix
@ -57,10 +57,22 @@
|
|||||||
dontFixup = true;
|
dontFixup = true;
|
||||||
auditable = false;
|
auditable = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pytec = pkgs.python3Packages.buildPythonPackage {
|
||||||
|
pname = "pytec";
|
||||||
|
version = "0.0.0";
|
||||||
|
src = "${self}/pytec";
|
||||||
|
|
||||||
|
propagatedBuildInputs =
|
||||||
|
with pkgs.python3Packages; [
|
||||||
|
numpy
|
||||||
|
matplotlib
|
||||||
|
];
|
||||||
|
};
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
packages.x86_64-linux = {
|
packages.x86_64-linux = {
|
||||||
inherit thermostat;
|
inherit thermostat pytec;
|
||||||
default = thermostat;
|
default = thermostat;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import time
|
||||||
from pytec.client import Client
|
from pytec.client import Client
|
||||||
|
|
||||||
tec = Client() #(host="localhost", port=6667)
|
tec = Client() #(host="localhost", port=6667)
|
||||||
@ -7,5 +8,6 @@ print(tec.get_pid())
|
|||||||
print(tec.get_output())
|
print(tec.get_output())
|
||||||
print(tec.get_postfilter())
|
print(tec.get_postfilter())
|
||||||
print(tec.get_b_parameter())
|
print(tec.get_b_parameter())
|
||||||
for data in tec.report_mode():
|
while True:
|
||||||
print(data)
|
print(tec.get_report())
|
||||||
|
time.sleep(0.05)
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import socket
|
import socket
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import time
|
|
||||||
|
|
||||||
class CommandError(Exception):
|
class CommandError(Exception):
|
||||||
pass
|
pass
|
||||||
@ -147,36 +147,6 @@ class Client:
|
|||||||
"""Get Thermostat hardware revision"""
|
"""Get Thermostat hardware revision"""
|
||||||
return self._command("hwrev")
|
return self._command("hwrev")
|
||||||
|
|
||||||
def report_mode(self):
|
|
||||||
"""Start reporting measurement values
|
|
||||||
|
|
||||||
Example of yielded data::
|
|
||||||
{'channel': 0,
|
|
||||||
'time': 2302524,
|
|
||||||
'adc': 0.6199188965423515,
|
|
||||||
'sens': 6138.519310282602,
|
|
||||||
'temperature': 36.87032392655527,
|
|
||||||
'pid_engaged': True,
|
|
||||||
'i_set': 2.0635816680889123,
|
|
||||||
'vref': 1.494,
|
|
||||||
'dac_value': 2.527790834044456,
|
|
||||||
'dac_feedback': 2.523,
|
|
||||||
'i_tec': 2.331,
|
|
||||||
'tec_i': 2.0925,
|
|
||||||
'tec_u_meas': 2.5340000000000003,
|
|
||||||
'pid_output': 2.067581958092247}
|
|
||||||
"""
|
|
||||||
while True:
|
|
||||||
self._socket.sendall("report\n".encode('utf-8'))
|
|
||||||
line = self._read_line()
|
|
||||||
if not line:
|
|
||||||
break
|
|
||||||
try:
|
|
||||||
yield json.loads(line)
|
|
||||||
except json.decoder.JSONDecodeError:
|
|
||||||
pass
|
|
||||||
time.sleep(0.05)
|
|
||||||
|
|
||||||
def set_param(self, topic, channel, field="", value=""):
|
def set_param(self, topic, channel, field="", value=""):
|
||||||
"""Set configuration parameters
|
"""Set configuration parameters
|
||||||
|
|
||||||
|
81
pytec/test.py
Normal file
81
pytec/test.py
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
import argparse
|
||||||
|
from contextlib import contextmanager
|
||||||
|
from pytec.client import Client
|
||||||
|
|
||||||
|
|
||||||
|
CHANNELS = 2
|
||||||
|
|
||||||
|
|
||||||
|
def get_argparser():
|
||||||
|
parser = argparse.ArgumentParser(description="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=1,
|
||||||
|
help="Allowed deviation of resistance in percentage",
|
||||||
|
)
|
||||||
|
|
||||||
|
return parser
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
args = get_argparser().parse_args()
|
||||||
|
|
||||||
|
min_allowed_resistance = args.testing_resistance * (1 - args.deviation / 100)
|
||||||
|
max_allowed_resistance = args.testing_resistance * (1 + args.deviation / 100)
|
||||||
|
|
||||||
|
print(min_allowed_resistance, max_allowed_resistance)
|
||||||
|
|
||||||
|
thermostat = Client(args.host, args.port)
|
||||||
|
for channel in range(CHANNELS):
|
||||||
|
print(f"Channel {channel} is active")
|
||||||
|
|
||||||
|
print("Checking resistance through SENS input ....", 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 input! 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 channel {channel} current = 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()
|
Loading…
Reference in New Issue
Block a user