本文整理汇总了Python中mi.core.instrument.protocol_param_dict.ProtocolParameterDict.update方法的典型用法代码示例。如果您正苦于以下问题:Python ProtocolParameterDict.update方法的具体用法?Python ProtocolParameterDict.update怎么用?Python ProtocolParameterDict.update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mi.core.instrument.protocol_param_dict.ProtocolParameterDict
的用法示例。
在下文中一共展示了ProtocolParameterDict.update方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Protocol
# 需要导入模块: from mi.core.instrument.protocol_param_dict import ProtocolParameterDict [as 别名]
# 或者: from mi.core.instrument.protocol_param_dict.ProtocolParameterDict import update [as 别名]
#.........这里部分代码省略.........
Populate the driver dictionary with options
"""
self._driver_dict.add(DriverDictKey.VENDOR_SW_COMPATIBLE, False)
def _build_command_dict(self):
"""
Populate the command dictionary with command.
"""
self._cmd_dict.add(Capability.START_AUTOSAMPLE, display_name="start autosample")
self._cmd_dict.add(Capability.STOP_AUTOSAMPLE, display_name="stop autosample")
self._cmd_dict.add(Capability.CLOCK_SYNC, display_name="synchronize clock")
self._cmd_dict.add(Capability.ACQUIRE_STATUS, display_name="acquire status")
self._cmd_dict.add(Capability.ACQUIRE_SAMPLE, display_name="acquire sample")
self._cmd_dict.add(Capability.FLASH_STATUS, display_name="flash status")
def _build_param_dict(self):
"""
Populate the parameter dictionary with XR-420 parameters.
For each parameter key add value formatting function for set commands.
"""
# The parameter dictionary.
self._param_dict = ProtocolParameterDict()
# Add parameter handlers to parameter dictionary for instrument configuration parameters.
self._param_dict.add(Parameter.CLOCK,
r'(.*)\r\n',
lambda match : match.group(1),
lambda string : str(string),
type=ParameterDictType.STRING,
display_name="clock",
expiration=0,
visibility=ParameterDictVisibility.READ_ONLY)
self._param_dict.add(Parameter.SAMPLE_INTERVAL,
r'Not used. This parameter is not parsed from instrument response',
None,
self._int_to_string,
type=ParameterDictType.INT,
default_value=30,
value=30,
startup_param=True,
display_name="sample_interval",
visibility=ParameterDictVisibility.IMMUTABLE)
def _update_params(self, *args, **kwargs):
"""
Update the parameter dictionary.
"""
log.debug("_update_params:")
# Issue clock command and parse results.
# This is the only parameter and it is always changing so don't bother with the 'change' event
self._do_cmd_resp(Command.GET_CLOCK)
def _build_set_clock_command(self, cmd, val):
"""
Build handler for set clock command (cmd=val followed by newline).
@param cmd the string for setting the clock (this should equal #CLOCK=).
@param val the parameter value to set.
@ retval The set command to be sent to the device.
"""
cmd = '%s%s' %(cmd, val) + NEWLINE
return cmd
def _parse_clock_response(self, response, prompt):
"""
Parse handler for clock command.
@param response command response string.
@param prompt prompt following command response.
@throws InstrumentProtocolException if clock command misunderstood.
"""
log.debug("_parse_clock_response: response=%s, prompt=%s" %(response, prompt))
if prompt not in [Prompt.CR_NL]:
raise InstrumentProtocolException('CLOCK command not recognized: %s.' % response)
if not self._param_dict.update(response):
raise InstrumentProtocolException('CLOCK command not parsed: %s.' % response)
return
def _parse_fs_response(self, response, prompt):
"""
Parse handler for FS command.
@param response command response string.
@param prompt prompt following command response.
@throws InstrumentProtocolException if FS command misunderstood.
"""
log.debug("_parse_fs_response: response=%s, prompt=%s" %(response, prompt))
if prompt not in [Prompt.FS]:
raise InstrumentProtocolException('FS command not recognized: %s.' % response)
return response
def _parse_common_response(self, response, prompt):
"""
Parse handler for common commands.
@param response command response string.
@param prompt prompt following command response.
"""
return response
示例2: TestUnitProtocolParameterDict
# 需要导入模块: from mi.core.instrument.protocol_param_dict import ProtocolParameterDict [as 别名]
# 或者: from mi.core.instrument.protocol_param_dict.ProtocolParameterDict import update [as 别名]
#.........这里部分代码省略.........
dummy: stuff
}
'''
def test_get_direct_access_list(self):
"""
Test to see we can get a list of direct access parameters
"""
result = self.param_dict.get_direct_access_list()
self.assertTrue(isinstance(result, list))
self.assertEquals(len(result), 3)
self.assert_("foo" in result)
self.assert_("baz" in result)
self.assert_("qut" in result)
def test_get_startup_list(self):
"""
Test to see we can get a list of direct access parameters
"""
result = self.param_dict.get_startup_list()
self.assertTrue(isinstance(result, list))
self.assertEquals(len(result), 2)
self.assert_("foo" in result)
self.assert_("bar" in result)
def test_set_default(self):
"""
Test setting a default value
"""
result = self.param_dict.get_config()
self.assertEquals(result["foo"], None)
self.param_dict.set_default("foo")
self.assertEquals(self.param_dict.get("foo"), 10)
self.param_dict.update("foo=1000")
self.assertEquals(self.param_dict.get("foo"), 1000)
self.param_dict.set_default("foo")
self.assertEquals(self.param_dict.get("foo"), 10)
self.assertRaises(ValueError, self.param_dict.set_default, "qux")
def test_update_many(self):
"""
Test updating of multiple variables from the same input
"""
sample_input = """
foo=100
bar=200, baz=300
"""
self.assertNotEquals(self.param_dict.get("foo"), 100)
self.assertNotEquals(self.param_dict.get("bar"), 200)
self.assertNotEquals(self.param_dict.get("baz"), 300)
result = self.param_dict.update_many(sample_input)
log.debug("result: %s", result)
self.assertEquals(result["foo"], True)
self.assertEquals(result["bar"], True)
self.assertEquals(result["baz"], True)
self.assertEquals(self.param_dict.get("foo"), 100)
self.assertEquals(self.param_dict.get("bar"), 200)
self.assertEquals(self.param_dict.get("baz"), 300)
def test_update_specific_values(self):
"""
test to verify we can limit update to a specific
set of parameters
"""
sample_input = "foo=100, bar=200"
示例3: Protocol
# 需要导入模块: from mi.core.instrument.protocol_param_dict import ProtocolParameterDict [as 别名]
# 或者: from mi.core.instrument.protocol_param_dict.ProtocolParameterDict import update [as 别名]
#.........这里部分代码省略.........
self._driver_event(DriverAsyncEvent.STATE_CHANGE)
def _handler_unknown_exit(self, *args, **kwargs):
"""
Exit unknown state.
"""
pass
def _handler_unknown_discover(self, *args, **kwargs):
"""
Discover current state; can only be COMMAND (instrument has no actual AUTOSAMPLE mode).
@retval (next_state, result), (ProtocolState.COMMAND, None) if successful.
"""
# force to command mode, this instrument has no autosample mode
next_state = ProtocolState.COMMAND
result = ResourceAgentState.COMMAND
log.debug("_handler_unknown_discover: state = %s", next_state)
return (next_state, result)
########################################################################
# Command handlers.
# just implemented to make DA possible, instrument has no actual command mode
########################################################################
def _handler_command_enter(self, *args, **kwargs):
"""
Enter command state.
"""
# Command device to update parameters and send a config change event if needed.
self._update_params()
# Tell driver superclass to send a state change event.
# Superclass will query the state.
self._driver_event(DriverAsyncEvent.STATE_CHANGE)
def _handler_command_exit(self, *args, **kwargs):
"""
Exit command state.
"""
pass
def _handler_command_set(self, *args, **kwargs):
"""
no writable parameters so does nothing, just implemented to make framework happy
"""
next_state = None
result = None
return (next_state, result)
def _handler_command_start_direct(self, *args, **kwargs):
"""
"""
result = None
next_state = ProtocolState.DIRECT_ACCESS
next_agent_state = ResourceAgentState.DIRECT_ACCESS
return (next_state, (next_agent_state, result))
########################################################################
# Direct access handlers.
########################################################################
示例4: TestUnitProtocolParameterDict
# 需要导入模块: from mi.core.instrument.protocol_param_dict import ProtocolParameterDict [as 别名]
# 或者: from mi.core.instrument.protocol_param_dict.ProtocolParameterDict import update [as 别名]
class TestUnitProtocolParameterDict(MiUnitTestCase):
@staticmethod
def pick_byte2(input):
""" Get the 2nd byte as an example of something tricky and
arbitrary"""
val = int(input) >> 8
val = val & 255
return val
"""
Test cases for instrument driver class. Functions in this class provide
instrument driver unit tests and provide a tutorial on use of
the driver interface.
"""
def setUp(self):
self.param_dict = ProtocolParameterDict()
self.param_dict.add("foo", r'.*foo=(\d+).*',
lambda match : int(match.group(1)),
lambda x : str(x),
direct_access=True,
startup_param=True,
default_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,
default_value=15,
visibility=ParameterDictVisibility.READ_WRITE)
self.param_dict.add("baz", r'.*baz=(\d+).*',
lambda match : int(match.group(1)),
lambda x : str(x),
direct_access=True,
default_value=20,
visibility=ParameterDictVisibility.DIRECT_ACCESS)
self.param_dict.add("bat", r'.*bat=(\d+).*',
lambda match : int(match.group(1)),
lambda x : str(x),
startup_param=False,
default_value=20,
visibility=ParameterDictVisibility.READ_ONLY)
self.param_dict.add("qux", r'.*qux=(\d+).*',
lambda match : int(match.group(1)),
lambda x : str(x),
startup_param=False,
visibility=ParameterDictVisibility.READ_ONLY)
def test_get_direct_access_list(self):
"""
Test to see we can get a list of direct access parameters
"""
result = self.param_dict.get_direct_access_list()
self.assertTrue(isinstance(result, list))
self.assertEquals(len(result), 2)
self.assert_("foo" in result)
self.assert_("baz" in result)
def test_get_startup_list(self):
"""
Test to see we can get a list of direct access parameters
"""
result = self.param_dict.get_startup_list()
self.assertTrue(isinstance(result, list))
self.assertEquals(len(result), 2)
self.assert_("foo" in result)
self.assert_("bar" in result)
def test_set_default(self):
"""
Test setting a default value
"""
result = self.param_dict.get_config()
self.assertEquals(result["foo"], None)
self.param_dict.set_default("foo")
self.assertEquals(self.param_dict.get("foo"), 10)
self.param_dict.update("foo=1000")
self.assertEquals(self.param_dict.get("foo"), 1000)
self.param_dict.set_default("foo")
self.assertEquals(self.param_dict.get("foo"), 10)
self.assertRaises(ValueError, self.param_dict.set_default, "qux")
def test_update_many(self):
"""
Test updating of multiple variables from the same input
"""
sample_input = """
foo=100
bar=200, baz=300
"""
self.assertNotEquals(self.param_dict.get("foo"), 100)
self.assertNotEquals(self.param_dict.get("bar"), 200)
self.assertNotEquals(self.param_dict.get("baz"), 300)
result = self.param_dict.update_many(sample_input)
log.debug("result: %s", result)
self.assertEquals(result["foo"], True)
self.assertEquals(result["bar"], True)
self.assertEquals(result["baz"], True)
#.........这里部分代码省略.........
示例5: TestUnitProtocolParameterDict
# 需要导入模块: from mi.core.instrument.protocol_param_dict import ProtocolParameterDict [as 别名]
# 或者: from mi.core.instrument.protocol_param_dict.ProtocolParameterDict import update [as 别名]
class TestUnitProtocolParameterDict(MiUnitTestCase):
"""
Test cases for instrument driver class. Functions in this class provide
instrument driver unit tests and provide a tutorial on use of
the driver interface.
"""
def setUp(self):
self.param_dict = ProtocolParameterDict()
self.param_dict.add("foo", r'.*foo=(\d*).*',
lambda match : int(match.group(1)),
lambda x : str(x),
direct_access=True,
startup_param=True,
default_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,
default_value=15,
visibility=ParameterDictVisibility.READ_WRITE)
self.param_dict.add("baz", r'.*baz=(\d*).*',
lambda match : int(match.group(1)),
lambda x : str(x),
direct_access=True,
default_value=20,
visibility=ParameterDictVisibility.DIRECT_ACCESS)
self.param_dict.add("bat", r'.*bat=(\d*).*',
lambda match : int(match.group(1)),
lambda x : str(x),
startup_param=False,
default_value=20,
visibility=ParameterDictVisibility.READ_ONLY)
self.param_dict.add("qux", r'.*qux=(\d*).*',
lambda match : int(match.group(1)),
lambda x : str(x),
startup_param=False,
visibility=ParameterDictVisibility.READ_ONLY)
def test_get_direct_access_list(self):
"""
Test to see we can get a list of direct access parameters
"""
result = self.param_dict.get_direct_access_list()
self.assertTrue(isinstance(result, list))
self.assertEquals(len(result), 2)
self.assert_("foo" in result)
self.assert_("baz" in result)
def test_get_startup_list(self):
"""
Test to see we can get a list of direct access parameters
"""
result = self.param_dict.get_startup_list()
self.assertTrue(isinstance(result, list))
self.assertEquals(len(result), 2)
self.assert_("foo" in result)
self.assert_("bar" in result)
def test_set_default(self):
"""
Test setting a default value
"""
result = self.param_dict.get_config()
self.assertEquals(result["foo"], None)
self.param_dict.set_default("foo")
self.assertEquals(self.param_dict.get("foo"), 10)
self.param_dict.update("foo=1000")
self.assertEquals(self.param_dict.get("foo"), 1000)
self.param_dict.set_default("foo")
self.assertEquals(self.param_dict.get("foo"), 10)
self.assertRaises(ValueError, self.param_dict.set_default, "qux")
def test_update_many(self):
"""
Test updating of multiple variables from the same input
"""
sample_input = """
foo=100
bar=200, baz=300
"""
self.assertNotEquals(self.param_dict.get("foo"), 100)
self.assertNotEquals(self.param_dict.get("bar"), 200)
self.assertNotEquals(self.param_dict.get("baz"), 300)
result = self.param_dict.update_many(sample_input)
log.debug("result: %s", result)
self.assertEquals(result["foo"], True)
self.assertEquals(result["bar"], True)
self.assertEquals(result["baz"], True)
self.assertEquals(self.param_dict.get("foo"), 100)
self.assertEquals(self.param_dict.get("bar"), 200)
self.assertEquals(self.param_dict.get("baz"), 300)
def test_visibility_list(self):
lst = self.param_dict.get_visibility_list(ParameterDictVisibility.READ_WRITE)
self.assertEquals(lst, ["foo", "bar"])
lst = self.param_dict.get_visibility_list(ParameterDictVisibility.DIRECT_ACCESS)
#.........这里部分代码省略.........