I have this code that sets up a serial port
_serialPort = new SerialPort(portName, 19200, Parity.None, 8, StopBits.One);
//hook in data received handler
//_serialPort.DataReceived += new SerialDataReceivedEventHandler(sp_DataReceived);
//hook in the error handler
//_serialPort.ErrorReceived += new SerialErrorReceivedEventHandler(ErrorReceived);
If I run this code, sometimes the serial port receive event does not fire when I send data to the port.
I checked to make sure the error handle is not firing instead - which it isnt
The strange thing is that the event mostly fires when I am in debug mode, but when I run the board
"stand alone", the event does not fire at all.
I remember something similar when I try perform some port test with serial module.
In my case and if i’m not wrong, The ‘DataReceived’ only fires the first time when incoming chars, and works fine if you read all incoming bytes “Serial.SerialLine.Read(buffer, 0, Serial.SerialLine.BytesToRead)” inside the event handler.
But just to be a short experience… I don’t know if this may occur in other scenarios.
This be quite deferent in .net for desktops, where the ‘DataReceived’ of SerialPort is fired every time that you are out of the ‘event handler function’ and receive new data with no matter the buffer status.