Automotive and Embedded Networks

cancel
Showing results for 
Search instead for 
Did you mean: 

Sending CAN frames on a CAN FD channel

Hello.

 

I'm trying to send CAN frames on an XNET device channel configured for CAN FD. This should be possible according to the protocol logistics. In the doc, the Interface:CAN:Transmit I/O Mode property says: "This property specifies the I/O Mode the interface uses when transmitting a CAN frame. By default, it is the same as the XNET Cluster CAN:I/O Mode property. However, even if the interface is in CAN FD (+ BRS) mode, you can force it to transmit frames in the standard CAN format. For this purpose, set this property to CAN."

 

So, I'm experimenting with changing this mode to CAN, writing, then changing it back to CAN FD, but it appears to still only send frames as CAN FD. Reception seems to work fine. If I sent a mix of CAN FD and CAN frames from another vendor device to the XNET device, they are received and denoted properly.

 

My code looks like the following. Please advise.

 

bool transmitMessage(CanFrame& message, int& status)

{

nxFrameFixed_t(64) frame;

nxStatus_t result;

// Load the message data to transmit.

frame.Identifier = static_cast<u32>(message.ID);

if (message.Extended)

{

frame.Identifier = frame.Identifier | nxFrameId_CAN_IsExtended;

}

frame.Type = nxFrameType_CAN_Data;

if (message.ProtocolMode == 1)

{

if (message.BRS)

{

frame.Type = nxFrameType_CANFDBRS_Data;

}

else

{

frame.Type = nxFrameType_CANFD_Data;

}

}

else

{

frame.Type = nxFrameType_CAN_Data;

}

frame.PayloadLength = static_cast<u8>(message.Length);

std::copy(message.Data, message.Data + message.Length, frame.Payload);

// If this message is a CAN frame, set the I/O mode for CAN for this transmit.

u32 propertySize = nxGetPropertySize(_handle, nxPropSession_IntfCanTxIoMode, &propertySize);

u32 value = static_cast<u32>(nxCANioMode_CAN);

if (message.ProtocolMode == 0)

{

result = nxSetProperty(_handle, nxPropSession_IntfCanTxIoMode, propertySize, &value);

}

// Send the message.

result = nxWriteFrame(_handle, &frame, nxFrameSize(message.Length), 0);

status = result; // Send back result in case of error.

// Restore the I/O mode if needed.

if (message.ProtocolMode == 0)

{

value = static_cast<u32>(nxCANioMode_CAN_FD_BRS);

result = nxSetProperty(_handle, nxPropSession_IntfCanTxIoMode, propertySize, &value);

}

// Return a flag as true if the message was sent, otherwise false.

return (result == nxSuccess);

}

 

0 Kudos
Message 1 of 3
(4,546 Views)

What version of XNET are you using?

Are you using ISO CAN FD or Non-ISO CAN FD?

 

The Interface:CAN:Transmit I/O mode isn't supported in ISO CAN FD and is only available for legacy Non-ISO applications.

 

If using ISO CAN FD, you will want to set the Interface:CAN:I/O Mode to CAN FD + BRS. Individual frames will then have a I/O mode property in the database that determines what mode to use when transmitting the frame. If using a Stream session, nxWriteFrame will check individual frames for their frame type and transmit them based on their frame type encoded in the raw frame format. Queued and Single Point session types will use the I/O mode property of the frame as defined in the database.

Jeff L
National Instruments
0 Kudos
Message 2 of 3
(4,514 Views)

Thank you. That worked. I was using the nxFrameType_CAN_Data mode, but needed to use the nxFrameType_CAN20_Data instead.

0 Kudos
Message 3 of 3
(4,460 Views)