-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcontrol.py
More file actions
executable file
·63 lines (54 loc) · 2.05 KB
/
control.py
File metadata and controls
executable file
·63 lines (54 loc) · 2.05 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
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/bin/env python3
import subprocess
from subprocess import Popen, PIPE
class ca:
def __init__(self):
print("V0.1")
def cagetstring(pv):
val = None
while val is None:
try:
a = Popen(["caget", "-S", pv], stdout=PIPE, stderr=PIPE)
a_stdout, a_stderr = a.communicate()
val = a_stdout.split()[1]
val = str(val.decode("ascii"))
except:
print("Exception in ca_py3.py cagetstring maybe this PV aint a string")
pass
return val
def caget(pv):
val = None
while val is None:
try:
a = Popen(["caget", pv], stdout=PIPE, stderr=PIPE)
a_stdout, a_stderr = a.communicate()
val = a_stdout.split()[1].decode("ascii")
# val = evaluate(val)
# val = val.decode('ascii')
except:
print("Exception in ca_py3.py caget, maybe this PV doesnt exist:", pv)
pass
return val
def caput(pv, new_val, force=False):
check = Popen(["cainfo", pv], stdout=PIPE, stderr=PIPE)
check_stdout, check_stderr = check.communicate()
try:
is_char = check_stdout.split()[11].decode("ascii") == "DBF_CHAR"
except (IndexError, UnicodeDecodeError):
is_char = False
if force:
a = Popen(["caput", pv, str(new_val)], stdout=PIPE, stderr=PIPE)
a_stdout, a_stderr = a.communicate()
elif is_char:
a = Popen(["caput", "-S", pv, str(new_val)], stdout=PIPE, stderr=PIPE)
a_stdout, a_stderr = a.communicate()
else:
a = Popen(["caput", pv, str(new_val)], stdout=PIPE, stderr=PIPE)
a_stdout, a_stderr = a.communicate()
class control:
def __init__(self):
print("V0.1")
def get_value(self, pv):
subprocess.run(("caget", pv))
def push_value(self, pv):
subprocess.run(("caput", pv))