- 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
1 view (last 30 days)
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
MarkB on 4 Feb 2011
Unfortunately, I'm pretty sure that this doesn't work. The main obstacles are:
Sebastian on 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.