I need to receive integer data from serial com port 7 data in simulink. Please help me design the simulink model
4 views (last 30 days)
Show older comments
How can I model this matlab code in simulink to receive integer data from serial com port 7 data in simulink?
s = serial('COM7'); set(s,'BaudRate',9600); fopen(s); fprintf(s,'*IDN?') %% out = fscanf(s) fclose(s); delete(s) clear s
0 Comments
Answers (1)
Naveed Ahmed
on 31 Jul 2018
Hi,
Open a new Simulink Model and add following three blocks. 1. Serial Configuration 2. Serial Receive 3. Matlab Function
Blocks 1 and 2 are present in the Instrumentation Library whereas the MATLAB Function block is available in the Sink Library. You can use the serial blocks to set as per your MATLAB command. And write the other matlab statements in the MATLAB function block.
Hope it helps.
2 Comments
Naveed Ahmed
on 1 Aug 2018
The design of your Simulink model depends entirely on what you want it to do. First of all, I want you to be sure that you are not caught up with similar named blocks such MATLAB Function/Embedded Function etc. You have to use the Embedded Function block that allows to write your own custom code in the form of function. And the I/O ports of the block are also defined by I/O of your MATLAB Function. You cannot omit the serial receive block otherwise where will you get input for the embedded function from? And yes learn something about the bus connector symbol that is pretty handy tool to view the serial receiver output while giving it to the Embedded MATLAB block at the same time.
See Also
Categories
Find more on Block and Blockset Authoring in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!