Serial port hanging on Raptor

Hi,

I am having a strange behavior with the serial port on Raptor.

I have a barcode scanner (symbol ls2208) plugged via RS232 module on socket 4 and a T43 display to the Raptor.

The code read by the scanner is shown on display. The problem is that the raptor stops processing the barcodes if I stop sending barcodes for a couple of minutes, sometimes even seconds. This happens with a barcode scanner and also with any other serial test frame sent to the raptor’s serial port, so it seems logic to discard the barcode scanner as being the problem.

I migrated the application from a spider board to the raptor. With the spider the barcode reader behaves without issues, and the code is exactly the same.

I shrinked the application to remove code not related with the issue, and I can reproduce the missbehavior on the Raptor with the following app on Gadgeteer:

namespace GW_Tests
{
    public partial class Program
    {

        void ProgramStarted()
        {
            //RS232 module on raptor socket 4
            rs232.Configure(9600, SerialParity.None, SerialStopBits.One, 8, HardwareFlowControl.NotRequired);
            rs232.Port.LineReceived += Port_LineReceived;
            displayT43.DebugPrintEnabled = true;
            displayT43.SimpleGraphics.DisplayText("Program started", Resources.GetFont(Resources.FontResources.NinaB), GT.Color.Yellow, 80, 80);

        }

        void Port_LineReceived(Serial sender, string line)
        {
            displayT43.SimpleGraphics.Clear();
            displayT43.SimpleGraphics.DisplayText(line, Resources.GetFont(Resources.FontResources.NinaB), GT.Color.Yellow, 80, 80);
        }
    }
}

from the last three days, I have been testing all kind of options to make the serial port stable, without luck. even tried the serial port with NETMF instead of gadgeteer, but the serial port also stops working with the app written for plain NETMF.

Can someone from GHI or the community give advice if I am doing something wrong here or try to reproduce the issue to discard a bad raptor board from my side?

Thanks ???

1 Like

@ Ninja - So we can try to reproduce it, can you post some sample data that the scanner sends?

@ John - Hi,

Thank you for your very fast response!

I read barcodes with 22 chars and others are 15 chars, plus the end of barcode “\r”.

A sample is “*ABC123456XY9ZA8DEF7G6\r”.

I forgot to mention that I am using firmware 4.3.6.0.

Kind regards.

How are you powering the board?

Have you looked with the debugger to see what is happening when the processing stops?

Have you tried to use the DataReceived event handler and looked for the \r yourself?

@ Mike - Hi,

Thanks for the answer.

I power the board with debug and without debug attached, with Client DP from USB and from 12V, but the result is the same.

I checked with the debugger attached but there is nither a message with an exception, nor a thread ending the execution.

I tried also with the DataReceived event, and the problem is still the same, the serial port stops working after a while.

Any help is appreciated.

Regards.

@ Ninja - To make sure I understand it properly: You can send barcodes repeatedly for hours on end with no issue. But if you stop for say a few minutes at some random point, you often won’t be able receive the barcodes again?

Does the board otherwise still respond once the barcodes start to fail?

@ John - Hi,

Yes, you understand it properly.

The board runs other threads like wifi handling after the serial port stops working, so the board is not frozen completely, only the serial port is dying. It takes sometimes only some seconds of no-frames to freeze the serial port.

If you run the test program with the T43 and the serial port, you only need to leave the program running for a minute and the serial port will be unresponsive. If you try this program without the display then the serial port will not stop working. It seems to be related with the combination of display and serial port i guess.

Kind regards.

@ Ninja - After it fails, can you dispose of the serial port and recreate it and see if it works?

@ John - Hi,

I tested as you suggested, disposing the serial port and recreating it again. The result is the same, the serial port hangs and it is not able to work again even if disposed and recreated.

This time I made the tests with the serial port connected to the PC via hyperterminal and with netmf instead of gadgeteer. No barcode reader.

Here is the code I used:

