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

!23639 guidance ArkTs sample code adaption.

Merge pull request !23639 from dufresne_andy/cherry-pick-1693488509
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
import deviceManager from '@ohos.driver.deviceManager'; import deviceManager from '@ohos.driver.deviceManager';
import { BusinessError } from '@ohos.base'; import { BusinessError } from '@ohos.base';
let matchDevice : deviceManager.USBDevice = null; let matchDevice : deviceManager.USBDevice | null = null;
try { try {
let devices : Array<Device> = deviceManager.queryDevices(deviceManager.BusType.USB); let devices : Array<Device> = deviceManager.queryDevices(deviceManager.BusType.USB);
for (let item : Device of devices : Array<Device>) { for (let item : Device of devices : Array<Device>) {
...@@ -45,7 +45,7 @@ ...@@ -45,7 +45,7 @@
break; break;
} }
} }
} catch (error : BusinessError) { } catch (error) {
let errCode = (error as BusinessError).code; let errCode = (error as BusinessError).code;
let message = (error as BusinessError).message; let message = (error as BusinessError).message;
console.error(`Failed to query device. Code is ${errCode}, message is ${message}`); console.error(`Failed to query device. Code is ${errCode}, message is ${message}`);
...@@ -62,19 +62,19 @@ ...@@ -62,19 +62,19 @@
import deviceManager from '@ohos.driver.deviceManager'; import deviceManager from '@ohos.driver.deviceManager';
import { BusinessError } from '@ohos.base'; import { BusinessError } from '@ohos.base';
let remoteObject : Object; let remoteObject : IRemoteObject;
try { try {
deviceManager.bindDevice(matchDevice.deviceId, ((error : BusinessError), (data : Object)) => { deviceManager.bindDevice(matchDevice.deviceId, (error : BusinessError, data : MessageSequence) => {
console.error('Device is disconnected'); console.error('Device is disconnected');
}, ((error : BusinessError), (data : Object)) => { }, (error : BusinessError, data : MessageSequence) => {
if (error) { if (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}`);
return; return;
} }
console.info('bindDevice success'); console.info('bindDevice success');
remoteObject = data.remote; remoteObject = data.remote;
}); });
} catch (error : BusinessError) { } catch (error) {
let errCode = (error as BusinessError).code; let errCode = (error as BusinessError).code;
let message = (error as BusinessError).message; let message = (error as BusinessError).message;
console.error(`bindDevice fail. Code is ${errCode}, message is ${message}`); console.error(`bindDevice fail. Code is ${errCode}, message is ${message}`);
...@@ -94,7 +94,7 @@ ...@@ -94,7 +94,7 @@
let code = 1; let code = 1;
// code和data内容取决于驱动提供的接口 // code和data内容取决于驱动提供的接口
remoteObject.sendMessageRequest(code, data, reply, option) remoteObject.sendMessageRequest(code, data, reply, option)
.then((result : string) => { .then((result : number) => {
console.info('sendMessageRequest finish.'); console.info('sendMessageRequest finish.');
}).catch((error : BusinessError) => { }).catch((error : BusinessError) => {
let errCode = (error as BusinessError).code; let errCode = (error as BusinessError).code;
...@@ -109,7 +109,7 @@ ...@@ -109,7 +109,7 @@
import { BusinessError } from '@ohos.base'; import { BusinessError } from '@ohos.base';
try { try {
deviceManager.unbindDevice(matchDevice.deviceId, (error : BusinessError, data : Object) => { deviceManager.unbindDevice(matchDevice.deviceId, (error : BusinessError, data : MessageSequence) => {
if (error : BusinessError) { if (error : BusinessError) {
let errCode = (error as BusinessError).code; let errCode = (error as BusinessError).code;
let message = (error as BusinessError).message; let message = (error as BusinessError).message;
...@@ -118,7 +118,7 @@ ...@@ -118,7 +118,7 @@
} }
console.info('unbindDevice success'); console.info('unbindDevice success');
}); });
} catch (error : BusinessError) { } catch (error) {
let errCode = (error as BusinessError).code; let errCode = (error as BusinessError).code;
let message = (error as BusinessError).message; let message = (error as BusinessError).message;
console.error('unbindDevice fail. Code is ${errCode}, message is ${message}'); console.error('unbindDevice fail. Code is ${errCode}, message is ${message}');
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册