Serial input from COM device via "Stream Input"-block in Simulink Desktop Real-Time External (SLDRT)
12 views (last 30 days)
Maximilian Becker on 19 Aug 2021
in short, I would like to imitate the functionality of the "Serial Receive" block (https://de.mathworks.com/help/instrument/serialreceive.html) with the "Stream Input" block (https://de.mathworks.com/help/sldrt/ref/streaminput.html) and don't know how to do it.
Explanation: As part of my project I am forced to run my code in the Simulink Desktop Real-Time External environment. But since the serial blocks are only available in normal mode but not external mode, I require to have some work around this, where the only alternative seems to be the Stream Input block.
In normal mode I am using the Serial Configuration and Serial Receive blocks as follows:
So one message contains of a starting byte "A" and an end byte "\n". In between there currently is one single value containing of 4 bytes. With this I can display the following function:
When I now try to imitate that behavior with the stream blocks in external mode I am trying to do this:
with the board settings:
With the same data stream as in the above example, the sinus now looks like this:
Does anyone have an idea of what I am doing wrong? One problem is, that Stream Input does not use a starting byte, but just end bytes (never the less I tried to enter 'A' also into the message terminator array).
Furthermore I would like to receive a message containing 3 values and I do not know how to do that either.
Thank you in advance for every hint.
Jan Houska on 20 Aug 2021
the Stream Input block is designed for receiving textual (ASCII) data of potentially variable length. Since your data is binary and of fixed length, Packet Input block is the right block for you. The reason why you are getting garbage instead of the correct numeric value is that the Stream Input block is trying to interpret the four binary bytes as ASCII text, which it isn't. Therefore this cannot work.
Good Luck, Jan