Skip to content

Commit

Permalink
ENH: added error catching when address is wrong
Browse files Browse the repository at this point in the history
  • Loading branch information
rpartzsch committed Jan 8, 2025
1 parent 604bad8 commit 94a78d8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
15 changes: 13 additions & 2 deletions motor_stage_ui/PIStagesInterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ def _read(self):
.decode()
.strip(self._terminator)
)
if msg == "":
self.log.error("No responds from motor controller.")
raise ValueError
return msg

def _write_read(self, command: str, address: int = None):
Expand Down Expand Up @@ -276,8 +279,16 @@ def _get_position(self, address: int) -> None:
Returns:
int: current position of motorstage in integer step sizes
"""
msg = self._write_read("TP", address)[3:].replace("+", "").replace(":", "")
return int(msg)
try:
msg = int(
self._write_read("TP", address)[3:].replace("+", "").replace(":", "")
)
except ValueError:
self.log.error(
"Invalid motor stage responds:, check addresses, baudrate..."
)
raise ValueError
return msg

def _calculate_value(
self, amount: str, unit: str, stage: str, step_size: float
Expand Down
2 changes: 1 addition & 1 deletion motor_stage_ui/motor_stage_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def motor_gui(
name (int, optional): Name of the motorstage. Defaults to 1.
"""
name = QLineEdit(text=name, parent=self)
name.move(0, (address - 1) * 30 + 20)
name.move(0, index * 30 + 20)
name.resize(100, 30)
name.setAlignment(Qt.AlignCenter)

Expand Down

0 comments on commit 94a78d8

Please sign in to comment.