diff --git a/en/application-dev/reference/apis/js-apis-usb.md b/en/application-dev/reference/apis/js-apis-usb.md index 82932c99be0a0c8c39ab989d656cb6b0fcde99f5..8979bdeefaaebbd77e0e17bd094313025155527b 100644 --- a/en/application-dev/reference/apis/js-apis-usb.md +++ b/en/application-dev/reference/apis/js-apis-usb.md @@ -1,8 +1,8 @@ # USB -This module provides USB device management functions, including USB device list query, bulk data transfer, control transfer, and permission control. +The USB module provides USB device management functions, including USB device list query, bulk data transfer, control transfer, and permission control. -> **NOTE** +> **NOTE** > > The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. @@ -20,68 +20,68 @@ Obtains the USB device list. **System capability**: SystemCapability.USB.USBManager -- **Return value** - | Type| Description| - | -------- | -------- | - | Array<Readonly<[USBDevice](#usbdevice)>> | Device information list. | - -- **Example** - - ```js - let devicesList = usb.getDevices(); - console.log(`devicesList = ${JSON.stringify(devicesList)}`); - // devicesList is a list of USB devices. - // A simple example of devicesList is provided as follows: - [ - { - name: "1-1", - serial: "", - manufacturerName: "", - productName: "", - version: "", - vendorId: 7531, - productId: 2, - clazz: 9, - subclass: 0, - protocol: 1, - devAddress: 1, - busNum: 1, - configs: [ - { - id: 1, - attributes: 224, - isRemoteWakeup: true, - isSelfPowered: true, - maxPower: 0, - name: "1-1", - interfaces: [ - { - id: 0, - protocol: 0, - clazz: 9, - subclass: 0, - alternateSetting: 0, - name: "1-1", - endpoints: [ - { - address: 129, - attributes: 3, - interval: 12, - maxPacketSize: 4, - direction: 128, - number: 1, - type: 3, - interfaceId: 0, - }, - ], - }, - ], - }, - ], - }, - ] - ``` +**Return value** + +| Type | Description | +| ---------------------------------------------------- | ------- | +| Array<Readonly<[USBDevice](#usbdevice)>> | Device information list.| +**Example** + +```js +let devicesList = usb.getDevices(); +console.log(`devicesList = ${JSON.stringify(devicesList)}`); +// devicesList is a list of USB devices. +// A simple example of devicesList is provided as follows: +[ + { + name: "1-1", + serial: "", + manufacturerName: "", + productName: "", + version: "", + vendorId: 7531, + productId: 2, + clazz: 9, + subclass: 0, + protocol: 1, + devAddress: 1, + busNum: 1, + configs: [ + { + id: 1, + attributes: 224, + isRemoteWakeup: true, + isSelfPowered: true, + maxPower: 0, + name: "1-1", + interfaces: [ + { + id: 0, + protocol: 0, + clazz: 9, + subclass: 0, + alternateSetting: 0, + name: "1-1", + endpoints: [ + { + address: 129, + attributes: 3, + interval: 12, + maxPacketSize: 4, + direction: 128, + number: 1, + type: 3, + interfaceId: 0, + }, + ], + }, + ], + }, + ], + }, +] +``` ## usb.connectDevice @@ -93,25 +93,22 @@ Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB devi **System capability**: SystemCapability.USB.USBManager -- **Parameters** - +**Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | - | device | [USBDevice](#usbdevice) | Yes| USB device information. | - -- **Return value** + | device | [USBDevice](#usbdevice) | Yes| USB device information.| +**Return value** | Type| Description| | -------- | -------- | - | Readonly<[USBDevicePipe](#usbdevicepipe)> | USB device pipe for data transfer. | - -- **Example** + | Readonly<[USBDevicePipe](#usbdevicepipe)> | USB device pipe for data transfer.| - ```js - let devicepipe= usb.connectDevice(device); - console.log(`devicepipe = ${JSON.stringify(devicepipe)}`); - ``` +**Example** +```js +let devicepipe= usb.connectDevice(device); +console.log(`devicepipe = ${JSON.stringify(devicepipe)}`); +``` ## usb.hasRight @@ -121,26 +118,23 @@ Checks whether the application has the permission to access the device. **System capability**: SystemCapability.USB.USBManager -- **Parameters** - +**Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | - | deviceName | string | Yes| Device name. | - -- **Return value** + | deviceName | string | Yes| Device name to set.| +**Return value** | Type| Description| | -------- | -------- | - | boolean | Returns **true** if the application has the permission to access the device; returns **false** otherwise. | - -- **Example** + | boolean | Returns **true** if the application has the permission to access the device; returns **false** otherwise.| - ```js - let devicesName="1-1"; - let bool = usb.hasRight(devicesName); - console.log(bool); - ``` +**Example** +```js +let devicesName="1-1"; +let bool = usb.hasRight(devicesName); +console.log(bool); +``` ## usb.requestRight @@ -150,26 +144,24 @@ Requests the temporary permission for the application to access the USB device. **System capability**: SystemCapability.USB.USBManager -- **Parameters** - +**Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | - | deviceName | string | Yes| Device name. | - -- **Return value** + | deviceName | string | Yes| Device name to set.| +**Return value** | Type| Description| | -------- | -------- | - | Promise<boolean> | Returns **true** if the temporary device access permissions are granted; returns **false** otherwise. | + | Promise<boolean> | Returns **true** if the temporary device access permissions are granted; returns **false** otherwise.| -- **Example** +**Example** - ```js - let devicesName="1-1"; - usb.requestRight(devicesName).then((ret) => { - console.log(`requestRight = ${JSON.stringify(ret)}`); - }); - ``` +```js +let devicesName="1-1"; +usb.requestRight(devicesName).then((ret) => { + console.log(`requestRight = ${JSON.stringify(ret)}`); +}); +``` ## usb.claimInterface @@ -181,27 +173,24 @@ Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB devi **System capability**: SystemCapability.USB.USBManager -- **Parameters** - +**Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | - | pipe | [USBDevicePipe](#usbdevicepipe) | Yes| Device pipe, which is used to determine the bus number and device address. | - | iface | [USBInterface](#usbinterface) | Yes| USB interface, which is used to determine the index of the interface to claim. | - | force | boolean | No| Whether to forcibly claim the USB interface. The default value is **false**, indicating not to forcibly claim the USB interface. | - -- **Return value** + | pipe | [USBDevicePipe](#usbdevicepipe) | Yes| Device pipe, which is used to determine the bus number and device address.| + | iface | [USBInterface](#usbinterface) | Yes| USB interface, which is used to determine the index of the interface to claim.| + | force | boolean | No| Whether to forcibly claim the USB interface. The default value is **false**, indicating not to forcibly claim the USB interface.| +**Return value** | Type| Description| | -------- | -------- | - | number | Returns **0** if the USB interface is successfully claimed; returns an error code otherwise. | - -- **Example** + | number | Returns **0** if the USB interface is successfully claimed; returns an error code otherwise.| - ```js - let ret = usb.claimInterface(devicepipe, interfaces); - console.log(`claimInterface = ${ret}`); - ``` +**Example** +```js +let ret = usb.claimInterface(devicepipe, interfaces); +console.log(`claimInterface = ${ret}`); +``` ## usb.releaseInterface @@ -213,26 +202,23 @@ Before you do this, ensure that you have claimed the interface by calling [usb.c **System capability**: SystemCapability.USB.USBManager -- **Parameters** - +**Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | - | pipe | [USBDevicePipe](#usbdevicepipe) | Yes| Device pipe, which is used to determine the bus number and device address. | - | iface | [USBInterface](#usbinterface) | Yes| USB interface, which is used to determine the index of the interface to release. | - -- **Return value** + | pipe | [USBDevicePipe](#usbdevicepipe) | Yes| Device pipe, which is used to determine the bus number and device address.| + | iface | [USBInterface](#usbinterface) | Yes| USB interface, which is used to determine the index of the interface to release.| +**Return value** | Type| Description| | -------- | -------- | - | number | Returns **0** if the USB interface is successfully released; returns an error code otherwise. | - -- **Example** + | number | Returns **0** if the USB interface is successfully released; returns an error code otherwise.| - ```js - let ret = usb.releaseInterface(devicepipe, interfaces); - console.log(`releaseInterface = ${ret}`); - ``` +**Example** +```js +let ret = usb.releaseInterface(devicepipe, interfaces); +console.log(`releaseInterface = ${ret}`); +``` ## usb.setConfiguration @@ -244,25 +230,23 @@ Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB devi **System capability**: SystemCapability.USB.USBManager -- **Parameters** - +**Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | - | pipe | [USBDevicePipe](#usbdevicepipe) | Yes| Device pipe, which is used to determine the bus number and device address. | - | config | [USBConfig](#usbconfig) | Yes| USB configuration to set. | - -- **Return value** + | pipe | [USBDevicePipe](#usbdevicepipe) | Yes| Device pipe, which is used to determine the bus number and device address.| + | config | [USBConfig](#usbconfig) | Yes| USB configuration to set.| +**Return value** | Type| Description| | -------- | -------- | - | number | Returns **0** if the USB configuration is successfully set; returns an error code otherwise. | + | number | Returns **0** if the USB configuration is successfully set; returns an error code otherwise.| -- **Example** +**Example** - ```js - let ret = usb.setConfiguration(devicepipe, config); - console.log(`setConfiguration = ${ret}`); - ``` +```js +let ret = usb.setConfiguration(devicepipe, config); +console.log(`setConfiguration = ${ret}`); +``` ## usb.setInterface @@ -270,30 +254,28 @@ setInterface(pipe: USBDevicePipe, iface: USBInterface): number Sets a USB interface. -Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB device list and interfaces, call [usb.requestRight](#usbrequestright) to request the device access permission, call [usb.connectDevice](#usbconnectdevice) to obtain **devicepipe** as an input parameter, and call [usb.claimInterface](#usbclaiminterface) to claim a USB interface.. +Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB device list and interfaces, call [usb.requestRight](#usbrequestright) to request the device access permission, call [usb.connectDevice](#usbconnectdevice) to obtain **devicepipe** as an input parameter, and call [usb.claimInterface](#usbclaiminterface) to claim the USB interface. **System capability**: SystemCapability.USB.USBManager -- **Parameters** +**Parameters** - | Name| Type| Mandatory| Description| - | -------- | -------- | -------- | -------- | - | pipe | [USBDevicePipe](#usbdevicepipe) | Yes| Device pipe, which is used to determine the bus number and device address. | - | iface | [USBInterface](#usbinterface) | Yes| USB interface to set. | - -- **Return value** +| Name | Type | Mandatory | Description | +| ----- | ------------------------------- | --- | ------------- | +| pipe | [USBDevicePipe](#usbdevicepipe) | Yes | Device pipe, which is used to determine the bus number and device address.| +| iface | [USBInterface](#usbinterface) | Yes | USB interface to set. | +**Return value** | Type| Description| | -------- | -------- | - | number | Returns **0** if the USB interface is successfully set; returns an error code otherwise. | + | number | Returns **0** if the USB interface is successfully set; returns an error code otherwise.| -- **Example** - - ```js - let ret = usb.setInterface(devicepipe, interfaces); - console.log(`setInterface = ${ret}`); - ``` +**Example** +```js +let ret = usb.setInterface(devicepipe, interfaces); +console.log(`setInterface = ${ret}`); +``` ## usb.getRawDescriptor @@ -305,24 +287,22 @@ Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB devi **System capability**: SystemCapability.USB.USBManager -- **Parameters** +**Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | - | pipe | [USBDevicePipe](#usbdevicepipe) | Yes| Device pipe, which is used to determine the bus number and device address. | + | pipe | [USBDevicePipe](#usbdevicepipe) | Yes| Device pipe, which is used to determine the bus number and device address.| -- **Return value** +**Return value** +| Type| Description| +| -------- | -------- | +| Uint8Array | Returns the raw USB descriptor if the operation is successful; returns **undefined** otherwise.| - | Type| Description| - | -------- | -------- | - | Uint8Array | Raw descriptor data. The value **undefined** indicates that the operation has failed. | - -- **Example** - - ```js - let ret = usb.getRawDescriptor(devicepipe); - ``` +**Example** +```js +let ret = usb.getRawDescriptor(devicepipe); +``` ## usb.getFileDescriptor @@ -334,24 +314,22 @@ Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB devi **System capability**: SystemCapability.USB.USBManager -- **Parameters** - +**Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | - | pipe | [USBDevicePipe](#usbdevicepipe) | Yes| Device pipe, which is used to determine the bus number and device address. | - -- **Return value** + | pipe | [USBDevicePipe](#usbdevicepipe) | Yes| Device pipe, which is used to determine the bus number and device address.| - | Type| Description| - | -------- | -------- | - | number | File descriptor of the USB device. The value **-1** indicates that the operation has failed. | +**Return value** -- **Example** +| Type | Description | +| ------ | -------------------- | +| number | Returns the file descriptor of the USB device if the operation is successful; returns **-1** otherwise.| - ```js - let ret = usb.getFileDescriptor(devicepipe); - ``` +**Example** +```js +let ret = usb.getFileDescriptor(devicepipe); +``` ## usb.controlTransfer @@ -363,28 +341,25 @@ Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB devi **System capability**: SystemCapability.USB.USBManager -- **Parameters** - +**Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | - | pipe | [USBDevicePipe](#usbdevicepipe) | Yes| USB device pipe, which is used to determine the USB device. | - | contrlparam | [USBControlParams](#usbcontrolparams) | Yes| Control transfer parameters. | - | timeout | number | No| Timeout duration. The default value is **0**, indicating no timeout. | - -- **Return value** + | pipe | [USBDevicePipe](#usbdevicepipe) | Yes| USB device pipe, which is used to determine the USB device.| + | contrlparam | [USBControlParams](#usbcontrolparams) | Yes| Control transfer parameters.| + | timeout | number | No| Timeout duration. The default value is **0**, indicating no timeout.| +**Return value** | Type| Description| | -------- | -------- | - | Promise<number> | Returns the size of the transmitted or received data block if the control transfer is successful; returns **-1** if an exception occurs. | + | Promise<number> | Returns the size of the transmitted or received data block if the control transfer is successful; returns **-1** if an exception occurs.| -- **Example** - - ```js - usb.controlTransfer(devicepipe, USBControlParams).then((ret) => { - console.log(`controlTransfer = ${JSON.stringify(ret)}`); - }) - ``` +**Example** +```js +usb.controlTransfer(devicepipe, USBControlParams).then((ret) => { + console.log(`controlTransfer = ${JSON.stringify(ret)}`); +}) +``` ## usb.bulkTransfer @@ -392,36 +367,33 @@ bulkTransfer(pipe: USBDevicePipe, endpoint: USBEndpoint, buffer: Uint8Array, tim Performs bulk transfer. -Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB device list and endpoints, call [usb.requestRight](#usbrequestright) to request the device access permission, call [usb.connectDevice](#usbconnectdevice) to obtain **devicepipe** as an input parameter, and call [usb.claimInterface](#usbclaiminterface) to claim a USB interface. +Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB device list and endpoints, call [usb.requestRight](#usbrequestright) to request the device access permission, call [usb.connectDevice](#usbconnectdevice) to obtain **devicepipe** as an input parameter, and call [usb.claimInterface](#usbclaiminterface) to claim the USB interface. **System capability**: SystemCapability.USB.USBManager -- **Parameters** - +**Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | - | pipe | [USBDevicePipe](#usbdevicepipe) | Yes| USB device pipe, which is used to determine the USB device. | - | endpoint | [USBEndpoint](#usbendpoint) | Yes| USB endpoint, which is used to determine the USB port for data transfer. | - | buffer | Uint8Array | Yes| Buffer for writing or reading data. | - | timeout | number | No| Timeout duration. The default value is **0**, indicating no timeout. | - -- **Return value** + | pipe | [USBDevicePipe](#usbdevicepipe) | Yes| USB device pipe, which is used to determine the USB device.| + | endpoint | [USBEndpoint](#usbendpoint) | Yes| USB endpoint, which is used to determine the USB port for data transfer.| + | buffer | Uint8Array | Yes| Buffer for writing or reading data.| + | timeout | number | No| Timeout duration. The default value is **0**, indicating no timeout.| +**Return value** | Type| Description| | -------- | -------- | - | Promise<number> | Returns the size of the transmitted or received data block if the control transfer is successful; returns **-1** if an exception occurs. | + | Promise<number> | Returns the size of the transmitted or received data block if the control transfer is successful; returns **-1** if an exception occurs.| -- **Example** - - ```js - // Call usb.getDevices to obtain a data set. Then, obtain a USB device and its access permission. - // Pass the obtained USB device as a parameter to usb.connectDevice. Then, call usb.connectDevice to connect the USB device. - // Call usb.claimInterface to claim a USB interface. After that, call usb.bulkTransfer to start bulk transfer. - usb.bulkTransfer(devicepipe, endpoint, buffer).then((ret) => { - console.log(`bulkTransfer = ${JSON.stringify(ret)}`); - }); - ``` +**Example** +```js +// Call usb.getDevices to obtain a data set. Then, obtain a USB device and its access permission. +// Pass the obtained USB device as a parameter to usb.connectDevice. Then, call usb.connectDevice to connect the USB device. +// Call usb.claimInterface to claim the USB interface. After that, call usb.bulkTransfer to start bulk transfer. +usb.bulkTransfer(devicepipe, endpoint, buffer).then((ret) => { + console.log(`bulkTransfer = ${JSON.stringify(ret)}`); +}); +``` ## usb.closePipe @@ -433,25 +405,211 @@ Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB devi **System capability**: SystemCapability.USB.USBManager -- **Parameters** - +**Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | - | pipe | [USBDevicePipe](#usbdevicepipe) | Yes| USB device pipe. | - -- **Return value** + | pipe | [USBDevicePipe](#usbdevicepipe) | Yes| USB device pipe.| +**Return value** | Type| Description| | -------- | -------- | - | number | Returns **0** if the USB device pipe is closed successfully; returns an error code otherwise. | + | number | Returns **0** if the USB device pipe is closed successfully; returns an error code otherwise.| + +**Example** + +```js +let ret = usb.closePipe(devicepipe); +console.log(`closePipe = ${ret}`); +``` + +## usb.usbFunctionsFromString9+ + +usbFunctionsFromString(funcs: string): number + +Converts the USB function list in the string format to a numeric mask in Device mode. + +**System API**: This is a system API. + +**System capability**: SystemCapability.USB.USBManager + +**Parameters** + +| Name| Type | Mandatory| Description | +| ------ | ------ | ---- | ---------------------- | +| funcs | string | Yes | Function list in string format.| + +**Return value** + +| Type | Description | +| ------ | ------------------ | +| number | Function list in numeric mask format.| + +**Example** + +```js +let funcs = "acm"; +let ret = usb.usbFunctionsFromString(funcs); +``` + +## usb.usbFunctionsToString9+ + +usbFunctionsToString(funcs: FunctionType): string + +Converts the USB function list in the numeric mask format to a string in Device mode. + +**System API**: This is a system API. + +**System capability**: SystemCapability.USB.USBManager + +**Parameters** -- **Example** +| Name| Type | Mandatory| Description | +| ------ | ------------------------------ | ---- | ----------------- | +| funcs | [FunctionType](#functiontype9) | Yes | USB function list in numeric mask format.| - ```js - let ret = usb.closePipe(devicepipe); - console.log(`closePipe = ${ret}`); - ``` +**Return value** +| Type | Description | +| ------ | ------------------------------ | +| string | Function list in string format.| + +**Example** + +```js +let funcs = ACM | ECM; +let ret = usb.usbFunctionsToString(funcs); +``` + +## usb.setCurrentFunctions9+ + +setCurrentFunctions(funcs: FunctionType): Promise\ + +Sets the current USB function list in Device mode. + +**System API**: This is a system API. + +**System capability**: SystemCapability.USB.USBManager + +**Parameters** + +| Name| Type | Mandatory| Description | +| ------ | ------------------------------ | ---- | ----------------- | +| funcs | [FunctionType](#functiontype9) | Yes | USB function list in numeric mask format.| + +**Return value** + +| Type | Description | +| ------------------ | ------------------------------------------------------ | +| Promise\ | Promise used to return the result. The value **true** indicates that the operation is successful, and the value **false** indicates the opposite.| + +**Example** + +```js +let funcs = HDC; +let ret = usb.setCurrentFunctions(funcs); +``` + +## usb.getCurrentFunctions9+ + +getCurrentFunctions(): FunctionType + +Obtains the numeric mask combination for the USB function list in Device mode. + +**System API**: This is a system API. + +**System capability**: SystemCapability.USB.USBManager + +**Return value** + +| Type | Description | +| ------------------------------ | --------------------------------- | +| [FunctionType](#functiontype9) | Numeric mask combination for the USB function list.| + +**Example** + +```js +let ret = usb.getCurrentFunctions(); +``` + +## usb.getPorts9+ + +getPorts(): Array\ + +Obtains the list of all physical USB ports. + +**System API**: This is a system API. + +**System capability**: SystemCapability.USB.USBManager + +**Return value** + +| Type | Description | +| ----------------------------- | --------------------- | +| [Array\](#usbport9) | List of physical USB ports.| + +**Example** + +```js +let ret = usb.getPorts(); +``` + +## usb.getSupportedModes9+ + +getSupportedModes(portId: number): PortModeType + +Obtains the mask combination for the supported mode list of a given USB port. + +**System API**: This is a system API. + +**System capability**: SystemCapability.USB.USBManager + +**Parameters** + +| Name| Type | Mandatory| Description | +| ------ | ------ | ---- | -------- | +| portId | number | Yes | Port number.| + +**Return value** + +| Type | Description | +| ------------------------------ | -------------------------- | +| [PortModeType](#portmodetype9) | Mask combination for the supported mode list.| + +**Example** + +```js +let ret = usb.getSupportedModes(0); +``` + +## usb.setPortRoles9+ + +setPortRoles(portId: number, powerRole: PowerRoleType, dataRole: DataRoleType): Promise\ + +Sets the role types supported by a specified port, which can be **powerRole** (for charging) and **dataRole** (for data transfer). + +**System API**: This is a system API. + +**System capability**: SystemCapability.USB.USBManager + +**Parameters** + +| Name | Type | Mandatory| Description | +| --------- | -------------------------------- | ---- | ---------------- | +| portId | number | Yes | Port number. | +| powerRole | [PowerRoleType](#powerroletype9) | Yes | Role for charging. | +| dataRole | [DataRoleType](#dataroletype9) | Yes | Role for data transfer.| + +**Return value** + +| Type | Description | +| ------------------ | -------------- | +| Promise\ | Promise used to return the result. The value **true** indicates that the operation is successful, and the value **false** indicates the opposite.| + +**Example** + +```js +let ret = usb.getSupportedModes(0); +``` ## USBEndpoint @@ -459,17 +617,16 @@ Represents the USB endpoint from which data is sent or received. You can obtain **System capability**: SystemCapability.USB.USBManager -| Name| Type| Description| -| -------- | -------- | -------- | -| address | number | Endpoint address. | -| attributes | number | Endpoint attributes. | -| interval | number | Endpoint interval. | -| maxPacketSize | number | Maximum size of data packets on the endpoint. | -| direction | [USBRequestDirection](#usbrequestdirection) | Endpoint direction. | -| number | number | Endpoint number. | -| type | number | Endpoint type. | -| interfaceId | number | Unique ID of the interface to which the endpoint belongs. | - +| Name | Type | Description | +| ------------- | ------------------------------------------- | ------------- | +| address | number | Endpoint address. | +| attributes | number | Endpoint attributes. | +| interval | number | Endpoint interval. | +| maxPacketSize | number | Maximum size of data packets on the endpoint. | +| direction | [USBRequestDirection](#usbrequestdirection) | Endpoint direction. | +| number | number | Endpoint number. | +| type | number | Endpoint type. | +| interfaceId | number | Unique ID of the interface to which the endpoint belongs.| ## USBInterface @@ -477,16 +634,15 @@ Represents a USB interface. One [USBConfig](#usbconfig) can contain multiple **U **System capability**: SystemCapability.USB.USBManager -| Name| Type| Description| -| -------- | -------- | -------- | -| id | number | Unique ID of the USB interface. | -| protocol | number | Interface protocol. | -| clazz | number | Device type. | -| subClass | number | Device subclass. | -| alternateSetting | number | Settings for alternating between descriptors of the same USB interface. | -| name | string | Interface name. | -| endpoints | Array<[USBEndpoint](#usbendpoint)> | Endpoints that belong to the USB interface. | - +| Name | Type | Description | +| ---------------- | ---------------------------------------- | --------------------- | +| id | number | Unique ID of the USB interface. | +| protocol | number | Interface protocol. | +| clazz | number | Device type. | +| subClass | number | Device subclass. | +| alternateSetting | number | Settings for alternating between descriptors of the same USB interface.| +| name | string | Interface name. | +| endpoints | Array<[USBEndpoint](#usbendpoint)> | Endpoints that belong to the USB interface. | ## USBConfig @@ -494,39 +650,37 @@ Represents the USB configuration. One [USBDevice](#usbdevice) can contain multip **System capability**: SystemCapability.USB.USBManager -| Name| Type| Description| -| -------- | -------- | -------- | -| id | number | Unique ID of the USB configuration. | -| attributes | number | Configuration attributes. | -| maxPower | number | Maximum power consumption, in mA. | -| name | string | Configuration name, which can be left empty. | -| isRemoteWakeup | boolean | Support for remote wakeup. | -| isSelfPowered | boolean | Support for independent power supplies. | -| interfaces | Array <[USBInterface](#usbinterface)> | Supported interface attributes. | - +| Name | Type | Description | +| -------------- | ------------------------------------------------ | --------------- | +| id | number | Unique ID of the USB configuration. | +| attributes | number | Configuration attributes. | +| maxPower | number | Maximum power consumption, in mA. | +| name | string | Configuration name, which can be left empty. | +| isRemoteWakeup | boolean | Support for remote wakeup.| +| isSelfPowered | boolean | Support for independent power supplies.| +| interfaces | Array <[USBInterface](#usbinterface)> | Supported interface attributes. | ## USBDevice -Represents USB device information. +Represents the USB device information. **System capability**: SystemCapability.USB.USBManager -| Name| Type| Description| -| -------- | -------- | -------- | -| busNum | number | Bus address. | -| devAddress | number | Device address. | -| serial | string | Device SN. | -| name | string | Device name. | -| manufacturerName | string | Device manufacturer. | -| productName | string | Product information. | -| version | string | Version. | -| vendorId | number | Vendor ID. | -| productId | number | Product ID. | -| clazz | number | Device class. | -| subClass | number | Device subclass. | -| protocol | number | Device protocol code. | -| configs | Array<[USBConfig](#usbconfig)> | Device configuration descriptor information. | - +| Name | Type | Description | +| ---------------- | ------------------------------------ | ---------- | +| busNum | number | Bus address. | +| devAddress | number | Device address. | +| serial | string | Sequence number. | +| name | string | Device name. | +| manufacturerName | string | Device manufacturer. | +| productName | string | Product name. | +| version | string | Version number. | +| vendorId | number | Vendor ID. | +| productId | number | Product ID. | +| clazz | number | Device class. | +| subClass | number | Device subclass. | +| protocol | number | Device protocol code. | +| configs | Array<[USBConfig](#usbconfig)> | Device configuration descriptor information.| ## USBDevicePipe @@ -534,11 +688,10 @@ Represents a USB device pipe, which is used to determine a USB device. **System capability**: SystemCapability.USB.USBManager -| Name| Type| Description| -| -------- | -------- | -------- | -| busNum | number | Bus address. | -| devAddress | number | Device address. | - +| Name | Type | Description | +| ---------- | ------ | ----- | +| busNum | number | Bus address.| +| devAddress | number | Device address.| ## USBControlParams @@ -546,29 +699,55 @@ Represents control transfer parameters. **System capability**: SystemCapability.USB.USBManager -| Name| Type| Description| -| -------- | -------- | -------- | -| request | number | Request type. | -| target | [USBRequestTargetType](#usbrequesttargettype) | Type of the request target. | -| reqType | [USBControlRequestType](#usbcontrolrequesttype) | Request control type. | -| value | number | Request parameters| -| index | number | Index of the request parameter value. | -| data | Uint8Array | Buffer for writing or reading data. | +| Name | Type | Description | +| ------- | ----------------------------------------------- | ---------------- | +| request | number | Request type. | +| target | [USBRequestTargetType](#usbrequesttargettype) | Request target type. | +| reqType | [USBControlRequestType](#usbcontrolrequesttype) | Control request type. | +| value | number | Request parameter value. | +| index | number | Index of the request parameter value.| +| data | Uint8Array | Buffer for writing or reading data. | +## USBPort9+ -## USBRequestTargetType +Represents a USB port. + +**System API**: This is a system API. -Represents the request target type. +**System capability**: SystemCapability.USB.USBManager + +| Name | Type | Description | +| -------------- | -------------------------------- | ----------------------------------- | +| id | number | Unique identifier of a USB port. | +| supportedModes | [PortModeType](#portmodetype9) | Numeric mask combination for the supported mode list.| +| status | [USBPortStatus](#usbportstatus9) | USB port role. | + +## USBPortStatus9+ + +Enumerates USB port roles. + +**System API**: This is a system API. **System capability**: SystemCapability.USB.USBManager -| Name| Default Value | Description| -| -------- | -------- | -------- | -| USB_REQUEST_TARGET_DEVICE | 0 | Device. | -| USB_REQUEST_TARGET_INTERFACE | 1 | Interface. | -| USB_REQUEST_TARGET_ENDPOINT | 2 | Endpoint| -| USB_REQUEST_TARGET_OTHER | 3 | Others| +| Name | Type| Description | +| ---------------- | -------- | ---------------------- | +| currentMode | number | Current USB mode. | +| currentPowerRole | number | Current power role. | +| currentDataRole | number | Current data role.| +## USBRequestTargetType + +Enumerates request target types. + +**System capability**: SystemCapability.USB.USBManager + +| Name | Value | Description | +| ---------------------------- | ---- | ------ | +| USB_REQUEST_TARGET_DEVICE | 0 | Device.| +| USB_REQUEST_TARGET_INTERFACE | 1 | Interface.| +| USB_REQUEST_TARGET_ENDPOINT | 2 | Endpoint.| +| USB_REQUEST_TARGET_OTHER | 3 | Other.| ## USBControlRequestType @@ -576,12 +755,11 @@ Enumerates control request types. **System capability**: SystemCapability.USB.USBManager -| Name| Default Value | Description| -| -------- | -------- | -------- | -| USB_REQUEST_TYPE_STANDARD | 0 | Standard| -| USB_REQUEST_TYPE_CLASS | 1 | Class. | -| USB_REQUEST_TYPE_VENDOR | 2 | Vendor| - +| Name | Value | Description | +| ------------------------- | ---- | ------ | +| USB_REQUEST_TYPE_STANDARD | 0 | Standard.| +| USB_REQUEST_TYPE_CLASS | 1 | Class. | +| USB_REQUEST_TYPE_VENDOR | 2 | Vendor.| ## USBRequestDirection @@ -589,16 +767,16 @@ Enumerates request directions. **System capability**: SystemCapability.USB.USBManager -| Name| Default Value | Description| -| -------- | -------- | -------- | -| USB_REQUEST_DIR_TO_DEVICE | 0 | Request for writing data from the host to the device. | -| USB_REQUEST_DIR_FROM_DEVICE | 0x80 | Request for reading data from the device to the host. | +| Name | Value | Description | +| --------------------------- | ---- | ------------------------ | +| USB_REQUEST_DIR_TO_DEVICE | 0 | Request for writing data from the host to the device.| +| USB_REQUEST_DIR_FROM_DEVICE | 0x80 | Request for reading data from the device to the host.| ## FunctionType9+ -Enumerates function types for the USB device. +Enumerates USB device function types. -This is a system API. +**System API**: This is a system API. **System capability**: SystemCapability.USB.USBManager @@ -619,7 +797,7 @@ This is a system API. Enumerates USB port mode types. -This is a system API. +**System API**: This is a system API. **System capability**: SystemCapability.USB.USBManager @@ -635,7 +813,7 @@ This is a system API. Enumerates power role types. -This is a system API. +**System API**: This is a system API. **System capability**: SystemCapability.USB.USBManager @@ -649,7 +827,7 @@ This is a system API. Enumerates data role types. -This is a system API. +**System API**: This is a system API. **System capability**: SystemCapability.USB.USBManager