Skip to content

Commit 688ab84

Browse files
Capturing exceptions in settings ASI interface
1 parent 64226d5 commit 688ab84

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

microscope/controllers/asi.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -491,12 +491,14 @@ def _get_setting(self, command, axis, dtype, value):
491491
)
492492
answer = answer.strip().decode()
493493
if answer[:2] == ":A":
494-
if dtype == "int":
495-
return int(answer[5:])
496-
elif dtype == "float":
497-
return float(answer[5:])
494+
if answer[-2:] == " A": # Some setting return a non-standard pattern with two A's: ':A axis=value A'
495+
answer = answer[5:-1]
496+
elif command == "MC": # The MC command does not follow the standard return pattern. It returns ':A 1'
497+
answer = answer[3:]
498498
else:
499-
return answer[5:]
499+
answer = answer[5:] # What I believe is the standard pattern: ':A axis=value' (':A X=42')
500+
elif answer[:2] == f":{axis}":
501+
answer = answer[3:-2] # Many settings return ':axis=value A' (':X=42 A')
500502
elif answer[0] == "N":
501503
# this is an error string
502504
error = answer[2:]
@@ -506,6 +508,13 @@ def _get_setting(self, command, axis, dtype, value):
506508
else:
507509
raise Exception(f"ASI controller error: {answer}")
508510

511+
if dtype == "int":
512+
return int(answer)
513+
elif dtype == "float":
514+
return float(answer)
515+
else:
516+
return answer
517+
509518
def _set_setting(self, value, command, axis):
510519
if command is None:
511520
return False

0 commit comments

Comments
 (0)