Clear Filters
Clear Filters

How to use Stream Input block for serial communication using Simulink Desktop Real-Time

8 views (last 30 days)
I am trying to use Stream Input block to read data from a Serial Port in my Simulink Desktop Real-Time Application. Can you give me some hints on how I have to choose the parameters to make it work?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 9 Jul 2019
Edited: MathWorks Support Team on 9 Jul 2019
Since serial communications does not come in packets, greater care must be taken to correctly specify the terminating sequence so that the parser is able to determine the end of the sequence and start of another one. Typically for serial communications, sequences end in a Carriage Return (CR, or \r), or a Carriage Return in combination with Line Feed (LF, or \n).
If you are unsure what the sequences look like, you may try out tools like RealTerm:
By selecting "Display as ASCII", you will be able to inspect the sequences. For example, it could look like this:
In this case, the sequence seems to be a 5-digit integer number with a CR ending sequence. One possible way to set the Stream Input block parameters would be:
Block output data types: uint16
Format string: %d
Message Termination: \r

More Answers (0)

Community Treasure Hunt

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

Start Hunting!