Using VirtualCAN Plugin
The VirtualCAN plugin allows testing of CAN applications with a local TCP/IP connection without CAN hardware. The TCP server is created, when the first client calls createDevice(). The default TCP port is 35468, which can be changed by giving the fully qualified URL to createDevice(). Once the server is running, no further server is started on the same system.
Afterwards, all clients send their CAN frames to the server, which distributes them to the other clients.
At first it is necessary to check that QCanBus provides the desired plugin:
Where virtualcan is the plugin name.
Next, a connection to a specific interface can be established:
QCanBusDevice *device = QCanBus::instance()->createDevice( QStringLiteral("virtualcan"), QStringLiteral("can0")); device->connectDevice();
Where can0 is the active CAN channel name. The VirtualCAN plugin provides two channels "can0" and "can1". Both can be used as CAN 2.0 or CAN FD channels. All applications connected to one of these channels receive all messages that are sent to this channel.
To connect to a remote server, use the following fully qualified URL as interface name:
The device is now open for writing and reading CAN frames:
QCanBusFrame frame; frame.setFrameId(8); QByteArray payload("A36E"); frame.setPayload(payload); device->writeFrame(frame);
QCanBusFrame frame = device->readFrame();
VirtualCAN supports the following configurations that can be controlled through setConfigurationParameter():
|Configuration parameter key||Description|
|QCanBusDevice::CanFdKey||Determines whether the virtual CAN bus operates in CAN FD mode or not. This option is disabled by default.|
|QCanBusDevice::ReceiveOwnKey||The reception of the CAN frames on the same device that was sending the CAN frame is disabled by default. When enabling this option, all CAN frames sent to the CAN bus immediately appear in the receive buffer. This can be used to check if sending was successful. If this option is enabled, the therefore received frames are marked with QCanBusFrame::hasLocalEcho()|
© 2018 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.