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

6 次查看(过去 30 天)

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?

采纳的回答

MathWorks Support Team
MathWorks Support Team 2024-9-18,0:00
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);

更多回答(0 个)

标签

尚未输入任何标签。

产品

Community Treasure Hunt

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

Start Hunting!

Translated by