本文整理汇总了Python中mi.core.instrument.protocol_param_dict.ProtocolParameterDict.get_init_value方法的典型用法代码示例。如果您正苦于以下问题:Python ProtocolParameterDict.get_init_value方法的具体用法?Python ProtocolParameterDict.get_init_value怎么用?Python ProtocolParameterDict.get_init_value使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mi.core.instrument.protocol_param_dict.ProtocolParameterDict
的用法示例。
在下文中一共展示了ProtocolParameterDict.get_init_value方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestUnitProtocolParameterDict
# 需要导入模块: from mi.core.instrument.protocol_param_dict import ProtocolParameterDict [as 别名]
# 或者: from mi.core.instrument.protocol_param_dict.ProtocolParameterDict import get_init_value [as 别名]
#.........这里部分代码省略.........
self.assertEqual(val, False)
# fn_bar does not get updated here
result = self.param_dict.update_many(1205)
self.assertEqual(result['fn_foo'], True)
self.assertEqual(len(result), 1)
val = self.param_dict.get("fn_foo")
self.assertEqual(val, 4)
val = self.param_dict.get("fn_bar")
self.assertEqual(val, False)
# both are updated now
result = self.param_dict.update_many(6)
self.assertEqual(result['fn_foo'], True)
self.assertEqual(result['fn_bar'], True)
self.assertEqual(len(result), 2)
val = self.param_dict.get("fn_foo")
self.assertEqual(val, 0)
val = self.param_dict.get("fn_bar")
self.assertEqual(val, True)
def test_mixed_pdv_types(self):
""" Verify we can add different types of PDVs in one container """
self.param_dict.add_paramdictval(
FunctionParamDictVal(
"fn_foo",
self.pick_byte2,
lambda x : str(x),
direct_access=True,
startup_param=True,
value=1,
visibility=ParameterDictVisibility.READ_WRITE)
)
self.param_dict.add_paramdictval(
RegexParamDictVal("foo", r'.*foo=(\d+).*',
lambda match : int(match.group(1)),
lambda x : str(x),
direct_access=True,
startup_param=True,
value=10,
visibility=ParameterDictVisibility.READ_WRITE)
)
self.param_dict.add("bar", r'.*bar=(\d+).*',
lambda match : int(match.group(1)),
lambda x : str(x),
direct_access=False,
startup_param=True,
value=15,
visibility=ParameterDictVisibility.READ_WRITE)
self.assertEqual(self.param_dict.get("fn_foo"), 1)
self.assertEqual(self.param_dict.get("foo"), 10)
self.assertEqual(self.param_dict.get("bar"), 15)
def test_base_update(self):
pdv = ParameterDictVal("foo",
lambda x : str(x),
value=12)
self.assertEqual(pdv.value, 12)
result = pdv.update(1)
self.assertEqual(result, True)
self.assertEqual(pdv.value, 1)
# Its a base class...monkey see, monkey do
result = pdv.update("foo=1")
self.assertEqual(result, True)
self.assertEqual(pdv.value, "foo=1")
def test_regex_val(self):
pdv = RegexParamDictVal("foo",
r'.*foo=(\d+).*',
lambda match : int(match.group(1)),
lambda x : str(x),
value=12)
self.assertEqual(pdv.value, 12)
result = pdv.update(1)
self.assertEqual(result, False)
self.assertEqual(pdv.value, 12)
result = pdv.update("foo=1")
self.assertEqual(result, True)
self.assertEqual(pdv.value, 1)
def test_function_val(self):
pdv = FunctionParamDictVal("foo",
self.pick_byte2,
lambda x : str(x),
value=12)
self.assertEqual(pdv.value, 12)
self.assertRaises(TypeError, pdv.update(1))
result = pdv.update("1205")
self.assertEqual(pdv.value, 4)
self.assertEqual(result, True)
def test_set_init_value(self):
result = self.param_dict.get("foo")
self.assertEqual(result, None)
self.param_dict.set_init_value("foo", 42)
result = self.param_dict.get_init_value("foo")
self.assertEqual(result, 42)
示例2: TestUnitProtocolParameterDict
# 需要导入模块: from mi.core.instrument.protocol_param_dict import ProtocolParameterDict [as 别名]
# 或者: from mi.core.instrument.protocol_param_dict.ProtocolParameterDict import get_init_value [as 别名]
#.........这里部分代码省略.........
result = pdv.update("foo=1")
self.assertEqual(result, True)
self.assertEqual(pdv.get_value(), "foo=1")
def test_regex_val(self):
pdv = RegexParameter("foo",
r'.*foo=(\d+).*',
lambda match: int(match.group(1)),
lambda x: str(x),
value=12)
self.assertEqual(pdv.get_value(), 12)
result = pdv.update(1)
self.assertEqual(result, False)
self.assertEqual(pdv.get_value(), 12)
result = pdv.update("foo=1")
self.assertEqual(result, True)
self.assertEqual(pdv.get_value(), 1)
def test_function_val(self):
pdv = FunctionParameter("foo",
self.pick_byte2,
lambda x: str(x),
value=12)
self.assertEqual(pdv.get_value(), 12)
self.assertRaises(TypeError, pdv.update(1))
result = pdv.update("1205")
self.assertEqual(pdv.get_value(), 4)
self.assertEqual(result, True)
def test_set_init_value(self):
result = self.param_dict.get("foo")
self.assertEqual(result, None)
self.param_dict.set_init_value("foo", 42)
result = self.param_dict.get_init_value("foo")
self.assertEqual(result, 42)
def test_schema_generation(self):
self.maxDiff = None
result = self.param_dict.generate_dict()
json_result = json.dumps(result, indent=4, sort_keys=True)
log.debug("Expected: %s", self.target_schema)
log.debug("Result: %s", json_result)
self.assertEqual(result, self.target_schema)
def test_empty_schema(self):
self.param_dict = ProtocolParameterDict()
result = self.param_dict.generate_dict()
self.assertEqual(result, {})
def test_bad_descriptions(self):
self.param_dict._param_dict["foo"].description = None
self.param_dict._param_dict["foo"].value = None
self.assertRaises(InstrumentParameterException,
self.param_dict.get_init_value, "foo")
self.assertRaises(InstrumentParameterException,
self.param_dict.get_default_value, "foo")
self.assertRaises(InstrumentParameterException,
self.param_dict.set_default, "foo")
self.assertRaises(InstrumentParameterException,
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")
示例3: InstrumentProtocol
# 需要导入模块: from mi.core.instrument.protocol_param_dict import ProtocolParameterDict [as 别名]
# 或者: from mi.core.instrument.protocol_param_dict.ProtocolParameterDict import get_init_value [as 别名]
#.........这里部分代码省略.........
"""
Set the initialization parameters to the given values in the protocol
parameter dictionary.
@param config The parameter_name/value to set in the initialization
fields of the parameter dictionary
@raise InstrumentParameterException If the config cannot be set
"""
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.set_init_value(name, param_config[name])
def get_startup_config(self):
"""
Gets the startup configuration for the instrument. The parameters
returned are marked as startup, and the values are the best as chosen
from the initialization, default, and current parameters.
@retval The dict of parameter_name/values (override this method if it
is more involved for a specific instrument) that should be set at
a higher level.
"""
return_dict = {}
start_list = self._param_dict.get_startup_list()
log.trace("Startup list: %s", start_list)
assert isinstance(start_list, list)
for param in start_list:
result = self._param_dict.get_init_value(param)
if result != None:
log.trace("Got init value for %s: %s", param, result)
return_dict[param] = result
else:
result = self._param_dict.get_default_value(param)
if result != None:
log.trace("Got default value for %s: %s", param, result)
return_dict[param] = result
else:
log.trace("Got current value for %s: %s", param, result)
return_dict[param] = self._param_dict.get(param)
return return_dict
def get_direct_access_params(self):
"""
Get the list of direct access parameters, useful for restoring direct
access configurations up in the driver.
@retval a list of direct access parameter names
"""
return self._param_dict.get_direct_access_list()
def get_cached_config(self):
"""
Return the configuration object that shows the instrument's
configuration as cached in the parameter dictionary...usually in
sync with the instrument, but accessible when offline...
@retval The cached configuration in the instruments config format. By
default, it is a dictionary of parameter names and values.
"""
assert self._param_dict != None