Esempio n. 1
0
    def setUp(self):
        """
        Sets up and connects the _client.
        """

        TrhphClientTest._end_client_if_any()

        super(TrhphClientTest, self).setUp()

        host = self.device_address
        port = self.device_port
        self._samples_recd = 0
        outfile = file('trhph_output.txt', 'a')
        prefix_state = True
        _client = TrhphClient(host, port, outfile, prefix_state)

        # set the class and instance variables to refer to this object:
        TrhphClientTest._trhph_client = self._client = _client

        # prepare client including going to the main menu
        _client.set_data_listener(self._data_listener)
        _client.set_generic_timeout(self._timeout)

        log.info("connecting")
        _client.connect()
Esempio n. 2
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(TrhphDriverState.UNCONFIGURED)

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

        # Verify dict and construct connection client.
        try:
            addr = config['addr']
            port = config['port']

            if isinstance(addr, str) and \
               isinstance(port, int) and len(addr) > 0:
                #                self._connection = LoggerClient(addr, port)

                def _data_listener(sample):
                    log.info("_data_listener: sample = %s" % str(sample))

                host = addr
                outfile = file('trhph_output.txt', 'a')
                log.info("setting TrhphClient to connect to %s:%s" %
                         (host, port))
                self.trhph_client = TrhphClient(host, port, outfile, True)
                self.trhph_client.set_data_listener(_data_listener)

            else:
                raise InstrumentParameterException(
                    msg='Invalid comms config dict')

        except (TypeError, KeyError):
            raise InstrumentParameterException(
                msg='Invalid comms config dict.')

        self._state = TrhphDriverState.DISCONNECTED