本文整理汇总了Python中opcua.Server.get_endpoints方法的典型用法代码示例。如果您正苦于以下问题:Python Server.get_endpoints方法的具体用法?Python Server.get_endpoints怎么用?Python Server.get_endpoints使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类opcua.Server
的用法示例。
在下文中一共展示了Server.get_endpoints方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: OPCServer
# 需要导入模块: from opcua import Server [as 别名]
# 或者: from opcua.Server import get_endpoints [as 别名]
class OPCServer(object):
def __init__(self, settings):
super(OPCServer, self).__init__()
server_settings = settings.get("server")
objects = settings.get("objects")
self._endpoint = server_settings["endpoint"]
self._name = server_settings["name"]
self._namespace = server_settings["namespace"]
self._init_server()
for o in objects:
self._add_object(o["name"])
for variable, value in o["ro_variables"].items():
self._add_variable(o["name"], variable, value)
for variable, value in o["rw_variables"].items():
self._add_variable(o["name"], variable, value, True)
def start(self):
if self._server:
self._server.start()
def _init_server(self):
self._server = Server()
self._server.set_endpoint(self._endpoint)
self._server.set_server_name(self._name)
self._index = self._server.register_namespace(self._namespace)
_log.info("Index: %r" % (self._index,))
self._objects_node = self._server.get_objects_node()
_log.info("Node: %r" % (self._objects_node))
self._objects = {}
_log.info("Endpoints: %r" % (self._server.get_endpoints()))
def stop(self):
self._server.stop()
def _add_object(self, object_name):
self._objects[object_name] = { 'object': self._objects_node.add_object(self._index, object_name), 'variables' : {}}
def _add_variable(self, object_name, variable_name, value, writable=False):
obj = self._objects.get(object_name, None)
if obj.get('object', None):
var = self._objects_node.add_variable(self._index, variable_name, str(value))
obj['variables'][variable_name] = var
if writable:
var.set_writable()
return True
return False
def _get_variable(self, object_name, variable_name):
obj = self._objects.get(object_name)
if obj.get('object', None):
var = obj['variables'].get(variable_name, None)
return var
return None
def set_value(self, object_name, variable_name, value):
var = self._get_variable(object_name, variable_name)
if var:
var.set_value(str(value))
return True
return False
def get_value(self, object_name, variable_name):
var = self._get_variable(object_name, variable_name)
if var:
return var.get_value()
return None