Main Site Documentation

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


#1

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


#2

@ 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;
    }
  }
}


#3

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++;
            }
        }
    }
}

#4

I left my Cobra running your code at work. Will check tomorrow if it crashed or not.


#5

Architect,

Fabulous…look forward to what you find.
Thanks


#6

@ 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.


#7

No issues here. Was running USB powered over the whole weekend.


#8

Have you tried to run something else for a while to see if the board crashes? Maybe it crashes after sometime with any program.


#9

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!


#10

@ mhardy - Have you tried different hardware?


#11

No not yet…have kinda been waiting on your guy’s analysis of the problem…


#12

@ mhardy - We have been unable to reproduce it. So it is likely something on your end. Trying different hardware will help us narrow it down.


#13

OK…

Can you tell me what voltage I should supply via the power jack. I have heard, thru the forum, anywhere from 6V to 12V? The webpage says anywhere from 7-30VDC. Note: I will also have the USB (client) debug cable connected.

So, the plan will be:

1.) Try a different RS232 module.
2.) Try a different USB cable.
3.) Re-flash everything.
4.) Try a different Cobra II (eco)

If I need to get a new Cobra II, will you guys find the root cause of the failure if I ship the board to you?


#14

@ mhardy - Anywhere from 7-30V will be fine. Just note that the higher the voltage you supply, the more heat that needs to be dissipated.

If the issue persists with different hardware, we can issue an RMA to you and take a look at your board.


#15

OK…Will let you know results.


#16

John,

So far the first two trials did not fix anything.

1.) Try a different RS232 module.
2.) Try a different USB cable.

I am on step 3.) Re-flash everything.

I don’t (can’t) update the ghi boot loader, right. Do I need to erase flash via commands (Teraterm).

Should I update Tiny booter with Fez config or do i use commands (TeraTerm)?


#17

@ mhardy - You can update TinyBooter using FEZ Config.


#18

@ John - FYI, I had to go with TeraTerm last week. Couldn’t update my Cobra II using FEZ Config. COM Port was visible in Device Manager, but FEZ Config acted like it was not.


#19

@ Architect - Thanks, we’ll take a look before the next SDK.


#20

John & Architect -

Using Fez Config I updated Tiny Booter and by default the Firmware (TinyCLR, netMF).
Reloaded my application and ran it.
Same results, crash report after ~30sec.

Is it agreed that my Cobra II (eco) has some problem / defect?
I would like to ship this one back and get it evaluated for root cause.
I will order another Cobra II (eco) and hopefully all goes well.

Does this sound like best method to keep moving forward?

Aside from above, It’s not clear how to update Tiny Booter manually?
The COM port is not visible in Device Manager until I run Fez Config to update Tiny Booter.
Once Tiny Booter starts loading, Fez Config says it found COM 3, and COM3 shows in device manager. After Fez Config is done loading stuff, COM 3 disappears from device manager?