> 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.
| type | string | Yes| Listening type. The available values are as follows:<br>- **add**: listening for whether a display is added<br>- **remove**: listening for whether a display is removed<br>- **change**: listening for whether a display is changed|
| type | string | Yes| Listening type. The available values are as follows:<br>- **add**: listening for whether a display is added<br>- **remove**: listening for whether a display is removed<br>- **change**: listening for whether a display is changed|
| callback | Callback<number> | Yes| Callback used to return the ID of the display.|
| callback | Callback<number> | Yes| Callback used to return the ID of the display.|
| type | string | Yes| Listening type. The available values are as follows:<br>- **add**: listening for whether a display is added<br>- **remove**: listening for whether a display is removed<br>- **change**: listening for whether a display is changed|
| type | string | Yes| Listening type. The available values are as follows:<br>- **add**: listening for whether a display is added<br>- **remove**: listening for whether a display is removed<br>- **change**: listening for whether a display is changed|
| callback | Callback<number> | No| Callback used to return the ID of the display.|
| callback | Callback<number> | No| Callback used to return the ID of the display.|
> 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.
| 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<image.PixelMap> | Yes | Callback used to return a **PixelMap** object. |
| callback | AsyncCallback<image.PixelMap> | Yes | Callback used to return a **PixelMap** object. |
- Example
**Example**
```js
```js
varScreenshotOptions={
varScreenshotOptions={
"screenRect":{
"screenRect":{
"left":200,
"left":200,
"top":100,
"top":100,
...
@@ -78,15 +79,15 @@ Takes a screenshot and saves it as a **PixelMap** object. This method uses a cal
...
@@ -78,15 +79,15 @@ Takes a screenshot and saves it as a **PixelMap** object. This method uses a cal
"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));
| 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.|
> 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.
| 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
| 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
| Type| Description|
**Return value**
| -------- | -------- |
| Promise<number> | 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<number> | Returns the size of the transmitted or received data block if the control transfer is successful; returns **-1** if an exception occurs.|
| 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<number> | 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<number> | 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.
> 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.
...
@@ -22,7 +23,7 @@ Create a **<canvas\>** component in the HML file. The following is an example:
...
@@ -22,7 +23,7 @@ Create a **<canvas\>** component in the HML file. The following is an example:
Obtain the **<canvas\>** component instance in the JS file. The following is an example:
Obtain the **<canvas\>** component instance in the JS file. The following is an example:
```
```js
// Obtain the <canvas> component instance.
// Obtain the <canvas> component instance.
constel=this.$refs.canvas1;
constel=this.$refs.canvas1;
// Obtain the WebGL context from the <canvas> component instance.
// Obtain the WebGL context from the <canvas> component instance.
> 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.
...
@@ -22,7 +23,7 @@ Create a **<canvas\>** component in the HML file. The following is an example:
...
@@ -22,7 +23,7 @@ Create a **<canvas\>** component in the HML file. The following is an example:
Obtain the **<canvas\>** component instance in the JS file. The following is an example:
Obtain the **<canvas\>** component instance in the JS file. The following is an example:
```
```js
// Obtain the <canvas> component instance.
// Obtain the <canvas> component instance.
constel=this.$refs.canvas1;
constel=this.$refs.canvas1;
// Obtain the WebGL context from the <canvas> component instance.
// Obtain the WebGL context from the <canvas> component instance.