""" * 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 telName="Dummy" class ${Assembly}Base(TCL.HardwareDevice.HardwareDevice): def __init__(self, telescopeName = None, componentName = "${Assembly}", 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["CONTROL/" + 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["CONTROL/" + 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 def callAllGet(self): result=[] for name in self.__dir__(): if "GET_" in name: print("Calling {}".format(name)) res=self.__getattribute__(name)() result.append({'value':res[0],'time':res[1]}) return result \# ----------------- 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