-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontrol.bcsctrl
More file actions
174 lines (171 loc) · 4.69 KB
/
Copy pathcontrol.bcsctrl
File metadata and controls
174 lines (171 loc) · 4.69 KB
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
import library Tc3_DALI;
import library Tc3_EventLogger;
extern type BYTE as INT;
extern type UDINT as INT;
extern type DWORD as INT;
extern enum E_DALIAddressType {
Short,
Group,
Broadcast,
BroadcastUnaddr
}
extern enum E_DALICommandPriority {
High,
MiddleHigh,
Middle,
MiddleLow,
Low,
Unknown
}
extern struct ST_DALIChangeAddressList {
nOldAddress : BYTE,
nNewAddress : BYTE,
nRandomAddress : UDINT,
nErrors : DWORD
}
extern struct I_TcMessage {
dummy : BOOL // Placeholder for actual message structure
}
extern functionblock FB_DALI207QueryFailureStatus from Tc3_DALI {
inputs {
var bStart: BOOL;
var nAddress: BYTE;
var eAddressType: E_DALIAddressType;
var eCommandPriority: E_DALICommandPriority;
}
outputs {
var bError: BOOL;
var ipResultMessage: I_TcMessage;
var bBusy: BOOL;
var nFailureStatus: BYTE;
}
}
control EtherCATController {
enum OperatingMode {
OFF,
ECO,
COMFORT
}
struct Temperatures {
Room1: REAL,
Room2: REAL
}
var mode: OperatingMode = OperatingMode.OFF;
var lightLevel: INT = 0;
var heater: BOOL;
var lightsOn: BOOL;
var heatingEnabled: BOOL;
var arrayOfLights: BOOL[10];
var temperaturesArray: Temperatures[10];
functionblock HeatingLogic {
inputs {
var iTemp: REAL;
var iMode: OperatingMode;
}
outputs {
var oHeating: BOOL;
}
logic {
if (iMode == OperatingMode.COMFORT && iTemp < 21.0){
oHeating = true;
} else if(iMode == OperatingMode.ECO && iTemp < 18.0){
oHeating = true;
} else {
oHeating = false;
}
}
}
unit ToggleLightsOnButtonPress {
on_rising(Buttons.Room1){
Lights.Room1 = !Lights.Room1;
}
on_rising(Buttons.Room2){
Lights.Room2 = !Lights.Room2;
}
}
unit TurnOnLightsScheduled at TOD#06:30:00 {
Lights.Room1 = true;
arrayOfLights[0] = true;
arrayOfLights[1] = true;
arrayOfLights[2] = true;
temperaturesArray[0].Room1 = 20.5;
temperaturesArray[1].Room2 = 22.0;
}
unit RetryHeaterStartup when (mode != OperatingMode.OFF) {
var retries: INT = 0;
while (retries < 3){
heater = true;
retries = retries + 1;
if (retries == 2){
break;
}
}
}
unit DimLightsGradually {
for (var i: INT = 0 to 5 by 1){
lightLevel = i * 20;
if (i == 2){
continue;
}
}
}
unit ControlHeating {
use HeatingLogic(iTemp: temperaturesArray[0].Room1, iMode: mode) -> heatingEnabled;
heater = heatingEnabled;
}
unit AdjustLightLevelByMode {
switch (mode){
case OperatingMode.COMFORT {
lightLevel = 100;
}
case OperatingMode.ECO {
lightLevel = 50;
}
default {
lightLevel = 0;
}
}
}
unit MorningPresenceCheck {
if (now >= TOD#07:00:00){
Lights.Room2 = true;
}
}
unit DelayedStartup once when (now >= TOD#07:05:00) {
after T#5m if(true){
heater = true;
Lights.Room1 = false;
}
}
unit UseDaliLibrary {
var daliAddress: E_DALIAddressType;
var daliPriority: E_DALICommandPriority = E_DALICommandPriority.High;
var addressList: ST_DALIChangeAddressList = { nOldAddress: 1, nNewAddress: 2, nRandomAddress: 3, nErrors: 0 };
var status: BOOL;
var resultMessage: I_TcMessage;
var failureStatus: BYTE;
use FB_DALI207QueryFailureStatus(bStart: true, nAddress: 1, eAddressType: daliAddress, eCommandPriority: daliPriority) -> {
bBusy: status,
bError: status,
nFailureStatus: failureStatus,
ipResultMessage: resultMessage
};
use FB_DALI207QueryFailureStatus(bStart: false, nAddress: 2, eAddressType: daliAddress, eCommandPriority: daliPriority) -> {
bBusy: status,
bError: status,
nFailureStatus: failureStatus,
ipResultMessage: resultMessage
};
}
unit ButtonReleaseHandler {
on_falling(Buttons.Room2){
Lights.Room2 = false;
}
}
unit ValidateSensorDistance {
var distance: INT = UltrasonicSensor.Distance;
if (!UltrasonicSensor.Error){
lightLevel = distance;
}
}
}