Getting error: "Invalid combination of start bit, signal size, and byte order", when packing message in big endian format using vehicle network toolbox

조회 수: 2 (최근 30일)
I am trying to transmit a 4 byte can message in big endian format using the vehicle network toolbox using the code below.
message = canMessage(0x123, false, 4);
pack(message, 0x12345678, 31, 32, 'BigEndian');
But when i run it i get the error below when packing the message.
Error using can.Message/pack
Invalid combination of start bit, signal size, and byte order.
Error in canDebug (line 2)
pack(message, 0x12345678, 31, 32, 'BigEndian');
I have tried fixing the issue using the following changes, all errornous:
message = canMessage(0x123, false, 4);
pack(message, 0x12345678, 32, 32, 'BigEndian');
Error using pack
Expected STARTBIT to be a scalar with value < 32.
Error in can.Message/pack (line 614)
validateattributes(startBit, {'numeric'}, ...
Error in canDebug (line 2)
pack(message, 0x12345678, 32, 32, 'BigEndian');
message = canMessage(0x123, false, 4);
pack(message, 0x12345678, 0, 32, 'BigEndian');
Error using can.Message/pack
Invalid combination of start bit, signal size, and byte order.
Error in canDebug (line 2)
pack(message, 0x12345678, 0, 32, 'BigEndian');

답변 (1개)

Muskan
Muskan 2024년 2월 21일
The start bit and the byte order are not independent. You can further refer to the following MATLAB Answer for a better understanding:
I hope this helps!
  댓글 수: 1
Søren Lang
Søren Lang 2024년 2월 21일
I have been looking at that question, though if you compress the message to 2 bytes, as to keep the message short and to the point.
message = canMessage(500,false,2);
pack(message,int16(1000),16,16,'BigEndian')
value = unpack(message,16,16,'BigEndian','int16')
You get the error:
Error using pack
Expected STARTBIT to be a scalar with value < 16.
This is because bit position 16 does not exist when doing 0 indexing as is done with the vehicle network toolbox.
When doing big endian the byte array is reversed, eg.
[0x12 0x34 0x56] -> [0x56 0x34 0x12]
Thus the startbit will be given as the total amount of bits in the message minus 8 bits. Thus to run the above code, it should look like below.
message = canMessage(500,false,2);
pack(message,int16(1000),8,16,'BigEndian')
value = unpack(message,8,16,'BigEndian','int16')

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Vehicle Network Toolbox에 대해 자세히 알아보기

태그

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by