未验证 提交 9c4315b0 编写于 作者: O openharmony_ci 提交者: Gitee

!24142 guidance ArkTs sample code adaption

Merge pull request !24142 from dufresne_andy/master
...@@ -8,8 +8,9 @@ ...@@ -8,8 +8,9 @@
## 导入模块 ## 导入模块
```js ```ts
import deviceManager from "@ohos.driver.deviceManager"; import deviceManager from "@ohos.driver.deviceManager";
import { BusinessError } from '@ohos.base';
``` ```
## deviceManager.queryDevices ## deviceManager.queryDevices
...@@ -43,8 +44,8 @@ queryDevices(busType?: number): Array<Readonly<Device>> ...@@ -43,8 +44,8 @@ queryDevices(busType?: number): Array<Readonly<Device>>
```js ```js
try { try {
let devices = deviceManager.queryDevices(deviceManager.BusType.USB); let devices : Array<Device> = deviceManager.queryDevices(deviceManager.BusType.USB);
for (let item of devices) { for (let item : Device of devices : Array<Device>) {
console.info('Device id is ${item.deviceId}') console.info('Device id is ${item.deviceId}')
} }
} catch (error) { } catch (error) {
...@@ -83,7 +84,7 @@ bindDevice(deviceId: number, onDisconnect: AsyncCallback&lt;number&gt;, ...@@ -83,7 +84,7 @@ bindDevice(deviceId: number, onDisconnect: AsyncCallback&lt;number&gt;,
```js ```js
try { try {
// 12345678为示例deviceId,应用开发时可通过queryDevices查询到相应设备的deviceId作为入参 // 12345678为示例deviceId,应用开发时可通过queryDevices查询到相应设备的deviceId作为入参
deviceManager.bindDevice(12345678, (error, data) => { deviceManager.bindDevice(12345678, (error : BusinessError, data : MessageSequence) => {
console.error('Device is disconnected'); console.error('Device is disconnected');
}, (error, data) => { }, (error, data) => {
if (error) { if (error) {
...@@ -137,7 +138,7 @@ try { ...@@ -137,7 +138,7 @@ try {
console.error('Device is disconnected'); console.error('Device is disconnected');
}).then(data => { }).then(data => {
console.info('bindDevice success'); console.info('bindDevice success');
}, error => { }, (error : BusinessError) => {
console.error('bindDevice async fail. Code is ${error.code}, message is ${error.message}'); console.error('bindDevice async fail. Code is ${error.code}, message is ${error.message}');
}); });
} catch (error) { } catch (error) {
...@@ -217,7 +218,7 @@ try { ...@@ -217,7 +218,7 @@ try {
// 12345678为示例deviceId,应用开发时可通过queryDevices查询到相应设备的deviceId作为入参 // 12345678为示例deviceId,应用开发时可通过queryDevices查询到相应设备的deviceId作为入参
deviceManager.unbindDevice(12345678).then(data => { deviceManager.unbindDevice(12345678).then(data => {
console.info('unbindDevice success'); console.info('unbindDevice success');
}, error => { }, (error : BusinessError) => {
console.error('unbindDevice async fail. Code is ${error.code}, message is ${error.message}'); console.error('unbindDevice async fail. Code is ${error.code}, message is ${error.message}');
}); });
} catch (error) { } catch (error) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册