In my project I want to create a Windows application using C# to communicate with the Electronic Board Atxmega via Serial Port Using the Modbus protocol. I could send the write command from the PC to board and the Board send the correct response but I couldn't read it in my PC. I don't know why I can't receive the complete packet
it tried this
bytesRead = new byte[Modbus1.BytesToRead];
for (i = 0; i < Modbus1.BytesToRead; i++)
{
bytesRead[i] = (byte)(Modbus1.ReadByte());
}
and this
Modbus1.Read(bytesRead, 0, Modbus1.BytesToRead);
but I couldn't receive the complete Packet so how can I receive the complete packet from the serial port ? And what's wrong with my code ?