• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.usbManager (USB管理)
2
3本模块主要提供管理USB设备的相关功能,包括主设备上查询USB设备列表、批量数据传输、控制命令传输、权限控制等;从设备上端口管理、功能切换及查询等。
4
5>  **说明:**
6>
7> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
8
9## 导入模块
10
11```js
12import usb from "@ohos.usbManager";
13```
14
15## usb.getDevices
16
17getDevices(): Array<Readonly<USBDevice>>
18
19获取接入主设备的USB设备列表。如果没有设备接入,那么将会返回一个空的列表。
20
21**系统能力:**  SystemCapability.USB.USBManager
22
23**返回值:**
24
25| 类型                                                   | 说明      |
26| ---------------------------------------------------- | ------- |
27| Array<Readonly<[USBDevice](#usbdevice)>> | 设备信息列表。 |
28
29**示例:**
30
31```js
32let devicesList = usb.getDevices();
33cconsole.log(`devicesList = ${devicesList}`);
34//devicesList  返回的数据结构
35//此处提供一个简单的示例,如下
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## usb.connectDevice
87
88connectDevice(device: USBDevice): Readonly<USBDevicePipe>
89
90根据getDevices()返回的设备信息打开USB设备。
91
92需要调用[usb.getDevices](#usbgetdevices)获取设备信息以及device,再调用[usb.requestRight](#usbrequestright)请求使用该设备的权限。
93
94**系统能力:**  SystemCapability.USB.USBManager
95
96**参数:**
97
98| 参数名 | 类型 | 必填 | 说明 |
99| -------- | -------- | -------- | -------- |
100| device | [USBDevice](#usbdevice) | 是 | USB设备信息。 |
101
102**返回值:**
103
104| 类型 | 说明 |
105| -------- | -------- |
106| Readonly<[USBDevicePipe](#usbdevicepipe)> | 指定的传输通道对象。 |
107
108**错误码:**
109
110以下错误码的详细介绍参见[USB错误码](../errorcodes/errorcode-usb.md)。
111
112| 错误码ID | 错误信息 |
113| -------- | -------- |
114| 14400001 |Permission denied. Need call requestRight to get permission. |
115
116**示例:**
117
118```js
119let devicesList = usb.getDevices();
120if (devicesList.length == 0) {
121  console.log(`device list is empty`);
122}
123
124let device = devicesList[0];
125usb.requestRight(device.name);
126let devicepipe = usb.connectDevice(device);
127console.log(`devicepipe = ${devicepipe}`);
128```
129
130## usb.hasRight
131
132hasRight(deviceName: string): boolean
133
134判断是否有权访问该设备。
135
136如果“使用者”(如各种App或系统)有权访问设备则返回true;无权访问设备则返回false。
137
138**系统能力:**  SystemCapability.USB.USBManager
139
140**参数:**
141
142| 参数名 | 类型 | 必填 | 说明 |
143| -------- | -------- | -------- | -------- |
144| deviceName | string | 是 | 设备名称。 |
145
146**返回值:**
147
148| 类型 | 说明 |
149| -------- | -------- |
150| boolean | true表示有访问设备的权限,false表示没有访问设备的权限。 |
151
152**示例:**
153
154```js
155let devicesName="1-1";
156let bool = usb.hasRight(devicesName);
157console.log(`${bool}`);
158```
159
160## usb.requestRight
161
162requestRight(deviceName: string): Promise<boolean>
163
164请求软件包的临时权限以访问设备。使用Promise异步回调。
165
166**系统能力:**  SystemCapability.USB.USBManager
167
168**参数:**
169
170| 参数名 | 类型 | 必填 | 说明 |
171| -------- | -------- | -------- | -------- |
172| deviceName | string | 是 | 设备名称。 |
173
174**返回值:**
175
176| 类型 | 说明 |
177| -------- | -------- |
178| Promise<boolean> | Promise对象,返回临时权限的申请结果。返回true表示临时权限申请成功;返回false则表示临时权限申请失败。 |
179
180**示例:**
181
182```js
183let devicesName="1-1";
184usb.requestRight(devicesName).then((ret) => {
185  console.log(`requestRight = ${ret}`);
186});
187```
188
189## usb.removeRight
190
191removeRight(deviceName: string): boolean
192
193移除软件包访问设备的权限。
194
195**系统能力:**  SystemCapability.USB.USBManager
196
197**参数:**
198
199| 参数名 | 类型 | 必填 | 说明 |
200| -------- | -------- | -------- | -------- |
201| deviceName | string | 是 | 设备名称。 |
202
203**返回值:**
204
205| 类型 | 说明 |
206| -------- | -------- |
207| boolean | 返回权限移除结果。返回true表示权限移除成功;返回false则表示权限移除失败。 |
208
209**示例:**
210
211```js
212let devicesName="1-1";
213if usb.removeRight(devicesName) {
214  console.log(`Succeed in removing right`);
215}
216```
217
218## usb.addRight
219
220addRight(bundleName: string, deviceName: string): boolean
221
222添加软件包访问设备的权限。
223
224[requestRight](#usbrequestright)会触发弹框请求用户授权;addRight不会触发弹框,而是直接添加软件包访问设备的权限。
225
226**系统接口:** 此接口为系统接口。
227
228**系统能力:**  SystemCapability.USB.USBManager
229
230**参数:**
231
232| 参数名 | 类型 | 必填 | 说明 |
233| -------- | -------- | -------- | -------- |
234| deviceName | string | 是 | 设备名称。 |
235| bundleName | string | 是 | 软件包名称。|
236
237**返回值:**
238
239| 类型 | 说明 |
240| -------- | -------- |
241| boolean | 返回权限添加结果。返回true表示权限添加成功;返回false则表示权限添加失败。 |
242
243**示例:**
244
245```js
246let devicesName = "1-1";
247let bundleName = "com.example.hello";
248if usb.addRight(bundleName, devicesName) {
249  console.log(`Succeed in adding right`);
250}
251```
252
253## usb.claimInterface
254
255claimInterface(pipe: USBDevicePipe, iface: USBInterface, force ?: boolean): number
256
257注册通信接口。
258
259需要调用[usb.getDevices](#usbgetdevices)获取设备信息以及interfaces;调用[usb.requestRight](#usbrequestright)获取设备请求权限;调用[usb.connectDevice](#usbconnectdevice)接口得到devicepipe作为参数。
260
261**系统能力:**  SystemCapability.USB.USBManager
262
263**参数:**
264
265| 参数名 | 类型 | 必填 | 说明 |
266| -------- | -------- | -------- | -------- |
267| pipe | [USBDevicePipe](#usbdevicepipe) | 是 | 用于确定总线号和设备地址。 |
268| iface | [USBInterface](#usbinterface) | 是 | 用于确定需要获取接口的索引。 |
269| force | boolean | 否 | 可选参数,是否强制获取。默认值为false ,表示不强制获取。 |
270
271**返回值:**
272
273| 类型 | 说明 |
274| -------- | -------- |
275| number | 注册通信接口成功返回0;注册通信接口失败返回其他错误码。 |
276
277**示例:**
278
279```js
280let ret = usb.claimInterface(devicepipe, interfaces);
281console.log(`claimInterface = ${ret}`);
282```
283
284## usb.releaseInterface
285
286releaseInterface(pipe: USBDevicePipe, iface: USBInterface): number
287
288释放注册过的通信接口。
289
290需要调用[usb.claimInterface](#usbclaiminterface)先获取接口,才能使用此方法释放接口。
291
292**系统能力:**  SystemCapability.USB.USBManager
293
294**参数:**
295
296| 参数名 | 类型 | 必填 | 说明 |
297| -------- | -------- | -------- | -------- |
298| pipe | [USBDevicePipe](#usbdevicepipe) | 是 | 用于确定总线号和设备地址。 |
299| iface | [USBInterface](#usbinterface) | 是 | 用于确定需要释放接口的索引。 |
300
301**返回值:**
302
303| 类型 | 说明 |
304| -------- | -------- |
305| number | 释放接口成功返回0;释放接口失败返回其他错误码。 |
306
307**示例:**
308
309```js
310let ret = usb.releaseInterface(devicepipe, interfaces);
311console.log(`releaseInterface = ${ret}`);
312```
313
314## usb.setConfiguration
315
316setConfiguration(pipe: USBDevicePipe, config: USBConfiguration): number
317
318设置设备配置。
319
320需要调用[usb.getDevices](#usbgetdevices)获取设备信息以及config;调用[usb.requestRight](#usbrequestright)获取设备请求权限;调用[usb.connectDevice](#usbconnectdevice)得到devicepipe作为参数。
321
322**系统能力:**  SystemCapability.USB.USBManager
323
324**参数:**
325
326| 参数名 | 类型 | 必填 | 说明 |
327| -------- | -------- | -------- | -------- |
328| pipe | [USBDevicePipe](#usbdevicepipe) | 是 | 用于确定总线号和设备地址。 |
329| config | [USBConfiguration](#usbconfiguration) | 是 | 用于确定需要设置的配置。 |
330
331**返回值:**
332
333| 类型 | 说明 |
334| -------- | -------- |
335| number | 设置设备配置成功返回0;设置设备配置失败返回其他错误码。 |
336
337**示例:**
338
339```js
340let ret = usb.setConfiguration(devicepipe, config);
341console.log(`setConfiguration = ${ret}`);
342```
343
344## usb.setInterface
345
346setInterface(pipe: USBDevicePipe, iface: USBInterface): number
347
348设置设备接口。
349
350需要调用[usb.getDevices](#usbgetdevices)获取设备列表以及interfaces;调用[usb.requestRight](#usbrequestright)获取设备请求权限;调用[usb.connectDevice](#usbconnectdevice)得到devicepipe作为参数;调用[usb.claimInterface](#usbclaiminterface)注册通信接口。
351
352**系统能力:**  SystemCapability.USB.USBManager
353
354**参数:**
355
356| 参数名   | 类型                              | 必填  | 说明            |
357| ----- | ------------------------------- | --- | ------------- |
358| pipe  | [USBDevicePipe](#usbdevicepipe) | 是   | 用于确定总线号和设备地址。 |
359| iface | [USBInterface](#usbinterface)   | 是   | 用于确定需要设置的接口。  |
360
361**返回值:**
362
363| 类型 | 说明 |
364| -------- | -------- |
365| number | 设置设备接口成功返回0;设置设备接口失败返回其他错误码。 |
366
367**示例:**
368
369```js
370let ret = usb.setInterface(devicepipe, interfaces);
371console.log(`setInterface = ${ret}`);
372```
373
374## usb.getRawDescriptor
375
376getRawDescriptor(pipe: USBDevicePipe): Uint8Array
377
378获取原始的USB描述符。
379
380需要调用[usb.getDevices](#usbgetdevices)获取设备列表;调用[usb.requestRight](#usbrequestright)获取设备请求权限;调用[usb.connectDevice](#usbconnectdevice)接口得到devicepipe作为参数。
381
382**系统能力:**  SystemCapability.USB.USBManager
383
384**参数:**
385
386| 参数名 | 类型 | 必填 | 说明 |
387| -------- | -------- | -------- | -------- |
388| pipe | [USBDevicePipe](#usbdevicepipe) | 是 | 用于确定总线号和设备地址。 |
389
390**返回值:**
391
392| 类型 | 说明 |
393| -------- | -------- |
394| Uint8Array | 返回获取的原始数据;失败返回undefined。 |
395
396**示例:**
397
398```js
399let ret = usb.getRawDescriptor(devicepipe);
400```
401
402## usb.getFileDescriptor
403
404getFileDescriptor(pipe: USBDevicePipe): number
405
406获取文件描述符。
407
408需要调用[usb.getDevices](#usbgetdevices)获取设备列表;调用[usb.requestRight](#usbrequestright)获取设备请求权限;调用[usb.connectDevice](#usbconnectdevice)接口得到devicepipe作为参数。
409
410**系统能力:**  SystemCapability.USB.USBManager
411
412**参数:**
413
414| 参数名 | 类型 | 必填 | 说明 |
415| -------- | -------- | -------- | -------- |
416| pipe | [USBDevicePipe](#usbdevicepipe) | 是 | 用于确定总线号和设备地址。 |
417
418**返回值:**
419
420| 类型     | 说明                   |
421| ------ | -------------------- |
422| number | 返回设备对应的文件描述符;失败返回-1。 |
423
424**示例:**
425
426```js
427let ret = usb.getFileDescriptor(devicepipe);
428```
429
430## usb.controlTransfer
431
432controlTransfer(pipe: USBDevicePipe, controlparam: USBControlParams, timeout ?: number): Promise<number>
433
434控制传输。
435
436需要调用[usb.getDevices](#usbgetdevices)获取设备列表;调用[usb.requestRight](#usbrequestright)获取设备请求权限;调用[usb.connectDevice](#usbconnectdevice)接口得到devicepipe作为参数。
437
438**系统能力:**  SystemCapability.USB.USBManager
439
440**参数:**
441
442| 参数名 | 类型 | 必填 | 说明 |
443| -------- | -------- | -------- | -------- |
444| pipe | [USBDevicePipe](#usbdevicepipe) | 是 | 用于确定设备。 |
445| controlparam | [USBControlParams](#usbcontrolparams) | 是 | 控制传输参数。 |
446| timeout | number | 否 | 超时时间(单位:ms),可选参数,默认为0不超时。 |
447
448**返回值:**
449
450| 类型 | 说明 |
451| -------- | -------- |
452| Promise<number> | Promise对象,获取传输或接收到的数据块大小。失败返回-1。 |
453
454**示例:**
455
456```js
457let param = new usb.USBControlParams();
458usb.controlTransfer(devicepipe, param).then((ret) => {
459 console.log(`controlTransfer = ${ret}`);
460})
461```
462
463## usb.bulkTransfer
464
465bulkTransfer(pipe: USBDevicePipe, endpoint: USBEndpoint, buffer: Uint8Array, timeout ?: number): Promise<number>
466
467批量传输。
468
469需要调用[usb.getDevices](#usbgetdevices)获取设备信息列表以及endpoint;再调用[usb.requestRight](#usbrequestright)获取设备请求权限;然后调用[usb.connectDevice](#usbconnectdevice)接口得到返回数据devicepipe之后,再次获取接口[usb.claimInterface](#usbclaiminterface);再调用usb.bulkTransfer接口。
470
471**系统能力:**  SystemCapability.USB.USBManager
472
473**参数:**
474
475| 参数名 | 类型 | 必填 | 说明 |
476| -------- | -------- | -------- | -------- |
477| pipe | [USBDevicePipe](#usbdevicepipe) | 是 | 用于确定设备。 |
478| endpoint | [USBEndpoint](#usbendpoint) | 是 | 用于确定传输的端口。 |
479| buffer | Uint8Array | 是 | 用于写入或读取的缓冲区。 |
480| timeout | number | 否 | 超时时间(单位:ms),可选参数,默认为0不超时。|
481
482**返回值:**
483
484| 类型 | 说明 |
485| -------- | -------- |
486| Promise<number> | Promise对象,获取传输或接收到的数据块大小。失败返回-1。 |
487
488**示例:**
489
490```js
491//usb.getDevices 接口返回数据集合,取其中一个设备对象,并获取权限 。
492//把获取到的设备对象作为参数传入usb.connectDevice;当usb.connectDevice接口成功返回之后;
493//才可以调用第三个接口usb.claimInterface.usb.claimInterface 调用成功以后,再调用该接口。
494usb.bulkTransfer(devicepipe, endpoint, buffer).then((ret) => {
495 console.log(`bulkTransfer = ${ret}`);
496});
497```
498
499## usb.closePipe
500
501closePipe(pipe: USBDevicePipe): number
502
503关闭设备消息控制通道。
504
505需要调用[usb.getDevices](#usbgetdevices)获取设备列表;调用[usb.requestRight](#usbrequestright)获取设备请求权限;调用[usb.connectDevice](#usbconnectdevice)得到devicepipe作为参数。
506
507**系统能力:**  SystemCapability.USB.USBManager
508
509**参数:**
510
511| 参数名 | 类型 | 必填 | 说明 |
512| -------- | -------- | -------- | -------- |
513| pipe | [USBDevicePipe](#usbdevicepipe) | 是 | 用于确定USB设备消息控制通道。 |
514
515**返回值:**
516
517| 类型 | 说明 |
518| -------- | -------- |
519| number | 关闭设备消息控制通道成功返回0;关闭设备消息控制通道失败返回其他错误码。 |
520
521**示例:**
522
523```js
524let ret = usb.closePipe(devicepipe);
525console.log(`closePipe = ${ret}`);
526```
527
528## usb.usbFunctionsFromString
529
530usbFunctionsFromString(funcs: string): number
531
532在设备模式下,将字符串形式的USB功能列表转化为数字掩码。
533
534**系统接口:** 此接口为系统接口。
535
536**系统能力:**  SystemCapability.USB.USBManager
537
538**参数:**
539
540| 参数名 | 类型   | 必填 | 说明                   |
541| ------ | ------ | ---- | ---------------------- |
542| funcs  | string | 是   | 字符串形式的功能列表。 |
543
544**返回值:**
545
546| 类型   | 说明               |
547| ------ | ------------------ |
548| number | 转化后的数字掩码。 |
549
550**示例:**
551
552```js
553let funcs = "acm";
554let ret = usb.usbFunctionsFromString(funcs);
555```
556
557## usb.usbFunctionsToString
558
559usbFunctionsToString(funcs: FunctionType): string
560
561在设备模式下,将数字掩码形式的USB功能列表转化为字符串。
562
563**系统接口:** 此接口为系统接口。
564
565**系统能力:**  SystemCapability.USB.USBManager
566
567**参数:**
568
569| 参数名 | 类型                           | 必填 | 说明              |
570| ------ | ------------------------------ | ---- | ----------------- |
571| funcs  | [FunctionType](#functiontype) | 是   | USB功能数字掩码。 |
572
573**返回值:**
574
575| 类型   | 说明                           |
576| ------ | ------------------------------ |
577| string | 转化后的字符串形式的功能列表。 |
578
579**示例:**
580
581```js
582let funcs = usb.ACM | usb.ECM;
583let ret = usb.usbFunctionsToString(funcs);
584```
585
586## usb.setCurrentFunctions
587
588setCurrentFunctions(funcs: FunctionType): Promise\<void\>
589
590在设备模式下,设置当前的USB功能列表。
591
592**系统接口:** 此接口为系统接口。
593
594**系统能力:**  SystemCapability.USB.USBManager
595
596**参数:**
597
598| 参数名 | 类型                           | 必填 | 说明              |
599| ------ | ------------------------------ | ---- | ----------------- |
600| funcs  | [FunctionType](#functiontype) | 是   | USB功能数字掩码。 |
601
602**返回值:**
603
604| 类型            | 说明          |
605| --------------- | ------------- |
606| Promise\<void\> | Promise对象。 |
607
608**示例:**
609
610```js
611let funcs = usb.HDC;
612usb.setCurrentFunctions(funcs).then(() => {
613    console.info('usb setCurrentFunctions successfully.');
614}).catch(err => {
615    console.error('usb setCurrentFunctions failed: ' + err.code + ' message: ' + err.message);
616});
617```
618
619## usb.getCurrentFunctions
620
621getCurrentFunctions(): FunctionType
622
623在设备模式下,获取当前的USB功能列表的数字组合掩码。
624
625**系统接口:** 此接口为系统接口。
626
627**系统能力:**  SystemCapability.USB.USBManager
628
629**返回值:**
630
631| 类型                           | 说明                              |
632| ------------------------------ | --------------------------------- |
633| [FunctionType](#functiontype) | 当前的USB功能列表的数字组合掩码。 |
634
635**示例:**
636
637```js
638let ret = usb.getCurrentFunctions();
639```
640
641## usb.getPorts
642
643getPorts(): Array\<USBPort\>
644
645获取所有物理USB端口描述信息。
646
647**系统接口:** 此接口为系统接口。
648
649**系统能力:**  SystemCapability.USB.USBManager
650
651**返回值:**
652
653| 类型                          | 说明                  |
654| ----------------------------- | --------------------- |
655| [Array\<USBPort\>](#usbport) | USB端口描述信息列表。 |
656
657**示例:**
658
659```js
660let ret = usb.getPorts();
661```
662
663## usb.getSupportedModes
664
665getSupportedModes(portId: number): PortModeType
666
667获取指定的端口支持的模式列表的组合掩码。
668
669**系统接口:** 此接口为系统接口。
670
671**系统能力:**  SystemCapability.USB.USBManager
672
673**参数:**
674
675| 参数名 | 类型   | 必填 | 说明     |
676| ------ | ------ | ---- | -------- |
677| portId | number | 是   | 端口号。 |
678
679**返回值:**
680
681| 类型                           | 说明                       |
682| ------------------------------ | -------------------------- |
683| [PortModeType](#portmodetype) | 支持的模式列表的组合掩码。 |
684
685**示例:**
686
687```js
688let ret = usb.getSupportedModes(0);
689```
690
691## usb.setPortRoles
692
693setPortRoles(portId: number, powerRole: PowerRoleType, dataRole: DataRoleType): Promise\<void\>
694
695设置指定的端口支持的角色模式,包含充电角色、数据传输角色。
696
697**系统接口:** 此接口为系统接口。
698
699**系统能力:**  SystemCapability.USB.USBManager
700
701**参数:**
702
703| 参数名    | 类型                             | 必填 | 说明             |
704| --------- | -------------------------------- | ---- | ---------------- |
705| portId    | number                           | 是   | 端口号。         |
706| powerRole | [PowerRoleType](#powerroletype) | 是   | 充电的角色。     |
707| dataRole  | [DataRoleType](#dataroletype)   | 是   | 数据传输的角色。 |
708
709**返回值:**
710
711| 类型            | 说明          |
712| --------------- | ------------- |
713| Promise\<void\> | Promise对象。 |
714
715**示例:**
716
717```js
718let portId = 1;
719usb.setPortRoles(portId, usb.PowerRoleType.SOURCE, usb.DataRoleType.HOST).then(() => {
720    console.info('usb setPortRoles successfully.');
721}).catch(err => {
722    console.error('usb setPortRoles failed: ' + err.code + ' message: ' + err.message);
723});
724```
725
726## USBEndpoint
727
728通过USB发送和接收数据的端口。通过[USBInterface](#usbinterface)获取。
729
730**系统能力:** SystemCapability.USB.USBManager
731
732| 名称            | 类型                                        | 必填            |说明            |
733| ------------- | ------------------------------------------- | ------------- |------------- |
734| address       | number                                      | 是 |端点地址。         |
735| attributes    | number                                      | 是 |端点属性。         |
736| interval      | number                                      | 是 |端点间隔。         |
737| maxPacketSize | number                                      | 是 |端点最大数据包大小。    |
738| direction     | [USBRequestDirection](#usbrequestdirection) | 是 |端点的方向。        |
739| number        | number                                      | 是 |端点号。          |
740| type          | number                                      | 是 |端点类型。         |
741| interfaceId   | number                                      | 是 |端点所属的接口的唯一标识。 |
742
743## USBInterface
744
745一个[USBConfiguration](#usbconfiguration)中可以含有多个USBInterface,每个USBInterface提供一个功能。
746
747**系统能力:** SystemCapability.USB.USBManager
748
749| 名称               | 类型                                     | 必填            |说明                    |
750| ---------------- | ---------------------------------------- | ------------- |--------------------- |
751| id               | number                                   | 是 |接口的唯一标识。              |
752| protocol         | number                                   | 是 |接口的协议。                |
753| clazz            | number                                   | 是 |设备类型。                 |
754| subClass         | number                                   | 是 |设备子类。                 |
755| alternateSetting | number                                   | 是 |在同一个接口中的多个描述符中进行切换设置。 |
756| name             | string                                   | 是 |接口名称。                 |
757| endpoints        | Array&lt;[USBEndpoint](#usbendpoint)&gt; | 是 |当前接口所包含的端点。           |
758
759## USBConfiguration
760
761USB配置,一个[USBDevice](#usbdevice)中可以含有多个配置。
762
763**系统能力:** SystemCapability.USB.USBManager
764
765| 名称             | 类型                                             | 必填  |说明              |
766| -------------- | ------------------------------------------------ | --------------- |--------------- |
767| id             | number                                           | 是 |配置的唯一标识。        |
768| attributes     | number                                           | 是 |配置的属性。          |
769| maxPower       | number                                           | 是 |最大功耗,以毫安为单位。    |
770| name           | string                                           | 是 |配置的名称,可以为空。     |
771| isRemoteWakeup | boolean                                          | 是 |检查当前配置是否支持远程唤醒。 |
772| isSelfPowered  | boolean                                          | 是 | 检查当前配置是否支持独立电源。 |
773| interfaces     | Array&nbsp;&lt;[USBInterface](#usbinterface)&gt; | 是 |配置支持的接口属性。      |
774
775## USBDevice
776
777USB设备信息。
778
779**系统能力:** SystemCapability.USB.USBManager
780
781| 名称               | 类型                                 | 必填         |说明         |
782| ---------------- | ------------------------------------ | ---------- |---------- |
783| busNum           | number                               | 是 |总线地址。      |
784| devAddress       | number                               | 是 |设备地址。      |
785| serial           | string                               | 是 |序列号。       |
786| name             | string                               | 是 |设备名字。      |
787| manufacturerName | string                               | 是 | 产商信息。      |
788| productName      | string                               | 是 |产品信息。      |
789| version          | string                               | 是 |版本。        |
790| vendorId         | number                               | 是 |厂商ID。      |
791| productId        | number                               | 是 |产品ID。      |
792| clazz            | number                               | 是 |设备类。       |
793| subClass         | number                               | 是 |设备子类。      |
794| protocol         | number                               | 是 |设备协议码。     |
795| configs          | Array&lt;[USBConfiguration](#usbconfiguration)&gt; | 是 |设备配置描述符信息。 |
796
797## USBDevicePipe
798
799USB设备消息传输通道,用于确定设备。
800
801**系统能力:** SystemCapability.USB.USBManager
802
803| 名称         | 类型   | 必填    |说明    |
804| ---------- | ------ | ----- |----- |
805| busNum     | number |是 | 总线地址。 |
806| devAddress | number |是 | 设备地址。 |
807
808## USBControlParams
809
810控制传输参数。
811
812**系统能力:** SystemCapability.USB.USBManager
813
814| 名称      | 类型                                            | 必填               |说明               |
815| ------- | ----------------------------------------------- | ---------------- |---------------- |
816| request | number                                          | 是   |请求类型。            |
817| target  | [USBRequestTargetType](#usbrequesttargettype)   | 是   |请求目标类型。          |
818| reqType | [USBControlRequestType](#usbcontrolrequesttype) | 是   |请求控制类型。          |
819| value   | number                                          | 是   |请求参数。            |
820| index   | number                                          | 是   |请求参数value对应的索引值。 |
821| data    | Uint8Array                                      | 是   |用于写入或读取的缓冲区。     |
822
823## USBPort
824
825USB设备端口。
826
827**系统接口:** 此接口为系统接口。
828
829**系统能力:** SystemCapability.USB.USBManager
830
831| 名称           | 类型                         | 必填      |说明                                |
832| -------------- | ------------------------------- | ------------------- |------------------------ |
833| id             | number                          | 是   |USB端口唯一标识。                   |
834| supportedModes | [PortModeType](#portmodetype)   | 是   |USB端口所支持的模式的数字组合掩码。 |
835| status         | [USBPortStatus](#usbportstatus) | 是   |USB端口角色。                       |
836
837## USBPortStatus
838
839USB设备端口角色信息。
840
841**系统接口:** 此接口为系统接口。
842
843**系统能力:** SystemCapability.USB.USBManager
844
845| 名称             | 类型 | 必填      |说明                   |
846| ---------------- | -------- | ---------------- |---------------------- |
847| currentMode      | number   | 是 |当前的USB模式。        |
848| currentPowerRole | number   | 是   |当前设备充电模式。     |
849| currentDataRole  | number   | 是   |当前设备数据传输模式。 |
850
851## USBRequestTargetType
852
853请求目标类型。
854
855**系统能力:** SystemCapability.USB.USBManager
856
857| 名称                         | 值   | 说明   |
858| ---------------------------- | ---- | ------ |
859| USB_REQUEST_TARGET_DEVICE    | 0    | 设备。 |
860| USB_REQUEST_TARGET_INTERFACE | 1    | 接口。 |
861| USB_REQUEST_TARGET_ENDPOINT  | 2    | 端点。 |
862| USB_REQUEST_TARGET_OTHER     | 3    | 其他。 |
863
864## USBControlRequestType
865
866控制请求类型。
867
868**系统能力:** SystemCapability.USB.USBManager
869
870| 名称                      | 值   | 说明   |
871| ------------------------- | ---- | ------ |
872| USB_REQUEST_TYPE_STANDARD | 0    | 标准。 |
873| USB_REQUEST_TYPE_CLASS    | 1    | 类。   |
874| USB_REQUEST_TYPE_VENDOR   | 2    | 厂商。 |
875
876## USBRequestDirection
877
878请求方向。
879
880**系统能力:** SystemCapability.USB.USBManager
881
882| 名称                        | 值   | 说明                     |
883| --------------------------- | ---- | ------------------------ |
884| USB_REQUEST_DIR_TO_DEVICE   | 0    | 写数据,主设备往从设备。 |
885| USB_REQUEST_DIR_FROM_DEVICE | 0x80 | 读数据,从设备往主设备。 |
886
887## FunctionType
888
889USB设备侧功能。
890
891**系统接口:** 此接口为系统接口。
892
893**系统能力:** SystemCapability.USB.USBManager
894
895| 名称         | 值   | 说明       |
896| ------------ | ---- | ---------- |
897| NONE         | 0    | 没有功能。 |
898| ACM          | 1    | acm功能。  |
899| ECM          | 2    | ecm功能。  |
900| HDC          | 4    | hdc功能。  |
901| MTP          | 8    | 暂不支持。 |
902| PTP          | 16   | 暂不支持。 |
903| RNDIS        | 32   | 暂不支持。 |
904| MIDI         | 64   | 暂不支持。 |
905| AUDIO_SOURCE | 128  | 暂不支持。 |
906| NCM          | 256  | 暂不支持。 |
907
908## PortModeType
909
910USB端口模式类型。
911
912**系统接口:** 此接口为系统接口。
913
914**系统能力:** SystemCapability.USB.USBManager
915
916| 名称      | 值   | 说明                                                 |
917| --------- | ---- | ---------------------------------------------------- |
918| NONE      | 0    | 无。                                                 |
919| UFP       | 1    | 数据上行,需要外部供电。                             |
920| DFP       | 2    | 数据下行,对外提供电源。                             |
921| DRP       | 3    | 既可以做DFP(Host),也可以做UFP(Device),当前不支持。 |
922| NUM_MODES | 4    | 当前不支持。                                         |
923
924## PowerRoleType
925
926电源角色类型。
927
928**系统接口:** 此接口为系统接口。
929
930**系统能力:** SystemCapability.USB.USBManager
931
932| 名称   | 值   | 说明       |
933| ------ | ---- | ---------- |
934| NONE   | 0    | 无。       |
935| SOURCE | 1    | 外部供电。 |
936| SINK   | 2    | 内部供电。 |
937
938## DataRoleType
939
940数据角色类型。
941
942**系统接口:** 此接口为系统接口。
943
944**系统能力:** SystemCapability.USB.USBManager
945
946| 名称   | 值   | 说明         |
947| ------ | ---- | ------------ |
948| NONE   | 0    | 无。         |
949| HOST   | 1    | 主设备角色。 |
950| DEVICE | 2    | 从设备角色。 |
951
952