basic CAN example

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

basic CAN example

2,204件の閲覧回数
dheeraj_k
Contributor I

Basic CAN communication example for IMX6ULL

0 件の賞賛
返信
2 返答(返信)

2,107件の閲覧回数
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,107件の閲覧回数
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 件の賞賛
返信