class QCanBusFrame#

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

Inheritance diagram of PySide6.QtSerialBus.QCanBusFrame

Synopsis#

Methods#

Note

This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE

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

TimeStamp

class FrameType#

This enum describes the type of the CAN frame.

Constant

Description

QCanBusFrame.UnknownFrame

The frame type is unknown.

QCanBusFrame.DataFrame

This value represents a data frame.

QCanBusFrame.ErrorFrame

This value represents an error frame.

QCanBusFrame.RemoteRequestFrame

This value represents a remote request.

QCanBusFrame.InvalidFrame

This value represents an invalid frame. This type is used for error reporting.

See also

setFrameType()

class FrameError#

(inherits enum.Flag) This enum describes the possible error types.

Constant

Description

QCanBusFrame.NoError

No error has occurred.

QCanBusFrame.TransmissionTimeoutError

The transmission has timed out.

QCanBusFrame.LostArbitrationError

The frame could not be sent due to lost arbitration on the bus.

QCanBusFrame.ControllerError

The controller encountered an error.

QCanBusFrame.ProtocolViolationError

A protocol violation has occurred.

QCanBusFrame.TransceiverError

A transceiver error occurred

QCanBusFrame.MissingAcknowledgmentError

The transmission received no acknowledgment.

QCanBusFrame.BusOffError

The CAN bus is offline.

QCanBusFrame.BusError

A CAN bus error occurred.

QCanBusFrame.ControllerRestartError

The controller restarted.

QCanBusFrame.UnknownError

An unknown error has occurred.

QCanBusFrame.AnyError

Matches every other error type.

class Version#
__init__(identifier, data)#
Parameters:

Constructs a CAN frame using identifier as the frame identifier and data as the payload.

__init__([type=QCanBusFrame.FrameType.DataFrame])
Parameters:

typeFrameType

Constructs a CAN frame of the specified type.

error()#
Return type:

Combination of FrameError

Returns the error of the current error frame. If the frame is not an ErrorFrame , this function returns NoError .

See also

setError()

frameId()#
Return type:

int

Returns the CAN frame identifier. If the CAN frame uses the extended frame format, the identifier has a maximum of 29 bits; otherwise 11 bits.

If the frame is of ErrorFrame type, this ID is always 0.

frameType()#
Return type:

FrameType

Returns the type of the frame.

See also

setFrameType()

hasBitrateSwitch()#
Return type:

bool

Returns true if the CAN uses Flexible Data-Rate with Bitrate Switch, to transfer the payload data at a higher data bitrate.

hasErrorStateIndicator()#
Return type:

bool

Returns true if the CAN uses Flexible Data-Rate with Error State Indicator set.

This flag is set by the transmitter’s CAN FD hardware to indicate the transmitter’s error state.

hasExtendedFrameFormat()#
Return type:

bool

Returns true if the CAN frame uses a 29bit identifier; otherwise false, implying an 11bit identifier.

hasFlexibleDataRateFormat()#
Return type:

bool

Returns true if the CAN frame uses Flexible Data-Rate which allows up to 64 data bytes, otherwise false, implying at most 8 byte of payload.

hasLocalEcho()#
Return type:

bool

Returns true if the frame is a local echo frame, i.e. a frame that is received as echo when the frame with the same content was successfully sent to the CAN bus. This flag is set for frames sent by the application itself as well as for frames sent by other applications running on the same system.

ReceiveOwnKey must be set to true to receive echo frames.

isValid()#
Return type:

bool

Returns false if the frameType() is InvalidFrame , the hasExtendedFrameFormat() is not set although frameId() is longer than 11 bit or the payload is longer than the maximal permitted payload length of 64 byte if Flexible Data-Rate mode is enabled or 8 byte if it is disabled. If frameType() is RemoteRequestFrame and the Flexible Data-Rate mode is enabled at the same time false is also returned.

Otherwise this function returns true.

payload()#
Return type:

QByteArray

Returns the data payload of the frame.

See also

setPayload()

setBitrateSwitch(bitrateSwitch)#
Parameters:

bitrateSwitch – bool

Set the Flexible Data-Rate flag Bitrate Switch flag to bitrateSwitch. The data field of frames with this flag is transferred at a higher data bitrate.

setError(e)#
Parameters:

e – Combination of FrameError

Sets the frame’s error type. This function does nothing if frameType() is not an ErrorFrame .

See also

error()

setErrorStateIndicator(errorStateIndicator)#
Parameters:

errorStateIndicator – bool

Set the Flexible Data-Rate flag Error State Indicator flag to errorStateIndicator.

When sending CAN FD frames, this flag is automatically set by the CAN FD hardware. QCanBusFrame::setErrorStateIndicator() should only be used for application testing, e.g. on virtual CAN FD busses.

setExtendedFrameFormat(isExtended)#
Parameters:

isExtended – bool

Sets the extended frame format flag to isExtended.

setFlexibleDataRateFormat(isFlexibleData)#
Parameters:

isFlexibleData – bool

Sets the Flexible Data-Rate flag to isFlexibleData. Those frames can be sent using a higher speed on supporting controllers. Additionally the payload length limit is raised to 64 byte.

setFrameId(newFrameId)#
Parameters:

newFrameId – int

Sets the identifier of the CAN frame to newFrameId.

The maximum size of a CAN frame identifier is 11 bits, which can be extended up to 29 bits by supporting the CAN extended frame format. The CAN extended frame format setting is automatically set when a newFrameId with more than 11 bits in size is given.

When the format is extended and a newFrameId with up to 11 bits or less is passed, the CAN extended frame format setting is not changed.

setFrameType(newFormat)#
Parameters:

newFormatFrameType

Sets the type of the frame to newType.

See also

frameType()

setLocalEcho(localEcho)#
Parameters:

localEcho – bool

Set the Local Echo flag to echo.

When sending CAN bus frames with ReceiveOwnKey enabled, all successfully sent frames are echoed to the receive queue and marked as local echo frames. QCanBusFrame::setLocalEcho should therefore only be used for application testing, e.g. on virtual CAN busses.

See also

hasLocalEcho()

setPayload(data)#
Parameters:

dataQByteArray

Sets data as the payload for the CAN frame. The maximum size of payload is 8 bytes, which can be extended up to 64 bytes by supporting Flexible Data-Rate. If data contains more than 8 byte the Flexible Data-Rate flag is automatically set. Flexible Data-Rate has to be enabled on the QCanBusDevice by setting the CanFdKey .

Frames of type RemoteRequestFrame (RTR) do not have a payload. However they have to provide an indication of the responses expected payload length. To set the expected length it is necessary to set a fake payload whose length matches the expected payload length of the response. One way of doing this might be as follows:

QCanBusFrame frame(QCanBusFrame::RemoteRequestFrame);
int expectedResponseLength = ...;
frame.setPayload(QByteArray(expectedResponseLength, 0));
setTimeStamp(ts)#
Parameters:

tsTimeStamp

Sets ts as the timestamp for the CAN frame. Usually, this function is not needed, because the timestamp is created during the read operation and not needed during the write operation.

See also

timeStamp() TimeStamp

timeStamp()#
Return type:

TimeStamp

Returns the timestamp of the frame.

See also

TimeStamp setTimeStamp()

toString()#
Return type:

str

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