hi
I Nedd help to read data form searilport
for Example
byte[] byt = new byte[23];
byt[0] =
byte.Parse("3A", NumberStyles.HexNumber);
byt[4] =
byte.Parse(txtMRP.Value.ToString()); //int iMRP = 5;
byt[ 6 ] =
byte.Parse(txtEQP.Value.ToString()); ; //int iEQP = 5;
byt[ 8 ] =
byte.Parse(txtBCP.Value.ToString()); //int iBCP = 5;
byt[10] =
byte.Parse(txtBPP.Value.ToString()); //int iBPP = 5;
byt[12] =
byte.Parse(txtAFI.Value.ToString()); //int iAFI = 5;
byt[14] =
byte.Parse(txtBEM.Value.ToString()); //int iBEM = 100;
byt[16] =
byte.Parse(txtTEM.Value.ToString()); //int iTEM = 200;
byt[18] =
byte.Parse(txtSPDI.Value.ToString()); //int iSPDI = 40;;
byt[21] =
byte.Parse("0D", NumberStyles.HexNumber);
byt[22] =
byte.Parse("0A", NumberStyles.HexNumber);
com1.Write(byt, 0, 23);
assume the above byt is one packet
here always byt[0] is start byte and byt[22] is end byte
When i read the data, i am not able get the 23 bytes. how do i get that exact byt in com2_DataReceived event.
void com2_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
byte[] getBytes = new byte[ 23 ];
com2.Read(getBytes, 0, 23);
for (x = 0; x <= 22; x++)
{
txtRead.AppendText(getBytes[x].ToString() +
" - ");
}
txtRead.AppendText(
"\n");
}
output is
58 - 0 - 0 - 0 - 5 - 0 - 5 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 -
5 - 0 - 5 - 0 - 5 - 0 - 100 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 -
200 - 0 - 40 - 0 - 0 - 13 - 10 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 -
In above case the DataReceived event is raised 3 times
expected result is
58 - 0 - 0 - 0 - 5 - 0 - 5 - 0 - 5 - 0 - 5 - 0 - 5 - 0 - 100 - 0 - 200 - 0 - 40 - 0 - 0 - 13 - 10
Please help.....