Can a bus be an IN/OUT variable with partial assignment in the resultant generated code

3 ビュー (過去 30 日間)
How do you make the Simulink generated C Code update a single item from a bus without re-assigning the whole bus?
I have a model which takes in a bus with many elements and updates a single entry in the bus which is then output. The output is routed to the next model block for additional computations.
I am trying to compile this atomic model into a stand-alone ERT library. I setup the input and output parameters to be pass-by-reference but can't find anything that would let the generator treat the input and output variables as one.
When the generated *_step function ends, it assigns all of the output entries to the input values which is essentially:
(*pParam) = (*pParam);
I am trying to get Matlab to write-back the computed value into the input bus for it to be sent on its merry way.

採用された回答

John
John 2016 年 11 月 22 日
The model has to be setup in 3 places in order to ensure that a bus structure is treated as a pass-through element.
  1. Ensure that the inport is set to NOT "Output as nonvirtual bus"
  2. Manually configure model interface per Combining I/O Arguments to have the outport to be combined with the inport as pointer arguments.
  3. Add a signal conversion block from virtual to nonvirtual before the bus assignment block.
This will create efficient C code where the C structure is passed in as a pointer and then modified without making any extra copies of the input bus structure.
  1 件のコメント
amit shelke
amit shelke 2019 年 10 月 28 日
Hello John
The link you have given in above answer is not working (Combining I/O Arguments) Can you provide the updated link

サインインしてコメントする。

その他の回答 (1 件)

John
John 2016 年 11 月 21 日
Instead of using a bus input, if I use a named data store and data store read/write blocks, the generated code will take in the data store reference as part of the model parameters (as a pointer) and only update the specific entries listed in the data store write block.
While this is good for the C code that is generated, this makes the block design at the next level up completely obfuscated where the referenced model has no inputs or outputs.

カテゴリ

Help Center および File ExchangeData Types についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by