未验证 提交 ad15f9e6 编写于 作者: 葛亚芳 提交者: Gitee

update zh-cn/application-dev/device/usb-guidelines.md.

Signed-off-by: N葛亚芳 <geyafang@huawei.com>
上级 703abfca
...@@ -43,7 +43,7 @@ USB设备可作为Host设备连接Device设备进行数据传输。开发示例 ...@@ -43,7 +43,7 @@ USB设备可作为Host设备连接Device设备进行数据传输。开发示例
// 导入USB接口api包。 // 导入USB接口api包。
import usb from '@ohos.usb'; import usb from '@ohos.usb';
// 获取设备列表。 // 获取设备列表。
var deviceList = usb.getDevices(); let deviceList = usb.getDevices();
/* /*
deviceList结构示例 deviceList结构示例
[ [
...@@ -86,21 +86,21 @@ USB设备可作为Host设备连接Device设备进行数据传输。开发示例 ...@@ -86,21 +86,21 @@ USB设备可作为Host设备连接Device设备进行数据传输。开发示例
number: 1, number: 1,
type: 3, type: 3,
interfaceId: 0, interfaceId: 0,
}, }
], ]
}, }
], ]
}, }
], ]
}, }
], ]
*/ */
``` ```
2. 获取设备操作权限。 2. 获取设备操作权限。
```js ```js
var deviceName = deviceList[0].name; let deviceName = deviceList[0].name;
// 申请操作指定的device的操作权限。 // 申请操作指定的device的操作权限。
usb.requestRight(deviceName).then(hasRight => { usb.requestRight(deviceName).then(hasRight => {
console.info("usb device request right result: " + hasRight); console.info("usb device request right result: " + hasRight);
...@@ -113,7 +113,7 @@ USB设备可作为Host设备连接Device设备进行数据传输。开发示例 ...@@ -113,7 +113,7 @@ USB设备可作为Host设备连接Device设备进行数据传输。开发示例
```js ```js
// 打开设备,获取数据传输通道。 // 打开设备,获取数据传输通道。
var pipe = usb.connectDevice(deviceList[0]); let pipe = usb.connectDevice(deviceList[0]);
/* /*
打开对应接口,在设备信息(deviceList)中选取对应的interface。 打开对应接口,在设备信息(deviceList)中选取对应的interface。
interface1为设备配置中的一个接口。 interface1为设备配置中的一个接口。
...@@ -132,7 +132,7 @@ USB设备可作为Host设备连接Device设备进行数据传输。开发示例 ...@@ -132,7 +132,7 @@ USB设备可作为Host设备连接Device设备进行数据传输。开发示例
usb.bulkTransfer(pipe, inEndpoint, dataUint8Array, 15000).then(dataLength => { usb.bulkTransfer(pipe, inEndpoint, dataUint8Array, 15000).then(dataLength => {
if (dataLength >= 0) { if (dataLength >= 0) {
console.info("usb readData result Length : " + dataLength); console.info("usb readData result Length : " + dataLength);
var resultStr = this.ab2str(dataUint8Array); // uint8数据转string。 let resultStr = this.ab2str(dataUint8Array); // uint8数据转string。
console.info("usb readData buffer : " + resultStr); console.info("usb readData buffer : " + resultStr);
} else { } else {
console.info("usb readData failed : " + dataLength); console.info("usb readData failed : " + dataLength);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册