/// <summary> /// 受信データに対してグラフを出力します /// </summary> /// <param name="datas">配列化した受信データ</param> /// <param name="i"></param> private void ShowChart(CycleDatas cDatas) { var xvalue = generalTimer.ElapsedMilliseconds / 1000.0; #region グラフ設定 try { chartWatt.Series["Watt"].Points.AddXY(xvalue, double.Parse(cDatas.Watt)); chartSpeed.Series["Speed"].Points.AddXY(xvalue, double.Parse(cDatas.Speed)); chartCadence.Series["Cadence"].Points.AddXY(xvalue, double.Parse(cDatas.Cadence)); } catch (Exception) { return; } chartCadence.ChartAreas[0].AxisX.Maximum = double.NaN; chartCadence.ChartAreas[0].AxisX.Minimum = double.NaN; chartCadence.ChartAreas[0].AxisY.Maximum = double.NaN; chartCadence.ChartAreas[0].AxisY.Minimum = double.NaN; chartWatt.ChartAreas[0].AxisX.Maximum = double.NaN; chartWatt.ChartAreas[0].AxisX.Minimum = double.NaN; chartWatt.ChartAreas[0].AxisY.Maximum = double.NaN; chartWatt.ChartAreas[0].AxisY.Minimum = double.NaN; chartSpeed.ChartAreas[0].AxisX.Maximum = double.NaN; chartSpeed.ChartAreas[0].AxisX.Minimum = double.NaN; chartSpeed.ChartAreas[0].AxisY.Maximum = double.NaN; chartSpeed.ChartAreas[0].AxisY.Minimum = double.NaN; #endregion }
public void ShowCycleData(CycleDatas cData) { if (cData.Cadence != null && cData.Speed != null && cData.Watt != null && cData.Timer != null) { textBoxCadence.Text = CycleRoutine.ToRoundDown(double.Parse(cData.Cadence), 1).ToString(); textBoxWatt.Text = CycleRoutine.ToRoundDown(double.Parse(cData.Watt) / 2.25, 1).ToString(); } }
private async void serialPortCycle_DataReceived(object sender, SerialDataReceivedEventArgs e) { var sw = new Stopwatch(); sw.Start(); await Task.Run(() => { try { data += serialPortCycle.ReadExisting(); } catch (Exception) { return; } }); sw.Stop(); //受信に時間がかかりすぎた場合はbufferを削除します。(いらないかも) if (sw.ElapsedMilliseconds > 5000) // serialPortCycle.DiscardInBuffer(); //データが短すぎるもしくは長すぎる場合は、returnしてdataの中身を調整します。 #region filter { try { if (data == null) { return; } else if (data.Length < Constants.minDataPoolAmount) { return; } else if (data.Length > Constants.maxDataPoolAmount) { data = null; return; } } catch (Exception ex) { } } #endregion var tempDataLines = data.Trim().Replace(";\r\n;", "\n").Split('\n'); var dataLines = new List <string>(); foreach (var dataMem in tempDataLines) { if (dataMem.Length > 20) { dataLines.Add(dataMem); } } try { foreach (var dataLine in dataLines) { var datas = dataLine.Trim().Split(';'); foreach (var oneData in datas) { if (String.IsNullOrEmpty(oneData)) { return; } } if (datas.Count() == 14) { var _cycleData = new CycleDatas(); _cycleData.Voltage = datas[5]; Voltage = datas[5]; _cycleData.Watt = CycleRoutine.CadenceToWatt((-double.Parse(datas[13]) / 6.0), _loadLevel).ToString(); _cycleData.Speed = (-double.Parse(datas[13])).ToString(); _cycleData.Cadence = (-double.Parse(datas[13]) / 6.0).ToString(); _cycleData.Timer = generalTimer; _cycleDataList.Add(_cycleData); BeginInvoke((MethodInvoker)(() => ShowCycleData(_cycleData))); BeginInvoke(new ChartHandler(ShowChart), _cycleData); } } } catch (Exception) { return; } }