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));
        }
Ejemplo n.º 2
0
        public void TestHasMoreData()
        {
            DbDacDataProvider           p    = new DbDacDataProvider();
            Dictionary <string, string> args = new Dictionary <string, string>();

            args.Add("dbcongxml", this.path);
            p.Init(args);
            // 5.
            ISqlHelper sqlHelper = SqlHelperFactory.Create(DbType.MSSQL, "Initial Catalog=DW_iSecureCloud_Empty;Data Source=192.168.1.128;User Id=sa;Password=861004");

            sqlHelper.Query("update T_THEMES_ENVI_WIND set lastSyncTime = null");
            int count = 0;

            Assert.IsTrue(p.HasMoreData());
            Console.WriteLine("TotalReminder: {0} records.", p.Remainder);
            Assert.IsTrue(p.Remainder > 0);
            count = p.Remainder;
            int len = 0;

            TranMsg[] msgs = p.NextPackages(out len);
            Assert.IsNotNull(msgs);
            byte[] buff = msgs[0].Data;
            Console.WriteLine(ValueHelper.BytesToHexStr(buff, 0, len, ""));
            // Record 4.
            Assert.IsTrue(len > 0);
            Console.WriteLine("len: {0}", len);
            // Data Sent
            p.OnPackageSent();
            var ds =
                sqlHelper.Query("select count(ID) from T_THEMES_ENVI_WIND where lastSyncTime is null");
            int count2 = Convert.ToInt32(ds.Tables[0].Rows[0][0]);
            int rows   = 1024 / (3 * 8 + 15);

            Assert.AreEqual(rows, count - count2 + 1);
        }
Ejemplo n.º 3
0
        public void TestSpliter()
        {
            DbDacDataProvider           p    = new DbDacDataProvider();
            Dictionary <string, string> args = new Dictionary <string, string>();

            args.Add("dbcongxml", this.path);
            p.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[] buff   = new byte[39];
            int    writed = p.DataToSegment(d, buff, 0);

            TranMsg[] msgs = p.Splite(buff, writed);
            Assert.AreEqual(1, msgs.Length);
            Console.WriteLine("MSG1={0}", ValueHelper.BytesToHexStr(msgs[0].Marshall()));
        }
        public void TestHasMoreData()
        {
            DbDacDataProvider           p    = new DbDacDataProvider();
            Dictionary <string, string> args = new Dictionary <string, string>();

            args.Add("sqlitedbcongxml", this.path);
            p.Init_Sqlite(args);
            // 5.
            // var cs = connstr.Split(',');
            LoadDbConfigXml lc = new LoadDbConfigXml(this.path);

            string[] sonstr = lc.GetSqlConnectionStrings("/config/databases");

            ISqlHelper sqlHelper = SqlHelperFactory.Create(DbType.SQLite, sonstr[0]);

            sqlHelper.Query("update D_OriginalWindData set lastSyncTime = null");

            Assert.IsTrue(p.HasMoreData());
            Console.WriteLine("TotalReminder: {0} records.", p.Remainder);
            Assert.IsTrue(p.Remainder > 0);

            int len = 0;

            TranMsg[] msgs = p.NextPackages(out len);
            Assert.IsNotNull(msgs);
            byte[] buff = msgs[0].Data;
            Console.WriteLine(ValueHelper.BytesToHexStr(buff, 0, len, ""));
            // Record 4.
            Assert.IsTrue(len > 0);

            // Data Sent
            p.OnPackageSent();

            var ds =
                sqlHelper.Query("select count(ID) from D_OriginalWindData where lastSyncTime is null");

            Assert.AreEqual(0, Convert.ToInt32(ds.Tables[0].Rows[0][0]));
        }
Ejemplo n.º 5
0
        public void TestSend()
        {
            // DAC.Test.Tran.TranDataSenderTester.TestSend
            Dictionary <string, string> args = new Dictionary <string, string>();

            args["PortName"]        = "COM1"; //COM6-COM13
            args["BaudRate"]        = "9600";
            args["Parity"]          = Convert.ToString((int)Parity.None);
            args["DataBits"]        = "8";
            args["StopBits"]        = Convert.ToString((int)StopBits.One);
            args["ReadTimeOut"]     = "1";       // 1ms
            args["sqlitedbcongxml"] = this.path; //SQLite用
            args["DataPath"]        = "VibData"; //振动用

            var provider1 = new DbDacDataProvider();
            ITranDataSendDelegator comSender = new ComDataSender
            {
                DtuCode = 20120049
            };

            comSender.Init(args);
            provider1.Init_Sqlite(args);
            ITranDataProvider provider2 = new VibFileDataProvider();

            provider2.Init(args);

            TranDataSender sender = new TranDataSender(comSender, provider1, provider2);

            sender.OnMessageSent += (TranMsg req, TranMsg resp) =>
            {
                int len = resp.LoadSize;
                Console.WriteLine("Data received. {0}: {1}", len, ValueHelper.BytesToHexStr(resp.Data));
            };
            sender.DoWork();

            Console.ReadLine();
            // SQLiteDataSpliter
        }
        public void TestSpliter()
        {
            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);

            TranMsg[] msgs = p.Splite(buff, writed);
            Assert.AreEqual(1, msgs.Length);
            Console.WriteLine("MSG1={0}", ValueHelper.BytesToHexStr(msgs[0].Marshall()));
        }
Ejemplo n.º 7
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));
        }