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

2 ビュー (過去 30 日間)
Jens Klimke
Jens Klimke 2017 年 5 月 3 日
コメント済み: Jens Klimke 2017 年 5 月 9 日
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 Center および File ExchangeSimulink Coder についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by