From f559d45b76e7937cfd56b93a281df99ff144180e Mon Sep 17 00:00:00 2001 From: William Vallet Date: Sun, 11 Dec 2022 19:06:43 +0100 Subject: [PATCH] Manage keyboard interrupt on demo --- demo/main.py | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/demo/main.py b/demo/main.py index 6b15b63..a8a660a 100644 --- a/demo/main.py +++ b/demo/main.py @@ -27,14 +27,17 @@ def parse_args(): export = ExportCSV(params.export) # Run data dump process. with UMmeter(params.tty) as meter: - while True: - data = meter.get_data() - now = datetime.now() - if export is not None: - export.update(now, data) - print( - f"[{data['model']}] {now.time()}" - f" {data['voltage']:1.04f}V {data['intensity']:1.04f}A" - f" {data['power']:1.04f}W {data['resistance']}Ohm" - ) - sleep(params.refresh) + try: + while True: + data = meter.get_data() + now = datetime.now() + if export is not None: + export.update(now, data) + print( + f"[{data['model']}] {now.time()}" + f" {data['voltage']:1.04f}V {data['intensity']:1.04f}A" + f" {data['power']:1.04f}W {data['resistance']}Ohm" + ) + sleep(params.refresh) + except KeyboardInterrupt: + pass