How to receive serial strings in Simulink
19 次查看(过去 30 天)
显示 更早的评论
I am trying to read a stream of strings from serial input (COM Port) and then display the strings. The issue I am having is that the strings are of variable length and Simulink only seems to be able to read a string if I specify its length in the data size field. What I'd really like is a method to specify the max length and use the CR/LF as the termination mechanism. I tried every combination of the serial read block and cannot get it to work.
The model is similar to this:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1157703/image.png)
In the above example, if I set the Data size to [1 1], then I only get the last character received.
I read thru the documentation multiple times for serial receive and was not able to understand what the Data size really means. Also, Row major and Column major are not defined very well. Two of built in examples are Matlab only. The simulink example is not found (2022a + I have the Instrument Toolbox installed).
Any help would be appreciated...
0 个评论
回答(1 个)
Pratyush Swain
2023-9-10
编辑:Pratyush Swain
2023-9-10
Hi Rick,
I understand that you want to receive strings of variable length through serial receive block, but block parameters are not dynamic and cannot change as per the input values.
Also here is some information regarding ‘Data Size’ and ‘Input Format’ (Row Major / Col major) parameters.
1- The data size parameter is specified by multidimensional numeric array in the format [a b] which implies an array with dimensions a x b. For example - data size parameter [1 18] implies a character row vector of size 18.
2- The input format is specified by values - ('Row major' or 'Column major'). 'Column major' means the elements in a column are read consecutively while 'Row major' implies elements are in row are read consecutively.
Hope the above information helps.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Development Computer Setup 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!