-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogSignalResetDaily.scl
83 lines (69 loc) · 2.18 KB
/
logSignalResetDaily.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
FUNCTION_BLOCK "logBoolCount2Months"
{ S7_Optimized_Access := 'TRUE' }
VERSION : 0.1
VAR_INPUT
bReset : Bool;
bMonthShift : Bool;
bLogSignal : Bool;
bFirstScan : Bool;
iDay : Int;
END_VAR
VAR_OUTPUT
aCurrentMonth : Array[1..#maxDays] of Real;
iCntLogSignal : Real := 0.0;
iCntAverageSignal : Real := 0.0;
END_VAR
VAR
R_TRIG_Signal {InstructionName := 'R_TRIG'; LibVersion := '1.0'} : R_TRIG;
END_VAR
VAR RETAIN
IEC_Counter_Signal {InstructionName := 'CTU_INT'; LibVersion := '1.0'; ExternalAccessible := 'False'; ExternalVisible := 'False'; ExternalWritable := 'False'; S7_SetPoint := 'False'} : CTU_INT;
END_VAR
VAR
R_TRIG_Reset {InstructionName := 'R_TRIG'; LibVersion := '1.0'} : R_TRIG;
aLastMonth : Array[1..#maxDays] of Real;
i1 : Int;
i2 : Int;
i3 : Int;
i4 : Int;
R_TRIG_Month {InstructionName := 'R_TRIG'; LibVersion := '1.0'} : R_TRIG;
END_VAR
VAR CONSTANT
maxDays : Int := 31;
maxCount : Int := 3000;
END_VAR
BEGIN
REGION Initialize
IF #bFirstScan THEN
#iCntLogSignal := 0.0;
#iCntAverageSignal := 0.0;
FOR #i4 := 1 TO #maxDays DO
#aCurrentMonth[#i4] := 0.0;
#aLastMonth[#i4] := 0.0;
END_FOR;
END_IF;
END_REGION ;
#R_TRIG_Reset(CLK := #bReset);
#R_TRIG_Month(CLK := #bMonthShift);
IF #R_TRIG_Reset.Q AND #iDay > 0 AND #iDay <= #maxDays THEN
#aCurrentMonth[#iDay] := #iCntLogSignal;
#iCntAverageSignal := 0.0;
FOR #i2 := 1 TO #maxDays BY 1 DO
#iCntAverageSignal := #iCntAverageSignal + #aCurrentMonth[#i2];
END_FOR;
#iCntAverageSignal := #iCntAverageSignal / (#maxDays);
END_IF;
REGION New month
IF #R_TRIG_Month.Q THEN
#aLastMonth := #aCurrentMonth;
FOR #i3 := 1 TO #maxDays BY 1 DO
#aCurrentMonth[#i3] := 0.0;
END_FOR;
END_IF;
END_REGION
#R_TRIG_Signal(CLK := #bLogSignal);
#IEC_Counter_Signal(CU := #R_TRIG_Signal.Q,
R := #R_TRIG_Reset.Q,
PV := #maxCount,
CV => #iCntLogSignal);
END_FUNCTION_BLOCK