I get temperature readings from the COM port and now I need to use them in the real-time temperature chart.

I want to do something like this:

public partial class Form1 : Form { public Form1() { InitializeComponent(); TemperatureGraph tempGraph = new TemperatureGraph(new List<int> { },new List<double> { }); Panelchart.Series[0].Points.DataBindXY(tempGraph.DateTimeList,tempGraph.TemperatureList); } } public class TemperatureGraph { private List<int> DateTime; private List<double> Temperature; public List<int> DateTimeList { get { return DateTime; } } public List<double> TemperatureList { get { return Temperature; } } public TemperatureGraph(List<int> DateTime,List<double> Temperature) { this.DateTime = DateTime; this.Temperature = Temperature; } } 

I get the data in these code snippets:

  private void Response(byte[] msg) { Invoke(new EventHandler(delegate { //Response Collect Data for (int i = 0; i < msg.Length; i++) responsecollect.Add(msg[i]); // Function 3 response if (responsecollect.Count == responseFunc3total) { byte[] responseFunc3 = responsecollect.ToArray(); //Function Code Check if (responseFunc3[1] == 3) { //CRC Error Check if (CRCResponseCheck(responseFunc3)) { for (int i = 0; i < Request_Collect.Count; i++) { for (int j = 0; j < General_Collect.Count; j++) if (Request_Collect[i].Adress_MB == General_Collect[j].Adress_MB) { Int16 value = 0; // Рассшифровка if (Request_Collect[i].Byte_Count == 2) { //Data Hi and Registers1 from Index3 value = responseFunc3[2 * i + 3]; //Move to Hi value <<= 8; //Data Lo and Registers1 from Index4 value += responseFunc3[2 * i + 4]; if (Request_Collect[i].Adress_MB == 0x0002) richTextBox111.Text += value * Math.Pow(10, -1) + "\n"; else richTextBox1111.Text = value * Math.Pow(10, -1) + " " + "\n"; } else if (Request_Collect[i].Byte_Count == 4) { richTextBox1111.Text += Request_Collect[i].Appointment + " (" + Request_Collect[i].Name_OWEN + ")" + " = " + BitConverter.ToSingle(new byte[] { responseFunc3[6], responseFunc3[5], responseFunc3[4], responseFunc3[3] }, 0) + "\n"; } /// char 

Value - the temperature values ​​that I get and I want to put Value instead:

 ,new List<double> { }); 

Tell me how to do this?

  • It scares me Invoke(new EventHandler(delegate very. Refactoring is needed, break these nesting dolls into a series of callable methods, it will be easier to understand and figure out what's what. - Bulson
  • The question is: how to bind the data that I get to, new List <double> {}); ??? - Abdulaziz Amanzhol
  • one
    Yes, TemperatureGraph tempGraph = new TemperatureGraph (new List <int> {}, new List <double> {}); // here, instead of the first parameter, write a List <int> with the desired dates, and the second parameter is a List <double> with the desired temperature. - Abdulaziz Amanzhol

1 answer 1

I suspect that you need to use Fifo https://ru.wikipedia.org/wiki/FIFO

Search for information about Queue in Sharp. This is exactly what is needed if this is a list of elements changing in real time. This is the first.

Second, create a simple method that works with the chart and fill it in every time you change the FIFO. If this is the first drawing - then all the points. If this is not the first drawing - then just delete the first point and add the last one.

Sign this method on the event changes Queue.