无法在 ubuntu 20.04 上的 chromium 118.0.5993.88 中使用 Web 串行 API 列出串行端口

问题描述 投票:0回答:1

我想与 esp32(通过 USB 连接到我的电脑)和 chromium 上的测试网站(版本 118.0.5993.88,Ubuntu 20.04)建立串行连接,但 chromium 上的串行连接列表为空(在 google chrome 上该列表显示每个串口)

这是我使用的测试 html 脚本:

<!DOCTYPE html>
<html>
<head>
  <title>Serial Ports List</title>
</head>
<body>

<h1>Serial Ports Test</h1>

<!-- Button to list available serial ports -->
<button id="listPortsButton">List Serial Ports</button>

<script>
  // Function to list available serial ports
  async function listSerialPorts() {
    try {
      // Request access to serial ports
      const availablePorts = await navigator.serial.getPorts();

      // Log each port
      availablePorts.forEach(port => {
        console.log('Port:', port);
      });
    } catch (error) {
      console.error('There was an error listing serial ports:', error);
    }
  }

  // Add click event listener to button
  document.querySelector("#listPortsButton").addEventListener("click", 
async () => {
    try {
      // Request a port from the user
      const port = await navigator.serial.requestPort();
      console.log('User-selected port:', port);

      // Now list all available ports (including the selected one)
      listSerialPorts();
    } catch (err) {
      console.error('There was an error selecting a port:', err);
    }
  });
</script>

</body>
</html>

script execution with google chrome: script execution with chromium: script html in debug console with chromium:

系统信息: 1. 2.

我已经用 google chrome 尝试过该脚本(如上所示),它可以工作,我还重新安装了 chromium 以检查我的 chromium 安装是否存在问题。 我想让脚本像在 google chrome 中一样工作并且需要帮助。

我还检查了arduino中的串行连接,串行端口显示在列表中,我可以连接到它并打开串行监视器,没有问题。用户也属于有权访问串行端口的正确组。

google-chrome ubuntu arduino serial-port chromium
1个回答
0
投票

我记得几年前有过这样的情况,我刚刚看了一些旧笔记,这与启用 Chromium 的 USB 连接有关?

sudo snap connect chromium:raw-usb

我不知道这是否有任何帮助,或者这是否是我当时的系统特有的?

最近我倾向于坚持使用 Node.js 与我的 ESP 进行串行通信,但这是一个更复杂的过程,如果你可以通过浏览器完成它,这是一个很好的快捷方式。

祝你好运

© www.soinside.com 2019 - 2024. All rights reserved.