-
Notifications
You must be signed in to change notification settings - Fork 22.4k
/
index.md
60 lines (48 loc) · 1.33 KB
/
index.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
---
title: USBDevice.opened
slug: Web/API/USBDevice/opened
page-type: web-api-instance-property
tags:
- API
- Property
- Reference
- USB
- USBDevice
- WebUSB
- WebUSB API
- opened
- Experimental
browser-compat: api.USBDevice.opened
---
{{SeeCompatTable}}{{APIRef("WebUSB API")}}
The **`opened`** read only property of the
{{domxref("USBDevice")}} interface indicates whether a session has been started with a
paired USB device. A device must be opened before it can be controlled by a web page.
## Value
A {{jsxref("boolean")}}.
## Examples
This example is for a hypothetical USB device with a multi-colored LED. It shows how to
test that a device is open before calling {{domxref("USBDevice.controlTransferOut")}} to
set a specified LED color.
> **Note:** What data can be passed to a USB device and how it is passed is particular and unique
> to each device.
```js
async setDeviceColor(usbDevice, r, g, b) {
if (device.opened) {
// This hypothetical USB device requires that the data passed to
// it be in a Uint8Array.
let payload = new Uint8Array([r, g, b]);
await usbDevice.controlTransferOut({
requestType: 'vendor',
recipient: 'device',
request: 1,
value: 0,
index: 0,
}, payload);
}
}
```
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}