4. Configuration
166
// 4 = module didn’t answer to the command (absent)
// 5 = command started or running
// 6 = There is already an active command on this point
// 7 = pulse command finished with success
END_VAR
VAR
byState: BYTE; // Function block state
udiPulseEnd: UDINT; // Pulse’s end instant
END_VAR
// PulsedCommandNexto’s state machine
CASE byState OF
0: // Init state, ready to receive commands:
CASE byCmdType OF
100:// Just returns the last status
101: // Execute pulse ON:
// Valids the pulse duration
IF byPulseTime > 1 THEN
// Check if there is already na active command on this point
IF ptDbpVarAdr^.ON OR ptDbpVarAdr^.OFF THEN
// Returns that there is already an active command
byStatus:= 6;
ELSE
// Enables CLOSE output
ptDbpVarAdr^.ON:= TRUE;
ptDbpVarAdr^.OFF:= FALSE;
// Next state: execute pulse ON
byState:= byCmdType;
// Returns started command
byStatus:= 5;
END_IF
ELSE
// Returns the out of range pulse
byStatus:= 2;
END_IF
102: // Execute pulse OFF
// Valids the pulse duration
IF byPulseTime > 1 THEN
// Check if there is already na active command on this point
IF ptDbpVarAdr^.ON OR ptDbpVarAdr^.OFF THEN
// Returns that there is already an active
byStatus:= 6;
ELSE
// Enables TRIP output
ptDbpVarAdr^.ON:= FALSE;
ptDbpVarAdr^.OFF:= TRUE;
// Next step: execute pulse OFF
byState:= byCmdType;
// Returns started command
byStatus:= 5;
END_IF
ELSE
// Returns the out of range pulse
byStatus:= 2;
END_IF
ELSE
// Returns invalid command
byStatus:= 1;
END_CASE
// Memorizes the instant of the pulse's end
udiPulseEnd:= SysTimeGetMs() + BYTE_TO_UDINT(byPulseTime) * 10;
101, 102:// Continues the pulse's execution ON/OFF
// It returns that the command is running
byStatus:= 5;
// Checks the running parameter change
IF byCmdType <> 100 AND byCmdType <> byState THEN
// Returns the running parameter change
byStatus:= 3;
END_IF
// Checks pulse’s end
IF SysTimeGetMs() >= udiPulseEnd THEN
// Disable TRIP and CLOSE outputs