Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
799b559e
D
Docs
项目概览
OpenHarmony
/
Docs
1 年多 前同步成功
通知
159
Star
292
Fork
28
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Docs
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
799b559e
编写于
4月 25, 2022
作者:
W
wu-chengwen
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(usb):add language type
Signed-off-by:
N
wu-chengwen
<
wuchengwen4@huawei.com
>
上级
9bfd5485
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
26 addition
and
26 deletion
+26
-26
en/application-dev/device/usb-guidelines.md
en/application-dev/device/usb-guidelines.md
+5
-5
en/device-dev/subsystems/subsys-usbservice-demo.md
en/device-dev/subsystems/subsys-usbservice-demo.md
+1
-1
en/device-dev/subsystems/subsys-usbservice-guide.md
en/device-dev/subsystems/subsys-usbservice-guide.md
+7
-7
zh-cn/application-dev/device/usb-guidelines.md
zh-cn/application-dev/device/usb-guidelines.md
+5
-5
zh-cn/device-dev/subsystems/subsys-usbservice-demo.md
zh-cn/device-dev/subsystems/subsys-usbservice-demo.md
+1
-1
zh-cn/device-dev/subsystems/subsys-usbservice-guide.md
zh-cn/device-dev/subsystems/subsys-usbservice-guide.md
+7
-7
未找到文件。
en/application-dev/device/usb-guidelines.md
浏览文件 @
799b559e
...
...
@@ -93,7 +93,7 @@ You can set a USB device as a host to connect to a device for data transfer. The
1.
Obtain the USB device list.
```
```
js
// Import the USB API package.
import usb from '@ohos.usb';
// Obtain the USB device list.
...
...
@@ -153,7 +153,7 @@ You can set a USB device as a host to connect to a device for data transfer. The
2.
Obtain the device operation permissions.
```
```
js
var deviceName = deviceList[0].name;
// Request the permissions to operate a specified device.
usb.requestRight(deviceName).then(hasRight => {
...
...
@@ -165,7 +165,7 @@ You can set a USB device as a host to connect to a device for data transfer. The
3.
Open the device.
```
```
js
// Open the device, and obtain the USB device pipe for data transfer.
var pipe = usb.connectDevice(deviceList[0]);
/*
...
...
@@ -177,7 +177,7 @@ You can set a USB device as a host to connect to a device for data transfer. The
4.
Perform data transfer.
```
```
js
/*
Read data. Select the corresponding RX endpoint from deviceList for data transfer.
(endpoint.direction == 0x80); dataUint8Array indicates the data to read. The data type is Uint8Array.
...
...
@@ -208,7 +208,7 @@ You can set a USB device as a host to connect to a device for data transfer. The
5.
Release the USB interface, and close the USB device.
```
```
js
usb.releaseInterface(pipe, interface);
usb.closePipe(pipe);
```
...
...
en/device-dev/subsystems/subsys-usbservice-demo.md
浏览文件 @
799b559e
# USB Usage Demo<a name="EN-US_TOPIC_0000001092792986"></a>
```
```
cpp
#include <cstdio>
#include <iostream>
#include <map>
...
...
en/device-dev/subsystems/subsys-usbservice-guide.md
浏览文件 @
799b559e
...
...
@@ -7,40 +7,40 @@ The following procedure uses bulk transfer as an example.
1.
Obtain a USB service instance.
```
```
cpp
static
OHOS
::
USB
::
UsbSrvClient
&
g_usbClient
=
OHOS
::
USB
::
UsbSrvClient
::
GetInstance
();
```
2.
Obtain the USB device list.
```
```
cpp
std
::
vector
<
OHOS
::
USB
::
UsbDevice
>
deviceList
;
int32_t
ret
=
g_usbClient
.
GetDevices
(
deviceList
);
```
3.
Apply for device access permissions.
```
```
cpp
int32_t
ret
=
g_usbClient
.
RequestRight
(
device
.
GetName
());
```
4.
Open the USB device.
```
```
cpp
USBDevicePipe
pip
;
int32_t
et
=
g_usbClient
.
OpenDevice
(
device
,
pip
);
```
5.
Configure the USB interface.
```
```
cpp
ret
=
g_usbClient
.
ClaimInterface
(
pip
,
interface
,
true
);
**
interface
**
indicates
an
interface
of
the
USB
device
in
**
deviceList
**
.
```
6.
Transfer data.
```
```
cpp
srvClient
.
BulkTransfer
(
pipe
,
endpoint
,
vdata
,
timeout
);
```
-
**pipe**
indicates the pipe for data transfer of the USB device opened.
...
...
@@ -50,6 +50,6 @@ srvClient.BulkTransfer(pipe, endpoint, vdata, timeout);
7.
Close the USB device.
```
```
cpp
ret
=
g_usbClient
.
Close
(
pip
);
```
zh-cn/application-dev/device/usb-guidelines.md
浏览文件 @
799b559e
...
...
@@ -38,7 +38,7 @@ USB设备可作为Host设备连接Device设备进行数据传输。开发示例
1.
获取设备列表。
```
```
js
// 导入usb接口api包。
import
usb
from
'
@ohos.usb
'
;
// 获取设备列表。
...
...
@@ -97,7 +97,7 @@ USB设备可作为Host设备连接Device设备进行数据传输。开发示例
```
2.
获取设备操作权限。
```
```
js
var
deviceName
=
deviceList
[
0
].
name
;
// 申请操作指定的device的操作权限。
usb
.
requestRight
(
deviceName
).
then
(
hasRight
=>
{
...
...
@@ -108,7 +108,7 @@ USB设备可作为Host设备连接Device设备进行数据传输。开发示例
```
3.
打开Device设备。
```
```
js
// 打开设备,获取数据传输通道。
var
pipe
=
usb
.
connectDevice
(
deviceList
[
0
]);
/*
...
...
@@ -119,7 +119,7 @@ USB设备可作为Host设备连接Device设备进行数据传输。开发示例
```
4.
数据传输。
```
```
js
/*
读取数据,在device信息中选取对应数据接收的endpoint来做数据传输
(endpoint.direction == 0x80);dataUint8Array是要读取的数据,类型为Uint8Array。
...
...
@@ -149,7 +149,7 @@ USB设备可作为Host设备连接Device设备进行数据传输。开发示例
```
5.
释放接口,关闭设备。
```
```
js
usb
.
releaseInterface
(
pipe
,
interface1
);
usb
.
closePipe
(
pipe
);
```
zh-cn/device-dev/subsystems/subsys-usbservice-demo.md
浏览文件 @
799b559e
# USB服务子系统使用实例<a name="ZH-CN_TOPIC_0000001092792986"></a>
```
```
cpp
#include <cstdio>
#include <iostream>
#include <map>
...
...
zh-cn/device-dev/subsystems/subsys-usbservice-guide.md
浏览文件 @
799b559e
...
...
@@ -7,46 +7,46 @@
1.
获取usb service实例
```
```
cpp
static
OHOS
::
USB
::
UsbSrvClient
&
g_usbClient
=
OHOS
::
USB
::
UsbSrvClient
::
GetInstance
();
```
2.
获取usb设备列表
```
```
cpp
std
::
vector
<
OHOS
::
USB
::
UsbDevice
>
deviceList
;
int32_t
ret
=
g_usbClient
.
GetDevices
(
deviceList
);
```
3.
申请设备权限
```
```
cpp
int32_t
ret
=
g_usbClient
.
RequestRight
(
device
.
GetName
());
```
4.
打开设备
```
```
cpp
USBDevicePipe
pip
;
int32_t
et
=
g_usbClient
.
OpenDevice
(
device
,
pip
);
```
5.
配置设备接口
```
```
cpp
ret
=
g_usbClient
.
ClaimInterface
(
pip
,
interface
,
true
);
interface
为
deviceList
中
device
的
interface
。
```
6.
数据传输
```
```
cpp
srvClient
.
BulkTransfer
(
pipe
,
endpoint
,
vdata
,
timeout
);
```
pipe为打开设备后的数据传输通道,endpoint为device中数据传输的端点,vdata是需要传输或读取的二进制数据块,timeout为传输超时时长。
7.
关闭设备
```
```
cpp
ret
=
g_usbClient
.
Close
(
pip
);
```
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录