コード例 #1
0
def opcua_converter_main(options):
    # setup our server
    server = Server()
    uasecurity = UaSecurity()
    if uasecurity.get_securitytype() == 'tls':
        server_cert, client_cert, private_key = uasecurity.get_certificates()
        if server_cert is None:
            logger.error(
                'tls is enabled, but server cert is missing with current configuration'
            )
            sys.exit(-1)
        if private_key is None:
            logger.error(
                'tls is enabled, but private key is missing with current configuration'
            )
            sys.exit(-1)
        server.load_certificate(server_cert)
        server.load_private_key(private_key)
    ConfigHistoryStorage(server)
    server.start()

    # setup adapter
    adapter = PlugInAdapter(options.conf_file)
    handler = SubHandler(server, adapter)
    handler.run()
    adapter.subscription(handler.datachange_notification,
                         handler.event_notification)
    adapter.start()

    try:
        while True:
            logger.debug('opcua converter running......')
            time.sleep(60)
    finally:
        # close connection, remove subcsriptions, etc
        adapter.stop()
        server.stop()
コード例 #2
0
    def datachange_notification(self, node, val, data):
        print("Python: New data change event", node, val)

    def event_notification(self, event):
        print("Python: New event", event)


if __name__ == "__main__":
    logging.basicConfig(level=logging.WARN)
    #logger = logging.getLogger("KeepAlive")
    # logger.setLevel(logging.DEBUG)

    client = Client("opc.tcp://localhost:4840")
    uasecurity = UaSecurity()
    if uasecurity.get_securitytype() == 'tls':
        server_cert, client_cert, private_key = uasecurity.get_certificates()
        if server_cert is None:
            print(
                'tls is enabled, but server cert is missing with current configuration'
            )
            sys.exit(-1)
        if private_key is None:
            print(
                'tls is enabled, but private key is missing with current configuration'
            )
            sys.exit(-1)
        client.load_client_certificate(server_cert)
        client.load_private_key(private_key)

    try:
        client.connect()