このページでは

TinyCANプラグインの使用方法

TinyCANプラグインは、MHS Elektronik製のCANアダプタと連携するための低レベルAPIをカプセル化しています。

注: TinyCANアダプタは 仮想シリアルポートを使用します。Linux で TinyCAN アダプタと通信するには、ユーザーに適切なアクセス権が必要です。通常、これらの権限は「dialout」グループに属するすべてのユーザーに付与されます。

CANバスデバイスの作成

まず、QCanBus に必要なプラグインが用意されているかを確認する必要があります:

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

ここで、tinycanはプラグイン名です。

次に、特定のインターフェースへの接続を確立できます:

QCanBusDevice *device = QCanBus::instance()->createDevice(
    QStringLiteral("tinycan"), QStringLiteral("can0.0"));
device->connectDevice();

ここで、can0.0はアクティブな CAN インターフェース名です。TinyCAN は現在、can0.0 というインターフェースのみを提供しており、これは TinyCAN プラグイン内の INDEX_CAN_KANAL_A にマッピングされます。

注: 現時点では利用可能なCANアダプタを検出する方法がないため、関数availableDevices()は 常に1つのデバイス「can0.0」を返します。

注: 現在、このプラグインでサポートされているのはUSBアダプタのみです 。

これで、デバイスは CAN フレームの読み書きが可能になりました:

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

読み取りは、readFrame() メソッドを使用して行えます。読み取り可能な新しいフレームが少なくとも1つ存在する場合、framesReceived() シグナルが発信されます:

QCanBusFrame frame = device->readFrame();

TinyCANは、setConfigurationParameter()を通じて制御可能な以下の設定をサポートしています:

設定パラメータキー説明
QCanBusDevice::BitRateKeyCANバス接続のビットレートを決定します。以下のビットレートがサポートされています:10000、20000、50000、100000、 125000、250000、500000、800000、1000000。

TinyCANは、以下の追加機能をサポートしています:

© 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.