本文整理汇总了Python中opcua.Server.set_application_uri方法的典型用法代码示例。如果您正苦于以下问题:Python Server.set_application_uri方法的具体用法?Python Server.set_application_uri怎么用?Python Server.set_application_uri使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类opcua.Server
的用法示例。
在下文中一共展示了Server.set_application_uri方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestServer
# 需要导入模块: from opcua import Server [as 别名]
# 或者: from opcua.Server import set_application_uri [as 别名]
class TestServer(unittest.TestCase, CommonTests, SubscriptionTests):
'''
Run common tests on server side
Tests that can only be run on server side must be defined here
'''
@classmethod
def setUpClass(self):
self.srv = Server()
self.srv.set_endpoint('opc.tcp://localhost:%d' % port_num)
add_server_methods(self.srv)
self.srv.start()
self.opc = self.srv
self.discovery = Server()
self.discovery.set_application_uri("urn:freeopcua:python:discovery")
self.discovery.set_endpoint('opc.tcp://localhost:%d' % port_discovery)
self.discovery.start()
@classmethod
def tearDownClass(self):
self.srv.stop()
self.discovery.stop()
def test_discovery(self):
client = Client(self.discovery.endpoint.geturl())
client.connect()
try:
servers = client.find_servers()
new_app_uri = "urn:freeopcua:python:server:test_discovery"
self.srv.application_uri = new_app_uri
self.srv.register_to_discovery(self.discovery.endpoint.geturl(), 0)
time.sleep(0.1) # let server register registration
new_servers = client.find_servers()
self.assertEqual(len(new_servers) - len(servers) , 1)
self.assertFalse(new_app_uri in [s.ApplicationUri for s in servers])
self.assertTrue(new_app_uri in [s.ApplicationUri for s in new_servers])
finally:
client.disconnect()
def test_find_servers2(self):
client = Client(self.discovery.endpoint.geturl())
client.connect()
try:
servers = client.find_servers()
new_app_uri1 = "urn:freeopcua:python:server:test_discovery1"
self.srv.application_uri = new_app_uri1
self.srv.register_to_discovery(self.discovery.endpoint.geturl(), period=0)
new_app_uri2 = "urn:freeopcua:python:test_discovery2"
self.srv.application_uri = new_app_uri2
self.srv.register_to_discovery(self.discovery.endpoint.geturl(), period=0)
time.sleep(0.1) # let server register registration
new_servers = client.find_servers()
self.assertEqual(len(new_servers) - len(servers) , 2)
self.assertFalse(new_app_uri1 in [s.ApplicationUri for s in servers])
self.assertFalse(new_app_uri2 in [s.ApplicationUri for s in servers])
self.assertTrue(new_app_uri1 in [s.ApplicationUri for s in new_servers])
self.assertTrue(new_app_uri2 in [s.ApplicationUri for s in new_servers])
# now do a query with filer
new_servers = client.find_servers(["urn:freeopcua:python:server"])
self.assertEqual(len(new_servers) - len(servers) , 0)
self.assertTrue(new_app_uri1 in [s.ApplicationUri for s in new_servers])
self.assertFalse(new_app_uri2 in [s.ApplicationUri for s in new_servers])
# now do a query with filer
new_servers = client.find_servers(["urn:freeopcua:python"])
self.assertEqual(len(new_servers) - len(servers) , 2)
self.assertTrue(new_app_uri1 in [s.ApplicationUri for s in new_servers])
self.assertTrue(new_app_uri2 in [s.ApplicationUri for s in new_servers])
finally:
client.disconnect()
"""
# not sure if this test is necessary, and there is a lot repetition with previous test
def test_discovery_server_side(self):
servers = self.discovery.find_servers()
self.assertEqual(len(servers), 1)
self.srv.register_to_discovery(self.discovery.endpoint.geturl(), 1)
time.sleep(1) # let server register registration
servers = self.discovery.find_servers()
print("SERVERS 2", servers)
self.assertEqual(len(servers), 2)
"""
#def test_register_server2(self):
#servers = self.opc.register_server()
def test_register_namespace(self):
uri = 'http://mycustom.Namespace.com'
idx1 = self.opc.register_namespace(uri)
idx2 = self.opc.get_namespace_index(uri)
self.assertEqual(idx1, idx2)
def test_register_use_namespace(self):
uri = 'http://my_very_custom.Namespace.com'
idx = self.opc.register_namespace(uri)
root = self.opc.get_root_node()
myvar = root.add_variable(idx, 'var_in_custom_namespace', [5])
myid = myvar.nodeid
self.assertEqual(idx, myid.NamespaceIndex)
def test_server_method(self):
#.........这里部分代码省略.........
示例2: TestServer
# 需要导入模块: from opcua import Server [as 别名]
# 或者: from opcua.Server import set_application_uri [as 别名]
class TestServer(unittest.TestCase, CommonTests):
'''
Run common tests on server side
Tests that can only be run on server side must be defined here
'''
@classmethod
def setUpClass(self):
self.srv = Server()
self.srv.set_endpoint('opc.tcp://localhost:%d' % port_num2)
add_server_methods(self.srv)
self.srv.start()
self.opc = self.srv
self.discovery = Server()
self.discovery.set_application_uri("urn:freeopcua:python:discovery")
self.discovery.set_endpoint('opc.tcp://localhost:%d' % port_discovery)
self.discovery.start()
@classmethod
def tearDownClass(self):
self.srv.stop()
self.discovery.stop()
def test_discovery(self):
client = Client(self.discovery.endpoint.geturl())
client.connect()
servers = client.find_servers()
new_app_uri = "urn:freeopcua:python:server::test_discovery"
self.srv.application_uri = new_app_uri
self.srv.register_to_discovery(self.discovery.endpoint.geturl(), 1)
time.sleep(0.1) # let server register registration
new_servers = client.find_servers()
self.assertEqual(len(new_servers) - len(servers) , 1)
self.assertFalse(new_app_uri in [s.ApplicationUri for s in servers])
self.assertTrue(new_app_uri in [s.ApplicationUri for s in new_servers])
client.disconnect()
"""
# not sure if this test is necessary, and there is a lot repetition with previous test
def test_discovery_server_side(self):
servers = self.discovery.find_servers()
self.assertEqual(len(servers), 1)
self.srv.register_to_discovery(self.discovery.endpoint.geturl(), 1)
time.sleep(1) # let server register registration
servers = self.discovery.find_servers()
print("SERVERS 2", servers)
self.assertEqual(len(servers), 2)
"""
#def test_register_server2(self):
#servers = self.opc.register_server()
def test_register_namespace(self):
uri = 'http://mycustom.Namespace.com'
idx1 = self.opc.register_namespace(uri)
idx2 = self.opc.get_namespace_index(uri)
self.assertEqual(idx1, idx2)
def test_register_use_namespace(self):
uri = 'http://my_very_custom.Namespace.com'
idx = self.opc.register_namespace(uri)
root = self.opc.get_root_node()
myvar = root.add_variable(idx, 'var_in_custom_namespace', [5])
myid = myvar.nodeid
self.assertEqual(idx, myid.NamespaceIndex)
def test_server_method(self):
def func(parent, variant):
variant.Value *= 2
return [variant]
o = self.opc.get_objects_node()
v = o.add_method(3, 'Method1', func, [ua.VariantType.Int64], [ua.VariantType.Int64])
result = o.call_method(v, ua.Variant(2.1))
self.assertEqual(result, 4.2)
def test_xml_import(self):
self.srv.import_xml("tests/custom_nodes.xml")
o = self.opc.get_objects_node()
v = o.get_child(["MyXMLFolder", "MyXMLObject", "MyXMLVariable"])
val = v.get_value()
self.assertEqual(val, "StringValue")