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

!24115 fix:Modifying arkts alarms

Merge pull request !24115 from 马海/master
......@@ -8,7 +8,7 @@
## 导入模块
```js
```ts
import usb from "@ohos.usbManager";
```
......@@ -28,8 +28,9 @@ getDevices(): Array<Readonly<USBDevice>>
**示例:**
```js
let devicesList = usb.getDevices();
```ts
/*
let devicesList: Array<USBDevice> = usb.getDevices();
console.log(`devicesList = ${devicesList}`);
//devicesList 返回的数据结构
//此处提供一个简单的示例,如下
......@@ -81,6 +82,7 @@ console.log(`devicesList = ${devicesList}`);
],
},
]
*/
```
## usb.connectDevice
......@@ -115,15 +117,15 @@ connectDevice(device: USBDevice): Readonly&lt;USBDevicePipe&gt;
**示例:**
```js
let devicesList = usb.getDevices();
```ts
let devicesList: Array<USBDevice> = usb.getDevices();
if (devicesList.length == 0) {
console.log(`device list is empty`);
}
let device = devicesList[0];
let device: USBDevice = devicesList[0];
usb.requestRight(device.name);
let devicepipe = usb.connectDevice(device);
let devicepipe: USBDevicePipe = usb.connectDevice(device);
console.log(`devicepipe = ${devicepipe}`);
```
......@@ -151,10 +153,10 @@ hasRight(deviceName: string): boolean
**示例:**
```js
let devicesName = "1-1";
let bool = usb.hasRight(devicesName);
console.log(`${bool}`);
```ts
let devicesName: string = "1-1";
let right: boolean = usb.hasRight(devicesName);
console.log(`${right}`);
```
## usb.requestRight
......@@ -179,9 +181,9 @@ requestRight(deviceName: string): Promise&lt;boolean&gt;
**示例:**
```js
let devicesName = "1-1";
usb.requestRight(devicesName).then((ret) => {
```ts
let devicesName: string = "1-1";
usb.requestRight(devicesName:).then((ret: number) => {
console.log(`requestRight = ${ret}`);
});
```
......@@ -208,8 +210,8 @@ removeRight(deviceName: string): boolean
**示例:**
```js
let devicesName = "1-1";
```ts
let devicesName: string = "1-1";
if (usb.removeRight(devicesName)) {
console.log(`Succeed in removing right`);
}
......@@ -242,9 +244,9 @@ addRight(bundleName: string, deviceName: string): boolean
**示例:**
```js
let devicesName = "1-1";
let bundleName = "com.example.hello";
```ts
let devicesName: string = "1-1";
let bundleName: string = "com.example.hello";
if (usb.addRight(bundleName, devicesName)) {
console.log(`Succeed in adding right`);
}
......@@ -276,17 +278,17 @@ claimInterface(pipe: USBDevicePipe, iface: USBInterface, force ?: boolean): numb
**示例:**
```js
let devicesList = usb.getDevices();
```ts
let devicesList: Array<USBDevice> = usb.getDevices();
if (devicesList.length == 0) {
console.log(`device list is empty`);
}
let device = devicesList[0];
let device: USBDevice = devicesList[0];
usb.requestRight(device.name);
let devicepipe = usb.connectDevice(device);
let interfaces = device.configs[0].interfaces[0];
let ret = usb.claimInterface(devicepipe, interfaces);
let devicepipe: USBDevicePipe = usb.connectDevice(device);
let interfaces: USBInterface = device.configs[0].interfaces[0];
let ret: number= usb.claimInterface(devicepipe, interfaces);
console.log(`claimInterface = ${ret}`);
```
......@@ -315,17 +317,17 @@ releaseInterface(pipe: USBDevicePipe, iface: USBInterface): number
**示例:**
```js
let devicesList = usb.getDevices();
```ts
let devicesList: Array<USBDevice> = usb.getDevices();
if (devicesList.length == 0) {
console.log(`device list is empty`);
}
let device = devicesList[0];
let device: USBDevice = devicesList[0];
usb.requestRight(device.name);
let devicepipe = usb.connectDevice(device);
let interfaces = device.configs[0].interfaces[0];
let ret = usb.claimInterface(devicepipe, interfaces);
let devicepipe: USBDevicePipe = usb.connectDevice(device);
let interfaces: USBInterface = device.configs[0].interfaces[0];
let ret: number = usb.claimInterface(devicepipe, interfaces);
ret = usb.releaseInterface(devicepipe, interfaces);
console.log(`releaseInterface = ${ret}`);
```
......@@ -355,17 +357,17 @@ setConfiguration(pipe: USBDevicePipe, config: USBConfiguration): number
**示例:**
```js
let devicesList = usb.getDevices();
```ts
let devicesList: Array<USBDevice> = usb.getDevices();
if (devicesList.length == 0) {
console.log(`device list is empty`);
}
let device = devicesList[0];
let device: USBDevice = devicesList[0];
usb.requestRight(device.name);
let devicepipe = usb.connectDevice(device);
let config = device.configs[0];
let ret = usb.setConfiguration(devicepipe, config);
let devicepipe: USBDevicePipe = usb.connectDevice(device);
let config: USBConfiguration = device.configs[0];
let ret: number= usb.setConfiguration(devicepipe, config);
console.log(`setConfiguration = ${ret}`);
```
......@@ -394,17 +396,17 @@ setInterface(pipe: USBDevicePipe, iface: USBInterface): number
**示例:**
```js
let devicesList = usb.getDevices();
```ts
let devicesList: Array<USBDevice> = usb.getDevices();
if (devicesList.length == 0) {
console.log(`device list is empty`);
}
let device = devicesList[0];
let device: USBDevice = devicesList[0];
usb.requestRight(device.name);
let devicepipe = usb.connectDevice(device);
let interfaces = device.configs[0].interfaces[0];
let ret = usb.claimInterface(devicepipe, interfaces);
let devicepipe: USBDevicePipe = usb.connectDevice(device);
let interfaces: USBInterface = device.configs[0].interfaces[0];
let ret: number = usb.claimInterface(devicepipe, interfaces);
ret = usb.setInterface(devicepipe, interfaces);
console.log(`setInterface = ${ret}`);
```
......@@ -433,15 +435,15 @@ getRawDescriptor(pipe: USBDevicePipe): Uint8Array
**示例:**
```js
let devicesList = usb.getDevices();
```ts
let devicesList: Array<USBDevice> = usb.getDevices();
if (devicesList.length == 0) {
console.log(`device list is empty`);
}
usb.requestRight(devicesList[0].name);
let devicepipe = usb.connectDevice(devicesList[0]);
let ret = usb.getRawDescriptor(devicepipe);
let devicepipe: USBDevicePipe = usb.connectDevice(devicesList[0]);
let ret: number = usb.getRawDescriptor(devicepipe);
```
## usb.getFileDescriptor
......@@ -468,15 +470,15 @@ getFileDescriptor(pipe: USBDevicePipe): number
**示例:**
```js
let devicesList = usb.getDevices();
```ts
let devicesList: Array<USBDevice> = usb.getDevices();
if (devicesList.length == 0) {
console.log(`device list is empty`);
}
usb.requestRight(devicesList[0].name);
let devicepipe = usb.connectDevice(devicesList[0]);
let ret = usb.getFileDescriptor(devicepipe);
let devicepipe: USBDevicePipe = usb.connectDevice(devicesList[0]);
let ret: number = usb.getFileDescriptor(devicepipe);
```
## usb.controlTransfer
......@@ -505,8 +507,8 @@ controlTransfer(pipe: USBDevicePipe, controlparam: USBControlParams, timeout ?:
**示例:**
```js
let param = {
```ts
let param: number = {
request: 0,
reqType: 0,
target:0,
......@@ -515,14 +517,14 @@ let param = {
data: null
};
let devicesList = usb.getDevices();
let devicesList: Array<USBDevice> = usb.getDevices();
if (devicesList.length == 0) {
console.log(`device list is empty`);
}
usb.requestRight(devicesList[0].name);
let devicepipe = usb.connectDevice(devicesList[0]);
usb.controlTransfer(devicepipe, param).then((ret) => {
let devicepipe: USBDevicePipe = usb.connectDevice(devicesList[0]);
usb.controlTransfer(devicepipe, param).then((ret: number) => {
console.log(`controlTransfer = ${ret}`);
})
```
......@@ -554,24 +556,24 @@ bulkTransfer(pipe: USBDevicePipe, endpoint: USBEndpoint, buffer: Uint8Array, tim
**示例:**
```js
```ts
//usb.getDevices 接口返回数据集合,取其中一个设备对象,并获取权限 。
//把获取到的设备对象作为参数传入usb.connectDevice;当usb.connectDevice接口成功返回之后;
//才可以调用第三个接口usb.claimInterface.当usb.claimInterface 调用成功以后,再调用该接口。
let devicesList = usb.getDevices();
let devicesList: Array<USBDevice> = usb.getDevices();
if (devicesList.length == 0) {
console.log(`device list is empty`);
}
let device = devicesList[0];
let device: USBDevice = devicesList[0];
usb.requestRight(device.name);
let devicepipe = usb.connectDevice(device);
let interfaces = device.configs[0].interfaces[0];
let endpoint = device.configs[0].interfaces[0].endpoints[0];
let ret = usb.claimInterface(devicepipe, interfaces);
let devicepipe: USBDevicePipe = usb.connectDevice(device);
let interfaces: USBInterface = device.configs[0].interfaces[0];
let endpoint: USBEndpoint = device.configs[0].interfaces[0].endpoints[0];
let ret: number = usb.claimInterface(devicepipe, interfaces);
let buffer = new Uint8Array(128);
usb.bulkTransfer(devicepipe, endpoint, buffer).then((ret) => {
usb.bulkTransfer(devicepipe, endpoint, buffer).then((ret: number) => {
console.log(`bulkTransfer = ${ret}`);
});
```
......@@ -600,15 +602,15 @@ closePipe(pipe: USBDevicePipe): number
**示例:**
```js
let devicesList = usb.getDevices();
```ts
let devicesList: Array<USBDevice> = usb.getDevices();
if (devicesList.length == 0) {
console.log(`device list is empty`);
}
usb.requestRight(devicesList[0].name);
let devicepipe = usb.connectDevice(devicesList[0]);
let ret = usb.closePipe(devicepipe);
let devicepipe: USBDevicePipe = usb.connectDevice(devicesList[0]);
let ret: number = usb.closePipe(devicepipe);
console.log(`closePipe = ${ret}`);
```
......@@ -636,9 +638,9 @@ usbFunctionsFromString(funcs: string): number
**示例:**
```js
let funcs = "acm";
let ret = usb.usbFunctionsFromString(funcs);
```ts
let funcs: string = "acm";
let ret: number = usb.usbFunctionsFromString(funcs);
```
## usb.usbFunctionsToString
......@@ -665,9 +667,9 @@ usbFunctionsToString(funcs: FunctionType): string
**示例:**
```js
let funcs = usb.FunctionType.ACM | usb.FunctionType.ECM;
let ret = usb.usbFunctionsToString(funcs);
```ts
let funcs: string = usb.FunctionType.ACM | usb.FunctionType.ECM;
let ret: number = usb.usbFunctionsToString(funcs);
```
## usb.setCurrentFunctions
......@@ -702,11 +704,12 @@ setCurrentFunctions(funcs: FunctionType): Promise\<void\>
**示例:**
```js
let funcs = usb.FunctionType.HDC;
```ts
import {BusinessError} from '@ohos.base';
let funcs: string = usb.FunctionType.HDC;
usb.setCurrentFunctions(funcs).then(() => {
console.info('usb setCurrentFunctions successfully.');
}).catch(err => {
}).catch(err: BusinessError => {
console.error('usb setCurrentFunctions failed: ' + err.code + ' message: ' + err.message);
});
```
......@@ -729,8 +732,8 @@ getCurrentFunctions(): FunctionType
**示例:**
```js
let ret = usb.getCurrentFunctions();
```ts
let ret: number = usb.getCurrentFunctions();
```
## usb.getPorts
......@@ -751,8 +754,8 @@ getPorts(): Array\<USBPort\>
**示例:**
```js
let ret = usb.getPorts();
```ts
let ret: number = usb.getPorts();
```
## usb.getSupportedModes
......@@ -779,8 +782,8 @@ getSupportedModes(portId: number): PortModeType
**示例:**
```js
let ret = usb.getSupportedModes(0);
```ts
let ret: number = usb.getSupportedModes(0);
```
## usb.setPortRoles
......@@ -809,11 +812,12 @@ setPortRoles(portId: number, powerRole: PowerRoleType, dataRole: DataRoleType):
**示例:**
```js
let portId = 1;
```ts
import {BusinessError} from '@ohos.base';
let portId: number = 1;
usb.setPortRoles(portId, usb.PowerRoleType.SOURCE, usb.DataRoleType.HOST).then(() => {
console.info('usb setPortRoles successfully.');
}).catch(err => {
}).catch(: BusinessError => {
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.
先完成此消息的编辑!
想要评论请 注册