basic CAN example

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

basic CAN example

2,226 次查看
dheeraj_k
Contributor I

Basic CAN communication example for IMX6ULL

0 项奖励
回复
2 回复数

2,129 次查看
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 项奖励
回复

2,129 次查看
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 项奖励
回复