1e41f4b71Sopenharmony_ci# @ohos.driver.deviceManager (外设管理)(系统接口)
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci本模块主要提供管理外部设备的相关功能,包括查询扩展外设详细信息和查询扩展外设驱动详细信息。
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci>  **说明:**
6e41f4b71Sopenharmony_ci>
7e41f4b71Sopenharmony_ci> * 本模块首批接口从API version 12开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
8e41f4b71Sopenharmony_ci> * 当前页面仅包含本模块的系统接口,其他公开接口请参见[@ohos.driver.deviceManager (外设管理)](js-apis-driver-deviceManager.md)
9e41f4b71Sopenharmony_ci
10e41f4b71Sopenharmony_ci## 导入模块
11e41f4b71Sopenharmony_ci
12e41f4b71Sopenharmony_ci```ts
13e41f4b71Sopenharmony_ciimport { deviceManager } from '@kit.DriverDevelopmentKit';
14e41f4b71Sopenharmony_ci```
15e41f4b71Sopenharmony_ci
16e41f4b71Sopenharmony_ci## deviceManager.queryDeviceInfo
17e41f4b71Sopenharmony_ci
18e41f4b71Sopenharmony_ciqueryDeviceInfo(deviceId?: number): Array<Readonly<DeviceInfo>>
19e41f4b71Sopenharmony_ci
20e41f4b71Sopenharmony_ci查询扩展外设详细信息列表。
21e41f4b71Sopenharmony_ci
22e41f4b71Sopenharmony_ci**系统接口**:此接口为系统接口。
23e41f4b71Sopenharmony_ci
24e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.ACCESS_EXTENSIONAL_DEVICE_DRIVER
25e41f4b71Sopenharmony_ci
26e41f4b71Sopenharmony_ci**系统能力:**  SystemCapability.Driver.ExternalDevice
27e41f4b71Sopenharmony_ci
28e41f4b71Sopenharmony_ci**参数:**
29e41f4b71Sopenharmony_ci
30e41f4b71Sopenharmony_ci| 参数名      | 类型     | 必填  | 说明                     |
31e41f4b71Sopenharmony_ci|----------|--------|-----|------------------------|
32e41f4b71Sopenharmony_ci| deviceId | number | 否   | 设备ID,通过queryDevices获得。 |
33e41f4b71Sopenharmony_ci
34e41f4b71Sopenharmony_ci**返回值:**
35e41f4b71Sopenharmony_ci
36e41f4b71Sopenharmony_ci| 类型                                                     | 说明          |
37e41f4b71Sopenharmony_ci|--------------------------------------------------------|-------------|
38e41f4b71Sopenharmony_ci| Array<Readonly<[DeviceInfo](#deviceinfo)>> | 扩展外设详细信息列表。 |
39e41f4b71Sopenharmony_ci
40e41f4b71Sopenharmony_ci**错误码:**
41e41f4b71Sopenharmony_ci
42e41f4b71Sopenharmony_ci| 错误码ID    | 错误信息                                                                  |
43e41f4b71Sopenharmony_ci|----------|-----------------------------------------------------------------------|
44e41f4b71Sopenharmony_ci| 201      | The permission check failed.                                          |
45e41f4b71Sopenharmony_ci| 202      | Permission denied. A non-system application cannot call a system API. |
46e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1.Incorrect parameter types.        |
47e41f4b71Sopenharmony_ci| 26300001 | ExternalDeviceManager service exception.                              |
48e41f4b71Sopenharmony_ci
49e41f4b71Sopenharmony_ci**示例:**
50e41f4b71Sopenharmony_ci
51e41f4b71Sopenharmony_ci```ts
52e41f4b71Sopenharmony_ciimport { deviceManager } from '@kit.DriverDevelopmentKit';
53e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
54e41f4b71Sopenharmony_ci
55e41f4b71Sopenharmony_citry {
56e41f4b71Sopenharmony_ci  // 12345678为示例deviceId,应用开发时可通过queryDevices查询到相应设备的deviceId作为入参
57e41f4b71Sopenharmony_ci  let deviceInfos : Array<deviceManager.DeviceInfo> = deviceManager.queryDeviceInfo(12345678);
58e41f4b71Sopenharmony_ci  for (let item of deviceInfos) {
59e41f4b71Sopenharmony_ci    console.info(`Device id is ${item.deviceId}`)
60e41f4b71Sopenharmony_ci  }
61e41f4b71Sopenharmony_ci} catch (error) {
62e41f4b71Sopenharmony_ci  let err: BusinessError = error as BusinessError;
63e41f4b71Sopenharmony_ci  console.error(`Failed to query device info. Code is ${err.code}, message is ${err.message}`);
64e41f4b71Sopenharmony_ci}
65e41f4b71Sopenharmony_ci```
66e41f4b71Sopenharmony_ci## deviceManager.queryDriverInfo
67e41f4b71Sopenharmony_ci
68e41f4b71Sopenharmony_ciqueryDriverInfo(driverUid?: string): Array&lt;Readonly&lt;DriverInfo&gt;&gt;
69e41f4b71Sopenharmony_ci
70e41f4b71Sopenharmony_ci查询扩展外设驱动详细信息列表。
71e41f4b71Sopenharmony_ci
72e41f4b71Sopenharmony_ci**系统接口**:此接口为系统接口。
73e41f4b71Sopenharmony_ci
74e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.ACCESS_EXTENSIONAL_DEVICE_DRIVER
75e41f4b71Sopenharmony_ci
76e41f4b71Sopenharmony_ci**系统能力:**  SystemCapability.Driver.ExternalDevice
77e41f4b71Sopenharmony_ci
78e41f4b71Sopenharmony_ci**参数:**
79e41f4b71Sopenharmony_ci
80e41f4b71Sopenharmony_ci| 参数名       | 类型     | 必填  | 说明                         |
81e41f4b71Sopenharmony_ci|-----------|--------|-----|----------------------------|
82e41f4b71Sopenharmony_ci| driverUid | string | 否   | 驱动UID,通过queryDeviceInfo获得。 |
83e41f4b71Sopenharmony_ci
84e41f4b71Sopenharmony_ci**返回值:**
85e41f4b71Sopenharmony_ci
86e41f4b71Sopenharmony_ci| 类型                                                     | 说明            |
87e41f4b71Sopenharmony_ci|--------------------------------------------------------|---------------|
88e41f4b71Sopenharmony_ci| Array&lt;Readonly&lt;[DriverInfo](#driverinfo)&gt;&gt; | 扩展外设驱动详细信息列表。 |
89e41f4b71Sopenharmony_ci
90e41f4b71Sopenharmony_ci**错误码:**
91e41f4b71Sopenharmony_ci
92e41f4b71Sopenharmony_ci| 错误码ID    | 错误信息                                                                  |
93e41f4b71Sopenharmony_ci|----------|-----------------------------------------------------------------------|
94e41f4b71Sopenharmony_ci| 201      | The permission check failed.                                          |
95e41f4b71Sopenharmony_ci| 202      | Permission denied. A non-system application cannot call a system API. |
96e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1.Incorrect parameter types.        |
97e41f4b71Sopenharmony_ci| 26300001 | ExternalDeviceManager service exception.                              |
98e41f4b71Sopenharmony_ci
99e41f4b71Sopenharmony_ci**示例:**
100e41f4b71Sopenharmony_ci
101e41f4b71Sopenharmony_ci```ts
102e41f4b71Sopenharmony_ciimport { deviceManager } from '@kit.DriverDevelopmentKit';
103e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
104e41f4b71Sopenharmony_ci
105e41f4b71Sopenharmony_citry {
106e41f4b71Sopenharmony_ci  // driver-12345为示例driverUid,应用开发时可通过queryDeviceInfo查询到相应设备匹配到的驱动的driverUid作为入参
107e41f4b71Sopenharmony_ci  let driverInfos : Array<deviceManager.DriverInfo> = deviceManager.queryDriverInfo("driver-12345");
108e41f4b71Sopenharmony_ci  for (let item of driverInfos) {
109e41f4b71Sopenharmony_ci    console.info(`driver name is ${item.driverName}`)
110e41f4b71Sopenharmony_ci  }
111e41f4b71Sopenharmony_ci} catch (error) {
112e41f4b71Sopenharmony_ci  let err: BusinessError = error as BusinessError;
113e41f4b71Sopenharmony_ci  console.error(`Failed to query driver info. Code is ${err.code}, message is ${err.message}`);
114e41f4b71Sopenharmony_ci}
115e41f4b71Sopenharmony_ci```
116e41f4b71Sopenharmony_ci
117e41f4b71Sopenharmony_ci## DeviceInfo
118e41f4b71Sopenharmony_ci
119e41f4b71Sopenharmony_ci设备详细信息。
120e41f4b71Sopenharmony_ci
121e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Driver.ExternalDevice
122e41f4b71Sopenharmony_ci
123e41f4b71Sopenharmony_ci| 名称              | 类型      | 必填  | 说明          |
124e41f4b71Sopenharmony_ci|-----------------|---------|-----|-------------|
125e41f4b71Sopenharmony_ci| deviceId        | number  | 是   | 设备ID。       |
126e41f4b71Sopenharmony_ci| isDriverMatched | boolean | 是   | 设备是否匹配到驱动。  |
127e41f4b71Sopenharmony_ci| driverUid       | string  | 否   | 设备匹配的驱动UID。 |
128e41f4b71Sopenharmony_ci
129e41f4b71Sopenharmony_ci## USBDeviceInfo
130e41f4b71Sopenharmony_ci
131e41f4b71Sopenharmony_ciUSB设备详细信息,继承自[DeviceInfo](#deviceinfo)。
132e41f4b71Sopenharmony_ci
133e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Driver.ExternalDevice
134e41f4b71Sopenharmony_ci
135e41f4b71Sopenharmony_ci| 名称                | 类型                                                                 | 必填  | 说明               |
136e41f4b71Sopenharmony_ci|-------------------|--------------------------------------------------------------------|-----|------------------|
137e41f4b71Sopenharmony_ci| vendorId          | number                                                             | 是   | USB设备Vendor ID。  |
138e41f4b71Sopenharmony_ci| productId         | number                                                             | 是   | USB设备Product ID。 |
139e41f4b71Sopenharmony_ci| interfaceDescList | Array&lt;Readonly&lt;[USBInterfaceDesc](#usbinterfacedesc)&gt;&gt; | 是   | USB设备接口描述符列表。    |
140e41f4b71Sopenharmony_ci
141e41f4b71Sopenharmony_ci## USBInterfaceDesc
142e41f4b71Sopenharmony_ci
143e41f4b71Sopenharmony_ciUSB设备接口描述符。
144e41f4b71Sopenharmony_ci
145e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Driver.ExternalDevice
146e41f4b71Sopenharmony_ci
147e41f4b71Sopenharmony_ci| 名称               | 类型     | 必填  | 说明     |
148e41f4b71Sopenharmony_ci|------------------|--------|-----|--------|
149e41f4b71Sopenharmony_ci| bInterfaceNumber | number | 是   | 接口编号。  |
150e41f4b71Sopenharmony_ci| bClass           | number | 是   | 类型代码。  |
151e41f4b71Sopenharmony_ci| bSubClass        | number | 是   | 子类型代码。 |
152e41f4b71Sopenharmony_ci| bProtocol        | number | 是   | 协议代码。  |
153e41f4b71Sopenharmony_ci
154e41f4b71Sopenharmony_ci## DriverInfo
155e41f4b71Sopenharmony_ci
156e41f4b71Sopenharmony_ci驱动详细信息。
157e41f4b71Sopenharmony_ci
158e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Driver.ExternalDevice
159e41f4b71Sopenharmony_ci
160e41f4b71Sopenharmony_ci| 名称            | 类型                                                 | 必填  | 说明             |
161e41f4b71Sopenharmony_ci|---------------|----------------------------------------------------|-----|----------------|
162e41f4b71Sopenharmony_ci| busType       | [BusType](js-apis-driver-deviceManager.md#bustype) | 是   | 总线类型。          |
163e41f4b71Sopenharmony_ci| driverUid     | string                                             | 是   | 驱动Uid。         |
164e41f4b71Sopenharmony_ci| driverName    | string                                             | 是   | 驱动名称。          |
165e41f4b71Sopenharmony_ci| driverVersion | string                                             | 是   | 驱动版本。          |
166e41f4b71Sopenharmony_ci| driverSize    | string                                             | 是   | 驱动大小(单位为Byte)。 |
167e41f4b71Sopenharmony_ci| description   | string                                             | 是   | 驱动描述。          |
168e41f4b71Sopenharmony_ci
169e41f4b71Sopenharmony_ci## USBDriverInfo
170e41f4b71Sopenharmony_ci
171e41f4b71Sopenharmony_ciUSB设备驱动详细信息,继承自[DriverInfo](#driverinfo)。
172e41f4b71Sopenharmony_ci
173e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Driver.ExternalDevice
174e41f4b71Sopenharmony_ci
175e41f4b71Sopenharmony_ci| 名称            | 类型                  | 必填  | 说明                      |
176e41f4b71Sopenharmony_ci|---------------|---------------------|-----|-------------------------|
177e41f4b71Sopenharmony_ci| productIdList | Array&lt;number&gt; | 是   | 驱动支持的USB设备product ID列表。 |
178e41f4b71Sopenharmony_ci| vendorIdList  | Array&lt;number&gt; | 是   | 驱动支持的USB设备vendor ID列表。  |