TinyCAN 플러그인 사용

TinyCAN 플러그인은 저수준 API를 캡슐화하여 MHS Elektronik CAN 어댑터와 함께 작동합니다.

참고: 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() 함수는 항상 하나의 장치 "can0.0"을 반환합니다.

참고: 현재 이 플러그인에서는 USB 어댑터만 지원됩니다.

이제 장치가 CAN 프레임 쓰기 및 읽기를 위해 열려 있습니다:

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

읽기는 readFrame() 메서드를 사용하여 수행할 수 있습니다. framesReceived () 신호는 하나 이상의 새 프레임을 읽을 수 있을 때 전송됩니다:

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.