未验证 提交 f57904e7 编写于 作者: O openharmony_ci 提交者: Gitee

!15838 fix:usb Document Modification

Merge pull request !15838 from 罗巍/master
...@@ -32,7 +32,7 @@ getDevices(): Array<Readonly<USBDevice>> ...@@ -32,7 +32,7 @@ getDevices(): Array<Readonly<USBDevice>>
```js ```js
let devicesList = usb.getDevices(); let devicesList = usb.getDevices();
console.log(`devicesList = ${JSON.stringify(devicesList)}`); console.log(`devicesList = ${devicesList}`);
//devicesList 返回的数据结构 //devicesList 返回的数据结构
//此处提供一个简单的示例,如下 //此处提供一个简单的示例,如下
[ [
...@@ -111,7 +111,7 @@ connectDevice(device: USBDevice): Readonly<USBDevicePipe> ...@@ -111,7 +111,7 @@ connectDevice(device: USBDevice): Readonly<USBDevicePipe>
```js ```js
let devicepipe= usb.connectDevice(device); let devicepipe= usb.connectDevice(device);
console.log(`devicepipe = ${JSON.stringify(devicepipe)}`); console.log(`devicepipe = ${devicepipe}`);
``` ```
## usb.hasRight ## usb.hasRight
...@@ -167,7 +167,7 @@ requestRight(deviceName: string): Promise<boolean> ...@@ -167,7 +167,7 @@ requestRight(deviceName: string): Promise<boolean>
```js ```js
let devicesName="1-1"; let devicesName="1-1";
usb.requestRight(devicesName).then((ret) => { usb.requestRight(devicesName).then((ret) => {
console.log(`requestRight = ${JSON.stringify(ret)}`); console.log(`requestRight = ${ret}`);
}); });
``` ```
...@@ -375,8 +375,9 @@ controlTransfer(pipe: USBDevicePipe, controlparam: USBControlParams, timeout ?: ...@@ -375,8 +375,9 @@ controlTransfer(pipe: USBDevicePipe, controlparam: USBControlParams, timeout ?:
**示例:** **示例:**
```js ```js
usb.controlTransfer(devicepipe, USBControlParams).then((ret) => { let param = new usb.USBControlParams();
console.log(`controlTransfer = ${JSON.stringify(ret)}`); usb.controlTransfer(devicepipe, param).then((ret) => {
console.log(`controlTransfer = ${ret}`);
}) })
``` ```
...@@ -412,7 +413,7 @@ bulkTransfer(pipe: USBDevicePipe, endpoint: USBEndpoint, buffer: Uint8Array, tim ...@@ -412,7 +413,7 @@ bulkTransfer(pipe: USBDevicePipe, endpoint: USBEndpoint, buffer: Uint8Array, tim
//把获取到的设备对象作为参数传入usb.connectDevice;当usb.connectDevice接口成功返回之后; //把获取到的设备对象作为参数传入usb.connectDevice;当usb.connectDevice接口成功返回之后;
//才可以调用第三个接口usb.claimInterface.当usb.claimInterface 调用成功以后,再调用该接口。 //才可以调用第三个接口usb.claimInterface.当usb.claimInterface 调用成功以后,再调用该接口。
usb.bulkTransfer(devicepipe, endpoint, buffer).then((ret) => { usb.bulkTransfer(devicepipe, endpoint, buffer).then((ret) => {
console.log(`bulkTransfer = ${JSON.stringify(ret)}`); console.log(`bulkTransfer = ${ret}`);
}); });
``` ```
...@@ -499,7 +500,7 @@ usbFunctionsToString(funcs: FunctionType): string ...@@ -499,7 +500,7 @@ usbFunctionsToString(funcs: FunctionType): string
**示例:** **示例:**
```js ```js
let funcs = ACM | ECM; let funcs = usb.ACM | usb.ECM;
let ret = usb.usbFunctionsToString(funcs); let ret = usb.usbFunctionsToString(funcs);
``` ```
...@@ -528,7 +529,7 @@ setCurrentFunctions(funcs: FunctionType): Promise\<boolean\> ...@@ -528,7 +529,7 @@ setCurrentFunctions(funcs: FunctionType): Promise\<boolean\>
**示例:** **示例:**
```js ```js
let funcs = HDC; let funcs = usb.HDC;
let ret = usb.setCurrentFunctions(funcs); let ret = usb.setCurrentFunctions(funcs);
``` ```
...@@ -631,7 +632,12 @@ setPortRoles(portId: number, powerRole: PowerRoleType, dataRole: DataRoleType): ...@@ -631,7 +632,12 @@ setPortRoles(portId: number, powerRole: PowerRoleType, dataRole: DataRoleType):
**示例:** **示例:**
```js ```js
let ret = usb.getSupportedModes(0); let portId = 1;
usb.setPortRoles(portId, usb.PowerRoleType.SOURCE, usb.DataRoleType.HOST).then(() => {
console.info('usb setPortRoles successfully.');
}).catch(err => {
console.error('usb setPortRoles failed: ' + err.code + ' message: ' + err.message);
});
``` ```
## USBEndpoint ## USBEndpoint
......
...@@ -32,7 +32,7 @@ getDevices(): Array&lt;Readonly&lt;USBDevice&gt;&gt; ...@@ -32,7 +32,7 @@ getDevices(): Array&lt;Readonly&lt;USBDevice&gt;&gt;
```js ```js
let devicesList = usb.getDevices(); let devicesList = usb.getDevices();
console.log(`devicesList = ${JSON.stringify(devicesList)}`); console.log(`devicesList = ${devicesList}`);
//devicesList 返回的数据结构 //devicesList 返回的数据结构
//此处提供一个简单的示例,如下 //此处提供一个简单的示例,如下
[ [
...@@ -121,13 +121,12 @@ connectDevice(device: USBDevice): Readonly&lt;USBDevicePipe&gt; ...@@ -121,13 +121,12 @@ connectDevice(device: USBDevice): Readonly&lt;USBDevicePipe&gt;
let devicesList = usb.getDevices(); let devicesList = usb.getDevices();
if (devicesList.length == 0) { if (devicesList.length == 0) {
console.log(`device list is empty`); console.log(`device list is empty`);
return;
} }
let device = devicesList[0]; let device = devicesList[0];
usb.requestRight(device.name); usb.requestRight(device.name);
let devicepipe = usb.connectDevice(device); let devicepipe = usb.connectDevice(device);
console.log(`devicepipe = ${JSON.stringify(devicepipe)}`); console.log(`devicepipe = ${devicepipe}`);
``` ```
## usb.hasRight ## usb.hasRight
...@@ -185,7 +184,7 @@ requestRight(deviceName: string): Promise&lt;boolean&gt; ...@@ -185,7 +184,7 @@ requestRight(deviceName: string): Promise&lt;boolean&gt;
```js ```js
let devicesName="1-1"; let devicesName="1-1";
usb.requestRight(devicesName).then((ret) => { usb.requestRight(devicesName).then((ret) => {
console.log(`requestRight = ${JSON.stringify(ret)}`); console.log(`requestRight = ${ret}`);
}); });
``` ```
...@@ -213,7 +212,7 @@ removeRight(deviceName: string): boolean ...@@ -213,7 +212,7 @@ removeRight(deviceName: string): boolean
```js ```js
let devicesName="1-1"; let devicesName="1-1";
if (usb.removeRight(devicesName) { if usb.removeRight(devicesName) {
console.log(`Succeed in removing right`); console.log(`Succeed in removing right`);
} }
``` ```
...@@ -248,7 +247,7 @@ addRight(bundleName: string, deviceName: string): boolean ...@@ -248,7 +247,7 @@ addRight(bundleName: string, deviceName: string): boolean
```js ```js
let devicesName = "1-1"; let devicesName = "1-1";
let bundleName = "com.example.hello"; let bundleName = "com.example.hello";
if (usb.addRight(bundleName, devicesName) { if usb.addRight(bundleName, devicesName) {
console.log(`Succeed in adding right`); console.log(`Succeed in adding right`);
} }
``` ```
...@@ -457,8 +456,9 @@ controlTransfer(pipe: USBDevicePipe, controlparam: USBControlParams, timeout ?: ...@@ -457,8 +456,9 @@ controlTransfer(pipe: USBDevicePipe, controlparam: USBControlParams, timeout ?:
**示例:** **示例:**
```js ```js
usb.controlTransfer(devicepipe, USBControlParams).then((ret) => { let param = new usb.USBControlParams();
console.log(`controlTransfer = ${JSON.stringify(ret)}`); usb.controlTransfer(devicepipe, param).then((ret) => {
console.log(`controlTransfer = ${ret}`);
}) })
``` ```
...@@ -494,7 +494,7 @@ bulkTransfer(pipe: USBDevicePipe, endpoint: USBEndpoint, buffer: Uint8Array, tim ...@@ -494,7 +494,7 @@ bulkTransfer(pipe: USBDevicePipe, endpoint: USBEndpoint, buffer: Uint8Array, tim
//把获取到的设备对象作为参数传入usb.connectDevice;当usb.connectDevice接口成功返回之后; //把获取到的设备对象作为参数传入usb.connectDevice;当usb.connectDevice接口成功返回之后;
//才可以调用第三个接口usb.claimInterface.当usb.claimInterface 调用成功以后,再调用该接口。 //才可以调用第三个接口usb.claimInterface.当usb.claimInterface 调用成功以后,再调用该接口。
usb.bulkTransfer(devicepipe, endpoint, buffer).then((ret) => { usb.bulkTransfer(devicepipe, endpoint, buffer).then((ret) => {
console.log(`bulkTransfer = ${JSON.stringify(ret)}`); console.log(`bulkTransfer = ${ret}`);
}); });
``` ```
...@@ -581,7 +581,7 @@ usbFunctionsToString(funcs: FunctionType): string ...@@ -581,7 +581,7 @@ usbFunctionsToString(funcs: FunctionType): string
**示例:** **示例:**
```js ```js
let funcs = ACM | ECM; let funcs = usb.ACM | usb.ECM;
let ret = usb.usbFunctionsToString(funcs); let ret = usb.usbFunctionsToString(funcs);
``` ```
...@@ -610,7 +610,7 @@ setCurrentFunctions(funcs: FunctionType): Promise\<void\> ...@@ -610,7 +610,7 @@ setCurrentFunctions(funcs: FunctionType): Promise\<void\>
**示例:** **示例:**
```js ```js
let funcs = HDC; let funcs = usb.HDC;
usb.setCurrentFunctions(funcs).then(() => { usb.setCurrentFunctions(funcs).then(() => {
console.info('usb setCurrentFunctions successfully.'); console.info('usb setCurrentFunctions successfully.');
}).catch(err => { }).catch(err => {
...@@ -718,7 +718,7 @@ setPortRoles(portId: number, powerRole: PowerRoleType, dataRole: DataRoleType): ...@@ -718,7 +718,7 @@ setPortRoles(portId: number, powerRole: PowerRoleType, dataRole: DataRoleType):
```js ```js
let portId = 1; let portId = 1;
usb.usb.setPortRoles(portId, usb.PowerRoleType.SOURCE, usb.DataRoleType.HOST).then(() => { usb.setPortRoles(portId, usb.PowerRoleType.SOURCE, usb.DataRoleType.HOST).then(() => {
console.info('usb setPortRoles successfully.'); console.info('usb setPortRoles successfully.');
}).catch(err => { }).catch(err => {
console.error('usb setPortRoles failed: ' + err.code + ' message: ' + err.message); console.error('usb setPortRoles failed: ' + err.code + ' message: ' + err.message);
......
...@@ -30,7 +30,7 @@ getDevices(): Array&lt;Readonly&lt;USBDevice&gt;&gt; ...@@ -30,7 +30,7 @@ getDevices(): Array&lt;Readonly&lt;USBDevice&gt;&gt;
```js ```js
let devicesList = usb.getDevices(); let devicesList = usb.getDevices();
console.log(`devicesList = ${JSON.stringify(devicesList)}`); console.log(`devicesList = ${devicesList}`);
//devicesList 返回的数据结构 //devicesList 返回的数据结构
//此处提供一个简单的示例,如下 //此处提供一个简单的示例,如下
[ [
...@@ -119,13 +119,12 @@ connectDevice(device: USBDevice): Readonly&lt;USBDevicePipe&gt; ...@@ -119,13 +119,12 @@ connectDevice(device: USBDevice): Readonly&lt;USBDevicePipe&gt;
let devicesList = usb.getDevices(); let devicesList = usb.getDevices();
if (devicesList.length == 0) { if (devicesList.length == 0) {
console.log(`device list is empty`); console.log(`device list is empty`);
return;
} }
let device = devicesList[0]; let device = devicesList[0];
usb.requestRight(device.name); usb.requestRight(device.name);
let devicepipe = usb.connectDevice(device); let devicepipe = usb.connectDevice(device);
console.log(`devicepipe = ${JSON.stringify(devicepipe)}`); console.log(`devicepipe = ${devicepipe}`);
``` ```
## usb.hasRight ## usb.hasRight
...@@ -155,7 +154,7 @@ hasRight(deviceName: string): boolean ...@@ -155,7 +154,7 @@ hasRight(deviceName: string): boolean
```js ```js
let devicesName="1-1"; let devicesName="1-1";
let bool = usb.hasRight(devicesName); let bool = usb.hasRight(devicesName);
console.log(bool); console.log(`${bool}`);
``` ```
## usb.requestRight ## usb.requestRight
...@@ -183,7 +182,7 @@ requestRight(deviceName: string): Promise&lt;boolean&gt; ...@@ -183,7 +182,7 @@ requestRight(deviceName: string): Promise&lt;boolean&gt;
```js ```js
let devicesName="1-1"; let devicesName="1-1";
usb.requestRight(devicesName).then((ret) => { usb.requestRight(devicesName).then((ret) => {
console.log(`requestRight = ${JSON.stringify(ret)}`); console.log(`requestRight = ${ret}`);
}); });
``` ```
...@@ -211,7 +210,7 @@ removeRight(deviceName: string): boolean ...@@ -211,7 +210,7 @@ removeRight(deviceName: string): boolean
```js ```js
let devicesName="1-1"; let devicesName="1-1";
if (usb.removeRight(devicesName) { if usb.removeRight(devicesName) {
console.log(`Succeed in removing right`); console.log(`Succeed in removing right`);
} }
``` ```
...@@ -246,7 +245,7 @@ addRight(bundleName: string, deviceName: string): boolean ...@@ -246,7 +245,7 @@ addRight(bundleName: string, deviceName: string): boolean
```js ```js
let devicesName = "1-1"; let devicesName = "1-1";
let bundleName = "com.example.hello"; let bundleName = "com.example.hello";
if (usb.addRight(bundleName, devicesName) { if usb.addRight(bundleName, devicesName) {
console.log(`Succeed in adding right`); console.log(`Succeed in adding right`);
} }
``` ```
...@@ -455,8 +454,9 @@ controlTransfer(pipe: USBDevicePipe, controlparam: USBControlParams, timeout ?: ...@@ -455,8 +454,9 @@ controlTransfer(pipe: USBDevicePipe, controlparam: USBControlParams, timeout ?:
**示例:** **示例:**
```js ```js
usb.controlTransfer(devicepipe, USBControlParams).then((ret) => { let param = new usb.USBControlParams();
console.log(`controlTransfer = ${JSON.stringify(ret)}`); usb.controlTransfer(devicepipe, param).then((ret) => {
console.log(`controlTransfer = ${ret}`);
}) })
``` ```
...@@ -492,7 +492,7 @@ bulkTransfer(pipe: USBDevicePipe, endpoint: USBEndpoint, buffer: Uint8Array, tim ...@@ -492,7 +492,7 @@ bulkTransfer(pipe: USBDevicePipe, endpoint: USBEndpoint, buffer: Uint8Array, tim
//把获取到的设备对象作为参数传入usb.connectDevice;当usb.connectDevice接口成功返回之后; //把获取到的设备对象作为参数传入usb.connectDevice;当usb.connectDevice接口成功返回之后;
//才可以调用第三个接口usb.claimInterface.当usb.claimInterface 调用成功以后,再调用该接口。 //才可以调用第三个接口usb.claimInterface.当usb.claimInterface 调用成功以后,再调用该接口。
usb.bulkTransfer(devicepipe, endpoint, buffer).then((ret) => { usb.bulkTransfer(devicepipe, endpoint, buffer).then((ret) => {
console.log(`bulkTransfer = ${JSON.stringify(ret)}`); console.log(`bulkTransfer = ${ret}`);
}); });
``` ```
...@@ -579,7 +579,7 @@ usbFunctionsToString(funcs: FunctionType): string ...@@ -579,7 +579,7 @@ usbFunctionsToString(funcs: FunctionType): string
**示例:** **示例:**
```js ```js
let funcs = ACM | ECM; let funcs = usb.ACM | usb.ECM;
let ret = usb.usbFunctionsToString(funcs); let ret = usb.usbFunctionsToString(funcs);
``` ```
...@@ -608,7 +608,7 @@ setCurrentFunctions(funcs: FunctionType): Promise\<void\> ...@@ -608,7 +608,7 @@ setCurrentFunctions(funcs: FunctionType): Promise\<void\>
**示例:** **示例:**
```js ```js
let funcs = HDC; let funcs = usb.HDC;
usb.setCurrentFunctions(funcs).then(() => { usb.setCurrentFunctions(funcs).then(() => {
console.info('usb setCurrentFunctions successfully.'); console.info('usb setCurrentFunctions successfully.');
}).catch(err => { }).catch(err => {
...@@ -716,7 +716,7 @@ setPortRoles(portId: number, powerRole: PowerRoleType, dataRole: DataRoleType): ...@@ -716,7 +716,7 @@ setPortRoles(portId: number, powerRole: PowerRoleType, dataRole: DataRoleType):
```js ```js
let portId = 1; let portId = 1;
usb.usb.setPortRoles(portId, usb.PowerRoleType.SOURCE, usb.DataRoleType.HOST).then(() => { usb.setPortRoles(portId, usb.PowerRoleType.SOURCE, usb.DataRoleType.HOST).then(() => {
console.info('usb setPortRoles successfully.'); console.info('usb setPortRoles successfully.');
}).catch(err => { }).catch(err => {
console.error('usb setPortRoles failed: ' + err.code + ' message: ' + err.message); console.error('usb setPortRoles failed: ' + err.code + ' message: ' + err.message);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册