How to use "BigEndian" byte order when using the pack and unpack functions in MATLAB R2023a?

13 visualizzazioni (ultimi 30 giorni)
I am trying to pack and unpack a CAN message using MATLAB R2023a while interfacing with one of my products. However, when I try to pack/ unpack my CAN frames that are in Big Endian format, I get the error shown below:
Invalid combination of start bit, signal size, and byte order.
This issue can be reproduced by the code given below:
message = canMessage(500,false,8);
pack(message,int16(1000),0,16,'BigEndian')
value = unpack(message,0,16,'BigEndian','int16'

Risposta accettata

MathWorks Support Team
MathWorks Support Team il 16 Ago 2023
The start bit and the byte order are not independent. In this example, the start bit should be 16 when Big Endian is used. Big Endian byte order is counted from the Least Significant Bit to the Lowest Address. So for Big Endian, an example code snippet for packing and unpacking data is as follows:
message = canMessage(500,false,8);
pack(message,int16(1000),16,16,'BigEndian')
value = unpack(message,16,16,'BigEndian','int16')
For more information on how "startbit" and "byteorder" are related to each other, please check the "Signals" section in the link below:

Più risposte (0)

Prodotti


Release

R2023a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by