3
document.getElementById('usb').addEventListener('click',async function(){
    var device;

    navigator.usb.requestDevice({ filters: [{name:'usb', vendorId: 0x76C }] })
        .then(selectedDevice => {
            device = selectedDevice;
            return device.open(); 
  })
        .then(() => device.selectConfiguration(1)) 
        .then(() => device.claimInterface(2)) 
        .then(() => device.controlTransferOut({
            requestType: 'class',
            recipient: 'interface',
            request: 0x22,
            value: 0x01,
            index: 0x02})) // Ready to receive data
        .then(() => device.transferIn(5, 64)) 
        .then(result => {
            let decoder = new TextDecoder();
            console.log('Received: ' + decoder.decode(result.data));
        })
        .catch(error => { console.log(error); });
})

usbweb显示此错误,尝试了一些解决方案但找不到,任何人都可以帮助解决这个问题。此错误 DOMException:访问被拒绝。

4

0 回答 0