Skip to content

Commit 8f25dbf

Browse files
committed
use send_command in luminescence
1 parent d9be377 commit 8f25dbf

File tree

1 file changed

+31
-34
lines changed

1 file changed

+31
-34
lines changed

pylabrobot/plate_reading/byonoy.py

Lines changed: 31 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ class Byonoy(PlateReaderBackend):
1414
absorbance, or fluorescence from a plate."""
1515

1616
def __init__(self) -> None:
17-
self.io = HID(vid=0x16D0, pid=0x1199) # 16d0:119B for fluorescence
17+
# self.io = HID(vid=0x16D0, pid=0x1199) # 16d0:119B for fluorescence
18+
self.io = HID(vid=0x16D0, pid=0x119B) # 16d0:119B for fluorescence
1819
self._background_thread: Optional[threading.Thread] = None
1920
self._stop_background = threading.Event()
2021
self._ping_interval = 1.0 # Send ping every second
@@ -68,22 +69,6 @@ def _start_background_pings(self) -> None:
6869
def _stop_background_pings(self) -> None:
6970
self._sending_pings = False
7071

71-
async def _read_until_empty(self, timeout=30):
72-
data = b""
73-
while True:
74-
chunk = await self.io.read(64, timeout=timeout)
75-
if not chunk:
76-
break
77-
data += chunk
78-
79-
if chunk.startswith(b"\x70"):
80-
await self.io.write(
81-
bytes.fromhex(
82-
"20007000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
83-
)
84-
)
85-
return data
86-
8772
async def _wait_for_response(self, timeout=30):
8873
time.sleep(1)
8974
data = b""
@@ -126,35 +111,38 @@ async def read_luminescence(self, plate: Plate, focal_height: float) -> List[Lis
126111

127112
# TODO: confirm that this particular device can read luminescence
128113

129-
await self.io.write(
114+
await self.send_command(
130115
bytes.fromhex(
131-
"10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040"
116+
"0010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040"
132117
)
133118
)
134-
await self.io.write(
119+
await self.send_command(
135120
bytes.fromhex(
136-
"50000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040"
121+
"0050000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040"
137122
)
138123
)
139-
await self.io.write(
124+
await self.send_command(
140125
bytes.fromhex(
141-
"00020700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008040"
126+
"0000020700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008040"
142127
)
143128
)
144-
await self.io.write(
129+
await self.send_command(
145130
bytes.fromhex(
146-
"40000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040"
147-
)
131+
"0040000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040"
132+
),
133+
wait_for_response=False
148134
)
149-
await self.io.write(
135+
await self.send_command(
150136
bytes.fromhex(
151-
"400380841e00ffffffffffffffffffffffff00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040"
152-
)
137+
"00400380841e00ffffffffffffffffffffffff00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040"
138+
),
139+
wait_for_response=False
153140
)
154-
await self.io.write(
141+
await self.send_command(
155142
bytes.fromhex(
156-
"40000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008040"
157-
)
143+
"0040000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008040"
144+
),
145+
wait_for_response=False
158146
)
159147

160148
t0 = time.time()
@@ -166,7 +154,7 @@ async def read_luminescence(self, plate: Plate, focal_height: float) -> List[Lis
166154
if time.time() - t0 > 120:
167155
break
168156

169-
chunk = await self._read_until_empty(timeout=30)
157+
chunk = await self.io.read(64, timeout=30)
170158

171159
if (
172160
bytes.fromhex(
@@ -189,7 +177,8 @@ async def read_luminescence(self, plate: Plate, focal_height: float) -> List[Lis
189177
self._start_background_pings()
190178

191179
# split data in 64 byte chunks
192-
start = 64 * 5
180+
chunks = [data[i : i + 64] for i in range(0, len(data), 64)]
181+
start = 64 * (chunks.index(bytes.fromhex("30000000000034000000526573756c74732020546f7020526561646f75740a0a0000000000000000000000000000000000000000000000000000000000000000")) + 1)
193182
blob_size = 64 * 9
194183
num_blobs = 8
195184
blobs = [data[start + i * blob_size : start + (i + 1) * blob_size] for i in range(num_blobs)]
@@ -233,6 +222,14 @@ async def send_command(self, command: bytes, wait_for_response: bool = True) ->
233222
if len(response) == 0:
234223
continue
235224

225+
if True:
226+
if response.startswith(b"\x70"):
227+
await self.io.write(
228+
bytes.fromhex(
229+
"20007000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
230+
)
231+
)
232+
236233
# if the first 2 bytes do not match, we continue reading
237234
if not response.startswith(should_start):
238235
response = b""

0 commit comments

Comments
 (0)