How to use "BigEndian" byte order when using the pack and unpack functions in MATLAB R2023a?
13 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
MathWorks Support Team
el 16 de Ag. de 2023
Respondida: MathWorks Support Team
el 17 de Ag. de 2023
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'
Respuesta aceptada
MathWorks Support Team
el 16 de Ag. de 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:
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Windows en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!