How to use "BigEndian" byte order when using the pack and unpack functions in MATLAB R2023a?
12 次查看(过去 30 天)
显示 更早的评论
MathWorks Support Team
2023-8-16
回答: MathWorks Support Team
2023-8-17
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'
采纳的回答
MathWorks Support Team
2023-8-16
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Windows 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!