/// <summary> /// read the data buff and timestamp buff start from buff tail /// /// </summary> /// <param name="data_name"></param> /// <param name="point_id"></param> /// <returns></returns> private ChartLineDataInfo getDataBuffFromTail(string data_name, int point_id) { ChartLineDataInfo info = new ChartLineDataInfo(); info = mainform.monitorData[data_name, point_id].readDecodedValueBuff(1); return(info); }
/// <summary> /// read the data buff and timestamp buff /// array[0]: value, array[1]: timestamp /// </summary> /// <param name="len"></param> /// <returns></returns> public ChartLineDataInfo readDecodedValueBuff(int len) { ChartLineDataInfo info; if (this.tail > 0) { info = new ChartLineDataInfo((double)time_stamp_buff[this.tail - 1], (double)value_buff[this.tail - 1]); //info = new ChartLineDataInfo((double)value_buff[this.tail - 1], (double)time_stamp_buff[this.tail - 1]); } else { info = new ChartLineDataInfo(); } int cnt = 0; while (this.head != this.tail && cnt < len) { if (this.tail < 0) { break; } info.YValueDataValue = (double)value_buff[this.tail]; info.XValueTimeStamp = (double)time_stamp_buff[this.tail] / 1000; // us -> ms this.tail += 1; cnt += 1; if (this.tail >= MAX_BUFF_LEN) { this.tail = 0; } } return(info); }
/// The AddNewPoint function is called for each series in the chart when /// new points need to be added. The new point will be placed at specified /// X axis (Date/Time) position with a Y value in a range +/- 1 from the previous /// data point's Y value, and not smaller than zero. public void AddNewPoint(DateTime timeStamp, Series ptSeries, int chart_ind, int area_ind, int add_data_times_cnt) { int time_length = 120; // unit: seconds double[] data = new double[2]; double[] data_value; int cnt = chart[chart_ind].ChartAreas.Count; ChartLineDataInfo lineDataInfo = new ChartLineDataInfo(); ChartLineDataInfo lineData = new ChartLineDataInfo(); DateTime time_tmp = DateTime.Now; for (int i = 0; i < 1; i++) { // including point_id and the date type(s0, s1, etc..) //string[] name_str = chart[chart_ind].Titles[area_ind].Text.Split('-'); // 1-S0, 5-S1 6-U1 etc. lineDataInfo.setDataInfo(chart[chart_ind].Titles[area_ind].Text); int buff_cnt = 0; double time_offset; double data_time_interval = this.chart_update_interval / this.add_num_amount; int tail = mainform.monitorData[lineDataInfo.DataName, lineDataInfo.DataPointID].tail; int head = mainform.monitorData[lineDataInfo.DataName, lineDataInfo.DataPointID].head; data_value = getDataBuffFromTail(lineDataInfo.DataName, lineDataInfo.DataPointID, add_num_amount); while (mainform.monitorData.tail != mainform.monitorData.head && buff_cnt < add_num_amount) { //lineDataInfo.getDataInfo(chart[chart_ind].Titles[area_ind].Text); //if (lineDataInfo.DataName != "") { /* * // get data from buff * if (buff_cnt == 0) * mainform.monitorData[lineDataInfo.DataName, lineDataInfo.DataPointID].tail = mainform.monitorData[lineDataInfo.DataName, lineDataInfo.DataPointID].head - add_num_amount; * * lineData = getDataBuffFromTail(lineDataInfo.DataName, lineDataInfo.DataPointID); * * time_offset = (double)(-data_time_interval) * (add_num_amount - buff_cnt - 1); // ms * time_tmp = timeStamp.AddMilliseconds(time_offset); * ptSeries.Points.AddXY(time_tmp.ToOADate(), lineData.YValueDataValue); */ time_offset = (double)(-data_time_interval) * (add_num_amount - buff_cnt - 1); // ms time_tmp = timeStamp.AddMilliseconds(time_offset); ptSeries.Points.AddXY(time_tmp.ToOADate(), data_value[buff_cnt]); /* * lineData.YValueDataValue = mainform.monitorData.getDecodedValue(lineDataInfo.DataName, lineDataInfo.DataPointID); * ptSeries.Points.AddXY(timeStamp.ToOADate(), lineData.YValueDataValue); */ mainform.monitorData.tail += 1; buff_cnt += 1; } } // Add new data point to its series. //ptSeries.Points.AddXY(timeStamp.ToOADate(), rand.Next(5, 20)); //ptSeries.Points.AddXY(mainform.DateTimeStamp.AddMilliseconds(data[1]).ToOADate(), data[0]); if (add_data_times_cnt >= 0) { // remove all points from the source series older than 1.5 minutes. double removeBefore = timeStamp.AddSeconds((double)(time_length) * (-1.2)).ToOADate(); //remove oldest values to maintain a constant number of data points if (ptSeries.Points.Count > 0) { while (ptSeries.Points[0].XValue < removeBefore) { if (ptSeries.Points.Count > 1) { ptSeries.Points.RemoveAt(0); } else { break; } } } //chart[ind].ChartAreas[i].AxisX.Minimum = ptSeries.Points[0].XValue; //chart[ind].ChartAreas[i].AxisX.Maximum = DateTime.FromOADate(ptSeries.Points[0].XValue).AddSeconds((double)time_length).ToOADate(); chart[chart_ind].ChartAreas[area_ind].AxisX.Minimum = timeStamp.AddSeconds((double)(time_length) * (-1)).ToOADate(); chart[chart_ind].ChartAreas[area_ind].AxisX.Maximum = timeStamp.ToOADate(); //chart[chart_ind].Invalidate(); } } // redraw chart[i] //chart[chart_ind].Invalidate(); }