You must be logged in to reply.

Page 1 of 3 out of 30 messages.

Scary G120 (Cobra II eco) NetMF, System.Text.UTF8Encoding, System Exception

Posted 4yr ago
by mhardy | Junior | 590 exp
Posted 4yr ago
by mhardy | Junior | 590 exp
I keep getting an exception thrown when converting strings to byte[].
The code increments a counter in a loop and writes the bytes out to COM1.
Inspecting the variables when an exception is thrown shows everything is OK.
The exception is thrown at various times (under 30sec it seems) and various counter values.
The code is shown further below
Any ideas as to what is happening?

Also, the output of the serial port "SOMETIMES" changes to like debug output, shown below:

Hello 34441


EXCEPTION 0x05:
cpsr=0x61000800
pc =0x0002c1c4
lr =0x00031adf
sp =0x1000fdf0
r00 =0xa06fe240
r01 =0x00000013
r02 =0x00000000
r03 =0x00000003
r04 =0xa06fe240
r05 =0x00010002
r06 =0x00010026
r07 =0x00000000
r08 =0xa00250c0
r09 =0x00000003
r10 =0x00000000
r11 =0x00000000
r12 =0x00000000
EXCEPTION 0x06:
cpsr=0x00000000
pc =0x00010026
lr =0x00010002
sp =0x1000fdd0
r00 =0xa06fe240
r01 =0x00000013
r02 =0x00000000
r03 =0x00000003
r04 =0xa06fe240
r05 =0x00010002
r06 =0x00010026
r07 =0x00000000
r08 =0xa00250c0
r09 =0x00000003
r10 =0x00000000
r11 =0x00000000
r12 =0xa06fe240

-----------------Code generating the error ------------------------------------

using System;
using Microsoft.SPOT;

namespace MFConsoleApplication1 {
public class Program {
private static System.IO.Ports.SerialPort _modemSerialPort = null;
private static byte[] _writeBuf = null;
private static byte[] _readBuf = new byte[256];

public static void Main() {
try {
_modemSerialPort = new System.IO.Ports.SerialPort("COM1", 115200, System.IO.Ports.Parity.None, 8, System.IO.Ports.StopBits.One);
_modemSerialPort.ReadTimeout = 5000;
_modemSerialPort.Open();

Microsoft.SPOT.Debug.Print(_modemSerialPort.PortName);
int cnt = -1;

while (true) {
if (_modemSerialPort.IsOpen) {
try {
_writeBuf = System.Text.Encoding.UTF8.GetBytes("Hello " + cnt.ToString() + "\r");
_modemSerialPort.Write(_writeBuf, 0, _writeBuf.Length);
} catch (Exception ey) {
Microsoft.SPOT.Debug.Print(ey.ToString()); //<-- Exception caught here
break;
}
}
cnt++;
}
} catch (Exception ez) {
Microsoft.SPOT.Debug.Print(ez.ToString());
}
}
}
}

Output of Microsoft.SPOT.Debug.Print(ey.ToString());
-----------------------------------------------------------
#### Exception System.Exception - CLR_E_WRONG_TYPE (1) ####
#### Message:
#### System.Text.UTF8Encoding::.ctor [IP: 0004] ####
#### System.Text.Encoding::get_UTF8 [IP: 0003] ####
#### MFConsoleApplication1.Program::Main [IP: 0047] ####
A first chance exception of type 'System.Exception' occurred in mscorlib.dll

Output of Stack Trace when inspecting Exception in Quick Watch
--------------------------------------------------------------
System.Text.UTF8Encoding::.ctor
System.Text.Encoding::get_UTF8
MFConsoleApplication1.Program::Main
Reply #1 — Posted 4yr ago
by taylorza | Legend | 63,805 exp
Reply #1 — Posted 4yr ago
by taylorza | Legend | 63,805 exp
@mhardy - I have not tried this and I do not have a G120 so I am not going to even try guess what the issue is (though I do have a gut feeling)... what would like to ask is that you try something a little different to confirm that the issues is where it looks like it is or is it just an artifact of something else.

Rather than access the UTF8 property every iteration, cache and instance of the encoder. For example

var encoder = System.Text.Encoding.UTF8; // Cache encoder

