bool QCanBusDevice::connectDevice and QCanBus's createDevice always return true?



  • Why are QCanBus's createDevice and QCanBusDevice's connectDevice always returning true even though no CAN device is plugged in?
    Even in the CAN bus example ( ran using QT creator), the bottom of the application will always state "Backend: vectorcan, connected to can0 at 500kBit/s" when there's no connection.

    Please let me know if I'm not understanding their functionalities correctly. Cheers

    p/s: I'm using QT 5.9 MSVC 2013


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Please add the version of Qt you are using as well as the platform you are running on.

    Your can setup details would also be a good idea.


  • Qt Champions 2017

    @MrBrightSide8

    IIRC, vectorcan has two simulated (virtual) channels. If no other CAN hardware is present, can0 will be the first of them. In Qt 5.9, the ConnectDialog shows you the available devices and should have printed "virtual" for can0 already.



  • @aha_1980
    So how would we know if the hardware connection is successful or not if it always show it's connected?


  • Qt Champions 2017

    @MrBrightSide8 said in bool QCanBusDevice::connectDevice and QCanBus's createDevice always return true?:

    So how would we know if the hardware connection is successful or not if it always show it's connected?

    The connection is successful. You're just connected to a virtual (simulated) channel (provided by the Vector Informatik drivers) that indeed works without hardware.

    Quoting https://doc.qt.io/qt-5/qtserialbus-vectorcan-overview.html :

    The VectorCAN plugin provides 64 channels (defined by XL_CONFIG_MAX_CHANNELS in the Vector API) from can0 to can63. Some of these channels can be virtual, and therefore can be used without actual CAN hardware. To find out the virtual channels, the program "Vector Hardware Config" (vcanconf.exe) can be used, which is included in Vector's driver package.

    So, if you connect your Vector CAN hardware to your computer, does it appear in the vcanconf.exe? Which device number does it get assigned?



  • @aha_1980
    Yes, I can see it in vcanconf.exe in channel 1 and 2 of the CAN device.
    Is there anyway to determine the actual hardware connection in code?


  • Qt Champions 2017

    @MrBrightSide8 said in bool QCanBusDevice::connectDevice and QCanBus's createDevice always return true?:

    Yes, I can see it in vcanconf.exe in channel 1 and 2 of the CAN device.

    So you mean, channel 1 and 2 are the real hardware channels, right? Do you see virtual channels there also? (You could also post a screenshot of vcanconf.exe).

    If the channels 1 and 2 are the hardware CAN channels, you should be able to connect to "can0" or "can1". Unfortunately I don't have Vector CAN hardware at hand so I could always test using the virtual channels only.

    Is there anyway to determine the actual hardware connection in code?

    There is currently none, except using availableDevices() first.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.