ArCanSend Data Length

Hello Community,

I have to send 11 bytes with the ArCanSend function block.

I see that the ArCanFrameType has: Data (array of 64 bytes) and Data Length.

The question is: how can I send 11 bytes if the ArCanSend FB accepts a DataLength <= 8? With values greater than 8 I have arCAN_ERR_INVALID_DATALENGTH.

This is the code I’m using:

memcpy(ADR(ArCanSenderAT2HI2.ArCanSend_0.Frame.Data), ADR(PGN_AT2HI2_Data_Byte), SIZEOF(PGN_AT2HI2_Data_Byte));
ArCanSenderAT2HI2.ArCanSend_0.Frame.DataLength := dataLength;
ArCanSenderAT2HI2.ArCanSend_0.Frame.ID := ArCanSenderAT2HI2.ID;			
ArCanSenderAT2HI2.ArCanSend_0.Frame.Format := arCAN_29BIT;						
ArCanSenderAT2HI2.ArCanSend_0.SendFrame := TRUE;

ArCanSenderAT2HI2.ArCanSend_0();

P.S.

PGN_AT2HI2_Data_Byte is an array of 11 bytes

Thank you

Hi @c462521 ,
Thanks for your post, now I know that CAN_lib is obsolete and should no longer be used, in new prj is recommended to use the ArCAN (time to study new library…)

The question is: how can I send 11 bytes if the ArCanSend FB accepts a DataLength <= 8? With values greater than 8 I have arCAN_ERR_INVALID_DATALENGTH.

Weird…maybe there is another issue and we are focus on wrong direction

Have you checked our examples in the help?

You can add them from logical view:


I have reviewed with @marcusbnr your issue and, thanks Marcus!, the limitation is on CAN Protocol itself where is limited to a maximum payload of 8 bytes. You will not be able to send a payload of greater than 8 bytes in one frame while working with CAN Protocol.

I asked some ideas to AI: “How Can I send 11 bytes with B&R Automation library ArCAN?”

To send 11 bytes using the B&R ArCAN library, you must account for the 8-byte payload limit of Classical CAN (CAN 2.0). Because ArCAN frames are fixed-length structures, you cannot simply increase the data size beyond 8 bytes.

1. The Multi-Frame Method (Segmentation)

Since a single frame is too small, you must split your 11 bytes into two frames.

  • Frame 1: Send the first 8 bytes.

  • Frame 2: Send the remaining 3 bytes.

Implementation Steps:

  1. Define a variable of type ArCanFrameType for each frame.

  2. Use brsmemcpy to copy the first 8 bytes of your data into the .Data array of the first frame.

  3. Copy the remaining 3 bytes into the .Data array of the second frame.

  4. Call the ArCanWrite() function block twice—once for each frame.

2. Example Code (Structured Text)

Here is a simplified logic for splitting the data manually using ArCAN:

(* Frame 1: First 8 bytes *)
canWrite1.Frame.ID := 0x123;
canWrite1.Frame.DataLength := 8;
brsmemcpy(ADR(canWrite1.Frame.Data[0]), ADR(MyData[0]), 8);
canWrite1.Execute := TRUE;

(* Frame 2: Remaining 3 bytes *)
canWrite2.Frame.ID := 0x124; // Use a different ID or a sequence counter
canWrite2.Frame.DataLength := 3;
brsmemcpy(ADR(canWrite2.Frame.Data[0]), ADR(MyData[8]), 3);
canWrite2.Execute := TRUE;

Additional input from Marcus (AI didn’t tell me that…): “You have to make sure those frame IDs aren’t already used by other devices on the network“

Back to AS Samples, the third one: “Receiving and transmitting multiple CAN frames“ should be a good reference for your case.
Thanks
Ciao
Valerio

You mentioned PGN_AT2HI2_Data_Byte is an array of 11 bytes.
A PGN is used in CAN J1939 communication, which also uses still only 8 bytes in the can message.
You should take a look at mapp J1939: SAE J1939 network protocol

As you can see in the structures in this section, they seem also bigger than 8 bytes.
So depending on the values some J1939 conversion is done to be able to put this data in an 8 byte can message. I have no access to the J1939 documentation but for instance a REAL values is not communicated as 4 bytes, but with less bytes.

a reason might be a preparation for CAN FD.

‘For CAN FD, a frame is labeled with a 29-bit identifier and carries a 64-byte message payload’

1 Like

Similar to what Christoph mentioned, I saw that in the Error description of the error -1070584150: Invalid data length, it states that only “CAN-FD” (CAN Flexible Data-Rate) supports up to 64 bytes per frames, while standard CAN only supports up to 8 bytes per frame.

This would make me believe that the ArCan library only supports standard CAN. Can anyone confirm this? I could not find any information in the Help documenting this, other than that it only mentions CAN 2.0A and CAN 2.0B - both limited to 8 bytes per frame.

This may need to be investigated in a support ticket to get a final answer.

1 Like