@@ 290-317 (lines=28) @@ | ||
287 | return results[0].AddedNodeId |
|
288 | ||
289 | ||
290 | def create_data_type(parent, nodeid, bname, description=None): |
|
291 | """ |
|
292 | Create a new data type to be used in new variables, etc .. |
|
293 | arguments are nodeid, browsename |
|
294 | or namespace index, name |
|
295 | """ |
|
296 | nodeid, qname = _parse_nodeid_qname(nodeid, bname) |
|
297 | ||
298 | addnode = ua.AddNodesItem() |
|
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) |
|
304 | #addnode.TypeDefinition = ua.NodeId(ua.ObjectIds.BaseDataVariableType) # No type definition for types |
|
305 | attrs = ua.DataTypeAttributes() |
|
306 | if description is None: |
|
307 | attrs.Description = ua.LocalizedText(qname.Name) |
|
308 | else: |
|
309 | attrs.Description = ua.LocalizedText(description) |
|
310 | attrs.DisplayName = ua.LocalizedText(qname.Name) |
|
311 | attrs.WriteMask = 0 |
|
312 | attrs.UserWriteMask = 0 |
|
313 | attrs.IsAbstract = False # True mean they cannot be instanciated |
|
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) |
|
318 | ||
319 | ||
320 | def _create_method(parent, nodeid, qname, callback, inputs, outputs): |
|
@@ 91-116 (lines=26) @@ | ||
88 | return node.Node(parent.server, _create_variable(parent.server, parent.nodeid, nodeid, qname, var, datatype=datatype, isproperty=False)) |
|
89 | ||
90 | ||
91 | def create_variable_type(parent, nodeid, bname, datatype): |
|
92 | """ |
|
93 | Create a new variable type |
|
94 | args are nodeid, browsename and datatype |
|
95 | or idx, name and data type |
|
96 | """ |
|
97 | nodeid, qname = _parse_nodeid_qname(nodeid, bname) |
|
98 | if datatype and not isinstance(datatype, ua.NodeId): |
|
99 | raise RuntimeError("Data type should be nodeid, got {}".format(datatype)) |
|
100 | addnode = ua.AddNodesItem() |
|
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) |
|
106 | attrs = ua.VariableTypeAttributes() |
|
107 | attrs.Description = ua.LocalizedText(qname.Name) |
|
108 | attrs.DisplayName = ua.LocalizedText(qname.Name) |
|
109 | attrs.DataType = datatype |
|
110 | attrs.IsAbstract = False |
|
111 | attrs.WriteMask = 0 |
|
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 |
|
117 | ||
118 | ||
119 | def create_reference_type(parent, nodeid, bname): |