Differences

This shows you the differences between two versions of the page.

Link to this comparison view

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:
 </code> </code>
  
-===== SocketCAN API =====+===== C/C++ API =====
  
 In case when you want to develop your own application to access CAN bus via ''SocketCAN'' please check [[https://www.kernel.org/doc/Documentation/networking/can.txt|Section 4 in SocketCAN readme]] file. In case when you want to develop your own application to access CAN bus via ''SocketCAN'' please check [[https://www.kernel.org/doc/Documentation/networking/can.txt|Section 4 in SocketCAN readme]] file.
Line 224: Line 224:
 struct ifreq ifr; struct ifreq ifr;
  
 +/*
 + * Open connection with CAN bus
 + */
 s = socket(PF_CAN, SOCK_RAW, CAN_RAW); s = socket(PF_CAN, SOCK_RAW, CAN_RAW);
  
Line 234: Line 237:
 bind(s, (struct sockaddr *)&addr, sizeof(addr)); bind(s, (struct sockaddr *)&addr, sizeof(addr));
  
-/build CAN data frame+/
 + build CAN data frame 
 + */
 struct can_frame frame; struct can_frame frame;
 frame.can_id = node_id | CAN_EFF_FLAG;  // node id + extended frame format frame.can_id = node_id | CAN_EFF_FLAG;  // node id + extended frame format
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+/
 + send data frame via CAN bus 
 + */
 write(s, &frame, sizeof(frame)); write(s, &frame, sizeof(frame));
 </code> </code>
  • litesom/devicetree/can.txt
  • Last modified: 2021/05/12 10:08
  • by kateryna.kozakova