コード例 #1
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()));
        }
コード例 #2
0
        public void TestRequest()
        {
            ISensorAdapter sa = new VibratingWireSensorAdapter();
            Sensor         s  = new Sensor()
            {
                ModuleNo  = 5864,
                ChannelNo = 1
            };
            int err;
            var r = this.GetSensorAcqResult();

            r.Sensor = s;
            sa.Request(ref r);
            byte[] buff = r.Request;
            Assert.AreEqual("00 0a 16 e8 01 01 67 73 76", ValueHelper.BytesToHexStr(buff));

            Sensor s2 = new Sensor()
            {
                ModuleNo  = 5135,
                ChannelNo = 1
            };

            r.Sensor = s2;
            sa.Request(ref r);
            buff = r.Request;
            Assert.AreEqual("00 0a 14 0f 01 01 67 07 39", ValueHelper.BytesToHexStr(buff));
        }
コード例 #3
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);
        }
コード例 #4
0
         public void ParseResult(ref SensorAcqResult rawData)
         {
             rawData.ErrorCode = IsValid(rawData.Response);
             if ((int)Errors.SUCCESS != rawData.ErrorCode)
                 return;
             int module = (int) ((rawData.Response[IDX_ADRESS] << 8) | (rawData.Response[1 + IDX_ADRESS]));
             if (module != rawData.Sensor.ModuleNo)
             {
                 rawData.ErrorCode = (int)Errors.ERR_INVALID_MODULE;
                 return;
             }
             int channel = Convert.ToInt16(rawData.Response[IDX_Req]);
             if (channel != rawData.Sensor.ChannelNo)
             {
                 rawData.ErrorCode = (int)Errors.ERR_RECEIVED_CH;
                 return;
             }
             try
             {
                 var capvol = (rawData.Response[IDX_CAPVOL] << 8) | rawData.Response[IDX_CAPVOL + 1];
                 var voltage = ValueHelper.GetFloat(rawData.Response, IDX_VOLTAGE);
                 var temp = ValueHelper.GetFloat(rawData.Response, IDX_TEMP);
                 double force = 0;
                 if (rawData.Sensor.FormulaID == 4 && rawData.Sensor.Parameters != null &&
                     rawData.Sensor.Parameters.Count == 7)
                 {
                     double kt = rawData.Sensor.Parameters[0].Value;
                     double t0 = rawData.Sensor.Parameters[1].Value;
                     double v0 = rawData.Sensor.Parameters[2].Value;
                     double v0B = rawData.Sensor.Parameters[3].Value;
                     double c0 = rawData.Sensor.Parameters[4].Value;
                     double c1 = rawData.Sensor.Parameters[5].Value;
                     double c2 = rawData.Sensor.Parameters[6].Value;

                     double vol = voltage - kt*(temp - t0) - (v0 - v0B);
                     double phy = c2*Math.Pow(vol, 2) + c1*vol + c0;
                     force = phy;
                 }
                 var raws = new double[] { voltage, temp };
                 var phys = new double[] { force };
                 
                 rawData.Data = new SensorData(raws, phys, phys)
                 {
                     JsonResultData = string.Format("{0}\"sensorId\":{1},\"data\":\"电压:{2} V, 温度:{3} ℃\"{4}", '{', rawData.Sensor.SensorID, voltage, temp, '}')
                 }; 
                 //rawData.Data = new MagneticFluxData(voltage, temp, force)
                 //{
                 //    JsonResultData =
                 //        string.Format("{0}\"sensorId\":{1},\"data\":\"电压:{2} V, 温度:{3} ℃\"{4}", '{',
                 //            rawData.Sensor.SensorID, voltage, temp, '}')
                 //};
             }
             catch (Exception ex)
             {
                 rawData.ErrorCode = (int)Errors.ERR_DATA_PARSEFAILED;
                 _logger.ErrorFormat("ctl sensor [Id:{0} m: {1} ch:{2}] parsedfailed,received bytes{3}, ERROR: {4}",
                         rawData.Sensor.SensorID, rawData.Sensor.ModuleNo, rawData.Sensor.ChannelNo,
                         ValueHelper.BytesToHexStr(rawData.Response), ex.Message);
             }
         }
コード例 #5
0
        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));
        }
コード例 #6
0
 public void DoWork()
 {
     this.started = System.DateTime.Now.Ticks;
     while (!this.dataReceived)
     {
         if (this._comconn.IsTimeOut(this.started, this.timeout))
         {
             this.Log.ErrorFormat("Timeout!");
             break;
         }
         Thread.Sleep(10);
     }
     if (!this.dataReceived)
     {
         this.Log.ErrorFormat("[{0}] Timeout: ({1} seconds)", this.port.PortName, this.timeout);
     }
     else
     {
         this.receivedMsg.Elapsed = (System.DateTime.Now.Ticks - this.started) / 10000; //ms
         this.Log.InfoFormat("[{0}] Msg received in {1} ms, {2}:{3}",
                             this.port.PortName, this.receivedMsg.Elapsed, this.receivedMsg.Databuffer.Length,
                             ValueHelper.BytesToHexStr(this.receivedMsg.Databuffer, 0, ""));
     }
     this.Log.Info("Send task finished");
 }
