Example of object definitionΒΆ
The following example shows how a single CAN object can be defined. The driver should already having been opened:
void define_object(int driver_handle)
{ /* it is assumed that the driver has been opened before and
that <driver_handle> is the handle returned by the
open() - command */
vcan_status_data vstat; /* a variable that is needed for driver-status
commands such as defining a CAN object */
printf("defining an read-object on CAN id 123,\n"
"port 0 with a timeout of 1000 ms\n");
vstat.tag = VCAN_OBJECT_MODE;/* a "Object-Mode"-command */
vstat.data.mode.mode = VCAN_MODE_READ; /* the object-mode: READ */
vstat.data.mode.port = 0; /* Port 0 */
vstat.data.mode.id = 123; /* CAN id 123 */
vstat.data.mode.timeout= 1000; /* timeout: 1000 ms */
ioctl(handle, 0, (char *)(&vstat));
if (vstat.errcode!=VCAN_NO_ERROR)
/* an error occured : */
{ printf("ioctl returned the following error: %d ", vstat.errcode);
/* you could compare the error-code against the symbolic
error-names of the type vcan_errcodes and react accordingly */
printf("fatal error\n");
return;
}
printf("done\n");
}