EasyLink
EasyLink is a C++ software development kit for developing blocks for SIMULINK (S-functions)
/Users/guillaume.laurent/Documents/Prog/easylinkEigen/easylink/sfunOffset.cpp
1 /*
2  * This file illustrates how to construct a simple C++ S-function with
3  * EasyLink. The S-function has one scalar input, one scalar output and one
4  * scalar parameter. The output of the S-function is the sum of its input and
5  * of the parameter,
6  *
7  * y = u + p
8  *
9  * To compile this C++ S-function, enter the following command in MATLAB:
10  *
11  * >>make sfunOffset.cpp
12  *
13  * Then open the file "testOffset.mdl/slx" and start the simulation.
14  */
15 
16 //------------------------------------------------------------------------------
17 
18 #define S_FUNCTION_NAME sfunOffset
19 
20 #include "EasyLink.h"
21 
22 //------------------------------------------------------------------------------
23 
24 class Block : public BaseBlock {
25 public:
26 
27  static void checkParametersSizes() {
29  assertParameterPort(0, true, 1, 1, mxDOUBLE_CLASS);
30  }
31 
32  static void initializeInputPortSizes() {
34  setInputPort(0, 1, 1, SS_DOUBLE);
35  }
36 
37  static void initializeOutputPortSizes() {
39  setOutputPort(0, 1, 1, SS_DOUBLE);
40  }
41 
42  void start() {
43  }
44 
45  void outputs() {
46  double in = getInputDouble(0);
47  double offset = getParameterDouble(0);
48 
49  setOutputDouble(0, in + offset);
50  }
51 
52  void terminate() {
53  }
54 
55 };
56 
57 //------------------------------------------------------------------------------
58 
59 #include "sfunDefinitions.h"
60 
61 //------------------------------------------------------------------------------
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 terminate()
Definition: BaseBlock.h:392
static void initializeOutputPortSizes()
Definition: BaseBlock.h:189
void start()
Definition: BaseBlock.h:327
static void setOutputDouble(int port, double value)
Definition: BaseBlock.h:469
static double getInputDouble(int port)
Definition: BaseBlock.h:399
static double getParameterDouble(int port)
Definition: BaseBlock.h:540
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.