コード例 #7
0
        public void TestGetAdapter()
        {
            IAdapterManager adapterManager = SensorAdapterManager.InitializeManager();

            Assert.IsNotNull(adapterManager);

            Assert.IsNull(SensorAdapterManager.InitializeManager("abcdedfg"));

            Assert.IsNotNull(adapterManager.GetSensorAdapter(ProtocolType.Voltage));

            Assert.IsNull(adapterManager.GetSensorAdapter(ProtocolType.TempHumidity_OLD));

            Assert.IsNull(adapterManager.GetSensorAdapter((uint)1234567));

            string str = "24 32 33 52 50 31 33 32 0d";
            Sensor s   = new Sensor()
            {
                ModuleNo     = 23,
                ChannelNo    = 1,
                ProtocolType = (uint)ProtocolType.Pressure_MPM
            };
            int err;
            var r = this.GetSensorAcqResult();

            r.Sensor = s;
            adapterManager.GetSensorAdapter(s.ProtocolType).Request(ref r);
            byte[] req = r.Request;
            Assert.AreEqual(str, ValueHelper.BytesToHexStr(req));
        }
コード例 #8
0
ファイル: TranMsg.cs プロジェクト: icprog/FS-SMISCloud
        private bool IsValid(byte[] buff)
        {
            if (buff == null || buff.Length <= InfoSize)
            {
                ErrorCode = (int)Errors.ERR_INVALID_DATA;
                ErrorMsg  = string.Format("Invalid msg: null or too short: {0}", buff != null ? buff.Length : 0);
                Log.Debug(ErrorMsg + ":" + ValueHelper.BytesToHexStr(buff));
                return(false);
            }
            if (buff[0] != ByteHead || buff[buff.Length - 1] != ByteTail)
            {
                ErrorCode = (int)Errors.ERR_INVALID_DATA;
                ErrorMsg  = string.Format("Invalid TranMsg format: HEAD/TAIL error: len={0}, H={1},T={2}", buff.Length,
                                          buff[0], buff[buff.Length - 1]);
                Log.DebugFormat(ErrorMsg);
                return(false);
            }
            byte crc8 = ValueHelper.CheckCRC8(buff, 0, buff.Length - 3);

            if (crc8 != buff[buff.Length - 2])
            {
                ErrorCode = (int)Errors.ERR_INVALID_DATA;
                ErrorMsg  = string.Format("CRC Error: {0}!={1}", crc8, buff[buff.Length - 2]);
                Log.DebugFormat(ErrorMsg);
                return(false);
            }
            ErrorCode = (int)Errors.SUCCESS;
            return(true);
        }
コード例 #9
0
        public void ParseResult(ref SensorAcqResult rawData)
        {
            rawData.ErrorCode = IsValid(rawData.Response);
            if (rawData.ErrorCode != (int)Errors.SUCCESS)
            {
                return;
            }
            short mno = ValueHelper.GetShort_BE(rawData.Response, 2);

            if (mno != rawData.Sensor.ModuleNo)
            {
                rawData.ErrorCode = (int)Errors.ERR_INVALID_MODULE;
                return;
            }
            switch (rawData.Response[IDX_CMD])
            {
            case 0x81:     // 采集命令回复
                try
                {
                    var surveyXAng = ValueHelper.GetInt_BE(rawData.Response, 13) / 1000000f;
                    var surveyYAng = ValueHelper.GetInt_BE(rawData.Response, 17) / 1000000f;

                    double changeX = 0;
                    double changeY = 0;
                    if (rawData.Sensor.Parameters != null && rawData.Sensor.Parameters.Count == 3)
                    {
                        double xinit  = rawData.Sensor.Parameters[0].Value;
                        double yinit  = rawData.Sensor.Parameters[1].Value;
                        double len    = rawData.Sensor.Parameters[2].Value;
                        var    xvalue = (len * Math.Sin(surveyXAng * Math.PI / 180)) - (len * Math.Sin(xinit * Math.PI / 180));
                        var    yvalue = (len * Math.Sin(surveyYAng * Math.PI / 180)) - (len * Math.Sin(yinit * Math.PI / 180));
                        changeX = xvalue;
                        changeY = yvalue;
                    }

                    var raws = new double[] { surveyXAng, surveyYAng };
                    var phys = new double[] { changeX, changeY };

                    rawData.Data = new SensorData(raws, phys, raws)
                    {
                        JsonResultData = string.Format("{0}\"sensorId\":{1},\"data\":\"X方向角度:{2} °,Y方向角度:{3} °\"{4}", '{', rawData.Sensor.SensorID, surveyXAng, surveyYAng, '}')
                    };
                }
                catch (Exception ex)
                {
                    rawData.ErrorCode = (int)Errors.ERR_DATA_PARSEFAILED;
                    _logger.ErrorFormat(
                        "rod Inclination sensor [Id:{0} m: {1}] parsedfailed,received bytes{2}, ERROR: {3}",
                        rawData.Sensor.SensorID, rawData.Sensor.ModuleNo,
                        ValueHelper.BytesToHexStr(rawData.Response), ex.Message);
                }
                break;

            case 0xC0:     // 回复错误码
                rawData.ErrorCode = ModbusErrorCode.GetErrorCode(rawData.Response[IDX_CMD + 1]);
                break;
            }
        }
コード例 #10
0
        public void TestHeartBeatTranMsg()
        {
            HeartBeatTranMsg msg2 = new HeartBeatTranMsg(20120049, 10);
            string           str  = ValueHelper.BytesToHexStr(msg2.Marshall());

            Assert.IsNotNull(str);
            // fa 00 01 00 01 0a 00 ff 32 30 31 32 30 30 34 39 0a 00 4b af
            Console.WriteLine(str);
        }
