MATLAB SIMULINK 7 - DEVELOPING S-FUNCTIONS Betriebsanweisung Seite 177

  • Herunterladen
  • Zu meinen Handbüchern hinzufügen
  • Drucken
  • Seite
    / 210
  • Inhaltsverzeichnis
  • LESEZEICHEN
  • Bewertet. / 5. Basierend auf Kundenbewertungen
Seitenansicht 176
Writing Wrapper S-Functions
4-11
Using an S-function wrapper to import algorithms in your Simulink model
means that the S-function serves as an interface that calls your C code
algorithmsfrom
mdlOutputs.S-functionwrappershavetheadvantagethatyou
can quickly integrate large stand-alone C code into your model without having
to make changes to the code.
This is an example of a model that includes an S-function wrapper.
Figure 4-1: An Example Model That Includes an S-Function Wrapper
There are two files asso ciatedwithwrapsfcn blo c k, the S-function wrapperan d
the C code that contains the algorithm. This is the S -function wrapper code for
this example, called
wrapsfcn.c:
#define S_FUNCTION_NAME wrapsfcn
#define S_FUNCTION_LEVEL 2
#include “simstruc.h
extern real_T my_alg(real_T u);
/*
* mdlInitializeSizes - initialize the sizes array
*/
static void mdlInitializeSizes(SimStruct *S)
{
ssSetNumSFcnParams( S, 0); /*number of input arguments*/
if (!ssSetNumInputPorts(S, 1)) return;
ssSetInputPortWidth(S, 0, 1);
ssSetInputPortDirectFeedThrough(S, 0, 1);
if (!ssSetNumOutputPorts(S,1)) return;
ssSetOutputPortWidth(S, 0, 1);
ssSetNumSampleTimes( S, 1);
}
Declare my_alg as
extern.
Seitenansicht 176
1 2 ... 172 173 174 175 176 177 178 179 180 181 182 ... 209 210

Kommentare zu diesen Handbüchern

Keine Kommentare