QCanBus 類

QCanBus 類處理總綫插件的注冊和創建。 更多...

頭: #include <QCanBus>
qmake: QT += serialbus
Since: Qt 5.8
繼承: QObject

該類在 Qt 5.8 引入。

公共函數

QList<QCanBusDeviceInfo> availableDevices (const QString & plugin , QString * errorMessage = nullptr) const
QCanBusDevice * createDevice (const QString & plugin , const QString & interfaceName , QString * errorMessage = nullptr) const
QStringList plugins () const

靜態公共成員

QCanBus * instance ()

詳細描述

QCanBus 在運行時加載 Qt CAN Bus 插件。將串行總綫插件的所有權轉移給加載程序。

成員函數文檔編製

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

返迴可用接口,為 plugin . In case of failure, the optional parameter errorMessage returns a textual error description.

注意: 某些插件可能不支持 (或僅部分支持) 此函數。

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

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

該函數在 Qt 5.9 引入。

另請參閱 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 () 方法。 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:

QString errorString;
QCanBusDevice *device = QCanBus::instance()->createDevice(
    QStringLiteral("socketcan"), QStringLiteral("vcan0"), &errorString);
if (!device)
    qDebug() << errorString;
else
    device->connectDevice();
					

注意: The interfaceName is plugin-dependent. See the corresponding plugin documentation for more information: CAN 總綫插件 . To get a list of available interfaces, availableDevices () 可以使用。

另請參閱 availableDevices ().

[static] QCanBus *QCanBus:: instance ()

返迴指針指嚮 QCanBus 類。對象會被加載 (若有必要)。 QCanBus 使用 Singleton (單例) 設計模式。

QStringList QCanBus:: plugins () const

返迴所有已加載插件的標識符列錶。