def run(self, fileno): sys.stdin = os.fdopen(fileno) # open stdin in this process beg = False while True: if not beg: print("Select the following option for this board (0 to save and quit):\n" "\t1 - Free addressing message operation\n" "\t2 - Automatic addressing message operation (detailed in algo.txt file)") choice = input(">") try: choice_int = int(choice) except ValueError: choice_int = -1 if 1 <= choice_int <= 2: beg = False if choice_int == 1: self.free_mode() else: if not self.is_auto_active: self.auto_mode() self.is_auto_active = True else: print('Auto mode is already active') else: if choice_int == 0: transmit_msg(self.inter_addr, [False, 'quit']) else: print("Wrong entry. Try again") beg = True
def launch_boards(self): for i in range(len(self.list_boards)): subprocess.call( 'start venv/Scripts/python.exe core/board.py' + ' ' + self.list_boards[i][0], shell=True) # parameters are the address of the board transmit_msg(self.list_boards[i][0], self.conf_string) print("Boards initialized")
def auto_mode_process(self, param_table, delay): addr_target = self.find_port_from_name(param_table[1][1]) if addr_target == "": return while True: transmit_msg(addr_target, param_table) transmit_msg(self.inter_addr, param_table) self.queue.put(param_table) if delay == 0: break time.sleep(delay)
def free_mode(self): while True: value = input("Enter the board name follow by a / and the message to send (0 to return to menu):\n") count = Counter(value) if count['/'] == 1: [name, msg] = value.split('/', 2) addr = self.find_port_from_name(str(name).upper()) if addr == "": print("No board with this name found. Try again") continue data = [False, self.name + " sends MSG: " + msg] transmit_msg(addr, data) transmit_msg(self.inter_addr, data) self.queue.put(data) else: if value == '0': break print("Wrong entry. Try again")
def exit_prgm(self): for i in range(len(self.list_boards)): transmit_msg(self.list_boards[i][0], [False, 'quit']) time.sleep(0.05) sys.exit(0)