Too few input values to make output type
Mostrar comentarios más antiguos
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 comentarios
Walter Roberson
el 31 de Mayo de 2018
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.
Jason Gauthier
el 31 de Mayo de 2018
Editada: Jason Gauthier
el 31 de Mayo de 2018
Walter Roberson
el 31 de Mayo de 2018
Is there the possibility that bytes might be empty on some path?
Have you tried
typecast(uint8(data(end-7:end))
Jason Gauthier
el 31 de Mayo de 2018
Walter Roberson
el 31 de Mayo de 2018
Odd...
Respuestas (0)
Categorías
Más información sobre Simulation en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!