TLC of M-S Function or workaround

4 次查看(过去 30 天)
Thomas
Thomas 2012-10-12
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