Exception Canhs.Can.SetExplicitFilters(null);



[quote]
Loop performs in52431 micro seconds
    #### Exception System.NullReferenceException - CLR_E_NULL_REFERENCE (1) ####
    #### Message: 
    #### GHI.IO.ControllerAreaNetwork::NativeSetExplicitFilters [IP: 0000] ####
    #### GHI.IO.ControllerAreaNetwork::SetExplicitFilters [IP: 0025] ####
    #### USU.Program::manage_cc_and_can [IP: 00a8] ####
    #### USU.Program::Main [IP: 2081] ####
A first chance exception of type 'System.NullReferenceException' occurred in GHI.Hardware.dll
An unhandled exception of type 'System.NullReferenceException' occurred in GHI.Hardware.dll
[/quote]

:O :O :O

Today is a bad day, each time I try to use a feature it does not work as it should be....

You gave it null and the exception is about null. What are you trying to do?

I am trying to apply the documentation.
https://www.ghielectronics.com/downloads/man/Library_Documentation_v4.3/html/M_GHI_IO_ControllerAreaNetwork_SetExplicitFilters.htm

As specified in the documentation, passing null is not supposed to fire an exception.

Looks like you found a bug :slight_smile: We will be looking into it but for now you can set your filter to include everything as a workaround.

1 Like

@ leforban - Can you post a complete program that causes that exception to be thrown?

No sorry I won’t have time till next month. In an other portion of my code I use the following. May bethis can help (please note that canfilter returns an empty array of uint due to the fact that I do not have any id to filter at this moment.


uint[] explicitIDs = Canfilter.Get();
            try
            {
                Can.Enabled = true;
                Can.SetExplicitFilters(explicitIDs);
                // subscribe to events
                //ControllerAreaNetwork.DataReceivedEvent += new CANDataReceivedEventHandler(can_process);
                Can.ErrorReceived -= can_ErrorReceivedEvent;
                Can.ErrorReceived += can_ErrorReceivedEvent;
                is_error_handled = true;
            }


in CanfilterClass:


  public static uint[] Get()
        {
            uint[] tabid = new uint[Listofid.Count];
            int i = 0;
            foreach (uint u in Listofid.Values)
            {
                tabid[i] = u;
                i++;
            }
            return tabid;
        }

passing null fire the exception whereas passing uint[0] seems ok…

@ leforban - I couldn’t find anything that immediately looked wrong. As soon as you have a program, we can take a further look. Are you using the G400?