벡터캔 플러그인 사용

VectorCAN 플러그인은 벡터 인포매틱의 CAN 어댑터와 함께 작동하도록 로우레벨 API를 캡슐화합니다.

이 플러그인을 사용하려면 벡터 CAN 디바이스 드라이버와 vxlapi.dll(64비트 빌드의 경우 vxlapi64.dll)이 필요합니다.

CAN 버스 디바이스 생성

먼저 QCanBus 에서 원하는 플러그인을 제공하는지 확인해야 합니다:

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

여기서 벡터캔은 플러그인 이름입니다.

다음으로 특정 인터페이스에 대한 연결을 설정할 수 있습니다:

QString errorString;QCanBusDevice *device = QCanBus::instance()->createDevice(    QStringLiteral("벡터캔"), QStringLiteral("can0"), &errorString);if (!device) { // 오류 처리는 여기서 진행됩니다.    qDebug << errorString;
} else {  device->connectDevice(); }

여기서 can0은 활성 CAN 채널 이름입니다. VectorCAN 플러그인은 can0부터 can63까지 64개의 채널(벡터 API의 XL_CONFIG_MAX_CHANNELS로 정의)을 제공합니다. 이 채널 중 일부는 가상 채널일 수 있으므로 실제 CAN 하드웨어 없이도 사용할 수 있습니다. 가상 채널을 확인하려면 벡터의 드라이버 패키지에 포함된 "Vector Hardware Config"(vcanconf.exe) 프로그램을 사용할 수 있습니다. availableDevices () 메서드는 현재 사용 가능한 장치 목록을 반환합니다.

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

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

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

QCanBusFrame frame = device->readFrame();

VectorCAN은 setConfigurationParameter()를 통해 제어할 수 있는 다음 구성을 지원합니다:

구성 파라미터 키설명
QCanBusDevice::BitRateKeyCAN 버스 연결의 비트 전송률을 결정합니다.
QCanBusDevice::ReceiveOwnKey기본적으로 CAN 프레임을 전송한 장치와 동일한 장치에서 CAN 프레임을 수신하는 것은 비활성화되어 있습니다. 이 옵션을 활성화하면 CAN 버스로 전송된 모든 CAN 프레임이 수신 버퍼에 즉시 나타납니다. 이를 통해 전송이 성공했는지 확인할 수 있습니다. 이 옵션을 활성화하면 수신된 프레임에 QCanBusFrame::hasLocalEcho()가 표시됩니다.
QCanBusDevice::CanFdKeyCAN 버스 연결에서 CAN FD 사용을 활성화합니다. 이 옵션을 활성화하면 전송되는 자신의 CAN 프레임을 수신할 수 없으므로 QCanBusDevice::ReceiveOwnKey 을 true로 설정해도 아무런 효과가 없습니다. Qt 5.15부터.
QCanBusDevice::DataBitRateKeyCAN 버스 연결의 데이터 비트 전송률을 결정합니다. QCanBusDevice::CanFdKey 을 참으로 설정한 경우에만 사용할 수 있습니다. Qt 5.15부터.

VectorCAN은 다음과 같은 추가 기능을 지원합니다:

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