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 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