You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Qt QCanBus过滤器配置未生效,Vector插件是否不支持过滤?

Qt 6.4.0 QCanBus过滤器失效问题

问题场景

我在Qt 6.4.0版本中使用QCanBus的Vector插件,尝试配置过滤器仅接收指定ID的CAN数据帧,但实际运行后所有总线消息都能被接收,过滤器未生效。

设备初始化与过滤器配置代码

if (QCanBus::instance()->plugins().contains(QStringLiteral("vectorcan"))) {
        QString errorString = QString("Error");
        canDevice = QCanBus::instance()->createDevice(QStringLiteral("vectorcan"), QStringLiteral("can0"), &errorString);
        if (!canDevice)
        {
            qDebug() << "Error: " << errorString << Qt::endl;
        }
        else
        {
            QCanBusDevice::Filter filter;
            QList<QCanBusDevice::Filter> filterList;

            filter.frameId = 0x18FFC281;
            filter.frameIdMask = 0x00FFFFFF;
            filter.format = QCanBusDevice::Filter::MatchExtendedFormat;
            filter.type = QCanBusFrame::DataFrame;
            filterList.append(filter);

            //apply filter
            canDevice->setConfigurationParameter(QCanBusDevice::RawFilterKey, QVariant::fromValue(filterList));

            //set baud rate
            canDevice->setConfigurationParameter(QCanBusDevice::BitRateKey, QVariant(250000));

            bool connected = canDevice->connectDevice();
            if (connected)
            {
                connect(canDevice, &QCanBusDevice::framesReceived, this, &CANHandler::ProcessFramesReceived);
            }
            else
            {
                qDebug() << "Error connecting to device." << Qt::endl;
            }
        }
    }

消息接收处理代码

void CANHandler::ProcessFramesReceived()
{
    while(canDevice->framesAvailable())
    {
        QCanBusFrame frame = canDevice->readFrame();
        qDebug() << QString::number(frame.frameId(), 16) << Qt::endl;
        //every CAN message on the bus appears here
    }
}

疑问

我原本期望过滤器仅允许匹配0x18FFC281(扩展帧格式)的消息通过,但实际所有CAN总线消息都被接收。想确认是我使用过滤器的方式有误,还是我的预期本身不正确?

补充说明

编辑:进一步查阅文档后发现,截至发帖时,Qt提供的Vector CAN插件并不支持过滤功能,只有少数QCanBus插件原生支持该特性。


内容的提问来源于stack exchange,提问作者Moocow12

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.05 23:55:27