mirror of
https://github.com/RfidResearchGroup/ChameleonUltra.git
synced 2026-05-12 11:22:59 -07:00
Graceful exit, also on ctrl-d
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user