public void TestDataToSegment()
        {
            DbDacDataProvider           p    = new DbDacDataProvider();
            Dictionary <string, string> args = new Dictionary <string, string>();

            args.Add("sqlitedbcongxml", this.path);
            p.Init_Sqlite(args);
            var d = new SensorOriginalData
            {
                AcqTime   = System.DateTime.Now,
                ModuleNo  = 12,
                ChannelNo = 23,
                Type      = ProtocolType.VibratingWire,
                Values    = new double[] { 1924, 12.340000d, 2.340000d }
            };

            byte[] buff   = new byte[39];
            int    writed = p.DataToSegment(d, buff, 0);

            Assert.AreEqual(39, writed);
            Assert.AreEqual(ProtocolType.VibratingWire, (uint)ValueHelper.GetShort(buff, 0));
            Assert.AreEqual(1924, ValueHelper.GetDouble(buff, 15));
            Assert.AreEqual(12.34f, ValueHelper.GetDouble(buff, 23));
            Assert.AreEqual(2.34f, ValueHelper.GetDouble(buff, 31));

            Assert.AreEqual(23, p.CalcDataLength(1));
            Assert.AreEqual(31, p.CalcDataLength(2));
            Assert.AreEqual(39, p.CalcDataLength(3));
            Assert.AreEqual(47, p.CalcDataLength(4));
            Assert.AreEqual(55, p.CalcDataLength(5));

            Console.WriteLine("buff={0}", ValueHelper.BytesToHexStr(buff));
        }
示例#2
0
        public void TestDataToSegment()
        {
            DbDacDataProvider           dp   = new DbDacDataProvider();
            Dictionary <string, string> args = new Dictionary <string, string>();

            args.Add("dbcongxml", this.path);
            dp.Init(args);

            var d = new SensorOriginalData
            {
                AcqTime = DateTime.Now,
                SID     = 108,
                Type    = ProtocolType.GPS_ZHD,
                Values  = new double[]
                {
                    2.134, 1.945, 1.07
                }
            };

            byte[] bytes  = new byte[39];
            int    writed = dp.DataToSegment(d, bytes, 0);

            Assert.AreEqual(39, writed);

            Assert.AreEqual(ProtocolType.GPS_ZHD, (uint)ValueHelper.GetShort(bytes, 0));
            Assert.AreEqual(2.134f, ValueHelper.GetDouble(bytes, 15));
            Assert.AreEqual(1.945f, ValueHelper.GetDouble(bytes, 23));
            Assert.AreEqual(1.07f, ValueHelper.GetDouble(bytes, 31));

            Assert.AreEqual(23, dp.CalcDataLength(1));
            Assert.AreEqual(31, dp.CalcDataLength(2));
            Assert.AreEqual(39, dp.CalcDataLength(3));
            Assert.AreEqual(47, dp.CalcDataLength(4));
            Assert.AreEqual(55, dp.CalcDataLength(5));

            Console.WriteLine("buff={0}", ValueHelper.BytesToHexStr(bytes));
        }