From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Automotive and Embedded Networks

cancel
Showing results for 
Search instead for 
Did you mean: 

Using X-NET C API

I'm at my wit's end after two days trying to receive raw data CAN messages using a PXI-8512. I'm reliably sending messages and I got that working with no problem, but I seem to be encountering an issue with the API I have no idea how to fix. I'm using C# and making PInvoke calls to the unmanaged nixnet.dll. At first I thought this was part of the problem, but the API is signalling that it has successfully read 24 bytes of data, but the payload is all 0s. I verified the following to confirm that something is wrong with the ReadFrame() function (or at least the way it's being used):

1) That this is not a PInvoke translation error by building the "CAN Frame Single Point Input" project in C++. I receive the same bogus message.

2) The data being sent by the slave is valid - the odd thing is that when I check the contents of the sent message using the Bus Monitor, I get what I expect to see

 

Basically my sequence of events is as follows:

1) Create XNET database in memory using nxdbOpenDatabase()

2) Create cluster within database

3) Create frame within cluster

4) Set baud rate property within cluster

5) Set payload length property within frame

6) Set arbitration ID property of CAN port

7) Create output session with above database, cluster, and frame using nxMode_FrameOutSinglePoint

😎 Create input session with above database, cluster, and frame using nxMode_FrameInSinglePoint

 

Now, when I call nxReadFrame, it tells me it successfully read 24 bytes, but the whole packet is 0s except for byte 8, which is 0x01 and byte 15, which is 0x08. I can confirm with the NI Bus Monitor that this packet info is wrong - it shows me all the correct data. I also get the same data when using the example project I mentioned earlier. Is there some other property that I need to configure when trying to receive raw data frames? As I mentioned, I am able to transmit frames with no problem.

 

Is it possible to get the source code for the Bus Monitor utility so I can determine what I'm doing wrong? Obviously the PXI-8512 is capable of retrieving the correct data or the Bus Monitor would never display the proper frame data. It's all I can do at this point not to pull this card out of my chassis and use something else for CAN communications.

0 Kudos
Message 1 of 2
(6,599 Views)

I figured it out. I'm using the hardware mode FrameInStream and for some reason, the data was valid the second time through the test routine. When I added a call to nxStart() with a scope of 0 on the session, the data is now present and correct the first time I read from the buffer. The "NI-XNET Hardware and Software Help" documentation explicity states in the nxStart() function that "Because the session is started automatically by default, this function is optional", which does not appear to be true in my case.

 

Perhaps I was doing something else wrong, but at least hopefully this information can help someone else save some debugging time if they encounter the same problem.

Message 2 of 2
(6,580 Views)