QCanBusFrame Class

QCanBusFrame is a container class representing a single CAN frame. More...

Header: #include <QCanBusFrame>
qmake: QT += serialbus
Since: Qt 5.8

This class was introduced in Qt 5.8.

Public Types

class TimeStamp
enum FrameError { NoError, TransmissionTimeoutError, LostArbitrationError, ControllerError, ..., AnyError }
flags FrameErrors
enum FrameType { UnknownFrame, DataFrame, ErrorFrame, RemoteRequestFrame, InvalidFrame }

Public Functions

QString toString() const
QDataStream &operator<<(QDataStream &out, const QCanBusFrame &frame)
QDataStream &operator>>(QDataStream &in, QCanBusFrame &frame)

Detailed Description

QCanBusDevice can use QCanBusFrame for read and write operations. It contains the frame identifier and the data payload. QCanBusFrame contains the timestamp of the moment it was read.

See also QCanBusFrame::TimeStamp.

Member Type Documentation

enum QCanBusFrame::FrameError
flags QCanBusFrame::FrameErrors

This enum describes the possible error types.

ConstantValueDescription
QCanBusFrame::NoError0No error has occurred.
QCanBusFrame::TransmissionTimeoutError(1 << 0)The transmission has timed out.
QCanBusFrame::LostArbitrationError(1 << 1)The frame could not be sent due to lost arbitration on the bus.
QCanBusFrame::ControllerError(1 << 2)The controller encountered an error.
QCanBusFrame::ProtocolViolationError(1 << 3)A protocol violation has occurred.
QCanBusFrame::TransceiverError(1 << 4)A transceiver error occurred
QCanBusFrame::MissingAcknowledgmentError(1 << 5)The transmission received no acknowledgment.
QCanBusFrame::BusOffError(1 << 6)The CAN bus is offline.
QCanBusFrame::BusError(1 << 7)A CAN bus error occurred.
QCanBusFrame::ControllerRestartError(1 << 8)The controller restarted.
QCanBusFrame::UnknownError(1 << 9)An unknown error has occurred.
QCanBusFrame::AnyError0x1FFFFFFFUMatches every other error type.

The FrameErrors type is a typedef for QFlags<FrameError>. It stores an OR combination of FrameError values.

enum QCanBusFrame::FrameType

This enum describes the type of the CAN frame.

ConstantValueDescription
QCanBusFrame::UnknownFrame0x0The frame type is unknown.
QCanBusFrame::DataFrame0x1This value represents a data frame.
QCanBusFrame::ErrorFrame0x2This value represents an error frame.
QCanBusFrame::RemoteRequestFrame0x3This value represents a remote request.
QCanBusFrame::InvalidFrame0x4This value represents an invalid frame. This type is used for error reporting.

See also setFrameType().

Member Function Documentation

QString QCanBusFrame::toString() const

Returns the CAN frame as a formatted string.

The output contains the CAN identifier in hexadecimal format, right adjusted to 32 bit, followed by the data length in square brackets and the payload in hexadecimal format.

Standard identifiers are filled with spaces while extended identifiers are filled with zeros.

Typical outputs are:


  (Error)                                  - error frame
       7FF   [1]  01                       - data frame with standard identifier
  1FFFFFFF   [8]  01 23 45 67 89 AB CD EF  - data frame with extended identifier
       400  [10]  01 23 45 67 ... EF 01 23 - CAN FD frame
       123   [5]  Remote Request           - remote frame with standard identifier
  00000234   [0]  Remote Request           - remote frame with extended identifier

Related Non-Members

QDataStream &QCanBusFrame::operator<<(QDataStream &out, const QCanBusFrame &frame)

Writes a frame to the stream (out) and returns a reference to the it.

QDataStream &QCanBusFrame::operator>>(QDataStream &in, QCanBusFrame &frame)

Reads a frame from the stream (in) and returns a reference to the it.