namespace GW_Tests
{
    public partial class Program
    {
        System.IO.Ports.SerialPort _uart;
        void ProgramStarted()
        {
            displayT43.DebugPrintEnabled = true;
            Gadgeteer.Timer tmr = new Gadgeteer.Timer(10000, GT.Timer.BehaviorType.RunContinuously);
            tmr.Tick += tmr_Tick;
            tmr.Start();
            RecreateSerialPort();
        }
        void tmr_Tick(GT.Timer timer)
        {
            RecreateSerialPort();
        }
        void RecreateSerialPort()
        {
            try
            {
                if (_uart != null)
                {
                    _uart.DataReceived -= uart_DataReceived;
                    _uart.ErrorReceived -= uart_ErrorReceived;
                    _uart.Dispose();
                }
                //RS232 module on raptor socket 4 (COM2)
                _uart = new System.IO.Ports.SerialPort("COM2", 9600, System.IO.Ports.Parity.None, 8, System.IO.Ports.StopBits.One);
                _uart.Open();
                _uart.DataReceived += uart_DataReceived;
                _uart.ErrorReceived += uart_ErrorReceived;
                displayT43.SimpleGraphics.Clear();
                displayT43.SimpleGraphics.DisplayText("Serial Port Created", Resources.GetFont(Resources.FontResources.NinaB), GT.Color.Yellow, 80, 80);
            }
            catch (Exception ex)
            {
                Debug.Print("Error while creating serial port: " + ex.Message);
            }
        }

        void uart_ErrorReceived(object sender, System.IO.Ports.SerialErrorReceivedEventArgs e)
        {
            Debug.Print("Error at serial port: " + e.EventType.ToString());
        }
        void uart_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
        {
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            while (_uart.BytesToRead > 0)
            {
                byte[] dataRead = new byte[64];
                int readBytes = _uart.Read(dataRead, 0, _uart.BytesToRead < 65 ?_uart.BytesToRead: 64 );
                if (readBytes > 0)
                    sb.Append(System.Text.Encoding.UTF8.GetChars(dataRead));
                Thread.Sleep(10);
            }
            if (sb.Length > 0)
            {
                displayT43.SimpleGraphics.Clear();
                displayT43.SimpleGraphics.DisplayText(sb.ToString(), Resources.GetFont(Resources.FontResources.small), GT.Color.Yellow, 20, 80);
            }
        }
    }
}

This code opens the serial port, and reopens it every 10 seconds. Any string sent will be shown in the display, and refreshed every time a new data is received or every 10 seconds once the serial port gets opened again.

In my case, if I send strings from the begining of execution, it behaves as expected. But if i wait a minute before sending the first string, then the serial port gets frozen even after the port is destroyed and reopened. This test was done with the USB cable connected but not debugging.

Can you try to reproduce this issue?

Kind regards.

1 Like

@ Ninja - We will take a look and see if we can reproduce it.

@ Ninja -

Fixed for next release!

@ Dat - Hi,

Is it a workaround to solve it while you release the next version?

Please keep in mind that I need to solve it asap for our production plant units.

Thank you.

Kind regards.

1 Like

@ Ninja - There is no workaround sadly.

I am also using a Raptor with T43 display and several serial ports. I find that the DataReceived event will stop firing at a random time after start. By random I mean between minutes to over 1 hour. The rates at the serial ports are in the 10-100 characters per second, with baudrates at 115200.

I find that the port will keep sending data, but the interrupt will not longer fire. The code is quite long, with several projects, so I am wondering if this might be the same bug that I have been trying to find for TOO long… So any description with more detail of the issue would be of a great help.

Also, FEZRaptor 4.3.6
Microsoft 4.3.1
Firmware updated to latest

@ rockybooth - It does sound like the issue described in this thread. The next SDK should hopefully improve it for you too. If you can create a small project that reliably reproduces your issue, we can always take a look to verify.

@ John - How about you describing the bug is so that all of us users could inspect our code to see if it would impact us? That could steer other user using a Raptor with a UART in the right direction, or give us a clue on what to try to work around this behavior?

My code does include displayT43.simplegraphics.displaytext(…), and does use rs232.port.linereceived() interrupt.

Also, how long do you anticipate it will be until you release new SDK? This has effectively stopped my commercial project.

How about a hotfix?

Rocky

2 Likes

@ rockybooth, I’d give GHI a call and talk to them about the commercial aspect of your issue as in a 1:1 way they have better ability to help than out here in public.

Dat, I also have problems with serial port stop working and cause the raptor board to reboot multiple times a day. I am using T43 display. I always thought that has something to do with the networking problem NETMF has. Can you tell me exactly what you’ve fixed?