def _send(self, s, info=None): """ Sends a string. Returns the number of bytes written. @param s the string to send @param info string for logging purposes """ c = self._sock.send(s) if log.isEnabledFor(logging.INFO): info_str = (' (%s)' % info) if info else '' log.info("_send:%s%s" % (repr(s), info_str)) return c
def execute_stop_autosample(self, *args, **kwargs): if log.isEnabledFor(logging.DEBUG): log.debug("args=%s kwargs=%s" % (str(args), str(kwargs))) self._assert_state(DriverState.CONNECTED) timeout = kwargs.get('timeout', self._timeout) try: result = self._client.stop_autosample(timeout=timeout) return result except TimeoutException, e: raise InstrumentTimeoutException(msg=str(e))
def execute_get_metadata(self, *args, **kwargs): if log.isEnabledFor(logging.DEBUG): log.debug("args=%s kwargs=%s" % (str(args), str(kwargs))) self._assert_state(DriverState.CONNECTED) timeout = kwargs.get('timeout', self._timeout) sections = kwargs.get('sections', None) try: result = self._client.get_metadata(sections, timeout) return result except TimeoutException, e: raise InstrumentTimeoutException(msg=str(e))
def _handler_command_run_all_tests(self, *args, **kwargs): """ """ if log.isEnabledFor(logging.DEBUG): log.debug("args=%s kwargs=%s" % (str(args), str(kwargs))) next_state = self._protocol_fsm.get_current_state() result = None timeout = kwargs.get('timeout', self._timeout) try: result = self._connection.run_all_tests(timeout) except TimeoutException, e: raise InstrumentTimeoutException(msg=str(e))
def _handler_autosample_stop(self, *args, **kwargs): """ """ if log.isEnabledFor(logging.DEBUG): log.debug("args=%s kwargs=%s" % (str(args), str(kwargs))) next_state = None result = None duration = int(kwargs.get('duration', 1000)) try: result = self._connection.send_break(duration) next_state = ProtocolState.COMMAND_MODE except TimeoutException, e: raise InstrumentTimeoutException(msg=str(e))
def disconnect(self, *args, **kwargs): """ Disconnect from device via port agent / logger. @raises InstrumentStateException if command not allowed in current state """ if log.isEnabledFor(logging.DEBUG): log.debug("args=%s kwargs=%s" % (str(args), str(kwargs))) self._assert_state(DriverState.CONNECTED) self._client.end() self._driver_event(DriverAsyncEvent.STATE_CHANGE) self._state = DriverState.DISCONNECTED
def _handler_command_autosample(self, *args, **kwargs): """ """ if log.isEnabledFor(logging.DEBUG): log.debug("args=%s kwargs=%s" % (str(args), str(kwargs))) next_state = None result = None timeout = kwargs.get('timeout', self._timeout) try: result = self._connection.start_autosample(timeout=timeout) next_state = ProtocolState.AUTOSAMPLE_MODE except TimeoutException, e: raise InstrumentTimeoutException(msg=str(e))
def connect(self, *args, **kwargs): """ Establish communications with the device via port agent / logger (connected connection object). @raises InstrumentStateException if command not allowed in current state @throws InstrumentConnectionException if the connection failed. """ if log.isEnabledFor(logging.DEBUG): log.debug("args=%s kwargs=%s" % (str(args), str(kwargs))) self._assert_state(DriverState.DISCONNECTED) self._client.set_data_listener(self._data_listener) self._client.connect() self._driver_event(DriverAsyncEvent.STATE_CHANGE) self._state = DriverState.CONNECTED
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
def initialize(self, *args, **kwargs): """ Initialize driver connection, bringing communications parameters into unconfigured state (no connection object). @raises InstrumentStateException if command not allowed in current state """ if log.isEnabledFor(logging.DEBUG): log.debug("args=%s kwargs=%s" % (str(args), str(kwargs))) if self._state == DriverState.UNCONFIGURED: assert self._client is None return if self._client is not None: try: self._client.end() finally: self._client = None self._driver_event(DriverAsyncEvent.STATE_CHANGE) self._state = DriverState.UNCONFIGURED