最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Failed to open devbususb001007: Permission denied for usb device - Stack Overflow

programmeradmin2浏览0评论

I am trying to connect usb device from webpage using webusb api ,but i cannot open the paired device using the below code.

<!DOCTYPE html>
<html>
<head allow="usb"></head>
    <body>
   <input type="submit" onclick="connect()" value="connect"/>

    <script>
    var device;
    function setup(device) {
        alert(device.productName+" open");
        return device.open()

        .then(() => device.selectConfiguration(1))
        .then(() => device.claimInterface(0))
    }

    function connect() {
        if (device == null) {
            navigator.usb.requestDevice({ filters: [{ vendorId : 2352 }] })
            .then(selectedDevice => {
                device = selectedDevice;
                console.log(device);
                return setup(device);
            })

            .catch(error => { console.log(error); })
        }


    }
    navigator.usb.getDevices()
    .then(devices => {
        if (devices.length > 0) {
            device = devices[0];
            return setup(device);
        }
    })
    .catch(error => { console.log(error); });
    </script>
    </body>
</html>

Its shows

DOMException Access denied cannot open usb after paired

I am trying to connect usb device from webpage using webusb api ,but i cannot open the paired device using the below code.

<!DOCTYPE html>
<html>
<head allow="usb"></head>
    <body>
   <input type="submit" onclick="connect()" value="connect"/>

    <script>
    var device;
    function setup(device) {
        alert(device.productName+" open");
        return device.open()

        .then(() => device.selectConfiguration(1))
        .then(() => device.claimInterface(0))
    }

    function connect() {
        if (device == null) {
            navigator.usb.requestDevice({ filters: [{ vendorId : 2352 }] })
            .then(selectedDevice => {
                device = selectedDevice;
                console.log(device);
                return setup(device);
            })

            .catch(error => { console.log(error); })
        }


    }
    navigator.usb.getDevices()
    .then(devices => {
        if (devices.length > 0) {
            device = devices[0];
            return setup(device);
        }
    })
    .catch(error => { console.log(error); });
    </script>
    </body>
</html>

Its shows

DOMException Access denied cannot open usb after paired

Share Improve this question edited Dec 6, 2017 at 8:08 Shijo Joseph asked Dec 5, 2017 at 9:43 Shijo JosephShijo Joseph 1152 silver badges8 bronze badges 1
  • 1 Possible duplicate of Webusb: Access Denied trying to open printer on Windows – Andreas Commented Dec 5, 2017 at 9:54
Add a ment  | 

1 Answer 1

Reset to default 5

Based on the title of this question it appears that you are running on Linux and that the permissions for the device node /dev/bus/usb/001/007 are not set up so that the user running Chrome can open it.

What you need to do is add a udev rule that will set the permissions for this device node so that it can be opened. First you need to figure out the vendor and product IDs for your device. If you run lsusb it will list the devices on your system in a format like this,

Bus BBB Device NNN: ID VVVV:PPPP Manufacturer Product

Where,

BBB: The bus number (usually one per controller, two for USB 3.0 controllers).
NNN: The device number on that bus.
VVVV: The vendor ID (in hexadecimal).
PPPP: The product ID (in hexadecimal).

Once you know this information you can create a file in /etc/udev/rules.d/ containing the line below after plugging in the IDs you discovered in the step above.

SUBSYSTEM=="usb", ATTRS{idVendor}=="VVVV", ATTR{idProduct}=="PPPP", MODE="0660", GROUP="plugdev"

This will make any device with the given vendor and product IDs accessible to users in the plugdev group. This is a vaguely appropriate group for removable device permissions according to the Debian documentation.

From your code already appear to know the vendor ID, 2352, which would be entered into the rule in hexadecimal as "0930".

发布评论

评论列表(0)

  1. 暂无评论