-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalcDiff.scl
80 lines (67 loc) · 2.2 KB
/
calcDiff.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
FUNCTION_BLOCK "calcDiff"
{ S7_Optimized_Access := 'TRUE' }
VERSION : 0.1
VAR_INPUT
aMotherCores : Array[1..#daysLogged] of Real;
aSetsProduced : Array[1..#daysLogged] of Real;
bTrigger : Bool;
bMonthShift : Bool;
bFirstScan : Bool;
iDay : Int;
END_VAR
VAR_OUTPUT
aDiffToday : Real;
aDiffYesterday : Real;
END_VAR
VAR
aDifferenceCurrentLast : Array[1..#daysLogged] of Real;
aDifferenceCurrent : Array[1..#daysLogged] of Real;
R_TRIG_Reset {InstructionName := 'R_TRIG'; LibVersion := '1.0'} : R_TRIG;
R_TRIG_Month {InstructionName := 'R_TRIG'; LibVersion := '1.0'} : R_TRIG;
i3 : Int;
i4 : Int;
END_VAR
VAR_TEMP
itempStorage : Real;
END_VAR
VAR CONSTANT
daysLogged : Int := 31;
END_VAR
BEGIN
REGION Initialize
IF #bFirstScan THEN
FOR #i4 := 1 TO #daysLogged DO
#aDifferenceCurrent[#i4] := 0.0;
#aDifferenceCurrentLast[#i4] := 0.0;
END_FOR;
END_IF;
END_REGION ;
#R_TRIG_Reset(CLK := #bTrigger);
#R_TRIG_Month(CLK := #bMonthShift);
REGION Loop log values
IF #R_TRIG_Reset.Q AND #iDay > 0 AND #iDay <= #daysLogged THEN
IF #aSetsProduced[#iDay] <> 0 AND #aMotherCores[#iDay] <> 0 THEN
//#aDifferenceCurrent[#iDay] := #aSetsProduced[#iDay] / #aMotherCores[#iDay];
#itempStorage := (ROUND(IN := 100 * (#aSetsProduced[#iDay] / #aMotherCores[#iDay])));
#aDifferenceCurrent[#iDay] := #itempStorage / 100;
//#aDifferenceCurrent[#iDay] := ROUND(IN := 100 * (#aSetsProduced[#iDay] / #aMotherCores[#iDay]))/100;
END_IF;
END_IF;
END_REGION
REGION New month
IF #R_TRIG_Month.Q THEN
#aDifferenceCurrentLast := #aDifferenceCurrent;
FOR #i3 := 1 TO #daysLogged BY 1 DO
#aDifferenceCurrent[#i3] := 0.0;
END_FOR;
END_IF;
END_REGION
IF #iDay <> 0 AND #iDay <= 31 THEN
#aDiffToday := #aDifferenceCurrent[#iDay];
IF #iDay > 1 THEN
#aDiffYesterday := #aDifferenceCurrent[#iDay - 1];
ELSIF #iDay = 1 THEN
#aDiffYesterday := #aDifferenceCurrent[#iDay + 30];
END_IF;
END_IF;
END_FUNCTION_BLOCK