コード例 #11
0
        public void ParseResult(ref SensorAcqResult rawData)
        {
            rawData.ErrorCode = IsValid(rawData);
            if (rawData.ErrorCode != (int)Errors.SUCCESS)
            {
                return;
            }
            uint moudle = rawData.Response[0];

            if (moudle != rawData.Sensor.ModuleNo)
            {
                rawData.ErrorCode = (int)Errors.ERR_INVALID_MODULE;
                return;
            }
            Encoding enc     = new ASCIIEncoding();
            string   datastr = enc.GetString(rawData.Response);

            try
            {
                datastr = datastr.Substring(3, datastr.Length - 4);
                if (datastr.ToCharArray().All(c => DataChars.Contains(c)))
                {
                    double len       = Convert.ToDouble(datastr);
                    double changelen = len - rawData.Sensor.Parameters[0].Value;
                    if (rawData.Sensor.FormulaID == 22)
                    {
                        changelen *= -1;
                    }
                    double[] raws = { len };
                    double[] phys = { changelen };

                    rawData.Data = new SensorData(raws, phys, raws)
                    {
                        JsonResultData = string.Format("{0}\"sensorId\":{1},\"data\":\"测量距离:{2} m\"{3}", '{', rawData.Sensor.SensorID, len, '}')
                    };
                    //rawData.Data = new LaserData(len, changelen)
                    //{
                    //    JsonResultData =
                    //        string.Format("{0}\"sensorId\":{1},\"data\":\"测量距离:{2} m\"{3}", '{',
                    //            rawData.Sensor.SensorID, len, '}')
                    //};
                }
                else
                {
                    rawData.ErrorCode = (int)Errors.ERR_GLS_RECEIVE;
                }
            }
            catch (Exception ex)
            {
                rawData.ErrorCode = (int)Errors.ERR_DATA_PARSEFAILED;
                _logger.ErrorFormat("GLSB Laser sensor [Id:{0} m:{1}]  parsedfailed,received bytes{2} ERROR: {3}", rawData.Sensor.SensorID, rawData.Sensor.ModuleNo,
                                    ValueHelper.BytesToHexStr(rawData.Response), ex.Message);
            }
        }
コード例 #12
0
        /// <summary>
        /// 解码: Sensor -> PC
        /// </summary>
        /// <param name="rawData"></param>
        /// <returns></returns>
        public void ParseResult(ref SensorAcqResult rawData)
        {
            byte[] data = rawData.Response;
            rawData.ErrorCode = IsValid(data);
            if ((int)Errors.SUCCESS != rawData.ErrorCode)
            {
                return;
            }
            var module = ValueHelper.GetShort_BE(data, IDX_DevId);

            if (module != rawData.Sensor.ModuleNo)
            {
                rawData.ErrorCode = (int)Errors.ERR_INVALID_MODULE;
                return;
            }
            try
            {
                var hum  = (data[IDX_Humidity] << 8 | data[IDX_Humidity + 1]) / 100.0;
                var temp = ValueHelper.GetFloat_BE(data, IDX_Temp);
                var raws = new double[] { temp, hum };
                rawData.Data = new SensorData(raws, raws, raws)
                {
                    JsonResultData =
                        string.Format(
                            "{0}\"sensorId\":{1},\"data\":\"温度:{2} ℃,湿度:{3} %\"{4}",
                            '{',
                            rawData.Sensor.SensorID,
                            temp,
                            hum,
                            '}')
                };

                //rawData.Data = new TempHumidityData(temp, hum)
                //{
                //    JsonResultData =
                //        string.Format(
                //            "{0}\"sensorId\":{1},\"data\":\"温度:{2} ℃,湿度:{3} %\"{4}",
                //            '{',
                //            rawData.Sensor.SensorID,
                //            temp,
                //            hum,
                //            '}')
                //};
            }
            catch (Exception ex)
            {
                rawData.ErrorCode = (int)Errors.ERR_DATA_PARSEFAILED;
                _logger.ErrorFormat(
                    "temphumi sensor [id:{0},m:{1}] parsedfailed ,received bytes{3},ERROR : {2}",
                    rawData.Sensor.SensorID, rawData.Sensor.ModuleNo, ex.Message,
                    ValueHelper.BytesToHexStr(rawData.Response));
            }
        }
コード例 #13
0
        public void TestBytes2HexStr()
        {
            byte[] bs = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, (byte)'a', (byte)'b', (byte)'c', (byte)'D' };
            Assert.AreEqual("00 01 02 03 04 05 06 07 08 09 00 61 62 63 44", ValueHelper.BytesToHexStr(bs));

            Assert.AreEqual("000102030405060708090061626344", ValueHelper.BytesToHexStr(bs, 0, bs.Length, ""));

            Assert.AreEqual("00", ValueHelper.BytesToHexStr(bs, 0, 1, ""));
            Assert.AreEqual("", ValueHelper.BytesToHexStr(bs, 0, 0, ""));

            Assert.AreEqual("44", ValueHelper.BytesToHexStr(bs, bs.Length - 1, 1, ""));
            Assert.AreEqual("63a44", ValueHelper.BytesToHexStr(bs, bs.Length - 2, 2, "a"));
        }
