Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Need to bring up CANbus interface before Qt can detect it?
QtWS25 Last Chance

Need to bring up CANbus interface before Qt can detect it?

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 438 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • O Offline
    O Offline
    ocgltd
    wrote on 30 Dec 2022, 17:33 last edited by
    #1

    I am trying to get my PEAK CAN device working under linux (Fedora 34). The device shows in Linux:

    [root@fedora ~]# dmesg | grep -i peak
    [    1.349528] usb 1-1: Manufacturer: PEAK-System Technik GmbH
    [   10.739841] peak_usb 1-1:1.0: PEAK-System PCAN-USB FD v1 fw v3.4.3 (1 channels)
    [   10.748044] peak_usb 1-1:1.0 can0: attached to PCAN-USB FD channel 0 (device 0)
    [   10.748081] usbcore: registered new interface driver peak_usb
    
    [root@fedora ~]# ip link
    1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
        link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    2: ens192: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000
        link/ether 00:0c:29:a2:02:e9 brd ff:ff:ff:ff:ff:ff
        altname enp11s0
    3: can0: <NOARP,ECHO> mtu 16 qdisc noop state DOWN mode DEFAULT group default qlen 10
        link/can 
    4: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN mode DEFAULT group default qlen 1000
        link/ether 52:54:00:d5:66:57 brd ff:ff:ff:ff:ff:ff
    

    But my code always always sets devices to an empty list:

    QString errorString;
    const QList<QCanBusDeviceInfo> devices = QCanBus::instance()->availableDevices(
        QStringLiteral("socketcan"), &errorString);
    if (devices.count()==0) qDebug() << "No devices found";
    

    However, if I manually bring up the device from Linux first like this, then a can device is found in the above code:

    [root@fedora ~]# ip link set can0 type can bitrate 125000
    [root@fedora ~]# ip link set up can0
    

    Is this normal behavior? I want my program to do everything without user intervention (including controlling the can0 interface). And my program will set the bitrate in later code. Why would the user have to do this in Linux command line first?

    1 Reply Last reply
    0
    • K Offline
      K Offline
      kuzulis
      Qt Champions 2020
      wrote on 30 Dec 2022, 17:56 last edited by kuzulis
      #2

      It is a normal behavior. To initialize the CAN interface you need to write a some udev-rules which are will configure your CAN automatically when it been attached to the system.

      It is similar as, e.g. the Network Manager does for the ETH interfaces and so on. Or, how the USB devices (flash drives) are mounted automatically when they are plugged in.

      UPD: AFAIK, the qt-serialbus module supports the configuring the CAN bus, but for the SocketCan driver. So, you can try to use your PEACK CAN device with the Socket CAN driver, instead of the vendor-specific PEACK CAN driver (if I understand it correctly). How to do it you can search in an internet. ;)

      1 Reply Last reply
      1
      • O Offline
        O Offline
        ocgltd
        wrote on 30 Dec 2022, 19:21 last edited by ocgltd
        #3

        I want to make my code generic for all CAN interfaces (not just Peak) - so I want to use the socketcan driver.

        Ok I will bring up the CAN0 interface separately then. However, something else isn't clear: since I must set the can0 bitrate from the commandline before bringing up the interface, what is the point of the of Qt's set configuration parameter for bitrate? For example:

        m_device->setConfigurationParameter(QCanBusDevice::BitRateKey, m_bitrateBus);
        

        Does this simple re-set the bitrate, or is this ignored?

        1 Reply Last reply
        0
        • K Offline
          K Offline
          kuzulis
          Qt Champions 2020
          wrote on 31 Dec 2022, 07:03 last edited by
          #4

          To configure the bitrate programmatically, you need the libsocketcan library installed. Also you need a root rights.

          In other cases it been ignored, just check the console warning messages.

          Also, you can read an official documentation about the SocketCAN driver support in QtSerialBus module.

          1 Reply Last reply
          1
          • A aha_1980 has marked this topic as solved on 27 Dec 2023, 07:23

          1/4

          30 Dec 2022, 17:33

          • Login

          • Login or register to search.
          1 out of 4
          • First post
            1/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved