public void OnIncomingData(string data) { gotData_ = true; double[] resultCsv = null; resultCsv = DataStream.ExtractCsvFromLine(data); ToggleInvalidDataAlert("", false); if (resultCsv != null && resultCsv.Length > 0) { TreeNode root = treeView.Nodes[0]; double lastTime = stopwatch_.ElapsedMilliseconds / 1000.0; foreach (var series in ChartManager.Inst.GetSeriesManagersList()) { try { switch (series.DataType) { case SeriesManager.Type.BYTES_RATE: ulong newBytesCount = bytesInCounter.GetRawCounter(); bytesInRateCounter.SetCounter(newBytesCount - bytesInRateCounter.PrevCount); bytesInRateCounter.PrevCount = newBytesCount; addPointToSeries("Bytes Rate", lastTime, bytesInRateCounter.GetRawCounter()); break; case SeriesManager.Type.SETPOINT: addPointToSeries(series.NameId, lastTime, series.Setpoint); break; case SeriesManager.Type.INCOMING_DATA: // fill tree view node with series name and data value root.Nodes[series.DataIndex].Nodes[0].Text = series.NameId; root.Nodes[series.DataIndex].Nodes[0].Nodes[0].Text = resultCsv[series.DataIndex].ToString(); addPointToSeries(series.NameId, lastTime, resultCsv[series.DataIndex]); break; default: ToggleInvalidDataAlert("INVALID DATA", true); break; } } catch (ObjectDisposedException exp) { ToggleInvalidDataAlert("Error: " + exp.Data.ToString(), true); return; } } } else { ToggleInvalidDataAlert("INVALID DATA", true); } }
private void bytesRateTimer_Tick(object sender, EventArgs e) { ulong newBytesCount = bytesInCounter.GetRawCounter(); bytesInRateCounter.SetCounter(newBytesCount - bytesInRateCounter.PrevCount); bytesInRateCounter.PrevCount = newBytesCount; BytesCounter.MeasureUnit mUnit = bytesInRateCounter.RecomendedMeasureUnit(); var format = "{0:0}"; if (mUnit != BytesCounter.MeasureUnit.Bytes) { format = "{0:0.00}"; } var processedCounter = String.Format(format, bytesInRateCounter.GetProcessedCounter(mUnit)); Invoke((MethodInvoker) delegate { receivingRateLbl.Text = processedCounter + " " + BytesCounter.MeasureUnitToString(mUnit) + "/s"; }); }