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)
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)
def _build_command_dict(self): """ Populate the command dictionary with command. """ SamiProtocol._build_command_dict(self) self._cmd_dict.add(Pco2wCapability.ACQUIRE_BLANK_SAMPLE, display_name="Acquire Blank Sample") self._cmd_dict.add(Pco2wCapability.DEIONIZED_WATER_FLUSH_100ML, display_name="Deionized Water Flush 100 ml") self._cmd_dict.add(Pco2wCapability.REAGENT_FLUSH_100ML, display_name="Reagent Flush 100 ml") self._cmd_dict.add(Pco2wCapability.DEIONIZED_WATER_FLUSH, display_name="Deionized Water Flush")
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) # Build protocol state machine. ### # most of these are defined in the base class with exception of handlers # defined below that differ for the two instruments (what defines # success and the timeout duration) ### # this state would be entered whenever an ACQUIRE_SAMPLE event occurred # while in the AUTOSAMPLE state and will last anywhere from a few # seconds to ~12 minutes depending on instrument and the type of # sampling. 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) # this state would be entered whenever an ACQUIRE_SAMPLE event occurred # while in either the COMMAND state (or via the discover transition # from the UNKNOWN state with the instrument unresponsive) and will # last anywhere from a few seconds to 3 minutes depending on instrument # and sample type. 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) # Add build handlers for device commands. ### primarily defined in base class self._add_build_handler(InstrumentCommand.ACQUIRE_SAMPLE_DEV1, self._build_sample_dev1) # Add response handlers for device commands. ### primarily defined in base class self._add_response_handler(InstrumentCommand.ACQUIRE_SAMPLE_DEV1, self._build_response_sample_dev1) # Add sample handlers # State state machine in UNKNOWN state. self._protocol_fsm.start(ProtocolState.UNKNOWN) # build the chunker self._chunker = StringChunker(Protocol.sieve_function)
def assert_time_sync(self, status_particle): status_dict = self.get_data_particle_values_as_dict(status_particle) elapsed_time_config = status_dict.get(SamiRegularStatusDataParticleKey.ELAPSED_TIME_CONFIG) current_sami_time = SamiProtocol._current_sami_time() log.debug("elapsed_time_config = %s", elapsed_time_config) log.debug("current_sami_time = %s", current_sami_time) time_difference = current_sami_time - elapsed_time_config log.debug("time difference = %s", time_difference) sami_now_seconds = current_sami_time - SAMI_UNIX_OFFSET.total_seconds() sami_now = datetime.datetime.utcfromtimestamp(sami_now_seconds) log.debug('utc time = %s', datetime.datetime.utcnow()) log.debug('sami_now = %s', sami_now) self.assertTrue(time_difference <= TIME_THRESHOLD, "Time threshold exceeded, time_difference = %s, time_threshold = %s" % ( time_difference, TIME_THRESHOLD))
def _build_param_dict(self): """ For each parameter key, add match string, match lambda function, and value formatting function for set commands. """ SamiProtocol._build_param_dict(self) configuration_string_regex = self._get_configuration_string_regex() # PCO2 0x04, PHSEN 0x0A self._param_dict.add(Pco2wParameter.SAMI_DRIVER_VERSION, configuration_string_regex, lambda match: int(match.group(6), 16), lambda x: self._int_to_hexstring(x, 2), type=ParameterDictType.INT, startup_param=True, direct_access=True, default_value=0x04, visibility=ParameterDictVisibility.READ_ONLY, display_name='Sami Driver Version') self._param_dict.add(Pco2wParameter.PUMP_PULSE, configuration_string_regex, lambda match: int(match.group(21), 16), lambda x: self._int_to_hexstring(x, 2), type=ParameterDictType.INT, startup_param=True, direct_access=True, default_value=0x10, visibility=ParameterDictVisibility.READ_WRITE, display_name='Pump Pulse Duration') self._param_dict.add(Pco2wParameter.PUMP_DURATION, configuration_string_regex, lambda match: int(match.group(22), 16), lambda x: self._int_to_hexstring(x, 2), type=ParameterDictType.INT, startup_param=True, direct_access=True, default_value=0x20, visibility=ParameterDictVisibility.READ_WRITE, display_name='Pump Measurement Duration') self._param_dict.add(Pco2wParameter.SAMPLES_PER_MEASUREMENT, configuration_string_regex, lambda match: int(match.group(23), 16), lambda x: self._int_to_hexstring(x, 2), type=ParameterDictType.INT, startup_param=True, direct_access=True, default_value=0xFF, visibility=ParameterDictVisibility.READ_WRITE, display_name='Samples Per Measurement') self._param_dict.add(Pco2wParameter.CYCLES_BETWEEN_BLANKS, configuration_string_regex, lambda match: int(match.group(24), 16), lambda x: self._int_to_hexstring(x, 2), type=ParameterDictType.INT, startup_param=True, direct_access=True, default_value=0x54, visibility=ParameterDictVisibility.READ_WRITE, display_name='Cycles Between Blanks') self._param_dict.add(Pco2wParameter.NUMBER_REAGENT_CYCLES, configuration_string_regex, lambda match: int(match.group(25), 16), lambda x: self._int_to_hexstring(x, 2), type=ParameterDictType.INT, startup_param=True, direct_access=True, default_value=0x18, visibility=ParameterDictVisibility.READ_WRITE, display_name='Number of Reagent Cycles') self._param_dict.add(Pco2wParameter.NUMBER_BLANK_CYCLES, configuration_string_regex, lambda match: int(match.group(26), 16), lambda x: self._int_to_hexstring(x, 2), type=ParameterDictType.INT, startup_param=True, direct_access=True, default_value=0x1C, visibility=ParameterDictVisibility.READ_WRITE, display_name='Number of Blank Cycles') self._param_dict.add(Pco2wParameter.FLUSH_PUMP_INTERVAL, configuration_string_regex, lambda match: int(match.group(27), 16), lambda x: self._int_to_hexstring(x, 2), type=ParameterDictType.INT, startup_param=True, direct_access=True, default_value=0x01, visibility=ParameterDictVisibility.READ_WRITE, display_name='Flush Pump Interval') self._param_dict.add(Pco2wParameter.BIT_SWITCHES, configuration_string_regex, lambda match: int(match.group(28), 16), lambda x: self._int_to_hexstring(x, 2), type=ParameterDictType.INT, startup_param=True, direct_access=True, default_value=0x00, visibility=ParameterDictVisibility.READ_WRITE, display_name='Bit Switches') self._param_dict.add(Pco2wParameter.NUMBER_EXTRA_PUMP_CYCLES, configuration_string_regex, lambda match: int(match.group(29), 16), lambda x: self._int_to_hexstring(x, 2), type=ParameterDictType.INT, startup_param=True, direct_access=True, default_value=0x38, visibility=ParameterDictVisibility.READ_WRITE, display_name='Number of Extra Pump Cycles') self._param_dict.add(Pco2wParameter.PUMP_100ML_CYCLES, r'Pump 100ml cycles = ([0-9]+)', lambda match: match.group(1), lambda x: self._int_to_hexstring(x, 2), type=ParameterDictType.INT, startup_param=True, direct_access=False, default_value=0x1, visibility=ParameterDictVisibility.READ_WRITE, display_name='Pump 100ml Cycles') self._param_dict.add(Pco2wParameter.REAGENT_FLUSH_DURATION, r'Reagent flush duration = ([0-9]+)', lambda match: match.group(1), lambda x: self._int_to_hexstring(x, 2), type=ParameterDictType.INT, startup_param=True, direct_access=False, default_value=0x8, visibility=ParameterDictVisibility.READ_WRITE, display_name='Reagent Flush Duration') self._param_dict.add(Pco2wParameter.DEIONIZED_WATER_FLUSH_DURATION, r'Deionized water flush duration = ([0-9]+)', lambda match: match.group(1), lambda x: self._int_to_hexstring(x, 2), type=ParameterDictType.INT, startup_param=True, direct_access=False, default_value=0x8, visibility=ParameterDictVisibility.READ_WRITE, display_name='Deionized Water Flush Duration')
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) self._protocol_fsm.add_handler( Pco2wProtocolState.COMMAND, Pco2wProtocolEvent.ACQUIRE_BLANK_SAMPLE, self._handler_command_acquire_blank_sample) self._protocol_fsm.add_handler( Pco2wProtocolState.COMMAND, Pco2wProtocolEvent.DEIONIZED_WATER_FLUSH_100ML, self._handler_command_deionized_water_flush_100ml) self._protocol_fsm.add_handler( Pco2wProtocolState.COMMAND, Pco2wProtocolEvent.REAGENT_FLUSH_100ML, self._handler_command_reagent_flush_100ml) self._protocol_fsm.add_handler( SamiProtocolState.COMMAND, Pco2wProtocolEvent.DEIONIZED_WATER_FLUSH, self._handler_command_deionized_water_flush) self._protocol_fsm.add_handler( Pco2wProtocolState.AUTOSAMPLE, Pco2wProtocolEvent.ACQUIRE_BLANK_SAMPLE, self._handler_autosample_acquire_blank_sample) # this state would be entered whenever an ACQUIRE_BLANK_SAMPLE event # occurred while in the COMMAND state # and will last anywhere from a few seconds to 3 # minutes depending on instrument and sample type. self._protocol_fsm.add_handler(Pco2wProtocolState.POLLED_BLANK_SAMPLE, Pco2wProtocolEvent.ENTER, self._execution_state_enter) self._protocol_fsm.add_handler(Pco2wProtocolState.POLLED_BLANK_SAMPLE, Pco2wProtocolEvent.EXIT, self._execution_state_exit) self._protocol_fsm.add_handler(Pco2wProtocolState.POLLED_BLANK_SAMPLE, Pco2wProtocolEvent.EXECUTE, self._handler_take_blank_sample) self._protocol_fsm.add_handler( Pco2wProtocolState.POLLED_BLANK_SAMPLE, Pco2wProtocolEvent.SUCCESS, self._execution_success_to_command_state) self._protocol_fsm.add_handler( Pco2wProtocolState.POLLED_BLANK_SAMPLE, Pco2wProtocolEvent.TIMEOUT, self._execution_timeout_to_command_state) ## Events to queue - intended for schedulable events occurring when a sample is being taken self._protocol_fsm.add_handler(Pco2wProtocolState.POLLED_BLANK_SAMPLE, Pco2wProtocolEvent.ACQUIRE_STATUS, self._handler_queue_acquire_status) # this state would be entered whenever an ACQUIRE_BLANK_SAMPLE event # occurred while in the AUTOSAMPLE state # and will last anywhere from a few seconds to 3 # minutes depending on instrument and sample type. self._protocol_fsm.add_handler( Pco2wProtocolState.SCHEDULED_BLANK_SAMPLE, Pco2wProtocolEvent.ENTER, self._execution_state_enter) self._protocol_fsm.add_handler( Pco2wProtocolState.SCHEDULED_BLANK_SAMPLE, Pco2wProtocolEvent.EXIT, self._execution_state_exit) self._protocol_fsm.add_handler( Pco2wProtocolState.SCHEDULED_BLANK_SAMPLE, Pco2wProtocolEvent.EXECUTE, self._handler_take_blank_sample) self._protocol_fsm.add_handler( Pco2wProtocolState.SCHEDULED_BLANK_SAMPLE, Pco2wProtocolEvent.SUCCESS, self._execution_success_to_autosample_state) self._protocol_fsm.add_handler( Pco2wProtocolState.SCHEDULED_BLANK_SAMPLE, Pco2wProtocolEvent.TIMEOUT, self._execution_timeout_to_autosample_state) ## Events to queue - intended for schedulable events occurring when a sample is being taken self._protocol_fsm.add_handler( Pco2wProtocolState.SCHEDULED_BLANK_SAMPLE, Pco2wProtocolEvent.ACQUIRE_STATUS, self._handler_queue_acquire_status) # this state would be entered whenever a DEIONIZED_WATER_FLUSH_100ML event # occurred while in the COMMAND state self._protocol_fsm.add_handler( Pco2wProtocolState.DEIONIZED_WATER_FLUSH_100ML, Pco2wProtocolEvent.ENTER, self._execution_state_enter) self._protocol_fsm.add_handler( Pco2wProtocolState.DEIONIZED_WATER_FLUSH_100ML, Pco2wProtocolEvent.EXIT, self._execution_state_exit) self._protocol_fsm.add_handler( Pco2wProtocolState.DEIONIZED_WATER_FLUSH_100ML, Pco2wProtocolEvent.EXECUTE, self._handler_deionized_water_flush_execute_100ml) self._protocol_fsm.add_handler( Pco2wProtocolState.DEIONIZED_WATER_FLUSH_100ML, Pco2wProtocolEvent.SUCCESS, self._execution_success_to_command_state) self._protocol_fsm.add_handler( Pco2wProtocolState.DEIONIZED_WATER_FLUSH_100ML, Pco2wProtocolEvent.TIMEOUT, self._execution_timeout_to_command_state) ## Events to queue - intended for schedulable events occurring when a sample is being taken self._protocol_fsm.add_handler( Pco2wProtocolState.DEIONIZED_WATER_FLUSH_100ML, Pco2wProtocolEvent.ACQUIRE_STATUS, self._handler_queue_acquire_status) # this state would be entered whenever a REAGENT_FLUSH_100ML event # occurred while in the COMMAND state self._protocol_fsm.add_handler(Pco2wProtocolState.REAGENT_FLUSH_100ML, Pco2wProtocolEvent.ENTER, self._execution_state_enter) self._protocol_fsm.add_handler(Pco2wProtocolState.REAGENT_FLUSH_100ML, Pco2wProtocolEvent.EXIT, self._execution_state_exit) self._protocol_fsm.add_handler( Pco2wProtocolState.REAGENT_FLUSH_100ML, Pco2wProtocolEvent.EXECUTE, self._handler_reagent_flush_execute_100ml) self._protocol_fsm.add_handler( Pco2wProtocolState.REAGENT_FLUSH_100ML, Pco2wProtocolEvent.SUCCESS, self._execution_success_to_command_state) self._protocol_fsm.add_handler( Pco2wProtocolState.REAGENT_FLUSH_100ML, Pco2wProtocolEvent.TIMEOUT, self._execution_timeout_to_command_state) ## Events to queue - intended for schedulable events occurring when a sample is being taken self._protocol_fsm.add_handler(Pco2wProtocolState.REAGENT_FLUSH_100ML, Pco2wProtocolEvent.ACQUIRE_STATUS, self._handler_queue_acquire_status) # this state would be entered whenever a DEIONIZED_WATER_FLUSH event # occurred while in the COMMAND state self._protocol_fsm.add_handler( Pco2wProtocolState.DEIONIZED_WATER_FLUSH, Pco2wProtocolEvent.ENTER, self._execution_state_enter) self._protocol_fsm.add_handler( Pco2wProtocolState.DEIONIZED_WATER_FLUSH, Pco2wProtocolEvent.EXIT, self._execution_state_exit) self._protocol_fsm.add_handler( Pco2wProtocolState.DEIONIZED_WATER_FLUSH, Pco2wProtocolEvent.EXECUTE, self._handler_deionized_water_flush_execute) self._protocol_fsm.add_handler( Pco2wProtocolState.DEIONIZED_WATER_FLUSH, Pco2wProtocolEvent.SUCCESS, self._execution_success_to_command_state) self._protocol_fsm.add_handler( Pco2wProtocolState.DEIONIZED_WATER_FLUSH, Pco2wProtocolEvent.TIMEOUT, self._execution_timeout_to_command_state) ## Events to queue - intended for schedulable events occurring when a sample is being taken self._protocol_fsm.add_handler( Pco2wProtocolState.DEIONIZED_WATER_FLUSH, Pco2wProtocolEvent.ACQUIRE_STATUS, self._handler_queue_acquire_status) self._engineering_parameters.append(Pco2wParameter.PUMP_100ML_CYCLES) self._engineering_parameters.append( Pco2wParameter.DEIONIZED_WATER_FLUSH_DURATION) self._add_build_handler( Pco2wInstrumentCommand.PCO2W_ACQUIRE_BLANK_SAMPLE, self._build_simple_command) self._add_build_handler( Pco2wInstrumentCommand.PCO2W_PUMP_DEIONIZED_WATER, self._build_pump_command) self._add_build_handler(Pco2wInstrumentCommand.PCO2W_PUMP_REAGENT, self._build_pump_command) # Add response handlers for device commands. self._add_response_handler( Pco2wInstrumentCommand.PCO2W_ACQUIRE_BLANK_SAMPLE, self._parse_response_blank_sample_sami) self._add_response_handler( Pco2wInstrumentCommand.PCO2W_PUMP_DEIONIZED_WATER, self._parse_response_newline) self._add_response_handler(Pco2wInstrumentCommand.PCO2W_PUMP_REAGENT, self._parse_response_newline)
def _build_param_dict(self): """ For each parameter key, add match string, match lambda function, and value formatting function for set commands. """ SamiProtocol._build_param_dict(self) configuration_string_regex = self._get_configuration_string_regex() # PCO2 0x04, PHSEN 0x0A self._param_dict.add(Pco2wParameter.SAMI_DRIVER_VERSION, configuration_string_regex, lambda match: int(match.group(6), 16), lambda x: self._int_to_hexstring(x, 2), type=ParameterDictType.INT, startup_param=True, direct_access=True, default_value=0x04, visibility=ParameterDictVisibility.READ_ONLY, display_name='Sami Driver Version', description='SAMI driver version: (04 = CO2 Ave+)') self._param_dict.add(Pco2wParameter.PUMP_PULSE, configuration_string_regex, lambda match: int(match.group(21), 16), lambda x: self._int_to_hexstring(x, 2), type=ParameterDictType.INT, startup_param=True, direct_access=True, default_value=0x10, visibility=ParameterDictVisibility.READ_WRITE, display_name='Pump Pulse Duration', description='', units='16 ' + Units.HERTZ) self._param_dict.add(Pco2wParameter.PUMP_DURATION, configuration_string_regex, lambda match: int(match.group(22), 16), lambda x: self._int_to_hexstring(x, 2), type=ParameterDictType.INT, startup_param=True, direct_access=True, default_value=0x20, visibility=ParameterDictVisibility.READ_WRITE, display_name='Pump Measurement Duration', description='', units='16 ' + Units.HERTZ) self._param_dict.add(Pco2wParameter.SAMPLES_PER_MEASUREMENT, configuration_string_regex, lambda match: int(match.group(23), 16), lambda x: self._int_to_hexstring(x, 2), type=ParameterDictType.INT, startup_param=True, direct_access=True, default_value=0xFF, visibility=ParameterDictVisibility.READ_WRITE, display_name='Samples Per Measurement', description='Number of samples per measurement.') self._param_dict.add(Pco2wParameter.CYCLES_BETWEEN_BLANKS, configuration_string_regex, lambda match: int(match.group(24), 16), lambda x: self._int_to_hexstring(x, 2), type=ParameterDictType.INT, startup_param=True, direct_access=True, default_value=0x54, visibility=ParameterDictVisibility.READ_WRITE, display_name='Cycles Between Blanks', description='Number of cycles between blanks.') self._param_dict.add(Pco2wParameter.NUMBER_REAGENT_CYCLES, configuration_string_regex, lambda match: int(match.group(25), 16), lambda x: self._int_to_hexstring(x, 2), type=ParameterDictType.INT, startup_param=True, direct_access=True, default_value=0x18, visibility=ParameterDictVisibility.READ_WRITE, display_name='Number of Reagent Cycles', description='') self._param_dict.add(Pco2wParameter.NUMBER_BLANK_CYCLES, configuration_string_regex, lambda match: int(match.group(26), 16), lambda x: self._int_to_hexstring(x, 2), type=ParameterDictType.INT, startup_param=True, direct_access=True, default_value=0x1C, visibility=ParameterDictVisibility.READ_WRITE, display_name='Number of Blank Cycles', description='') self._param_dict.add(Pco2wParameter.FLUSH_PUMP_INTERVAL, configuration_string_regex, lambda match: int(match.group(27), 16), lambda x: self._int_to_hexstring(x, 2), type=ParameterDictType.INT, startup_param=True, direct_access=True, default_value=0x01, visibility=ParameterDictVisibility.READ_WRITE, display_name='Flush Pump Interval', description='', units=Units.SECOND) self._param_dict.add(Pco2wParameter.PUMP_SETTINGS, configuration_string_regex, lambda match: int(match.group(28), 16), lambda x: self._int_to_hexstring(x, 2), type=ParameterDictType.INT, startup_param=True, direct_access=True, default_value=0x00, visibility=ParameterDictVisibility.READ_WRITE, display_name='Pump Settings', description='Bit switches, where bit 0 = Don\'t start with blank flush,' ' bit 1 = measure after each pump pulse, Bits 2-7 = Unassigned, set to 0.') self._param_dict.add(Pco2wParameter.NUMBER_EXTRA_PUMP_CYCLES, configuration_string_regex, lambda match: int(match.group(29), 16), lambda x: self._int_to_hexstring(x, 2), type=ParameterDictType.INT, startup_param=True, direct_access=True, default_value=0x38, visibility=ParameterDictVisibility.READ_WRITE, display_name='Number of Extra Pump Cycles', description='') self._param_dict.add(Pco2wParameter.PUMP_100ML_CYCLES, r'Pump 100ml cycles = ([0-9]+)', lambda match: match.group(1), lambda x: self._int_to_hexstring(x, 2), type=ParameterDictType.INT, startup_param=True, direct_access=False, default_value=0x1, visibility=ParameterDictVisibility.READ_WRITE, display_name='Pump 100ml Cycles', description='Number of pump cycles when executing pump.') self._param_dict.add(Pco2wParameter.REAGENT_FLUSH_DURATION, r'Reagent flush duration = ([0-9]+)', lambda match: match.group(1), lambda x: self._int_to_hexstring(x, 2), type=ParameterDictType.INT, startup_param=True, direct_access=False, default_value=0x8, visibility=ParameterDictVisibility.READ_WRITE, display_name='Reagent Flush Duration', description='Set duration of reagent flush when executing pump.', units='8 ' + Units.HERTZ) self._param_dict.add(Pco2wParameter.DEIONIZED_WATER_FLUSH_DURATION, r'Deionized water flush duration = ([0-9]+)', lambda match: match.group(1), lambda x: self._int_to_hexstring(x, 2), type=ParameterDictType.INT, startup_param=True, direct_access=False, default_value=0x8, visibility=ParameterDictVisibility.READ_WRITE, display_name='Deionized Water Flush Duration', description='Set duration of deionized water flush when executing pump.', units='8 ' + Units.HERTZ)
def _build_param_dict(self): """ For each parameter key, add match string, match lambda function, and value formatting function for set commands. """ SamiProtocol._build_param_dict(self) configuration_string_regex = self._get_configuration_string_regex() # PCO2 0x04, PHSEN 0x0A self._param_dict.add(Pco2wParameter.SAMI_DRIVER_VERSION, configuration_string_regex, lambda match: int(match.group(6), 16), lambda x: self._int_to_hexstring(x, 2), type=ParameterDictType.INT, startup_param=True, direct_access=True, default_value=0x04, visibility=ParameterDictVisibility.IMMUTABLE, display_name='Sami Driver Version', description='SAMI driver version: (04 = CO2 Ave+)') self._param_dict.add(Pco2wParameter.PUMP_PULSE, configuration_string_regex, lambda match: int(match.group(21), 16), lambda x: self._int_to_hexstring(x, 2), type=ParameterDictType.INT, startup_param=True, direct_access=True, default_value=0x10, range=(0, 0xFF), visibility=ParameterDictVisibility.READ_WRITE, display_name='Pump Pulse Duration', description='(0-255)', units='1/16 ' + Units.SECOND) self._param_dict.add(Pco2wParameter.PUMP_DURATION, configuration_string_regex, lambda match: int(match.group(22), 16), lambda x: self._int_to_hexstring(x, 2), type=ParameterDictType.INT, startup_param=True, direct_access=True, default_value=0x20, range=(0, 0xFF), visibility=ParameterDictVisibility.READ_WRITE, display_name='Pump Measurement Duration', description='(0-255)', units='1/16 ' + Units.SECOND) self._param_dict.add(Pco2wParameter.SAMPLES_PER_MEASUREMENT, configuration_string_regex, lambda match: int(match.group(23), 16), lambda x: self._int_to_hexstring(x, 2), type=ParameterDictType.INT, startup_param=True, direct_access=True, default_value=0xFF, range=(0, 0xFF), visibility=ParameterDictVisibility.READ_WRITE, display_name='Samples Per Measurement', description='Number of samples per measurement (0-255)') self._param_dict.add(Pco2wParameter.CYCLES_BETWEEN_BLANKS, configuration_string_regex, lambda match: int(match.group(24), 16), lambda x: self._int_to_hexstring(x, 2), type=ParameterDictType.INT, startup_param=True, direct_access=True, default_value=0x54, range=(0, 0xFF), visibility=ParameterDictVisibility.READ_WRITE, display_name='Cycles Between Blanks', description='Number of cycles between blanks (0-255)') self._param_dict.add(Pco2wParameter.NUMBER_REAGENT_CYCLES, configuration_string_regex, lambda match: int(match.group(25), 16), lambda x: self._int_to_hexstring(x, 2), type=ParameterDictType.INT, startup_param=True, direct_access=True, default_value=0x18, range=(0, 0xFF), visibility=ParameterDictVisibility.READ_WRITE, display_name='Number of Reagent Cycles', description='(0-255)') self._param_dict.add(Pco2wParameter.NUMBER_BLANK_CYCLES, configuration_string_regex, lambda match: int(match.group(26), 16), lambda x: self._int_to_hexstring(x, 2), type=ParameterDictType.INT, startup_param=True, direct_access=True, default_value=0x1C, range=(0, 0xFF), visibility=ParameterDictVisibility.READ_WRITE, display_name='Number of Blank Cycles', description='(0-255)') self._param_dict.add(Pco2wParameter.FLUSH_PUMP_INTERVAL, configuration_string_regex, lambda match: int(match.group(27), 16), lambda x: self._int_to_hexstring(x, 2), type=ParameterDictType.INT, startup_param=True, direct_access=True, default_value=0x01, range=(0, 0xFF), visibility=ParameterDictVisibility.READ_WRITE, display_name='Flush Pump Interval', description='(0-255)', units=Units.SECOND) self._param_dict.add(Pco2wParameter.PUMP_SETTINGS, configuration_string_regex, lambda match: int(match.group(28), 16), lambda x: self._int_to_hexstring(x, 2), type=ParameterDictType.INT, startup_param=True, direct_access=True, default_value=0x00, range=(0, 0xFF), visibility=ParameterDictVisibility.READ_WRITE, display_name='Pump Settings', description='Bit switches, where bit 0 = Don\'t start with blank flush,' ' bit 1 = measure after each pump pulse, Bits 2-7 = Unassigned, set to 0.') self._param_dict.add(Pco2wParameter.NUMBER_EXTRA_PUMP_CYCLES, configuration_string_regex, lambda match: int(match.group(29), 16), lambda x: self._int_to_hexstring(x, 2), type=ParameterDictType.INT, startup_param=True, direct_access=True, default_value=0x38, range=(0, 0xFF), visibility=ParameterDictVisibility.READ_WRITE, display_name='Number of Extra Pump Cycles', description='(0-255)') self._param_dict.add(Pco2wParameter.PUMP_100ML_CYCLES, r'Pump 100ml cycles = ([0-9]+)', lambda match: match.group(1), lambda x: self._int_to_hexstring(x, 2), type=ParameterDictType.INT, startup_param=True, direct_access=False, default_value=0x1, range=(0, 0xFF), visibility=ParameterDictVisibility.READ_WRITE, display_name='Pump 100ml Cycles', description='Number of pump cycles when executing pump (0-255)') self._param_dict.add(Pco2wParameter.REAGENT_FLUSH_DURATION, r'Reagent flush duration = ([0-9]+)', lambda match: match.group(1), lambda x: self._int_to_hexstring(x, 2), type=ParameterDictType.INT, startup_param=True, direct_access=False, default_value=0x8, range=(0, 0xFF), visibility=ParameterDictVisibility.READ_WRITE, display_name='Reagent Flush Duration', description='Set duration of reagent flush when executing pump (0-255)', units='1/8 ' + Units.SECOND) self._param_dict.add(Pco2wParameter.DEIONIZED_WATER_FLUSH_DURATION, r'Deionized water flush duration = ([0-9]+)', lambda match: match.group(1), lambda x: self._int_to_hexstring(x, 2), type=ParameterDictType.INT, startup_param=True, direct_access=False, default_value=0x8, range=(0, 0xFF), visibility=ParameterDictVisibility.READ_WRITE, display_name='Deionized Water Flush Duration', description='Set duration of deionized water flush when executing pump (0-255)', units='1/8 ' + Units.SECOND)
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) self._protocol_fsm.add_handler( Pco2wProtocolState.COMMAND, Pco2wProtocolEvent.ACQUIRE_BLANK_SAMPLE, self._handler_command_acquire_blank_sample) self._protocol_fsm.add_handler( Pco2wProtocolState.COMMAND, Pco2wProtocolEvent.DEIONIZED_WATER_FLUSH_100ML, self._handler_command_deionized_water_flush_100ml) self._protocol_fsm.add_handler( Pco2wProtocolState.COMMAND, Pco2wProtocolEvent.REAGENT_FLUSH_100ML, self._handler_command_reagent_flush_100ml) self._protocol_fsm.add_handler( SamiProtocolState.COMMAND, Pco2wProtocolEvent.DEIONIZED_WATER_FLUSH, self._handler_command_deionized_water_flush) self._protocol_fsm.add_handler( Pco2wProtocolState.AUTOSAMPLE, Pco2wProtocolEvent.ACQUIRE_BLANK_SAMPLE, self._handler_autosample_acquire_blank_sample) # this state would be entered whenever an ACQUIRE_BLANK_SAMPLE event # occurred while in the COMMAND state # and will last anywhere from a few seconds to 3 # minutes depending on instrument and sample type. self._protocol_fsm.add_handler( Pco2wProtocolState.POLLED_BLANK_SAMPLE, Pco2wProtocolEvent.ENTER, self._execution_state_enter) self._protocol_fsm.add_handler( Pco2wProtocolState.POLLED_BLANK_SAMPLE, Pco2wProtocolEvent.EXIT, self._execution_state_exit) self._protocol_fsm.add_handler( Pco2wProtocolState.POLLED_BLANK_SAMPLE, Pco2wProtocolEvent.EXECUTE, self._handler_take_blank_sample) self._protocol_fsm.add_handler( Pco2wProtocolState.POLLED_BLANK_SAMPLE, Pco2wProtocolEvent.SUCCESS, self._execution_success_to_command_state) self._protocol_fsm.add_handler( Pco2wProtocolState.POLLED_BLANK_SAMPLE, Pco2wProtocolEvent.TIMEOUT, self._execution_timeout_to_command_state) # this state would be entered whenever an ACQUIRE_BLANK_SAMPLE event # occurred while in the AUTOSAMPLE state # and will last anywhere from a few seconds to 3 # minutes depending on instrument and sample type. self._protocol_fsm.add_handler( Pco2wProtocolState.SCHEDULED_BLANK_SAMPLE, Pco2wProtocolEvent.ENTER, self._execution_state_enter) self._protocol_fsm.add_handler( Pco2wProtocolState.SCHEDULED_BLANK_SAMPLE, Pco2wProtocolEvent.EXIT, self._execution_state_exit) self._protocol_fsm.add_handler( Pco2wProtocolState.SCHEDULED_BLANK_SAMPLE, Pco2wProtocolEvent.EXECUTE, self._handler_take_blank_sample) self._protocol_fsm.add_handler( Pco2wProtocolState.SCHEDULED_BLANK_SAMPLE, Pco2wProtocolEvent.SUCCESS, self._execution_success_to_autosample_state) self._protocol_fsm.add_handler( Pco2wProtocolState.SCHEDULED_BLANK_SAMPLE, Pco2wProtocolEvent.TIMEOUT, self._execution_timeout_to_autosample_state) # this state would be entered whenever a DEIONIZED_WATER_FLUSH_100ML event # occurred while in the COMMAND state self._protocol_fsm.add_handler( Pco2wProtocolState.DEIONIZED_WATER_FLUSH_100ML, Pco2wProtocolEvent.ENTER, self._execution_state_enter) self._protocol_fsm.add_handler( Pco2wProtocolState.DEIONIZED_WATER_FLUSH_100ML, Pco2wProtocolEvent.EXIT, self._execution_state_exit) self._protocol_fsm.add_handler( Pco2wProtocolState.DEIONIZED_WATER_FLUSH_100ML, Pco2wProtocolEvent.EXECUTE, self._handler_deionized_water_flush_execute_100ml) self._protocol_fsm.add_handler( Pco2wProtocolState.DEIONIZED_WATER_FLUSH_100ML, Pco2wProtocolEvent.SUCCESS, self._execution_success_to_command_state) self._protocol_fsm.add_handler( Pco2wProtocolState.DEIONIZED_WATER_FLUSH_100ML, Pco2wProtocolEvent.TIMEOUT, self._execution_timeout_to_command_state) # this state would be entered whenever a REAGENT_FLUSH_100ML event # occurred while in the COMMAND state self._protocol_fsm.add_handler( Pco2wProtocolState.REAGENT_FLUSH_100ML, Pco2wProtocolEvent.ENTER, self._execution_state_enter) self._protocol_fsm.add_handler( Pco2wProtocolState.REAGENT_FLUSH_100ML, Pco2wProtocolEvent.EXIT, self._execution_state_exit) self._protocol_fsm.add_handler( Pco2wProtocolState.REAGENT_FLUSH_100ML, Pco2wProtocolEvent.EXECUTE, self._handler_reagent_flush_execute_100ml) self._protocol_fsm.add_handler( Pco2wProtocolState.REAGENT_FLUSH_100ML, Pco2wProtocolEvent.SUCCESS, self._execution_success_to_command_state) self._protocol_fsm.add_handler( Pco2wProtocolState.REAGENT_FLUSH_100ML, Pco2wProtocolEvent.TIMEOUT, self._execution_timeout_to_command_state) # this state would be entered whenever a DEIONIZED_WATER_FLUSH event # occurred while in the COMMAND state self._protocol_fsm.add_handler( Pco2wProtocolState.DEIONIZED_WATER_FLUSH, Pco2wProtocolEvent.ENTER, self._execution_state_enter) self._protocol_fsm.add_handler( Pco2wProtocolState.DEIONIZED_WATER_FLUSH, Pco2wProtocolEvent.EXIT, self._execution_state_exit) self._protocol_fsm.add_handler( Pco2wProtocolState.DEIONIZED_WATER_FLUSH, Pco2wProtocolEvent.EXECUTE, self._handler_deionized_water_flush_execute) self._protocol_fsm.add_handler( Pco2wProtocolState.DEIONIZED_WATER_FLUSH, Pco2wProtocolEvent.SUCCESS, self._execution_success_to_command_state) self._protocol_fsm.add_handler( Pco2wProtocolState.DEIONIZED_WATER_FLUSH, Pco2wProtocolEvent.TIMEOUT, self._execution_timeout_to_command_state) self._engineering_parameters.append(Pco2wParameter.PUMP_100ML_CYCLES) self._engineering_parameters.append(Pco2wParameter.DEIONIZED_WATER_FLUSH_DURATION) self._add_build_handler(Pco2wInstrumentCommand.PCO2W_ACQUIRE_BLANK_SAMPLE, self._build_simple_command) self._add_build_handler(Pco2wInstrumentCommand.PCO2W_PUMP_DEIONIZED_WATER, self._build_pump_command) self._add_build_handler(Pco2wInstrumentCommand.PCO2W_PUMP_REAGENT, self._build_pump_command) # Add response handlers for device commands. self._add_response_handler(Pco2wInstrumentCommand.PCO2W_ACQUIRE_BLANK_SAMPLE, self._parse_response_blank_sample_sami) self._add_response_handler(Pco2wInstrumentCommand.PCO2W_PUMP_DEIONIZED_WATER, self._parse_response_newline) self._add_response_handler(Pco2wInstrumentCommand.PCO2W_PUMP_REAGENT, self._parse_response_newline)