Esempio n. 1
0
        public override bool DataPackageAnalyse(byte[] byteArray, int count)
        {
            //  return base.DataPackageAnalyse(byteArray);
            if (count <= 0)
            {
                return(false);
            }
            int dataLength = count;

            if ((0x10 == byteArray[count - 2]) && (0x03 == byteArray[count - 1]))
            {
                //数据结尾正确
                //取传感器数据
                byte[] bValue = new byte[5]; //气体值
                byte[] bPoint = new byte[1]; //小数点位置
                byte[] bUnit  = new byte[3]; //单位
                Array.Copy(byteArray, 30, bValue, 0, 5);
                Array.Copy(byteArray, 35, bPoint, 0, 1);
                Array.Copy(byteArray, 36, bUnit, 0, 3);

                for (int i = 0; i < bValue.Length; i++)
                {
                    if ((bValue[i] < 0x30) || (bValue[i] > 0x39))
                    {
                        return(false);
                    }
                }

                string strValue = System.Text.Encoding.ASCII.GetString(bValue);
                double dValue   = GetRealValue(Convert.ToDouble(strValue), byte2HexStr(bPoint, 1));
                string strUnit  = GetStrUnit(byte2HexStr(bUnit, 3));

                //
                DataClassHW dchw = new DataClassHW();
                dchw.dNH3Value = dValue;
                DataManager.listHW.AddLast(dchw);

                //输出结果
                string strResult = System.DateTime.Now.ToString() + "气体浓度为:" + dValue.ToString() + strUnit + System.Environment.NewLine;
                Console.WriteLine(strResult);
            }
            else
            {
                string messageOut = "数据帧尾出错:" + byteArray[dataLength - 2].ToString() + byteArray[dataLength - 1].ToString();
                Program.Logger.Error(messageOut);
                return(false);
            }
            return(true);
        }
Esempio n. 2
0
        /// <summary>
        /// HW:环卫气体:将数据存入数据库
        /// </summary>
        private void DataProcessListHW()
        {
            while (true)
            {
                if (0 == listHW.Count)//没有数据
                {
                    Thread.Sleep(100);
                    Console.WriteLine("+++++++++++none");
                    continue;
                }

                DataClassHW dchw = (DataClassHW)listHW.Last();

                Console.WriteLine(dchw.dNH3Value);
            }
        }