-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathepicsZeroDController.py
More file actions
106 lines (84 loc) · 3.36 KB
/
epicsZeroDController.py
File metadata and controls
106 lines (84 loc) · 3.36 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
##############################################################################
##
# This file is part of Sardana
##
# http://www.sardana-controls.org/
##
# Copyright 2011 CELLS / ALBA Synchrotron, Bellaterra, Spain
##
# Sardana is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
##
# Sardana is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
##
# You should have received a copy of the GNU Lesser General Public License
# along with Sardana. If not, see <http://www.gnu.org/licenses/>.
##
##############################################################################
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 xrange(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)