EasyLink
EasyLink is a C++ software development kit for developing blocks for SIMULINK (S-functions)
/Users/guillaume.laurent/Documents/Prog/easylinkEigen/easylink/sfunSizeChange.cpp
1 /*
2  * C++ S-function that changes the size of an output according to the
3  * value of a parameter.
4  *
5  * y = [ u u u ... u ]'
6  *
7  * To compile this C++ S-function, enter the following command in MATLAB:
8  *
9  * >>make sfunSizeChange.cpp
10  *
11  * Then open the file "testSizeChange.mdl/slx" and start the simulation.
12  */
13 
14 //------------------------------------------------------------------------------
15 
16 #define S_FUNCTION_NAME sfunSizeChange
17 
18 #include "EasyLink.h"
19 
20 //------------------------------------------------------------------------------
21 
22 class Block : public BaseBlock {
23 public:
24 
25  static void checkParametersSizes() {
27  assertParameterPort(0, false, 1, 1, mxINT32_CLASS);
28  }
29 
30  static void initializeInputPortSizes() {
32  setInputPort(0, 1, 1, SS_DOUBLE);
33  }
34 
35  static void initializeOutputPortSizes() {
37  int nRows = getParameterScalar<int>(0);
38  setOutputPort(0, 1, nRows, SS_DOUBLE);
39  }
40 
41  void outputs() {
42  double in = getInputDouble(0);
43  Array<double> out = getOutputArray<double>(0);
44 
45  out.init(in);
46  }
47 
48 };
49 
50 //------------------------------------------------------------------------------
51 
52 #include "sfunDefinitions.h"
53 
54 //------------------------------------------------------------------------------
static void setInputPortsCount(int portsCount)
Definition: BaseBlock.h:104
static void setOutputPortsCount(int portsCount)
Definition: BaseBlock.h:152
void outputs()
Definition: BaseBlock.h:340
static void setInputPort(int port, int nRows, int nCols, DTypeId type=SS_DOUBLE, bool directFeedThrough=true)
Definition: BaseBlock.h:116
static void initializeInputPortSizes()
Definition: BaseBlock.h:145
static void assertParameterPort(int port, bool tunable, int nRows, int nCols, mxClassID type=mxDOUBLE_CLASS, mxComplexity complexFlag=mxREAL)
Definition: BaseBlock.h:57
static void checkParametersSizes()
Definition: BaseBlock.h:97
void init(_Scalar x=0)
Definition: Array.h:300
static void initializeOutputPortSizes()
Definition: BaseBlock.h:189
static double getInputDouble(int port)
Definition: BaseBlock.h:399
static void assertParameterPortsCount(int portsCount)
Definition: BaseBlock.h:42
static void setOutputPort(int port, int nRows, int nCols, DTypeId type=SS_DOUBLE)
Definition: BaseBlock.h:164

Copyright (c) 2014 FEMTO-ST / ENSMM / UFC / UTBM, Besançon, France. Generated by Doxygen.