EasyLink
EasyLink is a C++ software development kit for developing blocks for SIMULINK (S-functions)
/Users/guillaume.laurent/Documents/Prog/easylinkEigen/easylink/sfunParameters.cpp
1 /*
2  * C++ S-function that shows all the different ways to use the parameters ports.
3  *
4  * To compile this C++ S-function, enter the following command in MATLAB:
5  *
6  * >>make sfunParameters.cpp
7  *
8  * Then open the file "testParameters.mdl/slx" and start the simulation.
9  */
10 
11 //------------------------------------------------------------------------------
12 
13 #define S_FUNCTION_NAME sfunParameters
14 
15 #include "EasyLink.h"
16 
17 enum parameterName {
18  PAR1, PAR2, PAR3, PAR4, PAR5, PAR6
19 };
20 
21 //------------------------------------------------------------------------------
22 
23 class Block : public BaseBlock {
24 public:
25 
26  static void checkParametersSizes() {
28  assertParameterPort(PAR1, true, 1, 1, mxDOUBLE_CLASS);
29  assertParameterPort(PAR2, false, 2, 3, mxDOUBLE_CLASS);
30  assertParameterPort(PAR3, true, 1, -1, mxDOUBLE_CLASS);
31  assertParameterPort(PAR4, false, -1, -1, mxDOUBLE_CLASS);
32  assertParameterPort(PAR5, true, 1, -1, mxCHAR_CLASS);
33  assertParameterPort(PAR6, false, 1, -1, mxCHAR_CLASS);
34  }
35 
36  void start() {
37  printf("Starting the s-function for parameters testing....\n");
38  }
39 
40  void outputs() {
41  double par1 = getParameterDouble(PAR1);
42  Array<double> par2 = getParameterArray<double>(PAR2);
43  Array<double> par3 = getParameterArray<double>(PAR3);
44  Array<double> par4 = getParameterArray<double>(PAR4);
45  std::string par5 = getParameterString(PAR5);
46  std::string par6 = getParameterString(PAR6);
47 
48  printf("---------- time = %f ----------\n", getSimulationTime());
49  printf("parameter %i = %f\n", PAR1, par1);
50  par2.print();
51  par3.print();
52  par4.print();
53  printf("parameter %i = %s\n", PAR5, par5.c_str());
54  printf("parameter %i = %s\n", PAR6, par6.c_str());
55 
56  }
57 
58  void terminate() {
59  printf("Terminating the s-function for parameters testing.\n");
60  }
61 
62 };
63 
64 //------------------------------------------------------------------------------
65 
66 #include "sfunDefinitions.h"
67 
68 //------------------------------------------------------------------------------
void outputs()
Definition: BaseBlock.h:340
void print()
Definition: Array.h:318
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
static time_T getSimulationTime()
Definition: BaseBlock.h:704
void terminate()
Definition: BaseBlock.h:392
void start()
Definition: BaseBlock.h:327
static std::string getParameterString(int port)
Definition: BaseBlock.h:561
static double getParameterDouble(int port)
Definition: BaseBlock.h:540
static void assertParameterPortsCount(int portsCount)
Definition: BaseBlock.h:42

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