コード例 #14
0
        public void ParseResult(ref SensorAcqResult rawData)
        {
            byte[] data = rawData.Response;
            rawData.ErrorCode = IsValid(data);
            if ((int)Errors.SUCCESS != rawData.ErrorCode)
            {
                return;
            }
            var module = ValueHelper.GetShort_BE(data, IDX_DevId);

            if (module != rawData.Sensor.ModuleNo)
            {
                rawData.ErrorCode = (int)Errors.ERR_INVALID_MODULE;
                return;
            }
            try
            {
                switch (data[IDX_CMD])
                {
                case 0x81:
                    var temp     = ValueHelper.GetFloat_BE(data, IDX_DataField);
                    var humidity = ValueHelper.GetFloat_BE(data, IDX_DataField + 4);

                    var raws = new double[] { temp, humidity };
                    rawData.Data = new SensorData(raws, raws, raws)
                    {
                        JsonResultData =
                            string.Format(
                                "{0}\"sensorId\":{1},\"data\":\"温度:{2} ℃,湿度:{3} %\"{4}",
                                '{',
                                rawData.Sensor.SensorID,
                                temp,
                                humidity,
                                '}')
                    };
                    return;

                case 0xc0:
                    rawData.ErrorCode = ModbusErrorCode.GetErrorCode(rawData.Response[IDX_CMD + 1]);
                    return;
                }
            }
            catch (Exception ex)
            {
                rawData.ErrorCode = (int)Errors.ERR_DATA_PARSEFAILED;
                _logger.ErrorFormat(
                    "ModBus temphumi sensor [id:{0},m:{1}] parsedfailed ,received bytes{3},ERROR : {2}",
                    rawData.Sensor.SensorID, rawData.Sensor.ModuleNo, ex.Message,
                    ValueHelper.BytesToHexStr(rawData.Response));
            }
        }
コード例 #15
0
        public void TestMarshallerTranMsg()
        {
            TranMsg msg = new TranMsg
            {
                PackageIndex = 1,
                PackageCount = 2,
                LoadSize     = 4,
                Data         = new byte[] { 1, 2, 3, 4 },
                Type         = TranMsgType.Vib
            };

            byte[] bs = msg.Marshall();
            // fa 00 0b 01 02 00 04 ff 01 02 03 04 e3 af
            string bss = ValueHelper.BytesToHexStr(bs);

            Assert.IsNotNull(bss);
            Console.WriteLine(bss);

            TranMsg msg2 = new TranMsg();

            msg2.Unmarshall(ValueHelper.StrToToHexByte("fb 00 0b 01 02 00 04 ff 01 02 03 04 e3 af"));
            Assert.AreEqual((int)Errors.ERR_INVALID_DATA, msg2.ErrorCode);
            msg2.Unmarshall(ValueHelper.StrToToHexByte("fa 00 0b 01 02 00 04 ff 01 02 03 04 e3 ef"));
            Assert.AreEqual((int)Errors.ERR_INVALID_DATA, msg2.ErrorCode);
            msg2.Unmarshall(ValueHelper.StrToToHexByte("fa 00 0b 01 02 00 04 ff 01 02 03 04 ef af"));
            Assert.AreEqual((int)Errors.ERR_INVALID_DATA, msg2.ErrorCode);
            msg2.Unmarshall(ValueHelper.StrToToHexByte("fa 00 Eb 01 02 00 04 ff 01 02 03 04 e3 af"));
            Assert.AreEqual((int)Errors.ERR_INVALID_DATA, msg2.ErrorCode);

            msg2.Unmarshall(ValueHelper.StrToToHexByte(bss));


            Assert.AreEqual(msg.PackageCount, msg2.PackageCount);
            Assert.AreEqual(msg.PackageIndex, msg2.PackageIndex);
            Assert.AreEqual(msg.LoadSize, msg2.LoadSize);
            Assert.AreEqual(msg.ID, msg2.ID);
            Assert.AreEqual(msg.Type, msg2.Type);
        }
コード例 #16
0
        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]));
        }
コード例 #17
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
        }
コード例 #18
0
            public void OnDataReceived(object sender, SerialDataReceivedEventArgs e)
            {
                int byteToRead = this._comconn.ReceiveFrame(this.port, this.timeout);

                byte[] recByteBuffer = null;
                if (byteToRead > 0)
                {
                    recByteBuffer = new byte[byteToRead];
                    this.port.Read(recByteBuffer, 0, recByteBuffer.Length);
                    this.port.DiscardOutBuffer();
                    var name = ((SerialPort)sender).PortName;
                    this.Log.DebugFormat("[{0}] received: {1}", this.port.PortName, ValueHelper.BytesToHexStr(recByteBuffer));
                    this.receivedMsg = new DtuMsg
                    {
                        Databuffer  = recByteBuffer,
                        Refreshtime = System.DateTime.Now,
                        DtuId       = this.dtuId,
                        ErrorCode   = 0
                    };
                    this.port.DataReceived -= this.OnDataReceived;
                    this.dataReceived       = true;
                }
            }
コード例 #19
0
        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()));
        }
コード例 #20
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));
        }
