RXevent on serial port not firing

Hello,
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);

        _serialPort.Open();

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.

Has anybody else run into this issue?

thanks,
Peter

Open the port first then attach to DataReceived. It’s a weird bug…

Hi Peter14,
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.

I hope this helps,
PepLluis,

brilliant!

open the port first and attach later apparently is the way to make it work.

thanks,
Peter

Please make you post a question and then give Ian credit for the answer. :slight_smile:

How do you solve RXevent not firing on USBizi?

the solution Ian sent resolves the issue.

Thanks again!

:slight_smile: