-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathca.py
More file actions
executable file
·50 lines (46 loc) · 1.51 KB
/
ca.py
File metadata and controls
executable file
·50 lines (46 loc) · 1.51 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
#!/bin/env python3
from subprocess import Popen, PIPE
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):
check = Popen(['cainfo', pv], stdout=PIPE, stderr=PIPE)
check_stdout, check_stderr = check.communicate()
if check_stdout.split()[11].decode('ascii') == 'DBF_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()
def evaluate(val):
try:
int(val)
return int(val)
except:
try:
float(val)
return float(val)
except ValueError:
return val