From 2bdf28fda258aa3849509626b24f586e21fc4eab Mon Sep 17 00:00:00 2001 From: dufresne_andy Date: Wed, 6 Sep 2023 08:29:11 +0000 Subject: [PATCH] Description: guidance sample code arkts adaption Feature or Bugfix:Bugfix Binary Source: No Signed-off-by: dufresne_andy --- .../reference/apis/js-apis-driver-deviceManager.md | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/zh-cn/application-dev/reference/apis/js-apis-driver-deviceManager.md b/zh-cn/application-dev/reference/apis/js-apis-driver-deviceManager.md index 5a76498ddb..a203dad324 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-driver-deviceManager.md +++ b/zh-cn/application-dev/reference/apis/js-apis-driver-deviceManager.md @@ -8,8 +8,9 @@ ## 导入模块 -```js +```ts import deviceManager from "@ohos.driver.deviceManager"; +import { BusinessError } from '@ohos.base'; ``` ## deviceManager.queryDevices @@ -43,8 +44,8 @@ queryDevices(busType?: number): Array<Readonly<Device>> ```js try { - let devices = deviceManager.queryDevices(deviceManager.BusType.USB); - for (let item of devices) { + let devices : Array = deviceManager.queryDevices(deviceManager.BusType.USB); + for (let item : Device of devices : Array) { console.info('Device id is ${item.deviceId}') } } catch (error) { @@ -83,7 +84,7 @@ bindDevice(deviceId: number, onDisconnect: AsyncCallback<number>, ```js try { // 12345678为示例deviceId,应用开发时可通过queryDevices查询到相应设备的deviceId作为入参 - deviceManager.bindDevice(12345678, (error, data) => { + deviceManager.bindDevice(12345678, (error : BusinessError, data : MessageSequence) => { console.error('Device is disconnected'); }, (error, data) => { if (error) { @@ -137,7 +138,7 @@ try { console.error('Device is disconnected'); }).then(data => { console.info('bindDevice success'); - }, error => { + }, (error : BusinessError) => { console.error('bindDevice async fail. Code is ${error.code}, message is ${error.message}'); }); } catch (error) { @@ -217,7 +218,7 @@ try { // 12345678为示例deviceId,应用开发时可通过queryDevices查询到相应设备的deviceId作为入参 deviceManager.unbindDevice(12345678).then(data => { console.info('unbindDevice success'); - }, error => { + }, (error : BusinessError) => { console.error('unbindDevice async fail. Code is ${error.code}, message is ${error.message}'); }); } catch (error) { -- GitLab