![enter image description here](https://i.stack.imgur.com/BBUWQ.png)
上面是我的设备配置。我正在尝试从中获取数据,我正在使用下面的代码来获取数据
document.getElementById("request").onclick = function() {
navigator.usb.requestDevice({
filters: [{
vendorId: 1659
}]
})
.then((requestedDevice) => {
device = requestedDevice;
}).then(() => {
console.log(device);
console.log(JSON.stringify(device));
return device.open();
}).then(() => device.selectConfiguration(1)) // Select configuration #1 for the device.
.then(() => {
return device.reset();
}).then(() => device.claimInterface(0))
.then(() => {
return device.transferIn(3, 64)
})
.then((data) => {
debugger;
console.log(data)
}).catch(err => {
console.log(err);
});
}
我正在正确选择端点编号和界面,但它似乎不起作用,我在这里遗漏了什么吗? .请帮忙。我没有收到任何错误,设备似乎已连接,但数据未从计算机传输到浏览器。
我看到这个问题,它的场景与我的完全相同WEBUSB获取串口数据PL2303
但就我而言,我什至没有得到任何数据。
我试过这个驱动程序https://github.com/tidepool-org/pl2303在 Node js 中并且它有效,但我想通过 Web USB API 来实现。
编辑-我研究了它,现在数据似乎不断出现
async function Get()
{
let device= await navigator.usb.requestDevice({ filters: [{ vendorId: 0x067b,productId:0x2303 }]})
console.log(device);
await device.open({ baudRate: 9600 });
await device.selectConfiguration(1);
await device.claimInterface(0);
while(true)
{
let result = await device.transferIn(3,64);
var string = new TextDecoder("utf-8").decode(result.data.buffer);
console.log("hii",string);
}
唯一的问题,我现在面临的写入是数据传输直到一些数据发送到设备后才开始,当我使用节点js驱动程序发送数据时,它可以工作并且我接收数据,但仅限于web usb api 不起作用
None
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)