Input/Output parameters of DLL

5 ビュー (過去 30 日間)
Rafael García Pérez
Rafael García Pérez 2022 年 3 月 21 日
回答済み: Raghava S N 2025 年 1 月 9 日
Hello everyone,
I am trying to generate a simple dll file from a simulink model. Basically the model takes an input, multiplies by two and puts it into an output. So I have created a matlab function in simulink such as this:
function y = fcn(u)
y = 2*u;
Now I want to generate the .dll file by using embedded coder. So I select 'Shared library', select the subsystem in simulink and click in embedded coder -> Generate subsystem. As a result I get a lot of files and mainly important the file multiply2.c Looking at the code I can see:
/* Model step function */
void multiply20_step(void)
{
/* Outport: '<Root>/y' incorporates:
* Inport: '<Root>/u'
* MATLAB Function: '<Root>/multiply2'
*/
multiply20_Y.y = 2.0 * multiply20_U.signal1;
}
The .dll file is also generated properly. The thing is that I want to use this .dll in other program and to use it I need to use a function with inputs and ouputs to be able to call the dll. So I am trying to generate the C files and the .dll such that this function is something like this:
int multiply20_step(int)
{
The rest of the code.
}
I want this to be able to call this function with input parameters. I think that it migth have something to do with the Code generation/Interface parameters or maybe with the 'Code Interface' but I wasn't able yet to solve it.
Could someone help me please. Thanks in advance.

回答 (1 件)

Raghava S N
Raghava S N 2025 年 1 月 9 日
Hi,
You may refer to this link for more information about the "model_step" function - https://www.mathworks.com/help/rtw/ref/model_step.html.
By default, the generated "model_step" function provides a void-void interface that does not have arguments. To configure the input arguments for a C step function, use the Code Mappings Editor - C: https://www.mathworks.com/help/rtw/ref/codemappingseditorc.html.
To include parameters in the "model_step" function, you can follow this procedure-
  1. From the Apps tab in the toolstrip, open Embedded coder
  2. In the Embedded Coder toolstrip, click on Code Interface > Default Code Mappings
  3. In the Code Mappings - Component Interface that opens up, click on the Functions tab.
  4. As you will be able to see, the "model_step" function will not be visible, as it has not been generated, yet. So go ahead and click on Build in the Embedded Coder toolstrip.
  5. Now, in the Functions tab of the Component Interface, you will be able to see the definition of "model_step" under the Function Preview column. Double click on the definition.
  6. A dialog box should open up, in which you can configure the generated C function interface. Check the "Configure arguments for Step function prototype" checkbox.
  7. This enables a "Get default" button. Click on it.
  8. Now, the function definition has been modified to include the inputs and outputs as function parameters. Click on "Validate" to verify that no issues arise.
  9. Generate code again, to obtain the modified C function.
Hope this helps!

カテゴリ

Help Center および File ExchangeDeployment, Integration, and Supported Hardware についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by