This function is used in Python Scripting.


Enables or disables an OPC server connection.

Client Permission Restrictions

Permission Type: OPC Server Management

Client access to this scripting function is blocked to users that do not meet the role/zone requirements for the above permission type. This function is unaffected when run in the Gateway scope.


system.opc.setServerEnabled(serverName, enabled)

  • Parameters

String serverNameThe 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


  • Scope

Gateway, Vision Client, Perspective Session

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(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.
		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")

	# Otherwise, let the user know which servers we enabled.
	system.gui.messageBox("The following servers were modified:\n" + message)

system opc setServerEnabled, opc.setServerEnabled