SIMULINK: send string via Stream Output

7 views (last 30 days)
John
John on 13 Aug 2014
Commented: John on 15 Aug 2014
How are strings sent to serial devices in Simulink? If I have a string that's of length N, all ASCII characters, how can I specify that as a single input to a Stream Output block?
Right now I can't imagine that I'd have to explicitly list out all (say) 100 characters in the "Format String" line inside that block.
NOTE: This is in the case of Real-Time Windows Target, but i think should be the same for any Stream Output block from other libraries.

Accepted Answer

Jan Houska
Jan Houska on 15 Aug 2014
Simulink does not have a signal of type "string". To work with strings, you must use their numeric (ASCII) encodings.
The Stream Output block is designed for sending numeric values formatted as ASCII, perhaps surrounded by additional characters. If you need to send, say "x=3.14" in one time step and "x=3.18" in the next time step, you would use this block.
With fixed-size messages that don't contain the input signal numeric value encoded as ASCII string, you may get better results using the Packet Output block. Please encode your messages into ASCII and then feed such encoded messages as numeric inputs into this block. To select different messages based on some input signal, it would be probably necessary to use some sort of look-up table that would translate the input signal into the encoded message.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!