未验证 提交 3799445a 编写于 作者: O openharmony_ci 提交者: Gitee

!23046 翻译已完成21896+22400+22607+22716+22653+22759

Merge pull request !23046 from shawn_he/22400-d
...@@ -11,6 +11,7 @@ Typical MDNS management scenarios include: ...@@ -11,6 +11,7 @@ Typical MDNS management scenarios include:
- Discovering local services and listening to the status changes of local services of the specified type through the **DiscoveryService** object. - Discovering local services and listening to the status changes of local services of the specified type through the **DiscoveryService** object.
> **NOTE** > **NOTE**
>
> To maximize the application running efficiency, most API calls are called asynchronously in callback or promise mode. The following code examples use the callback mode. For details about the APIs, see [mDNS Management](../reference/apis/js-apis-net-mdns.md). > To maximize the application running efficiency, most API calls are called asynchronously in callback or promise mode. The following code examples use the callback mode. For details about the APIs, see [mDNS Management](../reference/apis/js-apis-net-mdns.md).
The following describes the development procedure specific to each application scenario. The following describes the development procedure specific to each application scenario.
...@@ -28,9 +29,13 @@ For the complete list of APIs and example code, see [mDNS Management](../referen ...@@ -28,9 +29,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 | 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 | 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 | 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 | 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\<LocalServiceInfo>): void | Enables listening for **serviceFound** events.| | ohos.net.mdns.DiscoveryService | on(type: 'serviceFound', callback: Callback\<LocalServiceInfo>): void | Enables listening for **serviceFound** events.|
| ohos.net.mdns.DiscoveryService | off(type: 'serviceFound', callback: Callback\<LocalServiceInfo>): void | Disables listening for **serviceFound** events.|
| ohos.net.mdns.DiscoveryService | on(type: 'serviceLost', callback: Callback\<LocalServiceInfo>): void | Enables listening for **serviceLost** events.| | ohos.net.mdns.DiscoveryService | on(type: 'serviceLost', callback: Callback\<LocalServiceInfo>): void | Enables listening for **serviceLost** events.|
| ohos.net.mdns.DiscoveryService | off(type: 'serviceLost', callback: Callback\<LocalServiceInfo>): void | Disables listening for **serviceLost** events.|
## Managing Local Services ## Managing Local Services
...@@ -94,10 +99,11 @@ mdns.removeLocalService(context, localServiceInfo, function (error, data) { ...@@ -94,10 +99,11 @@ mdns.removeLocalService(context, localServiceInfo, function (error, data) {
1. Connect the device to the Wi-Fi network. 1. Connect the device to the Wi-Fi network.
2. Import the **mdns** namespace from **@ohos.net.mdns**. 2. Import the **mdns** namespace from **@ohos.net.mdns**.
3. Creates a **DiscoveryService** object, which is used to discover mDNS services of the specified type. 3. Create a **DiscoveryService** object, which is used to discover mDNS services of the specified type.
4. Subscribe to mDNS service discovery status changes. 4. Subscribe to mDNS service discovery status changes.
5. Enable discovery of mDNS services on the LAN. 5. Enable discovery of mDNS services on the LAN.
6. Stop searching for mDNS services on the LAN. 6. Stop searching for mDNS services on the LAN.
7. Unsubscribe from mDNS service discovery status changes.
```js ```js
// Import the mdns namespace from @ohos.net.mdns. // Import the mdns namespace from @ohos.net.mdns.
...@@ -139,4 +145,18 @@ discoveryService.startSearchingMDNS(); ...@@ -139,4 +145,18 @@ discoveryService.startSearchingMDNS();
// Stop searching for mDNS services on the LAN. // Stop searching for mDNS services on the LAN.
discoveryService.stopSearchingMDNS(); 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));
});
``` ```
...@@ -484,3 +484,8 @@ The development process of the Neural Network Runtime consists of three phases: ...@@ -484,3 +484,8 @@ The development process of the Neural Network Runtime consists of three phases:
rm /data/local/tmp/*nncache 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)
# @ohos. deviceStatus.dragInteraction (Drag) # @ohos.deviceStatus.dragInteraction (Drag)
The **dragInteraction** module provides the APIs to enable and disable listening for dragging status changes. The **dragInteraction** module provides the APIs to enable and disable listening for dragging status changes.
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
import dragInteraction from '@ohos.deviceStatus.dragInteraction' import dragInteraction from '@ohos.deviceStatus.dragInteraction'
``` ```
## dragInteraction.on ## dragInteraction.on('drag')
on(type: 'drag', callback: Callback&lt;DragState&gt;): void; on(type: 'drag', callback: Callback&lt;DragState&gt;): void;
...@@ -41,7 +41,7 @@ try { ...@@ -41,7 +41,7 @@ try {
} }
``` ```
## dragInteraction.off ## dragInteraction.off('drag')
off(type: 'drag', callback?: Callback&lt;DragState&gt;): void; off(type: 'drag', callback?: Callback&lt;DragState&gt;): void;
......
# @ohos.ai.mindSporeLite (Inference) # @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. 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** > **NOTE**
> >
...@@ -48,7 +48,7 @@ Defines the CPU backend device option. ...@@ -48,7 +48,7 @@ Defines the CPU backend device option.
| threadNum | number | Yes | Yes | Number of runtime threads. The default value is **2**. | | 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**.| | 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 **[]**.| | 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. **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 ...@@ -125,7 +125,7 @@ Loads the input model from the full path for model inference. This API uses an a
```js ```js
let context: mindSporeLite.Context = {}; let context: mindSporeLite.Context = {};
let context = {'target': ['cpu']}; context = {'target': ['cpu']};
let model_file = '/path/to/xxx.ms'; let model_file = '/path/to/xxx.ms';
mindSporeLite.loadModelFromFile(model_file, context, (result) => { mindSporeLite.loadModelFromFile(model_file, context, (result) => {
const modelInputs = result.getInputs(); const modelInputs = result.getInputs();
...@@ -181,16 +181,16 @@ Loads the input model from the memory for inference. This API uses an asynchrono ...@@ -181,16 +181,16 @@ Loads the input model from the memory for inference. This API uses an asynchrono
```js ```js
import resourceManager from '@ohos.resourceManager' import resourceManager from '@ohos.resourceManager'
@State modelName: string = 'xxx.ms'; let modelName = '/path/to/xxx.ms';
let syscontext = globalThis.context; let syscontext = globalThis.context;
syscontext.resourceManager.getRawFileContent(this.modelName).then((buffer) => { syscontext.resourceManager.getRawFileContent(modelName).then((buffer) => {
this.modelBuffer = buffer; let modelBuffer = buffer;
}).catch(error => { mindSporeLite.loadModelFromBuffer(modelBuffer.buffer, (result) => {
console.error('Failed to get buffer, error code: ${error.code},message:${error.message}.');
})
mindSporeLite.loadModelFromBuffer(this.modelBuffer.buffer, (result) => {
const modelInputs = result.getInputs(); const modelInputs = result.getInputs();
console.log(modelInputs[0].name); console.log(modelInputs[0].name);
})
}).catch(error => {
console.error('Failed to get buffer, error code: ${error.code},message:${error.message}.');
}) })
``` ```
## mindSporeLite.loadModelFromBuffer ## mindSporeLite.loadModelFromBuffer
...@@ -213,18 +213,18 @@ Loads the input model from the memory for inference. This API uses an asynchrono ...@@ -213,18 +213,18 @@ Loads the input model from the memory for inference. This API uses an asynchrono
```js ```js
import resourceManager from '@ohos.resourceManager' import resourceManager from '@ohos.resourceManager'
@State modelName: string = 'xxx.ms'; let modelName = '/path/to/xxx.ms';
let syscontext = globalThis.context; let syscontext = globalThis.context;
syscontext.resourceManager.getRawFileContent(this.modelName).then((error,buffer) => { syscontext.resourceManager.getRawFileContent(modelName).then((error,buffer) => {
this.modelBuffer = buffer; let modelBuffer = buffer;
}).catch(error => { let context: mindSporeLite.Context = {};
console.error('Failed to get buffer, error code: ${error.code},message:${error.message}.'); context = {'target': ['cpu']};
}) mindSporeLite.loadModelFromBuffer(modelBuffer.buffer, context, (result) => {
let context: mindSporeLite.Context = {};
context = {'target': ['cpu']};
mindSporeLite.loadModelFromBuffer(this.modelBuffer.buffer, context, (result) => {
const modelInputs = result.getInputs(); const modelInputs = result.getInputs();
console.log(modelInputs[0].name); console.log(modelInputs[0].name);
})
}).catch(error => {
console.error('Failed to get buffer, error code: ${error.code},message:${error.message}.');
}) })
``` ```
## mindSporeLite.loadModelFromBuffer ## mindSporeLite.loadModelFromBuffer
...@@ -252,16 +252,16 @@ Loads the input model from the memory for inference. This API uses a promise to ...@@ -252,16 +252,16 @@ Loads the input model from the memory for inference. This API uses a promise to
```js ```js
import resourceManager from '@ohos.resourceManager' import resourceManager from '@ohos.resourceManager'
@State modelName: string = 'xxx.ms'; let modelName = '/path/to/xxx.ms';
let syscontext = globalThis.context; let syscontext = globalThis.context;
syscontext.resourceManager.getRawFileContent(this.modelName).then((buffer) => { syscontext.resourceManager.getRawFileContent(modelName).then((buffer) => {
this.modelBuffer = buffer; let modelBuffer = buffer;
}).catch(error => { mindSporeLite.loadModelFromBuffer(modelBuffer.buffer).then((result) => {
console.error('Failed to get buffer, error code: ${error.code},message:${error.message}.');
})
mindSporeLite.loadModelFromBuffer(model_file).then((result) => {
const modelInputs = result.getInputs(); const modelInputs = result.getInputs();
console.log(modelInputs[0].name); console.log(modelInputs[0].name);
})
}).catch(error => {
console.error('Failed to get buffer, error code: ${error.code},message:${error.message}.');
}) })
``` ```
## mindSporeLite.loadModelFromFd ## mindSporeLite.loadModelFromFd
...@@ -284,7 +284,7 @@ Loads the input model based on the specified file descriptor for inference. This ...@@ -284,7 +284,7 @@ Loads the input model based on the specified file descriptor for inference. This
```js ```js
import fs from '@ohos.file.fs'; import fs from '@ohos.file.fs';
let model_file = '/path/to/xxx.ms'; 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) => { mindSporeLite.loadModelFromFd(file.fd, (result) => {
const modelInputs = result.getInputs(); const modelInputs = result.getInputs();
console.log(modelInputs[0].name); console.log(modelInputs[0].name);
...@@ -313,7 +313,7 @@ import fs from '@ohos.file.fs'; ...@@ -313,7 +313,7 @@ import fs from '@ohos.file.fs';
let model_file = '/path/to/xxx.ms'; let model_file = '/path/to/xxx.ms';
let context : mindSporeLite.Context = {}; let context : mindSporeLite.Context = {};
context = {'target': ['cpu']}; 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) => { mindSporeLite.loadModelFromFd(file.fd, context, (result) => {
const modelInputs = result.getInputs(); const modelInputs = result.getInputs();
console.log(modelInputs[0].name); console.log(modelInputs[0].name);
...@@ -345,7 +345,7 @@ Loads the input model based on the specified file descriptor for inference. This ...@@ -345,7 +345,7 @@ Loads the input model based on the specified file descriptor for inference. This
```js ```js
import fs from '@ohos.file.fs'; import fs from '@ohos.file.fs';
let model_file = '/path/to/xxx.ms'; 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); let mindSporeLiteModel = await mindSporeLite.loadModelFromFd(file.fd);
mindSporeLite.loadModelFromFd(file.fd).then((result) => { mindSporeLite.loadModelFromFd(file.fd).then((result) => {
const modelInputs = result.getInputs(); const modelInputs = result.getInputs();
...@@ -383,9 +383,9 @@ mindSporeLite.loadModelFromFile(model_file).then((result) => { ...@@ -383,9 +383,9 @@ mindSporeLite.loadModelFromFile(model_file).then((result) => {
``` ```
### predict ### predict
predict(inputs: MSTensor[], callback: Callback&lt;Model&gt;): void predict(inputs: MSTensor[], callback: Callback&lt;MSTensor[]&gt;): 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 **System capability**: SystemCapability.AI.MindSporeLite
...@@ -394,21 +394,21 @@ Executes the inference model. This API uses an asynchronous callback to return t ...@@ -394,21 +394,21 @@ Executes the inference model. This API uses an asynchronous callback to return t
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ----------------------- | ---- | -------------------------- | | ------ | ----------------------- | ---- | -------------------------- |
| inputs | [MSTensor](#mstensor)[] | Yes | Model input, which is an **MSTensor** object.| | 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** **Example**
```js ```js
import resourceManager from '@ohos.resourceManager' import resourceManager from '@ohos.resourceManager'
@State inputName: string = 'input_data.bin'; let inputName = 'input_data.bin';
let syscontext = globalThis.context; let syscontext = globalThis.context;
syscontext.resourceManager.getRawFileContent(this.inputName).then((buffer) => { syscontext.resourceManager.getRawFileContent(inputName).then(async (buffer) => {
this.inputBuffer = buffer; let inputBuffer = buffer;
let model_file = '/path/to/xxx.ms'; let model_file = '/path/to/xxx.ms';
let mindSporeLiteModel = await mindSporeLite.loadModelFromFile(model_file); let mindSporeLiteModel = await mindSporeLite.loadModelFromFile(model_file);
const modelInputs = mindSporeLiteModel.getInputs(); const modelInputs = mindSporeLiteModel.getInputs();
modelInputs[0].setData(this.inputBuffer.buffer); modelInputs[0].setData(inputBuffer.buffer);
result.predict(modelInputs, (result) => { mindSporeLiteModel.predict(modelInputs, (result) => {
let output = new Float32Array(result[0].getData()); let output = new Float32Array(result[0].getData());
for (let i = 0; i < output.length; i++) { for (let i = 0; i < output.length; i++) {
console.log(output[i].toString()); console.log(output[i].toString());
...@@ -420,7 +420,7 @@ syscontext.resourceManager.getRawFileContent(this.inputName).then((buffer) => { ...@@ -420,7 +420,7 @@ syscontext.resourceManager.getRawFileContent(this.inputName).then((buffer) => {
predict(inputs: MSTensor[]): Promise&lt;MSTensor[]&gt; predict(inputs: MSTensor[]): Promise&lt;MSTensor[]&gt;
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 **System capability**: SystemCapability.AI.MindSporeLite
...@@ -440,15 +440,15 @@ Executes the inference model. This API uses a promise to return the result. ...@@ -440,15 +440,15 @@ Executes the inference model. This API uses a promise to return the result.
```js ```js
import resourceManager from '@ohos.resourceManager' import resourceManager from '@ohos.resourceManager'
@State inputName: string = 'input_data.bin'; let inputName = 'input_data.bin';
let syscontext = globalThis.context; let syscontext = globalThis.context;
syscontext.resourceManager.getRawFileContent(this.inputName).then((buffer) => { syscontext.resourceManager.getRawFileContent(inputName).then(async (buffer) => {
this.inputBuffer = buffer; let inputBuffer = buffer;
let model_file = '/path/to/xxx.ms'; let model_file = '/path/to/xxx.ms';
let mindSporeLiteModel = await mindSporeLite.loadModelFromFile(model_file); let mindSporeLiteModel = await mindSporeLite.loadModelFromFile(model_file);
const modelInputs = mindSporeLiteModel.getInputs(); const modelInputs = mindSporeLiteModel.getInputs();
modelInputs[0].setData(this.inputBuffer.buffer); modelInputs[0].setData(inputBuffer.buffer);
result.predict(modelInputs).then((result) => { mindSporeLiteModel.predict(modelInputs).then((result) => {
let output = new Float32Array(result[0].getData()); let output = new Float32Array(result[0].getData());
for (let i = 0; i < output.length; i++) { for (let i = 0; i < output.length; i++) {
console.log(output[i].toString()); console.log(output[i].toString());
...@@ -541,15 +541,15 @@ Obtains tensor data. ...@@ -541,15 +541,15 @@ Obtains tensor data.
```js ```js
import resourceManager from '@ohos.resourceManager' import resourceManager from '@ohos.resourceManager'
@State inputName: string = 'input_data.bin'; let inputName = 'input_data.bin';
let syscontext = globalThis.context; let syscontext = globalThis.context;
syscontext.resourceManager.getRawFileContent(this.inputName).then((buffer) => { syscontext.resourceManager.getRawFileContent(inputName).then(async (buffer) => {
this.inputBuffer = buffer; let inputBuffer = buffer;
let model_file = '/path/to/xxx.ms'; let model_file = '/path/to/xxx.ms';
let mindSporeLiteModel = await mindSporeLite.loadModelFromFile(model_file); let mindSporeLiteModel = await mindSporeLite.loadModelFromFile(model_file);
const modelInputs = mindSporeLiteModel.getInputs(); const modelInputs = mindSporeLiteModel.getInputs();
modelInputs[0].setData(this.inputBuffer.buffer); modelInputs[0].setData(inputBuffer.buffer);
result.predict(modelInputs).then((result) => { mindSporeLiteModel.predict(modelInputs).then((result) => {
let output = new Float32Array(result[0].getData()); let output = new Float32Array(result[0].getData());
for (let i = 0; i < output.length; i++) { for (let i = 0; i < output.length; i++) {
console.log(output[i].toString()); console.log(output[i].toString());
...@@ -576,15 +576,15 @@ Sets the tensor data. ...@@ -576,15 +576,15 @@ Sets the tensor data.
```js ```js
import resourceManager from '@ohos.resourceManager' import resourceManager from '@ohos.resourceManager'
@State inputName: string = 'input_data.bin'; let inputName = 'input_data.bin';
let syscontext = globalThis.context; let syscontext = globalThis.context;
syscontext.resourceManager.getRawFileContent(this.inputName).then((buffer) => { syscontext.resourceManager.getRawFileContent(inputName).then(async (buffer) => {
this.inputBuffer = 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 ## DataType
......
...@@ -718,6 +718,41 @@ discoveryService.on('discoveryStart', (data) => { ...@@ -718,6 +718,41 @@ discoveryService.on('discoveryStart', (data) => {
discoveryService.stopSearchingMDNS(); discoveryService.stopSearchingMDNS();
``` ```
### off('discoveryStart')<sup>10+</sup>
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**.<br>**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')<sup>10+</sup> ### on('discoveryStop')<sup>10+</sup>
on(type: 'discoveryStop', callback: Callback<{serviceInfo: LocalServiceInfo, errorCode?: MdnsError}>): void on(type: 'discoveryStop', callback: Callback<{serviceInfo: LocalServiceInfo, errorCode?: MdnsError}>): void
...@@ -749,6 +784,41 @@ discoveryService.on('discoveryStop', (data) => { ...@@ -749,6 +784,41 @@ discoveryService.on('discoveryStop', (data) => {
discoveryService.stopSearchingMDNS(); discoveryService.stopSearchingMDNS();
``` ```
### off('discoveryStop')<sup>10+</sup>
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**.<br>**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')<sup>10+</sup> ### on('serviceFound')<sup>10+</sup>
on(type: 'serviceFound', callback: Callback\<LocalServiceInfo>): void on(type: 'serviceFound', callback: Callback\<LocalServiceInfo>): void
...@@ -780,6 +850,41 @@ discoveryService.on('serviceFound', (data) => { ...@@ -780,6 +850,41 @@ discoveryService.on('serviceFound', (data) => {
discoveryService.stopSearchingMDNS(); discoveryService.stopSearchingMDNS();
``` ```
### off('serviceFound')<sup>10+</sup>
off(type: 'serviceFound', callback: Callback\<LocalServiceInfo>): 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**.<br>**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')<sup>10+</sup> ### on('serviceLost')<sup>10+</sup>
on(type: 'serviceLost', callback: Callback\<LocalServiceInfo>): void on(type: 'serviceLost', callback: Callback\<LocalServiceInfo>): void
...@@ -811,6 +916,41 @@ discoveryService.on('serviceLost', (data) => { ...@@ -811,6 +916,41 @@ discoveryService.on('serviceLost', (data) => {
discoveryService.stopSearchingMDNS(); discoveryService.stopSearchingMDNS();
``` ```
### off('serviceLost')<sup>10+</sup>
off(type: 'serviceLost', callback: Callback\<LocalServiceInfo>): 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**.<br>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));
});
```
## LocalServiceInfo<sup>10+</sup> ## LocalServiceInfo<sup>10+</sup>
Defines the mDNS service information. Defines the mDNS service information.
......
# # @ohos.net.socket (Socket Connection) # @ohos.net.socket (Socket Connection)
The **socket** module implements data transfer over TCP, UDP, Web, and TLS socket connections. The **socket** module implements data transfer over TCP, UDP, Web, and TLS socket connections.
...@@ -1691,7 +1691,7 @@ listen(address: NetAddress, callback: AsyncCallback\<void\>): void ...@@ -1691,7 +1691,7 @@ listen(address: NetAddress, callback: AsyncCallback\<void\>): 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. 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**<br>
> 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. > 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 **Required permissions**: ohos.permission.INTERNET
...@@ -1736,7 +1736,7 @@ listen(address: NetAddress): Promise\<void\> ...@@ -1736,7 +1736,7 @@ listen(address: NetAddress): Promise\<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 a promise to return the result. 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**<br>
> 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. > 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 **Required permissions**: ohos.permission.INTERNET
...@@ -2515,7 +2515,7 @@ tcpServer.on('connect', function(client) { ...@@ -2515,7 +2515,7 @@ tcpServer.on('connect', function(client) {
### off('close')<sup>10+</sup> ### off('close')<sup>10+</sup>
on(type: 'close', callback: Callback\<void\>): void off(type: 'close', callback?: Callback<void>): void
Unsubscribes from **close** events of a **TCPSocketConnection** object. This API uses an asynchronous callback to return the result. 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) { ...@@ -5706,7 +5706,7 @@ tlsServer.on('connect', function(client) {
### off('close')<sup>10+</sup> ### off('close')<sup>10+</sup>
on(type: 'close', callback: Callback\<void\>): void off(type: 'close', callback?: Callback<void>): void
Unsubscribes from **close** events of a **TLSSocketConnection** object. This API uses an asynchronous callback to return the result. Unsubscribes from **close** events of a **TLSSocketConnection** object. This API uses an asynchronous callback to return the result.
......
...@@ -137,7 +137,7 @@ Checks whether the application has the permission to access the device. ...@@ -137,7 +137,7 @@ Checks whether the application has the permission to access the device.
**Example** **Example**
```js ```js
let devicesName="1-1"; let devicesName= "1-1";
let bool = usb.hasRight(devicesName); let bool = usb.hasRight(devicesName);
console.log(bool); console.log(bool);
``` ```
...@@ -146,7 +146,7 @@ console.log(bool); ...@@ -146,7 +146,7 @@ console.log(bool);
requestRight(deviceName: string): Promise&lt;boolean&gt; requestRight(deviceName: string): Promise&lt;boolean&gt;
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 **System capability**: SystemCapability.USB.USBManager
...@@ -165,7 +165,7 @@ Requests the temporary permission for the application to access a USB device. Th ...@@ -165,7 +165,7 @@ Requests the temporary permission for the application to access a USB device. Th
**Example** **Example**
```js ```js
let devicesName="1-1"; let devicesName= "1-1";
usb.requestRight(devicesName).then((ret) => { usb.requestRight(devicesName).then((ret) => {
console.log(`requestRight = ${ret}`); console.log(`requestRight = ${ret}`);
}); });
...@@ -375,7 +375,14 @@ Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB devi ...@@ -375,7 +375,14 @@ Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB devi
**Example** **Example**
```js ```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) => { usb.controlTransfer(devicepipe, param).then((ret) => {
console.log(`controlTransfer = ${ret}`); console.log(`controlTransfer = ${ret}`);
}) })
...@@ -500,7 +507,7 @@ Converts the USB function list in the numeric mask format to a string in Device ...@@ -500,7 +507,7 @@ Converts the USB function list in the numeric mask format to a string in Device
**Example** **Example**
```js ```js
let funcs = usb.ACM | usb.ECM; let funcs = usb.FunctionType.ACM | usb.FunctionType.ECM;
let ret = usb.usbFunctionsToString(funcs); let ret = usb.usbFunctionsToString(funcs);
``` ```
...@@ -529,8 +536,12 @@ Sets the current USB function list in Device mode. ...@@ -529,8 +536,12 @@ Sets the current USB function list in Device mode.
**Example** **Example**
```js ```js
let funcs = usb.HDC; let funcs = usb.FunctionType.HDC;
let ret = usb.setCurrentFunctions(funcs); usb.setCurrentFunctions(funcs).then(() => {
console.info('usb setCurrentFunctions successfully.');
}).catch(err => {
console.error('usb setCurrentFunctions failed: ' + err.code + ' message: ' + err.message);
});
``` ```
## usb.getCurrentFunctions<sup>9+</sup> ## usb.getCurrentFunctions<sup>9+</sup>
...@@ -848,7 +859,7 @@ Enumerates power role types. ...@@ -848,7 +859,7 @@ Enumerates power role types.
| Name | Value | Description | | Name | Value | Description |
| ------ | ---- | ---------- | | ------ | ---- | ---------- |
| NONE | 0 | None | | NONE | 0 | None. |
| SOURCE | 1 | External power supply.| | SOURCE | 1 | External power supply.|
| SINK | 2 | Internal power supply.| | SINK | 2 | Internal power supply.|
...@@ -862,6 +873,6 @@ Enumerates data role types. ...@@ -862,6 +873,6 @@ Enumerates data role types.
| Name | Value | Description | | Name | Value | Description |
| ------ | ---- | ------------ | | ------ | ---- | ------------ |
| NONE | 0 | None | | NONE | 0 | None. |
| HOST | 1 | USB host.| | HOST | 1 | USB host.|
| DEVICE | 2 | USB device.| | DEVICE | 2 | USB device.|
...@@ -161,7 +161,7 @@ console.log(`${bool}`); ...@@ -161,7 +161,7 @@ console.log(`${bool}`);
requestRight(deviceName: string): Promise&lt;boolean&gt; requestRight(deviceName: string): Promise&lt;boolean&gt;
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 **System capability**: SystemCapability.USB.USBManager
...@@ -190,7 +190,7 @@ usb.requestRight(devicesName).then((ret) => { ...@@ -190,7 +190,7 @@ usb.requestRight(devicesName).then((ret) => {
removeRight(deviceName: string): boolean 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 **System capability**: SystemCapability.USB.USBManager
...@@ -219,7 +219,7 @@ if (usb.removeRight(devicesName)) { ...@@ -219,7 +219,7 @@ if (usb.removeRight(devicesName)) {
addRight(bundleName: string, deviceName: string): boolean 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. [requestRight](#usbrequestright) triggers a dialog box to request for user authorization, whereas **addRight** adds the access permission directly without displaying a dialog box.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册