本文整理汇总了Python中mi.core.instrument.protocol_param_dict.ProtocolParameterDict类的典型用法代码示例。如果您正苦于以下问题:Python ProtocolParameterDict类的具体用法?Python ProtocolParameterDict怎么用?Python ProtocolParameterDict使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ProtocolParameterDict类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: setUp
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)
开发者ID:lukecampbell,项目名称:marine-integrations,代码行数:34,代码来源:test_protocol_param_dict.py
示例2: __init__
def __init__(self, driver_event):
"""
Base constructor.
@param driver_event The callback for asynchronous driver events.
"""
# Event callback to send asynchronous events to the agent.
self._driver_event = driver_event
# The connection used to talk to the device.
self._connection = None
# The protocol state machine.
self._protocol_fsm = None
# The parameter dictionary.
self._param_dict = ProtocolParameterDict()
# The spot to stash a configuration before going into direct access
# mode
self._pre_direct_access_config = None
# Driver configuration passed from the user
self._startup_config = {}
# scheduler config is a bit redundant now, but if we ever want to
# re-initialize a scheduler we will need it.
self._scheduler = None
self._scheduler_callback = {}
self._scheduler_config = {}
开发者ID:lytlej,项目名称:marine-integrations,代码行数:29,代码来源:instrument_protocol.py
示例3: _build_param_dict
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)
开发者ID:JeffRoy,项目名称:marine-integrations,代码行数:28,代码来源:driver.py
示例4: _set_params
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])
开发者ID:kehunt06,项目名称:mi-instrument,代码行数:14,代码来源:driver.py
示例5: __init__
def __init__(self, config, memento, data_callback, state_callback, exception_callback):
self._config = config
self._data_callback = data_callback
self._state_callback = state_callback
self._exception_callback = exception_callback
self._memento = memento
self._verify_config()
self._param_dict = ProtocolParameterDict()
# Updated my set_resource, defaults defined in build_param_dict
self._polling_interval = None
self._generate_particle_count = None
self._particle_count_per_second = None
self._build_param_dict()
开发者ID:s-pearce,项目名称:marine-integrations,代码行数:16,代码来源:dataset_driver.py
示例6: __init__
def __init__(self, driver_event):
"""
Base constructor.
@param driver_event The callback for asynchronous driver events.
"""
# Event callback to send asynchronous events to the agent.
self._driver_event = driver_event
# The connection used to talk to the device.
self._connection = None
# The protocol state machine.
self._protocol_fsm = None
# The parameter dictionary.
self._param_dict = ProtocolParameterDict()
开发者ID:pombredanne,项目名称:coi-services,代码行数:16,代码来源:instrument_protocol.py
示例7: __init__
def __init__(self, prompts, newline, driver_event, connections=None):
"""
Constructor.
@param prompts Enum class containing possible device prompts used for
command response logic.
@param newline The device newline.
@driver_event The callback for asynchronous driver events.
"""
if not type(connections) is list:
raise InstrumentProtocolException('Unable to instantiate multi connection protocol without connection list')
self._param_dict2 = ProtocolParameterDict()
# Construct superclass.
WorkhorseProtocol.__init__(self, prompts, newline, driver_event)
# Create multiple connection versions of the pieces of protocol involving data to/from the instrument
self._linebuf = {connection: '' for connection in connections}
self._promptbuf = {connection: '' for connection in connections}
self._last_data_timestamp = {connection: None for connection in connections}
self.connections = {connection: None for connection in connections}
self.chunkers = {connection: StringChunker(self.sieve_function) for connection in connections}
开发者ID:r-swilderd,项目名称:mi-instrument,代码行数:21,代码来源:driver.py
示例8: __init__
def __init__(self, config, memento, data_callback, state_callback, event_callback, exception_callback):
self._config = copy.deepcopy(config)
self._data_callback = data_callback
self._state_callback = state_callback
self._event_callback = event_callback
self._exception_callback = exception_callback
self._memento = memento
self._publisher_thread = None
self._verify_config()
# Updated my set_resource, defaults defined in build_param_dict
self._polling_interval = None
self._generate_particle_count = None
self._particle_count_per_second = None
self._resource_id = None
self._param_dict = ProtocolParameterDict()
self._cmd_dict = ProtocolCommandDict()
self._driver_dict = DriverDict()
self._build_command_dict()
self._build_driver_dict()
self._build_param_dict()
开发者ID:locateSung,项目名称:marine-integrations,代码行数:24,代码来源:dataset_driver.py
示例9: TestUnitProtocolParameterDict
class TestUnitProtocolParameterDict(TestUnitStringsDict):
"""
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.
"""
__test__ = True
@staticmethod
def pick_byte2(input_val):
""" Get the 2nd byte as an example of something tricky and
arbitrary"""
val = int(input_val) >> 8
val &= 255
return val
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,
get_timeout=30,
set_timeout=40,
display_name="Baz",
description="The baz parameter",
type=ParameterDictType.INT,
units="nano-bazers",
value_description="Should be an integer between 2 and 2000")
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,
get_timeout=10,
set_timeout=20,
display_name="Bat",
description="The bat parameter",
type=ParameterDictType.INT,
units="nano-batbit",
value_description="Should be an integer between 1 and 1000")
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)
self.param_dict.add("pho", r'.*qux=(\d+).*',
lambda match: int(match.group(1)),
lambda x: str(x),
startup_param=False,
visibility=ParameterDictVisibility.IMMUTABLE)
self.param_dict.add("dil", r'.*qux=(\d+).*',
lambda match: int(match.group(1)),
lambda x: str(x),
startup_param=False,
visibility=ParameterDictVisibility.IMMUTABLE)
self.param_dict.add("qut", r'.*qut=(\d+).*',
lambda match: int(match.group(1)),
lambda x: str(x),
direct_access=True,
default_value=[10, 100],
visibility=ParameterDictVisibility.DIRECT_ACCESS,
expiration=1,
get_timeout=10,
set_timeout=20,
display_name="Qut",
description="The qut list parameter",
type=ParameterDictType.LIST,
units="nano-qutters",
value_description="Should be a 2-10 element list of integers between 2 and 2000")
self.target_schema = {
"bar": {
"direct_access": False,
"get_timeout": 10,
"set_timeout": 10,
"startup": True,
"value": {
"default": 15
},
"visibility": "READ_WRITE",
#.........这里部分代码省略.........
开发者ID:kehunt06,项目名称:mi-instrument,代码行数:101,代码来源:test_protocol_param_dict.py
示例10: InstrumentProtocol
class InstrumentProtocol(object):
"""
Base instrument protocol class.
"""
def __init__(self, driver_event):
"""
Base constructor.
@param driver_event The callback for asynchronous driver events.
"""
# Event callback to send asynchronous events to the agent.
self._driver_event = driver_event
# The connection used to talk to the device.
self._connection = None
# The protocol state machine.
self._protocol_fsm = None
# The parameter dictionary.
self._param_dict = ProtocolParameterDict()
########################################################################
# Helper methods
########################################################################
def got_data(self, data):
"""
Called by the instrument connection when data is available.
Defined in subclasses.
"""
pass
def get_current_state(self):
"""
Return current state of the protocol FSM.
"""
return self._protocol_fsm.get_current_state()
def get_resource_capabilities(self, current_state=True):
"""
"""
res_cmds = self._protocol_fsm.get_events(current_state)
res_cmds = self._filter_capabilities(res_cmds)
res_params = self._param_dict.get_keys()
return [res_cmds, res_params]
def _filter_capabilities(self, events):
"""
"""
return events
########################################################################
# Command build and response parse handlers.
########################################################################
def _add_response_handler(self, cmd, func, state=None):
"""
Insert a handler class responsible for handling the response to a
command sent to the instrument, optionally available only in a
specific state.
@param cmd The high level key of the command to respond to.
@param func The function that handles the response
@param state The state to pair with the command for which the function
should be used
"""
if state == None:
self._response_handlers[cmd] = func
else:
self._response_handlers[(state, cmd)] = func
def _add_build_handler(self, cmd, func):
"""
Add a command building function.
@param cmd The device command to build.
@param func The function that constructs the command.
"""
self._build_handlers[cmd] = func
########################################################################
# Helpers to build commands.
########################################################################
def _build_simple_command(self, cmd, *args):
"""
Builder for simple commands
@param cmd The command to build
@param args Unused arguments
@retval Returns string ready for sending to instrument
"""
return "%s%s" % (cmd, self.eoln)
def _build_keypress_command(self, cmd, *args):
"""
Builder for simple, non-EOLN-terminated commands
@param cmd The command to build
@param args Unused arguments
@retval Returns string ready for sending to instrument
#.........这里部分代码省略.........
开发者ID:pombredanne,项目名称:coi-services,代码行数:101,代码来源:instrument_protocol.py
示例11: _build_param_dict
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.FLUSH_VOLUME,
r"Flush Volume: (.*)mL",
None,
self._int_to_string,
type=ParameterDictType.INT,
default_value=FLUSH_VOLUME,
units=Prefixes.MILLI + Units.LITER,
startup_param=True,
display_name="Flush Volume",
description="Amount of sea water to flush prior to taking sample: (10 - 20000)",
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=Prefixes.MILLI + Units.LITER + "/" + Units.MINUTE,
startup_param=True,
display_name="Flush Flow Rate",
description="Rate at which to flush: (100 - 250)",
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=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)",
#.........这里部分代码省略.........
开发者ID:r-swilderd,项目名称:mi-instrument,代码行数:101,代码来源:driver.py
示例12: Protocol
class Protocol(McLaneProtocol):
"""
Instrument protocol class
Subclasses CommandResponseInstrumentProtocol
"""
def __init__(self, prompts, newline, driver_event):
"""
Protocol constructor.
@param prompts A BaseEnum class containing instrument prompts.
@param newline The newline.
@param driver_event Driver process event callback.
"""
# Construct protocol superclass.
McLaneProtocol.__init__(self, prompts, newline, driver_event)
# TODO - reset next_port on mechanical refresh of the PPS filters - how is the driver notified?
# TODO - need to persist state for next_port to save driver restart
self.next_port = 1 # next available port
# get the following:
# - VERSION
# - CAPACITY (pump flow)
# - BATTERY
# - CODES (termination codes)
# - COPYRIGHT (termination codes)
def _got_chunk(self, chunk, timestamp):
"""
The base class got_data has gotten a chunk from the chunker. Pass it to extract_sample
with the appropriate particle objects and REGEXes.
"""
filling = self.get_current_state() == ProtocolState.FILL
log.debug("_got_chunk:\n%s", chunk)
sample_dict = self._extract_sample(
PPSDNSampleDataParticle, PPSDNSampleDataParticle.regex_compiled(), chunk, timestamp, publish=filling
)
if sample_dict:
self._linebuf = ""
self._promptbuf = ""
self._protocol_fsm.on_event(
ProtocolEvent.PUMP_STATUS, PPSDNSampleDataParticle.regex_compiled().search(chunk)
)
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.FLUSH_VOLUME,
r"Flush Volume: (.*)mL",
None,
self._int_to_string,
type=ParameterDictType.INT,
default_value=FLUSH_VOLUME,
units=Prefixes.MILLI + Units.LITER,
startup_param=True,
display_name="Flush Volume",
description="Amount of sea water to flush prior to taking sample: (10 - 20000)",
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=Prefixes.MILLI + Units.LITER + "/" + Units.MINUTE,
startup_param=True,
display_name="Flush Flow Rate",
description="Rate at which to flush: (100 - 250)",
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=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,
#.........这里部分代码省略.........
开发者ID:r-swilderd,项目名称:mi-instrument,代码行数:101,代码来源:driver.py
示例13: Protocol
#.........这里部分代码省略.........
time_format = "%Y/%m/%d %H:%M:%S"
str_val = get_timestamp_delayed(time_format)
log.debug("Setting instrument clock to '%s'", str_val)
self._do_cmd_resp(Command.SET_CLOCK, str_val, expected_prompt=Prompt.CR_NL)
def _wakeup(self, timeout):
"""There is no wakeup sequence for this instrument"""
pass
def _build_driver_dict(self):
"""
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)
开发者ID:JeffRoy,项目名称:marine-integrations,代码行数:66,代码来源:driver.py
示例14: Protocol
class Protocol(SamiProtocol):
"""
Instrument protocol class
Subclasses SamiProtocol and CommandResponseInstrumentProtocol
"""
def __init__(self, prompts, newline, driver_event):
"""
Protocol constructor.
@param prompts A BaseEnum class containing instrument prompts.
@param newline The newline.
@param driver_event Driver process event callback.
"""
# Construct protocol superclass.
SamiProtocol.__init__(self, prompts, newline, driver_event)
## Continue building protocol state machine from SamiProtocol
self._protocol_fsm.add_handler(
ProtocolState.SCHEDULED_SAMPLE, ProtocolEvent.SUCCESS,
self._handler_sample_success)
self._protocol_fsm.add_handler(
ProtocolState.SCHEDULED_SAMPLE, ProtocolEvent.TIMEOUT,
self._handler_sample_timeout)
self._protocol_fsm.add_handler(
ProtocolState.POLLED_SAMPLE, ProtocolEvent.SUCCESS,
self._handler_sample_success)
self._protocol_fsm.add_handler(
ProtocolState.POLLED_SAMPLE, ProtocolEvent.TIMEOUT,
self._handler_sample_timeout)
# State state machine in UNKNOWN state.
self._protocol_fsm.start(ProtocolState.UNKNOWN)
# build the chunker bot
self._chunker = StringChunker(Protocol.sieve_function)
@staticmethod
def sieve_function(raw_data):
"""
The method that splits samples
"""
return_list = []
sieve_matchers = [REGULAR_STATUS_REGEX_MATCHER,
CONTROL_RECORD_REGEX_MATCHER,
SAMI_SAMPLE_REGEX_MATCHER,
CONFIGURATION_REGEX_MATCHER,
ERROR_REGEX_MATCHER]
for matcher in sieve_matchers:
for match in matcher.finditer(raw_data):
return_list.append((match.start(), match.end()))
return return_list
def _got_chunk(self, chunk, timestamp):
"""
The base class got_data has gotten a chunk from the chunker. Pass it to extract_sample
with the appropriate particle objects and REGEXes.
"""
self._extract_sample(SamiRegularStatusDataParticle, REGULAR_STATUS_REGEX_MATCHER, chunk, timestamp)
self._extract_sample(SamiControlRecordDataParticle, CONTROL_RECORD_REGEX_MATCHER, chunk, timestamp)
self._extract_sample(PhsenSamiSampleDataParticle, SAMI_SAMPLE_REGEX_MATCHER, chunk, timestamp)
self._extract_sample(PhsenConfigDataParticle, CONFIGURATION_REGEX_MATCHER, chunk, timestamp)
#########################################################################
## General (for POLLED and SCHEDULED states) Sample handlers.
#########################################################################
def _handler_sample_success(self, *args, **kwargs):
next_state = None
result = None
return (next_state, result)
def _handler_sample_timeout(self, ):
next_state = None
result = None
return (next_state, result)
####################################################################
# Build Parameter dictionary
####################################################################
def _build_param_dict(self):
"""
Populate the parameter dictionary with parameters.
For each parameter key, add match stirng, match lambda function,
and value formatting function for set commands.
"""
# Add parameter handlers to parameter dict.
self._param_dict = ProtocolParameterDict()
self._param_dict.add(Parameter.LAUNCH_TIME, CONFIGURATION_REGEX,
lambda match: int(match.group(1), 16),
lambda x: self._int_to_hexstring(x, 8),
type=ParameterDictType.INT,
startup_param=False,
#.........这里部分代码省略.........
开发者ID:StevenMyerson,项目名称:marine-integrations,代码行数:101,代码来源:driver.py
示例15: _build_param_dict
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.FLUSH_VOLUME,
r'Flush Volume: (.*)mL',
None,
self._int_to_string,
type=ParameterDictType.INT,
default_value=150,
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=100,
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=75,
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=4000,
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=100,
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=75,
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=100,
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=100,
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=75,
units='mL/min',
startup_param=True,
display_name="clear_min_flow",
visibility=ParameterDictVisibility.IMMUTABLE)
开发者ID:kehunt06,项目名称:mi-instrument,代码行数:99,代码来源:driver.py
示例16: Protocol
class Protocol(WorkhorseProtocol):
def __init__(self, prompts, newline, driver_event, connections=None):
"""
Constructor.
@param prompts Enum class containing possible device prompts used for
command response logic.
@param newline The device newline.
@driver_event The callback for asynchronous driver events.
"""
if not type(connections) is list:
raise InstrumentProtocolException('Unable to instantiate multi connection protocol without connection list')
self._param_dict2 = ProtocolParameterDict()
# Construct superclass.
WorkhorseProtocol.__init__(self, prompts, newline, driver_event)
# Create multiple connection versions of the pieces of protocol involving data to/from the instrument
self._linebuf = {connection: '' for connection in connections}
self._promptbuf = {connection: '' for connection in connections}
self._last_data_timestamp = {connection: None for connection in connections}
self.connections = {connection: None for connection in connections}
self.chunkers = {connection: StringChunker(self.sieve_function) for connection in connections}
def _get_response(self, timeout=10, expected_prompt=None, response_regex=None, connection=None):
"""
Overridden to handle multiple port agent connections
"""
if connection is None:
raise InstrumentProtocolException('_get_response: no connection supplied!')
# Grab time for timeout and wait for prompt.
end_time = time.time() + timeout
if response_regex and not isinstance(response_regex, RE_PATTERN):
raise InstrumentProtocolException('Response regex is not a compiled pattern!')
if expected_prompt and response_regex:
raise InstrumentProtocolException('Cannot supply both regex and expected prompt!')
if expected_prompt is None:
prompt_list = self._get_prompts()
else:
if isinstance(expected_prompt, str):
prompt_list = [expected_prompt]
else:
prompt_list = expected_prompt
if response_regex is None:
pattern = None
else:
pattern = response_regex.pattern
log.debug('_get_response: timeout=%s, prompt_list=%s, expected_prompt=%r, response_regex=%r, promptbuf=%r',
timeout, prompt_list, expected_prompt, pattern, self._promptbuf)
while time.time() < end_time:
if response_regex:
# noinspection PyArgumentList
match = response_regex.search(self._linebuf[connection])
if match:
return match.groups()
else:
for item in prompt_list:
index = self._promptbuf[connection].find(item)
if index >= 0:
result = self._promptbuf[connection][0:index + len(item)]
return item, result
time.sleep(.1)
raise InstrumentTimeoutException("in InstrumentProtocol._get_response()")
def _do_cmd_resp(self, cmd, *args, **kwargs):
"""
Overridden to handle multiple port agent connections
"""
connection = kwargs.get('connection')
if connection is None:
|
请发表评论