Automotive and Embedded Networks

cancel
Showing results for 
Search instead for 
Did you mean: 

Identifier not being sent correctly with nxWriteFrame()

Solved!
Go to solution
#define CAN_FRAME 0x00
#define NORMAL_FRAME 0x00

u32 ID = 0x18FC9FFE; OutputSingleFrame(ID,CAN_FRAME,NORMAL_FRAME,"ABCDEF0102030405"); void OutputSingleFrame(u32 Identifier, u8 Type, u8 Flags, char *PayloadString) { int i = 0; u8 Info = 0; // Not used in CAN. Set to zero. // Allocate memory for Payload and the Frame u8 *Payload = (u8*)malloc(g_payloadLength*sizeof(u8)); nxFrameCAN_t *l_pFrame = (nxFrameCAN_t*)malloc(sizeof(nxFrameCAN_t)); // Convert string into byte array for(i=0; i<g_payloadLength; i++) { sscanf(&PayloadString[i*2],"%2hhx",&Payload[i]); } // Create frame InitFixedCANFrame (l_pFrame, Identifier, Type, Flags, Info, Payload); // Create session g_Status = nxCreateSession("J1939", "Cluster", "", "CAN1", nxMode_FrameOutStream, &FrameOneShot); if(g_Status != nxSuccess) { MessagePopup("NI-XNET Status", "Failed to create FrameOutSinglePoint session in OutputSingleFrame."); } // Write frame and error check g_Status = nxWriteFrame(FrameOneShot, l_pFrame, sizeof(nxFrameCAN_t), 0); if(g_Status != nxSuccess) { MessagePopup("NI-XNET Status", "Failed to write frame using OutputSingleFrame."); } // Close session //nxClear(FrameOneShot); // Free memory free(Payload); free(l_pFrame); }

 I'm outputting a frame using nxWriteFrame and the Raw Frame format.  When I do this, the identifier gets sent out as 0x7FE instead of the one specified in the first line of code.  The Raw Frame format seems pretty straightforward, so I'm not sure what's failing here. 

 

The data shows up correctly (in CANalyzer) so it's apparently being output as a standard CAN frame in stead of an extended J1939 frame despite the extended bit being set in the ID. 

 

NOTE: InitCANFrame() is from the NI-XNET-Helper.c file included with NI XNET.  It just copies the fields into the right struct members.

0 Kudos
Message 1 of 3
(5,214 Views)

Realized what I was doing.  I was looking at the wrong bit.  So for J1939 ID 0x18FC9F00,  you need to set the ID in NI-XNET to 0x38FC9F00.  Hope his helps someone else who may be making a dumb mistake!

0 Kudos
Message 2 of 3
(5,205 Views)