PySide6.QtSerialBus.QCanFrameProcessor¶
- class QCanFrameProcessor¶
- The - QCanFrameProcessorclass can be used to decode a- QCanBusFrameor to convert the input data into a- QCanBusFramethat is ready to be sent to the receiver. More_…- Synopsis¶- Methods¶- def - __init__()
- def - error()
- def - errorString()
- def - parseFrame()
- def - prepareFrame()
- def - warnings()
 - 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¶- The - QCanFrameProcessorclass operates on the CAN message descriptions (represented by the- QCanMessageDescriptionand- QCanSignalDescriptionclasses) and a unique identifier description (represented by- QCanUniqueIdDescription). It uses the descriptions to decode the incoming- QCanBusFrameor to encode the user-specified data into the proper payload.- Before doing any decoding or encoding, the - QCanFrameProcessorinstance must be initialized properly. The following data needs to be provided:- A - validunique identifier description. Use the- setUniqueIdDescription()method to provide a proper description.
- At least one message description. Use the - addMessageDescriptions()or- setMessageDescriptions()method to provide message descriptions. All message descriptions must have distinct unique identifiers. Each message can contain multiple signal descriptions, but signal names within one message must be unique as well.
 - The - parseFrame()method can be used to process the incoming- QCanBusFrame. The method returns a- ParseResultstructure which contains the unique identifier and the signal values map. The keys of the map are the- signal names, and the values of the map are signal values.- The - prepareFrame()method can be used to generate a- QCanBusFrameobject for a specific unique identifier, using the provided signal names and desired values.- Errors can occur during the encoding or decoding process. In such cases the - error()and- errorString()methods can be used to get the information about the error.- Some non-critical problems may occur as well. Such problems will be logged, but the process will not be stopped. After the process is completed, the - warnings()method can be used to access the list of all the warnings.- Note - The last error and error description, as well as the warnings, are reset once the decoding or encoding is started. - class Error¶
- This enum represents the possible errors that can occur while encoding or decoding the - QCanBusFrame.- Constant - Description - QCanFrameProcessor.Error.None_ - No error occurred. - QCanFrameProcessor.Error.InvalidFrame - The received frame is invalid and cannot be parsed. - QCanFrameProcessor.Error.UnsupportedFrameFormat - The format of the received frame is not supported and cannot be parsed. - QCanFrameProcessor.Error.Decoding - An error occurred during decoding. Use - errorString()to get a string representation of the error.- QCanFrameProcessor.Error.Encoding - An error occurred during encoding. Use - errorString()to get a string representation of the error.
 - __init__()¶
 - Creates a CAN frame processor. - addMessageDescriptions(descriptions)¶
- Parameters:
- descriptions – .list of QCanMessageDescription 
 
 - Adds new message descriptions - descriptionsto the available message descriptions.- All message descriptions should have distinct unique ids. - If some message descriptions have repeated unique ids, only the last description will be used. - If the parser already had a message description with the same unique id, it will be overwritten. - clearMessageDescriptions()¶
 - Removes all message descriptions for this frame processor. - Returns the last error. - See also - errorString()¶
- Return type:
- str 
 
 - Returns the text description of the last error. - See also - messageDescriptions()¶
- Return type:
- .list of QCanMessageDescription 
 
 - Returns all the message descriptions that are currently used by this frame processor. - parseFrame(frame)¶
- Parameters:
- frame – - QCanBusFrame
- Return type:
 
 - Parses the frame - frameusing the specified message descriptions.- The process of parsing is as follows: - The - uniqueIdDescription()is used to extract the unique identifier of the message.
- The extracted unique identifier is used to search for a suitable - QCanMessageDescriptionfrom the list of all available- messageDescriptions().
- The matching - QCanMessageDescriptionis used to extract the signal values from the frame.
 - This method returns a - ParseResult, which contains both the extracted unique identifier and a QVariantMap with the signals and their values. The keys of the map are the- signal names, and the values of the map are signal values.- If an error occurred during the decoding, a result with empty signalValues is returned. In such cases, the - error()and- errorString()methods can be used to get information about the errors.- Note - Calling this method clears all previous errors and warnings. - prepareFrame(uniqueId, signalValues)¶
- Parameters:
- uniqueId – - UniqueId
- signalValues – Dictionary with keys of type .QString and values of type QVariant. 
 
- Return type:
 
 - Constructs a CAN data frame, using - uniqueIdand- signalValuesand returns the constructed- QCanBusFrame.- The - signalValuesparameter must contain signal names as keys, and expected signal values as values.- The process of creating the frame is as follows: - The - uniqueIdis used to find an appropriate message description.
- If the message description is found, a - QCanBusFramewith a payload of the specified size is created. All bytes of the payload, as well as the frame id, are initialized to zeros.
- The - uniqueIdDescription()is used to encode the- uniqueIdinto the appropriate part of the frame (frame id or payload).
- The selected message description is used to encode all the - signalValuesinto the frame.
- The parts of the frame that are not covered by a unique id or existing signal descriptions are untouched (and so still contain zeros). 
 - If an error occurred during the encoding, an invalid - QCanBusFrameis returned. In such cases, the- error()and- errorString()methods can be used to get information about the errors.- Note - Calling this method clears all previous errors and warnings. - setMessageDescriptions(descriptions)¶
- Parameters:
- descriptions – .list of QCanMessageDescription 
 
 - Replaces current message descriptions used by this frame processor with the new message descriptions - descriptions.- setUniqueIdDescription(description)¶
- Parameters:
- description – - QCanUniqueIdDescription
 
 - Sets the unique identifier description to - description.- The unique identifier description must be valid in order to encode or decode the CAN bus frames. See the - QCanUniqueIdDescriptionclass documentation for more details.- uniqueIdDescription()¶
- Return type:
 
 - Returns the unique identifier description. - The unique identifier description must be valid in order to encode or decode the CAN bus frames. See the - QCanUniqueIdDescriptionclass documentation for more details.- warnings()¶
- Return type:
- list of strings 
 
 - Returns the list of warnings generated during the last encoding or decoding call. - See also - class ParseResult¶
- 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¶- PySide6.QtSerialBus.QCanFrameProcessor.ParseResult.uniqueId¶
 - PySide6.QtSerialBus.QCanFrameProcessor.ParseResult.signalValues¶