Guy on Simulink

Simulink & Model-Based Design

使用Simu金宝applink函数模拟硬件服务

本周,我想介绍另一个功能,该功能与在itialize Function,,,,重置功能and终止功能blocks.

在R2014b,金宝appSimulink函数被介绍了。在this post,,,,we highlighted how Simulink Functions can be used to create an导出功能模型。在这种情况下,将Simulink函数金宝app放置在模型内。在仿真中,您可以参考模型并使用功能呼叫者块调用功能。

金宝appSimulink函数用作功能库

然后,您可以为函数库模型生成代码,并以任何您想要的方式从手写代码调用这些函数。

相反

One thing we did not mention at that time, is that it is possible to use Simulink Functions and the Function Caller block in completely opposite way, where the referenced model has a Function Caller block, calling Simulink Functions present in the top model.

模拟线束

为什么有人要这样做?简而言之,答案是模拟无法直接可用于仿真的自定义代码。让我们看看这是如何工作的。

Using the Function Caller block to call external code

如果我们在上面的图片模型中为子CodegenModel.slx生成代码,则代码将看起来像:

生成的代码

By default, this code would not build, since the compiler would not know where to find the function时间段。但是,如果正确配置模型,则功能时间段can come from anywhere you want. For example, it could be in a dynamic library against which you will link to on your embedded target. For this example, imagine that there is a时间段这项服务可用时间段。cfile:

自定义代码

在the model configuration, I specify that this file should be included in the build process:

自定义代码配置

这使我能够生成一个调用我的自定义的可执行文件时间段。c执行。

Conclusion

总而言之,这个想法是创建模拟外部软件行为的模拟函数。金宝app您可以构建一个模拟模型,该模型引用您的代码生成模型,并且会看到Simulink函数。金宝app当时间来生成儿童模型的代码时,它将不知道Simulink函数存在,而是会根据您指定的任何外部代码链接。金宝app

It is important to note that this technique is just one way to include custom code in the code generated from Simulink.

如果主机上有自定义代码,我建议您使用S功能在模拟和代码生成中包装和重复使用相同的自定义代码。

然而如果代码不可用,例如cause it is available as an OS service on the target embedded processor, this approach can be interesting.

下一步是什么?

现在我们介绍了导出功能模型, 这国家读者和作家块,以及这种使用Simulink函数的方式,我相信金宝app我们有所有的作品来说明一个现实的例子,说明我们如何看待在itialize Function,,,,重置功能and终止功能下周使用的块。

|

댓글

댓글을남기려면링크를클릭하여하여계정계정하거나계정만드십시오만드십시오만드십시오。