VectorCAN 플러그인 사용법
VectorCAN 플러그인은 Vector Informatik CAN 어댑터와 연동하기 위한 저수준 API를 캡슐화합니다.
이 플러그인을 사용하려면 Vector CAN 장치 드라이버와 vxlapi.dll(64비트 빌드의 경우 vxlapi64.dll)이 필요합니다.
CAN 버스 장치 생성
먼저 QCanBus 에서 원하는 플러그인이 제공되는지 확인해야 합니다:
if (QCanBus::instance()->plugins().contains(QStringLiteral("vectorcan"))) {
// plugin available
}여기서 vectorcan은 플러그인 이름입니다.
다음으로, 특정 인터페이스에 대한 연결을 설정할 수 있습니다:
QString errorString;
QCanBusDevice*device = QCanBus::instance()->createDevice(
QStringLiteral("vectorcan"), QStringLiteral("can0"), &errorString);
if (!device) {
// 오류 처리 코드는 여기에 작성합니다
qDebug << errorString;
} else {
device->connectDevice();
}여기서 can0은 활성 CAN 채널 이름입니다. VectorCAN 플러그인은 can0부터 can63까지 총 64개의 채널(Vector API의 XL_CONFIG_MAX_CHANNELS로 정의됨)을 제공합니다. 이 채널 중 일부는 가상 채널일 수 있으며, 따라서 실제 CAN 하드웨어 없이도 사용할 수 있습니다. 가상 채널을 확인하려면 Vector 드라이버 패키지에 포함된 “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::BitRateKey | CAN 버스 연결의 전송 속도를 결정합니다. |
| QCanBusDevice::ReceiveOwnKey | 기본적으로 CAN 프레임을 전송한 동일한 장치에서 해당 프레임을 수신하는 기능은 비활성화되어 있습니다. 이 옵션을 활성화하면 CAN 버스로 전송된 모든 CAN 프레임이 즉시 수신 버퍼에 나타납니다. 이를 통해 전송이 성공적으로 이루어졌는지 확인할 수 있습니다. 이 옵션이 활성화되면 수신된 프레임은 QCanBusFrame::hasLocalEcho()로 표시됩니다. |
| QCanBusDevice::CanFdKey | CAN 버스 연결에서 CAN FD 사용을 활성화합니다. 이 옵션을 활성화하면 자신이 전송한 CAN 프레임을 수신할 수 없으므로, ` QCanBusDevice::ReceiveOwnKey `를 `true`로 설정해도 아무런 효과가 없습니다. Qt 5.15부터. |
| QCanBusDevice::DataBitRateKey | CAN 버스 연결의 데이터 전송 속도를 결정합니다. 이 옵션은 QCanBusDevice::CanFdKey 가 true로 설정된 경우에만 사용할 수 있습니다. Qt 5.15부터. |
VectorCAN은 다음과 같은 추가 기능을 지원합니다:
© 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.