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

2 次查看(过去 30 天)
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 个评论
Jens Klimke
Jens Klimke 2017-5-9
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.

请先登录,再进行评论。

回答(1 个)

Wilson A N
Wilson A N 2017-5-8
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 个评论
Jens Klimke
Jens Klimke 2017-5-8
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?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Simulink Coder 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by