Skip to content

Commit cd2994e

Browse files
committed
Add timeout to avoid infinite loop during startup
1 parent 47a0f5d commit cd2994e

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/aslm/model/devices/stages/stage_asi.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@
4545

4646

4747
def build_ASI_Stage_connection(com_port,
48-
baud_rate):
48+
baud_rate,
49+
timeout=1000):
4950
"""Connect to the ASI Stage
5051
5152
Parameters
@@ -54,6 +55,8 @@ def build_ASI_Stage_connection(com_port,
5455
Communication port for ASI Tiger Controller - e.g., COM1
5556
baud_rate : int
5657
Baud rate for ASI Tiger Controller - e.g., 9600
58+
timeout: int
59+
Time to wait for stage in milliseconds.
5760
5861
Returns
5962
-------
@@ -63,14 +66,20 @@ def build_ASI_Stage_connection(com_port,
6366

6467
# wait until ASI device is ready
6568
block_flag = True
69+
wait_start = time.time()
70+
timeout_s = timeout/1000
6671
while block_flag:
6772
asi_stage = TigerController(com_port, baud_rate)
6873
asi_stage.connect_to_serial()
6974
if asi_stage.is_open():
7075
block_flag = False
7176
else:
7277
print("Trying to connect to the ASI Stage again")
78+
elapsed = time.time()
79+
if (elapsed - wait_start) > timeout_s:
80+
break
7381
time.sleep(0.1)
82+
7483
return asi_stage
7584

7685

0 commit comments

Comments
 (0)