From 938f0dd8ddaa074196b0109f973a4b5ecc8615fb Mon Sep 17 00:00:00 2001 From: neo-dl Date: Thu, 16 Feb 2023 15:58:09 +0100 Subject: [PATCH] second leak test tbt --- src/components/usb_586x.py | 42 +++++++++++++++++++++++++++-------- src/ui/test_leak/test_leak.py | 21 +++++++++++------- 2 files changed, 46 insertions(+), 17 deletions(-) diff --git a/src/components/usb_586x.py b/src/components/usb_586x.py index e9047a9..4d1f1e1 100644 --- a/src/components/usb_586x.py +++ b/src/components/usb_586x.py @@ -36,6 +36,7 @@ class USB_586x(Component): def __init__(self, config=None, name=None, period=1, lazy=True, paused=False, threaded=True): super().__init__(config=config, name=name, period=period, lazy=lazy, paused=paused, threaded=threaded) self.mutex = QMutex() + # DEVICE INFORMATION self.id=config["digital_io"]["id"] if "5860" in self.id: @@ -52,6 +53,19 @@ class USB_586x(Component): # self.info.DeviceNumber = -1 self.info.DeviceMode = 1 self.info.ModuleIndex = 0 + + self.open_device() + + # SET ALL RELAYS OFF + for bit in range(0, self.out_size*8): + self.set_bit(int(bit/8), bit%8, False) + + self.state_delay = 1 + self.last_get = None + self.state_count = None + self.last_out = None + + def open_device(self): # DIGITAL INPUTS CLASS if is_win: self.di_ctrl = InstantDiCtrl(self.info.Description) @@ -90,15 +104,8 @@ class USB_586x(Component): self.do_ctrl = self.do_create() self.di_init_status = self.di_setSelectedDevice(self.di_ctrl, ctypes.byref(self.info)) self.do_init_status = self.do_setSelectedDevice(self.do_ctrl, ctypes.byref(self.info)) - - # SET ALL RELAYS OFF - for bit in range(0, self.out_size*8): - self.set_bit(int(bit/8), bit%8, False) - - self.state_delay = 1 - self.last_get = None - self.state_count = None - self.last_out = None + def close_device(self): + pass @pyqtSlot() def start(self): @@ -177,6 +184,23 @@ class USB_586x(Component): else: ret=self.do_write_bit(self.do_ctrl, byte, bit, int(val)) self.mutex.unlock() + return ret + + def set_bit_verify(self, byte, bit, val): + + ok = False + retry=0 + max_retry = 3 + while not ok and retry