Download PCAN-driver for Linux - Benutzerhandbuch - PEAK
Transcript
PCAN-driver for Linux - User Manual
Appendix A
Usage of the Driver with
chardev Mode
There are 4 options to ‘talk’ with the chardev driver. Some code
snippets explain the options.
A.1
Polling
Polling is the worst of all possibilities. But sometimes it becomes
the easiest choise.
To poll the driver path have to be opend with the option
O_NONBLOCK:
#include <fcntl.h>
#include <libpcan.h>
TPCANRdMsg msg;
int ret;
HANDLE h = LINUX_CAN_Open("/dev/pcan0", O_RDWR | O_NONBLOCK);
do
{
ret = LINUX_CAN_Read(h, &msg);
} while (ret == -EAGAIN);
if (!ret)
{
/* use 'msg' */
}
else
...
56