Simulink Stream I/O

4 次查看(过去 30 天)
Rick Policy
Rick Policy 2022-10-8
评论: Rick Policy 2022-10-10
I have a need to communicate with serial devices in an ascii fashion. I was not able to use Serial Config/Send/Receive from the Instrument Control toolbox due to it only supporting numerical data types. I did create a model working exactly the way I needed using Stream Input and Stream Output.
My question is: can you programatticaly or thru parameters setup the serial port? I had to "Install" a new board as a Standard Device -> Serial Port. I would like to be able to change the comm port if necessary when using my model on another machine without going thru the setup/install manually within the model. It would be great to be able to have the user enter the comm number on a numeric input and the model would do the rest.
- Rick

回答(1 个)

Walter Roberson
Walter Roberson 2022-10-8
I have a need to communicate with serial devices in an ascii fashion.
I was not able to use Serial Config/Send/Receive from the Instrument Control toolbox
due to it only supporting numerical data types.
Serial ports completely lack the capacity to mark particular data as being "ascii" or "numeric". Serial ports only have the capacity to transmit streams of bits, possibly with internal overhead to mark boundaries (such as start and stop bits for RS232 type protocols, or the ethernet frame structure.) It is up to the receiver to interpret the meaning of the bits. If the receiver sees binary 0100 0001 then there is absolutely nothing at the serial protocol level that would tell the receiver whether that is binary 65 or ascii 'A'
So, if you want to send ascii, just uint8() your stream of characters and send the result as binary. (For more advanced purposes, unicode2native() the text and send the resulting byte stream -- that would handle characters with Unicode positions 256 and greater as well.)
  1 个评论
Rick Policy
Rick Policy 2022-10-10
Understood. I just tried using a String to ASCII object and was able to see that the standard Serial In and Serial Out should work as you stated. The downside is my simulation was running very slow compared to Stream Input and Output.
My questions still stands for possible future uses of Stream Input and Stream Output blocks outside of serial communication (i.e. other devs) . It would be really nice to be able to configure them programatically instead of having to do it manually.

请先登录,再进行评论。

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by