# The following will iterate through all configured OPC servers, and check if they are enabled or disabled.
# If a OPC server is disabled, the code will enable it with a call to setServerEnabled.
# This code interacts in the Client scope, so it should be placed on a component, such as a Button.
# Retrieve a list of all servers in the Gateway.
allServers = system.opc.getServers(True)
# Initialize a message. The empty string is initially used so that the value may be checked later.
message = ""
# Iterate through each server.
for server in allServers:
# For each server, call isServerEnabled. Uses Python's "not" operator to check if a false value is returned.
if not system.opc.isServerEnabled(server):
# If disabled, then enable the server.
# Append details about the state change we made to the message variable.
message += "%s \n" % (server)
# Check to see if any changes were made. If the length (len()) of the message is less than 1 character, then a change wasn't made.
if len(message) < 1:
# Notify the user that the code did not make any changes.
system.gui.messageBox("No servers were modified")
# Otherwise, let the user know which servers we enabled.
system.gui.messageBox("The following servers were modified:\n" + message)