From 655eb4874f006c64f78d398c6a8b354aa6c2b177 Mon Sep 17 00:00:00 2001 From: Ilya Zhuravlev Date: Fri, 5 Feb 2021 01:39:15 -0500 Subject: [PATCH] vial_device: retry opening up to 10 times --- src/main/python/vial_device.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/python/vial_device.py b/src/main/python/vial_device.py index 183ed84..f3d7ccb 100644 --- a/src/main/python/vial_device.py +++ b/src/main/python/vial_device.py @@ -1,4 +1,6 @@ # SPDX-License-Identifier: GPL-2.0-or-later +import time + from hidproxy import hid from keyboard_comm import Keyboard, DummyKeyboard from util import MSG_LEN, pad_for_vibl @@ -13,9 +15,14 @@ class VialDevice: self.via_stack = False def open(self, override_json=None): - # TODO: error handling here self.dev = hid.device() - self.dev.open_path(self.desc["path"]) + for x in range(10): + try: + self.dev.open_path(self.desc["path"]) + return + except OSError: + time.sleep(1) + raise RuntimeError("unable to open the device") def send(self, data): # add 00 at start for hidapi report id