QCanBus 类

QCanBus class handles registration and creation of bus plugins. 更多...

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

公共函数

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 class handles registration and creation of bus plugins.

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

成员函数文档编制

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();
					

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

另请参阅 availableDevices ().

[static] QCanBus *QCanBus:: instance ()

返回指针指向 QCanBus 类。对象会被加载 (若有必要)。 QCanBus 使用 Singleton (单例) 设计模式。

QStringList QCanBus:: plugins () const

返回所有已加载插件的标识符列表。