• 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```ts
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```ts
32let devicesList: Array<usb.USBDevice> = usb.getDevices();
33console.log(`devicesList = ${devicesList}`);
34/*
35devicesList 返回的数据结构,此处提供一个简单的示例,如下
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## usb.connectDevice
88
89connectDevice(device: USBDevice): Readonly&lt;USBDevicePipe&gt;
90
91根据getDevices()返回的设备信息打开USB设备。
92
93需要调用[usb.getDevices](#usbgetdevices)获取设备信息以及device,再调用[usb.requestRight](#usbrequestright)请求使用该设备的权限。
94
95**系统能力:**  SystemCapability.USB.USBManager
96
97**参数:**
98
99| 参数名 | 类型 | 必填 | 说明 |
100| -------- | -------- | -------- | -------- |
101| device | [USBDevice](#usbdevice) | 是 | USB设备信息。 |
102
103**返回值:**
104
105| 类型 | 说明 |
106| -------- | -------- |
107| Readonly&lt;[USBDevicePipe](#usbdevicepipe)&gt; | 指定的传输通道对象。 |
108
109**错误码:**
110
111以下错误码的详细介绍参见[USB服务错误码](errorcode-usb.md)。
112
113| 错误码ID | 错误信息 |
114| -------- | -------- |
115| 14400001 |Permission denied. Need call requestRight to get permission. |
116
117**示例:**
118
119```ts
120let devicesList: Array<usb.USBDevice> = usb.getDevices();
121if (devicesList.length == 0) {
122  console.log(`device list is empty`);
123}
124
125let device: usb.USBDevice = devicesList[0];
126usb.requestRight(device.name);
127let devicepipe: usb.USBDevicePipe = usb.connectDevice(device);
128console.log(`devicepipe = ${devicepipe}`);
129```
130
131## usb.hasRight
132
133hasRight(deviceName: string): boolean
134
135判断是否有权访问该设备。
136
137如果“使用者”(如各种App或系统)有权访问设备则返回true;无权访问设备则返回false。
138
139**系统能力:**  SystemCapability.USB.USBManager
140
141**参数:**
142
143| 参数名 | 类型 | 必填 | 说明 |
144| -------- | -------- | -------- | -------- |
145| deviceName | string | 是 | 设备名称。 |
146
147**返回值:**
148
149| 类型 | 说明 |
150| -------- | -------- |
151| boolean | true表示有访问设备的权限,false表示没有访问设备的权限。 |
152
153**示例:**
154
155```ts
156let devicesName: string = "1-1";
157let right: boolean = usb.hasRight(devicesName);
158console.log(`${right}`);
159```
160
161## usb.requestRight
162
163requestRight(deviceName: string): Promise&lt;boolean&gt;
164
165请求软件包的临时权限以访问设备。使用Promise异步回调。系统应用默认拥有访问设备权限,无需调用此接口申请。
166
167**系统能力:**  SystemCapability.USB.USBManager
168
169**参数:**
170
171| 参数名 | 类型 | 必填 | 说明 |
172| -------- | -------- | -------- | -------- |
173| deviceName | string | 是 | 设备名称。 |
174
175**返回值:**
176
177| 类型 | 说明 |
178| -------- | -------- |
179| Promise&lt;boolean&gt; | Promise对象,返回临时权限的申请结果。返回true表示临时权限申请成功;返回false则表示临时权限申请失败。 |
180
181**示例:**
182
183```ts
184let devicesName: string = "1-1";
185usb.requestRight(devicesName).then(ret => {
186  console.log(`requestRight = ${ret}`);
187});
188```
189
190## usb.removeRight
191
192removeRight(deviceName: string): boolean
193
194移除软件包访问设备的权限。系统应用默认拥有访问设备权限,调用此接口不会产生影响。
195
196**系统能力:**  SystemCapability.USB.USBManager
197
198**参数:**
199
200| 参数名 | 类型 | 必填 | 说明 |
201| -------- | -------- | -------- | -------- |
202| deviceName | string | 是 | 设备名称。 |
203
204**返回值:**
205
206| 类型 | 说明 |
207| -------- | -------- |
208| boolean | 返回权限移除结果。返回true表示权限移除成功;返回false则表示权限移除失败。 |
209
210**示例:**
211
212```ts
213let devicesName: string = "1-1";
214if (usb.removeRight(devicesName)) {
215  console.log(`Succeed in removing right`);
216}
217```
218
219## usb.claimInterface
220
221claimInterface(pipe: USBDevicePipe, iface: USBInterface, force ?: boolean): number
222
223注册通信接口。
224
225需要调用[usb.getDevices](#usbgetdevices)获取设备信息以及interfaces;调用[usb.requestRight](#usbrequestright)获取设备请求权限;调用[usb.connectDevice](#usbconnectdevice)接口得到devicepipe作为参数。
226
227**系统能力:**  SystemCapability.USB.USBManager
228
229**参数:**
230
231| 参数名 | 类型 | 必填 | 说明 |
232| -------- | -------- | -------- | -------- |
233| pipe | [USBDevicePipe](#usbdevicepipe) | 是 | 用于确定总线号和设备地址。 |
234| iface | [USBInterface](#usbinterface) | 是 | 用于确定需要获取接口的索引。 |
235| force | boolean | 否 | 可选参数,是否强制获取。默认值为false&nbsp;,表示不强制获取。 |
236
237**返回值:**
238
239| 类型 | 说明 |
240| -------- | -------- |
241| number | 注册通信接口成功返回0;注册通信接口失败返回其他错误码。 |
242
243**示例:**
244
245```ts
246let devicesList: Array<usb.USBDevice> = usb.getDevices();
247if (devicesList.length == 0) {
248  console.log(`device list is empty`);
249}
250
251let device: usb.USBDevice = devicesList[0];
252usb.requestRight(device.name);
253let devicepipe: usb.USBDevicePipe = usb.connectDevice(device);
254let interfaces: usb.USBInterface = device.configs[0].interfaces[0];
255let ret: number= usb.claimInterface(devicepipe, interfaces);
256console.log(`claimInterface = ${ret}`);
257```
258
259## usb.releaseInterface
260
261releaseInterface(pipe: USBDevicePipe, iface: USBInterface): number
262
263释放注册过的通信接口。
264
265需要调用[usb.claimInterface](#usbclaiminterface)先获取接口,才能使用此方法释放接口。
266
267**系统能力:**  SystemCapability.USB.USBManager
268
269**参数:**
270
271| 参数名 | 类型 | 必填 | 说明 |
272| -------- | -------- | -------- | -------- |
273| pipe | [USBDevicePipe](#usbdevicepipe) | 是 | 用于确定总线号和设备地址。 |
274| iface | [USBInterface](#usbinterface) | 是 | 用于确定需要释放接口的索引。 |
275
276**返回值:**
277
278| 类型 | 说明 |
279| -------- | -------- |
280| number | 释放接口成功返回0;释放接口失败返回其他错误码。 |
281
282**示例:**
283
284```ts
285let devicesList: Array<usb.USBDevice> = usb.getDevices();
286if (devicesList.length == 0) {
287  console.log(`device list is empty`);
288}
289
290let device: usb.USBDevice = devicesList[0];
291usb.requestRight(device.name);
292let devicepipe: usb.USBDevicePipe = usb.connectDevice(device);
293let interfaces: usb.USBInterface = device.configs[0].interfaces[0];
294let ret: number = usb.claimInterface(devicepipe, interfaces);
295ret = usb.releaseInterface(devicepipe, interfaces);
296console.log(`releaseInterface = ${ret}`);
297```
298
299## usb.setConfiguration
300
301setConfiguration(pipe: USBDevicePipe, config: USBConfiguration): number
302
303设置设备配置。
304
305需要调用[usb.getDevices](#usbgetdevices)获取设备信息以及config;调用[usb.requestRight](#usbrequestright)获取设备请求权限;调用[usb.connectDevice](#usbconnectdevice)得到devicepipe作为参数。
306
307**系统能力:**  SystemCapability.USB.USBManager
308
309**参数:**
310
311| 参数名 | 类型 | 必填 | 说明 |
312| -------- | -------- | -------- | -------- |
313| pipe | [USBDevicePipe](#usbdevicepipe) | 是 | 用于确定总线号和设备地址。 |
314| config | [USBConfiguration](#usbconfiguration) | 是 | 用于确定需要设置的配置。 |
315
316**返回值:**
317
318| 类型 | 说明 |
319| -------- | -------- |
320| number | 设置设备配置成功返回0;设置设备配置失败返回其他错误码。 |
321
322**示例:**
323
324```ts
325let devicesList: Array<usb.USBDevice> = usb.getDevices();
326if (devicesList.length == 0) {
327  console.log(`device list is empty`);
328}
329
330let device: usb.USBDevice = devicesList[0];
331usb.requestRight(device.name);
332let devicepipe: usb.USBDevicePipe = usb.connectDevice(device);
333let config: usb.USBConfiguration = device.configs[0];
334let ret: number= usb.setConfiguration(devicepipe, config);
335console.log(`setConfiguration = ${ret}`);
336```
337
338## usb.setInterface
339
340setInterface(pipe: USBDevicePipe, iface: USBInterface): number
341
342设置设备接口。
343
344需要调用[usb.getDevices](#usbgetdevices)获取设备列表以及interfaces;调用[usb.requestRight](#usbrequestright)获取设备请求权限;调用[usb.connectDevice](#usbconnectdevice)得到devicepipe作为参数;调用[usb.claimInterface](#usbclaiminterface)注册通信接口。
345
346**系统能力:**  SystemCapability.USB.USBManager
347
348**参数:**
349
350| 参数名   | 类型                              | 必填  | 说明            |
351| ----- | ------------------------------- | --- | ------------- |
352| pipe  | [USBDevicePipe](#usbdevicepipe) | 是   | 用于确定总线号和设备地址。 |
353| iface | [USBInterface](#usbinterface)   | 是   | 用于确定需要设置的接口。  |
354
355**返回值:**
356
357| 类型 | 说明 |
358| -------- | -------- |
359| number | 设置设备接口成功返回0;设置设备接口失败返回其他错误码。 |
360
361**示例:**
362
363```ts
364let devicesList: Array<usb.USBDevice> = usb.getDevices();
365if (devicesList.length == 0) {
366  console.log(`device list is empty`);
367}
368
369let device: usb.USBDevice = devicesList[0];
370usb.requestRight(device.name);
371let devicepipe: usb.USBDevicePipe = usb.connectDevice(device);
372let interfaces: usb.USBInterface = device.configs[0].interfaces[0];
373let ret: number = usb.claimInterface(devicepipe, interfaces);
374ret = usb.setInterface(devicepipe, interfaces);
375console.log(`setInterface = ${ret}`);
376```
377
378## usb.getRawDescriptor
379
380getRawDescriptor(pipe: USBDevicePipe): Uint8Array
381
382获取原始的USB描述符。
383
384需要调用[usb.getDevices](#usbgetdevices)获取设备列表;调用[usb.requestRight](#usbrequestright)获取设备请求权限;调用[usb.connectDevice](#usbconnectdevice)接口得到devicepipe作为参数。
385
386**系统能力:**  SystemCapability.USB.USBManager
387
388**参数:**
389
390| 参数名 | 类型 | 必填 | 说明 |
391| -------- | -------- | -------- | -------- |
392| pipe | [USBDevicePipe](#usbdevicepipe) | 是 | 用于确定总线号和设备地址。 |
393
394**返回值:**
395
396| 类型 | 说明 |
397| -------- | -------- |
398| Uint8Array | 返回获取的原始数据;失败返回undefined。 |
399
400**示例:**
401
402```ts
403let devicesList: Array<usb.USBDevice> = usb.getDevices();
404if (devicesList.length == 0) {
405  console.log(`device list is empty`);
406}
407
408usb.requestRight(devicesList[0].name);
409let devicepipe: usb.USBDevicePipe = usb.connectDevice(devicesList[0]);
410let ret: Uint8Array = usb.getRawDescriptor(devicepipe);
411```
412
413## usb.getFileDescriptor
414
415getFileDescriptor(pipe: USBDevicePipe): number
416
417获取文件描述符。
418
419需要调用[usb.getDevices](#usbgetdevices)获取设备列表;调用[usb.requestRight](#usbrequestright)获取设备请求权限;调用[usb.connectDevice](#usbconnectdevice)接口得到devicepipe作为参数。
420
421**系统能力:**  SystemCapability.USB.USBManager
422
423**参数:**
424
425| 参数名 | 类型 | 必填 | 说明 |
426| -------- | -------- | -------- | -------- |
427| pipe | [USBDevicePipe](#usbdevicepipe) | 是 | 用于确定总线号和设备地址。 |
428
429**返回值:**
430
431| 类型     | 说明                   |
432| ------ | -------------------- |
433| number | 返回设备对应的文件描述符;失败返回-1。 |
434
435**示例:**
436
437```ts
438let devicesList: Array<usb.USBDevice> = usb.getDevices();
439if (devicesList.length == 0) {
440  console.log(`device list is empty`);
441}
442
443usb.requestRight(devicesList[0].name);
444let devicepipe: usb.USBDevicePipe = usb.connectDevice(devicesList[0]);
445let ret: number = usb.getFileDescriptor(devicepipe);
446```
447
448## usb.controlTransfer
449
450controlTransfer(pipe: USBDevicePipe, controlparam: USBControlParams, timeout ?: number): Promise&lt;number&gt;
451
452控制传输。
453
454需要调用[usb.getDevices](#usbgetdevices)获取设备列表;调用[usb.requestRight](#usbrequestright)获取设备请求权限;调用[usb.connectDevice](#usbconnectdevice)接口得到devicepipe作为参数。
455
456**系统能力:**  SystemCapability.USB.USBManager
457
458**参数:**
459
460| 参数名 | 类型 | 必填 | 说明 |
461| -------- | -------- | -------- | -------- |
462| pipe | [USBDevicePipe](#usbdevicepipe) | 是 | 用于确定设备。 |
463| controlparam | [USBControlParams](#usbcontrolparams) | 是 | 控制传输参数。 |
464| timeout | number | 否 | 超时时间(单位:ms),可选参数,默认为0不超时。 |
465
466**返回值:**
467
468| 类型 | 说明 |
469| -------- | -------- |
470| Promise&lt;number&gt; | Promise对象,获取传输或接收到的数据块大小。失败返回-1。 |
471
472**示例:**
473
474```ts
475class PARA {
476  request: number = 0
477  reqType: usb.USBControlRequestType = 0
478  target: usb.USBRequestTargetType = 0
479  value: number = 0
480  index: number = 0
481  data: Uint8Array = new Uint8Array()
482}
483
484let param: PARA = {
485  request: 0,
486  reqType: 0,
487  target:0,
488  value: 0,
489  index: 0,
490  data: new Uint8Array()
491};
492
493let devicesList: Array<usb.USBDevice> = usb.getDevices();
494if (devicesList.length == 0) {
495  console.log(`device list is empty`);
496}
497
498usb.requestRight(devicesList[0].name);
499let devicepipe: usb.USBDevicePipe = usb.connectDevice(devicesList[0]);
500usb.controlTransfer(devicepipe, param).then((ret: number) => {
501 console.log(`controlTransfer = ${ret}`);
502})
503```
504
505## usb.bulkTransfer
506
507bulkTransfer(pipe: USBDevicePipe, endpoint: USBEndpoint, buffer: Uint8Array, timeout ?: number): Promise&lt;number&gt;
508
509批量传输。
510
511需要调用[usb.getDevices](#usbgetdevices)获取设备信息列表以及endpoint;再调用[usb.requestRight](#usbrequestright)获取设备请求权限;然后调用[usb.connectDevice](#usbconnectdevice)接口得到返回数据devicepipe之后,再次获取接口[usb.claimInterface](#usbclaiminterface);再调用usb.bulkTransfer接口。
512
513**系统能力:**  SystemCapability.USB.USBManager
514
515**参数:**
516
517| 参数名 | 类型 | 必填 | 说明 |
518| -------- | -------- | -------- | -------- |
519| pipe | [USBDevicePipe](#usbdevicepipe) | 是 | 用于确定设备。 |
520| endpoint | [USBEndpoint](#usbendpoint) | 是 | 用于确定传输的端口。 |
521| buffer | Uint8Array | 是 | 用于写入或读取数据的缓冲区。 |
522| timeout | number | 否 | 超时时间(单位:ms),可选参数,默认为0不超时。|
523
524**返回值:**
525
526| 类型 | 说明 |
527| -------- | -------- |
528| Promise&lt;number&gt; | Promise对象,获取传输或接收到的数据块大小。失败返回-1。 |
529
530**示例:**
531
532```ts
533//usb.getDevices 接口返回数据集合,取其中一个设备对象,并获取权限 。
534//把获取到的设备对象作为参数传入usb.connectDevice;当usb.connectDevice接口成功返回之后;
535//才可以调用第三个接口usb.claimInterface.usb.claimInterface 调用成功以后,再调用该接口。
536let devicesList: Array<usb.USBDevice> = usb.getDevices();
537if (devicesList.length == 0) {
538  console.log(`device list is empty`);
539}
540
541let device: usb.USBDevice = devicesList[0];
542usb.requestRight(device.name);
543
544let devicepipe: usb.USBDevicePipe = usb.connectDevice(device);
545let interfaces: usb.USBInterface = device.configs[0].interfaces[0];
546let endpoint: usb.USBEndpoint = device.configs[0].interfaces[0].endpoints[0];
547let ret: number = usb.claimInterface(devicepipe, interfaces);
548let buffer =  new Uint8Array(128);
549usb.bulkTransfer(devicepipe, endpoint, buffer).then((ret: number) => {
550  console.log(`bulkTransfer = ${ret}`);
551});
552```
553
554## usb.closePipe
555
556closePipe(pipe: USBDevicePipe): number
557
558关闭设备消息控制通道。
559
560需要调用[usb.getDevices](#usbgetdevices)获取设备列表;调用[usb.requestRight](#usbrequestright)获取设备请求权限;调用[usb.connectDevice](#usbconnectdevice)得到devicepipe作为参数。
561
562**系统能力:**  SystemCapability.USB.USBManager
563
564**参数:**
565
566| 参数名 | 类型 | 必填 | 说明 |
567| -------- | -------- | -------- | -------- |
568| pipe | [USBDevicePipe](#usbdevicepipe) | 是 | 用于确定USB设备消息控制通道。 |
569
570**返回值:**
571
572| 类型 | 说明 |
573| -------- | -------- |
574| number | 关闭设备消息控制通道成功返回0;关闭设备消息控制通道失败返回其他错误码。 |
575
576**示例:**
577
578```ts
579let devicesList: Array<usb.USBDevice> = usb.getDevices();
580if (devicesList.length == 0) {
581  console.log(`device list is empty`);
582}
583
584usb.requestRight(devicesList[0].name);
585let devicepipe: usb.USBDevicePipe = usb.connectDevice(devicesList[0]);
586let ret: number = usb.closePipe(devicepipe);
587console.log(`closePipe = ${ret}`);
588```
589
590## USBEndpoint
591
592通过USB发送和接收数据的端口。通过[USBInterface](#usbinterface)获取。
593
594**系统能力:** SystemCapability.USB.USBManager
595
596| 名称            | 类型                                        | 必填            |说明            |
597| ------------- | ------------------------------------------- | ------------- |------------- |
598| address       | number                                      | 是 |端点地址。         |
599| attributes    | number                                      | 是 |端点属性。         |
600| interval      | number                                      | 是 |端点间隔。         |
601| maxPacketSize | number                                      | 是 |端点最大数据包大小。    |
602| direction     | [USBRequestDirection](#usbrequestdirection) | 是 |端点的方向。        |
603| number        | number                                      | 是 |端点号。          |
604| type          | number                                      | 是 |端点类型。         |
605| interfaceId   | number                                      | 是 |端点所属的接口的唯一标识。 |
606
607## USBInterface
608
609一个[USBConfiguration](#usbconfiguration)中可以含有多个USBInterface,每个USBInterface提供一个功能。
610
611**系统能力:** SystemCapability.USB.USBManager
612
613| 名称               | 类型                                     | 必填            |说明                    |
614| ---------------- | ---------------------------------------- | ------------- |--------------------- |
615| id               | number                                   | 是 |接口的唯一标识。              |
616| protocol         | number                                   | 是 |接口的协议。                |
617| clazz            | number                                   | 是 |设备类型。                 |
618| subClass         | number                                   | 是 |设备子类。                 |
619| alternateSetting | number                                   | 是 |在同一个接口中的多个描述符中进行切换设置。 |
620| name             | string                                   | 是 |接口名称。                 |
621| endpoints        | Array&lt;[USBEndpoint](#usbendpoint)&gt; | 是 |当前接口所包含的端点。           |
622
623## USBConfiguration
624
625USB配置,一个[USBDevice](#usbdevice)中可以含有多个配置。
626
627**系统能力:** SystemCapability.USB.USBManager
628
629| 名称             | 类型                                             | 必填  |说明              |
630| -------------- | ------------------------------------------------ | --------------- |--------------- |
631| id             | number                                           | 是 |配置的唯一标识。        |
632| attributes     | number                                           | 是 |配置的属性。          |
633| maxPower       | number                                           | 是 |最大功耗,以毫安为单位。    |
634| name           | string                                           | 是 |配置的名称,可以为空。     |
635| isRemoteWakeup | boolean                                          | 是 |检查当前配置是否支持远程唤醒。 |
636| isSelfPowered  | boolean                                          | 是 | 检查当前配置是否支持独立电源。 |
637| interfaces     | Array&nbsp;&lt;[USBInterface](#usbinterface)&gt; | 是 |配置支持的接口属性。      |
638
639## USBDevice
640
641USB设备信息。
642
643**系统能力:** SystemCapability.USB.USBManager
644
645| 名称               | 类型                                 | 必填         |说明         |
646| ---------------- | ------------------------------------ | ---------- |---------- |
647| busNum           | number                               | 是 |总线地址。      |
648| devAddress       | number                               | 是 |设备地址。      |
649| serial           | string                               | 是 |序列号。       |
650| name             | string                               | 是 |设备名字。      |
651| manufacturerName | string                               | 是 | 产商信息。      |
652| productName      | string                               | 是 |产品信息。      |
653| version          | string                               | 是 |版本。        |
654| vendorId         | number                               | 是 |厂商ID。      |
655| productId        | number                               | 是 |产品ID。      |
656| clazz            | number                               | 是 |设备类。       |
657| subClass         | number                               | 是 |设备子类。      |
658| protocol         | number                               | 是 |设备协议码。     |
659| configs          | Array&lt;[USBConfiguration](#usbconfiguration)&gt; | 是 |设备配置描述符信息。 |
660
661## USBDevicePipe
662
663USB设备消息传输通道,用于确定设备。
664
665**系统能力:** SystemCapability.USB.USBManager
666
667| 名称         | 类型   | 必填    |说明    |
668| ---------- | ------ | ----- |----- |
669| busNum     | number |是 | 总线地址。 |
670| devAddress | number |是 | 设备地址。 |
671
672## USBControlParams
673
674控制传输参数。
675
676**系统能力:** SystemCapability.USB.USBManager
677
678| 名称      | 类型                                            | 必填               |说明               |
679| ------- | ----------------------------------------------- | ---------------- |---------------- |
680| request | number                                          | 是   |请求类型。            |
681| target  | [USBRequestTargetType](#usbrequesttargettype)   | 是   |请求目标类型。          |
682| reqType | [USBControlRequestType](#usbcontrolrequesttype) | 是   |请求控制类型。          |
683| value   | number                                          | 是   |请求参数。            |
684| index   | number                                          | 是   |请求参数value对应的索引值。 |
685| data    | Uint8Array                                      | 是   |用于写入或读取的缓冲区。     |
686
687## USBRequestTargetType
688
689请求目标类型。
690
691**系统能力:** SystemCapability.USB.USBManager
692
693| 名称                         | 值   | 说明   |
694| ---------------------------- | ---- | ------ |
695| USB_REQUEST_TARGET_DEVICE    | 0    | 设备。 |
696| USB_REQUEST_TARGET_INTERFACE | 1    | 接口。 |
697| USB_REQUEST_TARGET_ENDPOINT  | 2    | 端点。 |
698| USB_REQUEST_TARGET_OTHER     | 3    | 其他。 |
699
700## USBControlRequestType
701
702控制请求类型。
703
704**系统能力:** SystemCapability.USB.USBManager
705
706| 名称                      | 值   | 说明   |
707| ------------------------- | ---- | ------ |
708| USB_REQUEST_TYPE_STANDARD | 0    | 标准。 |
709| USB_REQUEST_TYPE_CLASS    | 1    | 类。   |
710| USB_REQUEST_TYPE_VENDOR   | 2    | 厂商。 |
711
712## USBRequestDirection
713
714请求方向。
715
716**系统能力:** SystemCapability.USB.USBManager
717
718| 名称                        | 值   | 说明                     |
719| --------------------------- | ---- | ------------------------ |
720| USB_REQUEST_DIR_TO_DEVICE   | 0    | 写数据,主设备往从设备。 |
721| USB_REQUEST_DIR_FROM_DEVICE | 0x80 | 读数据,从设备往主设备。 |
722
723