Skip to content

Commit

Permalink
feat(modules): request reset reason on module connection (#17052)
Browse files Browse the repository at this point in the history
  • Loading branch information
caila-marashaj authored Dec 6, 2024
1 parent a9fe59a commit 0644df1
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 15 deletions.
13 changes: 11 additions & 2 deletions api/src/opentrons/drivers/heater_shaker/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class GCODE(str, Enum):
CLOSE_LABWARE_LATCH = "M243"
GET_LABWARE_LATCH_STATE = "M241"
DEACTIVATE_HEATER = "M106"
GET_RESET_REASON = "M114"


HS_BAUDRATE = 115200
Expand Down Expand Up @@ -166,12 +167,20 @@ async def home(self) -> None:

async def get_device_info(self) -> Dict[str, str]:
"""Send get-device-info command"""
c = CommandBuilder(terminator=HS_COMMAND_TERMINATOR).add_gcode(
device_info = CommandBuilder(terminator=HS_COMMAND_TERMINATOR).add_gcode(
gcode=GCODE.GET_VERSION
)
response = await self._connection.send_command(
command=c, retries=DEFAULT_COMMAND_RETRIES
command=device_info, retries=DEFAULT_COMMAND_RETRIES
)

reset_reason = CommandBuilder(terminator=HS_COMMAND_TERMINATOR).add_gcode(
gcode=GCODE.GET_RESET_REASON
)
await self._connection.send_command(
command=reset_reason, retries=DEFAULT_COMMAND_RETRIES
)

return utils.parse_hs_device_information(device_info_string=response)

async def enter_programming_mode(self) -> None:
Expand Down
11 changes: 9 additions & 2 deletions api/src/opentrons/drivers/temp_deck/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class GCODE(str, Enum):
GET_TEMP = "M105"
SET_TEMP = "M104"
DEVICE_INFO = "M115"
GET_RESET_REASON = "M114"
DISENGAGE = "M18"
PROGRAMMING_MODE = "dfu"

Expand Down Expand Up @@ -154,10 +155,16 @@ async def get_device_info(self) -> Dict[str, str]:
Example input from Temp-Deck's serial response:
"serial:aa11bb22 model:aa11bb22 version:aa11bb22"
"""
c = CommandBuilder(terminator=TEMP_DECK_COMMAND_TERMINATOR).add_gcode(
device_info = CommandBuilder(terminator=TEMP_DECK_COMMAND_TERMINATOR).add_gcode(
gcode=GCODE.DEVICE_INFO
)
response = await self._send_command(command=c)
response = await self._send_command(command=device_info)

reset_reason = CommandBuilder(
terminator=TEMP_DECK_COMMAND_TERMINATOR
).add_gcode(gcode=GCODE.GET_RESET_REASON)
await self._send_command(command=reset_reason)

return utils.parse_device_information(device_info_string=response)

async def enter_programming_mode(self) -> None:
Expand Down
21 changes: 19 additions & 2 deletions api/src/opentrons/drivers/thermocycler/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class GCODE(str, Enum):
DEACTIVATE_LID = "M108"
DEACTIVATE_BLOCK = "M14"
DEVICE_INFO = "M115"
GET_RESET_REASON = "M114"
ENTER_PROGRAMMING = "dfu"


Expand Down Expand Up @@ -292,12 +293,20 @@ async def deactivate_block(self) -> None:

async def get_device_info(self) -> Dict[str, str]:
"""Send get device info command"""
c = CommandBuilder(terminator=TC_COMMAND_TERMINATOR).add_gcode(
device_info = CommandBuilder(terminator=TC_COMMAND_TERMINATOR).add_gcode(
gcode=GCODE.DEVICE_INFO
)
response = await self._connection.send_command(
command=c, retries=DEFAULT_COMMAND_RETRIES
command=device_info, retries=DEFAULT_COMMAND_RETRIES
)

reset_reason = CommandBuilder(terminator=TC_COMMAND_TERMINATOR).add_gcode(
gcode=GCODE.GET_RESET_REASON
)
await self._connection.send_command(
command=reset_reason, retries=DEFAULT_COMMAND_RETRIES
)

return utils.parse_device_information(device_info_string=response)

async def enter_programming_mode(self) -> None:
Expand Down Expand Up @@ -353,6 +362,14 @@ async def get_device_info(self) -> Dict[str, str]:
response = await self._connection.send_command(
command=c, retries=DEFAULT_COMMAND_RETRIES
)

reset_reason = CommandBuilder(terminator=TC_COMMAND_TERMINATOR).add_gcode(
gcode=GCODE.GET_RESET_REASON
)
await self._connection.send_command(
command=reset_reason, retries=DEFAULT_COMMAND_RETRIES
)

return utils.parse_hs_device_information(device_info_string=response)

async def enter_programming_mode(self) -> None:
Expand Down
4 changes: 4 additions & 0 deletions api/src/opentrons/hardware_control/emulation/heater_shaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def __init__(self, parser: Parser, settings: HeaterShakerSettings) -> None:
GCODE.HOME.value: self._home,
GCODE.ENTER_BOOTLOADER.value: self._enter_bootloader,
GCODE.GET_VERSION.value: self._get_version,
GCODE.GET_RESET_REASON.value: self._get_reset_reason,
GCODE.OPEN_LABWARE_LATCH.value: self._open_labware_latch,
GCODE.CLOSE_LABWARE_LATCH.value: self._close_labware_latch,
GCODE.GET_LABWARE_LATCH_STATE.value: self._get_labware_latch_state,
Expand Down Expand Up @@ -126,6 +127,9 @@ def _get_version(self, command: Command) -> str:
f"SerialNo:{self._settings.serial_number}"
)

def _get_reset_reason(self, command: Command) -> str:
return "M114 Last Reset Reason: 01"

def _open_labware_latch(self, command: Command) -> str:
self._latch_status = HeaterShakerLabwareLatchStatus.IDLE_OPEN
return "M242"
Expand Down
8 changes: 6 additions & 2 deletions api/tests/opentrons/drivers/heater_shaker/test_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,14 @@ async def test_get_device_info(
)
response = await subject.get_device_info()
assert response == {"serial": "TC2101010A2", "model": "A", "version": "21.2.1"}
expected = CommandBuilder(terminator=driver.HS_COMMAND_TERMINATOR).add_gcode(
device_info = CommandBuilder(terminator=driver.HS_COMMAND_TERMINATOR).add_gcode(
gcode="M115"
)
connection.send_command.assert_called_once_with(command=expected, retries=0)
reset_reason = CommandBuilder(terminator=driver.HS_COMMAND_TERMINATOR).add_gcode(
gcode="M114"
)
connection.send_command.assert_any_call(command=device_info, retries=0)
connection.send_command.assert_called_with(command=reset_reason, retries=0)


async def test_enter_bootloader(
Expand Down
10 changes: 8 additions & 2 deletions api/tests/opentrons/drivers/temp_deck/test_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,15 @@ async def test_get_device_info(driver: TempDeckDriver, connection: AsyncMock) ->

response = await driver.get_device_info()

expected = CommandBuilder(terminator=TEMP_DECK_COMMAND_TERMINATOR).add_gcode("M115")
device_info = CommandBuilder(terminator=TEMP_DECK_COMMAND_TERMINATOR).add_gcode(
"M115"
)
reset_reason = CommandBuilder(terminator=TEMP_DECK_COMMAND_TERMINATOR).add_gcode(
"M114"
)

connection.send_command.assert_called_once_with(command=expected, retries=3)
connection.send_command.assert_any_call(command=device_info, retries=3)
connection.send_command.assert_called_with(command=reset_reason, retries=3)

assert response == {"serial": "s", "model": "m", "version": "v"}

Expand Down
9 changes: 6 additions & 3 deletions api/tests/opentrons/drivers/thermocycler/test_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,13 @@ async def test_device_info(

device_info = await subject.get_device_info()

expected = CommandBuilder(terminator=driver.TC_COMMAND_TERMINATOR).add_gcode(
get_device_info = CommandBuilder(terminator=driver.TC_COMMAND_TERMINATOR).add_gcode(
gcode="M115"
)
reset_reason = CommandBuilder(terminator=driver.TC_COMMAND_TERMINATOR).add_gcode(
gcode="M114"
)

connection.send_command.assert_called_once_with(command=expected, retries=3)

connection.send_command.assert_any_call(command=get_device_info, retries=3)
connection.send_command.assert_called_with(command=reset_reason, retries=3)
assert device_info == {"serial": "s", "model": "m", "version": "v"}
8 changes: 6 additions & 2 deletions api/tests/opentrons/drivers/thermocycler/test_gen2_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,15 @@ async def test_device_info(

device_info = await subject.get_device_info()

expected = CommandBuilder(terminator=driver.TC_COMMAND_TERMINATOR).add_gcode(
get_device_info = CommandBuilder(terminator=driver.TC_COMMAND_TERMINATOR).add_gcode(
gcode="M115"
)
reset_reason = CommandBuilder(terminator=driver.TC_COMMAND_TERMINATOR).add_gcode(
gcode="M114"
)

connection.send_command.assert_called_once_with(command=expected, retries=3)
connection.send_command.assert_any_call(command=get_device_info, retries=3)
connection.send_command.assert_called_with(command=reset_reason, retries=3)

assert device_info == {
"serial": "EMPTYSN",
Expand Down

0 comments on commit 0644df1

Please sign in to comment.