2 from concurrent.futures
import Future, TimeoutError
4 from datetime
import datetime
5 from datetime
import timedelta
10 from opcua
import uamethod
11 from opcua
import instantiate
12 from opcua
import copy_node
18 def func(parent, value):
21 o = srv.get_objects_node()
22 v = o.add_method(ua.NodeId(
"ServerMethod", 2), ua.QualifiedName(
'ServerMethod', 2), func, [ua.VariantType.Int64], [ua.VariantType.Int64])
25 def func2(parent, methodname, value):
26 return math.sin(value)
28 o = srv.get_objects_node()
29 v = o.add_method(ua.NodeId(
"ServerMethodArray", 2), ua.QualifiedName(
'ServerMethodArray', 2), func2, [ua.VariantType.String, ua.VariantType.Int64], [ua.VariantType.Int64])
32 def func3(parent, mylist):
33 return [i * 2
for i
in mylist]
35 o = srv.get_objects_node()
36 v = o.add_method(ua.NodeId(
"ServerMethodArray2", 2), ua.QualifiedName(
'ServerMethodArray2', 2), func3, [ua.VariantType.Int64], [ua.VariantType.Int64])
42 Tests that will be run twice. Once on server side and once on 43 client side since we have been carefull to have the exact 44 same api on server and client side 48 assertEqual =
lambda x, y:
True 49 assertIn =
lambda x, y:
True 52 servers = self.opc.find_servers()
56 obj = self.opc.get_objects_node()
58 with self.assertRaises(TypeError):
59 fold = obj.add_folder(1.2,
"kk")
61 with self.assertRaises(TypeError):
62 fold = obj.add_folder(ua.UaError,
"khjh")
64 with self.assertRaises(ua.UaError):
65 fold = obj.add_folder(
"kjk", 1.2)
67 with self.assertRaises(TypeError):
68 fold = obj.add_folder(
"i=0;s='oooo'", 1.2)
70 with self.assertRaises(ua.UaError):
71 fold = obj.add_folder(
"i=0;s='oooo'",
"tt:oioi")
74 obj = self.opc.get_objects_node()
75 fold = obj.add_folder(2,
"FolderToDelete")
76 var = fold.add_variable(2,
"VarToDelete", 9.1)
77 childs = fold.get_children()
79 self.opc.delete_nodes([var])
80 with self.assertRaises(ua.UaStatusCodeError):
82 with self.assertRaises(ua.UaStatusCodeError):
83 obj.get_child([
"2:FolderToDelete",
"2:VarToDelete"])
84 childs = fold.get_children()
85 self.assertNotIn(var, childs)
88 obj = self.opc.get_objects_node()
89 fold = obj.add_folder(2,
"FolderToDeleteR")
90 var = fold.add_variable(2,
"VarToDeleteR", 9.1)
91 self.opc.delete_nodes([fold, var])
92 with self.assertRaises(ua.UaStatusCodeError):
94 with self.assertRaises(ua.UaStatusCodeError):
95 obj.get_child([
"2:FolderToDelete",
"2:VarToDelete"])
98 obj = self.opc.get_objects_node()
99 fold = obj.add_folder(2,
"FolderToDeleteRoot")
103 nfold = fold.add_folder(2,
"FolderToDeleteRoot")
104 var = fold.add_variable(2,
"VarToDeleteR", 9.1)
105 var = fold.add_property(2,
"ProToDeleteR", 9.1)
106 prop = fold.add_property(2,
"ProToDeleteR", 9.1)
107 o = fold.add_object(3,
"ObjToDeleteR")
108 mynodes.append(nfold)
112 self.opc.delete_nodes([fold], recursive=
True)
114 with self.assertRaises(ua.UaStatusCodeError):
115 node.get_browse_name()
118 node = self.opc.get_server_node()
119 self.
assertEqual(ua.QualifiedName(
'Server', 0), node.get_browse_name())
122 root = self.opc.get_root_node()
123 self.
assertEqual(ua.QualifiedName(
'Root', 0), root.get_browse_name())
124 self.
assertEqual(ua.LocalizedText(
'Root'), root.get_display_name())
125 nid = ua.NodeId(84, 0)
129 objects = self.opc.get_objects_node()
130 self.
assertEqual(ua.QualifiedName(
'Objects', 0), objects.get_browse_name())
131 nid = ua.NodeId(85, 0)
135 objects = self.opc.get_objects_node()
136 obj = objects.add_object(4,
"browsetest")
137 folder = obj.add_folder(4,
"folder")
138 prop = obj.add_property(4,
"property", 1)
139 prop2 = obj.add_property(4,
"property2", 2)
140 var = obj.add_variable(4,
"variable", 3)
141 obj2 = obj.add_object(4,
"obj")
142 alle = obj.get_children()
143 self.assertTrue(prop
in alle)
144 self.assertTrue(prop2
in alle)
145 self.assertTrue(var
in alle)
146 self.assertTrue(folder
in alle)
147 self.assertFalse(obj
in alle)
148 props = obj.get_children(refs=ua.ObjectIds.HasProperty)
149 self.assertTrue(prop
in props)
150 self.assertTrue(prop2
in props)
151 self.assertFalse(var
in props)
152 self.assertFalse(folder
in props)
153 self.assertFalse(obj2
in props)
154 all_vars = obj.get_children(nodeclassmask=ua.NodeClass.Variable)
155 self.assertTrue(prop
in all_vars)
156 self.assertTrue(var
in all_vars)
157 self.assertFalse(folder
in props)
158 self.assertFalse(obj2
in props)
159 all_objs = obj.get_children(nodeclassmask=ua.NodeClass.Object)
160 self.assertTrue(folder
in all_objs)
161 self.assertTrue(obj2
in all_objs)
162 self.assertFalse(var
in all_objs)
165 objects = self.opc.get_objects_node()
166 folder = objects.add_folder(4,
"folder")
168 childs = objects.get_referenced_nodes(refs=ua.ObjectIds.Organizes, direction=ua.BrowseDirection.Forward, includesubtypes=
False)
169 self.assertTrue(folder
in childs)
171 childs = objects.get_referenced_nodes(refs=ua.ObjectIds.Organizes, direction=ua.BrowseDirection.Both, includesubtypes=
False)
172 self.assertTrue(folder
in childs)
174 childs = objects.get_referenced_nodes(refs=ua.ObjectIds.Organizes, direction=ua.BrowseDirection.Inverse, includesubtypes=
False)
175 self.assertFalse(folder
in childs)
177 parents = folder.get_referenced_nodes(refs=ua.ObjectIds.Organizes, direction=ua.BrowseDirection.Inverse, includesubtypes=
False)
178 self.assertTrue(objects
in parents)
180 parents = folder.get_referenced_nodes(refs=ua.ObjectIds.HierarchicalReferences, direction=ua.BrowseDirection.Inverse, includesubtypes=
False)
181 self.assertTrue(objects
in parents)
183 parent = folder.get_parent()
187 o = self.opc.get_objects_node()
188 v = o.add_variable(3,
'BNVariable with spaces and %&+?/', 1.3)
189 v2 = o.get_child(
"3:BNVariable with spaces and %&+?/")
193 root = self.opc.get_root_node()
194 with self.assertRaises(ua.UaStatusCodeError):
195 server_time_node = root.get_child([
'0:Objects',
'0:Server',
'0:nonexistingnode'])
198 root = self.opc.get_root_node()
199 with self.assertRaises(ua.UaStatusCodeError):
203 root = self.opc.get_root_node()
204 server_time_node = root.get_child([
'0:Objects',
'0:Server',
'0:ServerStatus',
'0:CurrentTime'])
205 correct = self.opc.get_node(ua.NodeId(ua.ObjectIds.Server_ServerStatus_CurrentTime))
209 time_node = self.opc.get_node(ua.NodeId(ua.ObjectIds.Server_ServerStatus_CurrentTime))
210 dt = time_node.get_value()
211 utcnow = datetime.utcnow()
213 self.assertTrue(delta < timedelta(seconds=1))
216 time_node = self.opc.get_node(ua.NodeId(ua.ObjectIds.Server_ServerStatus_CurrentTime))
217 now = datetime.utcnow()
218 objects = self.opc.get_objects_node()
219 v1 = objects.add_variable(4,
"test_datetime", now)
224 objects = self.opc.get_objects_node()
225 l = [[[1.0, 1.0, 1.0, 1.0], [2.0, 2.0, 2.0, 2.0], [3.0, 3.0, 3.0, 3.0]],[[5.0, 5.0, 5.0, 5.0], [7.0, 8.0, 9.0, 01.0], [1.0, 1.0, 1.0, 1.0]]]
226 v = objects.add_variable(3,
'variableWithDims', l)
228 v.set_array_dimensions([0, 0, 0])
229 dim = v.get_array_dimensions()
233 rank = v.get_value_rank()
238 dv = v.get_data_value()
241 l = [[[], [], []], [[], [], []]]
242 variant = ua.Variant(l, ua.VariantType.UInt32)
243 v = objects.add_variable(3,
'variableWithDimsEmpty', variant)
246 dv = v.get_data_value()
250 objects = self.opc.get_objects_node()
251 v = objects.add_variable(
'ns=3;i=888;',
'3:numericnodefromstring', 99)
252 nid = ua.NodeId(888, 3)
253 qn = ua.QualifiedName(
'numericnodefromstring', 3)
258 objects = self.opc.get_objects_node()
259 v = objects.add_variable(
'ns=3;s=stringid;',
'3:stringnodefromstring', [68])
260 nid = ua.NodeId(
'stringid', 3)
261 qn = ua.QualifiedName(
'stringnodefromstring', 3)
266 objects = self.opc.get_objects_node()
267 utf_string =
"æøå@%&" 268 bn = ua.QualifiedName(utf_string, 3)
269 nid = ua.NodeId(
"æølå", 3)
271 v = objects.add_variable(nid, bn, val)
275 bn2 = v.get_browse_name()
279 objects = self.opc.get_objects_node()
280 var = objects.add_variable(3,
'nullstring',
"a string")
282 val = var.get_value()
285 val = var.get_value()
286 self.assertNotEqual(val,
None)
290 objects = self.opc.get_objects_node()
291 var = objects.add_variable(3,
'stringfordatatype',
"a string")
292 val = var.get_data_type_as_variant_type()
294 var = objects.add_variable(3,
'stringarrayfordatatype', [
"a",
"b"])
295 val = var.get_data_type_as_variant_type()
299 objects = self.opc.get_objects_node()
300 v = objects.add_variable(
'ns=3;s=stringarrayid;',
'9:stringarray', [
'l',
'b'])
301 nid = ua.NodeId(
'stringarrayid', 3)
302 qn = ua.QualifiedName(
'stringarray', 9)
309 objects = self.opc.get_objects_node()
310 nid = ua.NodeId(9999, 3)
311 qn = ua.QualifiedName(
'AddNodeVar1', 3)
312 v1 = objects.add_variable(nid, qn, 0)
317 objects = self.opc.get_objects_node()
318 qn = ua.QualifiedName(
'AddNodeVar2', 3)
319 nid = ua.NodeId(
'AddNodeVar2Id', 3)
320 v2 = objects.add_variable(nid, qn, 0)
325 objects = self.opc.get_objects_node()
326 o = objects.add_object(
'ns=2;i=101;',
'2:AddFindObject')
327 o2 = objects.get_child(
'2:AddFindObject')
331 objects = self.opc.get_objects_node()
332 o = objects.add_object(
'ns=2;i=105;',
'2:NodePathObject')
333 root = self.opc.get_root_node()
334 o2 = root.get_child([
'0:Objects',
'2:NodePathObject'])
338 objects = self.opc.get_objects_node()
339 o = objects.add_object(
'ns=2;i=102;',
'2:AddReadObject')
340 nid = ua.NodeId(102, 2)
342 qn = ua.QualifiedName(
'AddReadObject', 2)
346 o = self.opc.get_objects_node()
347 v = o.add_variable(3,
'VariableTestValue', 4.32)
352 objects = self.opc.get_objects_node()
353 o = objects.add_object(
'ns=2;i=103;',
'2:AddReadObject')
354 with self.assertRaises(ua.UaStatusCodeError):
355 o2 = objects.add_object(
'ns=2;i=103;',
'2:AddReadObject')
358 o = self.opc.get_objects_node()
359 v = o.add_variable(3,
'VariableNegativeValue', 4)
365 statenode = self.opc.get_node(ua.NodeId(ua.ObjectIds.Server_ServerStatus_State))
366 state = statenode.get_value()
370 bad = self.opc.get_node(ua.NodeId(999, 999))
371 with self.assertRaises(ua.UaStatusCodeError):
372 bad.get_browse_name()
373 with self.assertRaises(ua.UaStatusCodeError):
375 with self.assertRaises(ua.UaStatusCodeError):
376 bad.add_object(0,
"0:myobj")
377 with self.assertRaises(ua.UaStatusCodeError):
378 bad.get_child(
"0:myobj")
381 o = self.opc.get_objects_node()
382 var = ua.Variant(1.98, ua.VariantType.Double)
383 v = o.add_variable(3,
'VariableValue', var)
387 dvar = ua.DataValue(var)
388 dv = v.get_data_value()
394 o = self.opc.get_objects_node()
395 var = ua.Variant(1.98, ua.VariantType.Double)
396 dvar = ua.DataValue(var)
397 v = o.add_variable(3,
'VariableValue', var)
398 v.set_value(var.Value)
404 v.set_data_value(dvar)
405 v3 = v.get_data_value()
409 o = self.opc.get_objects_node()
410 v = o.add_variable(3,
'VariableArrayValue', [1, 2, 3])
415 o = self.opc.get_objects_node()
416 v = o.add_variable(3,
'BoolVariable',
True)
417 dt = v.get_data_type_as_variant_type()
426 o = self.opc.get_objects_node()
427 v = o.add_variable(3,
'VariableArrayValue', [1, 2, 3])
433 idx = self.opc.get_namespace_index(
"urn:freeopcua:python:server")
435 root = self.opc.get_root_node()
436 myvar = root.add_variable(idx,
'var_in_custom_namespace', [5])
441 o = self.opc.get_objects_node()
442 m = o.get_child(
"2:ServerMethod")
443 result = o.call_method(
"2:ServerMethod", 2.1)
445 with self.assertRaises(ua.UaStatusCodeError):
447 result = o.call_method(
"2:ServerMethod", 2.1, 89, 9)
448 with self.assertRaises(ua.UaStatusCodeError):
449 result = o.call_method(ua.NodeId(999), 2.1)
452 o = self.opc.get_objects_node()
453 m = o.get_child(
"2:ServerMethodArray")
454 result = o.call_method(m,
"sin", ua.Variant(math.pi))
455 self.assertTrue(result < 0.01)
458 o = self.opc.get_objects_node()
459 m = o.get_child(
"2:ServerMethodArray2")
460 result = o.call_method(m, [1.1, 3.4, 9])
464 objects = self.opc.get_objects_node()
465 f = objects.add_folder(3,
'MyFolder')
466 child = objects.get_child(
"3:MyFolder")
468 o = f.add_object(3,
'MyObject')
469 child = f.get_child(
"3:MyObject")
471 v = f.add_variable(3,
'MyVariable', 6)
472 child = f.get_child(
"3:MyVariable")
474 p = f.add_property(3,
'MyProperty', 10)
475 child = f.get_child(
"3:MyProperty")
477 childs = f.get_children()
478 self.assertTrue(o
in childs)
479 self.assertTrue(v
in childs)
480 self.assertTrue(p
in childs)
483 base_type = self.opc.get_root_node().get_child([
"0:Types",
"0:ObjectTypes",
"0:BaseObjectType"])
484 descs = base_type.get_children_descriptions(includesubtypes=
True)
485 self.assertTrue(len(descs) > 10)
486 descs = base_type.get_children_descriptions(includesubtypes=
False)
490 objects = self.opc.get_objects_node()
491 f = objects.add_folder(3,
'MyFolder_TypeTest')
493 o = f.add_object(3,
'MyObject1', ua.ObjectIds.BaseObjectType)
494 self.
assertEqual(o.get_type_definition().Identifier, ua.ObjectIds.BaseObjectType)
496 o = f.add_object(3,
'MyObject2', ua.NodeId(ua.ObjectIds.BaseObjectType, 0))
497 self.
assertEqual(o.get_type_definition().Identifier, ua.ObjectIds.BaseObjectType)
499 base_otype= self.opc.get_node(ua.ObjectIds.BaseObjectType)
500 custom_otype = base_otype.add_object_type(2,
'MyFooObjectType')
502 o = f.add_object(3,
'MyObject3', custom_otype.nodeid)
503 self.
assertEqual(o.get_type_definition().Identifier, custom_otype.nodeid.Identifier)
505 references = o.get_references(refs=ua.ObjectIds.HasTypeDefinition, direction=ua.BrowseDirection.Forward)
507 self.
assertEqual(references[0].NodeId, custom_otype.nodeid)
510 objects = self.opc.get_objects_node()
511 o = objects.add_object(3,
'MyObject')
512 nodes = objects.get_referenced_nodes(refs=ua.ObjectIds.Organizes, direction=ua.BrowseDirection.Forward, includesubtypes=
False)
513 self.assertTrue(o
in nodes)
514 nodes = o.get_referenced_nodes(refs=ua.ObjectIds.Organizes, direction=ua.BrowseDirection.Inverse, includesubtypes=
False)
515 self.assertTrue(objects
in nodes)
517 self.
assertEqual(o.get_type_definition().Identifier, ua.ObjectIds.BaseObjectType)
519 o2 = o.add_object(3,
'MySecondObject')
520 nodes = o.get_referenced_nodes(refs=ua.ObjectIds.HasComponent, direction=ua.BrowseDirection.Forward, includesubtypes=
False)
521 self.assertTrue(o2
in nodes)
522 nodes = o2.get_referenced_nodes(refs=ua.ObjectIds.HasComponent, direction=ua.BrowseDirection.Inverse, includesubtypes=
False)
523 self.assertTrue(o
in nodes)
525 self.
assertEqual(o2.get_type_definition().Identifier, ua.ObjectIds.BaseObjectType)
527 v = o.add_variable(3,
'MyVariable', 6)
528 nodes = o.get_referenced_nodes(refs=ua.ObjectIds.HasComponent, direction=ua.BrowseDirection.Forward, includesubtypes=
False)
529 self.assertTrue(v
in nodes)
530 nodes = v.get_referenced_nodes(refs=ua.ObjectIds.HasComponent, direction=ua.BrowseDirection.Inverse, includesubtypes=
False)
531 self.assertTrue(o
in nodes)
533 self.
assertEqual(v.get_type_definition().Identifier, ua.ObjectIds.BaseDataVariableType)
535 p = o.add_property(3,
'MyProperty', 2)
536 nodes = o.get_referenced_nodes(refs=ua.ObjectIds.HasProperty, direction=ua.BrowseDirection.Forward, includesubtypes=
False)
537 self.assertTrue(p
in nodes)
538 nodes = p.get_referenced_nodes(refs=ua.ObjectIds.HasProperty, direction=ua.BrowseDirection.Inverse, includesubtypes=
False)
539 self.assertTrue(o
in nodes)
541 self.
assertEqual(p.get_type_definition().Identifier, ua.ObjectIds.PropertyType)
544 o = self.opc.nodes.objects.add_folder(1,
"titif").add_object(3,
"opath")
545 path = o.get_path_as_string()
546 self.
assertEqual([
"0:Root",
"0:Objects",
"1:titif",
"3:opath"], path)
547 path = o.get_path_as_string(2)
549 path = self.opc.get_node(
"i=13387").get_path_as_string()
551 self.
assertEqual([
'0:BaseObjectType',
'0:FolderType',
'0:FileDirectoryType',
'0:CreateDirectory'], path)
554 of = self.opc.nodes.objects.add_folder(1,
"titif")
555 op = of.add_object(3,
"opath")
557 self.
assertEqual([self.opc.nodes.root, self.opc.nodes.objects, of, op], path)
558 path = op.get_path(2)
560 target = self.opc.get_node(
"i=13387")
561 path = target.get_path()
563 self.
assertEqual([self.opc.nodes.base_object_type, self.opc.nodes.folder_type, self.opc.get_node(ua.ObjectIds.FileDirectoryType), target], path)
566 endpoints = self.opc.get_endpoints()
567 self.assertTrue(len(endpoints) > 0)
568 self.assertTrue(endpoints[0].EndpointUrl.startswith(
"opc.tcp://"))
571 dev_t = self.opc.nodes.base_data_type.add_object_type(0,
"MyDevice")
572 v_t = dev_t.add_variable(0,
"sensor", 1.0)
573 p_t = dev_t.add_property(0,
"sensor_id",
"0340")
574 ctrl_t = dev_t.add_object(0,
"controller")
575 prop_t = ctrl_t.add_property(0,
"state",
"Running")
577 devd_t = dev_t.add_object_type(0,
"MyDeviceDervived")
578 v_t = devd_t.add_variable(0,
"childparam", 1.0)
579 p_t = devd_t.add_property(0,
"sensorx_id",
"0340")
582 nodes =
copy_node(self.opc.nodes.objects, dev_t)
585 self.
assertEqual(mydevice.get_node_class(), ua.NodeClass.ObjectType)
587 obj = mydevice.get_child([
"0:controller"])
588 prop = mydevice.get_child([
"0:controller",
"0:state"])
589 self.
assertEqual(prop.get_type_definition().Identifier, ua.ObjectIds.PropertyType)
591 self.assertNotEqual(prop.nodeid, prop_t.nodeid)
595 dev_t = self.opc.nodes.base_object_type.add_object_type(0,
"MyDevice")
596 v_t = dev_t.add_variable(0,
"sensor", 1.0)
597 p_t = dev_t.add_property(0,
"sensor_id",
"0340")
598 ctrl_t = dev_t.add_object(0,
"controller")
599 prop_t = ctrl_t.add_property(0,
"state",
"Running")
602 devd_t = dev_t.add_object_type(0,
"MyDeviceDervived")
603 v_t = devd_t.add_variable(0,
"childparam", 1.0)
604 p_t = devd_t.add_property(0,
"sensorx_id",
"0340")
607 nodes =
instantiate(self.opc.nodes.objects, dev_t, bname=
"2:Device0001")
610 self.
assertEqual(mydevice.get_node_class(), ua.NodeClass.Object)
611 self.
assertEqual(mydevice.get_type_definition(), dev_t.nodeid)
612 obj = mydevice.get_child([
"0:controller"])
613 prop = mydevice.get_child([
"0:controller",
"0:state"])
614 self.
assertEqual(prop.get_type_definition().Identifier, ua.ObjectIds.PropertyType)
616 self.assertNotEqual(prop.nodeid, prop_t.nodeid)
619 nodes =
instantiate(self.opc.nodes.objects, devd_t, bname=
"2:Device0002")
620 mydevicederived = nodes[0]
621 prop1 = mydevicederived.get_child([
"0:sensorx_id"])
622 var1 = mydevicederived.get_child([
"0:childparam"])
623 var_parent = mydevicederived.get_child([
"0:sensor"])
624 prop_parent = mydevicederived.get_child([
"0:sensor_id"])
628 dev_t = self.opc.nodes.base_object_type.add_object_type(0,
"MyDevice2")
629 v_t = dev_t.add_variable(0,
"sensor", 1.0)
630 p_t = dev_t.add_property(0,
"sensor_id",
"0340")
631 ctrl_t = dev_t.add_object(0,
"controller")
632 prop_t = ctrl_t.add_property(0,
"state",
"Running")
635 nodes =
instantiate(self.opc.nodes.objects, dev_t, nodeid=ua.NodeId(
"InstDevice", 2, ua.NodeIdType.String), bname=
"2:InstDevice")
638 self.
assertEqual(mydevice.get_node_class(), ua.NodeClass.Object)
639 self.
assertEqual(mydevice.get_type_definition(), dev_t.nodeid)
640 obj = mydevice.get_child([
"0:controller"])
641 obj_nodeid_ident = obj.nodeid.Identifier
642 prop = mydevice.get_child([
"0:controller",
"0:state"])
643 self.
assertEqual(obj_nodeid_ident,
"InstDevice.controller")
644 self.
assertEqual(prop.get_type_definition().Identifier, ua.ObjectIds.PropertyType)
646 self.assertNotEqual(prop.nodeid, prop_t.nodeid)
649 v1 = self.opc.nodes.objects.add_variable(3,
'VariableEnumType1', ua.ApplicationType.ClientAndServer, datatype=ua.NodeId(ua.ObjectIds.ApplicationType))
650 tp1 = v1.get_data_type()
651 self.
assertEqual(ua.NodeId(ua.ObjectIds.ApplicationType), tp1)
653 v2 = self.opc.nodes.objects.add_variable(3,
'VariableEnumType2', ua.ApplicationType.ClientAndServer, datatype=ua.NodeId(ua.ObjectIds.ApplicationType) )
654 tp2 = v2.get_data_type()
655 self.
assertEqual( ua.NodeId(ua.ObjectIds.ApplicationType), tp2)
659 enums = self.opc.get_root_node().get_child([
"0:Types",
"0:DataTypes",
"0:BaseDataType",
"0:Enumeration"])
660 myenum_type = enums.add_data_type(0,
"MyEnum")
661 es = myenum_type.add_variable(0,
"EnumStrings", [ua.LocalizedText(
"String0"), ua.LocalizedText(
"String1"), ua.LocalizedText(
"String2")], ua.VariantType.LocalizedText)
664 o = self.opc.get_objects_node()
665 myvar = o.add_variable(2,
"MyEnumVar", ua.LocalizedText(
"String1"), datatype=myenum_type.nodeid)
668 self.
assertEqual(myvar.get_data_type(), myenum_type.nodeid)
669 myvar.set_value(ua.LocalizedText(
"String2"))
672 nint32 = self.opc.get_node(ua.ObjectIds.Int32)
673 node = ua_utils.get_node_supertype(nint32)
674 self.
assertEqual(node, self.opc.get_node(ua.ObjectIds.Integer))
676 nodes = ua_utils.get_node_supertypes(nint32)
677 self.
assertEqual(nodes[1], self.opc.get_node(ua.ObjectIds.Number))
678 self.
assertEqual(nodes[0], self.opc.get_node(ua.ObjectIds.Integer))
681 dtype = nint32.add_data_type(0,
"MyCustomDataType")
682 node = ua_utils.get_node_supertype(dtype)
685 dtype2 = dtype.add_data_type(0,
"MyCustomDataType2")
686 node = ua_utils.get_node_supertype(dtype2)
690 nint32 = self.opc.get_node(ua.ObjectIds.Int32)
691 dtype = nint32.add_data_type(0,
"MyCustomDataType")
692 dtype2 = dtype.add_data_type(0,
"MyCustomDataType2")
693 self.
assertEqual(ua_utils.get_base_data_type(dtype), nint32)
694 self.
assertEqual(ua_utils.get_base_data_type(dtype2), nint32)
696 ext = self.opc.nodes.objects.add_variable(0,
"MyExtensionObject", ua.Argument())
697 d = ext.get_data_type()
698 d = self.opc.get_node(d)
699 self.
assertEqual(ua_utils.get_base_data_type(d), self.opc.get_node(ua.ObjectIds.Structure))
700 self.
assertEqual(ua_utils.data_type_to_variant_type(d), ua.VariantType.ExtensionObject)
def test_get_node_by_nodeid(self)
def test_simple_value(self)
def test_instantiate_1(self)
def test_non_existing_path(self)
def test_method_array2(self)
def test_add_string_array_variable(self)
def test_datetime_write(self)
def test_delete_nodes_recursive(self)
def test_incl_subtypes(self)
def test_references_for_added_nodes(self)
def test_supertypes(self)
def test_browsename_with_spaces(self)
def test_bool_variable(self)
def instantiate(parent, node_type, nodeid=None, bname=None, idx=0)
def test_method_array(self)
def test_add_string_variable(self)
def test_variable_with_datatype(self)
def test_bad_attribute(self)
def test_null_variable(self)
def test_add_node_bad_args(self)
def test_add_numeric_variable(self)
def test_add_string_node(self)
def test_use_namespace(self)
def test_path_string(self)
def test_add_read_node(self)
def test_base_data_type(self)
def test_array_size_one_value(self)
def add_server_methods(srv)
def test_datetime_read(self)
def test_add_node_with_type(self)
def test_get_endpoints(self)
def test_delete_nodes_recursive2(self)
def test_negative_value(self)
def func(parent, variant)
def test_add_find_node_(self)
def test_browse_references(self)
def test_array_value(self)
def test_read_server_state(self)
def test_delete_nodes(self)
def test_variant_array_dim(self)
def test_instantiate_string_nodeid(self)
def copy_node(parent, node, nodeid=None, recursive=True)
def test_add_exception(self)
def test_server_node(self)
def test_find_servers(self)
def test_add_numeric_node(self)
def test_variable_data_type(self)