1e41f4b71Sopenharmony_ci# @ohos.driver.deviceManager (Peripheral Management)
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ciThe **deviceManager** module provides APIs for managing peripheral devices, including querying the peripheral device list and binding or unbinding a peripheral device.
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci>  **Note:**
6e41f4b71Sopenharmony_ci> 
7e41f4b71Sopenharmony_ci> The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8e41f4b71Sopenharmony_ci
9e41f4b71Sopenharmony_ci## Modules to Import
10e41f4b71Sopenharmony_ci
11e41f4b71Sopenharmony_ci```ts
12e41f4b71Sopenharmony_ciimport { deviceManager } from '@kit.DriverDevelopmentKit';
13e41f4b71Sopenharmony_ci```
14e41f4b71Sopenharmony_ci
15e41f4b71Sopenharmony_ci## deviceManager.queryDevices
16e41f4b71Sopenharmony_ci
17e41f4b71Sopenharmony_ciqueryDevices(busType?: number): Array<Readonly<Device>>
18e41f4b71Sopenharmony_ci
19e41f4b71Sopenharmony_ciQueries the list of peripheral devices. If the device has no peripheral device connected, an empty list is returned.
20e41f4b71Sopenharmony_ci
21e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.ACCESS_EXTENSIONAL_DEVICE_DRIVER
22e41f4b71Sopenharmony_ci
23e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Driver.ExternalDevice
24e41f4b71Sopenharmony_ci
25e41f4b71Sopenharmony_ci**Parameters**
26e41f4b71Sopenharmony_ci
27e41f4b71Sopenharmony_ci| Name | Type  | Mandatory| Description                                |
28e41f4b71Sopenharmony_ci| ------- | ------ | ---- | ------------------------------------ |
29e41f4b71Sopenharmony_ci| busType | number | No  | Bus type of the peripheral device to query. If this parameter is left blank, all types of peripheral devices are queried.|
30e41f4b71Sopenharmony_ci
31e41f4b71Sopenharmony_ci**Return value**
32e41f4b71Sopenharmony_ci
33e41f4b71Sopenharmony_ci| Type                                          | Description          |
34e41f4b71Sopenharmony_ci| ---------------------------------------------- | -------------- |
35e41f4b71Sopenharmony_ci| Array<Readonly<[Device](#device)>> | List of peripheral devices obtained.|
36e41f4b71Sopenharmony_ci
37e41f4b71Sopenharmony_ci**Error codes**
38e41f4b71Sopenharmony_ci
39e41f4b71Sopenharmony_ci| ID| Error Message                                |
40e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- |
41e41f4b71Sopenharmony_ci| 201      | The permission check failed.             |
42e41f4b71Sopenharmony_ci| 401      | The parameter check failed.              |
43e41f4b71Sopenharmony_ci| 22900001 | ExternalDeviceManager service exception. |
44e41f4b71Sopenharmony_ci
45e41f4b71Sopenharmony_ci**Example**
46e41f4b71Sopenharmony_ci
47e41f4b71Sopenharmony_ci```ts
48e41f4b71Sopenharmony_ciimport { deviceManager } from '@kit.DriverDevelopmentKit';
49e41f4b71Sopenharmony_ci
50e41f4b71Sopenharmony_citry {
51e41f4b71Sopenharmony_ci  let devices : Array<deviceManager.Device> = deviceManager.queryDevices(deviceManager.BusType.USB);
52e41f4b71Sopenharmony_ci  for (let item of devices) {
53e41f4b71Sopenharmony_ci    let device : deviceManager.USBDevice = item as deviceManager.USBDevice;
54e41f4b71Sopenharmony_ci    console.info(`Device id is ${device.deviceId}`)
55e41f4b71Sopenharmony_ci  }
56e41f4b71Sopenharmony_ci} catch (error) {
57e41f4b71Sopenharmony_ci  console.error(`Failed to query device. Code is ${error.code}, message is ${error.message}`);
58e41f4b71Sopenharmony_ci}
59e41f4b71Sopenharmony_ci```
60e41f4b71Sopenharmony_ci
61e41f4b71Sopenharmony_ci## deviceManager.bindDevice
62e41f4b71Sopenharmony_ci
63e41f4b71Sopenharmony_cibindDevice(deviceId: number, onDisconnect: AsyncCallback&lt;number&gt;,
64e41f4b71Sopenharmony_ci  callback: AsyncCallback&lt;{deviceId: number; remote: rpc.IRemoteObject;}&gt;): void;
65e41f4b71Sopenharmony_ci
66e41f4b71Sopenharmony_ciBinds a peripheral device based on the device information returned by **queryDevices()**. This API uses an asynchronous callback to return the result.
67e41f4b71Sopenharmony_ci
68e41f4b71Sopenharmony_ciYou can use [deviceManager.queryDevices](#devicemanagerquerydevices) to obtain the peripheral device information first.
69e41f4b71Sopenharmony_ci
70e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.ACCESS_EXTENSIONAL_DEVICE_DRIVER
71e41f4b71Sopenharmony_ci
72e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Driver.ExternalDevice
73e41f4b71Sopenharmony_ci
74e41f4b71Sopenharmony_ci**Parameters**
75e41f4b71Sopenharmony_ci
76e41f4b71Sopenharmony_ci| Name      | Type                                                                                                | Mandatory| Description                                  |
77e41f4b71Sopenharmony_ci| ------------ | ---------------------------------------------------------------------------------------------------- | ---- | -------------------------------------- |
78e41f4b71Sopenharmony_ci| deviceId     | number                                                                                               | Yes  | Device ID, which can be obtained by **queryDevices**.          |
79e41f4b71Sopenharmony_ci| onDisconnect | AsyncCallback&lt;number&gt;                                                                          | Yes  | Callback to be invoked when the bound peripheral device is disconnected.                    |
80e41f4b71Sopenharmony_ci| callback     | AsyncCallback&lt;{deviceId: number; remote: [rpc.IRemoteObject](../apis-ipc-kit/js-apis-rpc.md#iremoteobject);}&gt; | Yes  | Callback invoked to return the communication object of the peripheral device bound.|
81e41f4b71Sopenharmony_ci
82e41f4b71Sopenharmony_ci**Error codes**
83e41f4b71Sopenharmony_ci
84e41f4b71Sopenharmony_ci| ID| Error Message                                |
85e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- |
86e41f4b71Sopenharmony_ci| 201      | The permission check failed.              |
87e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. |
88e41f4b71Sopenharmony_ci| 22900001 | ExternalDeviceManager service exception. |
89e41f4b71Sopenharmony_ci
90e41f4b71Sopenharmony_ci**Example**
91e41f4b71Sopenharmony_ci
92e41f4b71Sopenharmony_ci```ts
93e41f4b71Sopenharmony_ciimport { deviceManager } from '@kit.DriverDevelopmentKit';
94e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
95e41f4b71Sopenharmony_ciimport { rpc } from '@kit.IPCKit';
96e41f4b71Sopenharmony_ci
97e41f4b71Sopenharmony_ciinterface DataType {
98e41f4b71Sopenharmony_ci  deviceId : number;
99e41f4b71Sopenharmony_ci  remote : rpc.IRemoteObject;
100e41f4b71Sopenharmony_ci}
101e41f4b71Sopenharmony_ci
102e41f4b71Sopenharmony_citry {
103e41f4b71Sopenharmony_ci  // For example, deviceId is 12345678. You can use queryDevices() to obtain the deviceId.
104e41f4b71Sopenharmony_ci  deviceManager.bindDevice(12345678, (error : BusinessError, data : number) => {
105e41f4b71Sopenharmony_ci    console.error(`Device is disconnected`);
106e41f4b71Sopenharmony_ci  }, (error : BusinessError, data : DataType) => {
107e41f4b71Sopenharmony_ci    if (error) {
108e41f4b71Sopenharmony_ci      console.error(`bindDevice async fail. Code is ${error.code}, message is ${error.message}`);
109e41f4b71Sopenharmony_ci      return;
110e41f4b71Sopenharmony_ci    }
111e41f4b71Sopenharmony_ci    console.info(`bindDevice success`);
112e41f4b71Sopenharmony_ci  });
113e41f4b71Sopenharmony_ci} catch (error) {
114e41f4b71Sopenharmony_ci  console.error(`bindDevice fail. Code is ${error.code}, message is ${error.message}`);
115e41f4b71Sopenharmony_ci}
116e41f4b71Sopenharmony_ci```
117e41f4b71Sopenharmony_ci
118e41f4b71Sopenharmony_ci## deviceManager.bindDeviceDriver<sup>11+</sup>
119e41f4b71Sopenharmony_cibindDeviceDriver(deviceId: number, onDisconnect: AsyncCallback&lt;number&gt;,
120e41f4b71Sopenharmony_ci  callback: AsyncCallback&lt;RemoteDeviceDriver&gt;): void;
121e41f4b71Sopenharmony_ci
122e41f4b71Sopenharmony_ciBinds a peripheral device based on the device information returned by **queryDevices()**. This API uses an asynchronous callback to return the result.
123e41f4b71Sopenharmony_ci
124e41f4b71Sopenharmony_ciYou can use [deviceManager.queryDevices](#devicemanagerquerydevices) to obtain the peripheral device information first.
125e41f4b71Sopenharmony_ci
126e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.ACCESS_EXTENSIONAL_DEVICE_DRIVER
127e41f4b71Sopenharmony_ci
128e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Driver.ExternalDevice
129e41f4b71Sopenharmony_ci
130e41f4b71Sopenharmony_ci**Parameters**
131e41f4b71Sopenharmony_ci
132e41f4b71Sopenharmony_ci| Name      | Type                       | Mandatory| Description                        |
133e41f4b71Sopenharmony_ci| ------------ | --------------------------- | ---- | ---------------------------- |
134e41f4b71Sopenharmony_ci| deviceId     | number                      | Yes  | Device ID, which can be obtained by **queryDevices**.|
135e41f4b71Sopenharmony_ci| onDisconnect | AsyncCallback&lt;number&gt; | Yes  | Callback to be invoked when the bound peripheral device is disconnected.          |
136e41f4b71Sopenharmony_ci| callback     | AsyncCallback&lt;RemoteDeviceDriver&gt;| Yes| Binding result, including the device ID and remote object.|
137e41f4b71Sopenharmony_ci
138e41f4b71Sopenharmony_ci**Error codes**
139e41f4b71Sopenharmony_ci
140e41f4b71Sopenharmony_ci| ID| Error Message                                |
141e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- |
142e41f4b71Sopenharmony_ci| 201      | The permission check failed.             |
143e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. |
144e41f4b71Sopenharmony_ci| 22900001 | ExternalDeviceManager service exception. |
145e41f4b71Sopenharmony_ci
146e41f4b71Sopenharmony_ci**Example**
147e41f4b71Sopenharmony_ci
148e41f4b71Sopenharmony_ci```ts
149e41f4b71Sopenharmony_ciimport { deviceManager } from '@kit.DriverDevelopmentKit';
150e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
151e41f4b71Sopenharmony_ciimport { rpc } from '@kit.IPCKit';
152e41f4b71Sopenharmony_ci
153e41f4b71Sopenharmony_citry {
154e41f4b71Sopenharmony_ci  // For example, deviceId is 12345678. You can use queryDevices() to obtain the deviceId.
155e41f4b71Sopenharmony_ci  deviceManager.bindDeviceDriver(12345678, (error : BusinessError, data : number) => {
156e41f4b71Sopenharmony_ci    console.error(`Device is disconnected`);
157e41f4b71Sopenharmony_ci  }, (error : BusinessError, data : deviceManager.RemoteDeviceDriver) => {
158e41f4b71Sopenharmony_ci    if (error) {
159e41f4b71Sopenharmony_ci      console.error(`bindDeviceDriver async fail. Code is ${error.code}, message is ${error.message}`);
160e41f4b71Sopenharmony_ci      return;
161e41f4b71Sopenharmony_ci    }
162e41f4b71Sopenharmony_ci    console.info(`bindDeviceDriver success`);
163e41f4b71Sopenharmony_ci  });
164e41f4b71Sopenharmony_ci} catch (error) {
165e41f4b71Sopenharmony_ci  console.error(`bindDeviceDriver fail. Code is ${error.code}, message is ${error.message}`);
166e41f4b71Sopenharmony_ci}
167e41f4b71Sopenharmony_ci```
168e41f4b71Sopenharmony_ci
169e41f4b71Sopenharmony_ci## deviceManager.bindDevice
170e41f4b71Sopenharmony_ci
171e41f4b71Sopenharmony_cibindDevice(deviceId: number, onDisconnect: AsyncCallback&lt;number&gt;): Promise&lt;{deviceId: number;
172e41f4b71Sopenharmony_ci  remote: rpc.IRemoteObject;}&gt;;
173e41f4b71Sopenharmony_ci
174e41f4b71Sopenharmony_ciBinds a peripheral device based on the device information returned by **queryDevices()**. This API uses an asynchronous callback to return the result.
175e41f4b71Sopenharmony_ci
176e41f4b71Sopenharmony_ciYou need to use [deviceManager.queryDevices](#devicemanagerquerydevices) to obtain the peripheral device information first.
177e41f4b71Sopenharmony_ci
178e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.ACCESS_EXTENSIONAL_DEVICE_DRIVER
179e41f4b71Sopenharmony_ci
180e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Driver.ExternalDevice
181e41f4b71Sopenharmony_ci
182e41f4b71Sopenharmony_ci**Parameters**
183e41f4b71Sopenharmony_ci
184e41f4b71Sopenharmony_ci| Name      | Type                       | Mandatory| Description                        |
185e41f4b71Sopenharmony_ci| ------------ | --------------------------- | ---- | ---------------------------- |
186e41f4b71Sopenharmony_ci| deviceId     | number                      | Yes  | Device ID, which can be obtained by **queryDevices**.|
187e41f4b71Sopenharmony_ci| onDisconnect | AsyncCallback&lt;number&gt; | Yes  | Callback to be invoked when the bound peripheral device is disconnected.          |
188e41f4b71Sopenharmony_ci
189e41f4b71Sopenharmony_ci**Return value**
190e41f4b71Sopenharmony_ci
191e41f4b71Sopenharmony_ci| Type                                                                                          | Description                                        |
192e41f4b71Sopenharmony_ci| ---------------------------------------------------------------------------------------------- | -------------------------------------------- |
193e41f4b71Sopenharmony_ci| Promise&lt;{deviceId: number; remote: [rpc.IRemoteObject](../apis-ipc-kit/js-apis-rpc.md#iremoteobject);}&gt; | Promise used to return the device ID and **IRemoteObject** object.|
194e41f4b71Sopenharmony_ci
195e41f4b71Sopenharmony_ci**Error codes**
196e41f4b71Sopenharmony_ci
197e41f4b71Sopenharmony_ci| ID| Error Message                                |
198e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- |
199e41f4b71Sopenharmony_ci| 201      | The permission check failed.             |
200e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. |
201e41f4b71Sopenharmony_ci| 22900001 | ExternalDeviceManager service exception. |
202e41f4b71Sopenharmony_ci
203e41f4b71Sopenharmony_ci**Example**
204e41f4b71Sopenharmony_ci
205e41f4b71Sopenharmony_ci```ts
206e41f4b71Sopenharmony_ciimport { deviceManager } from '@kit.DriverDevelopmentKit';
207e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
208e41f4b71Sopenharmony_ci
209e41f4b71Sopenharmony_citry {
210e41f4b71Sopenharmony_ci  // For example, deviceId is 12345678. You can use queryDevices() to obtain the deviceId.
211e41f4b71Sopenharmony_ci  deviceManager.bindDevice(12345678, (error : BusinessError, data : number) => {
212e41f4b71Sopenharmony_ci    console.error(`Device is disconnected`);
213e41f4b71Sopenharmony_ci  }).then(data => {
214e41f4b71Sopenharmony_ci    console.info(`bindDevice success, Device_Id is ${data.deviceId}.
215e41f4b71Sopenharmony_ci    remote is ${data.remote != null ? data.remote.getDescriptor() : "null"}`);
216e41f4b71Sopenharmony_ci  }, (error: BusinessError) => {
217e41f4b71Sopenharmony_ci    console.error(`bindDevice async fail. Code is ${error.code}, message is ${error.message}`);
218e41f4b71Sopenharmony_ci  });
219e41f4b71Sopenharmony_ci} catch (error) {
220e41f4b71Sopenharmony_ci  console.error(`bindDevice fail. Code is ${error.code}, message is ${error.message}`);
221e41f4b71Sopenharmony_ci}
222e41f4b71Sopenharmony_ci```
223e41f4b71Sopenharmony_ci## deviceManager.bindDeviceDriver<sup>11+</sup>
224e41f4b71Sopenharmony_ci
225e41f4b71Sopenharmony_cibindDeviceDriver(deviceId: number, onDisconnect: AsyncCallback&lt;number&gt;): Promise&lt;RemoteDeviceDriver&gt;;
226e41f4b71Sopenharmony_ci
227e41f4b71Sopenharmony_ciBinds a peripheral device based on the device information returned by **queryDevices()**. This API uses an asynchronous callback to return the result.
228e41f4b71Sopenharmony_ci
229e41f4b71Sopenharmony_ciYou need to use [deviceManager.queryDevices](#devicemanagerquerydevices) to obtain the peripheral device information first.
230e41f4b71Sopenharmony_ci
231e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.ACCESS_EXTENSIONAL_DEVICE_DRIVER
232e41f4b71Sopenharmony_ci
233e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Driver.ExternalDevice
234e41f4b71Sopenharmony_ci
235e41f4b71Sopenharmony_ci**Parameters**
236e41f4b71Sopenharmony_ci
237e41f4b71Sopenharmony_ci| Name      | Type                       | Mandatory| Description                        |
238e41f4b71Sopenharmony_ci| ------------ | --------------------------- | ---- | ---------------------------- |
239e41f4b71Sopenharmony_ci| deviceId     | number                      | Yes  | Device ID, which can be obtained by **queryDevices**.|
240e41f4b71Sopenharmony_ci| onDisconnect | AsyncCallback&lt;number&gt; | Yes  | Callback to be invoked when the bound peripheral device is disconnected.          |
241e41f4b71Sopenharmony_ci
242e41f4b71Sopenharmony_ci**Return value**
243e41f4b71Sopenharmony_ci
244e41f4b71Sopenharmony_ci| Type                             | Description                                     |
245e41f4b71Sopenharmony_ci| --------------------------------- | -----------------------------------------|
246e41f4b71Sopenharmony_ci| Promise&lt;RemoteDeviceDriver&gt; | Promise used to return a **RemoteDeviceDriver** object.|
247e41f4b71Sopenharmony_ci
248e41f4b71Sopenharmony_ci**Error codes**
249e41f4b71Sopenharmony_ci
250e41f4b71Sopenharmony_ci| ID| Error Message                                |
251e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- |
252e41f4b71Sopenharmony_ci| 201      | The permission check failed.             |
253e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. |
254e41f4b71Sopenharmony_ci| 22900001 | ExternalDeviceManager service exception. |
255e41f4b71Sopenharmony_ci
256e41f4b71Sopenharmony_ci**Example**
257e41f4b71Sopenharmony_ci
258e41f4b71Sopenharmony_ci```ts
259e41f4b71Sopenharmony_ciimport { deviceManager } from '@kit.DriverDevelopmentKit';
260e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
261e41f4b71Sopenharmony_ci
262e41f4b71Sopenharmony_citry {
263e41f4b71Sopenharmony_ci  // For example, deviceId is 12345678. You can use queryDevices() to obtain the deviceId.
264e41f4b71Sopenharmony_ci  deviceManager.bindDeviceDriver(12345678, (error : BusinessError, data : number) => {
265e41f4b71Sopenharmony_ci    console.error(`Device is disconnected`);
266e41f4b71Sopenharmony_ci  }).then((data: deviceManager.RemoteDeviceDriver) => {
267e41f4b71Sopenharmony_ci    console.info(`bindDeviceDriver success, Device_Id is ${data.deviceId}.
268e41f4b71Sopenharmony_ci    remote is ${data.remote != null ? data.remote.getDescriptor() : "null"}`);
269e41f4b71Sopenharmony_ci  }, (error: BusinessError) => {
270e41f4b71Sopenharmony_ci    console.error(`bindDeviceDriver async fail. Code is ${error.code}, message is ${error.message}`);
271e41f4b71Sopenharmony_ci  });
272e41f4b71Sopenharmony_ci} catch (error) {
273e41f4b71Sopenharmony_ci  console.error(`bindDeviceDriver fail. Code is ${error.code}, message is ${error.message}`);
274e41f4b71Sopenharmony_ci}
275e41f4b71Sopenharmony_ci```
276e41f4b71Sopenharmony_ci
277e41f4b71Sopenharmony_ci## deviceManager.unbindDevice
278e41f4b71Sopenharmony_ci
279e41f4b71Sopenharmony_ciunbindDevice(deviceId: number, callback: AsyncCallback&lt;number&gt;): void
280e41f4b71Sopenharmony_ci
281e41f4b71Sopenharmony_ciUnbinds a peripheral device. This API uses an asynchronous callback to return the result.
282e41f4b71Sopenharmony_ci
283e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.ACCESS_EXTENSIONAL_DEVICE_DRIVER
284e41f4b71Sopenharmony_ci
285e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Driver.ExternalDevice
286e41f4b71Sopenharmony_ci
287e41f4b71Sopenharmony_ci**Parameters**
288e41f4b71Sopenharmony_ci
289e41f4b71Sopenharmony_ci| Name  | Type                       | Mandatory| Description                          |
290e41f4b71Sopenharmony_ci| -------- | --------------------------- | ---- | ------------------------------ |
291e41f4b71Sopenharmony_ci| deviceId | number                      | Yes  | Device ID, which can be obtained by **queryDevices**.|
292e41f4b71Sopenharmony_ci| callback | AsyncCallback&lt;number&gt; | Yes  | Callback invoked to return the result.              |
293e41f4b71Sopenharmony_ci
294e41f4b71Sopenharmony_ci**Error codes**
295e41f4b71Sopenharmony_ci
296e41f4b71Sopenharmony_ci| ID| Error Message                                |
297e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- |
298e41f4b71Sopenharmony_ci| 201      | The permission check failed.             |
299e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
300e41f4b71Sopenharmony_ci| 22900001 | ExternalDeviceManager service exception. |
301e41f4b71Sopenharmony_ci
302e41f4b71Sopenharmony_ci**Example**
303e41f4b71Sopenharmony_ci
304e41f4b71Sopenharmony_ci```ts
305e41f4b71Sopenharmony_ciimport { deviceManager } from '@kit.DriverDevelopmentKit';
306e41f4b71Sopenharmony_ci
307e41f4b71Sopenharmony_citry {
308e41f4b71Sopenharmony_ci  // For example, deviceId is 12345678. You can use queryDevices() to obtain the deviceId.
309e41f4b71Sopenharmony_ci  deviceManager.unbindDevice(12345678, (error : BusinessError, data : number) => {
310e41f4b71Sopenharmony_ci    if (error) {
311e41f4b71Sopenharmony_ci      console.error(`unbindDevice async fail. Code is ${error.code}, message is ${error.message}`);
312e41f4b71Sopenharmony_ci      return;
313e41f4b71Sopenharmony_ci    }
314e41f4b71Sopenharmony_ci    console.info(`unbindDevice success`);
315e41f4b71Sopenharmony_ci  });
316e41f4b71Sopenharmony_ci} catch (error) {
317e41f4b71Sopenharmony_ci  console.error(`unbindDevice fail. Code is ${error.code}, message is ${error.message}`);
318e41f4b71Sopenharmony_ci}
319e41f4b71Sopenharmony_ci```
320e41f4b71Sopenharmony_ci## deviceManager.unbindDevice
321e41f4b71Sopenharmony_ci
322e41f4b71Sopenharmony_ciunbindDevice(deviceId: number): Promise&lt;number&gt;
323e41f4b71Sopenharmony_ci
324e41f4b71Sopenharmony_ciUnbinds a peripheral device. This API uses an asynchronous callback to return the result.
325e41f4b71Sopenharmony_ci
326e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.ACCESS_EXTENSIONAL_DEVICE_DRIVER
327e41f4b71Sopenharmony_ci
328e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Driver.ExternalDevice
329e41f4b71Sopenharmony_ci
330e41f4b71Sopenharmony_ci**Parameters**
331e41f4b71Sopenharmony_ci
332e41f4b71Sopenharmony_ci| Name  | Type  | Mandatory| Description                          |
333e41f4b71Sopenharmony_ci| -------- | ------ | ---- | ------------------------------ |
334e41f4b71Sopenharmony_ci| deviceId | number | Yes  | Device ID, which can be obtained by **queryDevices**.|
335e41f4b71Sopenharmony_ci
336e41f4b71Sopenharmony_ci**Error codes**
337e41f4b71Sopenharmony_ci
338e41f4b71Sopenharmony_ci| ID| Error Message                                |
339e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- |
340e41f4b71Sopenharmony_ci| 201      | The permission check failed.             |
341e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. |
342e41f4b71Sopenharmony_ci| 22900001 | ExternalDeviceManager service exception. |
343e41f4b71Sopenharmony_ci
344e41f4b71Sopenharmony_ci**Return value**
345e41f4b71Sopenharmony_ci
346e41f4b71Sopenharmony_ci| Type                 | Description                     |
347e41f4b71Sopenharmony_ci| --------------------- | ------------------------- |
348e41f4b71Sopenharmony_ci| Promise&lt;number&gt; | Promise used to return the device ID.|
349e41f4b71Sopenharmony_ci
350e41f4b71Sopenharmony_ci**Example**
351e41f4b71Sopenharmony_ci
352e41f4b71Sopenharmony_ci```ts
353e41f4b71Sopenharmony_ciimport { deviceManager } from '@kit.DriverDevelopmentKit';
354e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
355e41f4b71Sopenharmony_ci
356e41f4b71Sopenharmony_citry {
357e41f4b71Sopenharmony_ci  // For example, deviceId is 12345678. You can use queryDevices() to obtain the deviceId.
358e41f4b71Sopenharmony_ci  deviceManager.unbindDevice(12345678).then((data : number) => {
359e41f4b71Sopenharmony_ci    console.info(`unbindDevice success, Device_Id is ${data}.`);
360e41f4b71Sopenharmony_ci  }, (error : BusinessError) => {
361e41f4b71Sopenharmony_ci    console.error(`unbindDevice async fail. Code is ${error.code}, message is ${error.message}`);
362e41f4b71Sopenharmony_ci  });
363e41f4b71Sopenharmony_ci} catch (error) {
364e41f4b71Sopenharmony_ci  console.error(`unbindDevice fail. Code is ${error.code}, message is ${error.message}`);
365e41f4b71Sopenharmony_ci}
366e41f4b71Sopenharmony_ci```
367e41f4b71Sopenharmony_ci
368e41f4b71Sopenharmony_ci## Device
369e41f4b71Sopenharmony_ci
370e41f4b71Sopenharmony_ciRepresents the peripheral device information.
371e41f4b71Sopenharmony_ci
372e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Driver.ExternalDevice
373e41f4b71Sopenharmony_ci
374e41f4b71Sopenharmony_ci| Name       | Type               | Mandatory| Description      |
375e41f4b71Sopenharmony_ci| ----------- | ------------------- | ---- | ---------- |
376e41f4b71Sopenharmony_ci| busType     | [BusType](#bustype) | Yes  | Bus type.|
377e41f4b71Sopenharmony_ci| deviceId    | number              | Yes  | Device ID.  |
378e41f4b71Sopenharmony_ci| description | string              | Yes  | Description of the peripheral device.|
379e41f4b71Sopenharmony_ci
380e41f4b71Sopenharmony_ci## USBDevice
381e41f4b71Sopenharmony_ci
382e41f4b71Sopenharmony_ciUSB device information, which is inherited from [Device](#device).
383e41f4b71Sopenharmony_ci
384e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Driver.ExternalDevice
385e41f4b71Sopenharmony_ci
386e41f4b71Sopenharmony_ci| Name     | Type  | Mandatory| Description               |
387e41f4b71Sopenharmony_ci| --------- | ------ | ---- | ------------------- |
388e41f4b71Sopenharmony_ci| vendorId  | number | Yes  | Vendor ID of the USB device. |
389e41f4b71Sopenharmony_ci| productId | number | Yes  | Product ID of the USB device.|
390e41f4b71Sopenharmony_ci
391e41f4b71Sopenharmony_ci## BusType
392e41f4b71Sopenharmony_ci
393e41f4b71Sopenharmony_ciEnumerates the device bus types.
394e41f4b71Sopenharmony_ci
395e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Driver.ExternalDevice
396e41f4b71Sopenharmony_ci
397e41f4b71Sopenharmony_ci| Name| Value | Description         |
398e41f4b71Sopenharmony_ci| ---- | --- | ------------- |
399e41f4b71Sopenharmony_ci| USB  | 1   | USB bus.|
400e41f4b71Sopenharmony_ci
401e41f4b71Sopenharmony_ci## RemoteDeviceDriver<sup>11+</sup>
402e41f4b71Sopenharmony_ci
403e41f4b71Sopenharmony_ciRepresents information about a remote device driver.
404e41f4b71Sopenharmony_ci
405e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Driver.ExternalDevice
406e41f4b71Sopenharmony_ci
407e41f4b71Sopenharmony_ci| Name     | Type  | Mandatory| Description               |
408e41f4b71Sopenharmony_ci| --------- | ------ | ---- | ------------------- |
409e41f4b71Sopenharmony_ci| deviceId<sup>11+</sup>  | number | Yes  | Device ID. |
410e41f4b71Sopenharmony_ci| remote<sup>11+</sup> | [rpc.IRemoteObject](../apis-ipc-kit/js-apis-rpc.md#iremoteobject) | Yes  | Remote driver object.|
411