2 High level functions to create nodes 11 if isinstance(args[0], int):
17 elif isinstance(args[0], str):
18 nodeid = ua.NodeId.from_string(args[0])
23 elif isinstance(args[1], str):
24 qname = ua.QualifiedName.from_string(args[1])
30 except Exception
as ex:
31 raise TypeError(
"This method takes either a namespace index and a string as argument or a nodeid and a qualifiedname. Received arguments {0} and got exception {1}".format(args, ex))
36 create a child node folder 37 arguments are nodeid, browsename 38 or namespace index, name 41 return node.Node(parent.server,
_create_object(parent.server, parent.nodeid, nodeid, qname, ua.ObjectIds.FolderType))
46 create a child node object 47 arguments are nodeid, browsename, [objecttype] 48 or namespace index, name, [objecttype] 49 if objectype is given (a NodeId) then the type node is instantiated inclusive its child nodes 52 if objecttype
is not None:
53 objecttype =
node.Node(parent.server, objecttype)
54 nodes =
instantiate(parent, objecttype, nodeid, bname)[0]
57 return node.Node(parent.server,
_create_object(parent.server, parent.nodeid, nodeid, qname, ua.ObjectIds.BaseObjectType))
62 create a child node property 63 args are nodeid, browsename, value, [variant type] 64 or idx, name, value, [variant type] 68 if datatype
and isinstance(datatype, int):
70 if datatype
and not isinstance(datatype,
ua.NodeId):
71 raise RuntimeError(
"datatype argument must be a nodeid or an int refering to a nodeid")
72 return node.Node(parent.server,
_create_variable(parent.server, parent.nodeid, nodeid, qname, var, datatype=datatype, isproperty=
True))
77 create a child node variable 78 args are nodeid, browsename, value, [variant type], [data type] 79 or idx, name, value, [variant type], [data type] 83 if datatype
and isinstance(datatype, int):
85 if datatype
and not isinstance(datatype,
ua.NodeId):
86 raise RuntimeError(
"datatype argument must be a nodeid or an int refering to a nodeid")
88 return node.Node(parent.server,
_create_variable(parent.server, parent.nodeid, nodeid, qname, var, datatype=datatype, isproperty=
False))
93 Create a new variable type 94 args are nodeid, browsename and datatype 95 or idx, name and data type 98 if datatype
and not isinstance(datatype,
ua.NodeId):
99 raise RuntimeError(
"Data type should be nodeid, got {0}".format(datatype))
101 addnode.RequestedNewNodeId = nodeid
102 addnode.BrowseName = qname
103 addnode.NodeClass = ua.NodeClass.Variable
104 addnode.ParentNodeId = parent.nodeid
105 addnode.ReferenceTypeId =
ua.NodeId(ua.ObjectIds.HasSubtype)
109 attrs.DataType = datatype
110 attrs.IsAbstract =
False 112 attrs.UserWriteMask = 0
113 addnode.NodeAttributes = attrs
114 results = parent.server.add_nodes([addnode])
115 results[0].StatusCode.check()
116 return results[0].AddedNodeId
121 Create a new reference type 122 args are nodeid and browsename 127 addnode.RequestedNewNodeId = nodeid
128 addnode.BrowseName = qname
129 addnode.NodeClass = ua.NodeClass.Variable
130 addnode.ParentNodeId = parent.nodeid
131 addnode.ReferenceTypeId =
ua.NodeId(ua.ObjectIds.HasSubtype)
133 attrs.IsAbstract =
False 136 attrs.AccessLevel = ua.AccessLevel.CurrentRead.mask
137 attrs.UserAccessLevel = ua.AccessLevel.CurrentRead.mask
138 addnode.NodeAttributes = attrs
139 results = parent.server.add_nodes([addnode])
140 results[0].StatusCode.check()
141 return results[0].AddedNodeId
146 Create a new object type to be instanciated in address space. 147 arguments are nodeid, browsename 148 or namespace index, name 156 create a child method object 157 This is only possible on server side!! 158 args are nodeid, browsename, method_to_be_called, [input argument types], [output argument types] 159 or idx, name, method_to_be_called, [input argument types], [output argument types] 160 if argument types is specified, child nodes advertising what arguments the method uses and returns will be created 161 a callback is a method accepting the nodeid of the parent as first argument and variants after. returns a list of variants 178 addnode.RequestedNewNodeId = nodeid
179 addnode.BrowseName = qname
180 addnode.ParentNodeId = parentnodeid
181 if node.Node(server, parentnodeid).get_type_definition() ==
ua.NodeId(ua.ObjectIds.FolderType):
182 addnode.ReferenceTypeId =
ua.NodeId(ua.ObjectIds.Organizes)
184 addnode.ReferenceTypeId =
ua.NodeId(ua.ObjectIds.HasComponent)
185 addnode.NodeClass = ua.NodeClass.Object
186 if isinstance(objecttype, int):
187 addnode.TypeDefinition =
ua.NodeId(objecttype)
189 addnode.TypeDefinition = objecttype
191 attrs.EventNotifier = 0
196 attrs.UserWriteMask = 0
197 addnode.NodeAttributes = attrs
198 results = server.add_nodes([addnode])
199 results[0].StatusCode.check()
200 return results[0].AddedNodeId
205 addnode.RequestedNewNodeId = nodeid
206 addnode.BrowseName = qname
207 addnode.ParentNodeId = parentnodeid
208 addnode.ReferenceTypeId =
ua.NodeId(ua.ObjectIds.HasSubtype)
209 addnode.NodeClass = ua.NodeClass.ObjectType
211 attrs.IsAbstract =
False 215 attrs.UserWriteMask = 0
216 addnode.NodeAttributes = attrs
217 results = server.add_nodes([addnode])
218 results[0].StatusCode.check()
219 return results[0].AddedNodeId
222 def _create_variable(server, parentnodeid, nodeid, qname, var, datatype=None, isproperty=False):
224 addnode.RequestedNewNodeId = nodeid
225 addnode.BrowseName = qname
226 addnode.NodeClass = ua.NodeClass.Variable
227 addnode.ParentNodeId = parentnodeid
229 addnode.ReferenceTypeId =
ua.NodeId(ua.ObjectIds.HasProperty)
230 addnode.TypeDefinition =
ua.NodeId(ua.ObjectIds.PropertyType)
232 addnode.ReferenceTypeId =
ua.NodeId(ua.ObjectIds.HasComponent)
233 addnode.TypeDefinition =
ua.NodeId(ua.ObjectIds.BaseDataVariableType)
238 attrs.DataType = datatype
243 if not isinstance(var.Value, (list, tuple)):
244 attrs.ValueRank = ua.ValueRank.Scalar
247 attrs.ValueRank = len(var.Dimensions)
248 attrs.ArrayDimensions = var.Dimensions
250 attrs.UserWriteMask = 0
251 attrs.Historizing = 0
252 attrs.AccessLevel = ua.AccessLevel.CurrentRead.mask
253 attrs.UserAccessLevel = ua.AccessLevel.CurrentRead.mask
254 addnode.NodeAttributes = attrs
255 results = server.add_nodes([addnode])
256 results[0].StatusCode.check()
257 return results[0].AddedNodeId
262 addnode.RequestedNewNodeId = nodeid
263 addnode.BrowseName = qname
264 addnode.NodeClass = ua.NodeClass.VariableType
265 addnode.ParentNodeId = parentnodeid
266 addnode.ReferenceTypeId =
ua.NodeId(ua.ObjectIds.HasSubtype)
271 attrs.DataType = datatype
274 if isinstance(value, (list, tuple)):
275 attrs.ValueRank = ua.ValueRank.OneDimension
277 attrs.ValueRank = ua.ValueRank.Scalar
280 attrs.UserWriteMask = 0
281 attrs.Historizing = 0
282 attrs.AccessLevel = ua.AccessLevel.CurrentRead.mask
283 attrs.UserAccessLevel = ua.AccessLevel.CurrentRead.mask
284 addnode.NodeAttributes = attrs
285 results = server.add_nodes([addnode])
286 results[0].StatusCode.check()
287 return results[0].AddedNodeId
292 Create a new data type to be used in new variables, etc .. 293 arguments are nodeid, browsename 294 or namespace index, name 299 addnode.RequestedNewNodeId = nodeid
300 addnode.BrowseName = qname
301 addnode.NodeClass = ua.NodeClass.DataType
302 addnode.ParentNodeId = parent.nodeid
303 addnode.ReferenceTypeId =
ua.NodeId(ua.ObjectIds.HasSubtype)
306 if description
is None:
312 attrs.UserWriteMask = 0
313 attrs.IsAbstract =
False 314 addnode.NodeAttributes = attrs
315 results = parent.server.add_nodes([addnode])
316 results[0].StatusCode.check()
317 return node.Node(parent.server, results[0].AddedNodeId)
322 addnode.RequestedNewNodeId = nodeid
323 addnode.BrowseName = qname
324 addnode.NodeClass = ua.NodeClass.Method
325 addnode.ParentNodeId = parent.nodeid
326 addnode.ReferenceTypeId =
ua.NodeId(ua.ObjectIds.HasComponent)
332 attrs.UserWriteMask = 0
333 attrs.Executable =
True 334 attrs.UserExecutable =
True 335 addnode.NodeAttributes = attrs
336 results = parent.server.add_nodes([addnode])
337 results[0].StatusCode.check()
338 method =
node.Node(parent.server, results[0].AddedNodeId)
341 ua.NodeId(namespaceidx=method.nodeid.NamespaceIndex),
344 varianttype=ua.VariantType.ExtensionObject,
345 datatype=ua.ObjectIds.Argument)
348 ua.NodeId(namespaceidx=method.nodeid.NamespaceIndex),
351 varianttype=ua.VariantType.ExtensionObject,
352 datatype=ua.ObjectIds.Argument)
353 parent.server.add_method_callback(method.nodeid, callback)
354 return results[0].AddedNodeId
369 if variant.VariantType == ua.VariantType.ExtensionObject:
370 if variant.Value
is None:
371 raise ua.UaError(
"Cannot guess DataType from Null ExtensionObject")
372 if type(variant.Value)
in (list, tuple):
373 if len(variant.Value) == 0:
374 raise ua.UaError(
"Cannot guess DataType from Null ExtensionObject")
375 extobj = variant.Value[0]
377 extobj = variant.Value
378 classname = extobj.__class__.__name__
386 Delete specified nodes. Optionally delete recursively all nodes with a 387 downward hierachic references to the node 394 it.NodeId = mynode.nodeid
395 it.DeleteTargetReferences =
True 396 nodestodelete.append(it)
398 params.NodesToDelete = nodestodelete
399 return server.delete_nodes(params)
404 for mynode
in nodes[:]:
405 results += mynode.get_children()
def _parse_nodeid_qname(args)
def _vtype_to_argument(vtype)
def _create_variable(server, parentnodeid, nodeid, qname, var, datatype=None, isproperty=False)
def instantiate(parent, node_type, nodeid=None, bname=None, idx=0)
def create_object(parent, nodeid, bname, objecttype=None)
def _create_variable_type(server, parentnodeid, nodeid, qname, datatype, value=None)
def create_folder(parent, nodeid, bname)
def create_data_type(parent, nodeid, bname, description=None)
def _guess_datatype(variant)
def _create_method(parent, nodeid, qname, callback, inputs, outputs)
def create_property(parent, nodeid, bname, val, varianttype=None, datatype=None)
def delete_nodes(server, nodes, recursive=False)
def create_object_type(parent, nodeid, bname)
def _create_object_type(server, parentnodeid, nodeid, qname)
def create_reference_type(parent, nodeid, bname)
def create_variable_type(parent, nodeid, bname, datatype)
def create_variable(parent, nodeid, bname, val, varianttype=None, datatype=None)
def create_method(parent, args)
def _create_object(server, parentnodeid, nodeid, qname, objecttype)