Hi all,
Can anyone guide me to some documentation or explain to me how I can figure out what is going on inside SerialPort.DataRecieved?
I use it as follows:
serial.DataReceived += new SerialDataReceivedEventHandler(SerialRecieveHandler);
I have an Arduino (Leonardo) sending data on serial interface to the Netduino+2 periodically (once pr sec).
Inside SerialRecieveHandler() I do like this:
if (serial.BytesToRead > 0) { while (serial.BytesToRead > 0) { // read data } // process data } else //write log to SD
My problem is that it seams like the event handler is triggered twice since:
- I get the data
- and I get the log in "else"
- every second.
I did see something on the forum about SerialHelper class for buffering data. Is my problem that the event handler is triggered on the first byte and again set in queue "later"? In this case I'm just lucky that my data is not cut in half! I don't like the uncertainty.
My full string that I receive every second is 9 bytes and it does get read right and converted to an int. I'm just wondering why the event handler is triggered twice.
So, how does it work and should I be using it differently?
PS, I use VS2010, NETMF 4.2 and firmware 4.2.2