Filter löschen
Filter löschen

Legacy Code Tool Not Running

7 Ansichten (letzte 30 Tage)
Marc Easton
Marc Easton am 18 Dez. 2018
Bearbeitet: Jonas Leibbrand am 2 Sep. 2020
I'm trying to use the Legacy Code Tool to generate an S Function and a block for Simulink to run auto-generated code from the MATLAB Coder. This is a process I've used before on similar code with no issues. When I try to run it, the Legacy Code Tool begins to run and then does not begin to compile. I get no outputs and no repsonse from it. It's as if it has entered into an infinite while loop. When I Ctrl+C, I get this error:
Operation terminated by user during legacycode.lct.spec.Function/parse
In legacycode.lct.spec.Function
In legacycode.lct.LCTSpecInfo/extractAllInfo
In legacycode.lct.LCTSpecInfo/extractAllInfo
In legacycode.lct.LCTSpecInfo/extractAllInfo>@(o,n,f)parseFun(n)
In legacycode.lct.LCTSpecInfo/forEachFunction
In legacycode.lct.LCTSpecInfo/extractAllInfo
In legacycode.lct.gen.SFunEmitter/emit
In legacycode.lct.gen.SFunEmitter.emitFile
In legacycode.LCT/generatesfcn
In legacycode.LCT.legacyCodeImpl
In legacy_code (line 101)
[varargout{1:nargout}] = legacycode.LCT.legacyCodeImpl(action, varargin{1:end});
In set_up_legacy_tool_func (line 50)
legacy_code('generate_for_sim',def)
The exact code I'm trying to generate into an S Function is proprietary so I can't post the whole thing here, but I can post the code I'm using to call the LCT.
%% Source Library
% Directory for Matlab Coder generated C files:
codedir = 'C:\Users\user\Desktop\func\codegen\lib\func_computer\';
%% Initialize the legacy code tool:
% Load the simulink bus structures file
load('func_Sim_Bus_Struct.mat')
def = legacy_code('initialize');
% Find c files:
list = dir([codedir '*.c']);
def.SourceFiles = {list.name};
% Find header files:
list = dir([codedir '*.h']);
def.HeaderFiles = {list.name};
% Set Include path:
def.IncPaths = {codedir};
def.SrcPaths = {codedir};
% mex function name and output spec:
def.SFunctionName = 'func';
% Define Inputs/Outputs. This should match the structure of the C code function
def.OutputFcnSpec = ['void func_computer(double u1, struct0_T u2[1], ', ...
'struct1_T u3[1], struct2_T u4[1], double y1[1], ', ...
'struct4_T y2[1], struct3_T y3[1], double y4[24], double y5[24], ', ...
'double y6[1]'];
def.InitializeConditionsFcnSpec = 'void func_computer_initialize(void)';
def.TerminateFcnSpec = 'void func_computer_terminate(void)';
% % Generate .c file:
% legacy_code('sfcn_cmex_generate', def)
% % % Compile everything:
% legacy_code('compile', def)
% % Also want to generate a tlc file for using in rapid accelerator mode:
% legacy_code('sfcn_tlc_generate', def);
%% Alternatively, use these commands to directly generate for simulink:
legacy_code('generate_for_sim',def);
legacy_code('slblock_generate',def);
I've tried running the 'sfcn_cmex_generate' option and I run into the same issue. The code doesn't error out, it just runs forever and produces nothing.
I've tried running it in the debugger and stepping through the various functions but the LCT is very complicated and I can't seem to make sense of what's going on.
Does anybody have any insight as to why the Legacy Code Tool would hang up?

Antworten (2)

SAID ELMOTAOUAKKEL
SAID ELMOTAOUAKKEL am 23 Mai 2019
its hard to say without the C code but here's some advice
try to include just the main .c .h not all the .c & .h files
use this command to bring the .c .h files and please note that u should work in the curent folder
% Find c files:
list = dir('*.c');
def.SourceFiles = {list.name};
% Find h files:
list = dir('*.h');
def.HeaderFiles = {list.name};

Jonas Leibbrand
Jonas Leibbrand am 2 Sep. 2020
Bearbeitet: Jonas Leibbrand am 2 Sep. 2020
The closing parenthesis of the function prototype is missing.

Community Treasure Hunt

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

Start Hunting!

Translated by