EasyLink
EasyLink is a C++ software development kit for developing blocks for SIMULINK (S-functions)
/Users/guillaume.laurent/Documents/Prog/easylinkEigen/easylink/sfunInputs.cpp
1 /*
2  * C++ S-function that shows all the different ways to use the input ports.
3  *
4  * To compile this C++ S-function, enter the following command in MATLAB:
5  *
6  * >>make sfunInputs.cpp
7  *
8  * Then open the file "testOnputs.mdl/slx" and start the simulation.
9  */
10 
11 //------------------------------------------------------------------------------
12 
13 #define S_FUNCTION_NAME sfunInputs
14 
15 #include "EasyLink.h"
16 
17 enum inputPortName {
18  IN1, IN2, IN3, IN4, IN5
19 };
20 
21 //------------------------------------------------------------------------------
22 
23 class Block : public BaseBlock {
24 public:
25 
26  static void initializeInputPortSizes() {
28  setInputPort(IN1, 1, 1, SS_DOUBLE);
29  setInputPort(IN2, 3, 1, SS_DOUBLE);
30  setInputPort(IN3, 4, 2, SS_DOUBLE);
31  setInputPort(IN4, -1, 1, SS_DOUBLE);
32  setInputPort(IN5, -1, -1, SS_DOUBLE);
33  }
34 
35  void start() {
36  printf("Starting the s-function for inputs testing...\n");
37  }
38 
39  void outputs() {
40  double in1 = getInputDouble(IN1);
41  Array<double> in2 = getInputArray<double>(IN2);
42  Array<double> in3 = getInputArray<double>(IN3);
43  Array<double> in4 = getInputArray<double>(IN4);
44  Array<double> in5 = getInputArray<double>(IN5);
45 
46  printf("---------- time = %f ----------\n", getSimulationTime());
47  printf("input port %i = %f\n", IN1, in1);
48  in2.print();
49  in3.print();
50  in4.print();
51  in5.print();
52  }
53 
54  void terminate() {
55  printf("Terminating the s-function for inputs testing.\n");
56  }
57 
58 };
59 
60 //------------------------------------------------------------------------------
61 
62 #include "sfunDefinitions.h"
63 
64 //------------------------------------------------------------------------------
static void setInputPortsCount(int portsCount)
Definition: BaseBlock.h:104
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
void print()
Definition: Array.h:318
static time_T getSimulationTime()
Definition: BaseBlock.h:704
void terminate()
Definition: BaseBlock.h:392
void start()
Definition: BaseBlock.h:327
static double getInputDouble(int port)
Definition: BaseBlock.h:399

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