Hey @Jan Houska, please excuse me pinging you, but I just remembered that you might have an idea on how to solve this problem, since you are versatile in terms of SLDRT. :)
Serial input from COM device via "Stream Input"-block in Simulink Desktop Real-Time External (SLDRT)
15 次查看(过去 30 天)
显示 更早的评论
Hi,
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.
Example:
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.
Best regards,
Max
采纳的回答
Jan Houska
2021-8-20
Hi Max,
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
更多回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Target Computer Setup 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!