Effacer les filtres
Effacer les filtres

Multiple outputs using Legacy Toolbox

5 vues (au cours des 30 derniers jours)
Pierre-Olivier Desrosiers
Pierre-Olivier Desrosiers le 9 Août 2022
Commenté : Sabarish le 30 Mai 2024
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 commentaires
Jeremy
Jeremy le 31 Mar 2023
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 le 30 Mai 2024
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.

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Simulink Coder dans Help Center et File Exchange

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by