• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.usbManager (USB Manager)
2
3The **usbManager** 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 USB interface 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## Modules to Import
10
11```ts
12import { usbManager } from '@kit.BasicServicesKit';
13```
14
15## usbManager.getDevices
16
17getDevices(): Array<Readonly<USBDevice>>
18
19Obtains the list of USB devices connected to the host. If no device is connected, an empty list is returned.
20
21**System capability**: SystemCapability.USB.USBManager
22
23**Return value**
24
25| Type                                                  | Description     |
26| ---------------------------------------------------- | ------- |
27| Array<Readonly<[USBDevice](#usbdevice)>> | USB device list.|
28
29**Example**
30
31```ts
32let devicesList: Array<usbManager.USBDevice> = usbManager.getDevices();
33console.log(`devicesList = ${devicesList}`);
34/*
35The following is a simple example of the data structure for devicesList:
36[
37  {
38    name: "1-1",
39    serial: "",
40    manufacturerName: "",
41    productName: "",
42    version: "",
43    vendorId: 7531,
44    productId: 2,
45    clazz: 9,
46    subClass: 0,
47    protocol: 1,
48    devAddress: 1,
49    busNum: 1,
50    configs: [
51      {
52        id: 1,
53        attributes: 224,
54        isRemoteWakeup: true,
55        isSelfPowered: true,
56        maxPower: 0,
57        name: "1-1",
58        interfaces: [
59          {
60            id: 0,
61            protocol: 0,
62            clazz: 9,
63            subClass: 0,
64            alternateSetting: 0,
65            name: "1-1",
66            endpoints: [
67              {
68                address: 129,
69                attributes: 3,
70                interval: 12,
71                maxPacketSize: 4,
72                direction: 128,
73                number: 1,
74                type: 3,
75                interfaceId: 0,
76              },
77            ],
78          },
79        ],
80      },
81    ],
82  },
83]
84*/
85```
86
87## usbManager.connectDevice
88
89connectDevice(device: USBDevice): Readonly&lt;USBDevicePipe&gt;
90
91Connects to the USB device based on the device information returned by **getDevices()**.
92
93Before you do this, call [usbManager.getDevices](#usbmanagergetdevices) to obtain the USB device list and device information, and then call [usbManager.requestRight](#usbmanagerrequestright) to request the device access permission.
94
95**System capability**: SystemCapability.USB.USBManager
96
97**Parameters**
98
99| Name| Type| Mandatory| Description|
100| -------- | -------- | -------- | ---------------- |
101| device | [USBDevice](#usbdevice) | Yes| USB device. The **busNum** and **devAddress** parameters obtained by **getDevices** are used to determine a USB device. Other parameters are passed transparently.|
102
103**Return value**
104
105| Type| Description|
106| -------- | -------- |
107| Readonly&lt;[USBDevicePipe](#usbdevicepipe)&gt; | USB device pipe for data transfer.|
108
109**Error codes**
110
111For details about the error codes, see [USB Service Error Codes](errorcode-usb.md).
112
113| ID| Error Message                                                    |
114| -------- | ------------------------------------------------------------ |
115| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
116| 14400001 | Access right denied. Call requestRight to get the USBDevicePipe access right first.|
117
118**Example**
119
120```ts
121let devicesList: Array<usbManager.USBDevice> = usbManager.getDevices();
122if (devicesList.length == 0) {
123  console.log(`device list is empty`);
124}
125
126let device: usbManager.USBDevice = devicesList[0];
127usbManager.requestRight(device.name);
128let devicepipe: usbManager.USBDevicePipe = usbManager.connectDevice(device);
129console.log(`devicepipe = ${devicepipe}`);
130```
131
132## usbManager.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, which can be obtained from the device list returned by **getDevices**.|
147
148**Error codes**
149
150For details about the error codes, see [USB Service Error Codes](errorcode-usb.md).
151
152| ID| Error Message                                                    |
153| -------- | ------------------------------------------------------------ |
154| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
155
156**Return value**
157
158| Type| Description|
159| -------- | -------- |
160| boolean | Returns **true** if the application has the permission to access the device; returns **false** otherwise.|
161
162**Example**
163
164```ts
165let devicesList: Array<usbManager.USBDevice> = usbManager.getDevices();
166if (devicesList.length == 0) {
167  console.log(`device list is empty`);
168}
169
170let device: usbManager.USBDevice = devicesList[0];
171usbManager.requestRight(device.name);
172let right: boolean = usbManager.hasRight(device.name);
173console.log(`${right}`);
174```
175
176## usbManager.requestRight
177
178requestRight(deviceName: string): Promise&lt;boolean&gt;
179
180Requests the temporary device access permission for the application. This API uses a promise to return the result. System applications are granted the device access permission by default, and you do not need to apply for the permission separately.
181
182**System capability**: SystemCapability.USB.USBManager
183
184**Parameters**
185
186| Name| Type| Mandatory| Description|
187| -------- | -------- | -------- | -------- |
188| deviceName | string | Yes| Device name, which can be obtained from the device list returned by **getDevices**.|
189
190**Error codes**
191
192For details about the error codes, see [USB Service Error Codes](errorcode-usb.md).
193
194| ID| Error Message                                                    |
195| -------- | ------------------------------------------------------------ |
196| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
197
198**Return value**
199
200| Type| Description|
201| -------- | -------- |
202| Promise&lt;boolean&gt; | 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.|
203
204**Example**
205
206```ts
207let devicesList: Array<usbManager.USBDevice> = usbManager.getDevices();
208if (devicesList.length == 0) {
209  console.log(`device list is empty`);
210}
211
212let device: usbManager.USBDevice = devicesList[0];
213usbManager.requestRight(device.name).then(ret => {
214  console.log(`requestRight = ${ret}`);
215});
216```
217
218## usbManager.removeRight
219
220removeRight(deviceName: string): boolean
221
222Removes the device access permission for the application. System applications are granted the device access permission by default, and calling this API will not revoke the permission.
223
224**System capability**: SystemCapability.USB.USBManager
225
226**Parameters**
227
228| Name| Type| Mandatory| Description|
229| -------- | -------- | -------- | -------- |
230| deviceName | string | Yes| Device name, which can be obtained from the device list returned by **getDevices**.|
231
232**Error codes**
233
234For details about the error codes, see [USB Service Error Codes](errorcode-usb.md).
235
236| ID| Error Message                                                    |
237| -------- | ------------------------------------------------------------ |
238| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
239
240**Return value**
241
242| Type| Description|
243| -------- | -------- |
244| boolean | Permission removal result. The value **true** indicates that the access permission is removed successfully; and the value **false** indicates the opposite.|
245
246**Example**
247
248```ts
249let devicesList: Array<usbManager.USBDevice> = usbManager.getDevices();
250if (devicesList.length == 0) {
251  console.log(`device list is empty`);
252}
253
254let device: usbManager.USBDevice = devicesList[0];
255if (usbManager.removeRight(device.name)) {
256  console.log(`Succeed in removing right`);
257}
258```
259
260## usbManager.claimInterface
261
262claimInterface(pipe: USBDevicePipe, iface: USBInterface, force ?: boolean): number
263
264Claims a USB interface.
265
2661. Call [usbManager.getDevices](#usbmanagergetdevices) to obtain the USB device list and USB interfaces.
2672. Call [usbManager.requestRight](#usbmanagerrequestright) to request the device access permission.
2683. Call [usbManager.connectDevice](#usbmanagerconnectdevice) to obtain **devicepipe** as an input parameter.
269
270**System capability**: SystemCapability.USB.USBManager
271
272**Parameters**
273
274| Name| Type| Mandatory| Description|
275| -------- | -------- | -------- | -------- |
276| pipe | [USBDevicePipe](#usbdevicepipe) | Yes| USB device pipe, which is used to determine the bus number and device address. You need to call **connectDevice** to obtain its value.|
277| iface | [USBInterface](#usbinterface) | Yes| USB interface. You can use **getDevices** to obtain device information and identify the USB interface based on its ID.|
278| force | boolean | No| Whether to forcibly claim a USB interface. The default value is **false**, which means not to forcibly claim a USB interface. You can set the value as required.|
279
280**Error codes**
281
282For details about the error codes, see [USB Service Error Codes](errorcode-usb.md).
283
284| ID| Error Message                                                    |
285| -------- | ------------------------------------------------------------ |
286| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
287
288**Return value**
289
290| Type| Description|
291| -------- | -------- |
292| number | Returns **0** if the USB interface is successfully claimed; returns an error code otherwise.|
293
294**Example**
295
296```ts
297let devicesList: Array<usbManager.USBDevice> = usbManager.getDevices();
298if (devicesList.length == 0) {
299  console.log(`device list is empty`);
300}
301
302let device: usbManager.USBDevice = devicesList[0];
303usbManager.requestRight(device.name);
304let devicepipe: usbManager.USBDevicePipe = usbManager.connectDevice(device);
305let interfaces: usbManager.USBInterface = device.configs[0].interfaces[0];
306let ret: number= usbManager.claimInterface(devicepipe, interfaces);
307console.log(`claimInterface = ${ret}`);
308```
309
310## usbManager.releaseInterface
311
312releaseInterface(pipe: USBDevicePipe, iface: USBInterface): number
313
314Releases a USB interface.
315
316Before you do this, ensure that you have claimed the interface by calling [usbManager.claimInterface](#usbmanagerclaiminterface).
317
318**System capability**: SystemCapability.USB.USBManager
319
320**Parameters**
321
322| Name| Type| Mandatory| Description|
323| -------- | -------- | -------- | -------- |
324| pipe | [USBDevicePipe](#usbdevicepipe) | Yes| USB device pipe, which is used to determine the bus number and device address. You need to call **connectDevice** to obtain its value.|
325| iface | [USBInterface](#usbinterface) | Yes| USB interface. You can use **getDevices** to obtain device information and identify the USB interface based on its ID.|
326
327**Error codes**
328
329For details about the error codes, see [USB Service Error Codes](errorcode-usb.md).
330
331| ID| Error Message                                                    |
332| -------- | ------------------------------------------------------------ |
333| 401      | Parameter error.Possible causes:1.Mandatory parameters are left unspecified.2.Incorrect parameter types. |
334
335**Return value**
336
337| Type| Description|
338| -------- | -------- |
339| number | Returns **0** if the USB interface is successfully released; returns an error code otherwise.|
340
341**Example**
342
343```ts
344let devicesList: Array<usbManager.USBDevice> = usbManager.getDevices();
345if (devicesList.length == 0) {
346  console.log(`device list is empty`);
347}
348
349let device: usbManager.USBDevice = devicesList[0];
350usbManager.requestRight(device.name);
351let devicepipe: usbManager.USBDevicePipe = usbManager.connectDevice(device);
352let interfaces: usbManager.USBInterface = device.configs[0].interfaces[0];
353let ret: number = usbManager.claimInterface(devicepipe, interfaces);
354ret = usbManager.releaseInterface(devicepipe, interfaces);
355console.log(`releaseInterface = ${ret}`);
356```
357
358## usbManager.setConfiguration
359
360setConfiguration(pipe: USBDevicePipe, config: USBConfiguration): number
361
362Sets the device configuration.
363
3641. Call [usbManager.getDevices](#usbmanagergetdevices) to obtain the USB device list and device configuration.
3652. Call [usbManager.requestRight](#usbmanagerrequestright) to request the device access permission.
3663. Call [usbManager.connectDevice](#usbmanagerconnectdevice) to obtain **devicepipe** as an input parameter.
367
368**System capability**: SystemCapability.USB.USBManager
369
370**Parameters**
371
372| Name| Type| Mandatory| Description|
373| -------- | -------- | -------- | -------- |
374| pipe | [USBDevicePipe](#usbdevicepipe) | Yes| USB device pipe, which is used to determine the bus number and device address. You need to call **connectDevice** to obtain its value.|
375| config | [USBConfiguration](#usbconfiguration) | Yes| USB configuration. You can use **getDevices** to obtain device information and identify the USB configuration based on the ID.|
376
377**Error codes**
378
379For details about the error codes, see [USB Service Error Codes](errorcode-usb.md).
380
381| ID| Error Message                                                    |
382| -------- | ------------------------------------------------------------ |
383| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
384
385**Return value**
386
387| Type| Description|
388| -------- | -------- |
389| number | Returns **0** if the USB configuration is successfully set; returns an error code otherwise.|
390
391**Example**
392
393```ts
394let devicesList: Array<usbManager.USBDevice> = usbManager.getDevices();
395if (devicesList.length == 0) {
396  console.log(`device list is empty`);
397}
398
399let device: usbManager.USBDevice = devicesList[0];
400usbManager.requestRight(device.name);
401let devicepipe: usbManager.USBDevicePipe = usbManager.connectDevice(device);
402let config: usbManager.USBConfiguration = device.configs[0];
403let ret: number= usbManager.setConfiguration(devicepipe, config);
404console.log(`setConfiguration = ${ret}`);
405```
406
407## usbManager.setInterface
408
409setInterface(pipe: USBDevicePipe, iface: USBInterface): number
410
411Sets a USB interface.
412
413Before you do this, call [usbManager.getDevices](#usbmanagergetdevices) to obtain the USB device list and interfaces, call [usbManager.requestRight](#usbmanagerrequestright) to request the device access permission, call [usbManager.connectDevice](#usbmanagerconnectdevice) to obtain **devicepipe** as an input parameter, and call [usbManager.claimInterface](#usbmanagerclaiminterface) to claim a USB interface.
414
415**System capability**: SystemCapability.USB.USBManager
416
417**Parameters**
418
419| Name| Type| Mandatory| Description|
420| -------- | -------- | -------- | -------- |
421| pipe | [USBDevicePipe](#usbdevicepipe) | Yes| USB device pipe, which is used to determine the bus number and device address. You need to call **connectDevice** to obtain its value.|
422| iface | [USBInterface](#usbinterface)   | Yes| USB interface. You can use **getDevices** to obtain device information and identify the USB interface based on its **id** and **alternateSetting**.|
423
424**Error codes**
425
426For details about the error codes, see [USB Service Error Codes](errorcode-usb.md).
427
428| ID| Error Message                                                    |
429| -------- | ------------------------------------------------------------ |
430| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
431
432**Return value**
433
434| Type| Description|
435| -------- | -------- |
436| number | Returns **0** if the USB interface is successfully set; returns an error code otherwise.|
437
438**Example**
439
440```ts
441let devicesList: Array<usbManager.USBDevice> = usbManager.getDevices();
442if (devicesList.length == 0) {
443  console.log(`device list is empty`);
444}
445
446let device: usbManager.USBDevice = devicesList[0];
447usbManager.requestRight(device.name);
448let devicepipe: usbManager.USBDevicePipe = usbManager.connectDevice(device);
449let interfaces: usbManager.USBInterface = device.configs[0].interfaces[0];
450let ret: number = usbManager.claimInterface(devicepipe, interfaces);
451ret = usbManager.setInterface(devicepipe, interfaces);
452console.log(`setInterface = ${ret}`);
453```
454
455## usbManager.getRawDescriptor
456
457getRawDescriptor(pipe: USBDevicePipe): Uint8Array
458
459Obtains the raw USB descriptor.
460
461Before you do this, call [usbManager.getDevices](#usbmanagergetdevices) to obtain the USB device list, call [usbManager.requestRight](#usbmanagerrequestright) to request the device access permission, and call [usbManager.connectDevice](#usbmanagerconnectdevice) to obtain **devicepipe** as an input parameter.
462
463**System capability**: SystemCapability.USB.USBManager
464
465**Parameters**
466
467| Name| Type| Mandatory| Description|
468| -------- | -------- | -------- | -------- |
469| pipe | [USBDevicePipe](#usbdevicepipe) | Yes| USB device pipe, which is used to determine the bus number and device address. You need to call **connectDevice** to obtain its value.|
470
471**Error codes**
472
473For details about the error codes, see [USB Service Error Codes](errorcode-usb.md).
474
475| ID| Error Message                                                    |
476| -------- | ------------------------------------------------------------ |
477| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
478
479**Return value**
480
481| Type| Description|
482| -------- | -------- |
483| Uint8Array | Returns the raw USB descriptor if the operation is successful; returns **undefined** otherwise.|
484
485**Example**
486
487```ts
488let devicesList: Array<usbManager.USBDevice> = usbManager.getDevices();
489if (devicesList.length == 0) {
490  console.log(`device list is empty`);
491}
492
493usbManager.requestRight(devicesList[0].name);
494let devicepipe: usbManager.USBDevicePipe = usbManager.connectDevice(devicesList[0]);
495let ret: Uint8Array = usbManager.getRawDescriptor(devicepipe);
496```
497
498## usbManager.getFileDescriptor
499
500getFileDescriptor(pipe: USBDevicePipe): number
501
502Obtains the file descriptor.
503
504Before you do this, call [usbManager.getDevices](#usbmanagergetdevices) to obtain the USB device list, call [usbManager.requestRight](#usbmanagerrequestright) to request the device access permission, and call [usbManager.connectDevice](#usbmanagerconnectdevice) to obtain **devicepipe** as an input parameter.
505
506**System capability**: SystemCapability.USB.USBManager
507
508**Parameters**
509
510| Name| Type| Mandatory| Description|
511| -------- | -------- | -------- | -------- |
512| pipe | [USBDevicePipe](#usbdevicepipe) | Yes| USB device pipe, which is used to determine the bus number and device address. You need to call **connectDevice** to obtain its value.|
513
514**Error codes**
515
516For details about the error codes, see [USB Service Error Codes](errorcode-usb.md).
517
518| ID| Error Message                                                    |
519| -------- | ------------------------------------------------------------ |
520| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
521
522**Return value**
523
524| Type    | Description                  |
525| ------ | -------------------- |
526| number | Returns the file descriptor of the USB device if the operation is successful; returns **-1** otherwise.|
527
528**Example**
529
530```ts
531let devicesList: Array<usbManager.USBDevice> = usbManager.getDevices();
532if (devicesList.length == 0) {
533  console.log(`device list is empty`);
534}
535
536usbManager.requestRight(devicesList[0].name);
537let devicepipe: usbManager.USBDevicePipe = usbManager.connectDevice(devicesList[0]);
538let ret: number = usbManager.getFileDescriptor(devicepipe);
539```
540
541## usbManager.controlTransfer<sup>(deprecated)</sup>
542
543controlTransfer(pipe: USBDevicePipe, controlparam: USBControlParams, timeout ?: number): Promise&lt;number&gt;
544
545Performs control transfer.
546
547Before you do this, call [usbManager.getDevices](#usbmanagergetdevices) to obtain the USB device list, call [usbManager.requestRight](#usbmanagerrequestright) to request the device access permission, and call [usbManager.connectDevice](#usbmanagerconnectdevice) to obtain **devicepipe** as an input parameter.
548
549**NOTE**
550
551> This API is supported since API version 9 and deprecated since API version 12. You are advised to use [usbControlTransfer](#usbmanagerusbcontroltransfer12).
552
553**System capability**: SystemCapability.USB.USBManager
554
555**Parameters**
556
557| Name| Type| Mandatory| Description|
558| -------- | -------- | -------- | -------- |
559| pipe | [USBDevicePipe](#usbdevicepipe) | Yes| USB device pipe. You need to call **connectDevice** to obtain its value.|
560| controlparam | [USBControlParams](#usbcontrolparamsdeprecated) | Yes| Control transfer parameters. Set the parameters as required. For details, see the USB protocol.|
561| timeout | number | No| (Optional) Timeout duration, in ms. The default value is **0**. You can set this parameter as required.|
562
563**Error codes**
564
565For details about the error codes, see [USB Service Error Codes](errorcode-usb.md).
566
567| ID| Error Message                                                    |
568| -------- | ------------------------------------------------------------ |
569| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
570
571**Return value**
572
573| Type| Description|
574| -------- | -------- |
575| Promise&lt;number&gt; | 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.|
576
577**Example**
578
579```ts
580class PARA {
581  request: number = 0
582  reqType: usbManager.USBControlRequestType = 0
583  target: usbManager.USBRequestTargetType = 0
584  value: number = 0
585  index: number = 0
586  data: Uint8Array = new Uint8Array()
587}
588
589let param: PARA = {
590  request: 0x06,
591  reqType: 0x80,
592  target:0,
593  value: 0x01 << 8 | 0,
594  index: 0,
595  data: new Uint8Array(18)
596};
597
598let devicesList: Array<usbManager.USBDevice> = usbManager.getDevices();
599if (devicesList.length == 0) {
600  console.log(`device list is empty`);
601}
602
603usbManager.requestRight(devicesList[0].name);
604let devicepipe: usbManager.USBDevicePipe = usbManager.connectDevice(devicesList[0]);
605usbManager.controlTransfer(devicepipe, param).then((ret: number) => {
606console.log(`controlTransfer = ${ret}`);
607})
608```
609
610## usbManager.usbControlTransfer<sup>12+</sup>
611
612usbControlTransfer(pipe: USBDevicePipe, requestparam: USBDeviceRequestParams, timeout ?: number): Promise&lt;number&gt;
613
614Performs control transfer.
615
616Before you do this, call [usbManager.getDevices](#usbmanagergetdevices) to obtain the USB device list, call [usbManager.requestRight](#usbmanagerrequestright) to request the device access permission, and call [usbManager.connectDevice](#usbmanagerconnectdevice) to obtain **devicepipe** as an input parameter.
617
618**System capability**: SystemCapability.USB.USBManager
619
620**Parameters**
621
622| Name| Type| Mandatory| Description|
623| -------- | -------- | -------- | -------- |
624| pipe | [USBDevicePipe](#usbdevicepipe) | Yes| USB device pipe, which is used to determine the USB device.|
625| requestparam | [USBDeviceRequestParams](#usbdevicerequestparams12) | Yes| Control transfer parameters. Set the parameters as required. For details, see the USB protocol.|
626| timeout | number | No| (Optional) Timeout duration, in ms. The default value is **0**, indicating no timeout.|
627
628**Error codes**
629
630For details about the error codes, see [USB Service Error Codes](errorcode-usb.md).
631
632| ID| Error Message                                                    |
633| -------- | ------------------------------------------------------------ |
634| 401      | Parameter error.Possible causes:1.Mandatory parameters are left unspecified.2.Incorrect parameter types. |
635
636**Return value**
637
638| Type| Description|
639| -------- | -------- |
640| Promise&lt;number&gt; | 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.|
641
642**Example**
643
644```ts
645class PARA {
646  bmRequestType: number = 0
647  bRequest: number = 0
648  wValue: number = 0
649  wIndex: number = 0
650  wLength: number = 0
651  data: Uint8Array = new Uint8Array()
652}
653
654let param: PARA = {
655  bmRequestType: 0x80,
656  bRequest: 0x06,
657
658  wValue:0x01 << 8 | 0,
659  wIndex: 0,
660  wLength: 18,
661  data: new Uint8Array(18)
662};
663
664let devicesList: Array<usbManager.USBDevice> = usbManager.getDevices();
665if (devicesList.length == 0) {
666  console.log(`device list is empty`);
667}
668
669usbManager.requestRight(devicesList[0].name);
670let devicepipe: usbManager.USBDevicePipe = usbManager.connectDevice(devicesList[0]);
671usbManager.usbControlTransfer(devicepipe, param).then((ret: number) => {
672console.log(`usbControlTransfer = ${ret}`);
673})
674```
675
676## usbManager.bulkTransfer
677
678bulkTransfer(pipe: USBDevicePipe, endpoint: USBEndpoint, buffer: Uint8Array, timeout ?: number): Promise&lt;number&gt;
679
680Performs bulk transfer.
681
6821. Call [usbManager.getDevices](#usbmanagergetdevices) to obtain the USB device list and endpoints.
6832. Call [usbManager.requestRight](#usbmanagerrequestright) to request the device access permission.
6843. Call [usbManager.connectDevice](#usbmanagerconnectdevice) to obtain **devicepipe** as an input parameter.
6854. Obtain [usbManager.claimInterface](#usbmanagerclaiminterface).
6865. Call **usbManager.bulkTransfer** to claim a USB interface.
687
688> **NOTE**
689>
690> The total amount of data (including **pipe**, **endpoint**, **buffer**, and **timeout**) transferred in bulk must be less than 200 KB.
691
692**System capability**: SystemCapability.USB.USBManager
693
694**Parameters**
695
696| Name| Type| Mandatory| Description|
697| -------- | -------- | -------- | -------- |
698| pipe | [USBDevicePipe](#usbdevicepipe) | Yes| USB device pipe. You need to call **connectDevice** to obtain its value.|
699| endpoint | [USBEndpoint](#usbendpoint) | Yes| USB endpoint, which is used to determine the USB interface for data transfer. You need to call **getDevices** to obtain the device information list and endpoint. Wherein, **address** is used to determine the endpoint address, **direction** is used to determine the endpoint direction, and **interfaceId** is used to determine the USB interface to which the endpoint belongs. Other parameters are passed transparently.|
700| buffer | Uint8Array | Yes| Buffer used to write or read data.|
701| timeout | number | No| (Optional) Timeout duration, in ms. The default value is **0**. You can set this parameter as required.|
702
703**Error codes**
704
705For details about the error codes, see [USB Service Error Codes](errorcode-usb.md).
706
707| ID| Error Message                                                    |
708| -------- | ------------------------------------------------------------ |
709| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
710
711**Return value**
712
713| Type| Description|
714| -------- | -------- |
715| Promise&lt;number&gt; | 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.|
716
717**Example**
718
719> **NOTE**
720>
721> The following sample code is only a basic process for calling the **bulkTransfer** API. In actual calling, you must comply with the device-related protocols to ensure correct data transfer and device compatibility.
722
723```ts
724// Call usbManager.getDevices to obtain a data set. Then, obtain a USB device and its access permission.
725// Pass the obtained USB device as a parameter to usbManager.connectDevice. Then, call usbManager.connectDevice to connect the USB device.
726// Call usbManager.claimInterface to claim a USB interface. After that, call usbManager.bulkTransfer to start bulk transfer.
727let devicesList: Array<usbManager.USBDevice> = usbManager.getDevices();
728if (devicesList.length == 0) {
729  console.log(`device list is empty`);
730}
731
732let device: usbManager.USBDevice = devicesList[0];
733usbManager.requestRight(device.name);
734
735let devicepipe: usbManager.USBDevicePipe = usbManager.connectDevice(device);
736for (let i = 0; i < device.configs[0].interfaces.length; i++) {
737  if (device.configs[0].interfaces[i].endpoints[0].attributes == 2) {
738    let endpoint: usbManager.USBEndpoint = device.configs[0].interfaces[i].endpoints[0];
739    let interfaces: usbManager.USBInterface = device.configs[0].interfaces[i];
740    let ret: number = usbManager.claimInterface(devicepipe, interfaces);
741    let buffer =  new Uint8Array(128);
742    usbManager.bulkTransfer(devicepipe, endpoint, buffer).then((ret: number) => {
743      console.log(`bulkTransfer = ${ret}`);
744    });
745  }
746}
747```
748
749## usbManager.usbSubmitTransfer<sup>16+</sup>
750
751usbSubmitTransfer(transfer: USBDataTransferParams): void
752
753Requests a USB data transfer.
754
755This API uses an asynchronous callback to return the result.
756
7571. Call [usbManager.getDevices](#usbmanagergetdevices) to obtain the USB device list and endpoints.
7582. Call [usbManager.requestRight](#usbmanagerrequestright) to request the device access permission.
7593. Call [usbManager.connectDevice](#usbmanagerconnectdevice) to obtain **devicepipe** as an input parameter.
7604. Obtain [usbManager.claimInterface](#usbmanagerclaiminterface).
7615. Call usbManager.usbSubmitTransfer to request a data transfer.
762
763**System capability**: SystemCapability.USB.USBManager
764
765**Parameters**
766
767| Name| Type| Mandatory| Description|
768| -------- | -------- | -------- | -------- |
769| transfer | [UsbDataTransferParams](#usbdatatransferparams16) | Yes| As a USB data transfer interface, it is required for a client to initiate a transfer request.|
770
771**Error codes**
772
773For details about the error codes, see [USB Service Error Codes](errorcode-usb.md).
774
775| ID| Error Message                                                    |
776| -------- | ------------------------------------------------------------ |
777| 401 | Parameter error. Possible causes:Mandatory parameters are left unspecified; Incorrect parameter types. |
778| 14400001 | Access right denied. Call requestRight to get the USBDevicePipe access right first. |
779| 14400007 | Resource busy. |
780| 14400008 | No such device (it may have been disconnected). |
781| 14400009 | Insufficient memory. |
782| 14400012 | Transmission I/O error. |
783
784**Example**
785
786> **NOTE**
787>
788> The following sample code is only a basic process for calling the **usbSubmitTransfer** API. In actual calling, you must comply with the device-related protocols to ensure correct data transfer and device compatibility.
789
790```ts
791// Call usbManager.getDevices to obtain a data set. Then, obtain a USB device and its access permission.
792// Pass the obtained USB device as a parameter to usbManager.connectDevice. Then, call usbManager.connectDevice to connect the USB device.
793// Call usbManager.claimInterface to claim a USB interface. After that, call usbManager.bulkTransfer to start bulk transfer.
794let devicesList: Array<usbManager.USBDevice> = usbManager.getDevices();
795if (devicesList.length == 0) {
796  console.log(`device list is empty`);
797  return;
798}
799let device: usbManager.USBDevice = devicesList[0];
800usbManager.requestRight(device.name);
801let devicepipe: usbManager.USBDevicePipe = usbManager.connectDevice(device);
802// Obtain the endpoint address.
803let endpoint = device.configs[0].interfaces[0]?.endpoints.find((value) => {
804  return value.direction === 0 && value.type === 2
805})
806// Obtain the first ID of the device.
807let ret: number = usbManager.claimInterface(devicepipe, device.configs[0].interfaces[0], true);
808
809const transferParams = {
810  devPipe: devicepipe,
811  flags: 0,
812  endpoint: 1,
813  type: 2,
814  timeout: 2000,
815  length: 10,
816  callback: () => {},
817  userData: new Uint8Array(10),
818  buffer: new Uint8Array(10),
819  isoPacketCount: 0,
820};
821try {
822  transferParams.endpoint=endpoint?.address as number;
823  transferParams.callback=(err, callBackData: usbManager.SubmitTransferCallback)=>{
824    console.info('callBackData =' +JSON.stringify(callBackData));
825  }
826  usbManager.usbSubmitTransfer(transferParams);
827  console.info('USB transfer request submitted.');
828} catch (error) {
829  console.error('USB transfer failed:', error);
830}
831```
832
833
834## usbManager.usbCancelTransfer<sup>16+</sup>
835
836usbCancelTransfer(transfer: USBDataTransferParams): void;
837
838Cancels an asynchronous USB data transfer request.
839
8401. Call [usbManager.getDevices](#usbmanagergetdevices) to obtain the USB device list and endpoints.
8412. Call [usbManager.requestRight](#usbmanagerrequestright) to request the device access permission.
8423. Call [usbManager.connectDevice](#usbmanagerconnectdevice) to obtain **devicepipe** as an input parameter.
8434. Obtain [usbManager.claimInterface](#usbmanagerclaiminterface).
8445. Call **usbManager.usbCancelTransfer** to cancel the request.
845
846**System capability**: SystemCapability.USB.USBManager
847
848**Parameters**
849
850| Name| Type| Mandatory| Description|
851| -------- | -------- | -------- | -------- |
852| transfer | [UsbDataTransferParams](#usbdatatransferparams16) | Yes| Only **USBDevicePipe** and **endpoint** are required for canceling the transfer.|
853
854**Error codes**
855
856For details about the error codes, see [USB Service Error Codes](errorcode-usb.md).
857
858| ID| Error Message                                                    |
859| -------- | ------------------------------------------------------------ |
860| 401 | Parameter error. Possible causes:Mandatory parameters are left unspecified; Incorrect parameter types. |
861| 14400001 | Access right denied. Call requestRight to get the USBDevicePipe access right first. |
862| 14400008 | No such device (it may have been disconnected). |
863| 14400010 | Other USB error. Possible causes:<br>1.Unrecognized discard error code. |
864| 14400011 | The transfer is not in progress, or is already complete or cancelled.|
865
866**Return value**
867
868| Type| Description|
869| -------- | -------- |
870| &lt;void&gt; | None.|
871
872**Example**
873
874> **NOTE**
875>
876> The following sample code is only a basic process for calling the **usbCancelTransfer** API. In actual calling, you must comply with the device-related protocols to ensure correct data transfer and device compatibility.
877
878```ts
879// Call usbManager.getDevices to obtain a data set. Then, obtain a USB device and its access permission.
880// Pass the obtained USB device as a parameter to usbManager.connectDevice. Then, call usbManager.connectDevice to connect the USB device.
881// Call usbManager.claimInterface to claim a USB interface. After that, call usbManager.bulkTransfer to start bulk transfer.
882let devicesList: Array<usbManager.USBDevice> = usbManager.getDevices();
883if (devicesList.length == 0) {
884  console.log(`device list is empty`);
885  return;
886}
887let device: usbManager.USBDevice = devicesList[0];
888usbManager.requestRight(device.name);
889let devicepipe: usbManager.USBDevicePipe = usbManager.connectDevice(device);
890// Obtain the endpoint address.
891let endpoint = device.configs[0].interfaces[0]?.endpoints.find((value) => {
892  return value.direction === 0 && value.type === 2
893})
894// Obtain the first ID of the device.
895let ret: number = usbManager.claimInterface(devicepipe, device.configs[0].interfaces[0], true);
896const transferParams = {
897  devPipe: devicepipe,
898  flags: 0,
899  endpoint: 1,
900  type: 2,
901  timeout: 2000,
902  length: 10,
903  callback: () => {},
904  userData: new Uint8Array(10),
905  buffer: new Uint8Array(10),
906  isoPacketCount: 0,
907};
908try {
909  transferParams.endpoint=endpoint?.address as number;
910  transferParams.callback=(err, callBackData: usbManager.SubmitTransferCallback)=>{
911    console.info('callBackData =' +JSON.stringify(callBackData));
912  }
913  usbManager.usbSubmitTransfer(transferParams);
914  usbManager.UsbCancelTransfer(transferParams);
915  console.info('USB transfer request submitted.');
916} catch (error) {
917  console.error('USB transfer failed:', error);
918}
919```
920
921## usbManager.closePipe
922
923closePipe(pipe: USBDevicePipe): number
924
925Closes a USB device pipe.
926
927Before you do this, call [usbManager.getDevices](#usbmanagergetdevices) to obtain the USB device list, call [usbManager.requestRight](#usbmanagerrequestright) to request the device access permission, and call [usbManager.connectDevice](#usbmanagerconnectdevice) to obtain **devicepipe** as an input parameter.
928
929**System capability**: SystemCapability.USB.USBManager
930
931**Parameters**
932
933| Name| Type| Mandatory| Description|
934| -------- | -------- | -------- | -------- |
935| pipe | [USBDevicePipe](#usbdevicepipe) | Yes| USB device pipe, which is used to determine the message control channel. You need to call **connectDevice** to obtain its value.|
936
937**Error codes**
938
939For details about the error codes, see [USB Service Error Codes](errorcode-usb.md).
940
941| ID| Error Message                                                    |
942| -------- | ------------------------------------------------------------ |
943| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
944
945**Return value**
946
947| Type| Description|
948| -------- | -------- |
949| number | Returns **0** if the USB device pipe is closed successfully; returns an error code otherwise.|
950
951**Example**
952
953```ts
954let devicesList: Array<usbManager.USBDevice> = usbManager.getDevices();
955if (devicesList.length == 0) {
956  console.log(`device list is empty`);
957}
958
959usbManager.requestRight(devicesList[0].name);
960let devicepipe: usbManager.USBDevicePipe = usbManager.connectDevice(devicesList[0]);
961let ret: number = usbManager.closePipe(devicepipe);
962console.log(`closePipe = ${ret}`);
963```
964
965## usbManager.hasAccessoryRight<sup>14+</sup>
966
967hasAccessoryRight(accessory: USBAccessory): boolean
968
969Checks whether the application has the permission to access the USB accessory.
970
971You need to call [usbManager.getAccessoryList](#usbmanagergetaccessorylist14) to obtain the accessory list and use [USBAccessory](#usbaccessory14) as a parameter.
972
973**System capability**: SystemCapability.USB.USBManager
974
975**Parameters**
976
977| Name   | Type        | Mandatory| Description                                 |
978| --------- | ------------ | ---- | ------------------------------------- |
979| accessory | [USBAccessory](#usbaccessory14) | Yes  | USB accessory.|
980
981**Error codes**
982
983For details about the error codes, see [USB Service Error Codes](errorcode-usb.md).
984
985| ID| Error Message                                                    |
986| -------- | ------------------------------------------------------------ |
987| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
988| 14400004 | Service exception. Possible causes: 1. No accessory is plugged in. |
989| 14400005 | Database operation exception.                                |
990| 14401001 | The target USBAccessory not matched.                         |
991
992**Return value**
993
994| Type   | Description                         |
995| ------- | ----------------------------- |
996| boolean | The value **true** indicates that the application has the permission to access the USB accessory; **false** indicates the opposite.|
997
998**Example**
999
1000```ts
1001import { hilog } from '@kit.PerformanceAnalysisKit';
1002try {
1003  let accList: usbManager.USBAccessory[] = usbManager.getAccessoryList()
1004  let flag = usbManager.hasAccessoryRight(accList[0])
1005  hilog.info(0, 'testTag ui', `hasAccessoryRight success, ret:${flag}`)
1006} catch (error) {
1007  hilog.info(0, 'testTag ui', `hasAccessoryRight error ${error.code}, message is ${error.message}`)
1008}
1009```
1010
1011## usbManager.requestAccessoryRight<sup>14+</sup>
1012
1013requestAccessoryRight(accessory: USBAccessory): Promise&lt;boolean&gt;
1014
1015Requests the permission to access a USB accessory for a specified application.
1016
1017You need to call [usbManager.getAccessoryList](#usbmanagergetaccessorylist14) to obtain the accessory list and use [USBAccessory](#usbaccessory14) as a parameter.
1018
1019**System capability**: SystemCapability.USB.USBManager
1020
1021**Parameters**
1022
1023| Name   | Type        | Mandatory| Description                                 |
1024| --------- | ------------ | ---- | ------------------------------------- |
1025| accessory | [USBAccessory](#usbaccessory14) | Yes  | USB accessory.|
1026
1027**Error codes**
1028
1029For details about the error codes, see [USB Service Error Codes](errorcode-usb.md).
1030
1031| ID| Error Message                                                    |
1032| -------- | ------------------------------------------------------------ |
1033| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
1034| 14400004 | Service exception. Possible causes: 1. No accessory is plugged in. |
1035| 14400005 | Database operation exception.                                |
1036| 14401001 | The target USBAccessory not matched.                         |
1037
1038**Return value**
1039
1040| Type            | Description                         |
1041| ---------------- | ----------------------------- |
1042| Promise&lt;boolean&gt; | Promise used to return the application result. The value **true** indicates that the permission application is successful; **false** indicates the opposite.|
1043
1044**Example**
1045
1046```ts
1047import { hilog } from '@kit.PerformanceAnalysisKit';
1048try {
1049  let accList: usbManager.USBAccessory[] = usbManager.getAccessoryList()
1050  let flag = usbManager.requestAccessoryRight(accList[0])
1051  hilog.info(0, 'testTag ui', `requestAccessoryRight success, ret:${flag}`)
1052} catch (error) {
1053  hilog.info(0, 'testTag ui', `requestAccessoryRight error ${error.code}, message is ${error.message}`)
1054}
1055```
1056
1057## usbManager.cancelAccessoryRight<sup>14+</sup>
1058
1059cancelAccessoryRight(accessory: USBAccessory): void
1060
1061Cancels the permission of the current application to access USB accessories.
1062
1063You need to call [usbManager.getAccessoryList](#usbmanagergetaccessorylist14) to obtain the accessory list and use [USBAccessory](#usbaccessory14) as a parameter.
1064
1065**System capability**: SystemCapability.USB.USBManager
1066
1067**Parameters**
1068
1069| Name   | Type        | Mandatory| Description                                 |
1070| --------- | ------------ | ---- | ------------------------------------- |
1071| accessory | [USBAccessory](#usbaccessory14) | Yes  | USB accessory.|
1072
1073**Error codes**
1074
1075For details about the error codes, see [USB Service Error Codes](errorcode-usb.md).
1076
1077| ID| Error Message                                                    |
1078| -------- | ------------------------------------------------------------ |
1079| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
1080| 14400004 | Service exception. Possible causes: 1. No accessory is plugged in. |
1081| 14400005 | Database operation exception.                                |
1082| 14401001 | The target USBAccessory not matched.                         |
1083
1084**Example**
1085
1086```ts
1087import { hilog } from '@kit.PerformanceAnalysisKit';
1088try {
1089  let accList: usbManager.USBAccessory[] = usbManager.getAccessoryList()
1090  let flag = usbManager.requestAccessoryRight(accList[0])
1091  usbManager.cancelAccessoryRight(accList[0])
1092  hilog.info(0, 'testTag ui', `cancelAccessoryRight success`)
1093} catch (error) {
1094  hilog.info(0, 'testTag ui', `cancelAccessoryRight error ${error.code}, message is ${error.message}`)
1095}
1096```
1097
1098## usbManager.getAccessoryList<sup>14+</sup>
1099
1100getAccessoryList(): Array<Readonly&lt;USBAccessory&gt;>
1101
1102Obtains the list of USB accessories connected to the host.
1103
1104**System capability**: SystemCapability.USB.USBManager
1105
1106**Error codes**
1107
1108For details about the error codes, see [USB Service Error Codes](errorcode-usb.md).
1109
1110| ID| Error Message                                                    |
1111| -------- | ------------------------------------------------------------ |
1112| 14400004 | Service exception. Possible causes: 1. No accessory is plugged in. |
1113
1114**Return value**
1115
1116| Type                         | Description                                              |
1117| ----------------------------- | -------------------------------------------------- |
1118| Array<Readonly&lt;USBAccessory&gt;> | List of USB accessories (read-only). Currently, only one USB accessory is contained in the list.|
1119
1120**Example**
1121
1122```ts
1123import { hilog } from '@kit.PerformanceAnalysisKit';
1124try {
1125  let accList: usbManager.USBAccessory[] = usbManager.getAccessoryList()
1126  hilog.info(0, 'testTag ui', `getAccessoryList success, accList: ${JSON.stringify(accList)}`)
1127} catch (error) {
1128  hilog.info(0, 'testTag ui', `getAccessoryList error ${error.code}, message is ${error.message}`)
1129}
1130```
1131
1132## usbManager.openAccessory<sup>14+</sup>
1133
1134openAccessory(accessory: USBAccessory): USBAccessoryHandle
1135
1136Obtains the accessory handle and opens the accessory file descriptor.
1137
1138You need to call [usbManager.getAccessoryList](#usbmanagergetaccessorylist14) to obtain the accessory list and use [USBAccessory](#usbaccessory14) as a parameter.
1139
1140**System capability**: SystemCapability.USB.USBManager
1141
1142**Parameters**
1143
1144| Name   | Type        | Mandatory| Description                                 |
1145| --------- | ------------ | ---- | ------------------------------------- |
1146| accessory | [USBAccessory](#usbaccessory14) | Yes  | USB accessory.|
1147
1148**Error codes**
1149
1150For details about the error codes, see [USB Service Error Codes](errorcode-usb.md).
1151
1152| ID| Error Message                                                    |
1153| -------- | ------------------------------------------------------------ |
1154| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
1155| 14400001 | Permission denied. Call requestAccessoryRight to get the right first. |
1156| 14400004 | Service exception. Possible causes: 1. No accessory is plugged in. |
1157| 14401001 | The target USBAccessory not matched.                         |
1158| 14401002 | Failed to open the native accessory node.                    |
1159| 14401003 | Cannot reopen the accessory.                                 |
1160
1161**Return value**
1162
1163| Type              | Description       |
1164| ------------------ | ----------- |
1165| [USBAccessoryHandle](#usbaccessoryhandle14) | USB accessory handle.|
1166
1167**Example**
1168
1169```ts
1170import { hilog } from '@kit.PerformanceAnalysisKit';
1171try {
1172  let accList: usbManager.USBAccessory[] = usbManager.getAccessoryList()
1173  let flag = usbManager.requestAccessoryRight(accList[0])
1174  let handle = usbManager.openAccessory(accList[0])
1175  hilog.info(0, 'testTag ui', `openAccessory success`)
1176} catch (error) {
1177  hilog.info(0, 'testTag ui', `openAccessory error ${error.code}, message is ${error.message}`)
1178}
1179```
1180
1181## usbManager.closeAccessory<sup>14+</sup>
1182
1183closeAccessory(accessoryHandle: USBAccessoryHandle): void
1184
1185Closes the accessory file descriptor.
1186
1187You need to call [usbManager.openAccessory](#usbmanageropenaccessory14) to obtain the accessory list and use [USBAccessoryHandle](#usbaccessoryhandle14) as a parameter.
1188
1189**System capability**: SystemCapability.USB.USBManager
1190
1191**Parameters**
1192
1193| Name         | Type              | Mandatory| Description                                  |
1194| --------------- | ------------------ | ---- | -------------------------------------- |
1195| accessoryHandle | [USBAccessoryHandle](#usbaccessoryhandle14) | Yes  | USB accessory handle, obtained through [openAccessory](#usbmanageropenaccessory14).|
1196
1197**Error codes**
1198
1199For details about the error codes, see [USB Service Error Codes](errorcode-usb.md).
1200
1201| ID| Error Message                                                    |
1202| -------- | ------------------------------------------------------------ |
1203| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
1204| 14400004 | Service exception. Possible causes: 1. No accessory is plugged in. |
1205
1206**Example**
1207
1208```ts
1209import { hilog } from '@kit.PerformanceAnalysisKit';
1210try {
1211  let accList: usbManager.USBAccessory[] = usbManager.getAccessoryList()
1212  let flag = usbManager.requestAccessoryRight(accList[0])
1213  let handle = usbManager.openAccessory(accList[0])
1214  usbManager.closeAccessory(handle)
1215  hilog.info(0, 'testTag ui', `closeAccessory success`)
1216} catch (error) {
1217  hilog.info(0, 'testTag ui', `closeAccessory error ${error.code}, message is ${error.message}`)
1218}
1219```
1220
1221## USBEndpoint
1222
1223Represents the USB endpoint from which data is sent or received. You can obtain the USB endpoint through [USBInterface](#usbinterface).
1224
1225**System capability**: SystemCapability.USB.USBManager
1226
1227| Name           | Type                                       | Mandatory           |Description           |
1228| ------------- | ------------------------------------------- | ------------- |------------- |
1229| address       | number                                      | Yes|Endpoint address.        |
1230| attributes    | number                                      | Yes|Endpoint attributes.        |
1231| interval      | number                                      | Yes|Endpoint interval.        |
1232| maxPacketSize | number                                      | Yes|Maximum size of data packets on the endpoint.   |
1233| direction     | [USBRequestDirection](#usbrequestdirection) | Yes|Endpoint direction.       |
1234| number        | number                                      | Yes|Endpoint number.         |
1235| type          | number                                      | Yes|Endpoint type.        |
1236| interfaceId   | number                                      | Yes|Unique ID of the interface to which the endpoint belongs.|
1237
1238## USBInterface
1239
1240Represents a USB interface. One [USBConfiguration](#usbconfiguration) object can contain multiple **USBInterface** instances, each providing a specific function.
1241
1242**System capability**: SystemCapability.USB.USBManager
1243
1244| Name              | Type                                    | Mandatory           |Description                   |
1245| ---------------- | ---------------------------------------- | ------------- |--------------------- |
1246| id               | number                                   | Yes|Unique ID of the USB interface.             |
1247| protocol         | number                                   | Yes|Interface protocol.               |
1248| clazz            | number                                   | Yes|Device type.                |
1249| subClass         | number                                   | Yes|Device subclass.                |
1250| alternateSetting | number                                   | Yes|Settings for alternating between descriptors of the same USB interface.|
1251| name             | string                                   | Yes|Interface name.                |
1252| endpoints        | Array&lt;[USBEndpoint](#usbendpoint)&gt; | Yes|Endpoints that belong to the USB interface.          |
1253
1254## USBConfiguration
1255
1256Represents the USB configuration. One [USBDevice](#usbdevice) can contain multiple **USBConfig** instances.
1257
1258**System capability**: SystemCapability.USB.USBManager
1259
1260| Name            | Type                                            | Mandatory |Description             |
1261| -------------- | ------------------------------------------------ | --------------- |--------------- |
1262| id             | number                                           | Yes|Unique ID of the USB configuration.       |
1263| attributes     | number                                           | Yes|Configuration attributes.         |
1264| maxPower       | number                                           | Yes|Maximum power consumption, in mA.   |
1265| name           | string                                           | Yes|Configuration name, which can be left empty.    |
1266| isRemoteWakeup | boolean                                          | Yes|Support for remote wakeup.|
1267| isSelfPowered  | boolean                                          | Yes| Support for independent power supplies.|
1268| interfaces     | Array&nbsp;&lt;[USBInterface](#usbinterface)&gt; | Yes|Supported interface attributes.     |
1269
1270## USBDevice
1271
1272Represents the USB device information.
1273
1274**System capability**: SystemCapability.USB.USBManager
1275
1276| Name              | Type                                | Mandatory        |Description        |
1277| ---------------- | ------------------------------------ | ---------- |---------- |
1278| busNum           | number                               | Yes|Bus address.     |
1279| devAddress       | number                               | Yes|Device address.     |
1280| serial           | string                               | Yes|Sequence number.      |
1281| name             | string                               | Yes|Device name.     |
1282| manufacturerName | string                               | Yes| Device manufacturer.     |
1283| productName      | string                               | Yes|Product name.     |
1284| version          | string                               | Yes|Version number.       |
1285| vendorId         | number                               | Yes|Vendor ID.     |
1286| productId        | number                               | Yes|Product ID.     |
1287| clazz            | number                               | Yes|Device class.      |
1288| subClass         | number                               | Yes|Device subclass.     |
1289| protocol         | number                               | Yes|Device protocol code.    |
1290| configs          | Array&lt;[USBConfiguration](#usbconfiguration)&gt; | Yes|Device configuration descriptor information.|
1291
1292## USBDevicePipe
1293
1294Represents a USB device pipe, which is used to determine a USB device.
1295
1296**System capability**: SystemCapability.USB.USBManager
1297
1298| Name        | Type  | Mandatory   |Description   |
1299| ---------- | ------ | ----- |----- |
1300| busNum     | number |Yes| Bus address.|
1301| devAddress | number |Yes| Device address.|
1302
1303## USBControlParams<sup>(deprecated)</sup>
1304
1305Represents control transfer parameters.
1306
1307**NOTE**
1308
1309> This API is supported since API version 9 and deprecated since API version 16. You are advised to use [USBDeviceRequestParams](#usbdevicerequestparams12) instead.
1310
1311**System capability**: SystemCapability.USB.USBManager
1312
1313| Name     | Type                                           | Mandatory              |Description              |
1314| ------- | ----------------------------------------------- | ---------------- |---------------- |
1315| request | number                                          | Yes  |Request type.           |
1316| target  | [USBRequestTargetType](#usbrequesttargettype)   | Yes  |Request target type.         |
1317| reqType | [USBControlRequestType](#usbcontrolrequesttype) | Yes  |Control request type.         |
1318| value   | number                                          | Yes  |Request parameter value.           |
1319| index   | number                                          | Yes  |Index of the request parameter value.|
1320| data    | Uint8Array                                      | Yes  |Buffer for writing or reading data.    |
1321
1322## USBDeviceRequestParams<sup>12+</sup>
1323
1324Represents control transfer parameters.
1325
1326**System capability**: SystemCapability.USB.USBManager
1327
1328| Name     | Type                                           | Mandatory              |Description              |
1329| ------- | ----------------------------------------------- | ---------------- |---------------- |
1330| bmRequestType | number                                    | Yes  |Control request type.           |
1331| bRequest  | number                                        | Yes  |Request type.         |
1332| wValue | number                                           | Yes  |Request parameter value.         |
1333| wIndex   | number                                         | Yes  |Index of the request parameter value.           |
1334| wLength   | number                                        | Yes  |Length of the requested data.|
1335| data    | Uint8Array                                      | Yes  |Buffer for writing or reading data.    |
1336
1337## USBRequestTargetType
1338
1339Enumerates request target types.
1340
1341**System capability**: SystemCapability.USB.USBManager
1342
1343| Name                        | Value  | Description  |
1344| ---------------------------- | ---- | ------ |
1345| USB_REQUEST_TARGET_DEVICE    | 0    | Device.|
1346| USB_REQUEST_TARGET_INTERFACE | 1    | Interface.|
1347| USB_REQUEST_TARGET_ENDPOINT  | 2    | Endpoint.|
1348| USB_REQUEST_TARGET_OTHER     | 3    | Other.|
1349
1350## USBControlRequestType
1351
1352Enumerates control request types.
1353
1354**System capability**: SystemCapability.USB.USBManager
1355
1356| Name                     | Value  | Description  |
1357| ------------------------- | ---- | ------ |
1358| USB_REQUEST_TYPE_STANDARD | 0    | Standard.|
1359| USB_REQUEST_TYPE_CLASS    | 1    | Class.  |
1360| USB_REQUEST_TYPE_VENDOR   | 2    | Vendor.|
1361
1362## USBRequestDirection
1363
1364Enumerates request directions.
1365
1366**System capability**: SystemCapability.USB.USBManager
1367
1368| Name                       | Value  | Description                    |
1369| --------------------------- | ---- | ------------------------ |
1370| USB_REQUEST_DIR_TO_DEVICE   | 0    | Request for writing data from the host to the device.|
1371| USB_REQUEST_DIR_FROM_DEVICE | 0x80 | Request for reading data from the device to the host.|
1372
1373## USBAccessory<sup>14+</sup>
1374
1375Describes the USB accessory information.
1376
1377**System capability**: SystemCapability.USB.USBManager
1378
1379| Name        | Type  | Mandatory| Description            |
1380| ------------ | ------ | ---- | ---------------- |
1381| manufacturer | string | Yes  | Manufacturer of an accessory.|
1382| product      | string | Yes  | Product type of an accessory.|
1383| description  | string | Yes  | Description of an accessory.    |
1384| version      | string | Yes  | Version of an accessory.    |
1385| serialNumber | string | Yes  | SN of an accessory.    |
1386
1387## USBAccessoryHandle<sup>14+</sup>
1388
1389USB accessory handle.
1390
1391**System capability**: SystemCapability.USB.USBManager
1392
1393| Name       | Type  | Mandatory| Description                                     |
1394| ----------- | ------ | ---- | ----------------------------------------- |
1395| accessoryFd | number | Yes  | Accessory file descriptor. A valid **accessoryFd** is a positive integer.|
1396
1397## UsbDataTransferParams<sup>16+</sup>
1398
1399As a USB data transfer interface, it is required for a client to initiate a transfer request.
1400
1401**System capability**: SystemCapability.USB.USBManager
1402
1403| Name        | Type  | Mandatory   |Description   |
1404| ---------- | ------ | ----- |----- |
1405| pipe | [UsbDevicePipe](#usbdevicepipe) | Yes| USB device pipe, which is used to determine the USB device.|
1406| flags | [UsbTransferFlags](#usbtransferflags16) |Yes| USB transfer flag.|
1407| endpoint | number | Yes| Endpoint address, which is a positive integer.|
1408| type | [UsbEndpointTransferType](#usbendpointtransfertype16) |Yes| Transfer type.|
1409| timeout | number | Yes| Timeout duration, in ms.|
1410| length | number |Yes| Length of the data buffer, in bytes. The value must be a non-negative number (expected length).|
1411| callback | AsyncCallback<[SubmitTransferCallback](#submittransfercallback16)> |Yes| Information returned by the callback.|
1412| userData | Uint8Array | No| User data.|
1413| buffer | Uint8Array | Yes| Buffer, which is used to store data for read or write requests.|
1414| isoPacketCount | number | Yes| Number of data packets during real-time transfer, used only for I/Os with real-time transfer endpoints. The value must be a non-negative number.|
1415
1416## UsbTransferFlags<sup>16+</sup>
1417
1418Enumerates USB transfer flags.
1419
1420**System capability**: SystemCapability.USB.USBManager
1421
1422| Name                        | Value  | Description  |
1423| ---------------------------- | ---- | ------ |
1424| USB_TRANSFER_SHORT_NOT_OK    | 0    | Reports short frames as errors.|
1425| USB_TRANSFER_FREE_BUFFER | 1    | Automatically releases the transfer buffer.|
1426| USB_TRANSFER_FREE_TRANSFER  | 2    | Automatically transfers after the callback is complete.|
1427| USB_TRANSFER_ADD_ZERO_PACKET     | 3    | Adds an additional data packet to the transfer.|
1428
1429## UsbEndpointTransferType<sup>16+</sup>
1430
1431Enumerates USB transfer types.
1432
1433**System capability**: SystemCapability.USB.USBManager
1434
1435| Name                        | Value  | Description  |
1436| ---------------------------- | ---- | ------ |
1437| TRANSFER_TYPE_ISOCHRONOUS | 1    | Real-time transfer.|
1438| TRANSFER_TYPE_BULK  | 2    | Bulk transfer.|
1439| TRANSFER_TYPE_INTERRUPT     | 3    | Interrupt transfer.|
1440
1441## SubmitTransferCallback<sup>16+</sup>
1442
1443Transfers USB data packets in an asynchronous manner.
1444
1445**System capability**: SystemCapability.USB.USBManager
1446
1447| Name        | Type| Description   |
1448| ---------- | ------ | ----- |
1449| actualLength | number | Actual length of the read or written data, in bytes.|
1450| status | [UsbTransferStatus](#usbtransferstatus16) | Status after reading or writing is complete.|
1451| isoPacketDescs | Array<Readonly<[UsbIsoPacketDescriptor](#usbisopacketdescriptor16)>> | Packet information transferred in real time.|
1452
1453## UsbTransferStatus<sup>16+</sup>
1454
1455Enumerates the statuses returned by **libusb** through callback after the actual processing is complete.
1456
1457**System capability**: SystemCapability.USB.USBManager
1458
1459| Name                        | Value  | Description  |
1460| ---------------------------- | ---- | ------ |
1461| TRANSFER_COMPLETED    | 0    | Transfer completed.|
1462| TRANSFER_ERROR | 1    | Transfer failed.|
1463| TRANSFER_TIMED_OUT  | 2    | Transfer timed out.|
1464| TRANSFER_CANCELLED     | 3    |Transfer canceled.|
1465| TRANSFER_STALL  | 4    | Transfer stalled (at bulk/interrupt endpoint).|
1466| TRANSFER_NO_DEVICE     | 5    | Device disconnected.|
1467| TRANSFER_OVERFLOW     | 6    | Data overflow.|
1468
1469
1470## UsbIsoPacketDescriptor<sup>16+</sup>
1471
1472Describes packet information returned in real time by the transfer callback.
1473
1474**System capability**: SystemCapability.USB.USBManager
1475
1476| Name        | Type| Description   |
1477| ---------- | ------ | ----- |
1478| length | number | Expected length of the read or written data, in bytes.|
1479| actualLength | number| Actual length of the read or written data, in bytes.|
1480| status | [UsbTransferStatus](#usbtransferstatus16) | Status returned by callback.|
1481