diff --git a/software/script/chameleon_cli_main.py b/software/script/chameleon_cli_main.py index 8f8ded7..89a2409 100644 --- a/software/script/chameleon_cli_main.py +++ b/software/script/chameleon_cli_main.py @@ -147,11 +147,21 @@ class ChameleonCLI: :return: """ self.print_banner() + closing = False while True: # wait user input status = f"{colorama.Fore.GREEN}USB" if self.device_com.isOpen() else f"{colorama.Fore.RED}Offline" print(f"[{status}{colorama.Style.RESET_ALL}] chameleon --> ", end="") - cmd_str = input().strip() + try: + cmd_str = input().strip() + except EOFError: + print("") + closing = True + + if closing or cmd_str == "exit": + print("Bye, thank you. ^.^ ") + self.device_com.close() + sys.exit(996) # clear screen if cmd_str == "clear": @@ -163,10 +173,6 @@ class ChameleonCLI: print("No screen clear implement") continue - if cmd_str == "exit": - print("Bye, thank you. ^.^ ") - sys.exit(996) - # parse cmd cmd_map, args_str = self.parse_cli_cmd(cmd_str) is_exec_map = 'unit' in cmd_map diff --git a/software/script/chameleon_cli_unit.py b/software/script/chameleon_cli_unit.py index 4e6e029..562bfad 100644 --- a/software/script/chameleon_cli_unit.py +++ b/software/script/chameleon_cli_unit.py @@ -935,9 +935,7 @@ class HWSlotOpenAll(DeviceRequiredUnit): lf_type = chameleon_cmd.TagSpecificType.TAG_TYPE_EM410X # set all slot - for slot in range(8): - # the slot not from 0 offset, so we can inc 1. - slot = slot + 1 + for slot in range(1,9): print(f' Slot{slot} setting...') # first to set tag type self.cmd_positive.set_slot_tag_type(slot, hf_type) diff --git a/software/script/chameleon_com.py b/software/script/chameleon_com.py index cbe72c3..f4bad59 100644 --- a/software/script/chameleon_com.py +++ b/software/script/chameleon_com.py @@ -52,6 +52,7 @@ class ChameleonCom: self.serial_instance: serial.Serial = None self.send_data_queue = queue.Queue() self.wait_response_map = {} + self.event_closing = threading.Event() def isOpen(self): """ @@ -83,6 +84,7 @@ class ChameleonCom: self.send_data_queue.queue.clear() self.wait_response_map.clear() # Start a sub thread to process data + self.event_closing.clear() threading.Thread(target=self.thread_data_receive, ).start() threading.Thread(target=self.thread_data_transfer, ).start() threading.Thread(target=self.thread_check_timeout, ).start() @@ -115,6 +117,7 @@ class ChameleonCom: Close chameleon and clear variable :return: """ + self.event_closing.set() try: self.serial_instance.close() except: @@ -140,7 +143,8 @@ class ChameleonCom: try: data_bytes = self.serial_instance.read() except Exception as e: - print(f"Serial Error {e}, thread for receiver exit.") + if not self.event_closing.is_set(): + print(f"Serial Error {e}, thread for receiver exit.") self.close() break if len(data_bytes) > 0: