Get Redundant and Distributed System Status
Get Remote Systems
In WinCC OA, you can work with remote systems to check their connection status and utilize this information for various purposes. This page explains a little trick to show you how to determine if remote systems are connected and provides code examples for handling this data.
Checking Remote System Connection
To check if a remote system is connected, you can use the following function:
public bool RemoteSystemConnected(string RemoteSystemName) {
dyn_string Hosts;
string SystemConnections = getSystemName() + "_DistConnections.Dist.HostNames";
dpGet(SystemConnections, Hosts);
for (int i = 0; i < Hosts.count(); i++) {
string ConnectedSystem = Hosts.at(i);
if (ConnectedSystem.contains(RemoteSystemName)) {
return true;
}
}
return false;
}
This function returns a Boolean value indicating whether the specified remote system is connected.
Utilizing Remote System Connection Status
Once you know the connection status of remote systems, you can use it in your scripts to make informed decisions. Here's an example:
void HandleRemoteSystems(dyn_string Hosts) {
dyn_uint ids;
int rc = CheckRemoteSystemConnection(Hosts);
string statusMessage, backgroundColor;
switch (rc) {
case 0:
backgroundColor = "Green"; // Use a different color for your application
statusMessage = (Hosts.count() == 0) ? "No stations online" :
(Hosts.count() == 1) ? "1 station online" :
(Hosts.count() == 10) ? "All stations online" : "Multiple stations online";
break;
default:
backgroundColor = "Red"; // Use a different color for your application
statusMessage = "Error in distributed systems";
break;
}
// Set the background color and display the status message
YourUIElement.BackgroundColor = backgroundColor;
YourUIElement.Text = statusMessage.Replace(" ", "\n");
}
int CheckRemoteSystemConnection(dyn_string Hosts) {
dyn_uint ids;
int rc = getRemoteSystemNamesConnected(Hosts, ids);
return rc;
}
Or this one for a simpler approach
void HandleRemoteSystem(string RemoteSystemName) {
bool isConnected = RemoteSystemConnected(RemoteSystemName);
if (isConnected) {
// Perform actions when the remote system is connected
} else {
// Handle the case when the remote system is not connected
}
}
This example shows how you can use the RemoteSystemConnected
function to determine whether a remote system is connected and take appropriate actions based on the result.
Caution
These examples are for illustration purposes, and you should adapt them to your specific requirements while protecting sensitive data.