-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathelta.py
More file actions
50 lines (39 loc) · 1.45 KB
/
elta.py
File metadata and controls
50 lines (39 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import serial
class EltaControl:
def __init__(self, port="/dev/ttyUSB0"):
self.port = port
self.elta = serial.Serial(port=self.port, baudrate=19200, timeout=1)
def __del__(self):
self.elta.close()
def __command(self, command):
self.elta.write(bytes(command, 'utf-8') + b"\r\n")
return self.elta.readline().decode('utf-8').strip()
def boot(self):
self.__command("\r\n\r\n\r\n")
def shutdown(self):
self.__command("SEO")
def read_angle(self):
zeile = self.__command("FW1")
hz, v = None, None
try:
hz_str = zeile.split("Hz")[1].split("gon")[0]
v_str = zeile.split("V")[1].split("gon")[0]
hz = float(hz_str.strip("| :"))
v = float(v_str.strip("| :"))
except (IndexError, ValueError):
print(f"Fehler beim Parsen der Antwort: '{zeile}'")
pass
return hz, v
def go_to(self, hz=None, v=None):
if hz is not None:
self.__command(f"!Khz | {hz:>9,.5f} gon ")
if v is not None:
self.__command(f"!Kv1 | {v:>9,.5f} gon ")
if hz is not None or v is not None:
self.__command("FAC")
def add_hz(self, hz):
current_hz, _ = self.read_angle()
self.go_to(hz=current_hz + hz)
def add_v(self, v):
_, current_v = self.read_angle()
self.go_to(v=current_v + v)