mehrdadh commented on code in PR #13518:
URL: https://github.com/apache/tvm/pull/13518#discussion_r1037691317


##########
apps/microtvm/arduino/template_project/microtvm_api_server.py:
##########
@@ -524,26 +534,42 @@ def _parse_connected_boards(self, tabular_str):
                 device[col_name] = str_row[column.start() : 
column.end()].strip()
             yield device
 
-    def _auto_detect_port(self, arduino_cli_cmd: str, board: str) -> str:
-        list_cmd = [self._get_arduino_cli_cmd(arduino_cli_cmd), "board", 
"list"]
-        list_cmd_output = subprocess.run(
-            list_cmd, check=True, stdout=subprocess.PIPE
-        ).stdout.decode("utf-8")
+    def _auto_detect_port(self, arduino_cli_cmd: str, board: str, 
serial_number: str) -> str:
+        # TODO: This is to avoid breaking GPU docker on running the tutorials.
+        import serial.tools.list_ports
 
-        desired_fqbn = self._get_fqbn(board)
-        for device in self._parse_connected_boards(list_cmd_output):
-            if device["fqbn"] == desired_fqbn:
-                return device["port"]
+        if not serial_number:
+            # If serial_number is not set, it is assumed only one board
+            # with this type is connected to this host machine.
+            list_cmd = [self._get_arduino_cli_cmd(arduino_cli_cmd), "board", 
"list"]
+            list_cmd_output = subprocess.run(
+                list_cmd, check=True, stdout=subprocess.PIPE
+            ).stdout.decode("utf-8")
+
+            desired_fqbn = self._get_fqbn(board)
+            for device in self._parse_connected_boards(list_cmd_output):
+                if device["fqbn"] == desired_fqbn:
+                    device_port = device["port"]
+                    break
+        else:
+            com_ports = serial.tools.list_ports.comports()
+            for port in com_ports:
+                if port.serial_number == serial_number:
+                    device_port = port.device
 
+        if device_port:
+            return device_port
         # If no compatible boards, raise an error
         raise BoardAutodetectFailed()

Review Comment:
   this was an issue. I changed `_get_arduino_port` function to address this 
issue. Now in this function we have this priority:
   1. port
   2. detect port using serial_number
   3. auto detect port with arduino-cli
   In 2 and 3 we show proper exception if it was not able to find the port



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@tvm.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to