CAN receive packed
Block to receive CAN messages, fitted into a packed CAN message.
Description
A "CAN Receive" block instructs the code generator to include CAN support.
Each time the block is evaluated, the last message with the given CAN ID is used
to get the output values.
The 'new data' output gives a 1 or higher (true) if new data
was received since the last evaluation, otherwise a 0 (false).
Use the "CAN Unpack" block from either the "xPC Target" or "Vehicle Network Toolbox" library to extract the desired data.
Remarks
- Always use a CAN config block to configure the CAN channel enabling and used baud rate.
- Two IDs are reserved for the XCP protocol by design, the CAN channel depends on the 'XCP Config' block.
- The CAN message includes;
- CAN ID
- Message length
- Data
- The CAN message DOESN'T include;
- Timestamp
- Remote request
- Error frame
- The receive mechanism reserves 1 slot for each receive ID used, the number of ID's is limited by the amount of aviable memory.
- The CAN ID must match the CAN ID from the "CAN Unpack" connected to this block.
- Connect the 'new data' output to a terminator if it is not used.
- A 'new data' value exceeding 1 indicates that messages where lost (only the most recent message is preserved). Consider increasing the sample rate of the CAN receive block.
- The 'new data' is maxed at 127 (so more messages might be received since the last sample).
Declaration
Use the CAN config block:
- To set the baud rate for the selected CAN channel.
- To enable the specific CAN channel.
Output
- Output 1
- The first output indicates new data was received; a 0 (false) represents no new data and > 0 (true) represents the number of new messages.
- This will be returned as an int8. Important: note that the message data outputs only contain valid data if this output is > 0 (true).
- Output 2
- The second output is the received CAN message.
- This will be returned as a CAN_message.
Parameters
- CAN channel
- Select the used channel.
- CAN ID
- Specify the message ID of the CAN messages you wish to receive
with this block. Use 'hex2dec()' to transform a hexadecimal formatted
ID into a decimal ID.