From 39d6298c0d62a077bfc1b7bf09aaf3a30146090f Mon Sep 17 00:00:00 2001 From: Alex Mikhalev Date: Sat, 9 Feb 2019 19:48:52 -0800 Subject: [PATCH] e32_client graceful exit --- e32_client/requirements.txt | 0 e32_client/ugv.py | 24 ++++++++++++++---------- 2 files changed, 14 insertions(+), 10 deletions(-) create mode 100644 e32_client/requirements.txt diff --git a/e32_client/requirements.txt b/e32_client/requirements.txt new file mode 100644 index 0000000..e69de29 diff --git a/e32_client/ugv.py b/e32_client/ugv.py index b695762..bc20f50 100755 --- a/e32_client/ugv.py +++ b/e32_client/ugv.py @@ -38,7 +38,7 @@ class UGVComms(E32): def __rx_thread_entry(ugv: UGVComms): - while True: + while ugv.ser.is_open: try: msg = ugv.read_message() if msg is not None: @@ -59,15 +59,19 @@ if __name__ == "__main__": # ugv.reset() cmd_id = 1 time.sleep(0.2) - while True: - gmsg = messages.GroundMessage() - gmsg.command.id = cmd_id - gmsg.command.type = messages.DISABLE - cmd_id += 1 - print("writing message: ", gmsg) - ugv.write_message(gmsg) - time.sleep(2.) + try: + while True: + gmsg = messages.GroundMessage() + gmsg.command.id = cmd_id + gmsg.command.type = messages.DISABLE + cmd_id += 1 + print("writing message: ", gmsg) + ugv.write_message(gmsg) + time.sleep(2.) + except KeyboardInterrupt: + print("exiting...") + finally: + ugv.ser.close() - rx_thread.In rx_thread.join()