basic CAN example

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

basic CAN example

1,232 Views
dheeraj_k
Contributor I

Basic CAN communication example for IMX6ULL

0 Kudos
2 Replies

1,135 Views
dheeraj_k
Contributor I

In my code if I try to bind the can socket getting an error, please do let me know what could be the reason,

pleas find the code below,

 struct sockaddr_can addr;
 struct can_frame frame;
 struct ifreq ifr;

 const char *ifname = "vcan0";
 if((s = socket(PF_CAN, SOCK_RAW, CAN_RAW)) < 0) {
  perror("Error while opening socket");
  return -1;
 }
 strcpy(ifr.ifr_name, ifname);
 ioctl(s, SIOCGIFINDEX, &ifr);
 
 addr.can_family  = AF_CAN;
 addr.can_ifindex = ifr.ifr_ifindex;
 if(bind(s, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
  perror("Error in socket bind");
  return -2;
 }
0 Kudos

1,135 Views
igorpadykov
NXP Employee
NXP Employee

Hi Dheeraj

one can try with:

doc\can\test - imx-test - i.MX Driver Test Application Software 

GitHub - linux-can/can-utils: Linux-CAN / SocketCAN user space applications 

Best regards
igor
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos