From 81ab801fe46737971500b1a2f85de5edb87d94ac Mon Sep 17 00:00:00 2001 From: Yann Sionneau Date: Fri, 28 Nov 2014 17:36:26 +0100 Subject: [PATCH] lda: filter reports when waiting for command response --- artiq/devices/lda/lda-controller.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/artiq/devices/lda/lda-controller.py b/artiq/devices/lda/lda-controller.py index 3925558f7..3cb1c5ea7 100755 --- a/artiq/devices/lda/lda-controller.py +++ b/artiq/devices/lda/lda-controller.py @@ -175,8 +175,6 @@ class Lda: self.write(command, len(data), data) def get(self, command, length, timeout=1000): - # FIXME: this can collide with the status reports that the - # device sends out by itself """Sends a GET command to read back some value of the Lab Brick device. :param int command: Command ID, most significant bit must be cleared. @@ -187,13 +185,15 @@ class Lda: """ assert not command & 0x80 + status = None self.write(command, length) buf = ctypes.create_string_buffer(8) - res = self._check_error(hidapi.hid_read_timeout(self._dev, - buf, len(buf), timeout)) - assert res == len(buf), res - command, length, data = struct.unpack("BB6s", buf.raw) - data = data[:length] + while status != command: + res = self._check_error(hidapi.hid_read_timeout(self._dev, + buf, len(buf), timeout)) + assert res == len(buf), res + status, length, data = struct.unpack("BB6s", buf.raw) + data = data[:length] logger.info("%s %s %r", command, length, data) return data