Too few input values to make output type

I'm reading a binary stream from a serial port. The binary stream looks like this:
start byte (actually byte series)
length of subsequent data
important data
checksum
The stream is coming from a QUARC block, 16 bytes at a time. So, I'm put this into a MATLAB function that uses persistent variables to process the stream, detect the sync sequence, grab the length byte, and then read the next x bytes. The last 8 bytes (which is a float) is the checksum.
I want to convert that byte stream into a float, and then I can determine from the important data if it matches.
I've successfully used typecast to do this, but in this case it's simply not working.
I suspect, because the other complication, is that this is being built for code generation.
So, to provide specific details:
'bytes' is read in, and determined to be 48 bytes. the 40-48 bytes is the checksum. But I'm not always guaranteed to read in 48 bytes. I'd like to have some flexibility, so I cannot guarantee the size of the bytes that I am going to read (based on what I am sending, which is why I am sending the length)
So, 'bytes' (variable) now contains the length of the data, including the 8-byte checksum.
so, I try to type case that:
checksum = typecast(uint8(data(bytes-7:bytes)), 'double');
And it seems that it's not going to work when I build it.
"Too few input values to make output type.
Function 'Subsystem/MATLAB Function3' (#59.1056.1084), line 56, column 19:
"typecast(uint8(d), 'double')"
Launch diagnostic report."
If I hard code in some values:
checksum = typecast(uint8(data(32-7:32)), 'double');
The application builds fine.
I've been banging my head at reading this byte stream for far too long, and I finally made some progress and now hit another wall. Any thoughts are welcome.

5 Comments

Your error message does not agree with the code. The error message is typecasting d, but your checksum is typecasting data(bytes-7:bytes) . That suggests that two different typecast lines are present.
Yes, you're correct. I've been trying various things to figure out the issue. I reverted my code before posting, but didn't compile it to get an error message with the current variable in it.
Too few input values to make output type.
Function 'Subsystem/MATLAB Function3' (#59.980.1026), line 52, column
19:
"typecast(uint8(data(bytes-7:bytes)), 'double')"
Launch diagnostic report.
Is the actual error.
Is there the possibility that bytes might be empty on some path?
Have you tried
typecast(uint8(data(end-7:end))
Well, this seems to have corrected when I type cast 'bytes' back into a double from a uint8.
checksum = typecast(uint8(data(double(bytes)-7:double(bytes))), 'double');
It's still not quite right, but at least it compiles now.

Sign in to comment.

Answers (0)

Categories

Find more on Simulation in Help Center and File Exchange

Asked:

on 31 May 2018

Commented:

on 31 May 2018

Community Treasure Hunt

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

Start Hunting!