- 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.
- 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.
SFunctions and Object Handles
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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
0 Kommentare
Antworten (2)
MarkB
am 4 Feb. 2011
Unfortunately, I'm pretty sure that this doesn't work. The main obstacles are:
1 Kommentar
Erwin Torreao Dassen
am 15 Jan. 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
Sebastian
am 27 Jan. 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.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Configure Block Features for MATLAB S-Functions finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!