Esempio n. 1
0
    def _show_structs(self):
        base_struct = self.server_mgr.get_node(ua.ObjectIds.Structure)
        opc_binary = self.server_mgr.get_node(
            ua.ObjectIds.OPCBinarySchema_TypeSystem)
        opc_schema = self.server_mgr.get_node(ua.ObjectIds.OpcUa_BinarySchema)
        for node in opc_binary.get_children():
            if node == opc_schema:
                continue  # This is standard namespace structures
            try:
                ns = node.get_child("0:NamespaceUri").get_value()
                ar = self.server_mgr.get_namespace_array()
                idx = ar.index(ns)
            except ua.UaError:
                idx = 1
            xml = node.get_value()
            if not xml:
                return

            xml = xml.decode("utf-8")
            generator = StructGenerator()
            generator.make_model_from_string(xml)
            for el in generator.model:
                # we only care about structs, ignoring enums
                if isinstance(el, Struct):
                    self._add_design_node(base_struct, idx, el)
Esempio n. 2
0
 def test_structs_save_and_import(self):
     xmlpath = "tests/example.bsd"
     c = StructGenerator()
     c.make_model_from_file(xmlpath)
     struct_dict = c.save_and_import("structures.py")
     for k, v in struct_dict.items():
         a = v()
         self.assertEqual(k, a.__class__.__name__)
Esempio n. 3
0
 def test_structs_save_and_import(self):
     xmlpath = "tests/example.bsd"
     c = StructGenerator()
     c.make_model_from_file(xmlpath)
     struct_dict = c.save_and_import("structures.py")
     for k, v in struct_dict.items():
         a = v()
         self.assertEqual(k, a.__class__.__name__)
Esempio n. 4
0
    def test_custom_structs_array(self):
        xmlpath = "tests/example.bsd"
        c = StructGenerator()
        c.make_model_from_file(xmlpath)
        c.save_to_file("tests/structures.py")
        import structures as s

        # test with default values
        v = s.ArrayValueDataType()
        data = struct_to_binary(v)
        v2 = struct_from_binary(s.ArrayValueDataType, ua.utils.Buffer(data))


        # set some values
        v = s.ArrayValueDataType()
        v.SbyteValue = [1]
        v.ByteValue = [2]
        v.Int16Value = [3]
        v.UInt16Value = [4]
        v.Int32Value = [5]
        v.UInt32Value = [6]
        v.Int64Value = [7]
        v.UInt64Value = [8]
        v.FloatValue = [9.0]
        v.DoubleValue = [10.0]
        v.StringValue = ["elleven"]
        v.DateTimeValue = [datetime.utcnow()]
        #self.GuidValue = uuid.uudib"14"
        v.ByteStringValue = [b"fifteen", b"sixteen"]
        v.XmlElementValue = [ua.XmlElement("<toto>titi</toto>")]
        v.NodeIdValue = [ua.NodeId.from_string("ns=4;i=9999"), ua.NodeId.from_string("i=6")]
        #self.ExpandedNodeIdValue =
        #self.QualifiedNameValue =
        #self.LocalizedTextValue =
        #self.StatusCodeValue =
        #self.VariantValue =
        #self.EnumerationValue =
        #self.StructureValue =
        #self.Number =
        #self.Integer =
        #self.UInteger =


        data = struct_to_binary(v)
        v2 = struct_from_binary(s.ArrayValueDataType, ua.utils.Buffer(data))
        self.assertEqual(v.NodeIdValue, v2.NodeIdValue)
        print(v2.NodeIdValue)
Esempio n. 5
0
    def test_custom_structs(self):
        xmlpath = "tests/example.bsd"
        c = StructGenerator()
        c.make_model_from_file(xmlpath)
        c.save_to_file("tests/structures.py")
        import structures as s

        # test with default values
        v = s.ScalarValueDataType()
        data = struct_to_binary(v)
        v2 = struct_from_binary(s.ScalarValueDataType, ua.utils.Buffer(data))


        # set some values
        v = s.ScalarValueDataType()
        v.SbyteValue = 1
        v.ByteValue = 2
        v.Int16Value = 3
        v.UInt16Value = 4
        v.Int32Value = 5
        v.UInt32Value = 6
        v.Int64Value = 7
        v.UInt64Value = 8
        v.FloatValue = 9.0
        v.DoubleValue = 10.0
        v.StringValue = "elleven"
        v.DateTimeValue = datetime.utcnow()
        #self.GuidValue = uuid.uudib"14"
        v.ByteStringValue = b"fifteen"
        v.XmlElementValue = ua.XmlElement("<toto>titi</toto>")
        v.NodeIdValue = ua.NodeId.from_string("ns=4;i=9999")
        #self.ExpandedNodeIdValue =
        #self.QualifiedNameValue =
        #self.LocalizedTextValue =
        #self.StatusCodeValue =
        #self.VariantValue =
        #self.EnumerationValue =
        #self.StructureValue =
        #self.Number =
        #self.Integer =
        #self.UInteger =


        data = struct_to_binary(v)
        v2 = struct_from_binary(s.ScalarValueDataType, ua.utils.Buffer(data))
        self.assertEqual(v.NodeIdValue, v2.NodeIdValue)
