I found that it creates a double version of the OutputFncSpec field. I have no idea why, if you can help me understand. Thank you
S-Function: Error in generating the interface to Simulink
1 次查看(过去 30 天)
显示 更早的评论
Hello everyone.
I want to learn how to generate the S-function, but when I try to generate it with Legacy code in a simple example, MATLAB gives me an error that I can't figure out.
<This is the .C code:>
#include "Op_Mult.h"
void Op_Mult(short u1, short u2, int *y1)
{
*y1 = (int32_T)(u1 * u2);
}
<This is the .H code:>
#ifndef _H_OP_MULT_
#define _H_OP_MULT_
#include "rtwtypes_mex.h"
void Op_Mult(short u1, short u2, int *y1);
#endif
<This is the .m code:>
clear;
clc;
% mex setup
% mex -setup
% Legacy Code: Integrate C/C++ code
% Initialize legacy code
def=legacy_code('initialize');
% Define the name of the S-Function
def.SFunctionName='fc_Op_Mult';
% Define S-Function interface
def.OutputFncSpec='void Op_Mult(short u1, short u2, int y1[1])';
% Define the name of the .c
def.SourceFiles={'Op_Mult.c'};
% Define the name of the .h
def.HeaderFiles={'Op_Mult.h'};
% Simulate the model in accelerated mode
% legacy_code('rtwmakecfg_generate', def);
% Generate the C code for the S-Function
legacy_code('sfcn_cmex_generate', def);
% Compile S-Function
legacy_code('compile', def);
% Generating Masked S-Function Blocks
legacy_code('slblock_generate', def);
<This is the error:>
Error in legacy_code (line 103)
[varargout{1:nargout}] = legacycode.LCT.legacyCodeImpl(action, varargin{1:end});
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in Op_Mult (line 27)
legacy_code('sfcn_cmex_generate', def);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
If I comment on this line: def.OutputFncSpec='void Op_Mult(short u1, short u2, int y1[1])'; there are no errors, but the Simulink interface has no inputs and outputs.
Could you help me? I have no idea what to do.
Thanks in advance.
Kind regards.
采纳的回答
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!