[英]Web Serial API - Uncaught (in promise) DOMException: Failed to open serial port / required member baudRate is undefined
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.下面的代码在我的 Xubuntu 机器上工作,但现在我在 Kubuntu 上,它不再工作 - 它不会打开端口。
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. Arduino IDE 工作正常(可以将代码写入电路板),我可以在 Chrome 中选择设备(Arduino Uno),但是当我尝试打开端口时代码将停止: Uncaught (in promise) DOMException: Failed to open serial port
或required member baudRate is undefined
会出现。
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)
}
}
}
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.我已经尝试按照此更改串行端口的权限,所以现在如果我运行groups user
我会得到user : user adm dialout cdrom sudo dip plugdev lpadmin lxd sambashare
,但它仍然无法工作。
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.我还检查了chrome://device-log
以查看是否可以找到任何错误,但我得到的只是有关(物理上)添加或删除 USB 设备的信息。
I believe the member name has recently been changed from 'baudrate' to 'baudRate'.我相信成员名称最近已从“baudrate”更改为“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'.可能是 Kubuntu 使用的是期望“波特率”的旧版 chrome 版本。
I am also having the same issue.我也有同样的问题。 I have an online IDE for CircuitPython:我有一个用于 CircuitPython 的在线 IDE:
https://github.com/Mr-Coxall/CircuitPython-IDE https://github.com/Mr-Coxall/CircuitPython-IDE
It was working fine and has recently stopped with the same error you are getting.它工作正常,最近因您遇到的相同错误而停止。 Not sure what has changed recently.不知道最近有什么变化。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.