private void ComRec(byte[] data) { int length = this.recStringBuilder.Length; int idx = 0; if (data == null) { return; } var datas = SerialProtocolParseHelper.Parse(data); Console.WriteLine(string.Join(",", datas) + "\r\n"); if (datas.Contains(calibrate)) { return; } var ds = Constant.solver2D.Update(datas.Select <long, double>(x => x).ToList()); Console.WriteLine(string.Join(",", ds) + "\r\n"); bool flag = false; if (Math.Abs(Global.Position[0] - ds[0] / 1000) > tolerance || double.IsNaN(Global.Position[0]) || XMovingAverage.Length < ringLength) { XMovingAverage.Push(ds[0]); Global.Position[0] = XMovingAverage.Current / 1000; flag = true; } if (Math.Abs(Global.Position[1] - ds[1] / 1000) > tolerance || double.IsNaN(Global.Position[1]) || YMovingAverage.Length < ringLength) { YMovingAverage.Push(ds[1]); Global.Position[1] = YMovingAverage.Current / 1000; flag = true; } if (flag) { Constant.DrawingHelper.Update(Global.Position[0] * 1000, Global.Position[1] * 1000); } Global.Position[2] = refHeight / 1000; SerialDataReceived?.Invoke(this, string.Join(",", ds) + "\r\n"); }
void ReceivedData(object sender, SerialDataReceivedEventArgs e) { _dataReceived = _serialPort.ReadLine(); SerialDataReceived.Raise(this, new EventArgs()); }