提交 083f7c38 编写于 作者: S shawn_he

update docs

Signed-off-by: Nshawn_he <shawn.he@huawei.com>
上级 65f93581
......@@ -5,7 +5,7 @@
## Modules to Import
```
```js
import usb from "@ohos.usb";
```
......@@ -17,13 +17,13 @@ Obtains the USB device list.
**System capability**: SystemCapability.USB.USBManager
- Return value
- **Return value**
| Type| Description|
| -------- | -------- |
| Array&lt;Readonly&lt;[USBDevice](#usbdevice)&gt;&gt; | Device information list.|
- Example
```
- **Example**
```js
let devicesList = usb.getDevices();
console.log(`devicesList = ${JSON.stringify(devicesList)}`);
// devicesList is a list of USB devices.
......@@ -89,18 +89,18 @@ Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB devi
**System capability**: SystemCapability.USB.USBManager
- Parameters
- **Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| device | [USBDevice](#usbdevice) | Yes| USB device information.|
- Return value
- **Return value**
| Type| Description|
| -------- | -------- |
| Readonly&lt;[USBDevicePipe](#usbdevicepipe)&gt; | USB device pipe for data transfer.|
- Example
```
- **Example**
```js
let devicepipe= usb.connectDevice(device);
console.log(`devicepipe = ${JSON.stringify(devicepipe)}`);
```
......@@ -114,18 +114,18 @@ Checks whether the application has the permission to access the device.
**System capability**: SystemCapability.USB.USBManager
- Parameters
- **Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| deviceName | string | Yes| Device name.|
- Return value
- **Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the application has the permission to access the device; returns **false** otherwise.|
- Example
```
- **Example**
```js
let divicesName="1-1";
let bool = usb.hasRight(divicesName);
console.log(bool);
......@@ -140,18 +140,18 @@ Requests the temporary permission for the application to access the USB device.
**System capability**: SystemCapability.USB.USBManager
- Parameters
- **Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| deviceName | string | Yes| Device name.|
- Return value
- **Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;boolean&gt; | Returns **true** if the temporary device access permissions are granted; returns **false** otherwise.|
- Example
```
- **Example**
```js
let divicesName="1-1";
usb.requestRight(divicesName).then((ret) => {
console.log(`requestRight = ${JSON.stringify(ret)}`);
......@@ -169,20 +169,20 @@ Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB devi
**System capability**: SystemCapability.USB.USBManager
- Parameters
- **Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| pipe | [USBDevicePipe](#usbdevicepipe) | Yes| Device pipe, which is used to determine the bus number and device address.|
| iface | [USBInterface](#usbinterface) | Yes| USB interface, which is used to determine the index of the interface to claim.|
| force | boolean | No| Whether to forcibly claim the USB interface. The default value is **false**, indicating not to forcibly claim the USB interface.|
- Return value
- **Return value**
| Type| Description|
| -------- | -------- |
| number | Returns **0** if the USB interface is successfully claimed; returns an error code otherwise.|
- Example
```
- **Example**
```js
let ret = usb.claimInterface(devicepipe, interfaces);
console.log(`claimInterface = ${ret}`);
```
......@@ -198,19 +198,19 @@ Before you do this, ensure that you have claimed the interface by calling [usb.c
**System capability**: SystemCapability.USB.USBManager
- Parameters
- **Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| pipe | [USBDevicePipe](#usbdevicepipe) | Yes| Device pipe, which is used to determine the bus number and device address.|
| iface | [USBInterface](#usbinterface) | Yes| USB interface, which is used to determine the index of the interface to release.|
- Return value
- **Return value**
| Type| Description|
| -------- | -------- |
| number | Returns **0** if the USB interface is successfully released; returns an error code otherwise.|
- Example
```
- **Example**
```js
let ret = usb.releaseInterface(devicepipe, interfaces);
console.log(`releaseInterface = ${ret}`);
```
......@@ -226,19 +226,19 @@ Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB devi
**System capability**: SystemCapability.USB.USBManager
- Parameters
- **Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| pipe | [USBDevicePipe](#usbdevicepipe) | Yes| Device pipe, which is used to determine the bus number and device address.|
| config | [USBConfig](#usbconfig) | Yes| USB configuration to set.|
- Return value
- **Return value**
| Type| Description|
| -------- | -------- |
| number | Returns **0** if the USB configuration is successfully set; returns an error code otherwise.|
- Example
```
- **Example**
```js
let ret = usb.setConfiguration(devicepipe, config);
console.log(`setConfiguration = ${ret}`);
```
......@@ -254,19 +254,19 @@ Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB devi
**System capability**: SystemCapability.USB.USBManager
- Parameters
- **Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| pipe | [USBDevicePipe](#usbdevicepipe) | Yes| Device pipe, which is used to determine the bus number and device address.|
| iface | [USBInterface](#usbinterface) | Yes| USB interface to set.|
- Return value
- **Return value**
| Type| Description|
| -------- | -------- |
| number | Returns **0** if the USB interface is successfully set; returns an error code otherwise.|
- Example
```
- **Example**
```js
let ret = usb.setInterface(devicepipe, interfaces);
console.log(`setInterface = ${ret}`);
```
......@@ -282,18 +282,18 @@ Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB devi
**System capability**: SystemCapability.USB.USBManager
- Parameters
- **Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| pipe | [USBDevicePipe](#usbdevicepipe) | Yes| Device pipe, which is used to determine the bus number and device address.|
- Return value
- **Return value**
| Type| Description|
| -------- | -------- |
| Uint8Array | Raw descriptor data.|
- Example
```
- **Example**
```js
let ret = usb.getRawDescriptor(devicepipe);
```
......@@ -308,18 +308,18 @@ Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB devi
**System capability**: SystemCapability.USB.USBManager
- Parameters
- **Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| pipe | [USBDevicePipe](#usbdevicepipe) | Yes| Device pipe, which is used to determine the bus number and device address.|
- Return value
- **Return value**
| Type| Description|
| -------- | -------- |
| number | File descriptor of the USB device.|
- Example
```
- **Example**
```js
let ret = usb.getFileDescriptor(devicepipe);
```
......@@ -334,20 +334,20 @@ Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB devi
**System capability**: SystemCapability.USB.USBManager
- Parameters
- **Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| pipe | [USBDevicePipe](#usbdevicepipe) | Yes| USB device pipe, which is used to determine the USB device.|
| contrlparam | [USBControlParams](#usbcontrolparams) | Yes| Control transfer parameters.|
| timeout | number | No| Timeout duration. The default value is **0**, indicating no timeout.|
- Return value
- **Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;number&gt; | Returns the size of the transmitted or received data block if the control transfer is successful; returns **-1** if an exception occurs.|
- Example
```
- **Example**
```js
usb.controlTransfer(devicepipe, USBControlParams).then((ret) => {
console.log(`controlTransfer = ${JSON.stringify(ret)}`);
})
......@@ -364,7 +364,7 @@ Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB devi
**System capability**: SystemCapability.USB.USBManager
- Parameters
- **Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| pipe | [USBDevicePipe](#usbdevicepipe) | Yes| USB device pipe, which is used to determine the USB device.|
......@@ -372,13 +372,13 @@ Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB devi
| buffer | Uint8Array | Yes| Buffer for writing or reading data.|
| timeout | number | No| Timeout duration. The default value is **0**, indicating no timeout.|
- Return value
- **Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;number&gt; | Returns the size of the transmitted or received data block if the control transfer is successful; returns **-1** if an exception occurs.|
- Example
```
- **Example**
```js
// Call usb.getDevices to obtain a data set. Then, obtain a USB device and its access permission.
// Pass the obtained USB device as a parameter to usb.connectDevice. Then, call usb.connectDevice to connect the USB device.
// Call usb.claimInterface to claim the USB interface. After that, call usb.bulkTransfer to start bulk transfer.
......@@ -398,18 +398,18 @@ Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB devi
**System capability**: SystemCapability.USB.USBManager
- Parameters
- **Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| pipe | [USBDevicePipe](#usbdevicepipe) | Yes| USB device pipe.|
- Return value
- **Return value**
| Type| Description|
| -------- | -------- |
| number | Returns **0** if the USB device pipe is closed successfully; returns an error code otherwise.|
- Example
```
- **Example**
```js
let ret = usb.closePipe(devicepipe);
console.log(`closePipe = ${ret}`);
```
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册