本页内容

使用 SystecCAN 插件

SystecCAN 插件封装了用于与SYS TECCAN 适配器配合使用的底层 API。

该插件需要 SYS TEC CAN 设备驱动程序以及 usbcan32.dll(64 位版本需使用 usbcan64.dll)。

创建 CAN 总线设备

首先需要确认QCanBus 是否提供了所需的插件:

if (QCanBus::instance()->plugins().contains(QStringLiteral("systeccan"))) {
    // plugin available
}

其中systeccan是插件名称。

接下来,可以建立与特定接口的连接:

QString errorString;
QCanBusDevice*device =QCanBus::instance()->createDevice(
    QStringLiteral("systeccan"), QStringLiteral("can0.0"), &errorString);
if(!device) {
    // 错误处理代码写在这里
    qDebug << errorString;
}else{
    device->connectDevice();
}

其中,can0.0是活动 CAN 接口的名称(接口 0,通道 0)。 SystecCAN 插件支持 64 个 USB 接口(即所谓的模块),编号从can0.0到can63.1。每个模块可包含一个或两个通道,可通过索引 canX.0 或 canX.1 访问。availableDevices() 方法返回当前可用设备的列表。

注意:SYS TEC 还提供 8 通道或 16 通道的 CAN 接口。这些设备内部由一个 USB 集线器和多个双通道模块组成。

该设备现已打开,可用于读写 CAN 帧:

QCanBusFrame frame;
frame.setFrameId(8);
QByteArray payload("A36E");
frame.setPayload(payload);
device->writeFrame(frame);

可通过调用readFrame()方法读取帧。当至少有一个新帧可供读取时,将触发framesReceived()信号:

QCanBusFrame frame = device->readFrame();

SystecCAN 支持以下配置,这些配置可通过setConfigurationParameter() 进行控制:

配置参数键描述
QCanBusDevice::BitRateKey确定 CAN 总线连接的波特率。支持以下波特率:10000、20000、50000、100000、 125000、250000、500000、800000 以及 1000000。请注意,此配置参数仅可在QCanBusDevice 未连接时进行调整。
QCanBusDevice::ReceiveOwnKey默认情况下,禁止在发送 CAN 帧的同一信道上接收 CAN 帧。如果启用此选项,则接收到的帧将被标记为QCanBusFrame::hasLocalEcho()

SystecCAN 支持以下附加功能:

© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.