Kvaser Linux CANLIB
|
Incoming messages are placed in a queue in the driver. In most cases the hardware does message buffering as well. You can read the first message in the queue by calling canRead; it will return canERR_NOMSG if there was no message available.
The flag parameter of canRead contains a combination of the canMSG_xxx flags and provides you with more information about the message; for example, a frame with a 29-bit identifier will have the canMSG_EXT bit set, and a remote frame will have the canMSG_RTR bit set. Note that the flag argument is a combination of the canMSG_xxx flags, so more than one bit might be set.
The size of the queues in the driver and hardware is descibed in Message Queue and Buffer Sizes.
Sometimes it is desirable to have a peek into the more remote parts of the queue. Is there, for example, any message waiting that has a certain identifier? You can call canReadSpecific to read that message. Messages not matching the specified identifier will be kept in the queue and will be returned on the next call to canRead.
If you want to read just a message with a specified identifier, and throw all others away, you can call canReadSpecificSkip(). This routine will return the first message with the specified identifier, discarding any other message in front of the desired one.
If you want to wait until a message arrives (or a timeout occurs) and then read it, call canReadWait().
If you want just to wait for an arbitrary message to arrive, but you don't want to read the message, call canReadSync().
If you want to wait until there is at least one message in the queue with a certain identifier, but you don't want to read it, call canReadSyncSpecific().
You can specify a timeout (in milliseconds) for those routines that wait for messages.
Example. Input Queue Handling
As an illustration of the abovementioned routines, consider the case where CAN messages with the following identifiers have arrived to the input queue:
1, 2, 3, 4, 5, 6, 7, 8, 9, 10