writing tlc file for level 2 m file s function which accessing guidata

Hello Matlab users, I have written m file s function which takes checkbox selection input and this input signal enables simulink subsystem.When I am trying to generating C code from this model by using RTW it is looking for corresponding tlc file in the current working directory.Please Can anyone share the procedure to write tlc file .the outputs function in sfunction looks like
function outputs
persistent h
if isempty(h)
h = guidata(my_gui);
end
block.OutputPort(1).Data = get(h.MOTOR_auto_reset,'Value');
%endfunction

6 件のコメント

Kaustubha Govind
Kaustubha Govind 2013 年 4 月 30 日
MATLAB GUI's cannot run or be present in the standalone/embedded code environment that the generated code will run on, so you can only write standard ANSI C code in the TLC file, and cannot attempt to access MATLAB GUIs - your code needs to be entirely independent of the MATLAB environment.
sai vasavi
sai vasavi 2013 年 5 月 4 日
Thanks for your reply Kaustubha. I have a quick a question ,is is possible to call matlab funtcions in tlc using FEVAL directive right?If yes,please tell me how can I assign return value of this function to block output signal(LibBlockoutputsignal).
Kaustubha Govind
Kaustubha Govind 2013 年 5 月 6 日
編集済み: Kaustubha Govind 2013 年 5 月 6 日
Yes, but that would make your output be a constant value received from the GUI at the time of code-generation - is this what you want? In that case, simply put your code to invoke the GUI into a helper MATLAB function and call it using FEVAL.
sai vasavi
sai vasavi 2013 年 5 月 7 日
exactly that I want Kaustubha.So i tried in this way like i have put my code in matlab helper function and same function i am calling in outputs function of M file S function.for this I have written tlc file by looking some help provided in matlab.I am getting error when I am generating code for that model by including tlc file .The eroor log is attached below ### Loading TLC function libraries
Error: File: C:\MATLAB\R2007b\rtw\c\tlc\lib\blkiolib.tlc Line: 1001 Column: 10 syntax error ..... ### Initial pass through model to cache user defined code Error: File: C:\MATLAB\R2007b\rtw\c\tlc\mw\commonpass.tlc Line: 186 Column: 63 Attempt to call a non-function value: SLibSetBlockInputSignalIsNotExpr Error: File: C:\MATLAB\R2007b\rtw\c\tlc\mw\commonpass.tlc Line: 186 Column: 43 Values of NULL type cannot be expanded Error: File: C:\MATLAB\R2007b\rtw\c\tlc\mw\commonpass.tlc Line: 197 Column: 45 Attempt to call a non-function value: SLibSetBlockOutputSignalsAreNotExpr ### Real-Time Workshop build procedure for model: 'sample' aborted due to an error. And my tlc looks like %% File : IFM_ULP.tlc %% S-function "IFM_Select". %% Function: Outputs %%
%implements "IFM_Select" "C"
%function Outputs(block, system) Output
%assign y = LibBlockOutputSignal(0,"","",0)
%assign out=FEVAL("IFM_Select_fcn")
%<y>=%<out>
%endfunction
%% [EOF] IFM_Select.tlc .Please help me in resolving this .
Kaustubha Govind
Kaustubha Govind 2013 年 5 月 7 日
Please use the TLC Debugger to see what value is returned to out.
vinothkannan K
vinothkannan K 2013 年 5 月 10 日
編集済み: vinothkannan K 2013 年 5 月 10 日
yeah Kaustubha Govind, we are from same team. Is there any standard format available to write tlc? Any structure for tlc file we wrote like this
%implements "IFM_Select" "C"
%function Outputs(block, system) Output
%assign y = LibBlockOutputSignal(0,"","",0)
%assign out=FEVAL("IFM_Select_fcn")
%<y>=%<out>
%endfunction%%[EOF] IFM_Select.tlc
Please help us in resolving this issue.

サインインしてコメントする。

回答 (1 件)

Kaustubha Govind
Kaustubha Govind 2013 年 5 月 10 日

1 投票

Yes, your TLC code looks right to me, except that you need to add a semicolon to the end of the line "%<y>=%<out>" as required by all C statements:
%implements "IFM_Select" "C"
%function Outputs(block, system) Output
%assign y = LibBlockOutputSignal(0,"","",0)
%assign out=FEVAL("IFM_Select_fcn")
%<y>=%<out>;
%endfunction
%%[EOF] IFM_Select.tlc
Also, note that you appear to be making the assumption that the MATLAB function IFM_Select_fcn returns a scalar value of the same datatype as what the S-function's output port is configured for, so please make sure that is true.

2 件のコメント

Wenjie Shi
Wenjie Shi 2016 年 10 月 19 日
Thanks for your answer, it's easy to be ignored but useful.
Hari Rangarajan
Hari Rangarajan 2021 年 12 月 17 日
Here is some documentation on how to write Level 2-MATLAB S-Functions. The Template section also provides the MATLAB command to open a template TLC file: https://www.mathworks.com/help/simulink/sfg/writing-level-2-matlab-s-functions.html

サインインしてコメントする。

カテゴリ

質問済み:

2013 年 4 月 26 日

コメント済み:

2021 年 12 月 17 日

Community Treasure Hunt

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

Start Hunting!

Translated by