0

is it possible to use bus datatypes for m-file s-function blocks in Simulink?

I haven't found any examples for this in the matlab documentation or anywhere online.

For s-Functions written in C the API looks somewhat like this

  DTypeId dataTypeIdReg;
  ssRegisterTypeFromNamedObject(S, "myBusObject", &dataTypeIdReg);
  if(dataTypeIdReg == INVALID_DTYPE_ID) return;
  ssSetInputPortDataType(S,0, dataTypeIdReg);

now I'd like to access the same data type (a structure in C, a bus object in Matlab) from within my *.m source code. Do you know of any example or tutorial about this? As you might notice I'm not too familiar with the Simulink environment...

I also found different information on whether this is even possible

Q: do level 2 s-functions support bus objects?

rava
  • 183
  • 12

1 Answers1

1

Actually, if you scroll down the page on your "answer 1", you'll see a line:

enter image description here

So both pages are in agreement: you can't use bus objects with MATLAB S-Functions. If you want to use bus objects with S-functions, it has to be a C-Mex S-function.

For some examples, see this blog post or this MATLAB Answer, or even this one.

am304
  • 13,758
  • 2
  • 22
  • 40
  • Whoops. Didn't see this. But interestingly enough, if you have a look into the documentation about "arrays of buses" these guys are gonna tell you that Matlab Functions (level 1) do support arrays of buses. So this is what you might want to look for if you're trying to avoid coding in C – rava Dec 18 '14 at 13:20
  • Actually, I don't believe arrays of busses are supported by any type of S-Function (see http://uk.mathworks.com/help/simulink/ug/arrays-of-buses-in-models.html). Level-1 S-Functions are really old technology and are only supported for historical reasons, but I can see them being phased out soon. There's certainly no new development effort into L1 S-functions as far as I can tell. – am304 Dec 18 '14 at 14:07