/// <summary> /// 更新调理版设置组 /// </summary> private void UpdateMeterageSample() { //设置每块调理版的参数组 byte[] recData = new byte[13]; Console.WriteLine("更新调理版参数组!"); for (int i = 1; i <= 4; i++) { byte[] cmd = OrderHelper.UpdateMeterageSample(_site.MeterageLibList.Where(item => item.GorupId == i).ToList(), i); if (cmd != null) { _sokect.Send(cmd); if (!_sokect.Receive(recData)) { ; } //LogHelper.Info(MethodBase.GetCurrentMethod(), string.Format("{0}站点更新调理{1}号参数组失败!", _site.Sn, i)); } } //设置对应每块调理版的参数组是否采集 for (int i = 1; i <= 4; i++) { List <MeterageLibModel> meterageLibList = _site.MeterageLibList.Where(item => item.GorupId == i).ToList(); if (meterageLibList.Count == 0) { continue; } for (int j = 1; j <= 8; j++) { int channelId = j + (i - 1) * 8; IEnumerable <ChannelStruct> channelStructList = _site.ChannelStructList.Where(c => c.ChannelID == channelId); if (channelStructList.Count() == 0) { continue; } ChannelStruct channelStruct = channelStructList.FirstOrDefault(); List <MeterageSamplerate> meterageSampleList = _meterageSamplerateService.Query(s => s.AreaId == channelStruct.AreaID && s.McId == channelStruct.MachineID && s.ParId == channelStruct.MonitorID && s.DirId == channelStruct.Position_HVA && s.IsSamplerate == 1); byte[] cmd = OrderHelper.UpdateMeterageChannelBind(meterageLibList, meterageSampleList, channelId); if (cmd != null) { if (_sokect.Send(cmd)) { if (_sokect.Receive(recData)) { continue; } //LogHelper.Info(MethodBase.GetCurrentMethod(), string.Format("{0}站点{1}通道号参数组是否采集配置失败!", _site.Sn, channelId)); } } } } Console.WriteLine("更新调理版参数组完成!"); }
public void GetDataTw(SiteModel site, SocketMiddleware socket) { Dictionary <string, bool> stopDic = RedisHelper.Get <Dictionary <string, bool> >($"{CallContext.GetData<ClientInfo>("clientInfo").Database}IsStop"); Console.WriteLine("开始采集波形数据!"); //存储集合 List <int> workStatuesList = null; List <MeterageSamplerate> list = null; int type, frequency, line; byte[] cmd = null; byte[] recData = new byte[20]; for (int i = 0; i < site.ChannelStructList.Count; i++) { //是否停机状态 string key = $"A{site.ChannelStructList[i].AreaID}M{site.ChannelStructList[i].MachineID}"; if (stopDic.GetValueOrDefault(key)) { continue; } list = _meterageSamplerateService.Query(s => s.AreaId == site.ChannelStructList[i].AreaID && s.McId == site.ChannelStructList[i].MachineID && s.ParId == site.ChannelStructList[i].MonitorID && s.DirId == site.ChannelStructList[i].Position_HVA && s.IsSamplerate == 1); workStatuesList = site.ChannelStructList[i].StateStatus.Where(w => w != -1).ToList(); foreach (MeterageSamplerate item in list) { line = item.MsrLine; frequency = item.MsrRateMax; type = item.MsrParameter.ToLower().Contains("env") ? 2 : 0; char typeName = item.MsrName.ToUpper()[0]; //类型的首字母 如:Disp 'D' cmd = OrderHelper.TwDataByChannel(site.ChannelStructList[i].ChannelID, typeName, frequency, line, 0); //获取每个通道取数据命令 if (socket.Send(cmd)) { if (!socket.Receive(recData)) //接收失败 { continue; } int len = BitConverter.ToInt32(recData, 15); //获取要接收的数据长度 if (len <= 0) //是否有数据 { continue; } //获取波形数据 cmd = OrderHelper.TwDataByChannel(site.ChannelStructList[i].ChannelID, typeName, frequency, line, 1); if (!socket.Send(cmd)) { continue; } byte[] data = new byte[len]; if (!socket.Receive(data)) //接收波形数据,最后4个字节是工况 { Console.WriteLine(string.Format("{0}站点{1}通道号接收波形异常!", site.Sn, i)); continue; } DataTw tw = new DataTw() //数据转化波形对象 { AreaId = item.AreaId, McId = item.McId, ParId = item.ParId, DirId = item.DirId, DataLines = GetLineByType(item.MsrLine, type), DataPoints = (int)(GetLineByType(item.MsrLine, type) * 2.56), DataHz = (int)(GetFrequencyByType(item.MsrRateMax, type) * 2.56), DataIsFFT = 0, DataType = type + 1, DataFormat = 2, Data = new byte[len - 7 * 4], DataWorkStatus = Convert.ToInt32(BitConverter.ToSingle(data, 24)), Time = ConvertTime(data) }; //是否是要取的工况 if (!workStatuesList.Exists(w => w == tw.DataWorkStatus)) { continue; } Array.Copy(data, 7 * 4, tw.Data, 0, len - 7 * 4); //把波形数据copy到 tw.data中 if (item.MsrParameter.ToLower().Contains("env")) //包络,直接存 { tw.DataIsFFT = 1; tw.Data = SplitMinFFT(tw.Data, item); //截取最小Fmin _dataTwService.InsertDataTw(tw, string.Format("tb_data_tw_{0}", item.MsrName)); //存入数据库 } else if (item.MsrParameter.ToLower().Contains("acc")) { //存储波形 _dataTwService.InsertDataTw(tw, string.Format("tb_data_tw_{0}", item.MsrName)); //频谱存储 float[] accSpectrum = GetAccSpectrum(ToFloatArray(tw.Data), tw.DataLines); for (int z = 0; z < accSpectrum.Length; z++) { accSpectrum[z] = accSpectrum[z] / 1.414f;//峰值转有效值 } tw.Data = ToByteArray(accSpectrum); tw.DataIsFFT = 1; tw.Data = SplitMinFFT(tw.Data, item); //截取最小Fmin _dataTwService.InsertDataTw(tw, string.Format("tb_data_tw_{0}", item.MsrName)); } else if (item.MsrParameter.ToLower().Contains("disp")) { float[] accSpectrum = GetAccSpectrum(ToFloatArray(tw.Data) /*原始波形*/, tw.DataLines); //位移频谱 float[] dispSpectrum = GetDispSpectrum(accSpectrum, tw.DataHz, tw.DataPoints); for (int k = 0; k < dispSpectrum.Length; k++) { //位移有效值 dispSpectrum[k] = dispSpectrum[k] * 9800 * 1000 / 1.414f; } //位移波形 float[] dispTw = new float[tw.DataPoints]; FFTHelper.IntegrateFromSpectrum(ToFloatArray(tw.Data) /*原始波形*/, tw.DataHz, tw.DataPoints, item.MsrRateMin, GetFrequencyByType(item.MsrRateMax, type), 2, ref dispTw); for (int k = 0; k < dispTw.Length; k++) { dispTw[k] = dispTw[k] * 9800 * 1000; } //存储波形 //tw.data = ToByteArray(dispTw); _dataTwService.InsertDataTw(tw, string.Format("tb_data_tw_{0}", item.MsrName)); //频谱存储 tw.DataIsFFT = 1; tw.Data = ToByteArray(dispSpectrum); tw.Data = SplitMinFFT(tw.Data, item); //截取最小Fmin _dataTwService.InsertDataTw(tw, string.Format("tb_data_tw_{0}", item.MsrName)); } else if (item.MsrParameter.ToLower().Contains("vel")) { float[] accSpectrum = GetAccSpectrum(ToFloatArray(tw.Data) /*原始波形*/, tw.DataLines); //速度波形 float[] velTw = new float[tw.DataPoints]; FFTHelper.IntegrateFromSpectrum(ToFloatArray(tw.Data) /*原始波形*/, tw.DataHz, tw.DataPoints, item.MsrRateMin, GetFrequencyByType(item.MsrRateMax, type), 1, ref velTw); for (int k = 0; k < velTw.Length; k++) { velTw[k] = velTw[k] * 9800; } //速度频谱 float[] velSpectrum = GetVelSpectrum(accSpectrum, tw.DataHz, tw.DataPoints); for (int k = 0; k < velSpectrum.Length; k++) { velSpectrum[k] = velSpectrum[k] * 9800 / 1.414f; } //波形存储 //tw.data = ToByteArray(velTw); _dataTwService.InsertDataTw(tw, string.Format("tb_data_tw_{0}", item.MsrName)); //频谱存储 tw.DataIsFFT = 1; tw.Data = ToByteArray(velSpectrum); //获取频谱 tw.Data = SplitMinFFT(tw.Data, item); //截取最小Fmin _dataTwService.InsertDataTw(tw, string.Format("tb_data_tw_{0}", item.MsrName)); } } } } Console.WriteLine("波形数据采集完成!"); }
/// <summary> /// 初始化,处理波形频谱需要的参数信息 /// </summary> /// <param name="site"></param> /// <param name="socket"></param> public void InitConfig(SiteModel site, SocketMiddleware socket) { _site = site; _socket = socket; _stopMachineOa = RedisHelper.Get <Dictionary <string, bool> >($"{CallContext.GetData<ClientInfo>("clientInfo").Database}IsStop"); _dirverRelationList = _dirverRelationService.Query(dr => dr.AreaId == _site.AearId); //获取测量参数组 及转速定义 List <MeterageSamplerate> meterageSamplerateList = _meterageSamplerateService.Query(ms => ms.AreaId == _site.AearId && ms.IsSamplerate == 1); List <TachoDefind> tachoDefindList = _tachoDefindService.Query(td => td.AreaId == _site.AearId); foreach (TachoDefind tachoDefind in tachoDefindList) { //没有找到需要的数据源,查找下一个 MeterageSamplerate ms = meterageSamplerateList.FirstOrDefault(m => m.MsrId == tachoDefind.MsrId); if (ms == null) { continue; } //获取频谱数据 DataTwModel model = GetTwFFTData(ms); if (model == null) { continue; } //提取转速 float rev = ExtractRPM(model.Data, model.DataHz / ((float)model.DataLines), tachoDefind); Console.WriteLine($"转速:{rev}"); //停机转态不提取 if (rev <= 0) { _stopMachine.Add($"A{tachoDefind.AreaId}M{tachoDefind.McId}", true); continue; } //修改转速 MachineRev machineRev = _machineRevService.Query(m => m.AreaId == tachoDefind.AreaId && m.McId == tachoDefind.McId).FirstOrDefault(); if (machineRev != null) { machineRev.MrRev = rev; machineRev.MrTime = DateTime.Now; _machineRevService.UpdateEntity(machineRev); } else { machineRev = new MachineRev() { AreaId = tachoDefind.AreaId, McId = tachoDefind.McId, MrTime = DateTime.Now, MrLevel = 2, MrRev = rev }; _machineRevService.InsertEntity(machineRev); } ExtractValue(model, ms, (int)rev); } foreach (MeterageSamplerate ms in meterageSamplerateList) { if (tachoDefindList.FirstOrDefault(t => t.MsrId == ms.MsrId) != null) { continue; } DataTwModel model = GetTwFFTData(ms); if (model == null) { continue; } //停机状态不提取 if (_stopMachine.ContainsKey($"A{ms.AreaId}M{ms.McId}")) { continue; } ExtractValue(model, ms); } //更新元件状态 foreach (DirverRelation dirverRelation in _dirverRelationList) { _dirverRelationService.UpdateEntity(dirverRelation); } }