TLC of M-S Function or workaround

조회 수: 4 (최근 30일)
Thomas
Thomas 2012년 10월 12일
댓글: Or Hirshfeld 2015년 2월 19일
What is the best way to include Matlab-Function in Simulink and make it ready for Code generation?
I wrote some Function in Matlab to Connect Matlab it with a SPS. This Function are Shadowfunction, who use MEX by running in Workspace and CPP by running in Matlab Coder.
Now I like to have the function in Simulink and also ready for coding. I created M-S-Function Level 2, in it I call the Shadowfunction. During simulation, it works fine. But I can not create code from it, by using the Simulink coder. I get following Error:
The corresponding 'mlpiConnectionBlock.tlc' file for the MATLAB S-function 'mlpiConnectionBlock' in block 'MSFunction/mlpiConnectionBlock' must be located in the current working directory, the MATLAB S-function directory 'C:\...\Simulink', or the directory 'C:\...\tlc_c'
I know, TLC files are not trivial. Exist a better way for easy including? If not, can someone help me with the TLC file? The S-Function "mlpiConnectionBlock" has one boolen Input, one uint32 output and one parameter (string).
M-S Function:
function Outputs(block)
%rising edge. Only one time
if (block.Dwork(1).Data == 0) && (logical(block.InputPort(1).Data) == true)
ipaddress = char(block.DialogPrm(1).Data);
block.Dwork(1).Data = mlpiApiConnect(ipaddress);%shadow
elseif (block.Dwork(1).Data ~= 0) && (logical(block.InputPort(1).Data) == false)
%falling edge, only one time
mlpiApiDisconnect(block.Dwork(1).Data); %shadow
block.Dwork(1).Data = uint32(0);
else
% do nothing
end
block.OutputPort(1).Data = block.Dwork(1).Data;
%end Outputs
Shadow-Function example:
function [con] = mlpiApiConnect(ipAddress)
if isempty(coder.target)
% running in MATLAB
con = mlpiApiConnectMex(ipAddress); %call MEX
else
% running in the generated code
con = uint32(0);
ipAddress = [ipAddress 0]; %terminierungszeichen
con = coder.ceval('mlpiApiConnectCoder',ipAddress); %call LIB
end
  댓글 수: 1
Or Hirshfeld
Or Hirshfeld 2015년 2월 19일
did you found any solution because I'm having similar problem, i have level 2 s-function that i wish to run in External mode for windows real time target.

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

답변 (1개)

Kaustubha Govind
Kaustubha Govind 2012년 10월 12일
Since you already have code that is compatible with MATLAB Coder, you can simply call your function using a MATLAB Function block, which automatically supports code-generation as long as you are able to generate standalone code from your code using MATLAB Coder. You don't have to worry about writing an S-function or its TLC file.
  댓글 수: 2
Thomas
Thomas 2012년 10월 31일
But if I like to run the toolbox in non-realtime only in the Simulink-Simulator, I need the Simulink-Coder license. But I like to need the license only for Code generation.
Kaustubha Govind
Kaustubha Govind 2012년 10월 31일
You won't need a Simulink Coder license to run the MATLAB Function block in normal mode simulation. You can verify this by starting a fresh session of MATLAB, run your model in normal mode and see the list of license checked out using:
>> license('inuse')

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by