本文整理汇总了Python中mi.core.instrument.protocol_param_dict.ProtocolParameterDict.set_value方法的典型用法代码示例。如果您正苦于以下问题:Python ProtocolParameterDict.set_value方法的具体用法?Python ProtocolParameterDict.set_value怎么用?Python ProtocolParameterDict.set_value使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mi.core.instrument.protocol_param_dict.ProtocolParameterDict
的用法示例。
在下文中一共展示了ProtocolParameterDict.set_value方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get
# 需要导入模块: from mi.core.instrument.protocol_param_dict import ProtocolParameterDict [as 别名]
# 或者: from mi.core.instrument.protocol_param_dict.ProtocolParameterDict import set_value [as 别名]
def test_get(self):
"""
test getting values with expiration
"""
# from mi.core.exceptions import InstrumentParameterExpirationException
pd = ProtocolParameterDict()
# No expiration, should work just fine
pd.add('noexp', r'', None, None, expiration=None)
pd.add('zeroexp', r'', None, None, expiration=0)
pd.add('lateexp', r'', None, None, expiration=2)
###
# Set and get with no expire
###
pd.set_value('noexp', 1)
self.assertEqual(pd.get('noexp'), 1)
###
# Set and get with a 0 expire
###
basetime = pd.get_current_timestamp()
pd.set_value('zeroexp', 2)
# We should fail because we are calculating exp against current time
with self.assertRaises(InstrumentParameterExpirationException):
pd.get('zeroexp')
# Should succeed because exp is calculated using basetime
self.assertEqual(pd.get('zeroexp', basetime), 2)
###
# Set and get with a delayed expire
###
basetime = pd.get_current_timestamp()
futuretime = pd.get_current_timestamp(3)
self.assertGreater(futuretime - basetime, 3)
pd.set_value('lateexp', 2)
# Success because data is not expired
self.assertEqual(pd.get('lateexp', basetime), 2)
# Fail because data is expired (simulated three seconds from now)
with self.assertRaises(InstrumentParameterExpirationException):
pd.get('lateexp', futuretime)
示例2: Protocol
# 需要导入模块: from mi.core.instrument.protocol_param_dict import ProtocolParameterDict [as 别名]
# 或者: from mi.core.instrument.protocol_param_dict.ProtocolParameterDict import set_value [as 别名]
#.........这里部分代码省略.........
timestamp)
def _filter_capabilities(self, events):
"""
Return a list of currently available capabilities.
"""
return [x for x in events if Capability.has(x)]
########################################################################
# implement virtual methods from base class.
########################################################################
def _set_params(self, *args, **kwargs):
"""
Issue commands to the instrument to set various parameters. If
startup is set to true that means we are setting startup values
and immutable parameters can be set. Otherwise only READ_WRITE
parameters can be set.
must be overloaded in derived classes
@param params dictionary containing parameter name and value pairs
@param startup - a flag, true indicates initializing, false otherwise
"""
params = args[0]
# check for attempt to set readonly parameters (read-only or immutable set outside startup)
self._verify_not_readonly(*args, **kwargs)
old_config = self._param_dict.get_config()
for (key, val) in params.iteritems():
log.debug("KEY = " + str(key) + " VALUE = " + str(val))
self._param_dict.set_value(key, val)
new_config = self._param_dict.get_config()
# check for parameter change
if not dict_equal(old_config, new_config):
self._driver_event(DriverAsyncEvent.CONFIG_CHANGE)
def apply_startup_params(self):
"""
Apply startup parameters
"""
config = self.get_startup_config()
for param in Parameter.list():
if param in config:
self._param_dict.set_value(param, config[param])
########################################################################
# Private helpers.
########################################################################
def _wakeup(self, wakeup_timeout=10, response_timeout=3):
"""
Over-ridden because the D1000 does not go to sleep and requires no special wake-up commands.
@param wakeup_timeout The timeout to wake the device.
@param response_timeout The time to look for response to a wakeup attempt.
@throw InstrumentTimeoutException if the device could not be woken.
"""
pass
def _do_command(self, cmd, unit, **kwargs):
"""
示例3: Protocol
# 需要导入模块: from mi.core.instrument.protocol_param_dict import ProtocolParameterDict [as 别名]
# 或者: from mi.core.instrument.protocol_param_dict.ProtocolParameterDict import set_value [as 别名]
#.........这里部分代码省略.........
self._int_to_string,
type=ParameterDictType.INT,
default_value=FLUSH_MIN_RATE,
units=Prefixes.MILLI + Units.LITER + "/" + Units.MINUTE,
startup_param=True,
display_name="Flush Minimum Flow",
description="If the flow rate falls below this value the flush will be terminated, "
"obstruction suspected: (75 - 100)",
visibility=ParameterDictVisibility.IMMUTABLE,
)
self._param_dict.add(
Parameter.FILL_VOLUME,
r"Fill Volume: (.*)mL",
None,
self._int_to_string,
type=ParameterDictType.INT,
default_value=FILL_VOLUME,
units=Prefixes.MILLI + Units.LITER,
startup_param=True,
display_name="Fill Volume",
description="Amount of seawater to run through the collection filter (10 - 20000)",
visibility=ParameterDictVisibility.IMMUTABLE,
)
self._param_dict.add(
Parameter.FILL_FLOWRATE,
r"Fill Flow Rate: (.*)mL/min",
None,
self._int_to_string,
type=ParameterDictType.INT,
default_value=FILL_RATE,
units=Prefixes.MILLI + Units.LITER + "/" + Units.MINUTE,
startup_param=True,
display_name="Fill Flow Rate",
description="Flow rate during sampling: (100 - 250)",
visibility=ParameterDictVisibility.IMMUTABLE,
)
self._param_dict.add(
Parameter.FILL_MINFLOW,
r"Fill Min Flow: (.*)mL/min",
None,
self._int_to_string,
type=ParameterDictType.INT,
default_value=FILL_MIN_RATE,
units=Prefixes.MILLI + Units.LITER + "/" + Units.MINUTE,
startup_param=True,
display_name="Fill Minimum Flow",
description="If the flow rate falls below this value the fill will be terminated, "
"obstruction suspected: (75 - 100)",
visibility=ParameterDictVisibility.IMMUTABLE,
)
self._param_dict.add(
Parameter.CLEAR_VOLUME,
r"Reverse Volume: (.*)mL",
None,
self._int_to_string,
type=ParameterDictType.INT,
default_value=CLEAR_VOLUME,
units=Prefixes.MILLI + Units.LITER,
startup_param=True,
display_name="Clear Volume",
description="Amount of sea water to flush the home port after taking sample: (10 - 20000)",
visibility=ParameterDictVisibility.IMMUTABLE,
)
self._param_dict.add(
Parameter.CLEAR_FLOWRATE,
r"Reverse Flow Rate: (.*)mL/min",
None,
self._int_to_string,
type=ParameterDictType.INT,
default_value=CLEAR_RATE,
units=Prefixes.MILLI + Units.LITER + "/" + Units.MINUTE,
startup_param=True,
display_name="Clear Flow Rate",
description="Rate at which to flush: (100 - 250)",
visibility=ParameterDictVisibility.IMMUTABLE,
)
self._param_dict.add(
Parameter.CLEAR_MINFLOW,
r"Reverse Min Flow: (.*)mL/min",
None,
self._int_to_string,
type=ParameterDictType.INT,
default_value=CLEAR_MIN_RATE,
units=Prefixes.MILLI + Units.LITER + "/" + Units.MINUTE,
startup_param=True,
display_name="Clear Minimum Flow",
description="If the flow rate falls below this value the reverse flush will be terminated, "
"obstruction suspected: (75 - 100)",
visibility=ParameterDictVisibility.IMMUTABLE,
)
self._param_dict.set_value(Parameter.FLUSH_VOLUME, FLUSH_VOLUME)
self._param_dict.set_value(Parameter.FLUSH_FLOWRATE, FLUSH_RATE)
self._param_dict.set_value(Parameter.FLUSH_MINFLOW, FLUSH_MIN_RATE)
self._param_dict.set_value(Parameter.FILL_VOLUME, FILL_VOLUME)
self._param_dict.set_value(Parameter.FILL_FLOWRATE, FILL_RATE)
self._param_dict.set_value(Parameter.FILL_MINFLOW, FILL_MIN_RATE)
self._param_dict.set_value(Parameter.CLEAR_VOLUME, CLEAR_VOLUME)
self._param_dict.set_value(Parameter.CLEAR_FLOWRATE, CLEAR_RATE)
self._param_dict.set_value(Parameter.CLEAR_MINFLOW, CLEAR_MIN_RATE)
示例4: TestUnitProtocolParameterDict
# 需要导入模块: from mi.core.instrument.protocol_param_dict import ProtocolParameterDict [as 别名]
# 或者: from mi.core.instrument.protocol_param_dict.ProtocolParameterDict import set_value [as 别名]
#.........这里部分代码省略.........
self.param_dict.get_init_value, "foo")
self.assertRaises(InstrumentParameterException,
self.param_dict.get_menu_path_read, "foo")
self.assertRaises(InstrumentParameterException,
self.param_dict.get_submenu_read, "foo")
self.assertRaises(InstrumentParameterException,
self.param_dict.get_menu_path_write, "foo")
self.assertRaises(InstrumentParameterException,
self.param_dict.get_submenu_write, "foo")
self.assertRaises(InstrumentParameterException,
self.param_dict.format, "foo", 1)
self.assertRaises(InstrumentParameterException,
self.param_dict.get_direct_access_list)
self.assertRaises(InstrumentParameterException,
self.param_dict.is_startup_param, "foo")
def test_set(self):
"""
Test a simple set of the parameter. Make sure the right values get
called and the correct exceptions are raised.
"""
new_param = FunctionParameter("foo",
self.pick_byte2,
lambda x: str(x),
direct_access=True,
startup_param=True,
value=1000,
visibility=ParameterDictVisibility.READ_WRITE)
self.assertEquals(new_param.get_value(), 1000)
self.assertEquals(self.param_dict.get("foo"), None)
# overwrites existing param
self.param_dict.add_parameter(new_param)
self.assertEquals(self.param_dict.get("foo"), 1000)
self.param_dict.set_value("foo", 2000)
self.assertEquals(self.param_dict.get("foo"), 2000)
def test_invalid_type(self):
self.assertRaises(InstrumentParameterException,
FunctionParameter,
"fn_bar",
lambda x: bool(x & 2), # bit map example
lambda x: str(x),
direct_access=True,
startup_param=True,
value=False,
type="bad_type",
visibility=ParameterDictVisibility.READ_WRITE)
def test_get(self):
"""
test getting values with expiration
"""
# from mi.core.exceptions import InstrumentParameterExpirationException
pd = ProtocolParameterDict()
# No expiration, should work just fine
pd.add('noexp', r'', None, None, expiration=None)
pd.add('zeroexp', r'', None, None, expiration=0)
pd.add('lateexp', r'', None, None, expiration=2)
###
# Set and get with no expire
###
pd.set_value('noexp', 1)
self.assertEqual(pd.get('noexp'), 1)
示例5: Protocol
# 需要导入模块: from mi.core.instrument.protocol_param_dict import ProtocolParameterDict [as 别名]
# 或者: from mi.core.instrument.protocol_param_dict.ProtocolParameterDict import set_value [as 别名]
#.........这里部分代码省略.........
self._param_dict.add(Parameter.FLUSH_VOLUME,
r'Flush Volume: (.*)mL',
None,
self._int_to_string,
type=ParameterDictType.INT,
default_value=FLUSH_VOLUME,
units='mL',
startup_param=True,
display_name="flush_volume",
visibility=ParameterDictVisibility.IMMUTABLE)
self._param_dict.add(Parameter.FLUSH_FLOWRATE,
r'Flush Flow Rate: (.*)mL/min',
None,
self._int_to_string,
type=ParameterDictType.INT,
default_value=FLUSH_RATE,
units='mL/min',
startup_param=True,
display_name="flush_flow_rate",
visibility=ParameterDictVisibility.IMMUTABLE)
self._param_dict.add(Parameter.FLUSH_MINFLOW,
r'Flush Min Flow: (.*)mL/min',
None,
self._int_to_string,
type=ParameterDictType.INT,
default_value=FLUSH_MIN_RATE,
units='mL/min',
startup_param=True,
display_name="flush_min_flow",
visibility=ParameterDictVisibility.IMMUTABLE)
self._param_dict.add(Parameter.FILL_VOLUME,
r'Fill Volume: (.*)mL',
None,
self._int_to_string,
type=ParameterDictType.INT,
default_value=FILL_VOLUME,
units='mL',
startup_param=True,
display_name="fill_volume",
visibility=ParameterDictVisibility.IMMUTABLE)
self._param_dict.add(Parameter.FILL_FLOWRATE,
r'Fill Flow Rate: (.*)mL/min',
None,
self._int_to_string,
type=ParameterDictType.INT,
default_value=FILL_RATE,
units='mL/min',
startup_param=True,
display_name="fill_flow_rate",
visibility=ParameterDictVisibility.IMMUTABLE)
self._param_dict.add(Parameter.FILL_MINFLOW,
r'Fill Min Flow: (.*)mL/min',
None,
self._int_to_string,
type=ParameterDictType.INT,
default_value=FILL_MIN_RATE,
units='mL/min',
startup_param=True,
display_name="fill_min_flow",
visibility=ParameterDictVisibility.IMMUTABLE)
self._param_dict.add(Parameter.CLEAR_VOLUME,
r'Reverse Volume: (.*)mL',
None,
self._int_to_string,
type=ParameterDictType.INT,
default_value=CLEAR_VOLUME,
units='mL',
startup_param=True,
display_name="clear_volume",
visibility=ParameterDictVisibility.IMMUTABLE)
self._param_dict.add(Parameter.CLEAR_FLOWRATE,
r'Reverse Flow Rate: (.*)mL/min',
None,
self._int_to_string,
type=ParameterDictType.INT,
default_value=CLEAR_RATE,
units='mL/min',
startup_param=True,
display_name="clear_flow_rate",
visibility=ParameterDictVisibility.IMMUTABLE)
self._param_dict.add(Parameter.CLEAR_MINFLOW,
r'Reverse Min Flow: (.*)mL/min',
None,
self._int_to_string,
type=ParameterDictType.INT,
default_value=CLEAR_MIN_RATE,
units='mL/min',
startup_param=True,
display_name="clear_min_flow",
visibility=ParameterDictVisibility.IMMUTABLE)
self._param_dict.set_value(Parameter.FLUSH_VOLUME, FLUSH_VOLUME)
self._param_dict.set_value(Parameter.FLUSH_FLOWRATE, FLUSH_RATE)
self._param_dict.set_value(Parameter.FLUSH_MINFLOW, FLUSH_MIN_RATE)
self._param_dict.set_value(Parameter.FILL_VOLUME, FILL_VOLUME)
self._param_dict.set_value(Parameter.FILL_FLOWRATE, FILL_RATE)
self._param_dict.set_value(Parameter.FILL_MINFLOW, FILL_MIN_RATE)
self._param_dict.set_value(Parameter.CLEAR_VOLUME, CLEAR_VOLUME)
self._param_dict.set_value(Parameter.CLEAR_FLOWRATE, CLEAR_RATE)
self._param_dict.set_value(Parameter.CLEAR_MINFLOW, CLEAR_MIN_RATE)
示例6: DataSetDriver
# 需要导入模块: from mi.core.instrument.protocol_param_dict import ProtocolParameterDict [as 别名]
# 或者: from mi.core.instrument.protocol_param_dict.ProtocolParameterDict import set_value [as 别名]
#.........这里部分代码省略.........
capabilities.
@raises NotImplementedException if not implemented by subclass.
"""
res_params = self._param_dict.get_keys()
res_cmds = [DriverEvent.STOP_AUTOSAMPLE, DriverEvent.START_AUTOSAMPLE]
if current_state and self._is_sampling():
res_cmds = [DriverEvent.STOP_AUTOSAMPLE]
elif current_state and not self._is_sampling():
res_cmds = [DriverEvent.START_AUTOSAMPLE]
return [res_cmds, res_params]
def set_resource(self, *args, **kwargs):
"""
Set the driver parameter
"""
log.trace("start set_resource")
try:
params = args[0]
except IndexError:
raise InstrumentParameterException('Set command requires a parameter dict.')
log.trace("set_resource: iterate through params: %s", params)
for (key, val) in params.iteritems():
if key in [DriverParameter.BATCHED_PARTICLE_COUNT, DriverParameter.RECORDS_PER_SECOND]:
if not isinstance(val, int): raise InstrumentParameterException("%s must be an integer" % key)
if key in [DriverParameter.PUBLISHER_POLLING_INTERVAL]:
if not isinstance(val, (int, float)): raise InstrumentParameterException("%s must be an float" % key)
if val <= 0:
raise InstrumentParameterException("%s must be > 0" % key)
self._param_dict.set_value(key, val)
# Set the driver parameters
self._generate_particle_count = self._param_dict.get(DriverParameter.BATCHED_PARTICLE_COUNT)
self._particle_count_per_second = self._param_dict.get(DriverParameter.RECORDS_PER_SECOND)
self._polling_interval = self._param_dict.get(DriverParameter.PUBLISHER_POLLING_INTERVAL)
log.trace("Driver Parameters: %s, %s, %s", self._polling_interval, self._particle_count_per_second, self._generate_particle_count)
def get_resource(self, *args, **kwargs):
"""
Get driver parameter
"""
result = {}
try:
params = args[0]
except IndexError:
raise InstrumentParameterException('Set command requires a parameter list.')
# If all params requested, retrieve config.
if params == DriverParameter.ALL:
result = self._param_dict.get_config()
# If not all params, confirm a list or tuple of params to retrieve.
# Raise if not a list or tuple.
# Retrieve each key in the list, raise if any are invalid.
else:
if not isinstance(params, (list, tuple)):
raise InstrumentParameterException('Get argument not a list or tuple.')
result = {}
for key in params:
try:
val = self._param_dict.get(key)
示例7: Protocol
# 需要导入模块: from mi.core.instrument.protocol_param_dict import ProtocolParameterDict [as 别名]
# 或者: from mi.core.instrument.protocol_param_dict.ProtocolParameterDict import set_value [as 别名]
#.........这里部分代码省略.........
return [x for x in events if Capability.has(x)]
def _build_command_dict(self):
"""
Populate the command dictionary with commands.
"""
self._cmd_dict.add(Capability.START_AUTOSAMPLE, display_name="Start Autosample")
self._cmd_dict.add(Capability.STOP_AUTOSAMPLE, display_name="Stop Autosample")
def _build_driver_dict(self):
"""
Populate the driver dictionary with options
"""
self._driver_dict.add(DriverDictKey.VENDOR_SW_COMPATIBLE, False)
def _update_params(self, *args, **kwargs):
"""
Update the param dictionary based on instrument response
"""
def _set_params(self, *args, **kwargs):
if len(args) < 1:
raise InstrumentParameterException("Set command requires a parameter dict.")
params = args[0]
if not isinstance(params, dict):
raise InstrumentParameterException("Set parameters not a dict.")
self._param_dict = ProtocolParameterDict()
for param in params:
log.info("Creating new parameter: %s", param)
self._param_dict.add(param, "", None, None)
self._param_dict.set_value(param, params[param])
def set_init_params(self, config):
if not isinstance(config, dict):
raise InstrumentParameterException("Invalid init config format")
self._startup_config = config
param_config = config.get(DriverConfigKey.PARAMETERS)
if param_config:
for name in param_config.keys():
self._param_dict.add(name, "", None, None)
log.debug("Setting init value for %s to %s", name, param_config[name])
self._param_dict.set_init_value(name, param_config[name])
def _very_long_command(self, *args, **kwargs):
return None, time.sleep(30)
########################################################################
# Unknown handlers.
########################################################################
def _handler_unknown_discover(self, *args, **kwargs):
"""
Process discover event
"""
next_state = ProtocolState.COMMAND
result = []
return next_state, (next_state, result)
########################################################################
# Autosample handlers.
########################################################################
示例8: DataSetDriver
# 需要导入模块: from mi.core.instrument.protocol_param_dict import ProtocolParameterDict [as 别名]
# 或者: from mi.core.instrument.protocol_param_dict.ProtocolParameterDict import set_value [as 别名]
#.........这里部分代码省略.........
def get_resource_capabilities(self, current_state=True, *args, **kwargs):
"""
Return driver commands and parameters.
@param current_state True to retrieve commands available in current
state, otherwise reutrn all commands.
@retval list of AgentCapability objects representing the drivers
capabilities.
@raises NotImplementedException if not implemented by subclass.
"""
res_params = self._param_dict.get_keys()
return [[], res_params]
def set_resource(self, *args, **kwargs):
"""
Set the driver parameter
"""
log.trace("start set_resource")
try:
params = args[0]
except IndexError:
raise InstrumentParameterException('Set command requires a parameter dict.')
log.trace("set_resource: iterate through params: %s", params)
for (key, val) in params.iteritems():
if key in [DriverParameter.BATCHED_PARTICLE_COUNT, DriverParameter.RECORDS_PER_SECOND]:
if not isinstance(val, int): raise InstrumentParameterException("%s must be an integer" % key)
if key in [DriverParameter.HARVESTER_POLLING_INTERVAL]:
if not isinstance(val, (int, float)): raise InstrumentParameterException("%s must be an float" % key)
if val <= 0:
raise InstrumentParameterException("%s must be > 0" % key)
self._param_dict.set_value(key, val)
# Set the driver parameters
self._generate_particle_count = self._param_dict.get(DriverParameter.BATCHED_PARTICLE_COUNT)
self._particle_count_per_second = self._param_dict.get(DriverParameter.RECORDS_PER_SECOND)
self._polling_interval = self._param_dict.get(DriverParameter.HARVESTER_POLLING_INTERVAL)
log.trace("Driver Parameters: %s, %s, %s", self._polling_interval, self._particle_count_per_second, self._generate_particle_count)
def get_resource(self, *args, **kwargs):
"""
Get driver parameter
"""
result = {}
try:
params = args[0]
except IndexError:
raise InstrumentParameterException('Set command requires a parameter list.')
# If all params requested, retrieve config.
if params == DriverParameter.ALL:
result = self._param_dict.get_config()
# If not all params, confirm a list or tuple of params to retrieve.
# Raise if not a list or tuple.
# Retrieve each key in the list, raise if any are invalid.
else:
if not isinstance(params, (list, tuple)):
raise InstrumentParameterException('Get argument not a list or tuple.')
result = {}
for key in params:
try:
val = self._param_dict.get(key)