Main Site Documentation

G400D CAN enable exception


#1

Hi, I am using G400D CAN1 to decode some CAN bus data. The program works fine but occasionally, I got an exception when enable the CAN device.

The exception looks like:

Exception System.Exception - 0xffffffff (1)

Message:

GHI.IO.ControllerAreaNetwork::NativeEnable [IP: 0000]

GHI.IO.ControllerAreaNetwork::set_Enabled [IP: 0021]

RadarDataProcessor.RadarDataDecoder::Run [IP: 0035]

RadarDataProcessor.RadarDataProcessorApp::Main [IP: 0018]

A first chance exception of type ‘System.Exception’ occurred in GHI.Hardware.dll

In my RadarDataDecoder program, the code is:

canDevice = new ControllerAreaNetwork (ControllerAreaNetwork.Channel.One, ControllerAreaNetwork.Speed.Kbps500);
            if (canDevice == null)
           {
                Debug.Print ("CAN 1 device cannot be initialized!");
                return;
           }

 // hook up handlers
            try
            {
                canDevice.Enabled = true;
            }
            catch (System.Exception e)
            {
                Debug.Print ("CAN enable error : " + e.Message);
                return;
            }

            canDevice.MessageAvailable += OnCanDataReceived;
            canDevice.ErrorReceived += OnCanErrorReceived;

I got the exception at canDevice.Enabled = true at about 50% chance every time I run the program. My G400D tinyloader and firmware are both 4.3.6 versions.

And then the CAN device works, I can receive all the data I want, but I will also receive the CAN error ErrorPassive from time to time. Any suggestion that I can get rid of this can error?

Thanks a lot.


#2

I think you should check your CAN configuration (timings, termination, cable lengths…). ErrorPassive means G400 pulls itself off from CAN bus due to high number of transmission errors. Maybe Enable fails for the same reason, too.


#3

Thanks for the help, Simon. I tried on both the CAN1 and CAN2, interesting thing is, even there is no CAN bus connected, nor the CAN gadgeteer module presented, when I enable the CAN device and hook up the data event handler, after a few seconds, it will still output the error passive message. I mean, there is no CAN bus connected and no data coming in and out, why the G400D still gets some CAN transmission error? Just really confused about that…

:open_mouth: