- 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!