OPCUA: Add browsing of variables exposed by client when selecting location from variable panel.
authorEdouard Tisserant <edouard.tisserant@gmail.com>
Tue, 19 Oct 2021 12:58:22 +0200
changeset 3366 1ca385429bba
parent 3365 9f7c9051c9ba
child 3367 3656d0d235c4
OPCUA: Add browsing of variables exposed by client when selecting location from variable panel.
opc_ua/client.py
--- a/opc_ua/client.py	Mon Oct 18 20:41:31 2021 +0200
+++ b/opc_ua/client.py	Tue Oct 19 12:58:22 2021 +0200
@@ -5,7 +5,8 @@
 import os
 
 from editors.ConfTreeNodeEditor import ConfTreeNodeEditor
-from .opcua_client_maker import OPCUAClientPanel, OPCUAClientModel
+from PLCControler import LOCATION_CONFNODE, LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT
+from .opcua_client_maker import OPCUAClientPanel, OPCUAClientModel, UA_IEC_types
 
 import util.paths as paths
 
@@ -84,3 +85,28 @@
 
         return [(c_path, CFLAGS)], LDFLAGS, True
 
+    def GetVariableLocationTree(self):
+        current_location = self.GetCurrentLocation()
+        locstr = "_".join(map(str, current_location))
+        name = self.BaseParams.getName()
+        entries = []
+        for direction, data in self.modeldata.iteritems():
+            iec_direction_prefix = {"input": "__I", "output": "__Q"}[direction]
+            for row in data:
+                dname, ua_nsidx, ua_nodeid_type, _ua_node_id, ua_type, iec_number = row
+                iec_type, C_type, iec_size_prefix, ua_type_enum, ua_type = UA_IEC_types[ua_type]
+                c_loc_name = iec_direction_prefix + iec_size_prefix + locstr + "_" + str(iec_number)
+                entries.append({
+                    "name": dname,
+                    "type": {"input": LOCATION_VAR_INPUT, "output": LOCATION_VAR_OUTPUT}[direction],
+                    "size": {"X":1, "B":8, "W":16, "D":32, "L":64}[iec_size_prefix],
+                    "IEC_type": iec_type,
+                    "var_name": c_loc_name,
+                    "location": iec_size_prefix + ".".join([str(i) for i in current_location]) + "." + str(iec_number),
+                    "description": "",
+                    "children": []})
+        return {"name": name,
+                "type": LOCATION_CONFNODE,
+                "location": ".".join([str(i) for i in current_location]) + ".x",
+                "children": entries}
+