/// <summary> /// 采集信号保存到Bvalue[]数组 /// </summary> void RcvUdpdataToBvalue_ThreatStart() { List <ArraySegment <byte> > buffer = new List <ArraySegment <byte> > { new ArraySegment <byte>(new byte[1282]), }; int ret; Stopwatch stopwatch = new Stopwatch(); while (true) { RcvResetEvent.WaitOne(); try { stopwatch.Start(); ret = MSocket.Receive(buffer); if (ret <= 0) { continue; } int offset = 0; var bytedata = buffer[0].Array; if (bytedata == null) { continue; } int chl = bytedata[0]; //通道 int tiv = bytedata[1]; //时分 int index = tiv * 8 + chl; // 1时分8通道 offset += 2; short[] sbdata = new short[(bytedata.Length - offset) / 2]; var purdata = new byte[bytedata.Length - offset]; Array.Copy(bytedata, offset, purdata, 0, purdata.Length); for (int i = 0; i < sbdata.Length; i++)//大端数据转小端 { var t = new byte[2]; t[0] = purdata[2 * i + 1]; t[1] = purdata[2 * i]; sbdata[i] = BitConverter.ToInt16(t, 0); } BvalueDatas[index] = new short[sbdata.Length]; double progressvalue = (index + 1) * 100.0 / 64; //进度条 Console.WriteLine("通道: " + index); Array.Copy(sbdata, BvalueDatas[index], sbdata.Length); DisPlayWindow.HMainWindow.bvaulue_pgbar.Dispatcher.Invoke(() => { DisPlayWindow.HMainWindow.bvaulue_pgbar.Value = progressvalue; }); //进度条 } catch (Exception e) { Console.WriteLine(e); throw; } stopwatch.Stop(); Console.WriteLine("RCVTime:" + stopwatch.ElapsedMilliseconds); RcvResetEvent.Reset(); } }
/// <summary> /// 接收网络流相位信号线程函数 /// </summary> void RcvUdpdataToPhase_ThreatStart() { List <ArraySegment <byte> > buffer = new List <ArraySegment <byte> > { new ArraySegment <byte>(new byte[1282]) }; int ret; Stopwatch stopwatch = new Stopwatch(); while (true) { RcvResetEvent.WaitOne(); try { stopwatch.Start(); ret = MSocket.Receive(buffer); if (ret <= 0) { continue; } int offset = 0; var bytedata = buffer[0].Array; if (bytedata == null) { continue; } int chl = bytedata[0]; //通道号 int tiv = bytedata[1]; //时分 int index = tiv * 8 + chl; //1时分表示8通道 offset += 2; short[] sbdata = new short[(bytedata.Length - offset) / 2]; //2byte转short数据 var purdata = new byte[bytedata.Length - offset]; //接收byte数组 Array.Copy(bytedata, offset, purdata, 0, purdata.Length); for (int i = 0; i < sbdata.Length; i++) //大端数据 { var t = new byte[2]; // 大端转小端 t[0] = purdata[2 * i + 1]; t[1] = purdata[2 * i]; sbdata[i] = BitConverter.ToInt16(t, 0); } if (index < 0 || index > 31) { Console.WriteLine("Index Error!"); } RcvPhaseData[index] = new short[sbdata.Length]; Console.WriteLine("通道: " + index); Array.Copy(sbdata, RcvPhaseData[index], sbdata.Length); } catch (Exception e) { Console.WriteLine(e); throw; } stopwatch.Stop(); Console.WriteLine("RCVTime:" + stopwatch.ElapsedMilliseconds); RcvResetEvent.Reset(); // 线程继续等待 } }