EasyLink
EasyLink is a C++ software development kit for developing blocks for SIMULINK (S-functions)
/Users/guillaume.laurent/Documents/Prog/easylinkEigen/easylink/sfunOutputs.cpp
1 /*
2  * C++ S-function that shows all the different ways to use the output ports.
3  *
4  * To compile this C++ S-function, enter the following command in MATLAB:
5  *
6  * >>make sfunOutputs.cpp
7  *
8  * Then open the file "testOutputs.mdl/slx" and start the simulation.
9  */
10 
11 //------------------------------------------------------------------------------
12 
13 #define S_FUNCTION_NAME sfunOutputs
14 
15 #include "EasyLink.h"
16 
17 enum outputPortName {
18  OUT1, OUT2, OUT3
19 };
20 
21 //------------------------------------------------------------------------------
22 
23 class Block : public BaseBlock {
24 public:
25 
26  static void initializeOutputPortSizes() {
28  setOutputPort(OUT1, 1, 1, SS_DOUBLE);
29  setOutputPort(OUT2, 3, 1, SS_DOUBLE);
30  setOutputPort(OUT3, 2, 3, SS_INT32);
31  }
32 
33  void start() {
34  printf("Starting the s-function for outputs testing...\n");
35  }
36 
37  void outputs() {
38  Array<double> out2 = getOutputArray<double>(OUT2);
39  Array<int> out3 = getOutputArray<int>(OUT3);
40 
41  printf("---------- time = %f ----------\n", getSimulationTime());
42  printf("output port %i = 7\n", OUT1);
43  setOutputDouble(OUT1, 7);
44 
45  out2.init(1);
46  out2[1] = 2;
47  out2.print();
48 
49  out3.init(3);
50  out3(0, 2) = 4;
51  out3.print();
52 
53  }
54 
55  void terminate() {
56  printf("Terminating the s-function for outputs testing.\n");
57  }
58 
59 };
60 
61 //------------------------------------------------------------------------------
62 
63 #include "sfunDefinitions.h"
64 
65 //------------------------------------------------------------------------------
static void setOutputPortsCount(int portsCount)
Definition: BaseBlock.h:152
void outputs()
Definition: BaseBlock.h:340
void print()
Definition: Array.h:318
static time_T getSimulationTime()
Definition: BaseBlock.h:704
void init(_Scalar x=0)
Definition: Array.h:300
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 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.