Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
28faa0a7
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
28faa0a7
编写于
12月 16, 2021
作者:
W
wu-chengwen
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: update subsys-usbservice-demo.md
Signed-off-by:
N
wu-chengwen
<
wuchengwen4@huawei.com
>
上级
c76307d0
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
19 addition
and
19 deletion
+19
-19
zh-cn/device-dev/subsystems/subsys-usbservice-demo.md
zh-cn/device-dev/subsystems/subsys-usbservice-demo.md
+19
-19
未找到文件。
zh-cn/device-dev/subsystems/subsys-usbservice-demo.md
浏览文件 @
28faa0a7
...
...
@@ -64,40 +64,40 @@ bool SelectEndpoint(OHOS::USB::USBConfig config,
return false;
}
int OpenDeviceTest(OHOS::USB::UsbSrvClient &
g_usbClient
, OHOS::USB::UsbDevice device, OHOS::USB::USBDevicePipe &pip)
int OpenDeviceTest(OHOS::USB::UsbSrvClient &
Instran
, OHOS::USB::UsbDevice device, OHOS::USB::USBDevicePipe &pip)
{
int ret =
g_usbClient
.RequestRight(device.GetName());
std::cout << "
设备请求权限结果 RequestRigh
t = " << ret << std::endl;
int ret =
Instran
.RequestRight(device.GetName());
std::cout << "
device RequestRight re
t = " << ret << std::endl;
if (0 != ret) {
std::cout << "
设备请求权限失败 RequestRight
= " << ret << std::endl;
std::cout << "
device RequestRight failed
= " << ret << std::endl;
}
ret =
g_usbClient
.OpenDevice(device, pip);
ret =
Instran
.OpenDevice(device, pip);
return ret;
}
int CtrTransferTest(OHOS::USB::UsbSrvClient &
g_usbClient
, OHOS::USB::USBDevicePipe &pip)
int CtrTransferTest(OHOS::USB::UsbSrvClient &
Instran
, OHOS::USB::USBDevicePipe &pip)
{
std::cout << "usb_device_test : << Control Transfer >> " << std::endl;
std::vector<uint8_t> vData;
const OHOS::USB::UsbCtrlTransfer tctrl = {REQUESTYPE, REQUESTCMD, VALUE, 0, TIMEOUT};
int ret =
g_usbClient
.ControlTransfer(pip, tctrl, vData);
int ret =
Instran
.ControlTransfer(pip, tctrl, vData);
if (ret != 0) {
std::cout << "control message read failed width ret = " << ret << std::endl;
} else {
std::cout << "control message read success" << std::endl;
}
std::cout << "control message read success" << std::endl;
return ret;
}
int ClaimTest(OHOS::USB::UsbSrvClient &
g_usbClient
,
int ClaimTest(OHOS::USB::UsbSrvClient &
Instran
,
OHOS::USB::USBDevicePipe &pip,
OHOS::USB::UsbInterface &interface,
bool interfaceFlg)
{
if (interfaceFlg) {
std::cout << "ClaimInterface InterfaceInfo:" << interface.ToString() << std::endl;
int ret =
g_usbClient
.ClaimInterface(pip, interface, true);
int ret =
Instran
.ClaimInterface(pip, interface, true);
if (ret != 0) {
std::cout << "ClaimInterface failed width ret = " << ret << std::endl;
} else {
...
...
@@ -107,7 +107,7 @@ int ClaimTest(OHOS::USB::UsbSrvClient &g_usbClient,
return 0;
}
int BulkTransferTest(OHOS::USB::UsbSrvClient &
g_usbClient
,
int BulkTransferTest(OHOS::USB::UsbSrvClient &
Instran
,
OHOS::USB::USBDevicePipe &pip,
OHOS::USB::USBEndpoint &outEp,
bool interfaceFlg,
...
...
@@ -118,7 +118,7 @@ int BulkTransferTest(OHOS::USB::UsbSrvClient &g_usbClient,
if (outEpFlg) {
uint8_t buffer[50] = "hello world 123456789";
std::vector<uint8_t> vData(buffer, buffer + BUFFERLENGTH);
int ret =
g_usbClient
.BulkTransfer(pip, outEp, vData, TIMEOUT);
int ret =
Instran
.BulkTransfer(pip, outEp, vData, TIMEOUT);
if (ret != 0) {
std::cout << "Bulk transfer write failed width ret = " << ret << std::endl;
} else {
...
...
@@ -133,10 +133,10 @@ int BulkTransferTest(OHOS::USB::UsbSrvClient &g_usbClient,
int main(int argc, char **argv)
{
std::cout << "usb_device_test " << std::endl;
static OHOS::USB::UsbSrvClient &
g_usbClient
= OHOS::USB::UsbSrvClient::GetInstance();
static OHOS::USB::UsbSrvClient &
Instran
= OHOS::USB::UsbSrvClient::GetInstance();
// GetDevices
std::vector<OHOS::USB::UsbDevice> deviceList;
int32_t ret =
g_usbClient
.GetDevices(deviceList);
int32_t ret =
Instran
.GetDevices(deviceList);
if (ret != 0) {
return OHOS::USB::UEC_SERVICE_INVALID_VALUE;
}
...
...
@@ -157,23 +157,23 @@ int main(int argc, char **argv)
// OpenDevice
std::cout << "usb_device_test : << OpenDevice >> test begin -> " << std::endl;
OHOS::USB::USBDevicePipe pip;
ret = OpenDeviceTest(
g_usbClient
, device, pip);
ret = OpenDeviceTest(
Instran
, device, pip);
if (ret != 0) {
return OHOS::USB::UEC_SERVICE_INVALID_VALUE;
}
// ControlTransfer
CtrTransferTest(
g_usbClient
, pip);
CtrTransferTest(
Instran
, pip);
// ClaimInterface
ClaimTest(
g_usbClient
, pip, interface, interfaceFlg);
ClaimTest(
Instran
, pip, interface, interfaceFlg);
// BulkTransferWrite
BulkTransferTest(
g_usbClient
, pip, outEp, interfaceFlg, outEpFlg);
BulkTransferTest(
Instran
, pip, outEp, interfaceFlg, outEpFlg);
// CloseDevice
std::cout << "usb_device_test : << Close Device >> " << std::endl;
ret =
g_usbClient
.Close(pip);
ret =
Instran
.Close(pip);
if (ret == 0) {
std::cout << "Close device failed width ret = " << ret << std::endl;
return OHOS::USB::UEC_SERVICE_INVALID_VALUE;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录