提交 30eea4e0 编写于 作者: W wusongqing

updated docs

Signed-off-by: Nwusongqing <wusongqing@huawei.com>
上级 f4ffb34e
# Display # Display
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE** > **NOTE**
>
> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import ## Modules to Import
...@@ -56,26 +57,27 @@ getDefaultDisplay(callback: AsyncCallback&lt;Display&gt;): void ...@@ -56,26 +57,27 @@ getDefaultDisplay(callback: AsyncCallback&lt;Display&gt;): void
Obtains the default display object. Obtains the default display object.
**System capabilities**: SystemCapability.WindowManager.WindowManager.Core **System capability**: SystemCapability.WindowManager.WindowManager.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;[Display](#display)&gt; | Yes| Callback used to return the default display object.|
- Example | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;[Display](#display)&gt; | Yes| Callback used to return the default display object.|
```js **Example**
var displayClass = null;
display.getDefaultDisplay((err, data) => { ```js
if (err.code) { var displayClass = null;
console.error('Failed to obtain the default display object. Code: ' + JSON.stringify(err)); display.getDefaultDisplay((err, data) => {
return; if (err.code) {
} console.error('Failed to obtain the default display object. Code: ' + JSON.stringify(err));
console.info('Succeeded in obtaining the default display object. Data:' + JSON.stringify(data)); return;
displayClass = data; }
}); console.info('Succeeded in obtaining the default display object. Data:' + JSON.stringify(data));
``` displayClass = data;
});
```
## display.getDefaultDisplay ## display.getDefaultDisplay
...@@ -83,24 +85,24 @@ getDefaultDisplay(): Promise&lt;Display&gt; ...@@ -83,24 +85,24 @@ getDefaultDisplay(): Promise&lt;Display&gt;
Obtains the default display object. Obtains the default display object.
**System capabilities**: SystemCapability.WindowManager.WindowManager.Core **System capability**: SystemCapability.WindowManager.WindowManager.Core
- Return value **Return value**
| Type | Description | | Type | Description |
| ---------------------------------- | ---------------------------------------------- | | ---------------------------------- | ---------------------------------------------- |
| Promise&lt;[Display](#display)&gt; | Promise used to return the default display object.| | Promise&lt;[Display](#display)&gt; | Promise used to return the default display object.|
- Example **Example**
```js ```js
let promise = display.getDefaultDisplay(); let promise = display.getDefaultDisplay();
promise.then(() => { promise.then(() => {
console.log('getDefaultDisplay success'); console.log('getDefaultDisplay success');
}).catch((err) => { }).catch((err) => {
console.log('getDefaultDisplay fail: ' + JSON.stringify(err)); console.log('getDefaultDisplay fail: ' + JSON.stringify(err));
}); });
``` ```
## display.getAllDisplay ## display.getAllDisplay
...@@ -108,25 +110,25 @@ getAllDisplay(callback: AsyncCallback&lt;Array&lt;Display&gt;&gt;): void ...@@ -108,25 +110,25 @@ getAllDisplay(callback: AsyncCallback&lt;Array&lt;Display&gt;&gt;): void
Obtains all the display objects. Obtains all the display objects.
**System capabilities**: SystemCapability.WindowManager.WindowManager.Core **System capability**: SystemCapability.WindowManager.WindowManager.Core
- Parameters **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ---------------------------------------------------- | ---- | ------------------------------- | | -------- | ---------------------------------------------------- | ---- | ------------------------------- |
| callback | AsyncCallback&lt;Array&lt;[Display](#display)&gt;&gt; | Yes | Callback used to return all the display objects.| | callback | AsyncCallback&lt;Array&lt;[Display](#display)&gt;&gt; | Yes | Callback used to return all the display objects.|
- Example **Example**
```js ```js
display.getAllDisplay((err, data) => { display.getAllDisplay((err, data) => {
if (err.code) { if (err.code) {
console.error('Failed to obtain all the display objects. Code: ' + JSON.stringify(err)); console.error('Failed to obtain all the display objects. Code: ' + JSON.stringify(err));
return; return;
} }
console.info('Succeeded in obtaining all the display objects. Data: ' + JSON.stringify(data)) console.info('Succeeded in obtaining all the display objects. Data: ' + JSON.stringify(data))
}); });
``` ```
## display.getAllDisplay ## display.getAllDisplay
...@@ -134,24 +136,24 @@ getAllDisplay(): Promise&lt;Array&lt;Display&gt;&gt; ...@@ -134,24 +136,24 @@ getAllDisplay(): Promise&lt;Array&lt;Display&gt;&gt;
Obtains all the display objects. Obtains all the display objects.
**System capabilities**: SystemCapability.WindowManager.WindowManager.Core **System capability**: SystemCapability.WindowManager.WindowManager.Core
- Return value **Return value**
| Type | Description | | Type | Description |
| ----------------------------------------------- | ------------------------------------------------------- | | ----------------------------------------------- | ------------------------------------------------------- |
| Promise&lt;Array&lt;[Display](#display)&gt;&gt; | Promise used to return an array containing all the display objects.| | Promise&lt;Array&lt;[Display](#display)&gt;&gt; | Promise used to return an array containing all the display objects.|
- Example **Example**
```js ```js
let promise = display.getAllDisplay(); let promise = display.getAllDisplay();
promise.then(() => { promise.then(() => {
console.log('getAllDisplay success'); console.log('getAllDisplay success');
}).catch((err) => { }).catch((err) => {
console.log('getAllDisplay fail: ' + JSON.stringify(err)); console.log('getAllDisplay fail: ' + JSON.stringify(err));
}); });
``` ```
## display.on('add'|'remove'|'change') ## display.on('add'|'remove'|'change')
...@@ -159,23 +161,24 @@ on(type: 'add'|'remove'|'change', callback: Callback&lt;number&gt;): void ...@@ -159,23 +161,24 @@ on(type: 'add'|'remove'|'change', callback: Callback&lt;number&gt;): void
Enables listening. Enables listening.
**System capabilities**: SystemCapability.WindowManager.WindowManager.Core **System capability**: SystemCapability.WindowManager.WindowManager.Core
**Parameters**
- Parameters | Name| Type| Mandatory| Description|
| Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- | | type | string | Yes| Listening type. The available values are as follows:<br>-&nbsp;**add**: listening for whether a display is added<br>-&nbsp;**remove**: listening for whether a display is removed<br>-&nbsp;**change**: listening for whether a display is changed|
| type | string | Yes| Listening type. The available values are as follows:<br>-&nbsp;**add**: listening for whether a display is added<br>-&nbsp;**remove**: listening for whether a display is removed<br>-&nbsp;**change**: listening for whether a display is changed| | callback | Callback&lt;number&gt; | Yes| Callback used to return the ID of the display.|
| callback | Callback&lt;number&gt; | Yes| Callback used to return the ID of the display.|
- Example **Example**
```js ```js
var type = "add"; var type = "add";
var callback = (data) => { var callback = (data) => {
console.info('Listening enabled. Data: ' + JSON.stringify(data)) console.info('Listening enabled. Data: ' + JSON.stringify(data))
} }
display.on(type, callback); display.on(type, callback);
``` ```
## display.off('add'|'remove'|'change') ## display.off('add'|'remove'|'change')
...@@ -184,17 +187,18 @@ off(type: 'add'|'remove'|'change', callback?: Callback&lt;number&gt;): void ...@@ -184,17 +187,18 @@ off(type: 'add'|'remove'|'change', callback?: Callback&lt;number&gt;): void
Disables listening. Disables listening.
**System capabilities**: SystemCapability.WindowManager.WindowManager.Core **System capability**: SystemCapability.WindowManager.WindowManager.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| type | string | Yes| Listening type. The available values are as follows:<br>-&nbsp;**add**: listening for whether a display is added<br>-&nbsp;**remove**: listening for whether a display is removed<br>-&nbsp;**change**: listening for whether a display is changed|
| callback | Callback&lt;number&gt; | No| Callback used to return the ID of the display.|
- Example | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| type | string | Yes| Listening type. The available values are as follows:<br>-&nbsp;**add**: listening for whether a display is added<br>-&nbsp;**remove**: listening for whether a display is removed<br>-&nbsp;**change**: listening for whether a display is changed|
| callback | Callback&lt;number&gt; | No| Callback used to return the ID of the display.|
```js **Example**
var type = "remove";
display.off(type); ```js
``` var type = "remove";
display.off(type);
```
\ No newline at end of file
# Screenshot # Screenshot
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE** > **NOTE**
>
> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import ## Modules to Import
...@@ -54,39 +55,39 @@ save(options?: ScreenshotOptions, callback: AsyncCallback&lt;image.PixelMap&gt;) ...@@ -54,39 +55,39 @@ save(options?: ScreenshotOptions, callback: AsyncCallback&lt;image.PixelMap&gt;)
Takes a screenshot and saves it as a **PixelMap** object. This method uses a callback to return the result. Takes a screenshot and saves it as a **PixelMap** object. This method uses a callback to return the result.
**System capabilities**: SystemCapability.WindowManager.WindowManager.Core **System capability**: SystemCapability.WindowManager.WindowManager.Core
**Required permissions**: ohos.permission.CAPTURE_SCREEN **Required permissions**: ohos.permission.CAPTURE_SCREEN
- Parameters **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ------------------------------------------------------------ | | -------- | --------------------------------------- | ---- | ------------------------------------------------------------ |
| options | [ScreenshotOptions](#screenshotoptions) | No | Screenshot options, which consist of **screenRect**, **imageSize**, and **rotation**. You need to set these parameters.| | options | [ScreenshotOptions](#screenshotoptions) | No | Screenshot options, which consist of **screenRect**, **imageSize**, and **rotation**. You need to set these parameters.|
| callback | AsyncCallback&lt;image.PixelMap&gt; | Yes | Callback used to return a **PixelMap** object. | | callback | AsyncCallback&lt;image.PixelMap&gt; | Yes | Callback used to return a **PixelMap** object. |
- Example **Example**
```js ```js
var ScreenshotOptions = { var ScreenshotOptions = {
"screenRect": { "screenRect": {
"left": 200, "left": 200,
"top": 100, "top": 100,
"width": 200, "width": 200,
"height": 200}, "height": 200},
"imageSize": { "imageSize": {
"width": 300, "width": 300,
"height": 300}, "height": 300},
"rotation": 0 "rotation": 0
}; };
screenshot.save(ScreenshotOptions, (err, data) => { screenshot.save(ScreenshotOptions, (err, data) => {
if (err) { if (err) {
console.error('Failed to save the screenshot. Error: ' + JSON.stringify(err)); console.error('Failed to save the screenshot. Error: ' + JSON.stringify(err));
return; return;
} }
console.info('Screenshot saved. Data: ' + JSON.stringify(data)); console.info('Screenshot saved. Data: ' + JSON.stringify(data));
}); });
``` ```
## screenshot.save ## screenshot.save
...@@ -94,40 +95,40 @@ save(options?: ScreenshotOptions): Promise&lt;image.PixelMap&gt; ...@@ -94,40 +95,40 @@ save(options?: ScreenshotOptions): Promise&lt;image.PixelMap&gt;
Takes a screenshot and saves it as a **PixelMap** object. This method uses a promise to return the result. Takes a screenshot and saves it as a **PixelMap** object. This method uses a promise to return the result.
**System capabilities**: SystemCapability.WindowManager.WindowManager.Core **System capability**: SystemCapability.WindowManager.WindowManager.Core
**Required permissions**: ohos.permission.CAPTURE_SCREEN **Required permissions**: ohos.permission.CAPTURE_SCREEN
- Parameters **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ------- | --------------------------------------- | ---- | ------------------------------------------------------------ | | ------- | --------------------------------------- | ---- | ------------------------------------------------------------ |
| options | [ScreenshotOptions](#screenshotoptions) | No | Screenshot options, which consist of **screenRect**, **imageSize**, and **rotation**. You need to set these parameters.| | options | [ScreenshotOptions](#screenshotoptions) | No | Screenshot options, which consist of **screenRect**, **imageSize**, and **rotation**. You need to set these parameters.|
- Return value **Return value**
| Type | Description | | Type | Description |
| ----------------------------- | ----------------------------------------------- | | ----------------------------- | ----------------------------------------------- |
| Promise&lt;image.PixelMap&gt; | Promise used to return an **image.PixelMap** object.| | Promise&lt;image.PixelMap&gt; | Promise used to return an **image.PixelMap** object.|
- Example **Example**
```js ```js
var ScreenshotOptions = { var ScreenshotOptions = {
"screenRect": { "screenRect": {
"left": 200, "left": 200,
"top": 100, "top": 100,
"width": 200, "width": 200,
"height": 200}, "height": 200},
"imageSize": { "imageSize": {
"width": 300, "width": 300,
"height": 300}, "height": 300},
"rotation": 0 "rotation": 0
}; };
let promise = screenshot.save(ScreenshotOptions); let promise = screenshot.save(ScreenshotOptions);
promise.then(() => { promise.then(() => {
console.log('screenshot save success'); console.log('screenshot save success');
}).catch((err) => { }).catch((err) => {
console.log('screenshot save fail: ' + JSON.stringify(err)); console.log('screenshot save fail: ' + JSON.stringify(err));
}); });
``` ```
\ No newline at end of file
# USB # USB
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE** > **NOTE**
>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import ## Modules to Import
...@@ -17,66 +18,68 @@ Obtains the USB device list. ...@@ -17,66 +18,68 @@ 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**
let devicesList = usb.getDevices();
console.log(`devicesList = ${JSON.stringify(devicesList)}`); ```
// devicesList is a list of USB devices. let devicesList = usb.getDevices();
// A simple example of devicesList is provided as follows: console.log(`devicesList = ${JSON.stringify(devicesList)}`);
[ // devicesList is a list of USB devices.
{ // A simple example of devicesList is provided as follows:
name: "1-1", [
serial: "", {
manufacturerName: "", name: "1-1",
productName: "", serial: "",
version: "", manufacturerName: "",
vendorId: 7531, productName: "",
productId: 2, version: "",
clazz: 9, vendorId: 7531,
subclass: 0, productId: 2,
protocol: 1, clazz: 9,
devAddress: 1, subclass: 0,
busNum: 1, protocol: 1,
configs: [ devAddress: 1,
{ busNum: 1,
id: 1, configs: [
attributes: 224, {
isRemoteWakeup: true, id: 1,
isSelfPowered: true, attributes: 224,
maxPower: 0, isRemoteWakeup: true,
name: "1-1", isSelfPowered: true,
interfaces: [ maxPower: 0,
{ name: "1-1",
id: 0, interfaces: [
protocol: 0, {
clazz: 9, id: 0,
subclass: 0, protocol: 0,
alternateSetting: 0, clazz: 9,
name: "1-1", subclass: 0,
endpoints: [ alternateSetting: 0,
{ name: "1-1",
address: 129, endpoints: [
attributes: 3, {
interval: 12, address: 129,
maxPacketSize: 4, attributes: 3,
direction: 128, interval: 12,
number: 1, maxPacketSize: 4,
type: 3, direction: 128,
interfaceId: 0, number: 1,
}, type: 3,
], interfaceId: 0,
}, },
], ],
}, },
], ],
}, },
] ],
``` },
]
```
## usb.connectDevice ## usb.connectDevice
...@@ -89,21 +92,24 @@ Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB devi ...@@ -89,21 +92,24 @@ 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|
| -------- | -------- | -------- | -------- |
| device | [USBDevice](#usbdevice) | Yes| USB device information.|
- Return value | Name| Type| Mandatory| Description|
| Type| Description| | -------- | -------- | -------- | -------- |
| -------- | -------- | | device | [USBDevice](#usbdevice) | Yes| USB device information.|
| Readonly&lt;[USBDevicePipe](#usbdevicepipe)&gt; | USB device pipe for data transfer.|
- Example **Return value**
```
let devicepipe= usb.connectDevice(device); | Type| Description|
console.log(`devicepipe = ${JSON.stringify(devicepipe)}`); | -------- | -------- |
``` | Readonly&lt;[USBDevicePipe](#usbdevicepipe)&gt; | USB device pipe for data transfer.|
**Example**
```
let devicepipe= usb.connectDevice(device);
console.log(`devicepipe = ${JSON.stringify(devicepipe)}`);
```
## usb.hasRight ## usb.hasRight
...@@ -114,22 +120,25 @@ Checks whether the application has the permission to access the device. ...@@ -114,22 +120,25 @@ 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**
```
let divicesName="1-1"; ```
let bool = usb.hasRight(divicesName); let divicesName="1-1";
console.log(bool); let bool = usb.hasRight(divicesName);
``` console.log(bool);
```
## usb.requestRight ## usb.requestRight
...@@ -140,23 +149,26 @@ Requests the temporary permission for the application to access the USB device. ...@@ -140,23 +149,26 @@ 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|
| -------- | -------- |
| Promise&lt;boolean&gt; | Returns **true** if the temporary device access permissions are granted; returns **false** otherwise.|
- Example | Type| Description|
``` | -------- | -------- |
let divicesName="1-1"; | Promise&lt;boolean&gt; | Returns **true** if the temporary device access permissions are granted; returns **false** otherwise.|
usb.requestRight(divicesName).then((ret) => {
console.log(`requestRight = ${JSON.stringify(ret)}`); **Example**
});
``` ```
let divicesName="1-1";
usb.requestRight(divicesName).then((ret) => {
console.log(`requestRight = ${JSON.stringify(ret)}`);
});
```
## usb.claimInterface ## usb.claimInterface
...@@ -169,23 +181,26 @@ Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB devi ...@@ -169,23 +181,26 @@ 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.| | -------- | -------- | -------- | -------- |
| iface | [USBInterface](#usbinterface) | Yes| USB interface, which is used to determine the index of the interface to claim.| | pipe | [USBDevicePipe](#usbdevicepipe) | Yes| Device pipe, which is used to determine the bus number and device address.|
| force | boolean | No| Whether to forcibly claim the USB interface. The default value is **false**, indicating not to forcibly claim the USB interface.| | 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 | Type| Description|
``` | -------- | -------- |
let ret = usb.claimInterface(devicepipe, interfaces); | number | Returns **0** if the USB interface is successfully claimed; returns an error code otherwise.|
console.log(`claimInterface = ${ret}`);
``` **Example**
```
let ret = usb.claimInterface(devicepipe, interfaces);
console.log(`claimInterface = ${ret}`);
```
## usb.releaseInterface ## usb.releaseInterface
...@@ -198,22 +213,25 @@ Before you do this, ensure that you have claimed the interface by calling [usb.c ...@@ -198,22 +213,25 @@ 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|
| -------- | -------- | -------- | -------- |
| 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 | Name| Type| Mandatory| Description|
| Type| Description| | -------- | -------- | -------- | -------- |
| -------- | -------- | | pipe | [USBDevicePipe](#usbdevicepipe) | Yes| Device pipe, which is used to determine the bus number and device address.|
| number | Returns **0** if the USB interface is successfully released; returns an error code otherwise.| | iface | [USBInterface](#usbinterface) | Yes| USB interface, which is used to determine the index of the interface to release.|
- Example **Return value**
```
let ret = usb.releaseInterface(devicepipe, interfaces); | Type| Description|
console.log(`releaseInterface = ${ret}`); | -------- | -------- |
``` | number | Returns **0** if the USB interface is successfully released; returns an error code otherwise.|
**Example**
```
let ret = usb.releaseInterface(devicepipe, interfaces);
console.log(`releaseInterface = ${ret}`);
```
## usb.setConfiguration ## usb.setConfiguration
...@@ -226,22 +244,25 @@ Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB devi ...@@ -226,22 +244,25 @@ 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.| | -------- | -------- | -------- | -------- |
| config | [USBConfig](#usbconfig) | Yes| USB configuration to set.| | 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 | Type| Description|
``` | -------- | -------- |
let ret = usb.setConfiguration(devicepipe, config); | number | Returns **0** if the USB configuration is successfully set; returns an error code otherwise.|
console.log(`setConfiguration = ${ret}`);
``` **Example**
```
let ret = usb.setConfiguration(devicepipe, config);
console.log(`setConfiguration = ${ret}`);
```
## usb.setInterface ## usb.setInterface
...@@ -254,22 +275,25 @@ Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB devi ...@@ -254,22 +275,25 @@ 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|
| -------- | -------- | -------- | -------- |
| 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 | Name| Type| Mandatory| Description|
| Type| Description| | -------- | -------- | -------- | -------- |
| -------- | -------- | | pipe | [USBDevicePipe](#usbdevicepipe) | Yes| Device pipe, which is used to determine the bus number and device address.|
| number | Returns **0** if the USB interface is successfully set; returns an error code otherwise.| | iface | [USBInterface](#usbinterface) | Yes| USB interface to set.|
- Example **Return value**
```
let ret = usb.setInterface(devicepipe, interfaces); | Type| Description|
console.log(`setInterface = ${ret}`); | -------- | -------- |
``` | number | Returns **0** if the USB interface is successfully set; returns an error code otherwise.|
**Example**
```
let ret = usb.setInterface(devicepipe, interfaces);
console.log(`setInterface = ${ret}`);
```
## usb.getRawDescriptor ## usb.getRawDescriptor
...@@ -282,20 +306,23 @@ Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB devi ...@@ -282,20 +306,23 @@ 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|
| -------- | -------- | -------- | -------- |
| pipe | [USBDevicePipe](#usbdevicepipe) | Yes| Device pipe, which is used to determine the bus number and device address.|
- Return value | Name| Type| Mandatory| Description|
| Type| Description| | -------- | -------- | -------- | -------- |
| -------- | -------- | | pipe | [USBDevicePipe](#usbdevicepipe) | Yes| Device pipe, which is used to determine the bus number and device address.|
| Uint8Array | Raw descriptor data.|
- Example **Return value**
```
let ret = usb.getRawDescriptor(devicepipe); | Type| Description|
``` | -------- | -------- |
| Uint8Array | Raw descriptor data.|
**Example**
```
let ret = usb.getRawDescriptor(devicepipe);
```
## usb.getFileDescriptor ## usb.getFileDescriptor
...@@ -308,20 +335,23 @@ Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB devi ...@@ -308,20 +335,23 @@ 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**
| Type| Description|
| -------- | -------- |
| number | File descriptor of the USB device.|
- Return value **Example**
| Type| Description|
| -------- | -------- |
| number | File descriptor of the USB device.|
- Example ```
``` let ret = usb.getFileDescriptor(devicepipe);
let ret = usb.getFileDescriptor(devicepipe); ```
```
## usb.controlTransfer ## usb.controlTransfer
...@@ -334,24 +364,27 @@ Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB devi ...@@ -334,24 +364,27 @@ 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.| | -------- | -------- | -------- | -------- |
| contrlparam | [USBControlParams](#usbcontrolparams) | Yes| Control transfer parameters.| | pipe | [USBDevicePipe](#usbdevicepipe) | Yes| USB device pipe, which is used to determine the USB device.|
| timeout | number | No| Timeout duration. The default value is **0**, indicating no timeout.| | 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|
| 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**
```
usb.controlTransfer(devicepipe, USBControlParams).then((ret) => { ```
console.log(`controlTransfer = ${JSON.stringify(ret)}`); usb.controlTransfer(devicepipe, USBControlParams).then((ret) => {
}) console.log(`controlTransfer = ${JSON.stringify(ret)}`);
``` })
```
## usb.bulkTransfer ## usb.bulkTransfer
...@@ -364,28 +397,31 @@ Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB devi ...@@ -364,28 +397,31 @@ 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.| | -------- | -------- | -------- | -------- |
| endpoint | [USBEndpoint](#usbendpoint) | Yes| USB endpoint, which is used to determine the USB port for data transfer.| | pipe | [USBDevicePipe](#usbdevicepipe) | Yes| USB device pipe, which is used to determine the USB device.|
| buffer | Uint8Array | Yes| Buffer for writing or reading data.| | endpoint | [USBEndpoint](#usbendpoint) | Yes| USB endpoint, which is used to determine the USB port for data transfer.|
| timeout | number | No| Timeout duration. The default value is **0**, indicating no timeout.| | buffer | Uint8Array | Yes| Buffer for writing or reading data.|
| timeout | number | No| Timeout duration. The default value is **0**, indicating no timeout.|
- Return value
| Type| Description| **Return value**
| -------- | -------- |
| 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.| | Type| Description|
| -------- | -------- |
- Example | 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.|
```
// Call usb.getDevices to obtain a data set. Then, obtain a USB device and its access permission. **Example**
// 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. ```
usb.bulkTransfer(devicepipe, endpoint, buffer).then((ret) => { // Call usb.getDevices to obtain a data set. Then, obtain a USB device and its access permission.
console.log(`bulkTransfer = ${JSON.stringify(ret)}`); // 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.
``` usb.bulkTransfer(devicepipe, endpoint, buffer).then((ret) => {
console.log(`bulkTransfer = ${JSON.stringify(ret)}`);
});
```
## usb.closePipe ## usb.closePipe
...@@ -398,21 +434,24 @@ Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB devi ...@@ -398,21 +434,24 @@ 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
| Type| Description| **Return value**
| -------- | -------- |
| number | Returns **0** if the USB device pipe is closed successfully; returns an error code otherwise.| | Type| Description|
| -------- | -------- |
- Example | number | Returns **0** if the USB device pipe is closed successfully; returns an error code otherwise.|
```
let ret = usb.closePipe(devicepipe); **Example**
console.log(`closePipe = ${ret}`);
``` ```
let ret = usb.closePipe(devicepipe);
console.log(`closePipe = ${ret}`);
```
## USBEndpoint ## USBEndpoint
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册