pytec: add configuration getters
This commit is contained in:
parent
6e0cf26d6a
commit
bfdb64ffd6
@ -6,15 +6,19 @@ from pytec.client import Client
|
||||
|
||||
TIME_WINDOW = 300.0
|
||||
|
||||
tec = Client()
|
||||
target_temperature = tec.get_pid()[0]['target']
|
||||
print("Channel 0 target temperature: {:.3f}".format(target_temperature))
|
||||
|
||||
class Series:
|
||||
def __init__(self, scale=1.0):
|
||||
self.scale = scale
|
||||
def __init__(self, conv=lambda x: x):
|
||||
self.conv = conv
|
||||
self.x_data = []
|
||||
self.y_data = []
|
||||
|
||||
def append(self, x, y):
|
||||
self.x_data.append(x)
|
||||
self.y_data.append(self.scale * y)
|
||||
self.y_data.append(self.conv(y))
|
||||
|
||||
def clip(self, min_x):
|
||||
drop = 0
|
||||
@ -25,8 +29,8 @@ class Series:
|
||||
|
||||
series = {
|
||||
'adc': Series(),
|
||||
'sens': Series(0.0001),
|
||||
'temperature': Series(),
|
||||
'sens': Series(lambda x: x * 0.0001),
|
||||
'temperature': Series(lambda t: t - target_temperature),
|
||||
'i_set': Series(),
|
||||
'pid_output': Series(),
|
||||
'vref': Series(),
|
||||
@ -55,7 +59,6 @@ def recv_data(tec):
|
||||
if quit:
|
||||
break
|
||||
|
||||
tec = Client()
|
||||
thread = Thread(target=recv_data, args=(tec,))
|
||||
thread.start()
|
||||
|
||||
|
@ -1,6 +1,8 @@
|
||||
import socket
|
||||
import json
|
||||
|
||||
CHANNELS = 2
|
||||
|
||||
class Client:
|
||||
def __init__(self, host="192.168.1.26", port=23, timeout=None):
|
||||
self._socket = socket.create_connection((host, port), timeout)
|
||||
@ -21,7 +23,28 @@ class Client:
|
||||
line = self._lines[0]
|
||||
self._lines = self._lines[1:]
|
||||
return line
|
||||
|
||||
|
||||
def _get_conf(self, topic):
|
||||
self._command(topic)
|
||||
result = []
|
||||
for channel in range(0, CHANNELS):
|
||||
line = self._read_line()
|
||||
conf = json.loads(line)
|
||||
result.append(conf)
|
||||
return result
|
||||
|
||||
def get_pwm(self):
|
||||
return self._get_conf("pwm")
|
||||
|
||||
def get_pid(self):
|
||||
return self._get_conf("pid")
|
||||
|
||||
def get_steinhart_hart(self):
|
||||
return self._get_conf("s-h")
|
||||
|
||||
def get_postfilter(self):
|
||||
return self._get_conf("postfilter")
|
||||
|
||||
def report_mode(self):
|
||||
"""Start reporting measurement values
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user