HIDDevice: phương thức open()
Khả dụng hạn chế
This feature is not Baseline because it does not work in some of the most widely-used browsers.
Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.
Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.
Note: This feature is available in Web Workers, except for Shared Web Workers.
Phương thức open() của giao diện HIDDevice yêu cầu hệ điều hành mở thiết bị HID.
Note:
Các thiết bị HID không được mở tự động. Do đó, một HIDDevice được trả về bởi HID.requestDevice() phải được mở bằng phương thức này trước khi có thể truyền dữ liệu.
Cú pháp
open()
Tham số
Không có.
Giá trị trả về
Một Promise được giải quyết với giá trị undefined khi kết nối đã được mở.
Ngoại lệ
InvalidStateErrorDOMException-
Được ném nếu kết nối đã mở.
NotAllowedErrorDOMException-
Được ném nếu việc mở kết nối thất bại vì bất kỳ lý do nào.
Ví dụ
Trong ví dụ sau, chúng ta chờ kết nối HID mở trước khi gửi hay nhận dữ liệu.
await device.open();
Thông số kỹ thuật
| Thông số kỹ thuật |
|---|
| WebHID API> # dom-hiddevice-open> |