Working in VS2008 C++/NET.
I have a SerialPort (spSIE) from which I am reading data at 921600 baud. I have the following code:
private: System::Void spSIE_DataReceived(...) { array<unsigned char>^ msg = gcnew array<unsigned char>(54); while (spSIE->BytesToRead > 54) { spSIE->Read(msg,0,54);<process record.....> } }
The probem is that sometimes there are bytes missing from the message, typically 5-20 bytes. For example if two records transmitted were both :
"s2345678901234567890123456789012345678901234567890123e"
I might receive:
"s23456789012345678456789012345678901234567890123es234"
I have set ReadBufferSize to 400000, and the BytesToRead doesn't get above 1000.
I have set ReadBytesThreshold=54 (the size of a record).
The records are not ASCII, but raw binary, any value may be in many of the records.
I replaced spSIE->Read(msg,0,54); with:
for (int i=0;i<54;i++) msg[i]=spSIE->ReadByte();
using the for loop, no bytes are ever lost, but the program does not keep up with the incoming messages (BytesToRead goes up and the buffer eventually gets full).
What can I do to read this message accuratly?