Introduction to Monitoring Data Point Commands
Monitoring data points and ensuring they return to a predefined state after a certain threshold is a common requirement in automation systems. This guide presents a programming trick in WinCC OA to check for changes in data points of a specific class and reset them if they remain in a changed state beyond a specified threshold.
Monitoring Data Point Changes
The following code continuously monitors a list of data points, checking if they have been altered. If a data point remains in a changed state for longer than the defined threshold, the system will reset it to its original state. This approach helps in handling commands that might get stuck or remain active for too long.
// Function to Monitor and Reset Data Point Commands
void MonitorDataPoints(dyn_string devices) {
while(TRUE) {
for(int i = 0; i < dynlen(devices); i++) {
dyn_string dataPoints = dpNames(devices.at(i) + "_Command" + "*");
CheckAndResetDataPoints(dataPoints);
}
delay(4);
}
}
void CheckAndResetDataPoints(dyn_string dataPoints) {
for(int i = 0; i < dynlen(dataPoints); i++) {
bool currentValue;
time timestampStr;
if(dpElementType(dataPoints.at(i)) == 23){
dpGet(dataPoints.at(i), currentValue);
if(currentValue) {
dpGet(dataPoints.at(i) + ":_original.._stime", timestampStr);
time currentTime = getCurrentTime();
if(period(currentTime) - period(timestampStr) >= threshold) {
DebugN("Resetting command due to threshold ", dataPoints.at(i), currentValue);
dpSet(dataPoints.at(i), FALSE);
}
}
}
}
}
Conclusion
This programming trick provides a robust method for monitoring and resetting commands in WinCC OA. By continuously checking the state of data points and ensuring they revert to a safe state after a defined period, you can enhance the reliability and stability of your automation systems.