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?
Invoke(new EventHandler(delegatevery. 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