问题描述
下面的代码在我的 Xubuntu 机器上工作,但现在我在 Kubuntu 上,它不再工作 - 它不会打开端口.
The code below works on my Xubuntu machine, but now I'm on Kubuntu and it isn't working anymore - it won't open the port.
Arduino IDE 工作正常(可以将代码写入开发板),我可以在 Chrome 中选择设备(Arduino Uno),但是当我尝试打开端口时代码会停止:Uncaught (in promise) DOMException: Failed to open serial port
或 required member baudRate is undefined
会出现.
The Arduino IDE works fine (can write code to the board) and I'm able to select the device (Arduino Uno) in Chrome, but the code will stop when I try to open the port: Uncaught (in promise) DOMException: Failed to open serial port
or required member baudRate is undefined
will come up.
const filters = [
// Filter on devices with the Arduino Uno USB Vendor/Product IDs.
{ usbVendorId: 0x2341, usbProductId: 0x0043 },
{ usbVendorId: 0x2341, usbProductId: 0x0001 },
];
async function getPortAndStartReading() {
if (!portFound) {
const port = await navigator.serial.requestPort({ filters });
await port.open({ baudRate: 9600 }) //problem here
reader = port.readable.getReader();
outputStream = port.writable
readLoop();
if (port) {
connectionToPortSuccessfulMessage = 'Connection successful'
setPortFound(true)
}
}
}
我已经尝试按照 this 更改串行端口的权限,所以现在如果我运行 groups user
我得到 user : user adm dialout cdrom sudo dip plugdev lpadmin lxd sambashare
,但它仍然无法工作.
I've tried changing the permissions on the serial port by following this, so now if I run groups user
I get user : user adm dialout cdrom sudo dip plugdev lpadmin lxd sambashare
, but it still won't work.
我还检查了 chrome://device-log
以查看是否可以找到任何错误,但我得到的只是有关(物理上)添加或移除 USB 设备的信息.
I've also checked chrome://device-log
to see if I could find any errors but all I get is info about (physically) adding or removing a USB device.
推荐答案
我相信成员名称最近已从 'baudrate' 更改为 'baudRate'.至少在我的情况下,从 'baudrate'(曾经可以工作)更改为 'baudRate' 为我修复了它.可能是 Kubuntu 使用的是期望波特率"的旧版 chrome.
I believe the member name has recently been changed from 'baudrate' to 'baudRate'. At least in my case changing from 'baudrate' (which used to work) to 'baudRate' fixed it for me. Could it perhaps be Kubuntu is using an older chrome version that expects 'baudrate'.
这篇关于Web Serial API - Uncaught (in promise) DOMException: Failed to open serial port/required member baudRate is undefined的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!