From a0f21987f48b63f3d2b01ecff2e5756cf34334bc Mon Sep 17 00:00:00 2001 From: shawn_he Date: Fri, 25 Aug 2023 16:57:28 +0800 Subject: [PATCH] update doc Signed-off-by: shawn_he --- en/application-dev/connectivity/net-mdns.md | 19 +++ .../napi/neural-network-runtime-guidelines.md | 9 +- .../js-apis-devicestatus-draginteraction.md | 6 +- .../reference/apis/js-apis-mindSporeLite.md | 110 +++++++------- .../reference/apis/js-apis-net-mdns.md | 140 ++++++++++++++++++ .../reference/apis/js-apis-socket.md | 10 +- .../reference/apis/js-apis-usb-deprecated.md | 29 ++-- .../reference/apis/js-apis-usbManager.md | 6 +- 8 files changed, 252 insertions(+), 77 deletions(-) diff --git a/en/application-dev/connectivity/net-mdns.md b/en/application-dev/connectivity/net-mdns.md index de7982a5c0..965a228de4 100644 --- a/en/application-dev/connectivity/net-mdns.md +++ b/en/application-dev/connectivity/net-mdns.md @@ -28,9 +28,13 @@ For the complete list of APIs and example code, see [mDNS Management](../referen | ohos.net.mdns.DiscoveryService | startSearchingMDNS(): void | Searches for mDNS services on the LAN.| | ohos.net.mdns.DiscoveryService | stopSearchingMDNS(): void | Stops searching for mDNS services on the LAN.| | ohos.net.mdns.DiscoveryService | on(type: 'discoveryStart', callback: Callback<{serviceInfo: LocalServiceInfo, errorCode?: MdnsError}>): void | Enables listening for **discoveryStart** events.| +| ohos.net.mdns.DiscoveryService | off(type: 'discoveryStart', callback: Callback<{serviceInfo: LocalServiceInfo, errorCode?: MdnsError}>): void | Disables listening for **discoveryStart** events.| | ohos.net.mdns.DiscoveryService | on(type: 'discoveryStop', callback: Callback<{serviceInfo: LocalServiceInfo, errorCode?: MdnsError}>): void | Enables listening for **discoveryStop** events.| +| ohos.net.mdns.DiscoveryService | off(type: 'discoveryStop', callback: Callback<{serviceInfo: LocalServiceInfo, errorCode?: MdnsError}>): void | Disables listening for **discoveryStop** events.| | ohos.net.mdns.DiscoveryService | on(type: 'serviceFound', callback: Callback\): void | Enables listening for **serviceFound** events.| +| ohos.net.mdns.DiscoveryService | off(type: 'serviceFound', callback: Callback\): void | Disables listening for **serviceFound** events.| | ohos.net.mdns.DiscoveryService | on(type: 'serviceLost', callback: Callback\): void | Enables listening for **serviceLost** events.| +| ohos.net.mdns.DiscoveryService | off(type: 'serviceLost', callback: Callback\): void | Disables listening for **serviceLost** events.| ## Managing Local Services @@ -98,6 +102,7 @@ mdns.removeLocalService(context, localServiceInfo, function (error, data) { 4. Subscribe to mDNS service discovery status changes. 5. Enable discovery of mDNS services on the LAN. 6. Stop searching for mDNS services on the LAN. +7. Unsubscribe from mDNS service discovery status changes. ```js // Import the mdns namespace from @ohos.net.mdns. @@ -139,4 +144,18 @@ discoveryService.startSearchingMDNS(); // Stop searching for mDNS services on the LAN. discoveryService.stopSearchingMDNS(); + +// Unsubscribe from mDNS service discovery status changes. +discoveryService.off('discoveryStart', (data) => { + console.log(JSON.stringify(data)); +}); +discoveryService.off('discoveryStop', (data) => { + console.log(JSON.stringify(data)); +}); +discoveryService.off('serviceFound', (data) => { + console.log(JSON.stringify(data)); +}); +discoveryService.off('serviceLost', (data) => { + console.log(JSON.stringify(data)); +}); ``` diff --git a/en/application-dev/napi/neural-network-runtime-guidelines.md b/en/application-dev/napi/neural-network-runtime-guidelines.md index cfb50fdc08..86a40dd1ad 100644 --- a/en/application-dev/napi/neural-network-runtime-guidelines.md +++ b/en/application-dev/napi/neural-network-runtime-guidelines.md @@ -1,4 +1,4 @@ -# Connecting the Neural Network Runtime to an AI Inference Framework +# Development Guide for Connecting the Neural Network Runtime to an AI Inference Framework ## When to Use @@ -19,7 +19,7 @@ The environment requirements for the Neural Network Runtime are as follows: - Development environment: Ubuntu 18.04 or later. - Access device: a standard device running OpenHarmony. The built-in hardware accelerator driver has been connected to the Neural Network Runtime through an HDI API. -The Neural Network Runtime is opened to external systems through OpenHarmony Native APIs. Therefore, you need to use the Native development suite of the OpenHarmony to compile Neural Network Runtime applications. +The Neural Network Runtime is opened to external systems through OpenHarmony Native APIs. Therefore, you need to use the Native development suite of the OpenHarmony to compile Neural Network Runtime applications. ### Environment Setup @@ -484,3 +484,8 @@ The development process of the Neural Network Runtime consists of three phases: rm /data/local/tmp/*nncache ``` +## Samples + +The following sample is provided to help you understand how to connect a third-party AI inference framework to the Neural Network Runtime: + +- [Development Guide for Connecting TensorFlow Lite to NNRt Delegate](https://gitee.com/openharmony/ai_neural_network_runtime/tree/master/example/deep_learning_framework) diff --git a/en/application-dev/reference/apis/js-apis-devicestatus-draginteraction.md b/en/application-dev/reference/apis/js-apis-devicestatus-draginteraction.md index 01b50c8fc5..8eba8e2a29 100644 --- a/en/application-dev/reference/apis/js-apis-devicestatus-draginteraction.md +++ b/en/application-dev/reference/apis/js-apis-devicestatus-draginteraction.md @@ -1,4 +1,4 @@ -# @ohos. deviceStatus.dragInteraction (Drag) +# @ohos.deviceStatus.dragInteraction (Drag) The **dragInteraction** module provides the APIs to enable and disable listening for dragging status changes. @@ -14,7 +14,7 @@ import dragInteraction from '@ohos.deviceStatus.dragInteraction' ``` -## dragInteraction.on +## dragInteraction.on('drag') on(type: 'drag', callback: Callback<DragState>): void; @@ -41,7 +41,7 @@ try { } ``` -## dragInteraction.off +## dragInteraction.off('drag') off(type: 'drag', callback?: Callback<DragState>): void; diff --git a/en/application-dev/reference/apis/js-apis-mindSporeLite.md b/en/application-dev/reference/apis/js-apis-mindSporeLite.md index 6a80afa397..499ce6a24d 100644 --- a/en/application-dev/reference/apis/js-apis-mindSporeLite.md +++ b/en/application-dev/reference/apis/js-apis-mindSporeLite.md @@ -1,7 +1,7 @@ # @ohos.ai.mindSporeLite (Inference) MindSpore Lite is an AI engine that implements AI model inference for different hardware devices. It has been used in a wide range of fields, such as image classification, target recognition, facial recognition, and character recognition. -The **mindSporeLite** module provides APIs for the MindSpore Lite inference engine to implment model inference. +The **mindSporeLite** module provides APIs for the MindSpore Lite inference engine to implement model inference. > **NOTE** > @@ -48,7 +48,7 @@ Defines the CPU backend device option. | threadNum | number | Yes | Yes | Number of runtime threads. The default value is **2**. | | threadAffinityMode | [ThreadAffinityMode](#threadaffinitymode) | Yes | Yes | Affinity mode for binding runtime threads to CPU cores. The default value is **mindSporeLite.ThreadAffinityMode.NO_AFFINITIES**.| | threadAffinityCoreList | number[] | Yes | Yes | List of CPU cores bound to runtime threads. Set this parameter only when **threadAffinityMode** is set. If **threadAffinityMode** is set to **mindSporeLite.ThreadAffinityMode.NO_AFFINITIES**, this parameter is empty. The number in the list indicates the SN of the CPU core. The default value is **[]**.| -| precisionMode | string | Yes | Yes | Whether to enable the Float16 inference mode. The value **preferred_fp16** means to enable half-precision inference and the default value **force_fp32** means to disable half-precision inference. Other settings are not supported.| +| precisionMode | string | Yes | Yes | Whether to enable the Float16 inference mode. The value **preferred_fp16** means to enable half-precision inference and the default value **enforce_fp32** means to disable half-precision inference. Other settings are not supported.| **Float16 inference mode**: a mode that uses half-precision inference. Float16 uses 16 bits to represent a number and therefore it is also called half-precision. @@ -125,7 +125,7 @@ Loads the input model from the full path for model inference. This API uses an a ```js let context: mindSporeLite.Context = {}; -let context = {'target': ['cpu']}; +context = {'target': ['cpu']}; let model_file = '/path/to/xxx.ms'; mindSporeLite.loadModelFromFile(model_file, context, (result) => { const modelInputs = result.getInputs(); @@ -181,17 +181,17 @@ Loads the input model from the memory for inference. This API uses an asynchrono ```js import resourceManager from '@ohos.resourceManager' -@State modelName: string = 'xxx.ms'; +let modelName = '/path/to/xxx.ms'; let syscontext = globalThis.context; -syscontext.resourceManager.getRawFileContent(this.modelName).then((buffer) => { - this.modelBuffer = buffer; +syscontext.resourceManager.getRawFileContent(modelName).then((buffer) => { + let modelBuffer = buffer; + mindSporeLite.loadModelFromBuffer(modelBuffer.buffer, (result) => { + const modelInputs = result.getInputs(); + console.log(modelInputs[0].name); + }) }).catch(error => { console.error('Failed to get buffer, error code: ${error.code},message:${error.message}.'); }) -mindSporeLite.loadModelFromBuffer(this.modelBuffer.buffer, (result) => { - const modelInputs = result.getInputs(); - console.log(modelInputs[0].name); -}) ``` ## mindSporeLite.loadModelFromBuffer @@ -213,19 +213,19 @@ Loads the input model from the memory for inference. This API uses an asynchrono ```js import resourceManager from '@ohos.resourceManager' -@State modelName: string = 'xxx.ms'; +let modelName = '/path/to/xxx.ms'; let syscontext = globalThis.context; -syscontext.resourceManager.getRawFileContent(this.modelName).then((error,buffer) => { - this.modelBuffer = buffer; +syscontext.resourceManager.getRawFileContent(modelName).then((error,buffer) => { + let modelBuffer = buffer; + let context: mindSporeLite.Context = {}; + context = {'target': ['cpu']}; + mindSporeLite.loadModelFromBuffer(modelBuffer.buffer, context, (result) => { + const modelInputs = result.getInputs(); + console.log(modelInputs[0].name); + }) }).catch(error => { console.error('Failed to get buffer, error code: ${error.code},message:${error.message}.'); }) -let context: mindSporeLite.Context = {}; -context = {'target': ['cpu']}; -mindSporeLite.loadModelFromBuffer(this.modelBuffer.buffer, context, (result) => { - const modelInputs = result.getInputs(); - console.log(modelInputs[0].name); -}) ``` ## mindSporeLite.loadModelFromBuffer @@ -252,17 +252,17 @@ Loads the input model from the memory for inference. This API uses a promise to ```js import resourceManager from '@ohos.resourceManager' -@State modelName: string = 'xxx.ms'; +let modelName = '/path/to/xxx.ms'; let syscontext = globalThis.context; -syscontext.resourceManager.getRawFileContent(this.modelName).then((buffer) => { - this.modelBuffer = buffer; +syscontext.resourceManager.getRawFileContent(modelName).then((buffer) => { + let modelBuffer = buffer; + mindSporeLite.loadModelFromBuffer(modelBuffer.buffer).then((result) => { + const modelInputs = result.getInputs(); + console.log(modelInputs[0].name); + }) }).catch(error => { console.error('Failed to get buffer, error code: ${error.code},message:${error.message}.'); }) -mindSporeLite.loadModelFromBuffer(model_file).then((result) => { - const modelInputs = result.getInputs(); - console.log(modelInputs[0].name); -}) ``` ## mindSporeLite.loadModelFromFd @@ -284,7 +284,7 @@ Loads the input model based on the specified file descriptor for inference. This ```js import fs from '@ohos.file.fs'; let model_file = '/path/to/xxx.ms'; -let file = await fs.open(model_file, 0); +let file = fs.openSync(model_file, fs.OpenMode.READ_ONLY); mindSporeLite.loadModelFromFd(file.fd, (result) => { const modelInputs = result.getInputs(); console.log(modelInputs[0].name); @@ -313,7 +313,7 @@ import fs from '@ohos.file.fs'; let model_file = '/path/to/xxx.ms'; let context : mindSporeLite.Context = {}; context = {'target': ['cpu']}; -let file = await fs.open(model_file, 0); +let file = fs.openSync(model_file, fs.OpenMode.READ_ONLY); mindSporeLite.loadModelFromFd(file.fd, context, (result) => { const modelInputs = result.getInputs(); console.log(modelInputs[0].name); @@ -345,7 +345,7 @@ Loads the input model based on the specified file descriptor for inference. This ```js import fs from '@ohos.file.fs'; let model_file = '/path/to/xxx.ms'; -let file = await fs.open(model_file, 0); +let file = fs.openSync(model_file, fs.OpenMode.READ_ONLY); let mindSporeLiteModel = await mindSporeLite.loadModelFromFd(file.fd); mindSporeLite.loadModelFromFd(file.fd).then((result) => { const modelInputs = result.getInputs(); @@ -383,9 +383,9 @@ mindSporeLite.loadModelFromFile(model_file).then((result) => { ``` ### predict -predict(inputs: MSTensor[], callback: Callback<Model>): void +predict(inputs: MSTensor[], callback: Callback<MSTensor[]>): void -Executes the inference model. This API uses an asynchronous callback to return the result. +Executes the inference model. This API uses an asynchronous callback to return the result. Ensure that the model object is not reclaimed when being invoked. **System capability**: SystemCapability.AI.MindSporeLite @@ -394,21 +394,21 @@ Executes the inference model. This API uses an asynchronous callback to return t | Name| Type | Mandatory| Description | | ------ | ----------------------- | ---- | -------------------------- | | inputs | [MSTensor](#mstensor)[] | Yes | Model input, which is an **MSTensor** object.| -| callback | Callback<[Model](#model)> | Yes | Callback used to return the result, which is a **Model** object.| +| callback | Callback<[MSTensor](#mstensor)[]> | Yes | Callback used to return the result, **MSTensor** object.| **Example** ```js import resourceManager from '@ohos.resourceManager' -@State inputName: string = 'input_data.bin'; +let inputName = 'input_data.bin'; let syscontext = globalThis.context; -syscontext.resourceManager.getRawFileContent(this.inputName).then((buffer) => { - this.inputBuffer = buffer; +syscontext.resourceManager.getRawFileContent(inputName).then(async (buffer) => { + let inputBuffer = buffer; let model_file = '/path/to/xxx.ms'; let mindSporeLiteModel = await mindSporeLite.loadModelFromFile(model_file); const modelInputs = mindSporeLiteModel.getInputs(); - modelInputs[0].setData(this.inputBuffer.buffer); - result.predict(modelInputs, (result) => { + modelInputs[0].setData(inputBuffer.buffer); + mindSporeLiteModel.predict(modelInputs, (result) => { let output = new Float32Array(result[0].getData()); for (let i = 0; i < output.length; i++) { console.log(output[i].toString()); @@ -420,7 +420,7 @@ syscontext.resourceManager.getRawFileContent(this.inputName).then((buffer) => { predict(inputs: MSTensor[]): Promise<MSTensor[]> -Executes the inference model. This API uses a promise to return the result. +Executes the inference model. This API uses a promise to return the result. Ensure that the model object is not reclaimed when being invoked. **System capability**: SystemCapability.AI.MindSporeLite @@ -440,15 +440,15 @@ Executes the inference model. This API uses a promise to return the result. ```js import resourceManager from '@ohos.resourceManager' -@State inputName: string = 'input_data.bin'; +let inputName = 'input_data.bin'; let syscontext = globalThis.context; -syscontext.resourceManager.getRawFileContent(this.inputName).then((buffer) => { - this.inputBuffer = buffer; +syscontext.resourceManager.getRawFileContent(inputName).then(async (buffer) => { + let inputBuffer = buffer; let model_file = '/path/to/xxx.ms'; let mindSporeLiteModel = await mindSporeLite.loadModelFromFile(model_file); const modelInputs = mindSporeLiteModel.getInputs(); - modelInputs[0].setData(this.inputBuffer.buffer); - result.predict(modelInputs).then((result) => { + modelInputs[0].setData(inputBuffer.buffer); + mindSporeLiteModel.predict(modelInputs).then((result) => { let output = new Float32Array(result[0].getData()); for (let i = 0; i < output.length; i++) { console.log(output[i].toString()); @@ -541,15 +541,15 @@ Obtains tensor data. ```js import resourceManager from '@ohos.resourceManager' -@State inputName: string = 'input_data.bin'; +let inputName = 'input_data.bin'; let syscontext = globalThis.context; -syscontext.resourceManager.getRawFileContent(this.inputName).then((buffer) => { - this.inputBuffer = buffer; +syscontext.resourceManager.getRawFileContent(inputName).then(async (buffer) => { + let inputBuffer = buffer; let model_file = '/path/to/xxx.ms'; let mindSporeLiteModel = await mindSporeLite.loadModelFromFile(model_file); const modelInputs = mindSporeLiteModel.getInputs(); - modelInputs[0].setData(this.inputBuffer.buffer); - result.predict(modelInputs).then((result) => { + modelInputs[0].setData(inputBuffer.buffer); + mindSporeLiteModel.predict(modelInputs).then((result) => { let output = new Float32Array(result[0].getData()); for (let i = 0; i < output.length; i++) { console.log(output[i].toString()); @@ -576,15 +576,15 @@ Sets the tensor data. ```js import resourceManager from '@ohos.resourceManager' -@State inputName: string = 'input_data.bin'; +let inputName = 'input_data.bin'; let syscontext = globalThis.context; -syscontext.resourceManager.getRawFileContent(this.inputName).then((buffer) => { - this.inputBuffer = buffer; +syscontext.resourceManager.getRawFileContent(inputName).then(async (buffer) => { + let inputBuffer = buffer; + let model_file = '/path/to/xxx.ms'; + let mindSporeLiteModel = await mindSporeLite.loadModelFromFile(model_file); + const modelInputs = mindSporeLiteModel.getInputs(); + modelInputs[0].setData(inputBuffer.buffer); }) -let model_file = '/path/to/xxx.ms'; -let mindSporeLiteModel = await mindSporeLite.loadModelFromFile(model_file); -const modelInputs = mindSporeLiteModel.getInputs(); -modelInputs[0].setData(this.inputBuffer.buffer); ``` ## DataType diff --git a/en/application-dev/reference/apis/js-apis-net-mdns.md b/en/application-dev/reference/apis/js-apis-net-mdns.md index de9ee7cf50..3d05860d53 100644 --- a/en/application-dev/reference/apis/js-apis-net-mdns.md +++ b/en/application-dev/reference/apis/js-apis-net-mdns.md @@ -718,6 +718,41 @@ discoveryService.on('discoveryStart', (data) => { discoveryService.stopSearchingMDNS(); ``` +### off('discoveryStart')10+ + +off(type: 'discoveryStart', callback?: Callback<{ serviceInfo: LocalServiceInfo, errorCode?: MdnsError }>): void; + +Disables listening for **discoveryStart** events. + +**System capability**: SystemCapability.Communication.NetManager.MDNS + +**Parameters** + +| Name | Type | Mandatory| Description | +|-------------|--------------|-----------|-----------------------------------------------------| +| type | string | Yes |Event type. This field has a fixed value of **discoveryStart**.
**discoveryStart**: event of starting discovery of mDNS services on the LAN.| +| callback | Callback<{serviceInfo: [LocalServiceInfo](#localserviceinfo), errorCode?: [MdnsError](#mdnserror)}> | Yes | Callback used to return the mDNS service and error information. | + +**Example** + +```js +// See mdns.createDiscoveryService. +let context = globalThis.context; +let serviceType = "_print._tcp"; +let discoveryService = mdns.createDiscoveryService(context, serviceType); +discoveryService.startSearchingMDNS(); + +discoveryService.on('discoveryStart', (data) => { + console.log(JSON.stringify(data)); +}); + +discoveryService.stopSearchingMDNS(); + +discoveryService.off('discoveryStart', (data) => { + console.log(JSON.stringify(data)); +}); +``` + ### on('discoveryStop')10+ on(type: 'discoveryStop', callback: Callback<{serviceInfo: LocalServiceInfo, errorCode?: MdnsError}>): void @@ -749,6 +784,41 @@ discoveryService.on('discoveryStop', (data) => { discoveryService.stopSearchingMDNS(); ``` +### off('discoveryStop')10+ + +off(type: 'discoveryStop', callback: Callback<{serviceInfo: LocalServiceInfo, errorCode?: MdnsError}>): void + +Disables listening for **discoveryStop** events. + +**System capability**: SystemCapability.Communication.NetManager.MDNS + +**Parameters** + +| Name | Type | Mandatory| Description | +|-------------|--------------|-----------|-----------------------------------------------------| +| type | string | Yes |Event type. This field has a fixed value of **discoveryStop**.
**discoveryStop**: event of stopping discovery of mDNS services on the LAN.| +| callback | Callback<{serviceInfo: [LocalServiceInfo](#localserviceinfo), errorCode?: [MdnsError](#mdnserror)}> | Yes | Callback used to return the mDNS service and error information. | + +**Example** + +```js +// See mdns.createDiscoveryService. +let context = globalThis.context; +let serviceType = "_print._tcp"; +let discoveryService = mdns.createDiscoveryService(context, serviceType); +discoveryService.startSearchingMDNS(); + +discoveryService.on('discoveryStop', (data) => { + console.log(JSON.stringify(data)); +}); + +discoveryService.stopSearchingMDNS(); + +discoveryService.off('discoveryStop', (data) => { + console.log(JSON.stringify(data)); +}); +``` + ### on('serviceFound')10+ on(type: 'serviceFound', callback: Callback\): void @@ -780,6 +850,41 @@ discoveryService.on('serviceFound', (data) => { discoveryService.stopSearchingMDNS(); ``` +### off('serviceFound')10+ + +off(type: 'serviceFound', callback: Callback\): void + +Disables listening for **serviceFound** events. + +**System capability**: SystemCapability.Communication.NetManager.MDNS + +**Parameters** + +| Name | Type | Mandatory| Description | +|-------------|--------------|-----------|-----------------------------------------------------| +| type | string | Yes |Event type. This field has a fixed value of **serviceFound**.
**serviceFound**: event indicating an mDNS service is found.| +| callback | Callback<[LocalServiceInfo](#localserviceinfo)> | Yes | mDNS service information. | + +**Example** + +```js +// See mdns.createDiscoveryService. +let context = globalThis.context; +let serviceType = "_print._tcp"; +let discoveryService = mdns.createDiscoveryService(context, serviceType); +discoveryService.startSearchingMDNS(); + +discoveryService.on('serviceFound', (data) => { + console.log(JSON.stringify(data)); +}); + +discoveryService.stopSearchingMDNS(); + +discoveryService.off('serviceFound', (data) => { + console.log(JSON.stringify(data)); +}); +``` + ### on('serviceLost')10+ on(type: 'serviceLost', callback: Callback\): void @@ -811,6 +916,41 @@ discoveryService.on('serviceLost', (data) => { discoveryService.stopSearchingMDNS(); ``` +### off('serviceLost')10+ + +off(type: 'serviceLost', callback: Callback\): void + +Disables listening for **serviceLost** events. + +**System capability**: SystemCapability.Communication.NetManager.MDNS + +**Parameters** + +| Name | Type | Mandatory| Description | +|-------------|--------------|-----------|-----------------------------------------------------| +| type | string | Yes |Event type. This field has a fixed value of **serviceLost**.
serviceLost: event indicating that an mDNS service is removed.| +| callback | Callback<[LocalServiceInfo](#localserviceinfo)> | Yes | mDNS service information. | + +**Example** + +```js +// See mdns.createDiscoveryService. +let context = globalThis.context; +let serviceType = "_print._tcp"; +let discoveryService = mdns.createDiscoveryService(context, serviceType); +discoveryService.startSearchingMDNS(); + +discoveryService.on('serviceLost', (data) => { + console.log(JSON.stringify(data)); +}); + +discoveryService.stopSearchingMDNS(); + +discoveryService.off('serviceLost', (data) => { + console.log(JSON.stringify(data)); +}); +``` + ## LocalServiceInfo10+ Defines the mDNS service information. diff --git a/en/application-dev/reference/apis/js-apis-socket.md b/en/application-dev/reference/apis/js-apis-socket.md index 27403a6776..6780a6483b 100644 --- a/en/application-dev/reference/apis/js-apis-socket.md +++ b/en/application-dev/reference/apis/js-apis-socket.md @@ -1,4 +1,4 @@ -# # @ohos.net.socket (Socket Connection) +# @ohos.net.socket (Socket Connection) The **socket** module implements data transfer over TCP, UDP, Web, and TLS socket connections. @@ -1691,7 +1691,7 @@ listen(address: NetAddress, callback: AsyncCallback\): void Binds the IP address and port number. The port number can be specified or randomly allocated by the system. The server listens to and accepts TCP socket connections established over the socket. Multiple threads are used to process client data concurrently. This API uses an asynchronous callback to return the result. -> **NOTE** +> **NOTE**
> The server uses this API to perform the **bind**, **listen**, and **accept** operations. If the **bind** operation fails, the system randomly allocates a port number. **Required permissions**: ohos.permission.INTERNET @@ -1736,7 +1736,7 @@ listen(address: NetAddress): Promise\ Binds the IP address and port number. The port number can be specified or randomly allocated by the system. The server listens to and accepts TCP socket connections established over the socket. Multiple threads are used to process client data concurrently. This API uses a promise to return the result. -> **NOTE** +> **NOTE**
> The server uses this API to perform the **bind**, **listen**, and **accept** operations. If the **bind** operation fails, the system randomly allocates a port number. **Required permissions**: ohos.permission.INTERNET @@ -2515,7 +2515,7 @@ tcpServer.on('connect', function(client) { ### off('close')10+ -on(type: 'close', callback: Callback\): void +off(type: 'close', callback?: Callback): void Unsubscribes from **close** events of a **TCPSocketConnection** object. This API uses an asynchronous callback to return the result. @@ -5706,7 +5706,7 @@ tlsServer.on('connect', function(client) { ### off('close')10+ -on(type: 'close', callback: Callback\): void +off(type: 'close', callback?: Callback): void Unsubscribes from **close** events of a **TLSSocketConnection** object. This API uses an asynchronous callback to return the result. diff --git a/en/application-dev/reference/apis/js-apis-usb-deprecated.md b/en/application-dev/reference/apis/js-apis-usb-deprecated.md index f5c4bc2d05..6a772fd6b9 100644 --- a/en/application-dev/reference/apis/js-apis-usb-deprecated.md +++ b/en/application-dev/reference/apis/js-apis-usb-deprecated.md @@ -137,7 +137,7 @@ Checks whether the application has the permission to access the device. **Example** ```js -let devicesName="1-1"; +let devicesName= "1-1"; let bool = usb.hasRight(devicesName); console.log(bool); ``` @@ -146,7 +146,7 @@ console.log(bool); requestRight(deviceName: string): Promise<boolean> -Requests the temporary permission for the application to access a USB device. This API uses a promise to return the result. +Requests the temporary permission for the application to access a USB device. This API uses a promise to return the result. By default, system applications are granted the device access permission. **System capability**: SystemCapability.USB.USBManager @@ -165,7 +165,7 @@ Requests the temporary permission for the application to access a USB device. Th **Example** ```js -let devicesName="1-1"; +let devicesName= "1-1"; usb.requestRight(devicesName).then((ret) => { console.log(`requestRight = ${ret}`); }); @@ -375,7 +375,14 @@ Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB devi **Example** ```js -let param = new usb.USBControlParams(); +let param = { + request: 0, + reqType: 0, + target:0, + value: 0, + index: 0, + data: null +}; usb.controlTransfer(devicepipe, param).then((ret) => { console.log(`controlTransfer = ${ret}`); }) @@ -500,7 +507,7 @@ Converts the USB function list in the numeric mask format to a string in Device **Example** ```js -let funcs = usb.ACM | usb.ECM; +let funcs = usb.FunctionType.ACM | usb.FunctionType.ECM; let ret = usb.usbFunctionsToString(funcs); ``` @@ -529,8 +536,12 @@ Sets the current USB function list in Device mode. **Example** ```js -let funcs = usb.HDC; -let ret = usb.setCurrentFunctions(funcs); +let funcs = usb.FunctionType.HDC; +usb.setCurrentFunctions(funcs).then(() => { + console.info('usb setCurrentFunctions successfully.'); +}).catch(err => { + console.error('usb setCurrentFunctions failed: ' + err.code + ' message: ' + err.message); +}); ``` ## usb.getCurrentFunctions9+ @@ -848,7 +859,7 @@ Enumerates power role types. | Name | Value | Description | | ------ | ---- | ---------- | -| NONE | 0 | None | +| NONE | 0 | None. | | SOURCE | 1 | External power supply.| | SINK | 2 | Internal power supply.| @@ -862,6 +873,6 @@ Enumerates data role types. | Name | Value | Description | | ------ | ---- | ------------ | -| NONE | 0 | None | +| NONE | 0 | None. | | HOST | 1 | USB host.| | DEVICE | 2 | USB device.| diff --git a/en/application-dev/reference/apis/js-apis-usbManager.md b/en/application-dev/reference/apis/js-apis-usbManager.md index 204318356f..e60bcc7ca5 100644 --- a/en/application-dev/reference/apis/js-apis-usbManager.md +++ b/en/application-dev/reference/apis/js-apis-usbManager.md @@ -161,7 +161,7 @@ console.log(`${bool}`); requestRight(deviceName: string): Promise<boolean> -Requests the temporary permission for the application to access a USB device. This API uses a promise to return the result. +Requests the temporary device access permission for the application. This API uses a promise to return the result. System applications are granted the device access permission by default, and you do not need to apply for the permission separately. **System capability**: SystemCapability.USB.USBManager @@ -190,7 +190,7 @@ usb.requestRight(devicesName).then((ret) => { removeRight(deviceName: string): boolean -Removes the permission for the application to access a USB device. +Removes the device access permission for the application. System applications are granted the device access permission by default, and calling this API will not revoke the permission. **System capability**: SystemCapability.USB.USBManager @@ -219,7 +219,7 @@ if (usb.removeRight(devicesName)) { addRight(bundleName: string, deviceName: string): boolean -Adds the permission for the application to access a USB device. +Adds the device access permission for the application. System applications are granted the device access permission by default, and calling this API will not revoke the permission. [requestRight](#usbrequestright) triggers a dialog box to request for user authorization, whereas **addRight** adds the access permission directly without displaying a dialog box. -- GitLab