FahriSnl
Member
- Joined
- Nov 22, 2021
- Messages
- 5
- Programming Experience
- 3-5
Hello everyone. I have a problem. I am getting datas from serial port than writing them in datagridview tool. If i add rows manually by a button there is no problem but if i write them in serial port recive function when datas reach edge of display app crashes. Do anyone know what is the problem?
Here code piece and error:
Works fine:
App Crashes:
Here code piece and error:
C#:
private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
label1.Text = "";
// 01 04 00 07 00 01 80 0B
byte[] a = { 0x5A, 0xB2, 0xC3 };
//Thread.Sleep(500);
byte[] receivedData = new byte[5];
serialPort1.Read(receivedData, 0, 5);
byte crc = 0;
crc = (byte)(receivedData[0] + receivedData[1] + receivedData[2] + receivedData[3]);
label8.Text = crc.ToString();
label9.Text = receivedData[4].ToString();
if ((receivedData[3] % 25 == 0)&&(crc==receivedData[4]))
{
table.Rows.Add(receivedData[0], receivedData[1], receivedData[2], receivedData[3], receivedData[4]);
}
label6.Text = data1;
int index = 0;
foreach (byte b in receivedData)
{
label1.Text += DecimalToHexadecimal(b);
// label1.Text += string.Format("{0:x}", b);
if (index % 2 == 0)
label1.Text += " ";
index++;
}
Works fine:
App Crashes:
Last edited by a moderator: