Skip to content

Commit

Permalink
homed and move completed fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rbudhrani committed Jul 10, 2024
1 parent 067c471 commit c251952
Showing 1 changed file with 10 additions and 20 deletions.
30 changes: 10 additions & 20 deletions qmi/instruments/thorlabs/mpc320.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,16 +316,11 @@ def is_channel_homed(self, channel_number: int, timeout: float = DEFAULT_RESPONS
_logger.info("[%s] Checking if channel %d is homed", self._name, channel_number)
self._validate_channel(channel_number)
self._check_is_open()
# This command needs a workaround. Instead of returning the MOT_MOVE_HOMED message, the instrument may return
# its current state first. So subsequent messages may have to be read.
num_reads = 5
while num_reads > 0:
try:
# Get response.
resp = self._apt_protocol.ask(MOT_MOVE_HOMED, timeout)
except QMI_InstrumentException:
num_reads -= 1
continue
# This command needs a workaround. Instead of returning the MOT_MOVE_HOMED message, the instrument returns
# its current state first, so read that to discard the buffer
_ = self._apt_protocol.ask(MOT_GET_USTATUSUPDATE, timeout)
# then read the actual response we need
resp = self._apt_protocol.ask(MOT_MOVE_HOMED, timeout)

# Check if the channel number in the response is equal to the one that was asked for.
return resp.chan_ident == Thorlabs_MPC320_ChannelMap[channel_number]
Expand Down Expand Up @@ -376,16 +371,11 @@ def is_move_completed(self, channel_number: int, timeout: float = DEFAULT_RESPON
)
self._validate_channel(channel_number)
self._check_is_open()
# This command needs a workaround. Instead of returning the MOT_MOVE_HOMED message, the instrument may return
# its current state first. So subsequent messages may have to be read.
num_reads = 5
while num_reads > 0:
try:
# Get response.
resp = self._apt_protocol.ask(MOT_MOVE_COMPLETED, timeout)
except QMI_InstrumentException:
num_reads -= 1
continue
# This command needs a workaround. Instead of returning the MOT_MOVE_COMPLETED message, the instrument returns
# its current state first, so read that to discard the buffer
_ = self._apt_protocol.ask(MOT_GET_USTATUSUPDATE, timeout)
# then read the actual response we need
resp = self._apt_protocol.ask(MOT_MOVE_COMPLETED, timeout)

return resp.chan_ident == Thorlabs_MPC320_ChannelMap[channel_number]

Expand Down

0 comments on commit c251952

Please sign in to comment.