Skip to content

[xmlimporter] support use of extension dictionaries #451

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions opcua/common/xmlimporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def import_xml(self, xmlpath):

self.namespaces = self._map_namespaces(self.parser.get_used_namespaces())
self.aliases = self._map_aliases(self.parser.get_aliases())

dnodes = self.parser.get_node_datas()
dnodes = self.make_objects(dnodes)
nodes_parsed = self._sort_nodes_by_parentid(dnodes)
Expand Down Expand Up @@ -98,7 +98,7 @@ def _add_references(self, refs):
return self.server.iserver.isession.add_references(refs)
else:
return self.server.uaclient.add_references(refs)

def make_objects(self, node_datas):
new_nodes = []
for ndata in node_datas:
Expand Down Expand Up @@ -206,8 +206,21 @@ def add_variable(self, obj):
res[0].StatusCode.check()
return res[0].AddedNodeId

def _get_ext_class(self, name):
if hasattr(ua, name):
return getattr(ua, name)
elif name in self.aliases.keys():
nodeid = self.aliases[name]
class_type = ua.uatypes.get_extensionobject_class_type(nodeid)
if class_type:
return class_type
else:
raise Exception("Error no extension class registered ", name, nodeid)
else:
raise Exception("Error no alias found for extension class", name)

def _make_ext_obj(self, obj):
ext = getattr(ua, obj.objname)()
ext = self._get_ext_class(obj.objname)()
for name, val in obj.body:
if isinstance(val, str):
raise Exception("Error val should a dict", name, val)
Expand Down
10 changes: 9 additions & 1 deletion opcua/ua/uatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ def __init__(self, identifier=None, namespaceidx=0, nodeidtype=None):
raise UaError("NodeId: Could not guess type of NodeId, set NodeIdType")

def _key(self):
if self.NodeIdType in (NodeIdType.TwoByte, NodeIdType.FourByte, NodeIdType.Numeric):
if self.NodeIdType in (NodeIdType.TwoByte, NodeIdType.FourByte, NodeIdType.Numeric):
# twobyte, fourbyte and numeric may represent the same node
return (NodeIdType.Numeric, self.NamespaceIndex, self.Identifier)
return (self.NodeIdType, self.NamespaceIndex, self.Identifier)
Expand Down Expand Up @@ -1129,6 +1129,14 @@ def register_extension_object(name, nodeid, class_type):
extension_object_classes[nodeid] = class_type
extension_object_ids[name] = nodeid

def get_extensionobject_class_type(typeid):
"""
Returns the registered class type for typid of an extension object
"""
if typeid in extension_object_classes:
return extension_object_classes[typeid]
else:
return None

def extensionobject_from_binary(data):
"""
Expand Down