Ktam3874/pitx software guide – Kontron KTAM3874-pITX User Manual

Page 81

Advertising
background image

KTD-S0057-I

Page 77 Linux® Programming Examples (DebianTM)


KTAM3874/pITX Software Guide


printf ("\nCAN bus test program\n");

/* For example only the identifier range from 0x200 to 0x2FF is valid.

If there are no restrictions regarding identifiers use init_can_bus (0, 0) */

if (init_can_bus (0x200UL, 0x2FFUL))

{

close_can_bus

();

printf ("Cannot initialize the CAN interface !\n\n");

return

-1;

}

memset (&data, 0, sizeof (data));

data[0] = 0x11;

data[1] = 0x22;

data[2] = 0x33;

data[3] = 0x44;

data[4] = 0x55;

data[5] = 0x66;

data[6] = 0x77;

data[7] = 0x88;

data_len = 8;

if (send_can_frame (CAN0_INDEX, 0x201UL, data, data_len))

{

close_can_bus

();

printf ("Cannot transmit CAN bus data !\n\n");

return

-1;

}

printf ("\nSome data are successfully transmitted from: CAN0\n\n");

for (i = 0; i < MAX_LOOPS; i++)

{

usleep

(DELAY_TIME);

if (! detect_can_frame ())

{

memset (&data, 0, sizeof (data));

if (recv_can_frame (name, data, &data_len))

{

close_can_bus

();

printf ("CAN bus receive function fails !\n\n");

return

-1;

}

else

{

printf ("Some data are successfully received from: %s\n", name);

printf ("Data: 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X\n\n",

data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7]);

}

}

}

close_can_bus

();

return

0;

}

Advertising
This manual is related to the following products: