USBDevice: claimInterface() 方法
注意:此功能在 Web Workers 中可用。
USBDevice 介面的 claimInterface() 方法會返回一個 Promise,當請求的介面被成功宣告為獨佔訪問時,該 Promise 會解析。
語法
js
claimInterface(interfaceNumber)
引數
interfaceNumber-
裝置支援的介面之一的索引。介面是裝置特定的。
返回值
一個 Promise。
示例
以下示例展示了在連線到 USB 裝置的上下文中使用的 claimInterface()。
js
async function connectDevice(usbDevice) {
await usbDevice.open();
if (usbDevice.configuration === null) await usbDevice.selectConfiguration(1);
await usbDevice.claimInterface(0);
}
規範
| 規範 |
|---|
| WebUSB API # dom-usbdevice-claiminterface |
瀏覽器相容性
載入中…