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

1 vue (au cours des 30 derniers jours)
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.

Réponse acceptée

John
John le 22 Nov 2016
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 commentaire
amit shelke
amit shelke le 28 Oct 2019
Hello John
The link you have given in above answer is not working (Combining I/O Arguments) Can you provide the updated link

Connectez-vous pour commenter.

Plus de réponses (1)

John
John le 21 Nov 2016
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.

Catégories

En savoir plus sur Simulink Functions dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by