system.opc.setServerEnabled
Description
Enables or disables an OPC server connection.
Syntax
system.opc.setServerEnabled ( serverName, enabled )
-
Parameters
String serverName - The name of an OPC server connection.
Boolean enabled - The new state the connection should be set to: true to enable the connection, false to disable.
-
Returns
No return value.
-
Scope
All
Code Examples
Code Snippet
#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()
#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
system.opc.setServerEnabled(server,
True
)
#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"
)
else
:
#Otherwise, let the user know which servers we enabled.
system.gui.messageBox(
"The following servers were modified:\n"
+
message)