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.
Implementation Steps:
-
Define a variable of type ArCanFrameType for each frame.
-
Use brsmemcpy to copy the first 8 bytes of your data into the .Data array of the first frame.
-
Copy the remaining 3 bytes into the .Data array of the second frame.
-
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