You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by GitBox <gi...@apache.org> on 2022/12/01 17:30:17 UTC

[GitHub] [tvm] mehrdadh commented on a diff in pull request #13518: [microTVM][Arduino]Add `serial_number` to project options and tests

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


##########
apps/microtvm/arduino/template_project/microtvm_api_server.py:
##########
@@ -93,6 +93,13 @@ class BoardAutodetectFailed(Exception):
         default=None,
         help="Port to use for connecting to hardware.",
     ),
+    server.ProjectOption(
+        "serial_number",
+        optional=["open_transport", "flash"],
+        type="str",
+        default=None,
+        help=("Board serial number."),
+    ),

Review Comment:
   good point, I added more info to both help messages. It should be clear now



##########
apps/microtvm/arduino/template_project/microtvm_api_server.py:
##########
@@ -524,26 +531,39 @@ 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")
-
-        desired_fqbn = self._get_fqbn(board)
-        for device in self._parse_connected_boards(list_cmd_output):
-            if device["fqbn"] == desired_fqbn:
-                return device["port"]
+    def _auto_detect_port(self, arduino_cli_cmd: str, board: str, serial_number) -> str:
+        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()
 
-    def _get_arduino_port(self, arduino_cli_cmd: str, board: str, port: int):
+    def _get_arduino_port(self, arduino_cli_cmd: str, board: str, port: int, serial_number: str):

Review Comment:
   done



##########
apps/microtvm/arduino/template_project/microtvm_api_server.py:
##########
@@ -524,26 +531,39 @@ 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")
-
-        desired_fqbn = self._get_fqbn(board)
-        for device in self._parse_connected_boards(list_cmd_output):
-            if device["fqbn"] == desired_fqbn:
-                return device["port"]
+    def _auto_detect_port(self, arduino_cli_cmd: str, board: str, serial_number) -> str:

Review Comment:
   done



-- 
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-unsubscribe@tvm.apache.org

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