-
Notifications
You must be signed in to change notification settings - Fork 0
/
EpicsZeroDController.py
82 lines (62 loc) · 2.44 KB
/
EpicsZeroDController.py
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
from epics import caget
import time
from sardana import State
from sardana.pool.controller import ZeroDController
from sardana.pool.controller import Type, Description, DefaultValue, Access, DataAccess, Memorize, Memorized
class Channel:
def __init__(self, idx):
self.idx = idx # 1 based index
self.value = 0.0
self.active = False
self.PVname = None
class EpicsZeroDController(ZeroDController):
"""This class represents a dummy Sardana 0D controller."""
MaxDevice = 1024
axis_attributes = {'PVname': {Type: str, Description: 'PV name of channel', DefaultValue: None, Access: DataAccess.ReadWrite, Memorized: Memorize},}
def __init__(self, inst, props, *args, **kwargs):
ZeroDController.__init__(self, inst, props, *args, **kwargs)
self.channels = [Channel(i + 1) for i in range(self.MaxDevice)]
self.read_channels = {}
def AddDevice(self, ind):
self.channels[ind-1].active = True
def DeleteDevice(self, ind):
self.channels[ind-1].active = False
def StateOne(self, ind):
return State.On, "OK"
def _setChannelValue(self, channel):
channel.value = caget(channel.PVname)
time.sleep(0.1)
def PreReadAll(self):
self.read_channels = {}
def PreReadOne(self, ind):
channel = self.channels[ind - 1]
self.read_channels[ind] = channel
def ReadAll(self):
for channel in self.read_channels.values():
self._setChannelValue(channel)
def ReadOne(self, ind):
v = self.read_channels[ind].value
return v
def GetAxisExtraPar(self, ind, name):
""" Get Smaract axis particular parameters.
@param axis to get the parameter
@param name of the parameter to retrive
@return the value of the parameter
"""
name = name.lower()
if name == 'pvname':
result = self.channels[ind - 1].PVname
else:
raise ValueError('There is not %s attribute' % name)
return result
def SetAxisExtraPar(self, ind, name, value):
""" Set Smaract axis particular parameters.
@param axis to set the parameter
@param name of the parameter
@param value to be set
"""
name = name.lower()
if name == 'pvname':
self.channels[ind - 1].PVname = value
else:
raise ValueError('There is not %s attribute' % name)