forked from CarstenMaul/MQTT-Siemens-S7-300
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MQTT_Runtime.SCL
68 lines (52 loc) · 1021 Bytes
/
MQTT_Runtime.SCL
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
FUNCTION_BLOCK mqttRuntime
TITLE = 'Runtimercounter'
VERSION : '1.0'
AUTHOR : Groschke
VAR_INPUT
IN : BOOL; //
RES : BOOL; // manuell reset
END_VAR
VAR_OUTPUT
RTIME : TIME; // maximal value is 24Days
END_VAR
VAR
last : DINT;
now : DINT;
run : DINT; // in secs
FP_IN : BOOL;
END_VAR
LABEL
Out;
END_LABEL
BEGIN
IF IN AND NOT FP_IN THEN
last := 0;
FP_IN := true;
END_IF;
IF NOT IN AND FP_IN THEN
FP_IN := false;
END_IF;
IF IN AND NOT RES THEN
now := DWORD_TO_DINT(Unixtime());
IF last = 0 THEN
last := now;
GOTO Out;
ELSE
run := run + (now - last);
last := now;
END_IF;
END_IF;
IF IN AND RES THEN
run := 0;
now := 0;
last := 0;
ELSIF NOT IN AND RES THEN
run := 0;
now := 0;
last := 0;
END_IF;
IF run >= 2073600 THEN // avoid overflow of time typ
run := 0;
END_IF;
Out: RTIME := DINT_TO_TIME(run * 1000);
END_FUNCTION_BLOCK