Example of open and closeΒΆ
The following program fragment shows how the driver is opened and closed. The driver must always be opened before any action can be performed:
void open_test(void)
{ int i:
printf("opening the vcan-driver...\n");
handle= open("/dev/vcan", O_RDWR, 0666);
if (handle==-1)
{ printf("opening of the driver failed!\n");
printf("errno: %d\n", errno);
return;
};
/* perform some commands : */
do_something_with_the_CAN_bus();
/* finished */
i= close(handle);
if (i==-1)
{ printf("closing failed !\n");
printf("errno: %d\n", errno);
return;
};
}