/// <summary> /// 循环发送命令 /// </summary> /// <param name="chinum">通道个数</param> /// <param name="timenum">时分个数</param> public void SendOrigSwitchCommand(int chinum, int timenum) { UCommandSocket.SwitchWindow(ConstUdpArg.SwicthToOriginalWindow); // UCommand.WriteOrigTDiv(0); // Console.WriteLine("发送时分0"); // UCommand.WriteOrigChannel(0); // Console.WriteLine("发送通道0"); for (int i = 0; i < timenum; i++) { for (int j = 0; j < chinum; j++) { UCommandSocket.WriteOrigTDiv(i); Console.WriteLine("发送时分{0}", i); UCommandSocket.WriteOrigChannel(j); Console.WriteLine("发送通道{0}", j); Thread.Sleep(15); RcvResetEvent.Set(); Thread.Sleep(20); } } Thread.Sleep(100); UCommandSocket.SwitchWindow(ConstUdpArg.SwicthToOriginalWindow); UCommandSocket.WriteOrigChannel(0); UCommandSocket.WriteOrigTDiv(0); UCommandSocket.SwitchWindow(ConstUdpArg.SwicthToStateWindow); }
/// <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(); // 线程继续等待 } }
void Dispose(bool disposing) { ReleaseUnmanagedResources(); if (disposing) { if (RcvResetEvent != null) { RcvResetEvent.Dispose(); } if (MSocket != null) { MSocket.Shutdown(SocketShutdown.Both); MSocket.Close(); MSocket.Dispose(); } } }