Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. Web APIs
  3. USBEndpoint

USBEndpoint

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Experimental:This is anexperimental technology
Check theBrowser compatibility table carefully before using this in production.

Secure context: This feature is available only insecure contexts (HTTPS), in some or allsupporting browsers.

Note: This feature is available inWeb Workers.

TheUSBEndpoint interface of theWebUSB API provides information about an endpoint provided by the USB device. An endpoint represents a unidirectional data stream into or out of a device.

Constructor

USBEndpoint()Experimental

Creates a newUSBEndpoint object which will be populated with information about the endpoint on the providedUSBAlternateInterface with the given endpoint number and transfer direction.

Instance properties

USBEndpoint.endpointNumberExperimental

Returns this endpoint's "endpoint number" which is a value from 1 to 15 extracted from thebEndpointAddress field of the endpoint descriptor defining this endpoint. This value is used to identify the endpoint when calling methods onUSBDevice.

USBEndpoint.directionExperimental

Returns the direction in which this endpoint transfers data, one of:

USBEndpoint.typeExperimental

Returns the type of this endpoint, one of:

USBEndpoint.packetSizeExperimental

Returns the size of the packets that data sent through this endpoint will be divided into.

Examples

While sometimes the developer knows ahead of time the exact layout of a device's endpoints there are cases where this must be discovered at runtime. For example, a USB serial device must provide bulk input and output endpoints but their endpoint numbers will depend on what other interfaces the device provides.

This code identifies the correct endpoints by searching for the interface implementing the USB CDC interface class and then identifying the candidate endpoints based on their type and direction.

js
let inEndpoint = undefined;let outEndpoint = undefined;for (const { alternates } of device.configuration.interfaces) {  // Only support devices with out multiple alternate interfaces.  const alternate = alternates[0];  // Identify the interface implementing the USB CDC class.  const USB_CDC_CLASS = 10;  if (alternate.interfaceClass !== USB_CDC_CLASS) {    continue;  }  for (const endpoint of alternate.endpoints) {    // Identify the bulk transfer endpoints.    if (endpoint.type !== "bulk") {      continue;    }    if (endpoint.direction === "in") {      inEndpoint = endpoint.endpointNumber;    } else if (endpoint.direction === "out") {      outEndpoint = endpoint.endpointNumber;    }  }}

Specifications

Specification
WebUSB API
# usbendpoint-interface

Browser compatibility

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2026 Movatter.jp