CAN Efus7UL ioctl(soc, SIOCGIFINDEX, &ifr) error

      CAN Efus7UL ioctl(soc, SIOCGIFINDEX, &ifr) error

      Hi all,

      I'm developing a CAN app under Qt Creator 3.3.2 with Efus7UL. I'm using the example provided in the buildroot "can.c" and I have an error when ioctl(soc, SIOCGIFINDEX, &ifr), in open_port() function, is executed. The error given by errno is 19.

      Is this error ENODEV 19 /* No such device */?

      What means and how can I solve this error? I am not sure if I am using the correct CAN driver...

      Thanks.

      Joaquim.
      Files
      • can.txt

        (11.28 kB, downloaded 129 times, last: )

      Post was edited 1 time, last by “jmartinez” ().

      I think your CAN device is not availble. Have you brought it up first?
      With ifconfig (ifconfig -a if it is down) you can see your can devices.

      E.G. to bring can0 device up run: ip link set can0 up type can bitrate 125000
      After that you can run the can example.

      Best Regards
      Yout F&S Support Team
      F&S Elektronik Systeme GmbH
      As this is an international forum, please try to post in English.
      Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.
      Hi,

      Thank for the answer, but I have still the same problem.

      As I developing my own app under Qt, I have modified the example, specifically the "open port" function, that follows. Basically the function not receives the argv of the port, and it is configured in the function (in bold).

      Source Code

      1. int CAN_OpenPort(void)
      2. {
      3. struct ifreq ifr;
      4. struct sockaddr_can addr;
      5. const char *CanPort = NULL;
      6. /* open socket */
      7. int soc = socket(PF_CAN, SOCK_RAW, CAN_RAW);
      8. if(soc < 0)
      9. {
      10. fprintf(stderr, "failed to open socket\n");
      11. return true;
      12. }
      13. addr.can_family = AF_CAN;
      14. CanPort = "Can0";
      15. qDebug() << "CAN Port" << CanPort;
      16. strcpy(ifr.ifr_name, CanPort);
      17. int error = ioctl(soc, SIOCGIFINDEX, &ifr);
      18. qDebug() << "error ioctl" << errno;
      19. //std::cout << "error ioctl" << errno;
      20. if (error < 0)
      21. {
      22. fprintf(stderr, "failed to initialize socket\n");
      23. return true;
      24. }
      25. addr.can_ifindex = ifr.ifr_ifindex;
      26. fcntl(soc, F_SETFL, O_NONBLOCK);
      27. if(bind(soc, (struct sockaddr *)&addr, sizeof(addr)) < 0)
      28. {
      29. fprintf(stderr, "failed to bind socket\n");
      30. return true;
      31. }
      32. return false;
      33. }


      The error in the command windows is the same as reported in Qt:

      Source Code

      1. # ./EVA_DEMO -qws
      2. CAN Port Can0
      3. error ioctl 19
      4. failed to initialize socket


      Thank you.
      Joaquim

      Post was edited 2 times, last by “fs-support_HK”: Code indentation repaired by using code tags. ().

      Error 2 is "no such file or directory". You can find the error codes in the Linux source code in

      include/uapi/asm-generic/errno-base.h
      include/uapi/asm-generic/errno.h

      or on your host PC in

      /usr/include/asm-generic/errno-base.h
      /usr/include/asm-generic/errno.h

      So you have to find out what file is missing. A good idea is to start your program with strace, then all system calls are listed. This may be a rather long list because also the loading of the libraries at program start is shown, but near the end of the list you should find the cause of the problem.

      Your F&S Support Team
      F&S Elektronik Systeme GmbH
      As this is an international forum, please try to post in English.
      Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.
      Hi,

      Sorry, but I don't have experience with "strace" command. Can I execute this command in my C++ code? If yes, how? I have tried to execute it in the command window (after booting kernel) of the Efus via Serial connection as follow, but I get this error message:

      # strace ./myapp -qws
      -sh: strace: not found

      Thanks.
      Hi,
      Is strace activated in your buildroot and available on your board?
      You can find out if your system knows strace with the 'which' command.
      If it is available it should look like this:

      # which strace
      /usr/bin/strace

      Best Regards
      Your F&S Support Team
      F&S Elektronik Systeme GmbH
      As this is an international forum, please try to post in English.
      Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.
      Hmm, if strace is not available in your system, then you probably are working on an old release version. Is your kernel 3.14 or 4.1? If 3.14, then please update to fsimx6ul-V2.0. This may solve quite a lot of problems.

      Your F&S Support Team
      F&S Elektronik Systeme GmbH
      As this is an international forum, please try to post in English.
      Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.
      You can add strace easily to your rootfilesystem.

      (If you haven't ran a config before type 'make fsimx6ul_std_defconfig' first)

      Type 'make menuconfig' in your buildroot source folder strace is located here:
      'Target packages -> Debugging, profiling and benchmark –> strace'
      Then type 'make' to rebuild.

      On the system call strace as you have described above.

      Best Regards,
      Your F&S Support Team
      F&S Elektronik Systeme GmbH
      As this is an international forum, please try to post in English.
      Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.
      Dear Martinez,

      i modified your program, compiled it in c and it works. Do you get the same error message like before "failed to initialize socket"?

      In the attachment you get the c-file and the executable of the file. You can execute it and you see if the problem is caused from the IO connection or if it is a QT problem.

      Best Regards,
      Your F&S Support Team
      Files
      F&S Elektronik Systeme GmbH
      As this is an international forum, please try to post in English.
      Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.

      Post was edited 1 time, last by “fs-support_PJ” ().