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


##########
tests/micro/arduino/README.md:
##########
@@ -33,3 +33,9 @@ To see the list of supported values for `--board`, run:
 ```
 $ pytest --help
 ```
+
+If you like to test with a real hardware, you have the option to pass the 
serial number

Review Comment:
   ```suggestion
   If you would like to test with a real hardware and need to target one of 
many identical devices, you have the option to pass the serial number
   ```



##########
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:
   hm but isn't device_port only set if we find a valid 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