def send_command(self, command_args): """ Send given command to control node and wait for an answer :param command_args: command arguments :type command_args: list of string :return: received answers or `None` if timeout caught """ command_str = ' '.join(command_args) + '\n' with self._send_mutex: # remove existing items (old not treated answers) common.empty_queue(self.msgs) try: LOGGER.debug('control_node_cmd: %r', command_args) self.process.stdin.write(command_str) # wait for answer 1 second at max answer_cn = self.msgs.get(block=True, timeout=1.0) except queue.Empty: LOGGER.error('control_node_serial answer timeout') answer_cn = None except AttributeError: LOGGER.error('control_node_serial stdin is None') answer_cn = None except IOError: LOGGER.error('control_node_serial process is terminated') answer_cn = None finally: LOGGER.debug('control_node_answer: %r', answer_cn) return answer_cn
def send_command(self, command_args): """ Send given command to control node and wait for an answer :param command_args: command arguments :type command_args: list of string :return: received answers or `None` if timeout caught """ command_str = ' '.join(command_args) + '\n' with self._send_mutex: # remove existing items (old not treated answers) common.empty_queue(self.msgs) try: LOGGER.debug('control_node_cmd: %r', command_args) self.process.stdin.write(command_str) # wait for answer 1 second at max answer_cn = self.msgs.get(block=True, timeout=1.0) except Queue.Empty: LOGGER.error('control_node_serial answer timeout') answer_cn = None except AttributeError: LOGGER.error('control_node_serial stdin is None') answer_cn = None except IOError: LOGGER.error('control_node_serial process is terminated') answer_cn = None finally: LOGGER.debug('control_node_answer: %r', answer_cn) return answer_cn
def start(self, oml_xml_config=None): """Start control node interface. Run `control node serial program` and handle its answers. """ common.empty_queue(self._wait_ready) args = self._cn_interface_args(oml_xml_config) self.process = subprocess_timeout.Popen(args, stderr=PIPE, stdin=PIPE) self.reader_thread = threading.Thread(target=self._reader) self.reader_thread.start() ret = self._wait_ready.get() return ret