Foreword: The biggest feature of CAPL is that it can be programmed to flexibly send messages. The messages include communication messages and diagnostic messages.
Now let's simulate an ordinary communication message with a message period of 10ms, a message ID of 0x756, and a message length of 8. At the same time, each byte of the message is used to send the number of current messages sent.
First, you need to define a timer with a period of 10ms. Then define a Message message.
The general framework is as follows:
Now you need to initialize the Message. This can be done in on start or in the timer processing function. Both are acceptable. As shown below:
Now realize sending each byte of the message the number of times the message is currently sent.
First define a variable in the Timer timer and then add 1 each time.
As shown below:
The sending of the message requires calling the Output function. As shown below:
It can be observed in the Trace window that the message cycle is 10ms. The number of messages sent increases in sequence.
Tips:
Have you noticed that although the local variable nSndCtr is defined, it does behave like a static variable. So be especially careful when using it.