Beispiel #1
0
    def _build_connection(self, config):
        """
        Constructs and returns a Connection object according to the given
        configuration. The object returned here is a VadcpClient instance.

        @param config configuration dict

        @retval a VadcpClient instance

        @throws InstrumentParameterException Invalid configuration.
        """
        log.info('_build_connection: config=%s' % config)

        c4 = config['four_beam']
        outfilename = 'vadcp_output_%s_%s.txt' % (c4.host, c4.port)
        u4_outfile = file(outfilename, 'w')
        c5 = config['fifth_beam']
        outfilename = 'vadcp_output_%s_%s.txt' % (c5.host, c5.port)
        u5_outfile = file(outfilename, 'w')

        log.info("setting VadcpClient with config: %s" % config)
        try:
            client = VadcpClient(config, u4_outfile, u5_outfile)
        except (TypeError, KeyError):
            raise InstrumentParameterException('Invalid comms config dict.'
                                               ' config=%s' % config)

        # set data_listener to the client so we can notify corresponding
        # DriverAsyncEvent.SAMPLE events:
        def _data_listener(sample):
            log.info("_data_listener: sample = %s" % str(sample))
            self._driver_event(DriverAsyncEvent.SAMPLE, val=sample)

        client.set_data_listener(_data_listener)
        return client
    def setUpClass(cls):
        super(Test, cls).setUpClass()
        if cls._skip_reason:
            return

        ReceiverBuilder.use_greenlets()

        cls._samples_recd = 0

        c4 = cls._conn_config['four_beam']
        outfilename = 'vadcp_output_%s_%s.txt' % (c4.host, c4.port)
        u4_outfile = file(outfilename, 'w')
        c5 = cls._conn_config['fifth_beam']
        outfilename = 'vadcp_output_%s_%s.txt' % (c5.host, c5.port)
        u5_outfile = file(outfilename, 'w')

        cls._client = VadcpClient(cls._conn_config, u4_outfile, u5_outfile)

        cls._client.set_generic_timeout(cls._timeout)

        log.info("connecting")
        cls._client.set_data_listener(cls._data_listener)
        cls._client.connect()

        log.info("sending break and waiting for prompt")
        cls._client.send_break()
Beispiel #3
0
    def configure(self, *args, **kwargs):
        """
        Configure the driver for communications with the device via
        port agent / logger (valid but unconnected connection object).

        @param config comms config dict.

        @raises InstrumentStateException if command not allowed in current
                state
        @throws InstrumentParameterException if missing comms or invalid
                config dict.
        """

        if log.isEnabledFor(logging.DEBUG):
            log.debug("args=%s kwargs=%s" % (str(args), str(kwargs)))

        self._assert_state(DriverState.UNCONFIGURED)

        config = kwargs.get('config', None)
        if config is None:
            #            raise InstrumentParameterException(msg="'config' parameter required")
            config = args[0]

        c4 = config['four_beam']
        outfilename = 'vadcp_output_%s_%s.txt' % (c4.host, c4.port)
        u4_outfile = file(outfilename, 'w')
        c5 = config['fifth_beam']
        outfilename = 'vadcp_output_%s_%s.txt' % (c5.host, c5.port)
        u5_outfile = file(outfilename, 'w')

        # Verify dict and construct connection client.
        log.info("setting VadcpClient with config: %s" % config)
        try:
            self._client = VadcpClient(config, u4_outfile, u5_outfile)
        except (TypeError, KeyError):
            raise InstrumentParameterException('Invalid comms config dict.'
                                               ' config=%s' % config)

        self._driver_event(DriverAsyncEvent.STATE_CHANGE)
        self._state = DriverState.DISCONNECTED