Skip to content

Commit 2b2f7f9

Browse files
committed
ham tilt module wait for response
1 parent c3949e1 commit 2b2f7f9

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

pylabrobot/tilting/hamilton_backend.py

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import re
2-
from typing import Optional, cast
2+
from typing import Optional
33

44
try:
55
import serial
@@ -30,26 +30,21 @@ def __init__(
3030
f"pyserial is required for the Hamilton tilt module backend. Import error: {_SERIAL_IMPORT_ERROR}"
3131
)
3232

33-
self.setup_finished = False
3433
self.com_port = com_port
35-
self.timeout = timeout
36-
self.write_timeout = write_timeout
3734
self.io = Serial(
3835
port=self.com_port,
3936
baudrate=1200,
4037
bytesize=serial.EIGHTBITS,
4138
parity=serial.PARITY_EVEN,
4239
stopbits=serial.STOPBITS_ONE,
43-
write_timeout=self.write_timeout,
44-
timeout=self.timeout,
40+
write_timeout=write_timeout,
41+
timeout=timeout,
4542
)
4643

4744
async def setup(self, initial_offset: int = 0):
4845
await self.io.setup()
4946
await self.tilt_initial_offset(initial_offset)
50-
await self.send_command("SI")
51-
52-
self.setup_finished = True
47+
await self.tilt_initialize()
5348

5449
async def stop(self):
5550
await self.io.stop()
@@ -61,7 +56,9 @@ async def send_command(self, command: str, parameter: Optional[str] = None) -> s
6156
parameter = ""
6257

6358
await self.io.write(f"99{command}{parameter}\r\n".encode("utf-8"))
64-
resp = (await self.io.read(128)).decode("utf-8")
59+
resp = ""
60+
while not resp.startswith("T1" + command):
61+
resp = (await self.io.read(128)).decode("utf-8")
6562

6663
# Check for error.
6764
error_matches = re.search("er[0-9]{2}", resp)
@@ -81,9 +78,7 @@ async def send_command(self, command: str, parameter: Optional[str] = None) -> s
8178
if err_code != 0:
8279
raise RuntimeError(f"Unexpected error code: {err_code}")
8380

84-
return cast(
85-
str, resp
86-
) # must do stupid because mypy will not recognize that pyserial is typed..
81+
return resp
8782

8883
async def set_angle(self, angle: float):
8984
"""Set the tilt module to rotate by a given angle."""

0 commit comments

Comments
 (0)