admin管理员组文章数量:1384350
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
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 1DOMException Access denied cannot open usb after paired
- 1 Possible duplicate of Webusb: Access Denied trying to open printer on Windows – Andreas Commented Dec 5, 2017 at 9:54
1 Answer
Reset to default 5Based 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".
本文标签: javascriptFailed to open devbususb001007 Permission denied for usb deviceStack Overflow
版权声明:本文标题:javascript - Failed to open devbususb001007: Permission denied for usb device - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744531102a2611041.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论