public void PlotMagnetic() { foreach (var it in magChart.Series) { it.Points.Clear(); } DeepPackage[] buf; Thread.BeginCriticalRegion(); buf = new DeepPackage[packMgr.MagBuf.Count]; packMgr.MagBuf.CopyTo(buf); Thread.EndCriticalRegion(); int cnt = 0; foreach (var it in buf) { ++cnt; for (int i = 0; i < 7; ++i) { magChart.Series[i].Points.AddXY(cnt, it.sensor[i]); } } }
private void AnalysePackages(MainForm owner) { // 解析当前帧,判定是那个数据包 SpeedPackage speed = new SpeedPackage(); SteerPackage steering = new SteerPackage(); DeepPackage deep = new DeepPackage(); switch (rxBuffer[0]) { case 0x8a: // 方向 steering.DecodePayload(rxBuffer); SteerBuf.Add(steering); break; case 0x8b: // 速度 speed.DecodePayload(rxBuffer); if (SpeedBuf.Count > 999) { SpeedBuf.RemoveAt(0); } SpeedBuf.Add(speed); owner.BeginInvoke(new MethodInvoker(() => { owner.lblSpeedL.Text = "左轮速度:" + speed.SpeedL.ToString() + " cm/s"; owner.lblSpeedR.Text = "右轮速度:" + speed.SpeedR.ToString() + " cm/s"; })); break; case 0x8c: // AI deep.DecodePayload(rxBuffer); MagBuf.Add(deep); break; case 0x8d: // 开关 owner.BeginInvoke(new MethodInvoker(() => { for (int i = 0; i < 8; ++i) { owner.checkedListBox.SetItemChecked(i, (rxBuffer[1] & (1 << i)) > 0); } })); break; case 0x8e: // 电磁 break; case 0x8f: // 日志 string str = Encoding.UTF8.GetString(rxBuffer, 2, bufTop - 3); Color color = Color.Black; switch (rxBuffer[1]) { case 1: color = Color.Red; break; case 2: color = Color.Green; break; case 3: color = Color.Blue; break; } owner.BeginInvoke(new MethodInvoker(() => { owner.richLogBox.SelectionColor = color; owner.richLogBox.AppendText(str); })); break; default: break; } }