Exemple #1
0
        private AutoMeasuredValue GetAutoMeasuredValue(byte[] data)
        {
            if (data.Length == 28)
            {
                return(null);
            }

            AutoMeasuredValue amv = new AutoMeasuredValue();
            int nYear             = 0;
            int nMonth            = 0;
            int nDay    = 0;
            int nHour   = 0;
            int nMinute = 0;
            int nSecond = 0;

            try
            {
                amv.areaId            = BitConverter.ToInt32(data, 0);
                amv.machineId         = BitConverter.ToInt32(data, 4);
                amv.monitorId         = BitConverter.ToInt32(data, 8);
                amv.position_HVA      = BitConverter.ToInt32(data, 12);
                amv.channeld          = BitConverter.ToInt32(data, 16);
                amv.monitorPeriodTime = BitConverter.ToInt32(data, 20);
                amv.typeSensor        = BitConverter.ToInt32(data, 24);

                if (amv.areaId == 0)//数据无效 返回空
                {
                    return(null);
                }


                amv.MeasuredList = new List <MeasuredValue>();
                //获取运行次数 =(总长度-数据头)/ 结构体大小
                int runNum = (data.Length - 28) / 84;
                for (int i = 0; i < runNum; i++)
                {
                    MeasuredValue mv = new MeasuredValue();
                    mv    = (MeasuredValue)MarshalHelper.ByteToStruct(data, i * 84 + 28, mv.GetType(), 84);
                    nYear = mv.year; nMonth = mv.month; nDay = mv.day; nHour = mv.hour; nMinute = mv.minute; nSecond = mv.second;
                    DateTime dateTime = new DateTime(mv.year, mv.month, mv.day, mv.hour, mv.minute, mv.second);
                    //PrintHelper.Info("CH-{0:D2} 数据{1} -- {2} ", channeld, i + 1, dateTime.ToString("yyyy-MM-dd HH:mm:ss"));
                    bool IsExists = amv.MeasuredList.Exists(x => x.year == mv.year && x.month == mv.month &&
                                                            x.day == mv.day && x.hour == mv.hour && x.minute == mv.minute && x.second == mv.second);
                    if (!IsExists)
                    {
                        amv.MeasuredList.Add(mv);
                    }
                }
            }
            catch (Exception ex)
            {
                //LogHelper.Error(System.Reflection.MethodBase.GetCurrentMethod(), ex.Message);
                return(null);
            }
            return(amv);
        }