QCanBusDevice Class

The QCanBusDevice class is the interface class for CAN bus. More...

Header: #include <QCanBusDevice>
qmake: QT += serialbus
Since: Qt 5.8
Inherits: QObject

This class was introduced in Qt 5.8.

Public Types

struct Filter
enum CanBusDeviceState { UnconnectedState, ConnectingState, ConnectedState, ClosingState }
enum CanBusError { NoError, ReadError, WriteError, ConnectionError, ConfigurationError, …, TimeoutError }
enum class CanBusStatus { Unknown, Good, Warning, Error, BusOff }
enum ConfigurationKey { RawFilterKey, ErrorFilterKey, LoopbackKey, ReceiveOwnKey, BitRateKey, …, UserKey }
enum Direction { Input, Output, AllDirections }

Detailed Description

QCanBusDevice communicates with a CAN plugin providing users with a convenient API. The CAN plugin must be specified during the object creation.

Member Type Documentation

enum QCanBusDevice::CanBusDeviceState

This enum describes all possible device states.

ConstantValueDescription
QCanBusDevice::UnconnectedState0The device is disconnected.
QCanBusDevice::ConnectingState1The device is being connected.
QCanBusDevice::ConnectedState2The device is connected to the CAN bus.
QCanBusDevice::ClosingState3The device is being closed.

enum QCanBusDevice::CanBusError

This enum describes all the possible error conditions.

ConstantValueDescription
QCanBusDevice::NoError0No errors have occurred.
QCanBusDevice::ReadError1An error occurred during a read operation.
QCanBusDevice::WriteError2An error occurred during a write operation.
QCanBusDevice::ConnectionError3An error occurred when attempting to open the plugin.
QCanBusDevice::ConfigurationError4An error occurred when attempting to set a configuration parameter.
QCanBusDevice::UnknownError5An unknown error occurred.
QCanBusDevice::OperationError6An operation was attempted while the device was in a state that did not permit it. This enum was introduced in Qt 5.14.
QCanBusDevice::TimeoutError7An timeout occurred while waiting for frames written or received. This enum was introduced in Qt 5.14.

enum class QCanBusDevice::CanBusStatus

This enum describes possible CAN bus status values.

ConstantValueDescription
QCanBusDevice::CanBusStatus::Unknown0The CAN bus status is unknown (e.g. not supported by the CAN plugin).
QCanBusDevice::CanBusStatus::Good1The CAN controller is fully operational
QCanBusDevice::CanBusStatus::Warning2The CAN controller is in warning status
QCanBusDevice::CanBusStatus::Error3The CAN controller is in error status (no longer sending CAN frames)
QCanBusDevice::CanBusStatus::BusOff4The CAN controller is in bus off status (disconnected from the CAN bus)

This enum was introduced or modified in Qt 5.14.

enum QCanBusDevice::ConfigurationKey

This enum describes the possible configuration options for the CAN bus connection.

ConstantValueDescription
QCanBusDevice::RawFilterKey0This configuration determines the type of CAN bus frames that the current device accepts. The expected value is QList<QCanBusDevice::Filter>. Passing an empty list clears all previously set filters including default filters. For more details see QCanBusDevice::Filter.
QCanBusDevice::ErrorFilterKey1This key defines the type of error that should be forwarded via the current connection. The associated value should be of type QCanBusFrame::FrameErrors.
QCanBusDevice::LoopbackKey2This key defines whether the CAN bus device should operate in loopback mode. Loopback means, whenever a CAN frame is transmitted on the CAN bus, a local echo of this frame is sent to all applications connected to this CAN device. The expected value for this key is bool.
QCanBusDevice::ReceiveOwnKey3This key defines whether this CAN device receives its own send frames. This can be used to check if the transmission was successful. The expected value for this key is bool.
QCanBusDevice::BitRateKey4This key defines the CAN bitrate in bits per second. With CAN FD, the payload can be transmitted at a higher data bitrate, if QCanBusFrame::hasBitrateSwitch() is set. In this case, QCanBusDevice::BitRateKey is only used for the CAN ID arbitration phase. See also QCanBusDevice::DataBitRateKey
QCanBusDevice::CanFdKey5This key defines whether sending and receiving of CAN FD frames should be enabled. The expected value for this key is bool.
QCanBusDevice::DataBitRateKey6This key defines the CAN FD payload bitrate in bits per second. CAN FD allows to transmit the payload of frames with QCanBusFrame::hasBitrateSwitch() flag at a higher data bitrate, after the arbitration phase at the nominal bitrate is finished. This enum value was introduced in Qt 5.9. See also QCanBusDevice::BitRateKey
QCanBusDevice::ProtocolKey7This key allows to specify another protocol. For now, this parameter can only be set and used in the SocketCAN plugin. This enum value was introduced in Qt 5.14.
QCanBusDevice::UserKey30This key defines the range where custom keys start. Its most common purpose is to permit platform-specific configuration options.

See also configurationParameter().

enum QCanBusDevice::Direction

This enum describes possible data transmission directions.

ConstantValueDescription
QCanBusDevice::Input1Input direction.
QCanBusDevice::Output2Output direction.
QCanBusDevice::AllDirectionsInput | OutputBoth directions, input and output.

This enum was introduced or modified in Qt 5.12.