Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
f44eec2c
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,发现更多精彩内容 >>
未验证
提交
f44eec2c
编写于
10月 18, 2022
作者:
O
openharmony_ci
提交者:
Gitee
10月 18, 2022
浏览文件
操作
浏览文件
下载
差异文件
!10449 add usb error code
Merge pull request !10449 from 吴成文/master
上级
eaf702c9
a548094f
变更
5
展开全部
隐藏空白更改
内联
并排
Showing
5 changed file
with
1074 addition
and
99 deletion
+1074
-99
zh-cn/application-dev/device/usb-guidelines.md
zh-cn/application-dev/device/usb-guidelines.md
+2
-1
zh-cn/application-dev/reference/apis/js-apis-usb-deprecated.md
.../application-dev/reference/apis/js-apis-usb-deprecated.md
+862
-0
zh-cn/application-dev/reference/apis/js-apis-usb.md
zh-cn/application-dev/reference/apis/js-apis-usb.md
+108
-28
zh-cn/application-dev/reference/errorcodes/errcode-usb.md
zh-cn/application-dev/reference/errorcodes/errcode-usb.md
+19
-0
zh-cn/device-dev/driver/driver-peripherals-usb-des.md
zh-cn/device-dev/driver/driver-peripherals-usb-des.md
+83
-70
未找到文件。
zh-cn/application-dev/device/usb-guidelines.md
浏览文件 @
f44eec2c
...
...
@@ -4,7 +4,7 @@
## 场景介绍
Host模式下,可以获取到已经连接的设备列表,并根据需要打开和关闭设备、控制设备权限、进行数据传输等。
Host模式下,可以获取到已经连接的
USB
设备列表,并根据需要打开和关闭设备、控制设备权限、进行数据传输等。
## 接口说明
...
...
@@ -19,6 +19,7 @@ USB类开放能力如下,具体请查阅[API参考文档](../reference/apis/js
| ------------------------------------------------------------ | ------------------------------------------------------------ |
| hasRight(deviceName: string): boolean | 如果“使用者”(如各种App或系统)有权访问设备则返回true;无权访问设备则返回false。 |
| requestRight(deviceName: string): Promise
<
boolean
>
| 请求给定软件包的临时权限以访问设备。 |
| removeRight(deviceName: string): boolean | 移除软件包对设备的访问权限。|
| connectDevice(device: USBDevice): Readonly
<
USBDevicePipe
>
| 根据
`getDevices()`
返回的设备信息打开USB设备。 |
| getDevices(): Array
<
Readonly
<
USBDevice
>>
| 返回USB设备列表。 |
| setConfiguration(pipe: USBDevicePipe, config: USBConfig): number | 设置设备的配置。 |
...
...
zh-cn/application-dev/reference/apis/js-apis-usb-deprecated.md
0 → 100644
浏览文件 @
f44eec2c
此差异已折叠。
点击以展开。
zh-cn/application-dev/reference/apis/js-apis-usb.md
浏览文件 @
f44eec2c
# USB管理
本模块主要提供管理USB设备的相关功能,包括
查询USB设备列表、批量数据传输、控制命令传输、权限控制
等。
本模块主要提供管理USB设备的相关功能,包括
主设备上查询USB设备列表、批量数据传输、控制命令传输、权限控制等;从设备上端口管理、功能切换及查询
等。
> **说明:**
>
> 本模块首批接口从API version
8
开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
> 本模块首批接口从API version
9
开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
## 导入模块
```
js
import
usb
from
"
@ohos.usb
"
;
import
usb
from
"
@ohos.usb
V9
"
;
```
## usb.getDevices
getDevices(): Array
<
Readonly
<
USBDevice
>>
获取
USB设备
列表。
获取
接入主设备的USB设备列表。如果没有设备接入,那么将会返回一个空的
列表。
**系统能力:**
SystemCapability.USB.USBManager
...
...
@@ -89,7 +89,7 @@ connectDevice(device: USBDevice): Readonly<USBDevicePipe>
打开USB设备。
需要调用
[
usb.getDevices
](
#usbgetdevices
)
获取设备信息以及device,再调用
[
usb.requestRight
](
#usbrequestright
)
获取设备请求
权限。
需要调用
[
usb.getDevices
](
#usbgetdevices
)
获取设备信息以及device,再调用
[
usb.requestRight
](
#usbrequestright
)
请求使用该设备的
权限。
**系统能力:**
SystemCapability.USB.USBManager
...
...
@@ -105,10 +105,26 @@ connectDevice(device: USBDevice): Readonly<USBDevicePipe>
| -------- | -------- |
| Readonly
<
[USBDevicePipe](#usbdevicepipe)
>
| 指定的传输通道对象。 |
**错误码:**
以下错误码的详细介绍参见
[
USB错误码
](
../errorcodes/errcode-usb.md
)
。
| 错误码ID | 错误信息 |
| -------- | -------- |
| 14400001 |Permission denied. Need call requestRight to get permission. |
**示例:**
```
js
let
devicepipe
=
usb
.
connectDevice
(
device
);
let
devicesList
=
usb
.
getDevices
();
if
(
devicesList
.
length
==
0
)
{
console
.
log
(
`device list is empty`
);
return
;
}
let
device
=
devicesList
[
0
];
usb
.
requestRight
(
device
.
name
);
let
devicepipe
=
usb
.
connectDevice
(
device
);
console
.
log
(
`devicepipe =
${
JSON
.
stringify
(
devicepipe
)}
`
);
```
...
...
@@ -169,6 +185,70 @@ usb.requestRight(devicesName).then((ret) => {
});
```
## usb.removeRight
removeRight(deviceName: string): boolean;
移除软件包访问设备的权限。
**系统能力:**
SystemCapability.USB.USBManager
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| deviceName | string | 是 | 设备名称。 |
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| boolean | 返回权限移除结果。返回true表示权限移除成功;返回false则表示权限移除失败。 |
**示例:**
```
js
let
devicesName
=
"
1-1
"
;
if
(
usb
.
removeRight
(
devicesName
)
{
console
.
log
(
`Succeed in removing right`
);
}
```
## usb.addRight
addRight(bundleName: string, deviceName: string): boolean;
添加软件包访问设备的权限。
[
requestRight
](
#usbrequestright
)
的会触发弹框请求用户授权;addRight不会触发弹框,而是直接添加软件包访问设备的权限。
**系统接口:**
此接口为系统接口。
**系统能力:**
SystemCapability.USB.USBManager
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| deviceName | string | 是 | 设备名称。 |
| bundleName | string | 是 | 软件包名称。|
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| boolean | 返回权限添加结果。返回true表示权限添加成功;返回false则表示权限添加失败。 |
**示例:**
```
js
let
devicesName
=
"
1-1
"
;
let
bundleName
=
"
com.example.hello
"
;
if
(
usb
.
addRight
(
bundleName
,
devicesName
)
{
console
.
log
(
`Succeed in adding right`
);
}
```
## usb.claimInterface
claimInterface(pipe: USBDevicePipe, iface: USBInterface, force?: boolean): number
...
...
@@ -443,7 +523,7 @@ let ret = usb.closePipe(devicepipe);
console
.
log
(
`closePipe =
${
ret
}
`
);
```
## usb.usbFunctionsFromString
<sup>9+</sup>
## usb.usbFunctionsFromString
usbFunctionsFromString(funcs: string): number
...
...
@@ -472,7 +552,7 @@ let funcs = "acm";
let
ret
=
usb
.
usbFunctionsFromString
(
funcs
);
```
## usb.usbFunctionsToString
<sup>9+</sup>
## usb.usbFunctionsToString
usbFunctionsToString(funcs: FunctionType): string
...
...
@@ -486,7 +566,7 @@ usbFunctionsToString(funcs: FunctionType): string
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------------------------------ | ---- | ----------------- |
| funcs |
[
FunctionType
](
#functiontype
9
)
| 是 | USB功能数字掩码。 |
| funcs |
[
FunctionType
](
#functiontype
)
| 是 | USB功能数字掩码。 |
**返回值:**
...
...
@@ -501,7 +581,7 @@ let funcs = ACM | ECM;
let
ret
=
usb
.
usbFunctionsToString
(
funcs
);
```
## usb.setCurrentFunctions
<sup>9+</sup>
## usb.setCurrentFunctions
setCurrentFunctions(funcs: FunctionType): Promise
\<
boolean
\>
...
...
@@ -515,7 +595,7 @@ setCurrentFunctions(funcs: FunctionType): Promise\<boolean\>
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------------------------------ | ---- | ----------------- |
| funcs |
[
FunctionType
](
#functiontype
9
)
| 是 | USB功能数字掩码。 |
| funcs |
[
FunctionType
](
#functiontype
)
| 是 | USB功能数字掩码。 |
**返回值:**
...
...
@@ -530,7 +610,7 @@ let funcs = HDC;
let
ret
=
usb
.
setCurrentFunctions
(
funcs
);
```
## usb.getCurrentFunctions
<sup>9+</sup>
## usb.getCurrentFunctions
getCurrentFunctions(): FunctionType
...
...
@@ -544,7 +624,7 @@ getCurrentFunctions(): FunctionType
| 类型 | 说明 |
| ------------------------------ | --------------------------------- |
|
[
FunctionType
](
#functiontype
9
)
| 当前的USB功能列表的数字组合掩码。 |
|
[
FunctionType
](
#functiontype
)
| 当前的USB功能列表的数字组合掩码。 |
**示例:**
...
...
@@ -552,7 +632,7 @@ getCurrentFunctions(): FunctionType
let
ret
=
usb
.
getCurrentFunctions
();
```
## usb.getPorts
<sup>9+</sup>
## usb.getPorts
getPorts(): Array
\<
USBPort
\>
...
...
@@ -566,7 +646,7 @@ getPorts(): Array\<USBPort\>
| 类型 | 说明 |
| ----------------------------- | --------------------- |
|
[
Array\<USBPort\>
](
#usbport
9
)
| USB端口描述信息列表。 |
|
[
Array\<USBPort\>
](
#usbport
)
| USB端口描述信息列表。 |
**示例:**
...
...
@@ -574,7 +654,7 @@ getPorts(): Array\<USBPort\>
let
ret
=
usb
.
getPorts
();
```
## usb.getSupportedModes
<sup>9+</sup>
## usb.getSupportedModes
getSupportedModes(portId: number): PortModeType
...
...
@@ -594,7 +674,7 @@ getSupportedModes(portId: number): PortModeType
| 类型 | 说明 |
| ------------------------------ | -------------------------- |
|
[
PortModeType
](
#portmodetype
9
)
| 支持的模式列表的组合掩码。 |
|
[
PortModeType
](
#portmodetype
)
| 支持的模式列表的组合掩码。 |
**示例:**
...
...
@@ -602,7 +682,7 @@ getSupportedModes(portId: number): PortModeType
let
ret
=
usb
.
getSupportedModes
(
0
);
```
## usb.setPortRoles
<sup>9+</sup>
## usb.setPortRoles
setPortRoles(portId: number, powerRole: PowerRoleType, dataRole: DataRoleType): Promise
\<
boolean
\>
...
...
@@ -617,8 +697,8 @@ setPortRoles(portId: number, powerRole: PowerRoleType, dataRole: DataRoleType):
| 参数名 | 类型 | 必填 | 说明 |
| --------- | -------------------------------- | ---- | ---------------- |
| portId | number | 是 | 端口号。 |
| powerRole |
[
PowerRoleType
](
#powerroletype
9
)
| 是 | 充电的角色。 |
| dataRole |
[
DataRoleType
](
#dataroletype
9
)
| 是 | 数据传输的角色。 |
| powerRole |
[
PowerRoleType
](
#powerroletype
)
| 是 | 充电的角色。 |
| dataRole |
[
DataRoleType
](
#dataroletype
)
| 是 | 数据传输的角色。 |
**返回值:**
...
...
@@ -729,7 +809,7 @@ USB设备消息传输通道,用于确定设备。
| index | number | 请求参数value对应的索引值。 |
| data | Uint8Array | 用于写入或读取的缓冲区。 |
## USBPort
<sup>9+</sup>
## USBPort
USB设备端口。
...
...
@@ -740,10 +820,10 @@ USB设备端口。
| 名称 | 参数类型 | 说明 |
| -------------- | -------------------------------- | ----------------------------------- |
| id | number | USB端口唯一标识。 |
| supportedModes |
[
PortModeType
](
#portmodetype
9
)
| USB端口所支持的模式的数字组合掩码。 |
| status |
[
USBPortStatus
](
#usbportstatus
9
)
| USB端口角色。 |
| supportedModes |
[
PortModeType
](
#portmodetype
)
| USB端口所支持的模式的数字组合掩码。 |
| status |
[
USBPortStatus
](
#usbportstatus
)
| USB端口角色。 |
## USBPortStatus
<sup>9+</sup>
## USBPortStatus
USB设备端口角色信息。
...
...
@@ -793,7 +873,7 @@ USB设备端口角色信息。
| USB_REQUEST_DIR_TO_DEVICE | 0 | 写数据,主设备往从设备。 |
| USB_REQUEST_DIR_FROM_DEVICE | 0x80 | 读数据,从设备往主设备。 |
## FunctionType
<sup>9+</sup>
## FunctionType
USB设备侧功能。
...
...
@@ -814,7 +894,7 @@ USB设备侧功能。
| AUDIO_SOURCE | 128 | 暂不支持。 |
| NCM | 256 | 暂不支持。 |
## PortModeType
<sup>9+</sup>
## PortModeType
USB端口模式类型。
...
...
@@ -830,7 +910,7 @@ USB端口模式类型。
| DRP | 3 | 既可以做DFP(Host),也可以做UFP(Device),当前不支持。 |
| NUM_MODES | 4 | 当前不支持。 |
## PowerRoleType
<sup>9+</sup>
## PowerRoleType
电源角色类型。
...
...
@@ -844,7 +924,7 @@ USB端口模式类型。
| SOURCE | 1 | 外部供电。 |
| SINK | 2 | 内部供电。 |
## DataRoleType
<sup>9+</sup>
## DataRoleType
数据角色类型。
...
...
zh-cn/application-dev/reference/errorcodes/errcode-usb.md
0 → 100644
浏览文件 @
f44eec2c
# USB服务错误码
## 14400001 连接USB设备被拒绝
**错误信息**
Permission denied. Need call requestRight to get permission.
**错误描述**
当调用USB模块部分接口时,如果没有相关权限,会报此错误码。
**可能原因**
没有获取到设备的使用权限。
**处理步骤**
调用requestRight方法申请设备的使用权限。
\ No newline at end of file
zh-cn/device-dev/driver/driver-peripherals-usb-des.md
浏览文件 @
f44eec2c
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录