To implement standard frame 11bit message id CAN communications or 29 bit, use the Codesys CAA CAN Low Level Libraries. The example included in this article makes use of the CL2 and CL2i library functions.
Both 29 bit and 11 bit ID messages are demonstrated in the example using the low level library functions.
Download the Codesys Example Project
Description
Transmitter - demonstrates how to send a 11bit ID and a 29bit ID CAN message. Use the visualization buttons to enable transmitting the data. Function blocks to transmit each message type were created to help simplify the code in the application. In this example the CAN network connection is defined in the transmitter POU which is also used by the receiver POU. Use CAN bus monitoring software to see message ID 1929 and 0x0CEF0023 being transmitted from the controller.
Receiver - demonstrates receiving both 11bit ID and 29bit ID CAN messages. A separate receiver is setup, one for 11bit message ID's and another one for 29bit message ID's, the only difference between them is the x29BitIdMask True/False setting. A loop is used to monitor incoming messages and strip out the message ID and the data where it can then be used by the application. Note that once a message is received and handled its memory allocation must be released using the .FreeMessage function else that memory location will be blocked and eventually the system will run out of memory. To test this function send any 11 bit or 29 bit message to the controller and monitor the msgID and readData values.
Helpful Tips
- Libraries Required
- Additional Help - Use built in help and search on CL2.
- Use the Input Assistant (Fn F2) to setup function calls with all the correct arguments.
Example:
Template: CL2.GetMessageId(hMessage:= , peError:= )
Implementation: msgID := CL2.GetMessageId(hMessage:= hMsg, peError:= ADR(error));
Comments
0 comments
Please sign in to leave a comment.