diff --git a/RCUSCC-DS/RCUSCC.py b/RCUSCC-DS/RCUSCC.py index 6e1b7dcabfa5e9a0b55063e871a7762df04f6cfc..4802f8e2194b9dff18eab94f2091296128fe83bd 100644 --- a/RCUSCC-DS/RCUSCC.py +++ b/RCUSCC-DS/RCUSCC.py @@ -22,6 +22,8 @@ from tango import AttrQuality, DispLevel, DevState from tango import AttrWriteType, PipeWriteType # Additional import # PROTECTED REGION ID(RCUSCC.additionnal_import) ENABLED START # +import opcua +import traceback # PROTECTED REGION END # // RCUSCC.additionnal_import __all__ = ["RCUSCC", "main"] @@ -69,12 +71,12 @@ class RCUSCC(Device): # Attributes # ---------- - time_offset_RW = attribute( + time_offset_rw = attribute( dtype='DevLong64', access=AttrWriteType.READ_WRITE, ) - time_offset_R = attribute( + time_offset_r = attribute( dtype='DevLong64', ) @@ -93,29 +95,32 @@ class RCUSCC(Device): # Set default values in the RW/R attributes and add them to # the mapping. - self._time_offset_RW = 0 - attribute_mapping["_time_offset_RW"] = {} - self._time_offset_R = 0 - attribute_mapping["_time_offset_R"] = {} + self._time_offset_rw = 0 + self.attribute_mapping["_time_offset_rw"] = {} + self._time_offset_r = 0 + self.attribute_mapping["_time_offset_r"] = {} # Set defaults to property values. try: self.debug_stream("Connecting to OPC-UA server %s:%d...", self.OPC_Server_Name, self.OPC_Server_Port) - self.client = opcua.Client("opc.tcp://{}:{}/".format(self.OPC_Server_Name, self.OPC_Server_Port), self.OPC_Time_out * 1000) + self.client = opcua.Client("opc.tcp://{}:{}/".format(self.OPC_Server_Name, self.OPC_Server_Port), self.OPC_Time_Out * 1000) self.client.connect() self.debug_stream("Connecting to OPC-UA server %s:%d done.", self.OPC_Server_Name, self.OPC_Server_Port) - self.name_space_index = self.client.get_namespace_index("http://lofar.eu") - self.name_space_index = 2 + try: + self.name_space_index = self.client.get_namespace_index("http://lofar.eu") + except Exception as e: + self.warn_stream("Cannot determine the OPC-UA name space index. Will try and use the default = 2.") + self.name_space_index = 2 - self.obj_node = self.client.get_obj_node() + self.obj_node = self.client.get_objects_node() self.debug_stream("Mapping OPC-UA MP/CP to attributes...") attribute_name = "time_offset" - self.attribute_mapping["_time_offset_RW"] = self.obj_node.get_child([ "{}:time_offset".format(name_space_index), "{}:control_point".format(name_space_index)]) - self.attribute_mapping["_time_offset_R"] = self.obj_node.get_child([ "{}:time_offset".format(name_space_index), "{}:monitor_point".format(name_space_index)]) + self.attribute_mapping["_time_offset_rw"] = self.obj_node.get_child([ "{}:time_offset".format(self.name_space_index), "{}:time_offset_RW".format(self.name_space_index)]) + self.attribute_mapping["_time_offset_r"] = self.obj_node.get_child([ "{}:time_offset".format(self.name_space_index), "{}:time_offset_R".format(self.name_space_index)]) self.debug_stream("Mapping OPC-UA MP/CP to attributes done.") self.set_state(DevState.ON) except Exception as e: @@ -149,25 +154,25 @@ class RCUSCC(Device): # Attributes methods # ------------------ - def read_time_offset_RW(self): - # PROTECTED REGION ID(RCUSCC.time_offset_RW_read) ENABLED START # - """Return the time_offset_RW attribute.""" - return self._time_offset__rw - # PROTECTED REGION END # // RCUSCC.time_offset_RW_read - - def write_time_offset_RW(self, value): - # PROTECTED REGION ID(RCUSCC.time_offset_RW_write) ENABLED START # - """Set the time_offset_RW attribute.""" - self.attribute_mapping["_time_offset_RW"].set_value(value) - self._time_offset__rw = value - # PROTECTED REGION END # // RCUSCC.time_offset_RW_write - - def read_time_offset_R(self): - # PROTECTED REGION ID(RCUSCC.time_offset_R_read) ENABLED START # - """Return the time_offset_R attribute.""" - self._time_offset__r = self.attribute_mapping["_time_offset_R"].get_value() - return self._time_offset__r - # PROTECTED REGION END # // RCUSCC.time_offset_R_read + def read_time_offset_rw(self): + # PROTECTED REGION ID(RCUSCC.time_offset_rw_read) ENABLED START # + """Return the time_offset_rw attribute.""" + return self._time_offset_rw + # PROTECTED REGION END # // RCUSCC.time_offset_rw_read + + def write_time_offset_rw(self, value): + # PROTECTED REGION ID(RCUSCC.time_offset_rw_write) ENABLED START # + """Set the time_offset_rw attribute.""" + self.attribute_mapping["_time_offset_rw"].set_value(value) + self._time_offset_rw = value + # PROTECTED REGION END # // RCUSCC.time_offset_rw_write + + def read_time_offset_r(self): + # PROTECTED REGION ID(RCUSCC.time_offset_r_read) ENABLED START # + """Return the time_offset_r attribute.""" + self._time_offset_r = self.attribute_mapping["_time_offset_r"].get_value() + return self._time_offset_r + # PROTECTED REGION END # // RCUSCC.time_offset_r_read # -------- # Commands diff --git a/RCUSCC-DS/RCUSCC.xmi b/RCUSCC-DS/RCUSCC.xmi index 72803e95941158c6b9f6b91c878af731af1c13e7..7d5483d29da59aad12d24f86984e098c6aa76355 100644 --- a/RCUSCC-DS/RCUSCC.xmi +++ b/RCUSCC-DS/RCUSCC.xmi @@ -35,7 +35,7 @@ </argout> <status abstract="true" inherited="true" concrete="true"/> </commands> - <attributes name="time_offset_RW" attType="Scalar" rwType="READ_WRITE" displayLevel="OPERATOR" polledPeriod="0" maxX="" maxY="" allocReadMember="true" isDynamic="false"> + <attributes name="time_offset_rw" attType="Scalar" rwType="READ_WRITE" displayLevel="OPERATOR" polledPeriod="0" maxX="" maxY="" allocReadMember="true" isDynamic="false"> <dataType xsi:type="pogoDsl:LongType"/> <changeEvent fire="false" libCheckCriteria="false"/> <archiveEvent fire="false" libCheckCriteria="false"/> @@ -43,7 +43,7 @@ <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> <properties description="" label="" unit="" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/> </attributes> - <attributes name="time_offset_R" attType="Scalar" rwType="READ" displayLevel="OPERATOR" polledPeriod="0" maxX="" maxY="" allocReadMember="true" isDynamic="false"> + <attributes name="time_offset_r" attType="Scalar" rwType="READ" displayLevel="OPERATOR" polledPeriod="0" maxX="" maxY="" allocReadMember="true" isDynamic="false"> <dataType xsi:type="pogoDsl:LongType"/> <changeEvent fire="false" libCheckCriteria="false"/> <archiveEvent fire="false" libCheckCriteria="false"/>