simulink tlc如何通过tlc写数据入文件

Target Language Compiler Directives

一个sfunction的tlc的基本结构如下:

%% Copyright 1990-2009 The MathWorks, Inc.

%implements "tt1" "C"

%function BlockInstanceSetup (block, system) void
    
%endfunction

%% Function: Outputs ===========================================================
%%
%function Outputs(block, system) Output
       
    
    
   

%endfunction

%% [EOF]
  1. 快速入门

设计sfunction时,如果需要代码的到其他c文件下面,而不是自己block所在的c文件,只要用openfile、closefile,举例:

%% Copyright 1990-2009 The MathWorks, Inc.

%implements "tt1" "C"

%function BlockInstanceSetup (block, system) void
    
%endfunction

%% Function: Outputs ===========================================================
%%
%function Outputs(block, system) Output
       
    %openfile srcFile = "init111.c"
        "hello word"
   
    %closefile srcFile
    
   

%endfunction

%% [EOF]

生成代码时,会自动生成名为 init111.c的c文件,并且里面自动写入“hello word”。

2.如果需要在c文件中追加数据而不是覆盖,

语法为:%openfile "c文件名", "a",举例:

%% Copyright 1990-2009 The MathWorks, Inc.

%implements "tt1" "C"

%function BlockInstanceSetup (block, system) void
    
%endfunction

%% Function: Outputs ===========================================================
%%
%function Outputs(block, system) Output
       
    %openfile srcFile = "init111.c","a"
        "hello word333"
   
    %closefile srcFile
    
   

%endfunction

%% [EOF]

如果这个模型只有1个sfunction,那么它生成代码时,每次都会覆盖原文件,而不是追加,里面的字符串就是只有“hello word333”.

如果这个模型只有2个sfunction及以上的sfunction,那么它生成代码时,就会在后面追加数据,有多少个sfunction,init111.c中就会有多少行"helll word333"。

如果单独把下面的tlc单独拎出来,例如保存为test.tlc,在MATLAB命令行调试,并执行:tlc test.tlc,就会直接在后面追加数据:

 %openfile srcFile = "init111.c","a"
        "hello word333"
   
%closefile srcFile

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值