Simulink Stream I/O
4 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(1 个)
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.)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!