|
rllib
1
|
#include <rlstatemachine.h>

Public Member Functions | |
| rlStatemachine (int numStates, int numProcessVariables) | |
| virtual | ~rlStatemachine () |
| int | setPlcStateInt (int index, int val) |
| float | setPlcStateFloat (int index, float val) |
| double | setPlcStateDouble (int index, double val) |
| virtual void | doState () |
| virtual void | enterState (int newState, int whichEntry=0) |
| virtual void | exitState (int whichExit=0) |
| int | getPlcStateInt (int index) |
| float | getPlcStateFloat (int index) |
| double | getPlcStateDouble (int index) |
| int | getState () |
| rlPlcState * | getVar () |
Protected Attributes | |
| int | num_states |
| int | num_process_variables |
| int | state |
| rlPlcState * | var |
class for a statemachine principle:
the user declares and implements his statemachine class Machine1 :public rlStatemachine { public: enum MyStates // declare your states { state1 = 0, state2, state3, numberOfStates };
enum MyIndexes // declare indexes for your process variables
{
temperature = 0,
speed,
voltage,
numberOfProcessVariables
}; Machine1(int numProcessVariables=numberOfProcessVariables);
virtual ~Machine1();
virtual void doState();
virtual void enterState(int newState, int whichEntry=0);
virtual void exitState(int whichExit=0);
};the statemachines are all executed forever Machine1 stm1; // declare some statemachines Machine2 stm2; // all Machines are derived from rlStatemachine Machine3 stm3; // user has to implement these Machines
while(1) // forever do the statemachines
{ // for example within your SoftPLC or within slotNullEvent
rlsleep(cycletime);
readProcessImageFromField(); // here the setPlcStateInt/Float/Double methods are called
the inputs are read from the field
stm1.doState(); // now we do the state transitions
stm2.doState();
stm3.doState();
writeProcessImageToField(); // here the getPlcStateInt/Float/Double methods are called
in case of SoftPLC write to field
in case of slotNullEvent update GUI
}
Definition at line 63 of file rlstatemachine.h.
| rlStatemachine::rlStatemachine | ( | int | numStates, |
| int | numProcessVariables | ||
| ) |
Definition at line 10 of file rlstatemachine.cpp.
{
state = 0;
num_states = 0;
var = NULL;
num_states = numStates;
num_process_variables = numProcessVariables;
if(numProcessVariables <= 0) return;
var = new rlPlcState(numProcessVariables, numProcessVariables, numProcessVariables);
}
| rlStatemachine::~rlStatemachine | ( | ) | [virtual] |
Definition at line 21 of file rlstatemachine.cpp.
| void rlStatemachine::doState | ( | ) | [virtual] |
Definition at line 56 of file rlstatemachine.cpp.
{
// implement in subclass
}
| void rlStatemachine::enterState | ( | int | newState, |
| int | whichEntry = 0 |
||
| ) | [virtual] |
Definition at line 61 of file rlstatemachine.cpp.
{
// implement in subclass and call rlStatemachine::enterState(newState,whichEntry);
if(newState < 0) return;
if(newState >= num_states) return;
if(whichEntry){}
state = newState;
}
| void rlStatemachine::exitState | ( | int | whichExit = 0 | ) | [virtual] |
Definition at line 70 of file rlstatemachine.cpp.
{
// implement in subclass
if(whichExit){}
}
| double rlStatemachine::getPlcStateDouble | ( | int | index | ) |
Definition at line 92 of file rlstatemachine.cpp.
{
if(index < 0) return 0;
if(index >= num_process_variables) return 0;
if(var == NULL) return 0;
return var->d[index];
}
| float rlStatemachine::getPlcStateFloat | ( | int | index | ) |
Definition at line 84 of file rlstatemachine.cpp.
{
if(index < 0) return 0;
if(index >= num_process_variables) return 0;
if(var == NULL) return 0;
return var->f[index];
}
| int rlStatemachine::getPlcStateInt | ( | int | index | ) |
Definition at line 76 of file rlstatemachine.cpp.
{
if(index < 0) return 0;
if(index >= num_process_variables) return 0;
if(var == NULL) return 0;
return var->i[index];
}
| int rlStatemachine::getState | ( | ) |
Definition at line 100 of file rlstatemachine.cpp.
{
return state;
}
| rlPlcState * rlStatemachine::getVar | ( | ) |
Definition at line 105 of file rlstatemachine.cpp.
{
return var;
}
| double rlStatemachine::setPlcStateDouble | ( | int | index, |
| double | val | ||
| ) |
Definition at line 46 of file rlstatemachine.cpp.
| float rlStatemachine::setPlcStateFloat | ( | int | index, |
| float | val | ||
| ) |
Definition at line 36 of file rlstatemachine.cpp.
| int rlStatemachine::setPlcStateInt | ( | int | index, |
| int | val | ||
| ) |
Definition at line 26 of file rlstatemachine.cpp.
int rlStatemachine::num_process_variables [protected] |
Definition at line 80 of file rlstatemachine.h.
int rlStatemachine::num_states [protected] |
Definition at line 80 of file rlstatemachine.h.
int rlStatemachine::state [protected] |
Definition at line 81 of file rlstatemachine.h.
rlPlcState* rlStatemachine::var [protected] |
Definition at line 82 of file rlstatemachine.h.
1.7.5.1