コード例 #21
0
        public void ParseResult(ref SensorAcqResult rawData)
        {
            rawData.ErrorCode = IsValid(rawData.Response);
            if ((int)Errors.SUCCESS != rawData.ErrorCode)
            {
                return;
            }
            byte[] data   = rawData.Response;
            var    module = data[IDX_ADDRESS];

            if (module != rawData.Sensor.ModuleNo)
            {
                rawData.ErrorCode = (int)Errors.ERR_INVALID_MODULE;
                return;
            }
            try
            {
                if (data[IDX_CMD] == 0x04)
                {
                    var by = new byte[4];
                    Array.Copy(data, IDX_DATA, by, 0, 4);
                    var sign = 1;
                    if (by[0] >= 0x80)
                    {
                        by[0] = (byte)(by[0] & 0x7f);
                        sign  = -1;
                    }

                    var    integer             = (((by[0] & 0xffff) << 8) | by[1]) * sign;
                    var    decim               = (((by[2] & 0xffff) << 8) | by[3]) / 1000d * sign;
                    var    elongationIndicator = integer + decim;
                    double changeElongation    = elongationIndicator;
                    if (rawData.Sensor.Parameters.Count > 0)
                    {
                        var displacement = elongationIndicator - rawData.Sensor.Parameters[0].Value;
                        changeElongation = displacement;
                    }

                    var raws = new double[] { elongationIndicator };
                    var phys = new double[] { changeElongation };

                    rawData.Data = new SensorData(raws, phys, raws)
                    {
                        JsonResultData =
                            string.Format("{0}\"sensorId\":{1},\"data\":\"偏移量:{2} mm\"{3}", '{',
                                          rawData.Sensor.SensorID, elongationIndicator, '}')
                    };

                    //rawData.Data = new LVDTData(elongationIndicator, changeElongation)
                    //{
                    //    JsonResultData =
                    //        string.Format("{0}\"sensorId\":{1},\"data\":\"偏移量:{2} mm\"{3}", '{',
                    //            rawData.Sensor.SensorID, elongationIndicator, '}')
                    //};
                }
                else
                {
                    switch (data[IDX_CMD + 1])
                    {
                    case 0x01:
                    case 0x06:
                        rawData.ErrorCode = (int)Errors.ERR_LVDTXW_CMD;
                        break;

                    case 0x02:
                    case 0x03:
                    case 0x05:
                        rawData.ErrorCode = (int)Errors.ERR_LVDTXW_EAX;
                        break;

                    case 0x04:
                        rawData.ErrorCode = (int)Errors.ERR_LVDTXW_ACTION;
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                rawData.ErrorCode = (int)Errors.ERR_DATA_PARSEFAILED;
                _logger.ErrorFormat("xw lvdt sensor [Id:{0} m: {1}] parsedfailed,received bytes{2}, ERROR: {3}",
                                    rawData.Sensor.SensorID, rawData.Sensor.ModuleNo, ValueHelper.BytesToHexStr(rawData.Response),
                                    ex.Message);
            }
        }
コード例 #22
0
        public void TestRequest()
        {
            ISensorAdapter sa = new VibratingWire_OLD_SensorAdapter();
            // fe 54 46 4c 13 15 04 00 00 00 03 01 00 00 00 00 00 a0 ef
            // fe 54 46 4c 12 13 15 00 00 00 03 00 00 00 00 00 00 b7 ef
            int    err;
            Sensor s = new Sensor()
            {
                ModuleNo  = 5380,
                ChannelNo = 1
            };
            var r = this.GetSensorAcqResult();

            r.Sensor = s;
            sa.Request(ref r);
            byte[] buff = r.Request;
            Assert.AreEqual("fe 54 46 4c 13 15 04 00 00 00 03 01 00 00 00 00 00 a0 ef", ValueHelper.BytesToHexStr(buff));

            Sensor s2 = new Sensor()
            {
                ModuleNo  = 5135,
                ChannelNo = 1
            };

            r.Sensor = s2;
            sa.Request(ref r);
            byte[] buff2 = r.Request;
            Assert.AreEqual("fe 54 46 4c 13 14 0f 00 00 00 03 01 00 00 00 00 00 aa ef", ValueHelper.BytesToHexStr(buff2));
        }
コード例 #23
0
ファイル: Program.cs プロジェクト: icprog/FS-SMISCloud
 public static void OnMsg(byte[] buff, int len)
 {
     Console.WriteLine("< {0}", ValueHelper.BytesToHexStr(buff, 0, len));
     Console.WriteLine("> {0}", AutoReply);
     //    client.Send(AutoReply);
 }
コード例 #24
0
        public void ParseResult(ref SensorAcqResult rawData)
        {
            rawData.ErrorCode = IsValid(rawData.Response);
            if (rawData.ErrorCode != (int)Errors.SUCCESS)
            {
                return;
            }
            int module = ((rawData.Response[IDX_SOURCE] << 8) | (rawData.Response[IDX_SOURCE + 1]));

            if (module != rawData.Sensor.ModuleNo)
            {
                rawData.ErrorCode = (int)Errors.ERR_INVALID_MODULE;
                return;
            }
            try
            {
                byte   xminus  = rawData.Response[IDX_XDATA];
                double xdegree = rawData.Response[IDX_XDATA + 1];
                double xcent   = rawData.Response[IDX_XDATA + 2] / 60.0;
                double xsec    = rawData.Response[IDX_XDATA + 3] / 3600.0;

                byte   yminus  = rawData.Response[IDX_YDATA];
                double ydegree = rawData.Response[IDX_YDATA + 1];
                double ycent   = rawData.Response[IDX_YDATA + 2] / 60.0;
                double ysec    = rawData.Response[IDX_YDATA + 3] / 3600.0;

                double angleX = xdegree + xcent + xsec;
                double angleY = ydegree + ycent + ysec;

                if (xminus == 0x0D)
                {
                    angleX = -angleX;
                }
                if (yminus == 0x0D)
                {
                    angleY = -angleY;
                }
                double changedx = 0;
                double changedy = 0;
                double r        = 0;

                if (rawData.Sensor.FormulaID == 2 && rawData.Sensor.Parameters != null &&
                    rawData.Sensor.ParamCount == 3)
                {
                    double xinit  = rawData.Sensor.Parameters[0].Value;
                    double yinit  = rawData.Sensor.Parameters[1].Value;
                    double len    = rawData.Sensor.Parameters[2].Value;
                    var    xvalue = (len * Math.Sin(angleX * Math.PI / 180)) - (len * Math.Sin(xinit * Math.PI / 180));
                    var    yvalue = (len * Math.Sin(angleY * Math.PI / 180)) - (len * Math.Sin(yinit * Math.PI / 180));
                    changedx = xvalue;
                    changedy = yvalue;
                }
                else if (rawData.Sensor.FormulaID == 6 && rawData.Sensor.Parameters != null &&
                         rawData.Sensor.ParamCount == 2)
                {
                    double xinit  = rawData.Sensor.Parameters[0].Value;
                    double yinit  = rawData.Sensor.Parameters[1].Value;
                    var    xvalue = angleX - xinit;
                    var    yvalue = angleY - yinit;
                    changedx = xvalue;
                    changedy = yvalue;
                }
                else if (rawData.Sensor.FormulaID == 30 && rawData.Sensor.Parameters != null &&
                         rawData.Sensor.ParamCount == 3)
                {
                    double xinit  = rawData.Sensor.Parameters[0].Value;
                    double yinit  = rawData.Sensor.Parameters[1].Value;
                    double len    = rawData.Sensor.Parameters[2].Value * 1000;
                    var    xvalue = (len * Math.Sin(angleX * Math.PI / 180)) - (len * Math.Sin(xinit * Math.PI / 180));
                    var    yvalue = (len * Math.Sin(angleY * Math.PI / 180)) - (len * Math.Sin(yinit * Math.PI / 180));

                    r        = Math.Sqrt(xvalue * xvalue + yvalue * yvalue);
                    changedx = xvalue;
                    changedy = yvalue;
                }

                var raws = new double[] { angleX, angleY };
                var phys = new double[] { changedx, changedy, r };

                rawData.Data = new SensorData(raws, phys, raws)
                {
                    JsonResultData = string.Format("{0}\"sensorId\":{1},\"data\":\"X方向角度:{2} °,Y方向角度:{3} °\"{4}", '{', rawData.Sensor.SensorID, angleX, angleY, '}')
                };

                //rawData.Data = new InclinationData(angleX, angleY, changedx, changedy)
                //{
                //    JsonResultData =
                //        string.Format("{0}\"sensorId\":{1},\"data\":\"X方向角度:{2} °,Y方向角度:{3} °\"{4}", '{',
                //            rawData.Sensor.SensorID, angleX, angleY, '}')
                //};
            }
            catch (Exception ex)
            {
                rawData.ErrorCode = (int)Errors.ERR_DATA_PARSEFAILED;
                _logger.ErrorFormat("old Inclination sensor [Id:{0} m: {1}] parsedfailed,received bytes{2}, ERROR: {3}",
                                    rawData.Sensor.SensorID, rawData.Sensor.ModuleNo, ValueHelper.BytesToHexStr(rawData.Response),
                                    ex.Message);
            }
        }
コード例 #25
0
        public void ParseResult(ref SensorAcqResult rawData)
        {
            rawData.ErrorCode = IsValid(rawData.Response);
            if (rawData.ErrorCode != (int)Errors.SUCCESS)
            {
                return;
            }
            Encoding enc    = new ASCIIEncoding();
            var      recstr = enc.GetString(rawData.Response);
            int      startIndex;

            try
            {
                if (!IsModule(rawData, out startIndex))
                {
                    rawData.ErrorCode = (int)Errors.ERR_INVALID_MODULE;
                    return;
                }
                var pdata     = recstr.Substring(startIndex, 6);
                var len       = Convert.ToInt32(pdata) / 1000.0;                   //mm --> m
                var changelen = (len - rawData.Sensor.Parameters[0].Value) * 1000; // m --> mm
                if (rawData.Sensor.FormulaID == 22)
                {
                    changelen *= -1;
                }
                double[] raws = { len };
                double[] phys = { changelen };
                rawData.Data = new SensorData(raws, phys, raws)
                {
                    JsonResultData =
                        string.Format("{0}\"sensorId\":{1},\"data\":\"测量距离:{2} m\"{3}", '{', rawData.Sensor.SensorID,
                                      len, '}')
                };

                //rawData.Data = new LaserData(len, changelen)
                //{
                //    JsonResultData =
                //        string.Format("{0}\"sensorId\":{1},\"data\":\"测量距离:{2} m\"{3}", '{', rawData.Sensor.SensorID,
                //            len, '}')
                //};
            }
            catch (Exception ex)
            {
                rawData.ErrorCode = (int)Errors.ERR_DATA_PARSEFAILED;
                _logger.ErrorFormat("ftm laser sensor [Id:{0} m: {1}] pasefailed, received bytes{2}: {3}",
                                    rawData.Sensor.SensorID, rawData.Sensor.ModuleNo, ValueHelper.BytesToHexStr(rawData.Response),
                                    ex.Message);
            }
        }
コード例 #26
0
        public void ParseResult(ref SensorAcqResult rawData)
        {
            byte[] data = rawData.Response;
            rawData.ErrorCode = IsValid(data);
            if ((int)Errors.SUCCESS != rawData.ErrorCode)
            {
                return;
            }
            Encoding enc      = new ASCIIEncoding();
            var      recbytes = enc.GetString(data);
            var      module   = recbytes.Substring(1, 2);

            if (int.Parse(module) != rawData.Sensor.ModuleNo)
            {
                rawData.ErrorCode = (int)Errors.ERR_INVALID_MODULE;
                return;
            }
            try
            {
                var    pdata          = recbytes.Substring(3, recbytes.Length - 6);
                var    pressure       = Convert.ToSingle(pdata);
                string jsonResultData = string.Format("{0}\"sensorId\":{1},\"data\":\"压强:{2} kPa\"{3}", '{',
                                                      rawData.Sensor.SensorID, pressure, '}');
                double physicalQuantity = 0;
                switch (rawData.Sensor.FormulaID)
                {
                case 8:
                    var pressCul = pressure - rawData.Sensor.Parameters[1].Value;
                    if (ValueHelper.IsEqualZero(rawData.Sensor.Parameters[0].Value))
                    {
                        rawData.Sensor.Parameters[0].Value = 1;
                    }
                    var settlement = 1000 * pressCul / (rawData.Sensor.Parameters[0].Value * 9.8f);
                    physicalQuantity = settlement;
                    break;

                case 10:
                    jsonResultData = string.Format("{0}\"sensorId\":{1},\"data\":\"米水柱:{2} mH2O\"{3}", '{',
                                                   rawData.Sensor.SensorID, pressure, '}');
                    int    type       = (int)rawData.Sensor.Parameters[0].Value;
                    double waterLevel = pressure * 100;
                    double len        = rawData.Sensor.Parameters[1].Value; // 底长
                    switch (type)
                    {
                    case 0:         //三角堰
                        physicalQuantity =
                            (float)(Math.Pow(waterLevel, 2.5) * (0.0142 - ((int)(waterLevel / 5)) * 0.0001));
                        break;

                    case 1:         //矩形堰
                        physicalQuantity = (float)(Math.Pow(waterLevel, 1.5) * len * 0.0186);
                        break;

                    case 2:         // 梯形堰
                        physicalQuantity =
                            (float)(Math.Pow(waterLevel, 1.5) * (len - 0.2 * waterLevel) * 0.01838);
                        break;
                    }
                    break;
                }

                var raws = new double[] { pressure };
                var phys = new double[] { physicalQuantity };
                rawData.Data = new SensorData(raws, phys, raws)
                {
                    JsonResultData = jsonResultData
                };

                //rawData.Data = new PressureData(pressure, physicalQuantity)
                //{
                //    JsonResultData = jsonResultData
                //};
            }
            catch (Exception ex)
            {
                rawData.ErrorCode = (int)Errors.ERR_DATA_PARSEFAILED;
                _logger.ErrorFormat("mpm pressure [id:{0},m:{1}] parsedfailed ,received bytes{3},ERROR : {2}", rawData.Sensor.SensorID, rawData.Sensor.ModuleNo, ex.Message, ValueHelper.BytesToHexStr(rawData.Response));
            }
        }
コード例 #27
0
        public void ParseResult(ref SensorAcqResult rawData)
        {
            var data = rawData.Response;

            rawData.ErrorCode = IsValid(data);
            if ((int)Errors.SUCCESS != rawData.ErrorCode)
            {
                return;
            }
            try
            {
                switch (data[IDX_CMD])
                {
                case 0x00:
                {
                    var temByte = new byte[2];
                    temByte[0] = data[IDX_RAINDATA];
                    temByte[1] = data[IDX_RAINDATA + 1];
                    var rain = BitConverter.ToInt16(temByte, 0) * 0.01;

                    var raws = new double[] { rain };
                    rawData.Data = new SensorData(raws, raws, raws)
                    {
                        JsonResultData = string.Format("{0}\"sensorId\":{1},\"data\":\"小时雨量:{2} mm\"{3}", '{',
                                                       rawData.Sensor.SensorID, rain, '}')
                    };

                    //rawData.Data = new RainFallData(rain)
                    //{
                    //    JsonResultData = string.Format("{0}\"sensorId\":{1},\"data\":\"小时雨量:{2} mm\"{3}", '{',
                    //        rawData.Sensor.SensorID, rain, '}')
                    //};
                }
                break;

                case 0x10:
                    rawData.ErrorCode = (int)Errors.ERR_RAINFALL_CLOCKSYNC;
                    break;
                }
            }
            catch (Exception ex)
            {
                rawData.ErrorCode = (int)Errors.ERR_DATA_PARSEFAILED;
                _logger.ErrorFormat("rainfall sensor [id:{0},m:{1}] parsedfailed ,received bytes{3},ERROR : {2}", rawData.Sensor.SensorID, rawData.Sensor.ModuleNo, ex.Message, ValueHelper.BytesToHexStr(rawData.Response));
            }
        }
コード例 #28
0
        public void ParseResult(ref SensorAcqResult rawData)
        {
            rawData.ErrorCode = IsValid(rawData.Response);
            if ((int)Errors.SUCCESS != rawData.ErrorCode)
            {
                return;
            }
            var data   = rawData.Response;
            var module = data[0];

            if (module != rawData.Sensor.ModuleNo)
            {
                rawData.ErrorCode = (int)Errors.ERR_INVALID_DATA;
                return;
            }
            try
            {
                var speedofWind       = this.Bytes2Float(data, IDX_SPEED);
                var azimuth           = this.Bytes2Float(data, IDX_AZIMUTH);
                var speedOfSound      = this.Bytes2Float(data, IDX_SpeedOfSound);
                var probesTemperature = this.Bytes2Float(data, IDX_ProbesTemperature);
                var raws = new double[] { speedofWind, azimuth };
                rawData.Data = new SensorData(raws, raws, raws)
                {
                    JsonResultData =
                        string.Format(
                            "{0}\"sensorId\":{1},\"data\":\"风速:{2} m/s,风向:{3} °\"{4}",
                            '{',
                            rawData.Sensor.SensorID,
                            speedofWind,
                            azimuth,
                            '}')
                };
                //rawData.Data = new Wind2dData(speedofWind, azimuth)
                //{
                //    JsonResultData =
                //        string.Format(
                //            "{0}\"sensorId\":{1},\"data\":\"风速:{2} m/s,风向:{3} °\"{4}",
                //            '{',
                //            rawData.Sensor.SensorID,
                //            speedofWind,
                //            azimuth,
                //            '}')
                //};
            }
            catch (Exception ex)
            {
                rawData.ErrorCode = (int)Errors.ERR_DATA_PARSEFAILED;
                _logger.ErrorFormat("wind osl sensor [id:{0},m:{1}] parsedfailed ,received bytes{3},ERROR : {2}", rawData.Sensor.SensorID, rawData.Sensor.ModuleNo, ex.Message, ValueHelper.BytesToHexStr(rawData.Response));
            }
        }
コード例 #29
0
 public void OnDataReceived(IDtuConnection c, DtuMsg msg)
 {
     this._log.DebugFormat("Data received: from {0} buff: {1}", c.DtuID, msg != null && msg.Databuffer != null ? ValueHelper.BytesToHexStr(msg.Databuffer) : " empty.");
     this._dataReceived = true;
     this._receivedMsg  = msg;
 }
コード例 #30
0
        public void ParseResult(ref SensorAcqResult rawData)
        {
            rawData.ErrorCode = IsValid(rawData.Response);
            if (rawData.ErrorCode != (int)Errors.SUCCESS)
            {
                return;
            }
            if (((rawData.Response[2] << 8) | rawData.Response[3]) != rawData.Sensor.ModuleNo)
            {
                rawData.ErrorCode = (int)Errors.ERR_INVALID_MODULE;
                return;
            }
            switch (rawData.Response[IDX_CMD])
            {
            case 0x81:     // 采集命令回复
                try
                {
                    var    surveyXAng = ValueHelper.GetInt_BE(rawData.Response, 13) / 1000000f;
                    var    surveyYAng = ValueHelper.GetInt_BE(rawData.Response, 17) / 1000000f;
                    double changedx   = 0;
                    double changedy   = 0;
                    double?r          = null;

                    if (rawData.Sensor.FormulaID == 6 && rawData.Sensor.Parameters != null &&
                        rawData.Sensor.Parameters.Count == 2)
                    {
                        double xinit  = rawData.Sensor.Parameters[0].Value;
                        double yinit  = rawData.Sensor.Parameters[1].Value;
                        var    xvalue = surveyXAng - xinit;
                        var    yvalue = surveyYAng - yinit;
                        changedx = xvalue;
                        changedy = yvalue;
                    }
                    else if (rawData.Sensor.FormulaID == 30 && rawData.Sensor.Parameters != null &&
                             rawData.Sensor.Parameters.Count == 3)
                    {
                        double xinit = rawData.Sensor.Parameters[0].Value;
                        double yinit = rawData.Sensor.Parameters[1].Value;
                        double len   = rawData.Sensor.Parameters[2].Value * 1000;

                        var xvalue = (len * Math.Sin(surveyXAng * Math.PI / 180)) - (len * Math.Sin(xinit * Math.PI / 180));
                        var yvalue = (len * Math.Sin(surveyYAng * Math.PI / 180)) - (len * Math.Sin(yinit * Math.PI / 180));
                        r = Math.Sqrt(xvalue * xvalue + yvalue * yvalue);

                        changedx = xvalue;
                        changedy = yvalue;
                    }

                    var           raws = new double[] { surveyXAng, surveyYAng };
                    List <double> phys = new List <double>(new double[] { changedx, changedy });
                    if (r != null)
                    {
                        phys.Add(r.Value);
                    }

                    rawData.Data = new SensorData(raws, phys.ToArray(), raws)
                    {
                        JsonResultData =
                            string.Format("{0}\"sensorId\":{1},\"data\":\"X方向角度:{2} °,Y方向角度:{3} °\"{4}", '{',
                                          rawData.Sensor.SensorID, surveyXAng, surveyYAng, '}')
                    };
                }
                catch (Exception ex)
                {
                    rawData.ErrorCode = (int)Errors.ERR_DATA_PARSEFAILED;
                    _logger.ErrorFormat(
                        "box Inclination sensor [Id:{0} m: {1}] parsedfailed,received bytes{2} ERROR: {3}",
                        rawData.Sensor.SensorID, rawData.Sensor.ModuleNo,
                        ValueHelper.BytesToHexStr(rawData.Response), ex.Message);
                }
                break;

            case 0xC0:     // 回复错误码
                rawData.ErrorCode = ModbusErrorCode.GetErrorCode(rawData.Response[IDX_CMD + 1]);
                break;
            }
        }