IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)

QCanBus Class

The QCanBus class handles registration and creation of bus plugins.

This class was introduced in Qt 5.8.

Article lu   fois.

L'auteur

Liens sociaux

Viadeo Twitter Facebook Share on Google+   

QCanBus Class

  • Header: QCanBus

  • Since: Qt 5.8

  • CMake:

    find_package(Qt6 REQUIRED COMPONENTS SerialBus)

    target_link_libraries(mytarget PRIVATE Qt6::SerialBus)

  • qmake: QT += serialbus

  • Inherits: QObject

Detailed Description

QCanBus loads Qt CAN Bus plugins at runtime. The ownership of serial bus plugins is transferred to the loader.

Member Function Documentation

 

[since 5.9] QList<QCanBusDeviceInfo> QCanBus::availableDevices(const QString &plugin, QString *errorMessage = nullptr) const

Returns the available interfaces for plugin. In case of failure, the optional parameter errorMessage returns a textual error description.

Some plugins might not or only partially support this function.

For example, the following call returns a list of all available SocketCAN interfaces (which can be used for createDevice()):

 
Sélectionnez
QString errorString;
const QList&lt;QCanBusDeviceInfo&gt; devices = QCanBus::instance()-&gt;availableDevices(
    QStringLiteral("socketcan"), &amp;errorString);
if (!errorString.isEmpty())
    qDebug() &lt;&lt; errorString;

This function was introduced in Qt 5.9.

See Also

See also createDevice()

QCanBusDevice *QCanBus::createDevice(const QString &plugin, const QString &interfaceName, QString *errorMessage = nullptr) const

Creates a CAN bus device. plugin is the name of the plugin as returned by the plugins() method. interfaceName is the CAN bus interface name. In case of failure, the optional parameter errorMessage returns a textual error description.

Ownership of the returned plugin is transferred to the caller. Returns nullptr if no suitable device can be found.

For example, the following call would connect to the SocketCAN interface vcan0:

 
Sélectionnez
QString errorString;
QCanBusDevice *device = QCanBus::instance()-&gt;createDevice(
    QStringLiteral("socketcan"), QStringLiteral("vcan0"), &amp;errorString);
if (!device)
    qDebug() &lt;&lt; errorString;
else
    device-&gt;connectDevice();

The interfaceName is plugin-dependent. See the corresponding plugin documentation for more information: CAN Bus Plugins. To get a list of available interfaces, availableDevices() can be used.

See Also

See also availableDevices()

[static] QCanBus *QCanBus::instance()

Returns a pointer to the QCanBus class. The object is loaded if necessary. QCanBus uses the singleton design pattern.

QStringList QCanBus::plugins() const

Returns a list of identifiers for all loaded plugins.

Vous avez aimé ce tutoriel ? Alors partagez-le en cliquant sur les boutons suivants : Viadeo Twitter Facebook Share on Google+