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. """ # Build protocol state machine. self._protocol_fsm = ThreadSafeFSM( ProtocolState, ProtocolEvent, ProtocolEvent.ENTER, ProtocolEvent.EXIT) # Construct protocol superclass. Pco2wProtocol.__init__(self, prompts, newline, driver_event) # Build protocol state machine. self._protocol_fsm.add_handler( ProtocolState.COMMAND, ProtocolEvent.RUN_EXTERNAL_PUMP, self._handler_command_run_external_pump) # this state would be entered whenever a RUN_EXTERNAL_PUMP event # occurred while in the COMMAND state self._protocol_fsm.add_handler( ProtocolState.RUN_EXTERNAL_PUMP, ProtocolEvent.ENTER, self._execution_state_enter) self._protocol_fsm.add_handler( ProtocolState.RUN_EXTERNAL_PUMP, ProtocolEvent.EXIT, self._execution_state_exit) self._protocol_fsm.add_handler( ProtocolState.RUN_EXTERNAL_PUMP, ProtocolEvent.EXECUTE, self._handler_run_external_pump_execute) self._protocol_fsm.add_handler( ProtocolState.RUN_EXTERNAL_PUMP, ProtocolEvent.SUCCESS, self._execution_success_to_command_state) self._protocol_fsm.add_handler( ProtocolState.RUN_EXTERNAL_PUMP, ProtocolEvent.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( ProtocolState.RUN_EXTERNAL_PUMP, ProtocolEvent.ACQUIRE_STATUS, self._handler_queue_acquire_status) # Add build handlers for device commands. ### primarily defined in base class self._add_build_handler(InstrumentCommand.PCO2WB_ACQUIRE_SAMPLE_DEV1, self._build_simple_command) # Add response handlers for device commands. ### primarily defined in base class self._add_response_handler(InstrumentCommand.PCO2WB_ACQUIRE_SAMPLE_DEV1, self._parse_response_sample_dev1) # Add sample handlers # Start state machine in UNKNOWN state. self._protocol_fsm.start(ProtocolState.UNKNOWN) # build the chunker self._chunker = StringChunker(Protocol.sieve_function) self._engineering_parameters.append(Parameter.EXTERNAL_PUMP_DELAY)
def _build_command_dict(self): """ Populate the command dictionary with command. """ Pco2wProtocol._build_command_dict(self) self._cmd_dict.add(Capability.RUN_EXTERNAL_PUMP, display_name="Run External Pump")
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. """ # Build protocol state machine. self._protocol_fsm = ThreadSafeFSM(ProtocolState, ProtocolEvent, ProtocolEvent.ENTER, ProtocolEvent.EXIT) # Construct protocol superclass. Pco2wProtocol.__init__(self, prompts, newline, driver_event) # Build protocol state machine. # Start state machine in UNKNOWN state. self._protocol_fsm.start(ProtocolState.UNKNOWN) # build the chunker self._chunker = StringChunker(Protocol.sieve_function)
def _build_param_dict(self): """ For each parameter key, add match string, match lambda function, and value formatting function for set commands. """ Pco2wProtocol._build_param_dict(self) ### example configuration string # VALID_CONFIG_STRING = 'CEE90B0002C7EA0001E133800A000E100402000E10010B' + \ # '000000000D000000000D000000000D07' + \ # '1020FF54181C01003814' + \ # '000000000000000000000000000000000000000000000000000' + \ # '000000000000000000000000000000000000000000000000000' + \ # '0000000000000000000000000000' + \ # 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF' + \ # 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF' + \ # 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF' + \ # 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF' + \ # 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF' + \ # 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFF' + NEWLINE # ### configuration_string_regex = self._get_configuration_string_regex() self._param_dict.add(Parameter.MODE_BITS, configuration_string_regex, lambda match: int(match.group(4), 16), lambda x: self._int_to_hexstring(x, 2), type=ParameterDictType.INT, startup_param=True, direct_access=True, default_value=0x02, visibility=ParameterDictVisibility.IMMUTABLE, display_name='Mode Bits', description='Switch bits for sample scheduling.') self._param_dict.add(Parameter.DEVICE1_SAMPLE_INTERVAL, configuration_string_regex, lambda match: int(match.group(8), 16), lambda x: self._int_to_hexstring(x, 6), type=ParameterDictType.INT, startup_param=True, direct_access=True, default_value=0x000E10, visibility=ParameterDictVisibility.IMMUTABLE, display_name='Device 1 Sample Interval', description='', units=Units.SECOND) self._param_dict.add(Parameter.DEVICE1_DRIVER_VERSION, configuration_string_regex, lambda match: int(match.group(9), 16), lambda x: self._int_to_hexstring(x, 2), type=ParameterDictType.INT, startup_param=True, direct_access=True, default_value=0x01, visibility=ParameterDictVisibility.IMMUTABLE, display_name='Device 1 Driver Version', description='') self._param_dict.add(Parameter.DEVICE1_PARAMS_POINTER, configuration_string_regex, lambda match: int(match.group(10), 16), lambda x: self._int_to_hexstring(x, 2), type=ParameterDictType.INT, startup_param=True, direct_access=True, default_value=0x0B, visibility=ParameterDictVisibility.IMMUTABLE, display_name='Device 1 Parameter Pointer', description='Pointer to device 1 parameters (offset from position 76).') self._param_dict.add(Parameter.EXTERNAL_PUMP_SETTINGS, configuration_string_regex, lambda match: int(match.group(30), 16), lambda x: self._int_to_hexstring(x, 2), type=ParameterDictType.INT, startup_param=True, direct_access=True, default_value=0x1E, range=(0, 0xFF), visibility=ParameterDictVisibility.READ_WRITE, display_name='External Pump Settings', description='Timeout for taking a device 1 sample.', units=Units.SECOND) ## Engineering parameter to set delay after running external pump to take a sample, set as startup parameter ## because it is configurable by the user and should be reapplied on application of startup parameters. self._param_dict.add(Parameter.EXTERNAL_PUMP_DELAY, r'External pump delay = ([0-9]+)', lambda match: match.group(1), lambda x: int(x), type=ParameterDictType.INT, startup_param=True, direct_access=False, default_value=360, range=(0, 86400), # up to 1 day visibility=ParameterDictVisibility.READ_WRITE, display_name='External Pump Delay', description='Time to wait before taking a sample after running the external pump.', units=Units.SECOND)
def _build_param_dict(self): """ For each parameter key, add match string, match lambda function, and value formatting function for set commands. """ Pco2wProtocol._build_param_dict(self) ### example configuration string # VALID_CONFIG_STRING = 'CEE90B0002C7EA0001E133800A000E100402000E10010B' + \ # '000000000D000000000D000000000D07' + \ # '1020FF54181C010038' + \ # '000000000000000000000000000000000000000000000000000' + \ # '000000000000000000000000000000000000000000000000000' + \ # '000000000000000000000000000000' + \ # 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF' + \ # 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF' + \ # 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF' + \ # 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF' + \ # 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF' + \ # 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFF' + NEWLINE # ### configuration_string_regex = self._get_configuration_string_regex() # Changed from 0x0A to 0x02 to indicate there is no external device, update IOS to indicate this is 0x02 self._param_dict.add(Parameter.MODE_BITS, configuration_string_regex, lambda match: int(match.group(4), 16), lambda x: self._int_to_hexstring(x, 2), type=ParameterDictType.INT, startup_param=True, direct_access=True, default_value=0x02, visibility=ParameterDictVisibility.READ_ONLY, display_name='Mode Bits') ## Changed from 0x000E10 to 0x000000 to indicate there is not external device self._param_dict.add(Parameter.DEVICE1_SAMPLE_INTERVAL, configuration_string_regex, lambda match: int(match.group(8), 16), lambda x: self._int_to_hexstring(x, 6), type=ParameterDictType.INT, startup_param=True, direct_access=True, default_value=0x000000, visibility=ParameterDictVisibility.READ_ONLY, display_name='Device 1 Sample Interval') ## Changed from 0x01 to 0x00 to indicate there is not external device self._param_dict.add(Parameter.DEVICE1_DRIVER_VERSION, configuration_string_regex, lambda match: int(match.group(9), 16), lambda x: self._int_to_hexstring(x, 2), type=ParameterDictType.INT, startup_param=True, direct_access=True, default_value=0x00, visibility=ParameterDictVisibility.READ_ONLY, display_name='Device 1 Driver Version') ## Changed from 0x0B to 0x00 to indicate there is not external device self._param_dict.add(Parameter.DEVICE1_PARAMS_POINTER, configuration_string_regex, lambda match: int(match.group(10), 16), lambda x: self._int_to_hexstring(x, 2), type=ParameterDictType.INT, startup_param=True, direct_access=True, default_value=0x00, visibility=ParameterDictVisibility.READ_ONLY, display_name='Device 1 Parameter Pointer')
def _build_param_dict(self): """ For each parameter key, add match string, match lambda function, and value formatting function for set commands. """ Pco2wProtocol._build_param_dict(self) ### example configuration string # VALID_CONFIG_STRING = 'CEE90B0002C7EA0001E133800A000E100402000E10010B' + \ # '000000000D000000000D000000000D07' + \ # '1020FF54181C01003814' + \ # '000000000000000000000000000000000000000000000000000' + \ # '000000000000000000000000000000000000000000000000000' + \ # '0000000000000000000000000000' + \ # 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF' + \ # 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF' + \ # 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF' + \ # 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF' + \ # 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF' + \ # 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFF' + NEWLINE # ### configuration_string_regex = self._get_configuration_string_regex() self._param_dict.add(Parameter.MODE_BITS, configuration_string_regex, lambda match: int(match.group(4), 16), lambda x: self._int_to_hexstring(x, 2), type=ParameterDictType.INT, startup_param=True, direct_access=True, default_value=0x0A, visibility=ParameterDictVisibility.READ_ONLY, display_name='Mode Bits') self._param_dict.add(Parameter.DEVICE1_SAMPLE_INTERVAL, configuration_string_regex, lambda match: int(match.group(8), 16), lambda x: self._int_to_hexstring(x, 6), type=ParameterDictType.INT, startup_param=True, direct_access=True, default_value=0x000E10, visibility=ParameterDictVisibility.READ_ONLY, display_name='Device 1 Sample Interval') self._param_dict.add(Parameter.DEVICE1_DRIVER_VERSION, configuration_string_regex, lambda match: int(match.group(9), 16), lambda x: self._int_to_hexstring(x, 2), type=ParameterDictType.INT, startup_param=True, direct_access=True, default_value=0x01, visibility=ParameterDictVisibility.READ_ONLY, display_name='Device 1 Driver Version') self._param_dict.add(Parameter.DEVICE1_PARAMS_POINTER, configuration_string_regex, lambda match: int(match.group(10), 16), lambda x: self._int_to_hexstring(x, 2), type=ParameterDictType.INT, startup_param=True, direct_access=True, default_value=0x0B, visibility=ParameterDictVisibility.READ_ONLY, display_name='Device 1 Parameter Pointer') self._param_dict.add(Parameter.EXTERNAL_PUMP_SETTINGS, configuration_string_regex, lambda match: int(match.group(30), 16), lambda x: self._int_to_hexstring(x, 2), type=ParameterDictType.INT, startup_param=True, direct_access=True, default_value=0x1E, visibility=ParameterDictVisibility.READ_WRITE, display_name='External Pump Settings') ## Engineering parameter to set delay after running external pump to take a sample, set as startup parameter ## because it is configurable by the user and should be reapplied on application of startup parameters. self._param_dict.add(Parameter.EXTERNAL_PUMP_DELAY, r'External pump delay = ([0-9]+)', lambda match: match.group(1), lambda x: int(x), type=ParameterDictType.INT, startup_param=True, direct_access=False, default_value=360, visibility=ParameterDictVisibility.READ_WRITE, display_name='External Pump Delay')
def _build_param_dict(self): """ For each parameter key, add match string, match lambda function, and value formatting function for set commands. """ Pco2wProtocol._build_param_dict(self) ### example configuration string # VALID_CONFIG_STRING = 'CEE90B0002C7EA0001E133800A000E100402000E10010B' + \ # '000000000D000000000D000000000D07' + \ # '1020FF54181C01003814' + \ # '000000000000000000000000000000000000000000000000000' + \ # '000000000000000000000000000000000000000000000000000' + \ # '0000000000000000000000000000' + \ # 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF' + \ # 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF' + \ # 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF' + \ # 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF' + \ # 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF' + \ # 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFF' + NEWLINE # ### configuration_string_regex = self._get_configuration_string_regex() self._param_dict.add( Parameter.MODE_BITS, configuration_string_regex, lambda match: int(match.group(4), 16), lambda x: self._int_to_hexstring(x, 2), type=ParameterDictType.INT, startup_param=True, direct_access=True, default_value=0x0A, visibility=ParameterDictVisibility.READ_ONLY, display_name="Mode Bits", ) self._param_dict.add( Parameter.DEVICE1_SAMPLE_INTERVAL, configuration_string_regex, lambda match: int(match.group(8), 16), lambda x: self._int_to_hexstring(x, 6), type=ParameterDictType.INT, startup_param=True, direct_access=True, default_value=0x000E10, visibility=ParameterDictVisibility.READ_ONLY, display_name="Device 1 Sample Interval", ) self._param_dict.add( Parameter.DEVICE1_DRIVER_VERSION, configuration_string_regex, lambda match: int(match.group(9), 16), lambda x: self._int_to_hexstring(x, 2), type=ParameterDictType.INT, startup_param=True, direct_access=True, default_value=0x01, visibility=ParameterDictVisibility.READ_ONLY, display_name="Device 1 Driver Version", ) self._param_dict.add( Parameter.DEVICE1_PARAMS_POINTER, configuration_string_regex, lambda match: int(match.group(10), 16), lambda x: self._int_to_hexstring(x, 2), type=ParameterDictType.INT, startup_param=True, direct_access=True, default_value=0x0B, visibility=ParameterDictVisibility.READ_ONLY, display_name="Device 1 Parameter Pointer", ) self._param_dict.add( Parameter.EXTERNAL_PUMP_SETTINGS, configuration_string_regex, lambda match: int(match.group(30), 16), lambda x: self._int_to_hexstring(x, 2), type=ParameterDictType.INT, startup_param=True, direct_access=True, default_value=0x1E, visibility=ParameterDictVisibility.READ_WRITE, display_name="External Pump Settings", ) ## Engineering parameter to set delay after running external pump to take a sample, set as startup parameter ## because it is configurable by the user and should be reapplied on application of startup parameters. self._param_dict.add( Parameter.EXTERNAL_PUMP_DELAY, r"External pump delay = ([0-9]+)", lambda match: match.group(1), lambda x: int(x), type=ParameterDictType.INT, startup_param=True, direct_access=False, default_value=360, visibility=ParameterDictVisibility.READ_WRITE, display_name="External Pump Delay", )