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

1 次查看(过去 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 个)

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 CenterFile Exchange 中查找有关 Simulink Functions 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by