void displayText(object o, EventArgs e) { //--Either Debug message or data char indicator = (char)UART.ReadChar(); if (indicator == 'a') { try { //-- byte[] bytes = new byte[55]; for (int i = 0; i < 55; i++) { bytes[i] = (byte)UART.ReadByte(); } ushort co2 = (ushort)((rxString[1] << 8) & (rxString[2])); float h1 = BitConverter.ToSingle(bytes, 2); //-- Add Data to Table. First get index to new row int n = dataGridView1.Rows.Add(); //-- Columns are DateTime, Co2, TempA, HumidA, TempB, HumidB etc dataGridView1.Rows[n].Cells[0].Value = (DateTime.Now).ToString(); dataGridView1.Rows[n].Cells[1].Value = BitConverter.ToUInt16(bytes, 0); //--Co2 dataGridView1.Rows[n].Cells[2].Value = BitConverter.ToSingle(bytes, 2); //--Temperature Dev A dataGridView1.Rows[n].Cells[3].Value = BitConverter.ToSingle(bytes, 6); //--Humidity Dev A dataGridView1.Rows[n].Cells[4].Value = BitConverter.ToSingle(bytes, 10); //-- Temperature Dev B dataGridView1.Rows[n].Cells[5].Value = BitConverter.ToSingle(bytes, 14); //-- Humidity Dev B dataGridView1.Rows[n].Cells[6].Value = BitConverter.ToUInt16(bytes, 18); //--Co2 dataGridView1.Rows[n].Cells[7].Value = BitConverter.ToSingle(bytes, 20); //--Temperature Dev A dataGridView1.Rows[n].Cells[8].Value = BitConverter.ToSingle(bytes, 24); //--Humidity Dev A dataGridView1.Rows[n].Cells[9].Value = BitConverter.ToSingle(bytes, 28); //-- Temperature Dev B dataGridView1.Rows[n].Cells[10].Value = BitConverter.ToSingle(bytes, 32); //-- Humidity Dev B dataGridView1.Rows[n].Cells[11].Value = BitConverter.ToUInt16(bytes, 36); //--Co2 dataGridView1.Rows[n].Cells[12].Value = BitConverter.ToSingle(bytes, 38); //--Temperature Dev A dataGridView1.Rows[n].Cells[13].Value = BitConverter.ToSingle(bytes, 42); //--Humidity Dev A dataGridView1.Rows[n].Cells[14].Value = BitConverter.ToSingle(bytes, 46); //-- Temperature Dev B dataGridView1.Rows[n].Cells[15].Value = BitConverter.ToSingle(bytes, 50); //-- Humidity Dev B } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Apppending to datagrid view failed with exception: " + ex.ToString()); } } else { rxString = UART.ReadLine(); System.Diagnostics.Debug.WriteLine(indicator + rxString); } }
private void Datareceive(object sender, SerialDataReceivedEventArgs e) { FeedbackData = UART.ReadLine(); SetTextFeedBack(FeedbackData); }