while (true) {
  if (_modemSerialPort.IsOpen) {
    try {
      _writeBuf = encoder.GetBytes("Hello " + cnt.ToString() + "\r");
      _modemSerialPort.Write(_writeBuf, 0, _writeBuf.Length);
    } 
    catch (Exception ey) {
      Microsoft.SPOT.Debug.Print(ey.ToString());
      break;
    }
  }
}
Reply #2 — Posted 4yr ago
by mhardy | Junior | 590 exp
Reply #2 — Posted 4yr ago
by mhardy | Junior | 590 exp
taylorza,

I tried your suggestion.
It did not work.
The port starts spewing crash data after ~30sec.

I also added System.Threading.Thread.Sleep(100) in the loop.
It did not work.
The port starts spewing crash data after ~40min.

I purchased a 6V supply, connected it to the power jack w/usb debug connected.
It did not work, same results.

I disconnected usb debug and ran off the 6V supply (which I measured with DMM at 6.167V).
It did not work, same results.

I am at the point of assuming I have a bad Cobra II eco?
Any other ideas?

using System;
using Microsoft.SPOT;

namespace MFConsoleApplication1 {
    public class Program {
        private static System.IO.Ports.SerialPort _modemSerialPort = null;
        private static byte[] _writeBuf = null;
        private static byte[] _readBuf = new byte[256];
        
        public static void Main() {
            var encoder = System.Text.Encoding.UTF8;
            _modemSerialPort = new System.IO.Ports.SerialPort("COM1", 115200, System.IO.Ports.Parity.None, 8, System.IO.Ports.StopBits.One);
            _modemSerialPort.ReadTimeout = 5000;
            _modemSerialPort.Open();

            Microsoft.SPOT.Debug.Print(_modemSerialPort.PortName);
            int cnt = -1;

            while (true) {
                if (_modemSerialPort.IsOpen) {
                    try {
                        _writeBuf = encoder.GetBytes("Hello " + cnt.ToString() + "\r");
                        _modemSerialPort.Write(_writeBuf, 0, _writeBuf.Length);
                    } catch (Exception ey) {
                        Microsoft.SPOT.Debug.Print(ey.ToString());
                        break;
                    }
                }
                System.Threading.Thread.Sleep(100);
                cnt++;
            }
        }
    }
}
Reply #3 — Posted 4yr ago
by Architect | Immortal | 176,996 exp
Reply #3 — Posted 4yr ago
by Architect | Immortal | 176,996 exp
I left my Cobra running your code at work. Will check tomorrow if it crashed or not.
Reply #4 — Posted 4yr ago
by mhardy | Junior | 590 exp
Reply #4 — Posted 4yr ago
by mhardy | Junior | 590 exp
Architect,

Fabulous...look forward to what you find.
Thanks
Reply #5 — Posted 4yr ago
by John_ghielectroncs | Employee
Reply #5 — Posted 4yr ago
by John_ghielectroncs | Employee
@mhardy - I've had your code running for over an hour now with no issue, both with and without the sleep. If you haven't already, I would reflash the loader and firmware, then I would try a second Cobra II, cable, connector, and computer.
Reply #6 — Posted 4yr ago
by Architect | Immortal | 176,996 exp
Reply #6 — Posted 4yr ago
by Architect | Immortal | 176,996 exp
No issues here. Was running USB powered over the whole weekend.
Reply #7 — Posted 4yr ago
by Gus_ghielectroncs | Employee
Reply #7 — Posted 4yr ago
by Gus_ghielectroncs | Employee
Have you tried to run something else for a while to see if the board crashes? Maybe it crashes after sometime with any program.
Reply #8 — Posted 4yr ago
by mhardy | Junior | 590 exp
Reply #8 — Posted 4yr ago
by mhardy | Junior | 590 exp
Yes, I started off running a much larger program (multiple serial ports, ethernet, SD Card, CAN....). The program crashed, so I tried to minimize scope, i.e. a simple serial port sending out data.

I have been stuck in the debug mode for about a week now!

I really want to send the board to you for evaluation. We are desinging a board based on the G120....we need to know the root cause of this problem!
Reply #9 — Posted 4yr ago
by John_ghielectroncs | Employee
Reply #9 — Posted 4yr ago
by John_ghielectroncs | Employee
@mhardy - Have you tried different hardware?

Page 1 of 3 out of 30 messages.

You must be logged in to reply.