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

update docs

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