TinyCANプラグインの使用

TinyCANプラグインは、MHS ElektronikCANアダプタで動作するための低レベル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() メソッドを使用して行うことができます。framesReceived() シグナルは、少なくとも1つの新しいフレームが読み取り可能になったときに出力されます:

QCanBusFrame frame = device->readFrame();

TinyCANは、setConfigurationParameter() から制御できる以下のコンフィギュレーションをサポートしています:

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

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

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