Hi, Im currently making an app on windows forms trying to program a micro over UART. I can achieve it, although it is taking a long time to carry out the program. I have used stopwatches to determine it is my read function taking up the majority of the time. When i try to read the micros response from each command I have to wait for all of it, which is why im using a while loop in the code below, if the returned message size is not what i expect. What im wondering is, if there is any way to speed up this process. The response from the micro should be pretty fast, its running at a baudrate of 115200, meaning the whole 512 kb file should in theory take just over 30 seconds to complete, at the moment it is more than double that, at 80 seconds.
private string CheckResponse(int mSize)
{
//ComPort.DataReceived += SerialPortDataReceived;
string response;
int intBuffer;
intBuffer = ComPort.BytesToRead;
byte\[\] byteBuffer = new byte\[intBuffer\];
ComPort.Read(byteBuffer, 0, intBuffer);
response = Encoding.ASCII.GetString(byteBuffer);
while(response.Length != mSize)
{
intBuffer = ComPort.BytesToRead;
byteBuffer = new byte\[intBuffer\];
ComPort.Read(byteBuffer, 0, intBuffer);
response += Encoding.ASCII.GetString(byteBuffer);
}
return response;
}
Any help greatly appreciated. Blair