1# @ohos.usbV9 (USB) 2 3The USB module provides USB device management functions, including USB device list query, bulk data transfer, control transfer, and permission control on the host side as well as port management, and function switch and query on the device side. 4 5> **NOTE** 6> 7> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. 8> 9> The APIs provided by this module are no longer maintained since API version 9. You are advised to use [`@ohos.usbManager`](js-apis-usbManager.md). 10 11## Modules to Import 12 13```js 14import usb from "@ohos.usbV9"; 15``` 16 17## usb.getDevices 18 19getDevices(): Array<Readonly<USBDevice>> 20 21Obtains the list of USB devices connected to the host. If no device is connected, an empty list is returned. 22 23**System capability**: SystemCapability.USB.USBManager 24 25**Return value** 26 27| Type | Description | 28| ---------------------------------------------------- | ------- | 29| Array<Readonly<[USBDevice](#usbdevice)>> | USB device list.| 30 31**Example** 32 33```js 34let devicesList = usb.getDevices(); 35console.log(`devicesList = ${devicesList}`); 36// devicesList is a list of USB devices. 37// A simple example of devicesList is provided as follows: 38[ 39 { 40 name: "1-1", 41 serial: "", 42 manufacturerName: "", 43 productName: "", 44 version: "", 45 vendorId: 7531, 46 productId: 2, 47 clazz: 9, 48 subClass: 0, 49 protocol: 1, 50 devAddress: 1, 51 busNum: 1, 52 configs: [ 53 { 54 id: 1, 55 attributes: 224, 56 isRemoteWakeup: true, 57 isSelfPowered: true, 58 maxPower: 0, 59 name: "1-1", 60 interfaces: [ 61 { 62 id: 0, 63 protocol: 0, 64 clazz: 9, 65 subClass: 0, 66 alternateSetting: 0, 67 name: "1-1", 68 endpoints: [ 69 { 70 address: 129, 71 attributes: 3, 72 interval: 12, 73 maxPacketSize: 4, 74 direction: 128, 75 number: 1, 76 type: 3, 77 interfaceId: 0, 78 }, 79 ], 80 }, 81 ], 82 }, 83 ], 84 }, 85] 86``` 87 88## usb.connectDevice 89 90connectDevice(device: USBDevice): Readonly<USBDevicePipe> 91 92Connects to the USB device based on the device information returned by **getDevices()**. 93 94Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB device list and device information, and then call [usb.requestRight](#usbrequestright) to request the device access permission. 95 96**System capability**: SystemCapability.USB.USBManager 97 98**Parameters** 99 100| Name| Type| Mandatory| Description| 101| -------- | -------- | -------- | -------- | 102| device | [USBDevice](#usbdevice) | Yes| USB device information.| 103 104**Return value** 105 106| Type| Description| 107| -------- | -------- | 108| Readonly<[USBDevicePipe](#usbdevicepipe)> | USB device pipe for data transfer.| 109 110**Error codes** 111 112For details about the error codes, see [USB Error Codes](../errorcodes/errorcode-usb.md). 113 114| ID| Error Message| 115| -------- | -------- | 116| 14400001 |Permission denied. Need call requestRight to get permission. | 117 118**Example** 119 120```js 121let devicesList = usb.getDevices(); 122if (devicesList.length == 0) { 123 console.log(`device list is empty`); 124} 125 126let device = devicesList[0]; 127usb.requestRight(device.name); 128let devicepipe = usb.connectDevice(device); 129console.log(`devicepipe = ${devicepipe}`); 130``` 131 132## usb.hasRight 133 134hasRight(deviceName: string): boolean 135 136Checks whether the application has the permission to access the device. 137 138Checks 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. 139 140**System capability**: SystemCapability.USB.USBManager 141 142**Parameters** 143 144| Name| Type| Mandatory| Description| 145| -------- | -------- | -------- | -------- | 146| deviceName | string | Yes| Device name.| 147 148**Return value** 149 150| Type| Description| 151| -------- | -------- | 152| boolean | Returns **true** if the application has the permission to access the device; returns **false** otherwise.| 153 154**Example** 155 156```js 157let devicesName="1-1"; 158let bool = usb.hasRight(devicesName); 159console.log(bool); 160``` 161 162## usb.requestRight 163 164requestRight(deviceName: string): Promise<boolean> 165 166Requests the temporary permission for the application to access a USB device. This API uses a promise to return the result. 167 168**System capability**: SystemCapability.USB.USBManager 169 170**Parameters** 171 172| Name| Type| Mandatory| Description| 173| -------- | -------- | -------- | -------- | 174| deviceName | string | Yes| Device name.| 175 176**Return value** 177 178| Type| Description| 179| -------- | -------- | 180| Promise<boolean> | Promise used to return the result. The value **true** indicates that the temporary device access permissions are granted; and the value **false** indicates the opposite.| 181 182**Example** 183 184```js 185let devicesName="1-1"; 186usb.requestRight(devicesName).then((ret) => { 187 console.log(`requestRight = ${ret}`); 188}); 189``` 190 191## usb.removeRight 192 193removeRight(deviceName: string): boolean 194 195Removes the permission for the application to access a USB device. 196 197**System capability**: SystemCapability.USB.USBManager 198 199**Parameters** 200 201| Name| Type| Mandatory| Description| 202| -------- | -------- | -------- | -------- | 203| deviceName | string | Yes| Device name.| 204 205**Return value** 206 207| Type| Description| 208| -------- | -------- | 209| boolean | Permission removal result. The value **true** indicates that the access permission is removed successfully; and the value **false** indicates the opposite.| 210 211**Example** 212 213```js 214let devicesName="1-1"; 215if usb.removeRight(devicesName) { 216 console.log(`Succeed in removing right`); 217} 218``` 219 220## usb.addRight 221 222addRight(bundleName: string, deviceName: string): boolean 223 224Adds the permission for the application to access a USB device. 225 226[requestRight](#usbrequestright) triggers a dialog box to request for user authorization, whereas **addRight** adds the access permission directly without displaying a dialog box. 227 228**System API**: This is a system API. 229 230**System capability**: SystemCapability.USB.USBManager 231 232**Parameters** 233 234| Name| Type| Mandatory| Description| 235| -------- | -------- | -------- | -------- | 236| deviceName | string | Yes| Device name.| 237| bundleName | string | Yes| Bundle name of the application.| 238 239**Return value** 240 241| Type| Description| 242| -------- | -------- | 243| boolean | Permission addition result. The value **true** indicates that the access permission is added successfully; and the value **false** indicates the opposite.| 244 245**Example** 246 247```js 248let devicesName = "1-1"; 249let bundleName = "com.example.hello"; 250if usb.addRight(bundleName, devicesName) { 251 console.log(`Succeed in adding right`); 252} 253``` 254 255## usb.claimInterface 256 257claimInterface(pipe: USBDevicePipe, iface: USBInterface, force ?: boolean): number 258 259Claims a USB interface. 260 261Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB device list and USB interfaces, call [usb.requestRight](#usbrequestright) to request the device access permission, and call [usb.connectDevice](#usbconnectdevice) to obtain **devicepipe** as an input parameter. 262 263**System capability**: SystemCapability.USB.USBManager 264 265**Parameters** 266 267| Name| Type| Mandatory| Description| 268| -------- | -------- | -------- | -------- | 269| pipe | [USBDevicePipe](#usbdevicepipe) | Yes| Device pipe, which is used to determine the bus number and device address.| 270| iface | [USBInterface](#usbinterface) | Yes| USB interface, which is used to determine the index of the interface to claim.| 271| force | boolean | No| Whether to forcibly claim the USB interface. The default value is **false**, indicating not to forcibly claim the USB interface.| 272 273**Return value** 274 275| Type| Description| 276| -------- | -------- | 277| number | Returns **0** if the USB interface is successfully claimed; returns an error code otherwise.| 278 279**Example** 280 281```js 282let ret = usb.claimInterface(devicepipe, interfaces); 283console.log(`claimInterface = ${ret}`); 284``` 285 286## usb.releaseInterface 287 288releaseInterface(pipe: USBDevicePipe, iface: USBInterface): number 289 290Releases a USB interface. 291 292Before you do this, ensure that you have claimed the interface by calling [usb.claimInterface](#usbclaiminterface). 293 294**System capability**: SystemCapability.USB.USBManager 295 296**Parameters** 297 298| Name| Type| Mandatory| Description| 299| -------- | -------- | -------- | -------- | 300| pipe | [USBDevicePipe](#usbdevicepipe) | Yes| Device pipe, which is used to determine the bus number and device address.| 301| iface | [USBInterface](#usbinterface) | Yes| USB interface, which is used to determine the index of the interface to release.| 302 303**Return value** 304 305| Type| Description| 306| -------- | -------- | 307| number | Returns **0** if the USB interface is successfully released; returns an error code otherwise.| 308 309**Example** 310 311```js 312let ret = usb.releaseInterface(devicepipe, interfaces); 313console.log(`releaseInterface = ${ret}`); 314``` 315 316## usb.setConfiguration 317 318setConfiguration(pipe: USBDevicePipe, config: USBConfig): number 319 320Sets the device configuration. 321 322Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB device list and device configuration, call [usb.requestRight](#usbrequestright) to request the device access permission, and call [usb.connectDevice](#usbconnectdevice) to obtain **devicepipe** as an input parameter. 323 324**System capability**: SystemCapability.USB.USBManager 325 326**Parameters** 327 328| Name| Type| Mandatory| Description| 329| -------- | -------- | -------- | -------- | 330| pipe | [USBDevicePipe](#usbdevicepipe) | Yes| Device pipe, which is used to determine the bus number and device address.| 331| config | [USBConfig](#usbconfig) | Yes| USB configuration to set.| 332 333**Return value** 334 335| Type| Description| 336| -------- | -------- | 337| number | Returns **0** if the USB configuration is successfully set; returns an error code otherwise.| 338 339**Example** 340 341```js 342let ret = usb.setConfiguration(devicepipe, config); 343console.log(`setConfiguration = ${ret}`); 344``` 345 346## usb.setInterface 347 348setInterface(pipe: USBDevicePipe, iface: USBInterface): number 349 350Sets a USB interface. 351 352Before 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. 353 354**System capability**: SystemCapability.USB.USBManager 355 356**Parameters** 357 358| Name | Type | Mandatory | Description | 359| ----- | ------------------------------- | --- | ------------- | 360| pipe | [USBDevicePipe](#usbdevicepipe) | Yes | Device pipe, which is used to determine the bus number and device address.| 361| iface | [USBInterface](#usbinterface) | Yes | USB interface to set. | 362 363**Return value** 364 365| Type| Description| 366| -------- | -------- | 367| number | Returns **0** if the USB interface is successfully set; returns an error code otherwise.| 368 369**Example** 370 371```js 372let ret = usb.setInterface(devicepipe, interfaces); 373console.log(`setInterface = ${ret}`); 374``` 375 376## usb.getRawDescriptor 377 378getRawDescriptor(pipe: USBDevicePipe): Uint8Array 379 380Obtains the raw USB descriptor. 381 382Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB device list, call [usb.requestRight](#usbrequestright) to request the device access permission, and call [usb.connectDevice](#usbconnectdevice) to obtain **devicepipe** as an input parameter. 383 384**System capability**: SystemCapability.USB.USBManager 385 386**Parameters** 387 388| Name| Type| Mandatory| Description| 389| -------- | -------- | -------- | -------- | 390| pipe | [USBDevicePipe](#usbdevicepipe) | Yes| Device pipe, which is used to determine the bus number and device address.| 391 392**Return value** 393 394| Type| Description| 395| -------- | -------- | 396| Uint8Array | Returns the raw USB descriptor if the operation is successful; returns **undefined** otherwise.| 397 398**Example** 399 400```js 401let ret = usb.getRawDescriptor(devicepipe); 402``` 403 404## usb.getFileDescriptor 405 406getFileDescriptor(pipe: USBDevicePipe): number 407 408Obtains the file descriptor. 409 410Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB device list, call [usb.requestRight](#usbrequestright) to request the device access permission, and call [usb.connectDevice](#usbconnectdevice) to obtain **devicepipe** as an input parameter. 411 412**System capability**: SystemCapability.USB.USBManager 413 414**Parameters** 415 416| Name| Type| Mandatory| Description| 417| -------- | -------- | -------- | -------- | 418| pipe | [USBDevicePipe](#usbdevicepipe) | Yes| Device pipe, which is used to determine the bus number and device address.| 419 420**Return value** 421 422| Type | Description | 423| ------ | -------------------- | 424| number | Returns the file descriptor of the USB device if the operation is successful; returns **-1** otherwise.| 425 426**Example** 427 428```js 429let ret = usb.getFileDescriptor(devicepipe); 430``` 431 432## usb.controlTransfer 433 434controlTransfer(pipe: USBDevicePipe, controlparam: USBControlParams, timeout ?: number): Promise<number> 435 436Performs control transfer. 437 438Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB device list, call [usb.requestRight](#usbrequestright) to request the device access permission, and call [usb.connectDevice](#usbconnectdevice) to obtain **devicepipe** as an input parameter. 439 440**System capability**: SystemCapability.USB.USBManager 441 442**Parameters** 443 444| Name| Type| Mandatory| Description| 445| -------- | -------- | -------- | -------- | 446| pipe | [USBDevicePipe](#usbdevicepipe) | Yes| USB device pipe, which is used to determine the USB device.| 447| controlparam | [USBControlParams](#usbcontrolparams) | Yes| Control transfer parameters.| 448| timeout | number | No| Timeout duration in ms. This parameter is optional. The default value is **0**, indicating no timeout.| 449 450**Return value** 451 452| Type| Description| 453| -------- | -------- | 454| Promise<number> | Promise used to return the result, which is the size of the transmitted or received data block if the transfer is successful, or **-1** if an exception has occurred.| 455 456**Example** 457 458```js 459let param = new usb.USBControlParams(); 460usb.controlTransfer(devicepipe, param).then((ret) => { 461 console.log(`controlTransfer = ${ret}`); 462}) 463``` 464 465## usb.bulkTransfer 466 467bulkTransfer(pipe: USBDevicePipe, endpoint: USBEndpoint, buffer: Uint8Array, timeout ?: number): Promise<number> 468 469Performs bulk transfer. 470 471Before 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. 472 473**System capability**: SystemCapability.USB.USBManager 474 475**Parameters** 476 477| Name| Type| Mandatory| Description| 478| -------- | -------- | -------- | -------- | 479| pipe | [USBDevicePipe](#usbdevicepipe) | Yes| USB device pipe, which is used to determine the USB device.| 480| endpoint | [USBEndpoint](#usbendpoint) | Yes| USB endpoint, which is used to determine the USB port for data transfer.| 481| buffer | Uint8Array | Yes| Buffer for writing or reading data.| 482| timeout | number | No| Timeout duration in ms. This parameter is optional. The default value is **0**, indicating no timeout.| 483 484**Return value** 485 486| Type| Description| 487| -------- | -------- | 488| Promise<number> | Promise used to return the result, which is the size of the transmitted or received data block if the transfer is successful, or **-1** if an exception has occurred.| 489 490**Example** 491 492```js 493// Call usb.getDevices to obtain a data set. Then, obtain a USB device and its access permission. 494// Pass the obtained USB device as a parameter to usb.connectDevice. Then, call usb.connectDevice to connect the USB device. 495// Call usb.claimInterface to claim the USB interface. After that, call usb.bulkTransfer to start bulk transfer. 496usb.bulkTransfer(devicepipe, endpoint, buffer).then((ret) => { 497 console.log(`bulkTransfer = ${ret}`); 498}); 499``` 500 501## usb.closePipe 502 503closePipe(pipe: USBDevicePipe): number 504 505Closes a USB device pipe. 506 507Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB device list, call [usb.requestRight](#usbrequestright) to request the device access permission, and call [usb.connectDevice](#usbconnectdevice) to obtain **devicepipe** as an input parameter. 508 509**System capability**: SystemCapability.USB.USBManager 510 511**Parameters** 512 513| Name| Type| Mandatory| Description| 514| -------- | -------- | -------- | -------- | 515| pipe | [USBDevicePipe](#usbdevicepipe) | Yes| USB device pipe.| 516 517**Return value** 518 519| Type| Description| 520| -------- | -------- | 521| number | Returns **0** if the USB device pipe is closed successfully; returns an error code otherwise.| 522 523**Example** 524 525```js 526let ret = usb.closePipe(devicepipe); 527console.log(`closePipe = ${ret}`); 528``` 529 530## usb.usbFunctionsFromString 531 532usbFunctionsFromString(funcs: string): number 533 534Converts the USB function list in the string format to a numeric mask in Device mode. 535 536**System API**: This is a system API. 537 538**System capability**: SystemCapability.USB.USBManager 539 540**Parameters** 541 542| Name| Type | Mandatory| Description | 543| ------ | ------ | ---- | ---------------------- | 544| funcs | string | Yes | Function list in string format.| 545 546**Return value** 547 548| Type | Description | 549| ------ | ------------------ | 550| number | Function list in numeric mask format.| 551 552**Example** 553 554```js 555let funcs = "acm"; 556let ret = usb.usbFunctionsFromString(funcs); 557``` 558 559## usb.usbFunctionsToString 560 561usbFunctionsToString(funcs: FunctionType): string 562 563Converts the USB function list in the numeric mask format to a string in Device mode. 564 565**System API**: This is a system API. 566 567**System capability**: SystemCapability.USB.USBManager 568 569**Parameters** 570 571| Name| Type | Mandatory| Description | 572| ------ | ------------------------------ | ---- | ----------------- | 573| funcs | [FunctionType](#functiontype) | Yes | USB function list in numeric mask format.| 574 575**Return value** 576 577| Type | Description | 578| ------ | ------------------------------ | 579| string | Function list in string format.| 580 581**Example** 582 583```js 584let funcs = usb.ACM | usb.ECM; 585let ret = usb.usbFunctionsToString(funcs); 586``` 587 588## usb.setCurrentFunctions 589 590setCurrentFunctions(funcs: FunctionType): Promise\<boolean\> 591 592Sets the current USB function list in Device mode. 593 594**System API**: This is a system API. 595 596**System capability**: SystemCapability.USB.USBManager 597 598**Parameters** 599 600| Name| Type | Mandatory| Description | 601| ------ | ------------------------------ | ---- | ----------------- | 602| funcs | [FunctionType](#functiontype) | Yes | USB function list in numeric mask format.| 603 604**Return value** 605 606| Type | Description | 607| ------------------ | ------------------------------------------------------------ | 608| Promise\<boolean\> | Promise used to return the result. The value **true** indicates that the operation is successful, and the value **false** indicates the opposite.| 609 610**Example** 611 612```js 613let funcs = usb.HDC; 614let ret = usb.setCurrentFunctions(funcs); 615``` 616 617## usb.getCurrentFunctions 618 619getCurrentFunctions(): FunctionType 620 621Obtains the numeric mask combination for the USB function list in Device mode. 622 623**System API**: This is a system API. 624 625**System capability**: SystemCapability.USB.USBManager 626 627**Return value** 628 629| Type | Description | 630| ------------------------------ | --------------------------------- | 631| [FunctionType](#functiontype) | Numeric mask combination for the USB function list.| 632 633**Example** 634 635```js 636let ret = usb.getCurrentFunctions(); 637``` 638 639## usb.getPorts 640 641getPorts(): Array\<USBPort\> 642 643Obtains the list of all physical USB ports. 644 645**System API**: This is a system API. 646 647**System capability**: SystemCapability.USB.USBManager 648 649**Return value** 650 651| Type | Description | 652| ----------------------------- | --------------------- | 653| [Array\<USBPort\>](#usbport) | List of physical USB ports.| 654 655**Example** 656 657```js 658let ret = usb.getPorts(); 659``` 660 661## usb.getSupportedModes 662 663getSupportedModes(portId: number): PortModeType 664 665Obtains the mask combination for the supported mode list of a given USB port. 666 667**System API**: This is a system API. 668 669**System capability**: SystemCapability.USB.USBManager 670 671**Parameters** 672 673| Name| Type | Mandatory| Description | 674| ------ | ------ | ---- | -------- | 675| portId | number | Yes | Port number.| 676 677**Return value** 678 679| Type | Description | 680| ------------------------------ | -------------------------- | 681| [PortModeType](#portmodetype) | Mask combination for the supported mode list.| 682 683**Example** 684 685```js 686let ret = usb.getSupportedModes(0); 687``` 688 689## usb.setPortRoles 690 691setPortRoles(portId: number, powerRole: PowerRoleType, dataRole: DataRoleType): Promise\<boolean\> 692 693Sets the role types supported by a specified port, which can be **powerRole** (for charging) and **dataRole** (for data transfer). 694 695**System API**: This is a system API. 696 697**System capability**: SystemCapability.USB.USBManager 698 699**Parameters** 700 701| Name | Type | Mandatory| Description | 702| --------- | -------------------------------- | ---- | ---------------- | 703| portId | number | Yes | Port number. | 704| powerRole | [PowerRoleType](#powerroletype) | Yes | Role for charging. | 705| dataRole | [DataRoleType](#dataroletype) | Yes | Role for data transfer.| 706 707**Return value** 708 709| Type | Description | 710| ------------------ | ------------------------------------------------------------ | 711| Promise\<boolean\> | Promise used to return the result. The value **true** indicates that the operation is successful, and the value **false** indicates the opposite.| 712 713**Example** 714 715```js 716let portId = 1; 717usb.setPortRoles(portId, usb.PowerRoleType.SOURCE, usb.DataRoleType.HOST).then(() => { 718 console.info('usb setPortRoles successfully.'); 719}).catch(err => { 720 console.error('usb setPortRoles failed: ' + err.code + ' message: ' + err.message); 721}); 722``` 723 724## USBEndpoint 725 726Represents the USB endpoint from which data is sent or received. You can obtain the USB endpoint through [USBInterface](#usbinterface). 727 728**System capability**: SystemCapability.USB.USBManager 729 730| Name | Type | Mandatory |Description | 731| ------------- | ------------------------------------------- | ------------- |------------- | 732| address | number | Yes|Endpoint address. | 733| attributes | number | Yes|Endpoint attributes. | 734| interval | number | Yes|Endpoint interval. | 735| maxPacketSize | number | Yes|Maximum size of data packets on the endpoint. | 736| direction | [USBRequestDirection](#usbrequestdirection) | Yes|Endpoint direction. | 737| number | number | Yes|Endpoint number. | 738| type | number | Yes|Endpoint type. | 739| interfaceId | number | Yes|Unique ID of the interface to which the endpoint belongs.| 740 741## USBInterface 742 743Represents a USB interface. One [USBConfig](#usbconfig) can contain multiple **USBInterface** instances, each providing a specific function. 744 745**System capability**: SystemCapability.USB.USBManager 746 747| Name | Type | Mandatory |Description | 748| ---------------- | ---------------------------------------- | ------------- |--------------------- | 749| id | number | Yes|Unique ID of the USB interface. | 750| protocol | number | Yes|Interface protocol. | 751| clazz | number | Yes|Device type. | 752| subClass | number | Yes|Device subclass. | 753| alternateSetting | number | Yes|Settings for alternating between descriptors of the same USB interface.| 754| name | string | Yes|Interface name. | 755| endpoints | Array<[USBEndpoint](#usbendpoint)> | Yes|Endpoints that belong to the USB interface. | 756 757## USBConfig 758 759Represents the USB configuration. One [USBDevice](#usbdevice) can contain multiple **USBConfig** instances. 760 761**System capability**: SystemCapability.USB.USBManager 762 763| Name | Type | Mandatory |Description | 764| -------------- | ------------------------------------------------ | --------------- |--------------- | 765| id | number | Yes|Unique ID of the USB configuration. | 766| attributes | number | Yes|Configuration attributes. | 767| maxPower | number | Yes|Maximum power consumption, in mA. | 768| name | string | Yes|Configuration name, which can be left empty. | 769| isRemoteWakeup | boolean | Yes|Support for remote wakeup.| 770| isSelfPowered | boolean | Yes| Support for independent power supplies.| 771| interfaces | Array <[USBInterface](#usbinterface)> | Yes|Supported interface attributes. | 772 773## USBDevice 774 775Represents the USB device information. 776 777**System capability**: SystemCapability.USB.USBManager 778 779| Name | Type | Mandatory |Description | 780| ---------------- | ------------------------------------ | ---------- |---------- | 781| busNum | number | Yes|Bus address. | 782| devAddress | number | Yes|Device address. | 783| serial | string | Yes|Sequence number. | 784| name | string | Yes|Device name. | 785| manufacturerName | string | Yes| Device manufacturer. | 786| productName | string | Yes|Product name. | 787| version | string | Yes|Version number. | 788| vendorId | number | Yes|Vendor ID. | 789| productId | number | Yes|Product ID. | 790| clazz | number | Yes|Device class. | 791| subClass | number | Yes|Device subclass. | 792| protocol | number | Yes|Device protocol code. | 793| configs | Array<[USBConfig](#usbconfig)> | Yes|Device configuration descriptor information.| 794 795## USBDevicePipe 796 797Represents a USB device pipe, which is used to determine a USB device. 798 799**System capability**: SystemCapability.USB.USBManager 800 801| Name | Type | Mandatory |Description | 802| ---------- | ------ | ----- |----- | 803| busNum | number |Yes| Bus address.| 804| devAddress | number |Yes| Device address.| 805 806## USBControlParams 807 808Represents control transfer parameters. 809 810**System capability**: SystemCapability.USB.USBManager 811 812| Name | Type | Mandatory |Description | 813| ------- | ----------------------------------------------- | ---------------- |---------------- | 814| request | number | Yes |Request type. | 815| target | [USBRequestTargetType](#usbrequesttargettype) | Yes |Request target type. | 816| reqType | [USBControlRequestType](#usbcontrolrequesttype) | Yes |Control request type. | 817| value | number | Yes |Request parameter value. | 818| index | number | Yes |Index of the request parameter value.| 819| data | Uint8Array | Yes |Buffer for writing or reading data. | 820 821## USBPort 822 823Represents a USB port. 824 825**System API**: This is a system API. 826 827**System capability**: SystemCapability.USB.USBManager 828 829| Name | Type | Mandatory |Description | 830| -------------- | ------------------------------- | ------------------- |------------------------ | 831| id | number | Yes |Unique identifier of a USB port. | 832| supportedModes | [PortModeType](#portmodetype) | Yes |Numeric mask combination for the supported mode list.| 833| status | [USBPortStatus](#usbportstatus) | Yes |USB port role. | 834 835## USBPortStatus 836 837Enumerates USB port roles. 838 839**System API**: This is a system API. 840 841**System capability**: SystemCapability.USB.USBManager 842 843| Name | Type| Mandatory |Description | 844| ---------------- | -------- | ---------------- |---------------------- | 845| currentMode | number | Yes|Current USB mode. | 846| currentPowerRole | number | Yes |Current power role. | 847| currentDataRole | number | Yes |Current data role.| 848 849## USBRequestTargetType 850 851Enumerates request target types. 852 853**System capability**: SystemCapability.USB.USBManager 854 855| Name | Value | Description | 856| ---------------------------- | ---- | ------ | 857| USB_REQUEST_TARGET_DEVICE | 0 | Device| 858| USB_REQUEST_TARGET_INTERFACE | 1 | Interface| 859| USB_REQUEST_TARGET_ENDPOINT | 2 | Endpoint| 860| USB_REQUEST_TARGET_OTHER | 3 | Other| 861 862## USBControlRequestType 863 864Enumerates control request types. 865 866**System capability**: SystemCapability.USB.USBManager 867 868| Name | Value | Description | 869| ------------------------- | ---- | ------ | 870| USB_REQUEST_TYPE_STANDARD | 0 | Standard| 871| USB_REQUEST_TYPE_CLASS | 1 | Class | 872| USB_REQUEST_TYPE_VENDOR | 2 | Vendor| 873 874## USBRequestDirection 875 876Enumerates request directions. 877 878**System capability**: SystemCapability.USB.USBManager 879 880| Name | Value | Description | 881| --------------------------- | ---- | ------------------------ | 882| USB_REQUEST_DIR_TO_DEVICE | 0 | Request for writing data from the host to the device.| 883| USB_REQUEST_DIR_FROM_DEVICE | 0x80 | Request for reading data from the device to the host.| 884 885## FunctionType 886 887Enumerates USB device function types. 888 889**System API**: This is a system API. 890 891**System capability**: SystemCapability.USB.USBManager 892 893| Name | Value | Description | 894| ------------ | ---- | ---------- | 895| NONE | 0 | No function.| 896| ACM | 1 | ACM function. | 897| ECM | 2 | ECM function. | 898| HDC | 4 | HDC function. | 899| MTP | 8 | Not supported currently.| 900| PTP | 16 | Not supported currently.| 901| RNDIS | 32 | Not supported currently.| 902| MIDI | 64 | Not supported currently.| 903| AUDIO_SOURCE | 128 | Not supported currently.| 904| NCM | 256 | Not supported currently.| 905 906## PortModeType 907 908Enumerates USB port mode types. 909 910**System API**: This is a system API. 911 912**System capability**: SystemCapability.USB.USBManager 913 914| Name | Value | Description | 915| --------- | ---- | ---------------------------------------------------- | 916| NONE | 0 | None. | 917| UFP | 1 | Upstream facing port, which functions as the sink of power supply. | 918| DFP | 2 | Downstream facing port, which functions as the source of power supply. | 919| DRP | 3 | Dynamic reconfiguration port (DRP), which can function as the DFP (host) or UFP (device). It is not supported currently.| 920| NUM_MODES | 4 | Not supported currently. | 921 922## PowerRoleType 923 924Enumerates power role types. 925 926**System API**: This is a system API. 927 928**System capability**: SystemCapability.USB.USBManager 929 930| Name | Value | Description | 931| ------ | ---- | ---------- | 932| NONE | 0 | None. | 933| SOURCE | 1 | External power supply.| 934| SINK | 2 | Internal power supply.| 935 936## DataRoleType 937 938Enumerates data role types. 939 940**System API**: This is a system API. 941 942**System capability**: SystemCapability.USB.USBManager 943 944| Name | Value | Description | 945| ------ | ---- | ------------ | 946| NONE | 0 | None. | 947| HOST | 1 | USB host.| 948| DEVICE | 2 | USB device.| 949