How can I define an S-Function Outport as bus typed?

2 views (last 30 days)

I want to create an S-Function with a bus-typed Outport. The name of the bus type shall be provided via mask parameter as shown below.

In the current implementation, I am using the code below to assign the mask parameter value to the bus type information

    char* busName;

    /* Bus object name is passed in as a parameter */
    ssGetSFcnParamName(S, 1, &busName);
    ssSetBusOutputObjectName(S, 1, busName);

    /* Output nonvirtual bus */
    ssSetBusOutputAsStruct(S, 1, true);
This however results in the error below
Variable or object 'BusName' in scope from 'ModelName/BlockName/S_Function' is not a Simulink.DataType object
The error refers to 'BusName' which is actually the name of the mask parameter rather than its value. Is it possible to define the Outport's bus type via mask parameter?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 18 Sep 2024
Before implementing the desired behavior, please consider these limitations
  1. The example block uses a char array, which is not allowed. For a list of supported types, please see this documentation link: https://www.mathworks.com/help/simulink/ug/data-types-supported-by-simulink.html
  2. Instead of character arrays, Simulink supports utilization of Strings, but not if the target block is an S-Function: https://www.mathworks.com/help/simulink/ug/simulink-strings.html#mw_588e9a27-6f3e-48f4-ad7a-4c66f6b0526c
By following the instructions below, you can define the bus type via block mask parameter
  1. create a Simulink.Bus object with the desired name, e.g. "outputBusName"
  2. inside the block mask, add a DataTypeStr element
  3. open the DataTypeStr's Type options via the pencil icon,
  4. navigate to User-defined tab and select "Bus"
  5. navigate to the mask and add the bus name to the new parameter field as "Bus: outputBusName"
  6. adjust the implementation your S-Function as follows
    //write the value of the DataTypeStr to busname     ssGetSFcnParamName(S, 1, &busName);      ssSetBusOutputObjectName(S, 1, busName);          // register bus name as valid data type     DTypeId dataTypeIdReg;      ssRegisterTypeFromParameter(S, 1, &dataTypeIdReg);          // set data type     ssSetOutputPortDataType(S, 1, dataTypeIdReg);     ssSetBusOutputAsStruct(S, 1, true);

More Answers (0)

Tags

No tags entered yet.

Products

Community Treasure Hunt

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

Start Hunting!