Exemplo n.º 1
0
    def setUp(self):
        # creates the 4diac manager
        self.manager_4diac = manager.Manager()
        # creates the opc-ua manager
        self.manager_4diac.build_ua_manager(self.address, self.port_server,
                                            self.file_name)

        # creates the tcp server to communicate with the 4diac
        self.handler = tcp_server.TcpServer(self.address, 61499, 10,
                                            self.manager_4diac)
        # creates the handler
        thread = Thread(target=self.handler.handle_client)
        thread.start()

        # get the path for the config
        config_path = os.path.join(os.path.dirname(sys.path[0]), 'tests',
                                   'configurations', self.config2upload)
        # sends the configuration to the
        sender_simulator = diac_simulator.DiacSimulator(self.address, 61499)
        sender_simulator.upload_dinasore(config_path)
        sender_simulator.disconnect()

        # stops the work at the
        self.manager_4diac.manager_ua.stop_ua()
        # stops the tcp server
        self.handler.stop_server()

        # creates the 4diac manager
        self.manager_4diac = manager.Manager()
        # creates the opc-ua manager
        self.manager_4diac.build_ua_manager(self.address, self.port_server,
                                            self.file_name)
    ##############################################################

    # Configure the logging output
    log_path = os.path.join(os.path.dirname(sys.path[0]), 'resources',
                            'error_list.log')
    if os.path.isfile(log_path):
        os.remove(log_path)
    logging.basicConfig(
        filename=log_path,
        level=log_level,
        format='[%(asctime)s][%(levelname)s][%(threadName)s] %(message)s')

    # creates the 4diac manager
    m = manager.Manager(monitor=monitor)
    # sets the ua integration option
    m.build_ua_manager(address, port_opc, 'data_model.xml')

    # creates the tcp server to communicate with the 4diac
    hand = tcp_server.TcpServer(address, port_diac, 10, m)

    try:
        # handles every client
        marketplace_bridge.MarketplaceBridge.announce(m.manager_ua.base_name)
        while True:
            hand.handle_client()
    except KeyboardInterrupt:
        logging.info('interrupted server')
        m.manager_ua.stop_ua()
        hand.stop_server()
        sys.exit(0)