필터 지우기
필터 지우기

Multiple outputs using Legacy Toolbox

조회 수: 5 (최근 30일)
Pierre-Olivier Desrosiers
Pierre-Olivier Desrosiers 2022년 8월 9일
댓글: Sabarish 2024년 5월 30일
Hi, i'm currently working on a project and I have to create a s-function written in C language. I have multiple outputs (V, m, h & fm) and multiple inputs(q1, q2, qe & qo). Here's my main file:
#include "Reservoir.h"
#include <math.h>
double Reservoir(double q1,
double q2,
double qe,
double qo,
double *V,
double *m,
double *h,
double *fm)
{
*V = q1 + q2 + qe - qo;
*m = 1875.0 * q1 + 1667.0 * q2 + 1000.0 * qe - 1468.48 * qo;
*h = sqrt(*V + 1) - 1;
*fm = ((3000.0) * (1 - 1000.0)) / ((3000.0 - 1000.0) * (*m/*V))
}
And here's my header file :
#ifndef RESERVOIR_H_INCLUDED
#define RESERVOIR_H_INCLUDED
double Reservoir(double q1, double q2, double qe, double qo, double *V, double *m, double *h, double *fm);
#endif // RESERVOIR_H_INCLUDED
I'M also working with Legacy Toolbox to generate a tlc file and the s-function. I'm using these lines to generate the s-function :
def = legacy_code('initialize')
def.SFunctionName = 'S_function1'
def.OutputFcnSpec = 'Reservoir(double q1, double q2, double qe, double qo, double *V, double *m, double *h, double *fm)'
def.HeaderFiles = {'Reservoir.h'}
def.SourceFiles = {'main.c'}
legacy_code('sfcn_cmex_generate', def)
When i execute the last line, i receive this error :
Error using legacycode.LCT.legacyCodeImpl
Unrecognized elements in the function specification:
--> Reservoir(double q1, double q2, double qe, double qo, double *V, double *m, double *h, double *fm)
Error in legacy_code (line 103)
[varargout{1:nargout}] = legacycode.LCT.legacyCodeImpl(action, varargin{1:end});
Thus, I was wondering what i've done wrong ? Thanks for your help.
  댓글 수: 2
Jeremy
Jeremy 2023년 3월 31일
running into a similar issue. unsure if the fix will be the same as I am incorporating a struct in the args as a simulink.bus obj, but legacy tool returns a successful import of that. Commenting in hope someone returns to this question.
Sabarish
Sabarish 2024년 5월 30일
Try using this and see Reservoir(double u1, double u2, double u3, double u4, double u5, double u6, double u7, double u8); I met this isuue too. The reason is that the input parameters of function must be named to u1, u2 etc.Similar to output parameters, they must be named to y1. Hope this helps. Thanks.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Simulink Coder에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by