public object ReadRecord(int DglbId, Type type)
        {
            BinarySerializer serializer = new BinarySerializer(new Type[] { type });
            uint readCount;

            //Code for reading record
            try
            {
                readCount = serializer.GetSerializedDataLength();
            }
            catch (SerializerException e)
            {
                throw new CommunicationException("Problems with getting length of serialized data", e);
            }

            //Here we read record
            UInt16[] receivedData = new UInt16[readCount / 2];
            BPModbusDecoder decoder = new BPModbusDecoder(receivedData, DglbId, (int)DevMgmtS_dcte.mgmt_cmd.DGLB_RD_FIRST);
            decoder._data = ReadData(DglbId, readCount);

            //Here we deserialize record
            try
            {
                return serializer.DeserializeData(decoder.data)[0];
            }
            catch (SerializerException e)
            {
                throw new CommunicationException("Problems with deserialization", e);
            }
        }
Beispiel #2
0
        public void TestMediumImport()
        {
            int offset = 0;
            BinarySerializer serializer = new BinarySerializer();
            serializer.SetSerializableTypes(new Type[] { typeof(string), typeof(Int16), typeof(UInt32), typeof(Int16), typeof(string) });
            Byte[] export = serializer.SerializeData(new object[] { "abcd", 100, 100000, 900, "defghi" });
            object[] import = serializer.DeserializeData(export,0,ref offset);

            Assert.AreEqual(new object[] { "abcd", (UInt16)100, (UInt32)100000, (UInt16)900, "defghi" }, import, "defghi");
            Assert.AreEqual(20, offset);
        }
Beispiel #3
0
        public void TestManyParse()
        {
            BinarySerializer serializer = new BinarySerializer();
            serializer.SetSerializableTypes(new Type[] { typeof(VarByte), typeof(UInt16) });
            object[] TestData= new object[]{ 5, 1, 2, 3, 4, 5 };

            Byte[] export = serializer.SerializeData(TestData);
            int offset=0;
            object[] import = serializer.DeserializeData(export, 0, ref offset);

            Assert.AreEqual(TestData, import);

            serializer.SetSerializableTypes(new Type[] { typeof(VarUInt32), typeof(string), typeof(Int16), typeof(VarUInt16), typeof(Byte) });
            TestData = new object[] { 5, "a", "b", "c", "d", "e", 10, 3, 1, 2, 3 };
            export = serializer.SerializeData(TestData);
            offset = 0;
            import = serializer.DeserializeData(export, 0, ref offset);

            Assert.AreEqual(TestData, import);
        }
Beispiel #4
0
        public void TestClassParse()
        {
            BinarySerializer serializer = new BinarySerializer(new Type[] { typeof(test2) });
            test2 t2= new test2();
            t2.a1=1;
            t2.a2=2;
            t2.a3=3;
            t2.a4=4;

            int off = 0;
            byte[] serData= serializer.SerializeData(new object[] { t2 });
            test2 desData = (test2)serializer.DeserializeData(serData, 0, ref off)[0];

            Assert.AreEqual(t2.a1, desData.a1);
            Assert.AreEqual(t2.a2, desData.a2);
            Assert.AreEqual(t2.a3, desData.a3);
            Assert.AreEqual(t2.a4, desData.a4);
        }
Beispiel #5
0
        public void TestByteSerialize()
        {
            int offset = 0;
            BinarySerializer serializer = new BinarySerializer();
            serializer.SetSerializableTypes(new Type[] { typeof(Byte[]) });

            Byte[] input = new Byte[] { 1, 2, 3, 4, 5 };
            Byte[] export = serializer.SerializeData(new object[] { input });

            object[] import = serializer.DeserializeData(export, 0, ref offset);
            Assert.AreEqual(input, import[0]);
        }
Beispiel #6
0
        public void TestBasicImport()
        {
            int offset = 0;
            BinarySerializer serializer = new BinarySerializer(new Type[] { typeof(UInt16) });
            Byte[] export = serializer.SerializeData(new object[] { 1 });
            object[] import = serializer.DeserializeData(export,0,ref offset);

            Assert.AreEqual(new object[] { (UInt16)1 }, import);
            Assert.AreEqual(2, offset);
        }