使用交叉发布工作流集成生成的代码
这个例子展示了如何通过创建一个交叉发布的循环软件(SIL)块并将该块合并到集成模型中来重用以前生成的代码。有关工作流的详细信息,请参见交叉发布代码集成.
从模型生成代码
在交叉发布的代码集成工作流中,您从先前生成的代码中创建了一个软件在循环(SIL)或处理器在循环(PIL)块。
本例使用当前版本生成的代码。
模型=“rtwdemo_crossrelease_counter”;load_system(model) set_param(model, 0)“SimulationCommand”,“更新”);open_system(模型)rtwbuild(模型);
开始模型的构建过程:rtwdemo_crossrelease_counter成功完成模型的代码生成:rtwdemo_crossrelease_counter
标识包含生成代码的构建文件夹。
buildFolder = RTW.getBuildDir(model).BuildDirectory;
标识包含与生成的代码相关联的共享实用程序的代码的文件夹。
previousSharedCodeFolder = RTW.getBuildDir(model).SharedUtilsTgtDir;
要重用以前版本中生成的代码:
在模拟选项卡,在文件部分中,选择保存>以前版本.
在另存为类型字段,指定版本和模型类型。
点击保存.
使用以前的版本打开保存的模型,然后生成代码。
设置的值
buildFolder
到上一个版本中生成的代码的位置。设置的值
previousSharedCodeFolder
到上一个版本中生成的共享实用程序的位置。
管理共享代码
将生成的共享源代码文件添加到集成模型使用的存储库文件夹中。
sharedCodeRepo =“SharedCodeRepo”;mkdir (sharedCodeRepo);sharedCodeUpdate (previousSharedCodeFolder sharedCodeRepo,“互动”、假);
从slprj/ert/_sharedutils复制到SharedCodeRepo/R2019b的文件如下:
导入代码
打开集成模型。
integrationModel =“rtwdemo_crossrelease_integration”;close_system (integrationModel 0);load_system (integrationModel);
修改Simulink配金宝app置集,使其引用现有的共享代码库。
cs = getActiveConfigSet(integrationModel);set_param (cs,“ExistingSharedCode”, fullfile(pwd, sharedCodeRepo));
创建交叉释放SIL块。
blockHandle = crossReleaseImport(buildFolder, cs,“SimulationMode”,“银”);
##启动组件的导入过程:rtwdemo_crossrelease_counter_R2019b
将交叉释放SIL块集成到集成模型中
要用交叉发布块替换集成模型中的块,请使用pil_block_replace
.该函数保留块大小、线路连接和优先级。
srcBlock = getfullname(blockHandle);dstBlock = [integrationModel,]' / ',“计数器”];pil_block_replace(srcBlock, dstBlock)
成功交换以下块:untitled/rtwdemo_crossrelease_counter_R2019b_sil rtwdemo_crossrelease_integration/Counter
模拟集成模型
运行集成模型的模拟。
sim (integrationModel)
###准备启动SIL块模拟:rtwdemo_crossrelease_integration/Counter…rtw.connectivity.HostLauncher:已启动可执行文件,主机进程标识为10496 rtw.connectivity.HostLauncher:已停止可执行文件,主机进程标识为10496 ###停止组件:rtwdemo_crossrelease_counter_R2019b_sil模拟
调整参数
交叉发布SIL块的源模型引用了两个可调参数,由Simulink控制。金宝app基本工作区中的参数对象。使用这些参数可以修改SIL模拟的行为。
countUpper。值= 30;countLower。Value = 20;youout_retuned = sim(integrationModel,“ReturnWorkspaceOutputs”,“上”);
###准备启动SIL块模拟:rtwdemo_crossrelease_integration/Counter…rtw.connectivity.HostLauncher:已启动可执行文件,主机进程标识为10538 rtw.connectivity.HostLauncher:已停止可执行文件,主机进程标识为10538 ###停止组件的SIL模拟:rtwdemo_crossrelease_counter_R2019b_sil
为集成模型中的信号配置存储类
配置:
集成模型中的信号名称与导入代码中使用的名称相匹配。
补充存储类。
在这种情况下,蜱虫
输入和数
输出是通过ImportedExtern
导入代码中的存储类。如果集成模型中连接到交叉释放块的输入和输出端口的信号的存储类为ExportedGlobal
时,集成模型必须提供变量的定义。
如果信号名称不匹配,集成模型将生成额外的代码,在集成模型实现的信号和导入代码实现的信号之间复制数据。
hLines = get_param(dstBlock,“LineHandles”);集(hLines.Inport (1),“名字”,“滴答”,“StorageClass”,“ExportedGlobal”);集(hLines.Outport (1),“名字”,“数”,“StorageClass”,“ExportedGlobal”);
在“集成模型”中配置参数和数据存储内存的存储类别
参数和数据存储通过ImportedExtern
导入代码中的存储类。如果已配置参数和使用的数据存储ExportedGlobal
存储类时,集成模型必须提供变量的定义。
resetSignal.CoderInfo.StorageClass =“ExportedGlobal”;countLower.CoderInfo.StorageClass =“ExportedGlobal”;countUpper.CoderInfo.StorageClass =“ExportedGlobal”;
从集成模型生成代码
一旦所需的共享代码在共享代码存储库中,删除之前生成的共享实用程序文件夹。
如果isfolder (RTW.getBuildDir (integrationModel) .SharedUtilsTgtDir)删除文件夹(RTW.getBuildDir .SharedUtilsTgtDir (integrationModel),“年代”);结束
删除不影响代码生成的作用域和连接线。
scopeBlock = [integrationModel,' / ',“范围”];hScopeLines = get_param(scopeBlock,“LineHandles”);hScopeLine = hscopelines . import (1);断言(strcmp (get (hScopeLine,“SegmentType”),“分支”));delete_line (hScopeLine);delete_block (scopeBlock);
生成的代码。
rtwbuild (integrationModel);
开始模型的构建过程:rtwdemo_crossrelease_integration成功完成模型的代码生成:rtwdemo_crossrelease_integration
检查对导入代码的调用
要检查集成模型代码中的交叉发布块代码,请使用rtwtrace
实用程序。
rtwtrace (dstBlock);
从集成模型生成的测试代码
运行集成模型的顶层模型软件在环(SIL)仿真。模拟运行从集成模型生成的代码,集成模型调用导入的代码。
在工作区中记录模拟输出。
set_param (integrationModel“SimulationMode”,“software-in-the-loop (sil)”);youout_sil = sim(integrationModel,“ReturnWorkspaceOutputs”,“上”);情节(yout_SIL.yout {1} . values);
###开始模型的构建过程:rtwdemo_crossrelease_integration成功完成模型的构建过程:rtwdemo_crossrelease_integration准备开始SIL模拟…使用“gcc”构建。MEX完成成功。###用SIL文件更新代码生成报告…##停止组件的SIL模拟:rtwdemo_crossrelease_integration
比较模拟输出
比较只有导入代码在SIL模式下运行的仿真输出与集成模型作为顶模型在SIL模式下运行的仿真输出。
马克斯(abs (yout_SIL.yout {1} . values。Data - youout_retuned .yout{1}.Values.Data))
Ans = uint8 0