Esempio n. 6
0
    def _show_structs(self):
        base_struct = self.server_mgr.get_node(ua.ObjectIds.Structure)
        opc_binary = self.server_mgr.get_node(ua.ObjectIds.OPCBinarySchema_TypeSystem)
        opc_schema = self.server_mgr.get_node(ua.ObjectIds.OpcUa_BinarySchema)
        for node in opc_binary.get_children():
            if node == opc_schema:
                continue  # This is standard namespace structures
            try:
                ns = node.get_child("0:NamespaceUri").get_value()
                ar = self.server_mgr.get_namespace_array()
                idx = ar.index(ns)
            except ua.UaError:
                idx = 1
            xml = node.get_value()
            if not xml:
                return

            xml = xml.decode("utf-8")
            generator = StructGenerator()
            generator.make_model_from_string(xml)
            for el in generator.model:
                # we only care about structs, ignoring enums
                if isinstance(el, Struct):
                    self._add_design_node(base_struct, idx, el)
Esempio n. 7
0
    def test_custom_structs_array(self):
        xmlpath = "tests/example.bsd"
        c = StructGenerator()
        c.make_model_from_file(xmlpath)
        c.save_to_file("tests/structures.py")
        import structures as s

        # test with default values
        v = s.ArrayValueDataType()
        data = struct_to_binary(v)
        v2 = struct_from_binary(s.ArrayValueDataType, ua.utils.Buffer(data))

        # set some values
        v = s.ArrayValueDataType()
        v.SbyteValue = [1]
        v.ByteValue = [2]
        v.Int16Value = [3]
        v.UInt16Value = [4]
        v.Int32Value = [5]
        v.UInt32Value = [6]
        v.Int64Value = [7]
        v.UInt64Value = [8]
        v.FloatValue = [9.0]
        v.DoubleValue = [10.0]
        v.StringValue = ["elleven"]
        v.DateTimeValue = [datetime.utcnow()]
        #self.GuidValue = uuid.uudib"14"
        v.ByteStringValue = [b"fifteen", b"sixteen"]
        v.XmlElementValue = [ua.XmlElement("<toto>titi</toto>")]
        v.NodeIdValue = [
            ua.NodeId.from_string("ns=4;i=9999"),
            ua.NodeId.from_string("i=6")
        ]
        #self.ExpandedNodeIdValue =
        #self.QualifiedNameValue =
        #self.LocalizedTextValue =
        #self.StatusCodeValue =
        #self.VariantValue =
        #self.EnumerationValue =
        #self.StructureValue =
        #self.Number =
        #self.Integer =
        #self.UInteger =

        data = struct_to_binary(v)
        v2 = struct_from_binary(s.ArrayValueDataType, ua.utils.Buffer(data))
        self.assertEqual(v.NodeIdValue, v2.NodeIdValue)
        print(v2.NodeIdValue)
Esempio n. 8
0
 def test_custom_struct_with_optional_fields(self):
     xmlpath = "custom_extension_with_optional_fields.xml"
     c = StructGenerator()
     c.make_model_from_file(xmlpath)
     for m in c.model:
         if type(m) in (Struct, EnumType):
             m.typeid = self._generate_node_id()
     c.save_to_file("custom_extension_with_optional_fields.py", register=True)
     import como_structures as s
     for name, obj in inspect.getmembers(sys.modules[s.__name__], predicate=inspect.isclass):
         if name.startswith('__') or obj in (datetime,) or isinstance(obj, EnumMeta):
             continue
         with self.subTest(name=name):
             original = obj()
             serialized = struct_to_binary(original)
             deserialized = struct_from_binary(obj, ua.utils.Buffer(serialized))
             self.assertCustomStructEqual(original, deserialized)
Esempio n. 9
0
    def test_custom_structs(self):
        xmlpath = "tests/example.bsd"
        c = StructGenerator()
        c.make_model_from_file(xmlpath)
        c.save_to_file("structures.py")
        import structures as s

        # test with default values
        v = s.ScalarValueDataType()
        data = v.to_binary()
        v2 = s.ScalarValueDataType.from_binary(ua.utils.Buffer(data))


        # set some values
        v = s.ScalarValueDataType()
        v.SbyteValue = 1
        v.ByteValue = 2
        v.Int16Value = 3
        v.UInt16Value = 4
        v.Int32Value = 5
        v.UInt32Value = 6
        v.Int64Value = 7
        v.UInt64Value = 8
        v.FloatValue = 9.0
        v.DoubleValue = 10.0
        v.StringValue = "elleven"
        v.DateTimeValue = datetime.utcnow()
        #self.GuidValue = uuid.uudib"14"
        v.ByteStringValue = b"fifteen"
        v.XmlElementValue = ua.XmlElement("<toto>titi</toto>")
        v.NodeIdValue = ua.NodeId.from_string("ns=4;i=9999")
        #self.ExpandedNodeIdValue =
        #self.QualifiedNameValue =
        #self.LocalizedTextValue =
        #self.StatusCodeValue =
        #self.VariantValue =
        #self.EnumerationValue =
        #self.StructureValue =
        #self.Number =
        #self.Integer =
        #self.UInteger =


        data = v.to_binary()
        v2 = s.ScalarValueDataType.from_binary(ua.utils.Buffer(data))
        self.assertEqual(v.NodeIdValue, v2.NodeIdValue)