이 페이지에서

TinyCAN 플러그인 사용

TinyCAN 플러그인은 MHS Elektronik CAN 어댑터와 연동하기 위한 저수준 API를 캡슐화합니다.

참고: TinyCAN어댑터는 가상 시리얼 포트를 사용합니다. 리눅스에서 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은 다음과 같은 추가 기능을 지원합니다:

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