- You can use a MATLAB Function block that leverages MATLAB's serialport functionality to read the data.
- Alternatively, you can configure the Serial Receive block to read the data as a stream of uint8 values. These can then be buffered and converted to strings outside of the block. To do this, set the data type to uint8, disable the header and terminator, and specify a fixed output size. Keep in mind that, depending on the output size you specify, the data from the block may not contain a complete NMEA string and could span across multiple NMEA strings.
Serial Receive Block Variable Data Size
6 views (last 30 days)
Show older comments
Hi,
I’m working with a data logger that sends measurements over a USB serial interface. I’d like to read the data using Simulink’s Serial Receive block, but I’m running into a problem: the block requires a fixed message length, while my measurements vary in digit count, so each message can be longer or shorter.
I’ve tried setting a maximum data size, but then the block misses the terminator since it relies solely on the fixed length. I’ve also experimented with a smaller fixed size in non-blocking mode, buffering incoming bytes and then parsing complete messages—but approaches that i tried introduce delays that are unacceptable for my application.
I’d appreciate any suggestions or solutions to handle variable-length serial messages in Simulink without significant latency.
0 Comments
Answers (1)
Anjaneyulu Bairi
on 3 Jul 2025
Hey,
Currently, the Serial Receive block in the Instrument Control Toolbox does not support string outputs or variable-size outputs. Depending on your workflow, there are alternative methods for reading the data:
Hope this helps!
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!