I'm receiving serialdata via the eventHandler
static void camera_DataReceived(object sender, SerialDataReceivedEventArgs e) { lock(serialBuffer){ int bytesReceived = serial.BytesToRead; //Debug.Print("" + bytesReceived); if (bytesReceived > 0) { serial.Read(serialBuffer, 0, bytesReceived); bufferLength += bytesReceived; } } }
works fine until i try to write the incomming data to the sd card.
while (watchdog.ElapsedMilliseconds <= timeout && bytesWritten < size60) { fs.Write(serialBuffer, 0, bufferLength); //write received bytes to sd bytesWritten += bufferLength; Debug.Print("written: " + bytesWritten); bufferLength = 0; } fs.Close();
I'm receiving a picture from a camera.
if i lose the line
fs.Write(serialBuffer, 0, bufferLength);I receive all the bytes of the picture.
When i write the bytes from buffer to SD, i lose some bytes.
I guess the write routine takes to long, and therefore the incoming serial-data can't be written to the buffer.
How can i buffer the incoming data without any loss?
Thanks in advance!