def test_get_set(self): self._connect() cp = (BarsChannel.INSTRUMENT, BarsParameter.TIME_BETWEEN_BURSTS) params = [cp] result = self._get(params) seconds = result.get(cp) assert isinstance(seconds, int) driver = self.driver new_seconds = seconds + 5 if new_seconds > 30 or new_seconds < 15: new_seconds = 15 # get a parameter result = driver.set({cp: new_seconds}) print "set result = %s" % str(result) code = result.get(cp) InstErrorCode.is_ok(code) self._assert_auto_sample() result = self._get(params) seconds = result.get(cp) self.assertEqual(new_seconds, seconds) time.sleep(1) self._disconnect()
def set(self, params, *args, **kwargs): """ """ # TODO it only handles BarsParameter.TIME_BETWEEN_BURSTS if log.isEnabledFor(logging.DEBUG): log.debug("params=%s args=%s kwargs=%s" % (str(params), str(args), str(kwargs))) assert isinstance(params, dict) updated_params = 0 result = {} for (param, value) in params.items(): if param == BarsParameter.TIME_BETWEEN_BURSTS: result[param] = self._set_cycle_time(value) if InstErrorCode.is_ok(result[param]): updated_params += 1 else: result[param] = InstErrorCode.INVALID_PARAMETER msg = "%s parameter(s) successfully set." % updated_params log.debug("announcing to driver: %s" % msg) self.announce_to_driver(DriverAnnouncement.CONFIG_CHANGE, msg=msg) return result
def _handler_observatory_go_inactive(self, *args, **kwargs): """ Handler for go_inactive agent command in observatory state. Attempt to disconnect and initialize all active driver channels. Switch to inactive state if successful. """ result = None next_state = None channels = self._dvr_client.cmd_dvr('get_active_channels') dis_result = self._dvr_client.cmd_dvr('disconnect', channels) [key for (key, val) in dis_result.iteritems() if not InstErrorCode.is_error(val)] init_result = self._dvr_client.cmd_dvr('initialize', channels) result = dis_result.copy() for (key, val) in init_result.iteritems(): result[key] = val self._active_channels = self._dvr_client.cmd_dvr('get_active_channels') if len(self._active_channels)==0: next_state = InstrumentAgentState.INACTIVE return (next_state, result)
def _handler_inactive_go_active(self, dvr_comms=None, *args, **kwargs): """ Handler for go_active agent command in inactive state. Attempt to establsih communications with all device channels. Switch to active state if any channels activated. """ result = None next_state = None if not dvr_comms: dvr_comms = self._dvr_config.get('comms_config', None) cfg_result = self._dvr_client.cmd_dvr('configure', dvr_comms) channels = [key for (key, val) in cfg_result.iteritems() if not InstErrorCode.is_error(val)] con_result = self._dvr_client.cmd_dvr('connect', channels) result = cfg_result.copy() for (key, val) in con_result.iteritems(): result[key] = val self._active_channels = self._dvr_client.cmd_dvr('get_active_channels') if len(self._active_channels)>0: next_state = InstrumentAgentState.IDLE return (next_state, result)
def set(self, params, *args, **kwargs): """ Sets the given parameters. It handles TIME_BETWEEN_BURSTS, VERBOSE_MODE. Once the parameters are set, it does a DriverAnnouncement .CONFIG_CHANGE. (removed after refactoring) """ if log.isEnabledFor(logging.DEBUG): log.debug("params=%s args=%s kwargs=%s" % (str(params), str(args), str(kwargs))) assert isinstance(params, dict) # TODO actually it should be ATTACHED if we want consistency with the # states related with connection and attachment. self._assert_state(DriverState.CONNECTED) timeout = kwargs.get('timeout', self._timeout) self.trhph_client.go_to_main_menu(timeout) updated_params = 0 result = {} for (param, value) in params.items(): if param == TrhphParameter.TIME_BETWEEN_BURSTS: result[param] = self._set_cycle_time(value, timeout) if InstErrorCode.is_ok(result[param]): updated_params += 1 elif param == TrhphParameter.VERBOSE_MODE: result[param] = self.set_is_data_only(value, timeout) if InstErrorCode.is_ok(result[param]): updated_params += 1 else: result[param] = InstErrorCode.INVALID_PARAMETER # msg = "%s parameter(s) successfully set." % updated_params # log.debug("announcing to driver: %s" % msg) # self.announce_to_driver(DriverAnnouncement.CONFIG_CHANGE, msg=msg) return result