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 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