diff --git a/en/application-dev/device/usb-guidelines.md b/en/application-dev/device/usb-guidelines.md index 46304e882adcc8f8fbd69daf30cbe58a565696cd..8476e88dc8ea1bf774b70991545dbd1d5f3620fe 100644 --- a/en/application-dev/device/usb-guidelines.md +++ b/en/application-dev/device/usb-guidelines.md @@ -1,93 +1,34 @@ -# USB Service Development +# USB Service Development -## When to Use +## When to Use In Host mode, you can obtain the list of connected devices, enable or disable the devices, manage device access permissions, and perform data transfer or control transfer. -## APIs +## APIs The USB service provides the following functions: query of USB device list, bulk data transfer, control transfer, and access permission management. -The following table lists the USB APIs currently available. For details, see the _API Reference_. +The following table lists the USB APIs currently available. For details, see the [API Reference](../reference/apis/js-apis-usb.md). **Table 1** Open USB APIs - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

API

-

Description

-

hasRight(deviceName: string): boolean

-

Checks whether the user, for example, the application or system, has the device access permissions. The value true is returned if the user has the device access permissions; the value false is returned otherwise.

-

requestRight(deviceName: string): Promise<boolean>

-

Requests the temporary permission for a given application to access the USB device.

-

connectDevice(device: USBDevice): Readonly<USBDevicePipe>

-

Connects to the USB device based on the device information returned by getDevices().

-

getDevices(): Array<Readonly<USBDevice>>

-

Obtains the USB device list.

-

setConfiguration(pipe: USBDevicePipe, config: USBConfig): number

-

Sets the USB device configuration.

-

setInterface(pipe: USBDevicePipe, iface: USBInterface): number

-

Sets a USB interface.

-

claimInterface(pipe: USBDevicePipe, iface: USBInterface, force?: boolean): number

-

Claims a USB interface

-

function bulkTransfer(pipe: USBDevicePipe, endpoint: USBEndpoint, buffer: Uint8Array, timeout?: number): Promise<number>

-

Performs bulk transfer.

-

closePipe(pipe: USBDevicePipe): number

-

Closes a USB device pipe.

-

releaseInterface(pipe: USBDevicePipe, iface: USBInterface): number

-

Releases a USB interface.

-

getFileDescriptor(pipe: USBDevicePipe): number

-

Obtains the file descriptor.

-

getRawDescriptor(pipe: USBDevicePipe): Uint8Array

-

Obtains the raw USB descriptor.

-

controlTransfer(pipe: USBDevicePipe, contrlparam: USBControlParams, timeout?: number): Promise<number>

-

Performs control transfer.

-
- -## How to Develop +| API | Description | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| hasRight(deviceName: string): boolean | Checks whether the user, for example, the application or system, has the device access permissions. The value **true** is returned if the user has the device access permissions; the value **false** is returned otherwise. | +| requestRight(deviceName: string): Promise\ | Requests the temporary permission for a given application to access the USB device. | +| connectDevice(device: USBDevice): Readonly\ | Connects to the USB device based on the device information returned by **getDevices()**. | +| getDevices(): Array> | Obtains the USB device list. | +| setConfiguration(pipe: USBDevicePipe, config: USBConfig): number | Sets the USB device configuration. | +| setInterface(pipe: USBDevicePipe, iface: USBInterface): number | Sets a USB interface. | +| claimInterface(pipe: USBDevicePipe, iface: USBInterface, force?: boolean): number | Claims a USB interface | +| function bulkTransfer(pipe: USBDevicePipe, endpoint: USBEndpoint, buffer: Uint8Array, timeout?: number): Promise\ | Performs bulk transfer. | +| closePipe(pipe: USBDevicePipe): number | Closes a USB device pipe. | +| releaseInterface(pipe: USBDevicePipe, iface: USBInterface): number | Releases a USB interface. | +| getFileDescriptor(pipe: USBDevicePipe): number | Obtains the file descriptor. | +| getRawDescriptor(pipe: USBDevicePipe): Uint8Array | Obtains the raw USB descriptor. | +| controlTransfer(pipe: USBDevicePipe, contrlparam: USBControlParams, timeout?: number): Promise\ | Performs control transfer. | + +## How to Develop You can set a USB device as a host to connect to a device for data transfer. The development procedure is as follows: @@ -211,6 +152,4 @@ You can set a USB device as a host to connect to a device for data transfer. The ```js usb.releaseInterface(pipe, interface); usb.closePipe(pipe); - ``` - - + ``` \ No newline at end of file