How to call API in simulink?

3 ビュー (過去 30 日間)
sneha bharadwaj
sneha bharadwaj 2017 年 1 月 11 日
編集済み: Shaunak 2025 年 6 月 13 日
I have a c code as follows # include "dfg_uu_file.h" extern double dfg_uu_getmaxsize_a(void)
how to call this using an API in simulink? given that a=[1 2]

回答 (1 件)

Shaunak
Shaunak 2025 年 6 月 13 日
編集済み: Shaunak 2025 年 6 月 13 日
It is my understanding that you want to call a C function from within Simulink using the S-Function Builder block, where your C code includes a header file and returns a double.
To achieve this, follow these steps:
  • Add an S-Function Builder block to your Simulink model (found under User-Defined Functions in the Simulink Library Browser).
  • Double-click the block to open the configuration editor:
  1. Under the "Inputs" tab, no input is needed since your function has no arguments.
  2. Under the "Outputs" tab, define one output port, e.g., y, with:
- Port Name: y
- Port Width: 1
- Data Type: double
  • Go to the "Data Properties" tab and add the line mentioned below to the "Include" section:
#include "dfg_uu_file.h"
  • Under the "Outputs" section, add the function call:
y[0] = dfg_uu_getmaxsize_a();
  • Click "Build" to generate the S-function.
  • Use the generated block in your model—this will now call your external C function during simulation.
For more information, kindly refer to the following MathWorks documentation on the S-function Builder Block:
Hope this helps!

カテゴリ

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