Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Next revision Both sides next revision | ||
litesom:devicetree:can [2017/06/09 22:00] filug [SocketCAN API] |
litesom:devicetree:can [2017/06/09 22:08] filug [SocketCAN API] |
||
---|---|---|---|
Line 213: | Line 213: | ||
</ | </ | ||
- | ===== SocketCAN | + | ===== C/C++ API ===== |
In case when you want to develop your own application to access CAN bus via '' | In case when you want to develop your own application to access CAN bus via '' | ||
Line 224: | Line 224: | ||
struct ifreq ifr; | struct ifreq ifr; | ||
+ | /* | ||
+ | * Open connection with CAN bus | ||
+ | */ | ||
s = socket(PF_CAN, | s = socket(PF_CAN, | ||
Line 234: | Line 237: | ||
bind(s, (struct sockaddr *)& | bind(s, (struct sockaddr *)& | ||
- | // build CAN data frame | + | /* |
+ | | ||
+ | */ | ||
struct can_frame frame; | struct can_frame frame; | ||
frame.can_id = node_id | CAN_EFF_FLAG; | frame.can_id = node_id | CAN_EFF_FLAG; | ||
Line 245: | Line 250: | ||
frame.data[5] = 0x66; // data frame last byte | frame.data[5] = 0x66; // data frame last byte | ||
- | // send data frame via CAN bus | + | /* |
+ | | ||
+ | */ | ||
write(s, &frame, sizeof(frame)); | write(s, &frame, sizeof(frame)); | ||
</ | </ |