Automotive and Embedded Networks

cancel
Showing results for 
Search instead for 
Did you mean: 

Occasional error 0xBFF63020 during otherwise stable CAN communication via NI-XNET 8502.

I am getting this error occasionally and I am kind of lost with possible solution....or where to look for mistake.

NI-XNET: (Hex 0xBFF63020) An invalid reference has been passed to a NI-XNET session function. Solution: Only pass reference retrieved from Create Session, or from an IO name of a session in LabVIEW project.

 

There is main application on Windows PC using NI-XNET 8502 interface to communicate with a device on CAN bus at 1Mbps.

 

The application is written in C#, it uses DllImport/PInvoke over nixnet.dll. The DLL comes from NI-XNET driver version 20.5.

 

The setup of the CAN interface is as follows:

1) Global init:

nxSystemOpen

 

2) Init CAN reader:

nxCreateSession(":memory:", "", "", "CAN1", 6 /*FrameInStream*/)

nxSetProperty(nxPropSession_IntfBaudRate, 4, 1000000)

 

3) Init CAN writer:

nxCreateSession(":memory:", "", "", "CAN1", 9 /*FrameOutStream*/)

nxSetProperty(nxPropSession_IntfBaudRate, 4, 1000000)

 

4) Start main communication thread, which is handling reads/writes using:
nxReadFrame(Buffer, (uint)Buffer.Length, 0.0d, out uint readBytes)

nxWriteFrame(Buffer, (uint)Buffer.Length, 0.0d)

...after some time, unrepeatably and unexpectedly both functions above return error 0xBFF63020.

 

What can cause the session to get lost? I do store the handle (IntPtr), which is being called in every nxXXX function.

 

A sidenote: The PC with application is running in an environment with high EM interference, there used to be lot of USB instability caused by that. Though we fixed that using short cables and proper grounding. Also the error thrown by read/write, when USB disconnects internally via protection circuits, was different:
NI-XNET: (Hex 0xBFF630B2) The NI-XNET driver no longer can communicate with the device. Solution: Make sure the device has not been removed from the computer.

0 Kudos
Message 1 of 4
(2,479 Views)

First I would make sure the session reference has not been accidentally overwritten:

- Print out the session reference obtained from CreateSession

- Print out the session reference again after the error has occured.

0 Kudos
Message 2 of 4
(2,468 Views)

The handle is the same. What I find interesting, the handle is always the same, even if the session is closed and new session is opened (literaly new object is created).

 

Here is log example. The handle value I get from calling IntPtr's ToInt64().

The OK scenario:

Spoiler

2021-09-03 07:09:37 DEBUG [CanCommLib.HW.NiXnet.ANiXnetSession] Created CAN1_Reader session.
2021-09-03 07:09:37 DEBUG [CanCommLib.HW.NiXnet.ANiXnetSession] Handle 4194305
2021-09-03 07:09:37 DEBUG [CanCommLib.HW.NiXnet.ANiXnetSession] Created CAN1_Writer session.
2021-09-03 07:09:37 DEBUG [CanCommLib.HW.NiXnet.ANiXnetSession] Handle 4194306
2021-09-03 07:09:37 DEBUG [CanCommLib.CanComm] Started CAN1 thread.
2021-09-03 07:09:37 INFO [CanCommLib.CanComm] CAN1 connected.
...
2021-09-03 07:21:14 DEBUG [CanCommLib.HW.NiXnet.ANiXnetSession] Handle 4194305
2021-09-03 07:21:14 DEBUG [CanCommLib.HW.NiXnet.ANiXnetSession] Closed CAN1_Reader session.
2021-09-03 07:21:14 DEBUG [CanCommLib.HW.NiXnet.ANiXnetSession] Handle 4194306
2021-09-03 07:21:14 DEBUG [CanCommLib.HW.NiXnet.ANiXnetSession] Closed CAN1_Writer session.
2021-09-03 07:21:14 INFO [CanCommLib.CanComm] CAN1 disconnected.

The OK scenario:

Spoiler
2021-09-03 06:05:38 DEBUG [CanCommLib.HW.NiXnet.ANiXnetSession] Created CAN1_Reader session.
2021-09-03 06:05:38 DEBUG [CanCommLib.HW.NiXnet.ANiXnetSession] Handle 4194305
2021-09-03 06:05:38 DEBUG [CanCommLib.HW.NiXnet.ANiXnetSession] Created CAN1_Writer session.
2021-09-03 06:05:38 DEBUG [CanCommLib.HW.NiXnet.ANiXnetSession] Handle 4194306
2021-09-03 06:05:38 DEBUG [CanCommLib.CanComm] Started CAN1 thread.
2021-09-03 06:05:38 INFO [CanCommLib.CanComm] CAN1 connected.
...
2021-09-03 06:11:59 ERROR [CanCommLib.HW.NiXnet.NiXnetReader] Failed reading CAN message from CAN1_Reader, error: NI-XNET: (Hex 0xBFF63020) An invalid reference has been passed to a NI-XNET session function. Solution: Only pass reference retrieved from Create Session, or from an IO name of a session in LabVIEW project.
2021-09-03 06:11:59 DEBUG [CanCommLib.HW.NiXnet.NiXnetReader] Handle 4194305
2021-09-03 06:11:59 WARN [CanCommLib.CanComm] Failed reading CAN messages, CAN1_Reader is not connected.
2021-09-03 06:11:59 ERROR [CanCommLib.HW.NiXnet.NiXnetWriter] Failed writing CAN message to CAN1_Writer, error: NI-XNET: (Hex 0xBFF63020) An invalid reference has been passed to a NI-XNET session function. Solution: Only pass reference retrieved from Create Session, or from an IO name of a session in LabVIEW project.
2021-09-03 06:11:59 DEBUG [CanCommLib.HW.NiXnet.NiXnetWriter] Handle 4194306
2021-09-03 06:12:00 WARN [CanCommLib.CanComm] Failed writing CAN messages, CAN1_Writer is not connected.

0 Kudos
Message 3 of 4
(2,409 Views)

@WaldemarM wrote:

First I would make sure the session reference has not been accidentally overwritten:

- Print out the session reference obtained from CreateSession

- Print out the session reference again after the error has occured.


The handle (in form of IntPtr) is an output parameter of nxCreateSession function. This handle is stored for both CAN reader, CAN writer and used for PInvoke functions of the native DLL.

 

The value of IntPtr (via ToInt64())...

Is the same, when the error occurs.

Is the same, when no error occurs and session is correcly closed via nxClose (value prior closing).

Is the same, when new session created after previous session is closed....that means every session with FrameInStream mode has same handle and every session with FrameOutStream mode has same session. This I find suspicious, I would expect the session/handle to change over the time/sessions created.

0 Kudos
Message 4 of 4
(2,417 Views)