- Go to the Configuration Parameters for the the model
- Go to the Code Generation pane
- Change the Language option to "C++"
- Go the the Code Generation > Interface pane
- Make sure Code Interface > Code interface packaging is set to "C++ class"
Simulink code interface to external C++ application
1 次查看(过去 30 天)
显示 更早的评论
I have a fairly complex Simulink model with multiple referenced models that I am trying to interface with external C++ code. I am using 2014a and generating code using Simulink Coder. Below are two important requirements I would like to satisfy while doing this:
- Have the ability to create multiple instances of the model in my external C++ code
- Have the ability to overwrite data that is input to the model and have it reflected to the external application.
Given these requirements, at the top level what is the best method to interface to external IO, datastores or IO ports?
From my understanding using global datastores (or Simulink.Signal objects) and by specifying the appropriate storage class I may be able to satisfy 2 above, but in doing so I would have to specify signal names and this would not allow me to satisfy 1.
If I use IO port blocks at top level, I may be able to satisfy 1 but not 2.
0 个评论
采纳的回答
Jon Boerner
2014-10-20
Hi Anup,
I think that the exact behavior you are looking for may be limited to the Embedded Coder product.
For Simulink Coder, here is what you can do.
Now if you generate code you should see that you have a class with a private member modelname_P. You could create as many instances of the model as you wanted, and there would be no interaction between them. Using this member you could modify the parameters inside of it (such as the value for a Gain block, or the value of a constant block), if it was not private.
Having Embedded Coder and using the Embedded Coder System Target File "ert.tlc" allows you to modify that property to be public, and edit it exactly as you have mentioned.
You could use storage classes as you mentioned to make the parameters accessible, but they would turn into global variables that would be used by multiple instances of the model, meaning you could not make the models independent.
I suppose if everything was guaranteed to be single-threaded, you could make the parameters global and change their values before interacting with each model, but this would be fragile. For example, if you had a gain G that you wanted to update and made global, and had different values for different models (G1, G2, and so on) you could do:
G = G1
Initialize model 1
G = G2
Initialize model 2
while(1)
G = G1
model 1 step
G = G2
model 2 step
end
It is not a very good solution though. Really, the way to go is with Embedded Coder.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Deployment, Integration, and Supported Hardware 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!