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

2 views (last 30 days)
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 Comment
Jens Klimke
Jens Klimke on 9 May 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.

Sign in to comment.

Answers (1)

Wilson A N
Wilson A N on 8 May 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 Comment
Jens Klimke
Jens Klimke on 8 May 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?

Sign in to comment.

Categories

Find more on Simulink Coder in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!