MATLAB BLOCK POINT IMPLEMENTATION

1 view (last 30 days)
Igor Slivinschi
Igor Slivinschi on 19 Jan 2021
Answered: Hari on 22 Apr 2024
I have a block point in a project and may be you can help me. I will try bellow to describe my issue.
I’m working in a project where I created a GUI in app designer. In the GUI I’m setting some parameters and I’m sending it to a Data Dictionary (DD) what is used in a Simulink model.
In Simulink Model based on some data and there is detected some state (for eg. Init, Ready, Fault, etc.) these states I need to send to GUI during simulation.
The sending data from Simulink model to GUI I’m doing using listener ( add_exec_event_listener(blk1, event, listener);)
The start/stop simulation of Simulink model is performing direct from GUI.
For start model simulation I’m using : open_system(simulinkModel);
set_param(simulinkModel,'SimulationCommand','start');
For stop model simulation I’m using:set_param(simulinkModel,'SimulationCommand','stop');
Until here everything is ok the simulation is as expected.
Next step is that all project should be standalone application and now are coming blocking point and the issues.
The GUI should be executable(.exe) and the Simulink model will be generated in C code with Simulink Coder and the source files should be integrated to exe GUI then it is created as standalone application.
But the standalone application should behave as described above.
From GUI.exe I need to send the parameters do DD also in parallel to a .mat file.
From application I need to receive in GUI.exe the status state((for eg. Init, Ready, Fault, etc).
In this case with standalone application where are integrated GUI.exe, source file (generated from Simulink model), DD how I can simulate it all together?
And to check if the behavior is expected one.
And instead listener what I need to use to receive the states from application to GUI.exe?

Answers (1)

Hari
Hari on 22 Apr 2024
Hi Igor Slivinschi,
I understand that you have developed a project involving a GUI created in MATLAB's App Designer, which interacts with a Simulink model through a Data Dictionary (DD). Your project requires starting and stopping the Simulink simulation from the GUI and exchanging data between the Simulink model and the GUI. You are now looking to compile this project into a standalone application (.exe) using MATLAB Compiler and Simulink Coder. You can follow the below steps to acheive the same.
  1. Use MATLAB Compiler to compile the GUI created in App Designer into an executable (.exe). This process converts your MATLAB code into a standalone application that can be run without a MATLAB license. To compile the GUI, use "mcc -m YourApp.m", where YourApp.m is the main function or script that launches your App Designer app.
  2. For the Simulink model, use Simulink Coder to generate C code. This code needs to be compiled into a library or executable that can be called from your GUI application.
  3. Data Exchange between GUI and Simulink Model: For sending parameters from the GUI to the Simulink model (now in C code), consider saving the parameters to a .mat file or a text file from the GUI. The C code can then read these parameters at the start of its execution.
  4. To replace the functionality of "add_exec_event_listener" for state feedback from the Simulink model to the GUI, you can implement a polling mechanism in your GUI that regularly checks for updates in a specified file or through a specific IPC (Inter-Process Communication) mechanism that your compiled Simulink model writes to.
Here are the steps to implement a polling mechanism for GUI updates based on a Simulink model's state:
  • Simulink Model Side: Continuously write the model's state to a file or send it via an IPC mechanism at regular intervals.
  • GUI Application Side: Set up a timer that triggers a function to check for updates from the Simulink model periodically.
  • Reading Model State: In the triggered function, read the model's state from the specified file or IPC channel.
  • Update GUI: Use the read state information to update the GUI accordingly, reflecting the current state of the Simulink model.
  • Repeat: Continue this process as long as the GUI is running, ensuring the GUI remains updated with the latest state information from the model.
For compiling MATLAB applications, refer to the MATLAB Compiler documentation at https://www.mathworks.com/help/compiler/index.html.
For generating C code from Simulink models, see the Simulink Coder documentation at https://www.mathworks.com/help/rtw/index.html.
For App Designer, the documentation can be found at
Hope this helps!

Categories

Find more on Dependency Analysis in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!