Example #1
0
        //  =Boolean.Parse()
        public IList <Data> TextOrBinarySelect(DataBaseName path)
        {
            var list = new List <Data>();

            if (path.DataBaseType == (int)DataBaseType.Vibration)
            {
                //DateTime readtime;
                //bool isSuccess = ValueHelper.String2Time(
                //    ExtractionConfigDic.GetExtractionConfigDic().GetExtractionConfig((int)path.ID, string.Empty).Acqtime,out readtime);
                //if (!isSuccess)
                //{
                //    readtime = new DateTime(2013, 1, 1);
                //}

                string[][] files = GetFileNames(path.Location, "*.*", TxtDateType.Vibration);

                if (files.Length > 0)
                {
                    foreach (string file in files[0])
                    {
                        if (file.EndsWith("odb"))
                        {
                            string parastr = file.Remove(file.Length - 3, 3);
                            parastr += "sdb";
                            if (files[1].Contains(parastr))
                            {
                                var             fi    = new FileInfo(file);
                                FileParamStruct para  = ReadParamS(parastr);
                                double[]        datas = ReadDatumS(file);
                                Data            data  = new Data();
                                string[]        strs  = fi.Name.Split(new[] { '_' }, StringSplitOptions.RemoveEmptyEntries);
                                string          strch = strs[1];
                                data.MoudleNo    = strs[0];
                                data.ChannelId   = int.Parse(strch);
                                data.OFlag       = para.diSampleFreq;
                                data.DataBaseId  = (int)path.ID;
                                data.SafeTypeId  = (int)SensorCategory.Vibration;
                                data.ProjectCode = (short)ProjectInfoDic.GetInstance().GetProjectInfo().ProjectCode;
                                data.DataSet     = datas.ToList();
                                DateTime acqtime;
                                string   str = strs[2].Trim();
                                if (strs[2].Contains(".sdb") || strs[2].Contains(".odb"))
                                {
                                    str = strs[2].Substring(0, strs[2].Length - 4);
                                }
                                ValueHelper.String2Time(str, out acqtime);
                                data.CollectTime = acqtime;
                                data.Reserve     = 0;
                                if (strs.Length == 4)
                                {
                                    // 触发采样
                                    data.Reserve = 1;
                                }
                                list.Add(data);
                                //ExtractionConfigDic.GetExtractionConfigDic()
                                //                        .UpdateExtractionConfig(
                                //                            new ExtractionConfig
                                //                            {
                                //                                DataBaseId = (int)path.ID,
                                //                                TableName = string.Empty,
                                //                                Acqtime =
                                //                                    fi.LastWriteTime.ToString("yyyyMMddHHmmss.fff")
                                //                            });
                                MoveFile(file);
                                MoveFile(parastr);
                            }
                        }
                    }
                }
            }

            return(list);
        }
Example #2
0
        public void ReloveReceivedData(string dtuid, byte[] bytes)
        {
            int    sensortype = bytes[TypeOfDataOfFrame];
            string moduleId   = BitConverter.ToInt16(bytes, ModuleNumOfFrame).ToString();
            int    channelid  = bytes[ChannelIdOfFrame];

            IList <SensorInfo> sensorlist = DeceiveInfoDic.GetDeceiveInfoDic().GeSensorInfosByChannel(dtuid, sensortype, moduleId, channelid);


            if (sensorlist.Count == 1)
            {
                int    sensorid = sensorlist[0].SensorId;
                int    safetype = sensorlist[0].SafetyFactorTypeId;
                int    count    = bytes[10];
                int    index    = bytes[11];
                double fre      = BitConverter.ToSingle(bytes, 12);
                // ValueHelper.GetFloat(bytes, 12);//计算时间?

                int      structureId = BitConverter.ToInt32(bytes, Structure);
                long     ticks       = BitConverter.ToInt64(bytes, AcqTimeOfFrame);
                var      time        = new DateTime(ticks);
                int      floatcount  = (bytes.Length - 33) / 4;
                double[] data        = new double[floatcount];
                for (int i = 0; i < floatcount; i++)
                {
                    data[i] = BitConverter.ToSingle(bytes, DataValueOfFrame + (4 * i)); //ValueHelper.GetFloat(bytes, DataValueOfFrame + (4 * i));
                }
                var fileParam = new FileParamStruct();
                fileParam.diSampleFreq   = fre;
                fileParam.diTestPointNum = moduleId + "_" + channelid;
                StringBuilder filename = new StringBuilder();
                filename.Append(fileParam.diTestPointNum).Append("_").Append(time.ToString("yyyyMMddHHmmssfff"));
                if (bytes[16] == 1)
                {
                    filename.Append("_TRI");
                }
                try
                {
                    //Directory.CreateDirectory(path);
                    DirectoryInfo dir = new DirectoryInfo(path);
                    if (!dir.Exists)
                    {
                        dir.Create();
                    }
                    string filePath = path + filename;
                    CreateParamsFile(filePath + ".sdb", fileParam);
                    CreateDataFile(filePath + ".odb", data);
                }
                catch (Exception ex)
                {
                    Log.FatalFormat(ex.Message);
                }

                if (index == count - 1)
                {
                    string filePath = path + filename;
                    MakeMsgToDataCalc.MakeMsgToRequestDataCalc(sensorid, filePath, time);
                }
            }
            else
            {
                Log.Error("不能确定唯一传感器:" + ValueHelper.ByteToHexStr(bytes));
            }
        }