How to use Global Objects in Matlab S-Function
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi! Im new with s-functions and I need to use an object among several functions on a Matlab S-Function. The object is used as a library and it is needed to set the conection with a server, get data from it in each loop and close it at the end of simulation. The use of the object its something like this:
ClassX ObjectX;
[Handle clientID]=ObjectX.setConnection(...);
while(coonection)
[result]=ObjectX.getPosition(Handle ClientID,...);
[result]=ObjectX.getAngle(Handle ClientID,...);
...
end
[result]=ObjectX.CloseConnection(...);
Its not convinient to instance and close the comunication in every loop. So I whant to create the object and set the conection on "function setup(block)", update data on "function Update(block)" and close the conection on "function Terminate(block)" but to do this I need to share the "ObjectX" an "clientID" among the functions.
It would also be useful to share the object instance among all the S-Function blocks used since it does not make sense to initiate a connection for each block.
I hope you can help me.
0 commentaires
Réponses (1)
Kaustubha Govind
le 4 Avr 2014
Modifié(e) : Kaustubha Govind
le 4 Avr 2014
Please see if my answer here helps: http://www.mathworks.com/matlabcentral/answers/27902-working-with-matlab-classes-in-the-level-2-matlab-s-functions
You could potentially search the model for all S-function Blocks of the same kind (you could perhaps create a mask over these blocks and set a MaskType to identify them), and see if any one of them already owns a UserData, and create a new instance if one doesn't already exist. (Note that this is not supported workflow - ideally, global data needs to be stored on Data Store Memory blocks)
You may also have the model be responsible for creating the object in the base workspace (via Model Callbacks), and have all your S-functions look there for the object.
0 commentaires
Voir également
Catégories
En savoir plus sur Simulink Functions dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!