SFunctions and Object Handles

7 visualizaciones (últimos 30 días)
josn
josn el 27 de En. de 2011
Hello all!
I've recently discovered two new Matlab features that I'm trying to explore: Object Oriented Programming and custom Simulink blocks with S-Functions.
My question is simple, is it possible to pass an object handle through a s-function block Output/Input ports? Or is the Simulink data types limited to data handling only (e.g. no handles).
Example: Create a serial port object inside an s-fcn (InitializeConditions) and place the serial port handle in the block.OutputPort (Outputs). Is this possible?
Thanks a lot in advance! Cheers

Respuestas (2)

MarkB
MarkB el 4 de Feb. de 2011
Unfortunately, I'm pretty sure that this doesn't work. The main obstacles are:
  1. If the object class is something that you have created, none of the other Simulink blocks know how to handle it, so you won't be able to connect the outport's signal to anything. The S-function API doesn't have a "handle" or "pointer" type that you can assign as a port data type. There are clever work-arounds along the lines of using big integer types that "happen to have addresses" stored in them, but relative sizes of integers versus pointers varies from machine-to-machine and isn't portable.
  2. Passing a handle on a signal line especially problematic (this same point applies to passing pointers around in plain C) because it violates a lot of the basic design of Simulink. Providing a handle through an outport allows the blocks that receive the signal to essentially "push data back upstream" which is really problematic. In particular, if the signal line with the handle is branched and connects to two downstream blocks, whichever one executes first could modify the upstream object because it has its handle before the second one has a chance to read the upstream block's original output. This means that the block sorted order has secondary side-effects that Simulink can't anticipate and can lead to all sorts of bugs.
  1 comentario
Erwin Torreao Dassen
Erwin Torreao Dassen el 15 de En. de 2013
I can see you point. In my case, I'm trying something else. I want to push block execution to a wrapper object so that I can work with states of more general data types (instead of only dvectors). Could you perhaps comment on this question of mine?
Kind regards,
Erwin

Iniciar sesión para comentar.


Sebastian
Sebastian el 27 de En. de 2011
Although I never tried it with a handle to an object, I think this should work. I tried passing a figure handle from one block to another. Handles in MATLAB are numbers of data type double. So if you might need to make sure that your S-function port is of type double.

Categorías

Más información sobre Simulink Coder en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by