Esempio n. 1
0
 /// <summary>
 /// 处理振动数据计算请求
 /// </summary>
 /// <param name="filename">原始数据文件路径</param>
 /// <param name="sensorId">传感器ID</param>
 /// <param name="acqTime">数据采集时间</param>
 /// <param name="calcCompletion">计算完成通知方法</param>
 public void ProcessRequest(string filename, int sensorId, DateTime acqTime, Action <IEnumerable <string> > calcCompletion)
 {
     if (string.IsNullOrEmpty(filename))
     {
         return;
     }
     try
     {
         ACCSensor.CalcAndSave(sensorId, acqTime, filename);
         _logger.Info(string.Format("处理数据 监测因素:振动 传感器ID:{0}, 采集时间:{1}, 数据文件:{2}", sensorId, acqTime, filename));
     }
     catch (System.Exception ex)
     {
         _logger.Error(string.Format("处理振动数据计算请求时发生异常 SensorID:{0}, AcqTime:{1}, File:{2}, {3}", sensorId, acqTime, filename, ex.Message));
     }
 }
Esempio n. 2
0
        /// <summary>
        /// 单文件格式振动数据的解析和计算
        /// </summary>
        public static ParserReturn Parse(int structid, string file)
        {
            ParserReturn pr = null;

            if (IsFileOccupation(structid, file, out pr))
            {
                return(pr);
            }

            try
            {
                using (var fs = new FileStream(file, FileMode.Open, FileAccess.Read))
                {
                    var    br = new BinaryReader(fs);
                    ushort T  = br.ReadUInt16();
                    ushort L  = br.ReadUInt16();
                    TriggerSaveFileTitle title =
                        (TriggerSaveFileTitle)
                        StructConvert.BytesToStruct(br.ReadBytes(L), typeof(TriggerSaveFileTitle));
                    var ch   = title.CHNum;
                    var mod  = title.DeviceID;
                    var fre  = title.SampleFreq;
                    var time = new DateTime(2000 + title.year, title.mon, title.day, title.hour, title.min, title.sec);
                    var cnt  = title.L_Date / 4;
                    var org  = new float[cnt];

                    for (var i = 0; i < cnt; i++)
                    {
                        org[i] = br.ReadSingle();
                    }
                    fs.Close();
#if DEBUG
                    //-- 生成数据文件
                    if (!Directory.Exists("debug"))
                    {
                        Directory.CreateDirectory("debug");
                    }
                    var debugfile = Path.Combine("debug", Path.GetFileNameWithoutExtension(file) + DateTime.Now.ToString("HHmmss") + ".txt");
                    using (var fsw = new FileStream(debugfile, FileMode.Create, FileAccess.ReadWrite))
                    {
                        StreamWriter sw = new StreamWriter(fsw);
                        for (var i = 0; i < cnt; i++)
                        {
                            sw.WriteLine(org[i]);
                        }
                        fsw.Close();
                    }
#endif

                    string err;
                    var    affects = ACCSensor.CalcAndSave(structid, mod, ch, fre, time, org, out err);

                    pr = new ParserReturn
                    {
                        Error   = err,
                        Struct  = structid,
                        File    = file,
                        Time    = time,
                        Affects = affects,
                        mod     = mod,
                        ch      = ch,
                        Period  = (int)(cnt / fre),
                        freq    = (int)fre
                    };
                }
            }
            catch (Exception ex)
            {
                pr = new ParserReturn
                {
                    Error   = ex.Message,
                    Struct  = structid,
                    File    = file,
                    Time    = DateTime.Now,
                    Affects = 0,
                    mod     = 0,
                    ch      = 0,
                    Period  = 0,
                    freq    = 0
                };
            }
            return(pr);
        }