QCanBusFrame is a container class representing a single CAN frame. 更多...
头: | #include <QCanBusFrame> |
qmake: | QT += serialbus |
Since: | Qt 5.8 |
class | TimeStamp |
enum | FrameError { NoError, TransmissionTimeoutError, LostArbitrationError, ControllerError, ProtocolViolationError, …, AnyError } |
flags | FrameErrors |
enum | FrameType { UnknownFrame, DataFrame, ErrorFrame, RemoteRequestFrame, InvalidFrame } |
QCanBusFrame (QCanBusFrame::FrameId identifier , const QByteArray & data ) | |
QCanBusFrame (QCanBusFrame::FrameType type = DataFrame) | |
QCanBusFrame::FrameErrors | error () const |
QCanBusFrame::FrameId | frameId () const |
QCanBusFrame::FrameType | frameType () const |
bool | hasBitrateSwitch () const |
bool | hasErrorStateIndicator () const |
bool | hasExtendedFrameFormat () const |
bool | hasFlexibleDataRateFormat () const |
bool | hasLocalEcho () const |
bool | isValid () const |
QByteArray | payload () const |
void | setBitrateSwitch (bool bitrateSwitch ) |
void | setError (QCanBusFrame::FrameErrors error ) |
void | setErrorStateIndicator (bool errorStateIndicator ) |
void | setExtendedFrameFormat (bool isExtended ) |
void | setFlexibleDataRateFormat (bool isFlexibleData ) |
void | setFrameId (QCanBusFrame::FrameId newFrameId ) |
void | setFrameType (QCanBusFrame::FrameType newType ) |
void | setLocalEcho (bool echo ) |
void | setPayload (const QByteArray & data ) |
void | setTimeStamp (QCanBusFrame::TimeStamp ts ) |
QCanBusFrame::TimeStamp | timeStamp () const |
QString | toString () const |
QDataStream & | operator<< (QDataStream & out , const QCanBusFrame & frame ) |
QDataStream & | operator>> (QDataStream & in , QCanBusFrame & frame ) |
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.
另请参阅 QCanBusFrame::TimeStamp .
This enum describes the possible error types.
常量 | 值 | 描述 |
---|---|---|
QCanBusFrame::NoError
|
0
|
没有出现错误。 |
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)
|
出现未知错误。 |
QCanBusFrame::AnyError
|
0x1FFFFFFFU
|
Matches every other error type. |
The FrameErrors type is a typedef for QFlags <FrameError>. It stores an OR combination of FrameError values.
This enum describes the type of the CAN frame.
常量 | 值 | 描述 |
---|---|---|
QCanBusFrame::UnknownFrame
|
0x0
|
The frame type is unknown. |
QCanBusFrame::DataFrame
|
0x1
|
This value represents a data frame. |
QCanBusFrame::ErrorFrame
|
0x2
|
This value represents an error frame. |
QCanBusFrame::RemoteRequestFrame
|
0x3
|
This value represents a remote request. |
QCanBusFrame::InvalidFrame
|
0x4
|
This value represents an invalid frame. This type is used for error reporting. |
另请参阅 setFrameType ().
Constructs a CAN frame using identifier as the frame identifier and data as the payload.
Constructs a CAN frame of the specified type .
Returns the error of the current error frame. If the frame is not an ErrorFrame ,此函数返回 NoError .
另请参阅 setError ().
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.
另请参阅 setFrameId () 和 hasExtendedFrameFormat ().
Returns the type of the frame.
另请参阅 setFrameType ().
[since 5.9]
bool
QCanBusFrame::
hasBitrateSwitch
() const
返回
true
if the CAN uses
Flexible Data-Rate
with
Bitrate Switch
, to transfer the payload data at a higher data bitrate.
该函数在 Qt 5.9 引入。
另请参阅 setBitrateSwitch () 和 QCanBusDevice::DataBitRateKey .
[since 5.9]
bool
QCanBusFrame::
hasErrorStateIndicator
() const
返回
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.
该函数在 Qt 5.9 引入。
另请参阅 setErrorStateIndicator ().
返回
true
if the CAN frame uses a 29bit identifier; otherwise
false
, implying an 11bit identifier.
另请参阅 setExtendedFrameFormat () 和 frameId ().
返回
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.
另请参阅 setFlexibleDataRateFormat () 和 payload ().
[since 5.10]
bool
QCanBusFrame::
hasLocalEcho
() const
返回
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.
QCanBusDevice::ReceiveOwnKey must be set to true to receive echo frames.
该函数在 Qt 5.10 引入。
另请参阅 setLocalEcho (), QCanBusDevice::ReceiveOwnKey ,和 QCanBusDevice::LoopbackKey .
返回
false
若
frameType
() 是
InvalidFrame
,
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
() 是
RemoteRequestFrame
和
Flexible Data-Rate
mode is enabled at the same time
false
is also returned.
Otherwise this function returns
true
.
Returns the data payload of the frame.
另请参阅 setPayload ().
[since 5.9]
void
QCanBusFrame::
setBitrateSwitch
(
bool
bitrateSwitch
)
设置 Flexible Data-Rate flag Bitrate Switch flag to bitrateSwitch . The data field of frames with this flag is transferred at a higher data bitrate.
该函数在 Qt 5.9 引入。
另请参阅 hasBitrateSwitch () 和 QCanBusDevice::DataBitRateKey .
Sets the frame's error type. This function does nothing if frameType () is not an ErrorFrame .
另请参阅 error ().
[since 5.9]
void
QCanBusFrame::
setErrorStateIndicator
(
bool
errorStateIndicator
)
设置 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.
该函数在 Qt 5.9 引入。
另请参阅 hasErrorStateIndicator ().
Sets the extended frame format flag to isExtended .
另请参阅 hasExtendedFrameFormat ().
设置 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.
另请参阅 hasFlexibleDataRateFormat ().
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 。 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 改变。
另请参阅 frameId () 和 hasExtendedFrameFormat ().
Sets the type of the frame to newType .
另请参阅 frameType ().
[since 5.10]
void
QCanBusFrame::
setLocalEcho
(
bool
echo
)
设置 Local Echo flag to echo .
When sending CAN bus frames with
QCanBusDevice::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.
该函数在 Qt 5.10 引入。
另请参阅 hasLocalEcho ().
设置 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 。若 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 QCanBusDevice::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 length expection 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));
另请参阅 payload () 和 hasFlexibleDataRateFormat ().
设置 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.
另请参阅 timeStamp () 和 QCanBusFrame::TimeStamp .
Returns the timestamp of the frame.
另请参阅 QCanBusFrame::TimeStamp and QCanBusFrame::setTimeStamp ().
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
写入 frame to the stream ( out ) and returns a reference to the it.
读取 frame from the stream ( in ) and returns a reference to the it.