How do I find out if simulink is in sim or coder mode?

2 visualizzazioni (ultimi 30 giorni)
The basic problem is: If I simulate (by clicking on the green play button in simulink), I want to receive data by an UDP Block. If I generate code (e.g. hit Ctrl+B) the inports shall be used to receive data and no UDP communication shall be done (also no UDP socket shall be initialized). Anyway, using the Environment Controller block leads to a generation of the UDP Code because this block is a S-Function. As a workaround, I want to exchange the UDP Block by the inports programmatically during the initialization if the "Coder flag" is set. But how do I get this flag?
  1 Commento
Jens Klimke
Jens Klimke il 9 Mag 2017
From the "Environment Controller" block, I extracted the code
switch_mode = rtwenvironmentmode(bdroot(gcbh)) || ...
(exist('sldvisactive','file')~=0 && sldvisactive(bdroot(gcbh)));
which is exactly the flag I needed. It separates between the code generation (ctrl + b) and the simulation in Simulink (green play button). I use it in the initialization method of the system by replacing droot(gcbh) with gcs.

Accedi per commentare.

Risposte (1)

Wilson A N
Wilson A N il 8 Mag 2017
You can obtain the 'Coder flag' by using the following command:
>> k = get_param(<modelName>,'GenCodeOnly');
You can programmatically set it using the following command:
>> set_param(<modelName>,'GenCodeOnly','on');
  1 Commento
Jens Klimke
Jens Klimke il 8 Mag 2017
Hi Wilson, thanks a lot for your help. I think this isn't the answer to my question unfortunately. Probably I didn't ask the question correctly. With the GenCodeOnly flag, I can set or receive whether I want to generate code only instead of compile the whole thing. But I need to know if I hit Strg+B (build or generate code) or click the green play button (simulate). Can you help me with that?

Accedi per commentare.

Categorie

Scopri di più su Simulink Coder in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by