Skip to content
Snippets Groups Projects
Commit 6502cf07 authored by Jan David Mol's avatar Jan David Mol
Browse files

Graceful fallback for non-existing OPC-UA nodes, and moved connect logic to dedicated function

parent e038646a
No related branches found
No related tags found
No related merge requests found
......@@ -160,7 +160,36 @@ class RCUSCC(Device):
# ---------------
def get_pcc_node(self, node):
return self.pcc_node.get_child(["{}:{}".format(self.name_space_index, node)])
try:
return self.pcc_node.get_child(["{}:{}".format(self.name_space_index, node)])
except opcua.ua.uaerrors._auto.BadNoMatch:
self.error_stream("Could not find PCC node %s, using a dummy", node)
class DummyNode:
def get_value(self):
pass
def set_value(self, val):
pass
return DummyNode()
def _connect(self):
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.connect()
self.debug_stream("Connecting to OPC-UA server %s:%d done.", self.OPC_Server_Name, self.OPC_Server_Port)
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_objects_node()
self.pcc_node = self.obj_node.get_child(["{}:PCC".format(self.name_space_index)])
def init_device(self):
......@@ -211,20 +240,7 @@ class RCUSCC(Device):
# 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.connect()
self.debug_stream("Connecting to OPC-UA server %s:%d done.", self.OPC_Server_Name, self.OPC_Server_Port)
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_objects_node()
self.pcc_node = self.obj_node.get_child(["{}:PCC".format(self.name_space_index)])
self._connect()
self.debug_stream("Mapping OPC-UA MP/CP to attributes...")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment