[英]Web Serial API - Uncaught (in promise) DOMException: Failed to open serial port / required member baudRate is undefined
[英]Web serial api , Port open without user gesture
在 web 串行 api 中,我可以通过单击按钮打开端口。 端口连接后有什么方法可以打开端口吗? onconnect 事件未打开端口,要求用户手势...我需要自动打开以进行量产...
如https://web.dev/serial/#open-port中所示, requestPort()
需要用户手势,例如触摸或鼠标单击。 但是,一旦有了端口,您就可以在后续页面加载时open()
一个,而无需任何用户手势。
// Get all serial ports the user has previously granted the website access to.
const ports = await navigator.serial.getPorts();
// Assuming the first one is the one you want to open...
const port = ports[0];
// Open serial port without user gesture.
await port.open({ baudRate: 9600 });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.