Newer
Older
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
"""
* ASTRI - Template for Hardware device scipt based on ALMA Software Templates
* (c) INAF/UNIPG, 2021
*
* WARNING! DO NOT MODIFY THIS FILE!
*
* Generated by: $Author
* Date: $Date
* Description: $Description
* Filename: $Filename
*
"""
"""
This package is part of the Telescope Command Language (TCL).
It contains the code used for accessing $Assembly.
"""
import math
import TCL.HardwareDevice
from TCL.Container import getComponent
from TCL.Container import getDynamicComponent
from TCL.logging import getLogger
class ${Assembly}Base(TCL.HardwareDevice.HardwareDevice):
def __init__(self, telescopeName = None, componentName = None, stickyFlag = False):
"""
The constructor creates a ${Assembly} object or a group of ${Assembly}
objects.
If the telescopeName is defined then this constructor references
the component running on that . Alternativly the full
componentName can be specified if desired.
If telescopeName or componentName are specified as list then a set of
${Assembly} components are created.
The ${Assembly}Base class is a python proxy to the ${Assembly}
component. The component can be running before creating this
proxy but if it is not it will be started. The object reference
is obtained using a call to getComponent (stickyFlag = True)
or to getComponentNonSticky (stickyFlag = False, default).
An exception is thrown if there is a problem creating
this component, establishing the connection to the
previously mentioned hardware components, or if either
both or neither telescopeName and componentName are specified.
EXAMPLE:
import TCL.${Assembly}Base
obj = TCL.${Assembly}Base.${Assembly}Base("ASTRI1")
or
import TCL.${Assembly}Base
obj = TCL.${Assembly}Base.${Assembly}Base(["ASTRI1", "ASTRI2",...])
"""
## Dictionary of device instances
self._devices = {}
## Group of telescopes or component names.
if ((isinstance(telescopeName, list) == True) or
(isinstance(componentName, list) == True)):
## Telescopes names
if isinstance(telescopeName, list) == True:
if len(telescopeName) != 0:
for idx in range(0, len(telescopeName)):
self._devices["SCADA/" + telescopeName[idx] + "/"+"${Assembly}"] = ""
## Component names
if isinstance(componentName, list) == True:
if len(componentName) != 0:
for idx in range(0, len(componentName)):
self._devices[componentName[idx]] = ""
## One component
else:
if((telescopeName == None) and (componentName == None)):
raise (NameError, "missing telescopeName or componentName")
elif((telescopeName != None) and (componentName != None)):
raise (NameError, "missing telescopeName or componentName")
if telescopeName != None:
self._devices["SCADA/" + telescopeName + "/"+"${Assembly}"] = ""
if componentName != None:
self._devices[componentName] = ""
## Initialize the base class
for key, val in self._devices.items():
TCL.HardwareDevice.HardwareDevice.__init__(self, key, stickyFlag)
self._devices[key] = self._HardwareDevice__hw
self.__logger = getLogger()
def __del__(self):
for key, val in self._devices.items():
instance = self._devices[key]
del(instance)
TCL.HardwareDevice.HardwareDevice.__del__(self)
\# --------------------- Monitor Points ---------------------
#for $idx in $range(0,$x["NRows"])
\# $x["Short name"][$idx]
def GET_${x["Short name"][$idx]}(self):
"""
$x["Description"][$idx]
"""
result = {}
for key, val in self._devices.items():
telName = key.rsplit("/")[1]
result[telName] = self._devices[key].${x["Name of command"][$idx]}()
values = [*result.values()]
if len(self._devices) == 1:
return values[0]
return result
#end for
\# --------------------- SET Points ---------------------
#for $idx in $range(0,$y["NRows"])
\# $y["Short name"][$idx]
def SET_${y["Short name"][$idx]}(self, arg):
"""
$y["Description"][$idx]
"""
result = {}
for key, val in self._devices.items():
telName = key.rsplit("/")[1]
result[telName] = self._devices[key].${y["Name of command"][$idx]}(arg)
values = [*result.values()]
if len(self._devices) == 1:
return values[0]
return result
#end for
\# ----------------- List of Monitor Points ------------------
def getMonitorList(self):
"""
This method returns a list containing all monitor point
names of this hardware device.
"""
result = {}
for key, val in self._devices.items():
telName = key.rsplit("/")[1]
monitorList = []
#for $idx in $range(0,$x["NRows"])
monitorList.append("$x["Short name"][$idx] --> xx.GET_${x["Short name"][$idx]}()")
#end for
result[telName] = monitorList
values = [*result.values()]
if len(self._devices) == 1:
return values[0]
return result
\# ----------------- List of SET Points ------------------
def getSetList(self):
"""
This method returns a list containing all set point
names of this hardware device.
"""
result = {}
for key, val in self._devices.items():
telName = key.rsplit("/")[1]
setList = []
#for $idx in $range(0,$y["NRows"])
setList.append("$y["Short name"][$idx] --> xx.SET_${y["Short name"][$idx]}(val)")
#end for
result[telName] = setList
values = [*result.values()]
if len(self._devices) == 1:
return values[0]
return result