Main Site Documentation

Serial Line Recieved only works in Debug mode


#1

I have an application that is receiving GPS data on a serial port. It works as expected in Debug mode, but if I end the debug session and reset the Fez Hydra, the LineReceived event never gets triggered and I get a buffer overflow.

I am using a local copy of serial.cs to avoid the memory overflow problem previously reported.

My setup code is:

        GT.Socket socket = GT.Socket.GetSocket(7, true, null, "U");

        ResetPin = new GTI.DigitalOutput(socket, GT.Socket.Pin.Three, true, null);

        serial = new GTI.Serial(socket, 57600, GTI.Serial.SerialParity.None, GTI.Serial.SerialStopBits.One, 8, GTI.Serial.HardwareFlowControl.NotRequired, null);
        serial.LineReceivedEventDelimiter = DELIMITER;
        serial.AutoReadLineEnabled = true;
        serial.Open();   
        serial.LineReceived += new GTI.Serial.LineReceivedEventHandler(serial_LineReceived);

I found a previous post with a similar issue and the solution was to open the port before defining the DataReceived event. I have tried putting the open statement before and after defining the LineReceived event but it makes no difference.

Thanks


#2

@ pi - If you do not have a debugger attached, how do you know the event is not firing and an overflow is occurring?

When a program works in debug but not standalone, it is usually a timing issue. For example, there is an device that takes a time period to initialize after power-up. When the debugger is attached, there is a delay before your code begins to execute, which is sufficient for the device to initialize. But, without the debugger, your code starts to execute sooner, and it is possible that a device has not had time to complete the power up.


#3

The linerecieved handler writes some of the GPS data to the LCD display. The output starts with a .Clear command, this is never executed. When an overflow occurs a message is written to the LCD screen, that always happens in a few seconds if the seral data processing stops.

To test your idea I put:

Thread.Sleep(1000);

just before opening the serial port, and that has fixed it. I can now disconnect the Hydra from my PC, press reset and it starts running as expected.

Thanks!