I need to receive integer data from serial com port 7 data in simulink. Please help me design the simulink model

8 views (last 30 days)
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

Answers (1)

Naveed Ahmed
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
Akash gupta
Akash gupta on 31 Jul 2018
thanks for your answer. The MATLAB function is not in SINK library. It is in user defined function. I am not sure how to make the connections. The Serial Receive block will give the output and i connect display block. What do I add in the Function block (what will be the input, output and body of the function?) If I do not put the function block, I do not get output. If I put the matlab code in function and leave out the serial receive block, i get error like 'The 'serial' class does not support code generation.'
Naveed Ahmed
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.

Sign in to comment.

Categories

Find more on Simulink Functions 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!