未验证 提交 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:
- Discovering local services and listening to the status changes of local services of the specified type through the **DiscoveryService** object.
> **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).
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
| 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\<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 | off(type: 'serviceLost', callback: Callback\<LocalServiceInfo>): void | Disables listening for **serviceLost** events.|
## Managing Local Services
......@@ -94,10 +99,11 @@ mdns.removeLocalService(context, localServiceInfo, function (error, data) {
1. Connect the device to the Wi-Fi network.
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.
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 +145,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));
});
```
......@@ -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)
# @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&lt;DragState&gt;): void;
......@@ -41,7 +41,7 @@ try {
}
```
## dragInteraction.off
## dragInteraction.off('drag')
off(type: 'drag', callback?: Callback&lt;DragState&gt;): void;
......
# @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&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
......@@ -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&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
......@@ -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
......
......@@ -718,6 +718,41 @@ discoveryService.on('discoveryStart', (data) => {
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(type: 'discoveryStop', callback: Callback<{serviceInfo: LocalServiceInfo, errorCode?: MdnsError}>): void
......@@ -749,6 +784,41 @@ discoveryService.on('discoveryStop', (data) => {
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(type: 'serviceFound', callback: Callback\<LocalServiceInfo>): void
......@@ -780,6 +850,41 @@ discoveryService.on('serviceFound', (data) => {
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(type: 'serviceLost', callback: Callback\<LocalServiceInfo>): void
......@@ -811,6 +916,41 @@ discoveryService.on('serviceLost', (data) => {
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>
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.
......@@ -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.
> **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.
**Required permissions**: ohos.permission.INTERNET
......@@ -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.
> **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.
**Required permissions**: ohos.permission.INTERNET
......@@ -2515,7 +2515,7 @@ tcpServer.on('connect', function(client) {
### 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.
......@@ -5706,7 +5706,7 @@ tlsServer.on('connect', function(client) {
### 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.
......
......@@ -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&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
......@@ -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.getCurrentFunctions<sup>9+</sup>
......@@ -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.|
......@@ -161,7 +161,7 @@ console.log(`${bool}`);
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
......@@ -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.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册