03-30-2015 09:41 AM
#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.
Solved! Go to Solution.
03-30-2015 01:22 PM - edited 03-30-2015 01:36 PM
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!
03-30-2015 01:31 PM
For extended messages are you ORing your ID with 0x20000000
http://digital.ni.com/public.nsf/allkb/2FA120A37EDBC51D86256854004FB0C7
http://digital.ni.com/public.nsf/allkb/D652EFA532C0D1AF862574F70071EB4C
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
17 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord