In questa pagina

QCanBusFrame Class

QCanBusFrame è una classe contenitore che rappresenta un singolo frame CAN. Per saperne di più...

Intestazione: #include <QCanBusFrame>
CMake: find_package(Qt6 REQUIRED COMPONENTS SerialBus)
target_link_libraries(mytarget PRIVATE Qt6::SerialBus)
qmake: QT += serialbus

Tipi pubblici

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

Funzioni pubbliche

QCanBusFrame(QCanBusFrame::FrameType type = DataFrame)
QCanBusFrame(QCanBusFrame::FrameId identifier, const QByteArray &data)
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)

Descrizione dettagliata

QCanBusDevice È possibile utilizzare QCanBusFrame per le operazioni di lettura e scrittura. Contiene l'identificatore del frame e il payload dei dati. QCanBusFrame contiene il timestamp del momento in cui è stato letto.

Vedi anche QCanBusFrame::FrameId, QCanBusFrame::TimeStamp e payload().

Documentazione sui tipi di membri

enum QCanBusFrame::FrameError
flags QCanBusFrame::FrameErrors

Questa enumerazione descrive i possibili tipi di errore.

CostanteValoreDescrizione
QCanBusFrame::NoError0Non si è verificato alcun errore.
QCanBusFrame::TransmissionTimeoutError(1 << 0)La trasmissione è scaduta.
QCanBusFrame::LostArbitrationError(1 << 1)Non è stato possibile inviare il frame a causa della perdita dell'arbitraggio sul bus.
QCanBusFrame::ControllerError(1 << 2)Il controller ha rilevato un errore.
QCanBusFrame::ProtocolViolationError(1 << 3)Si è verificata una violazione del protocollo.
QCanBusFrame::TransceiverError(1 << 4)Si è verificato un errore del ricetrasmettitore
QCanBusFrame::MissingAcknowledgmentError(1 << 5)La trasmissione non ha ricevuto alcun riconoscimento.
QCanBusFrame::BusOffError(1 << 6)Il bus CAN è offline.
QCanBusFrame::BusError(1 << 7)Si è verificato un errore sul bus CAN.
QCanBusFrame::ControllerRestartError(1 << 8)Il controller si è riavviato.
QCanBusFrame::UnknownError(1 << 9)Si è verificato un errore sconosciuto.
QCanBusFrame::AnyError0x1FFFFFFFUCorrisponde a tutti gli altri tipi di errore.

Il tipo FrameErrors è un typedef per QFlags<FrameError>. Memorizza una combinazione OR di valori FrameError.

Vedi anche error() e setError().

[alias] QCanBusFrame::FrameId

Un tipo specifico per l'identificatore di un frame del bus CAN a 11 o 29 bit.

Vedi anche frameId() e setFrameId().

enum QCanBusFrame::FrameType

Questa enumerazione descrive il tipo di frame CAN.

CostanteValoreDescrizione
QCanBusFrame::UnknownFrame0x0Il tipo di frame è sconosciuto.
QCanBusFrame::DataFrame0x1Questo valore rappresenta un frame di dati.
QCanBusFrame::ErrorFrame0x2Questo valore rappresenta un frame di errore.
QCanBusFrame::RemoteRequestFrame0x3Questo valore rappresenta una richiesta remota.
QCanBusFrame::InvalidFrame0x4Questo valore rappresenta un frame non valido. Questo tipo viene utilizzato per la segnalazione degli errori.

Vedi anche frameType() e setFrameType().

Documentazione delle funzioni membro

[explicit noexcept] QCanBusFrame::QCanBusFrame(QCanBusFrame::FrameType type = DataFrame)

Crea un frame CAN in base all'type e specificata.

Vedi anche QCanBusFrame::FrameType e setFrameType().

[explicit] QCanBusFrame::QCanBusFrame(QCanBusFrame::FrameId identifier, const QByteArray &data)

Crea un frame CAN utilizzando identifier come identificatore del frame e data come payload.

Vedi anche QCanBusFrame::FrameId.

[constexpr noexcept] QCanBusFrame::FrameErrors QCanBusFrame::error() const

Restituisce l'errore del frame di errore corrente. Se il frame non è un ` ErrorFrame`, questa funzione restituisce ` NoError`.

Vedi anche ` QCanBusFrame::FrameError ` e ` setError()`.

[constexpr noexcept] QCanBusFrame::FrameId QCanBusFrame::frameId() const

Restituisce l'identificatore del frame CAN. Se il frame CAN utilizza il formato esteso, l'identificatore ha una lunghezza massima di 29 bit; in caso contrario, è di 11 bit.

Se il frame è di tipo « ErrorFrame », questo ID è sempre 0.

Vedi anche QCanBusFrame::FrameId, setFrameId() e hasExtendedFrameFormat().

[constexpr noexcept] QCanBusFrame::FrameType QCanBusFrame::frameType() const

Restituisce il tipo del frame.

Vedi anche QCanBusFrame::FrameType e setFrameType().

[constexpr noexcept] bool QCanBusFrame::hasBitrateSwitch() const

Restituisce true se il CAN utilizza la modalità “Flexible Data-Rate with Bitrate Switch” per trasferire i dati di payload a una velocità di trasmissione più elevata.

Vedi anche setBitrateSwitch() e QCanBusDevice::DataBitRateKey.

[constexpr noexcept] bool QCanBusFrame::hasErrorStateIndicator() const

Restituisce " true " se il CAN utilizza la modalità " Flexible Data-Rate " con l'indicatore di stato di errore attivato.

Questo flag viene impostato dall'hardware CAN FD del trasmettitore per indicare lo stato di errore del trasmettitore.

Vedi anche setErrorStateIndicator().

[constexpr noexcept] bool QCanBusFrame::hasExtendedFrameFormat() const

Restituisce true se il frame CAN utilizza un identificatore a 29 bit; in caso contrario, restituisce false, il che implica un identificatore a 11 bit.

Vedi anche setExtendedFrameFormat() e frameId().

[constexpr noexcept] bool QCanBusFrame::hasFlexibleDataRateFormat() const

Restituisce ` true ` se il frame CAN utilizza la modalità “Flexible Data-Rate”, che consente fino a 64 byte di dati; in caso contrario, restituisce ` false`, il che implica un carico utile massimo di 8 byte.

Vedi anche setFlexibleDataRateFormat() e payload().

[constexpr noexcept] bool QCanBusFrame::hasLocalEcho() const

Restituisce " true " se il frame è un frame di eco locale, ovvero un frame ricevuto come eco quando il frame con lo stesso contenuto è stato inviato con successo al bus CAN. Questo flag viene impostato sia per i frame inviati dall'applicazione stessa sia per quelli inviati da altre applicazioni in esecuzione sullo stesso sistema.

QCanBusDevice::ReceiveOwnKey Deve essere impostato su true per ricevere i frame di eco.

Vedi anche setLocalEcho(), QCanBusDevice::ReceiveOwnKey e QCanBusDevice::LoopbackKey.

[noexcept] bool QCanBusFrame::isValid() const

Restituisce " false " se " frameType()" è " InvalidFrame", se " hasExtendedFrameFormat()" non è impostato nonostante " frameId()" sia più lungo di 11 bit oppure se il payload è più lungo della lunghezza massima consentita di 64 byte (se la modalità " Flexible Data-Rate " è abilitata) o di 8 byte (se è disabilitata). Se frameType() è RemoteRequestFrame e contemporaneamente è abilitata la modalità Flexible Data-Rate, viene restituito anche false.

In caso contrario, questa funzione restituisce « true ».

QByteArray QCanBusFrame::payload() const

Restituisce il payload di dati del frame.

Vedi anche setPayload().

[constexpr noexcept] void QCanBusFrame::setBitrateSwitch(bool bitrateSwitch)

Impostare il flag "Flexible Data-Rate " ( Bitrate Switch ) su " bitrateSwitch". Il campo dati dei frame con questo flag viene trasmesso a una velocità di trasmissione più elevata.

Vedi anche ` hasBitrateSwitch()` e ` QCanBusDevice::DataBitRateKey`.

[constexpr] void QCanBusFrame::setError(QCanBusFrame::FrameErrors error)

Imposta il tipo di " error " del frame. Questa funzione non esegue alcuna operazione se frameType() non è un ErrorFrame.

Vedi anche ` QCanBusFrame::FrameError ` e ` error()`.

[constexpr noexcept] void QCanBusFrame::setErrorStateIndicator(bool errorStateIndicator)

Impostare il flag " Flexible Data-Rate " (Velocità di trasmissione flessibile) e il flag " Error State Indicator " (Indicatore di stato di errore) su " errorStateIndicator".

Durante l'invio di frame CAN FD, questo flag viene impostato automaticamente dall'hardware CAN FD. Il valore " QCanBusFrame::setErrorStateIndicator() " deve essere utilizzato solo per i test delle applicazioni, ad esempio su bus CAN FD virtuali.

Vedi anche " hasErrorStateIndicator" ().

[constexpr noexcept] void QCanBusFrame::setExtendedFrameFormat(bool isExtended)

Imposta il flag del formato frame esteso su " isExtended".

Vedi anche hasExtendedFrameFormat().

[constexpr noexcept] void QCanBusFrame::setFlexibleDataRateFormat(bool isFlexibleData)

Imposta il flag “Flexible Data-Rate” su “ isFlexibleData ”. Tali frame possono essere inviati a una velocità maggiore sui controller che supportano questa funzione. Inoltre, il limite di lunghezza del payload viene aumentato a 64 byte.

Vedi anche hasFlexibleDataRateFormat().

[constexpr] void QCanBusFrame::setFrameId(QCanBusFrame::FrameId newFrameId)

Imposta l'identificatore del frame CAN su newFrameId.

La dimensione massima di un identificatore di frame CAN è di 11 bit, estendibile fino a 29 bit grazie al supporto del formato di frame CAN esteso. L'impostazione del formato di frame CAN esteso viene configurata automaticamente quando viene specificato un " newFrameId " di dimensioni superiori a 11 bit.

Quando il formato è esteso e viene passato un identificatore di frame CAN ( newFrameId ) di lunghezza pari o inferiore a 11 bit, l’impostazione del formato esteso del frame CAN non viene modificata.

Vedi anche QCanBusFrame::FrameId, frameId() e hasExtendedFrameFormat().

[constexpr noexcept] void QCanBusFrame::setFrameType(QCanBusFrame::FrameType newType)

Imposta il tipo di cornice su " newType".

Vedi anche QCanBusFrame::FrameType e frameType().

[constexpr noexcept] void QCanBusFrame::setLocalEcho(bool echo)

Impostare il flag “Local Echo ” su “ echo ”.

Quando si inviano frame sul bus CAN con l'opzione " QCanBusDevice::ReceiveOwnKey " abilitata, tutti i frame inviati con successo vengono reindirizzati alla coda di ricezione e contrassegnati come frame di eco locale. L'opzione " QCanBusFrame::setLocalEcho " dovrebbe quindi essere utilizzata solo per il collaudo delle applicazioni, ad esempio su bus CAN virtuali.

Vedi anche hasLocalEcho().

void QCanBusFrame::setPayload(const QByteArray &data)

Imposta “ data ” come payload per il frame CAN. La dimensione massima del payload è di 8 byte, estendibile fino a 64 byte grazie al supporto della modalità “Flexible Data-Rate”. Se “ data ” contiene più di 8 byte, il flag “Flexible Data-Rate ” viene impostato automaticamente. La modalità Flexible Data-Rate deve essere abilitata sull’ QCanBusDevice e impostando l’ QCanBusDevice::CanFdKey.

I frame di tipo RTR ( RemoteRequestFrame ) non hanno un payload. Tuttavia, devono fornire un’indicazione della lunghezza prevista del payload della risposta. Per impostare la lunghezza prevista è necessario impostare un payload fittizio la cui lunghezza corrisponda a quella prevista del payload della risposta. Un modo per farlo potrebbe essere il seguente:

QCanBusFrame frame(QCanBusFrame::RemoteRequestFrame);
int expectedResponseLength = ...;
frame.setPayload(QByteArray(expectedResponseLength, 0));

Vedi anche payload() e hasFlexibleDataRateFormat().

[constexpr noexcept] void QCanBusFrame::setTimeStamp(QCanBusFrame::TimeStamp ts)

Imposta ts come timestamp per il frame CAN. Di solito questa funzione non è necessaria, poiché il timestamp viene creato durante l'operazione di lettura e non è richiesto durante l'operazione di scrittura.

Vedi anche timeStamp() e QCanBusFrame::TimeStamp.

[constexpr noexcept] QCanBusFrame::TimeStamp QCanBusFrame::timeStamp() const

Restituisce il timestamp del fotogramma.

Vedi anche QCanBusFrame::TimeStamp e QCanBusFrame::setTimeStamp().

QString QCanBusFrame::toString() const

Restituisce il frame CAN come stringa formattata.

L'output contiene l'identificatore CAN in formato esadecimale, allineato a destra a 32 bit, seguito dalla lunghezza dei dati tra parentesi quadre e dal payload in formato esadecimale.

Gli identificatori standard vengono riempiti con spazi, mentre quelli estesi vengono riempiti con zeri.

Esempi tipici di output sono:

(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

Correlati per i non membri

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

Scrive un oggetto di tipo ` frame ` nel flusso (out) e restituisce un riferimento ad esso.

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

Legge un oggetto ` frame ` dallo stream (in) e restituisce un riferimento ad esso.

© 2026 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.