Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
aefd1382
D
Docs
项目概览
OpenHarmony
/
Docs
12 个月 前同步成功
通知
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看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
aefd1382
编写于
4月 26, 2022
作者:
O
openharmony_ci
提交者:
Gitee
4月 26, 2022
浏览文件
操作
浏览文件
下载
差异文件
!3467 usb docs add language type
Merge pull request !3467 from 吴成文/master
上级
1c8af3f0
799b559e
变更
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
浏览文件 @
aefd1382
...
@@ -93,7 +93,7 @@ You can set a USB device as a host to connect to a device for data transfer. The
...
@@ -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.
1.
Obtain the USB device list.
```
```
js
// Import the USB API package.
// Import the USB API package.
import usb from '@ohos.usb';
import usb from '@ohos.usb';
// Obtain the USB device list.
// 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
...
@@ -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.
2.
Obtain the device operation permissions.
```
```
js
var deviceName = deviceList[0].name;
var deviceName = deviceList[0].name;
// Request the permissions to operate a specified device.
// Request the permissions to operate a specified device.
usb.requestRight(deviceName).then(hasRight => {
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
...
@@ -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.
3.
Open the device.
```
```
js
// Open the device, and obtain the USB device pipe for data transfer.
// Open the device, and obtain the USB device pipe for data transfer.
var pipe = usb.connectDevice(deviceList[0]);
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
...
@@ -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.
4.
Perform data transfer.
```
```
js
/*
/*
Read data. Select the corresponding RX endpoint from deviceList for data transfer.
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.
(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
...
@@ -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.
5.
Release the USB interface, and close the USB device.
```
```
js
usb.releaseInterface(pipe, interface);
usb.releaseInterface(pipe, interface);
usb.closePipe(pipe);
usb.closePipe(pipe);
```
```
...
...
en/device-dev/subsystems/subsys-usbservice-demo.md
浏览文件 @
aefd1382
# USB Usage Demo<a name="EN-US_TOPIC_0000001092792986"></a>
# USB Usage Demo<a name="EN-US_TOPIC_0000001092792986"></a>
```
```
cpp
#include <cstdio>
#include <cstdio>
#include <iostream>
#include <iostream>
#include <map>
#include <map>
...
...
en/device-dev/subsystems/subsys-usbservice-guide.md
浏览文件 @
aefd1382
...
@@ -7,40 +7,40 @@ The following procedure uses bulk transfer as an example.
...
@@ -7,40 +7,40 @@ The following procedure uses bulk transfer as an example.
1.
Obtain a USB service instance.
1.
Obtain a USB service instance.
```
```
cpp
static
OHOS
::
USB
::
UsbSrvClient
&
g_usbClient
=
OHOS
::
USB
::
UsbSrvClient
::
GetInstance
();
static
OHOS
::
USB
::
UsbSrvClient
&
g_usbClient
=
OHOS
::
USB
::
UsbSrvClient
::
GetInstance
();
```
```
2.
Obtain the USB device list.
2.
Obtain the USB device list.
```
```
cpp
std
::
vector
<
OHOS
::
USB
::
UsbDevice
>
deviceList
;
std
::
vector
<
OHOS
::
USB
::
UsbDevice
>
deviceList
;
int32_t
ret
=
g_usbClient
.
GetDevices
(
deviceList
);
int32_t
ret
=
g_usbClient
.
GetDevices
(
deviceList
);
```
```
3.
Apply for device access permissions.
3.
Apply for device access permissions.
```
```
cpp
int32_t
ret
=
g_usbClient
.
RequestRight
(
device
.
GetName
());
int32_t
ret
=
g_usbClient
.
RequestRight
(
device
.
GetName
());
```
```
4.
Open the USB device.
4.
Open the USB device.
```
```
cpp
USBDevicePipe
pip
;
USBDevicePipe
pip
;
int32_t
et
=
g_usbClient
.
OpenDevice
(
device
,
pip
);
int32_t
et
=
g_usbClient
.
OpenDevice
(
device
,
pip
);
```
```
5.
Configure the USB interface.
5.
Configure the USB interface.
```
```
cpp
ret
=
g_usbClient
.
ClaimInterface
(
pip
,
interface
,
true
);
ret
=
g_usbClient
.
ClaimInterface
(
pip
,
interface
,
true
);
**
interface
**
indicates
an
interface
of
the
USB
device
in
**
deviceList
**
.
**
interface
**
indicates
an
interface
of
the
USB
device
in
**
deviceList
**
.
```
```
6.
Transfer data.
6.
Transfer data.
```
```
cpp
srvClient
.
BulkTransfer
(
pipe
,
endpoint
,
vdata
,
timeout
);
srvClient
.
BulkTransfer
(
pipe
,
endpoint
,
vdata
,
timeout
);
```
```
-
**pipe**
indicates the pipe for data transfer of the USB device opened.
-
**pipe**
indicates the pipe for data transfer of the USB device opened.
...
@@ -50,6 +50,6 @@ srvClient.BulkTransfer(pipe, endpoint, vdata, timeout);
...
@@ -50,6 +50,6 @@ srvClient.BulkTransfer(pipe, endpoint, vdata, timeout);
7.
Close the USB device.
7.
Close the USB device.
```
```
cpp
ret
=
g_usbClient
.
Close
(
pip
);
ret
=
g_usbClient
.
Close
(
pip
);
```
```
zh-cn/application-dev/device/usb-guidelines.md
浏览文件 @
aefd1382
...
@@ -38,7 +38,7 @@ USB设备可作为Host设备连接Device设备进行数据传输。开发示例
...
@@ -38,7 +38,7 @@ USB设备可作为Host设备连接Device设备进行数据传输。开发示例
1.
获取设备列表。
1.
获取设备列表。
```
```
js
// 导入usb接口api包。
// 导入usb接口api包。
import
usb
from
'
@ohos.usb
'
;
import
usb
from
'
@ohos.usb
'
;
// 获取设备列表。
// 获取设备列表。
...
@@ -97,7 +97,7 @@ USB设备可作为Host设备连接Device设备进行数据传输。开发示例
...
@@ -97,7 +97,7 @@ USB设备可作为Host设备连接Device设备进行数据传输。开发示例
```
```
2.
获取设备操作权限。
2.
获取设备操作权限。
```
```
js
var
deviceName
=
deviceList
[
0
].
name
;
var
deviceName
=
deviceList
[
0
].
name
;
// 申请操作指定的device的操作权限。
// 申请操作指定的device的操作权限。
usb
.
requestRight
(
deviceName
).
then
(
hasRight
=>
{
usb
.
requestRight
(
deviceName
).
then
(
hasRight
=>
{
...
@@ -108,7 +108,7 @@ USB设备可作为Host设备连接Device设备进行数据传输。开发示例
...
@@ -108,7 +108,7 @@ USB设备可作为Host设备连接Device设备进行数据传输。开发示例
```
```
3.
打开Device设备。
3.
打开Device设备。
```
```
js
// 打开设备,获取数据传输通道。
// 打开设备,获取数据传输通道。
var
pipe
=
usb
.
connectDevice
(
deviceList
[
0
]);
var
pipe
=
usb
.
connectDevice
(
deviceList
[
0
]);
/*
/*
...
@@ -119,7 +119,7 @@ USB设备可作为Host设备连接Device设备进行数据传输。开发示例
...
@@ -119,7 +119,7 @@ USB设备可作为Host设备连接Device设备进行数据传输。开发示例
```
```
4.
数据传输。
4.
数据传输。
```
```
js
/*
/*
读取数据,在device信息中选取对应数据接收的endpoint来做数据传输
读取数据,在device信息中选取对应数据接收的endpoint来做数据传输
(endpoint.direction == 0x80);dataUint8Array是要读取的数据,类型为Uint8Array。
(endpoint.direction == 0x80);dataUint8Array是要读取的数据,类型为Uint8Array。
...
@@ -149,7 +149,7 @@ USB设备可作为Host设备连接Device设备进行数据传输。开发示例
...
@@ -149,7 +149,7 @@ USB设备可作为Host设备连接Device设备进行数据传输。开发示例
```
```
5.
释放接口,关闭设备。
5.
释放接口,关闭设备。
```
```
js
usb
.
releaseInterface
(
pipe
,
interface1
);
usb
.
releaseInterface
(
pipe
,
interface1
);
usb
.
closePipe
(
pipe
);
usb
.
closePipe
(
pipe
);
```
```
zh-cn/device-dev/subsystems/subsys-usbservice-demo.md
浏览文件 @
aefd1382
# USB服务子系统使用实例<a name="ZH-CN_TOPIC_0000001092792986"></a>
# USB服务子系统使用实例<a name="ZH-CN_TOPIC_0000001092792986"></a>
```
```
cpp
#include <cstdio>
#include <cstdio>
#include <iostream>
#include <iostream>
#include <map>
#include <map>
...
...
zh-cn/device-dev/subsystems/subsys-usbservice-guide.md
浏览文件 @
aefd1382
...
@@ -7,46 +7,46 @@
...
@@ -7,46 +7,46 @@
1.
获取usb service实例
1.
获取usb service实例
```
```
cpp
static
OHOS
::
USB
::
UsbSrvClient
&
g_usbClient
=
OHOS
::
USB
::
UsbSrvClient
::
GetInstance
();
static
OHOS
::
USB
::
UsbSrvClient
&
g_usbClient
=
OHOS
::
USB
::
UsbSrvClient
::
GetInstance
();
```
```
2.
获取usb设备列表
2.
获取usb设备列表
```
```
cpp
std
::
vector
<
OHOS
::
USB
::
UsbDevice
>
deviceList
;
std
::
vector
<
OHOS
::
USB
::
UsbDevice
>
deviceList
;
int32_t
ret
=
g_usbClient
.
GetDevices
(
deviceList
);
int32_t
ret
=
g_usbClient
.
GetDevices
(
deviceList
);
```
```
3.
申请设备权限
3.
申请设备权限
```
```
cpp
int32_t
ret
=
g_usbClient
.
RequestRight
(
device
.
GetName
());
int32_t
ret
=
g_usbClient
.
RequestRight
(
device
.
GetName
());
```
```
4.
打开设备
4.
打开设备
```
```
cpp
USBDevicePipe
pip
;
USBDevicePipe
pip
;
int32_t
et
=
g_usbClient
.
OpenDevice
(
device
,
pip
);
int32_t
et
=
g_usbClient
.
OpenDevice
(
device
,
pip
);
```
```
5.
配置设备接口
5.
配置设备接口
```
```
cpp
ret
=
g_usbClient
.
ClaimInterface
(
pip
,
interface
,
true
);
ret
=
g_usbClient
.
ClaimInterface
(
pip
,
interface
,
true
);
interface
为
deviceList
中
device
的
interface
。
interface
为
deviceList
中
device
的
interface
。
```
```
6.
数据传输
6.
数据传输
```
```
cpp
srvClient
.
BulkTransfer
(
pipe
,
endpoint
,
vdata
,
timeout
);
srvClient
.
BulkTransfer
(
pipe
,
endpoint
,
vdata
,
timeout
);
```
```
pipe为打开设备后的数据传输通道,endpoint为device中数据传输的端点,vdata是需要传输或读取的二进制数据块,timeout为传输超时时长。
pipe为打开设备后的数据传输通道,endpoint为device中数据传输的端点,vdata是需要传输或读取的二进制数据块,timeout为传输超时时长。
7.
关闭设备
7.
关闭设备
```
```
cpp
ret
=
g_usbClient
.
Close
(
pip
);
ret
=
g_usbClient
.
Close
(
pip
);
```
```
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录