The USB service provides the following functions: query of USB device list, bulk data transfer, control transfer, and access permission management.
## When to Use
## When to Use
In Host mode, you can obtain the list of connected devices, enable or disable the devices, manage device access permissions, and perform data transfer or control transfer.
In Host mode, you can obtain the list of connected devices, enable or disable the devices, manage device access permissions, and perform data transfer or control transfer.
## APIs
## APIs
The USB service provides the following functions: query of USB device list, bulk data transfer, control transfer, and access permission management.
The following table lists the USB APIs currently available. For details, see the [API Reference](../reference/apis/js-apis-usb.md).
The following table lists the USB APIs currently available. For details, see the [API Reference](../reference/apis/js-apis-usb.md).
**Table 1** Open USB APIs
**Table 1** Open USB APIs
...
@@ -16,12 +16,12 @@ The following table lists the USB APIs currently available. For details, see the
...
@@ -16,12 +16,12 @@ The following table lists the USB APIs currently available. For details, see the
| hasRight(deviceName: string): boolean | Checks whether the user, for example, the application or system, has the device access permissions. The value **true** is returned if the user has the device access permissions; the value **false** is returned otherwise. |
| hasRight(deviceName: string): boolean | Checks whether the user, for example, the application or system, has the device access permissions. The value **true** is returned if the user has the device access permissions; the value **false** is returned otherwise. |
| requestRight(deviceName: string): Promise\<boolean> | Requests the temporary permission for a given application to access the USB device. |
| requestRight(deviceName: string): Promise\<boolean> | Requests the temporary permission for a given application to access the USB device. |
| connectDevice(device: USBDevice): Readonly\<USBDevicePipe> | Connects to the USB device based on the device information returned by **getDevices()**. |
| connectDevice(device: USBDevice): Readonly\<USBDevicePipe> | Connects to the USB device based on the device information returned by `getDevices()`. |
| getDevices(): Array<Readonly\<USBDevice>> | Obtains the USB device list. |
| getDevices(): Array<Readonly\<USBDevice>> | Obtains the USB device list. |
| setConfiguration(pipe: USBDevicePipe, config: USBConfig): number | Sets the USB device configuration. |
| setConfiguration(pipe: USBDevicePipe, config: USBConfig): number | Sets the USB device configuration. |
| setInterface(pipe: USBDevicePipe, iface: USBInterface): number | Sets a USB interface. |
| setInterface(pipe: USBDevicePipe, iface: USBInterface): number | Sets a USB interface. |
| claimInterface(pipe: USBDevicePipe, iface: USBInterface, force?: boolean): number | Claims a USB interface |
| claimInterface(pipe: USBDevicePipe, iface: USBInterface, force?: boolean): number | Claims a USB interface. |
@@ -7,7 +7,7 @@ There are two types of updates: SD card update and over the air (OTA) update.
...
@@ -7,7 +7,7 @@ There are two types of updates: SD card update and over the air (OTA) update.
- The SD card update depends on the update packages and SD cards.
- The SD card update depends on the update packages and SD cards.
- The OTA update depends on the server deployed by the device manufacturer for managing update packages. The OTA server IP address is passed by the caller. The request interface is fixed and developed by the device manufacturer.
- The OTA update depends on the server deployed by the device manufacturer for managing update packages. The OTA server IP address is passed by the caller. The request interface is fixed and developed by the device manufacturer.
> **Note:**
> **NOTE**
>
>
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
>
>
...
@@ -239,7 +239,7 @@ var versionDigestInfo = {
...
@@ -239,7 +239,7 @@ var versionDigestInfo = {
// Options of the description file
// Options of the description file
vardescriptionOptions={
vardescriptionOptions={
format:DescriptionFormat.STANDARD,// Standard format
format:update.DescriptionFormat.STANDARD,// Standard format
language:"zh-cn"// Chinese
language:"zh-cn"// Chinese
}
}
...
@@ -282,7 +282,7 @@ var versionDigestInfo = {
...
@@ -282,7 +282,7 @@ var versionDigestInfo = {
// Options of the description file
// Options of the description file
vardescriptionOptions={
vardescriptionOptions={
format:DescriptionFormat.STANDARD,// Standard format
format:update.DescriptionFormat.STANDARD,// Standard format
language:"zh-cn"// Chinese
language:"zh-cn"// Chinese
}
}
...
@@ -369,7 +369,7 @@ Obtains the description file of the current version. This API uses an asynchrono
...
@@ -369,7 +369,7 @@ Obtains the description file of the current version. This API uses an asynchrono
```ts
```ts
// Options of the description file
// Options of the description file
vardescriptionOptions={
vardescriptionOptions={
format:DescriptionFormat.STANDARD,// Standard format
format:update.DescriptionFormat.STANDARD,// Standard format
language:"zh-cn"// Chinese
language:"zh-cn"// Chinese
}
}
...
@@ -406,7 +406,7 @@ Obtains the description file of the current version. This API uses a promise to
...
@@ -406,7 +406,7 @@ Obtains the description file of the current version. This API uses a promise to
```ts
```ts
// Options of the description file
// Options of the description file
vardescriptionOptions={
vardescriptionOptions={
format:DescriptionFormat.STANDARD,// Standard format
format:update.DescriptionFormat.STANDARD,// Standard format
| boolean | Returns **true** if the application has the permission to access the device; returns **false** otherwise.|
| -------- | -------- |
| boolean | The value **true** indicates that the application has the permission to access the device, and the value **false** indicates the opposite.|
| Promise<boolean> | Returns **true** if the temporary device access permissions are granted; returns **false** otherwise.|
| -------- | -------- |
| Promise<boolean> | Promise used to return the result. The value **true** indicates that the temporary device access permissions are granted, and the value **false** indicates the opposite.|
**Example**
**Example**
...
@@ -174,16 +180,18 @@ Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB devi
...
@@ -174,16 +180,18 @@ Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB devi
| pipe | [USBDevicePipe](#usbdevicepipe) | Yes| Device pipe, which is used to determine the bus number and device address.|
| -------- | -------- | -------- | -------- |
| iface | [USBInterface](#usbinterface) | Yes| USB interface, which is used to determine the index of the interface to claim.|
| pipe | [USBDevicePipe](#usbdevicepipe) | Yes| Device pipe, which is used to determine the bus number and device address.|
| force | boolean | No| Whether to forcibly claim the USB interface. The default value is **false**, indicating not to forcibly claim the USB interface.|
| iface | [USBInterface](#usbinterface) | Yes| USB interface, which is used to determine the index of the interface to claim.|
| force | boolean | No| Whether to forcibly claim the USB interface. The default value is **false**, indicating not to forcibly claim the USB interface.|
**Return value**
**Return value**
| Type| Description|
| -------- | -------- |
| Type| Description|
| number | Returns **0** if the USB interface is successfully claimed; returns an error code otherwise.|
| -------- | -------- |
| number | The value **0** indicates that the USB interface is successfully claimed, and an error code indicates the opposite.|
**Example**
**Example**
...
@@ -203,15 +211,17 @@ Before you do this, ensure that you have claimed the interface by calling [usb.c
...
@@ -203,15 +211,17 @@ Before you do this, ensure that you have claimed the interface by calling [usb.c
| pipe | [USBDevicePipe](#usbdevicepipe) | Yes| USB device pipe, which is used to determine the USB device.|
| -------- | -------- | -------- | -------- |
| contrlparam | [USBControlParams](#usbcontrolparams) | Yes| Control transfer parameters.|
| pipe | [USBDevicePipe](#usbdevicepipe) | Yes| USB device pipe, which is used to determine the USB device.|
| timeout | number | No| Timeout duration. The default value is **0**, indicating no timeout.|
| contrlparam | [USBControlParams](#usbcontrolparams) | Yes| Control transfer parameters.|
| timeout | number | No| Timeout duration in ms. This parameter is optional. The default value is **0**, indicating no timeout.|
**Return value**
**Return value**
| Type| Description|
| -------- | -------- |
| Type| Description|
| Promise<number> | Returns the size of the transmitted or received data block if the control transfer is successful; returns **-1** if an exception occurs.|
| -------- | -------- |
| Promise<number> | Promise used to return the result, which is the size of the transmitted or received data block if the transfer is successful, or **-1** if an exception has occurred.|
**Example**
**Example**
...
@@ -372,17 +389,19 @@ Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB devi
...
@@ -372,17 +389,19 @@ Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB devi
| pipe | [USBDevicePipe](#usbdevicepipe) | Yes| USB device pipe, which is used to determine the USB device.|
| -------- | -------- | -------- | -------- |
| endpoint | [USBEndpoint](#usbendpoint) | Yes| USB endpoint, which is used to determine the USB port for data transfer.|
| pipe | [USBDevicePipe](#usbdevicepipe) | Yes| USB device pipe, which is used to determine the USB device.|
| buffer | Uint8Array | Yes| Buffer for writing or reading data.|
| endpoint | [USBEndpoint](#usbendpoint) | Yes| USB endpoint, which is used to determine the USB port for data transfer.|
| timeout | number | No| Timeout duration. The default value is **0**, indicating no timeout.|
| buffer | Uint8Array | Yes| Buffer for writing or reading data.|
| timeout | number | No| Timeout duration in ms. This parameter is optional. The default value is **0**, indicating no timeout.|
**Return value**
**Return value**
| Type| Description|
| -------- | -------- |
| Type| Description|
| Promise<number> | Returns the size of the transmitted or received data block if the control transfer is successful; returns **-1** if an exception occurs.|
| -------- | -------- |
| Promise<number> | Promise used to return the result, which is the size of the transmitted or received data block if the transfer is successful, or **-1** if an exception has occurred.|
**Example**
**Example**
...
@@ -406,14 +425,16 @@ Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB devi
...
@@ -406,14 +425,16 @@ Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB devi
| Promise\<boolean\> | Promise used to return the result. The value **true** indicates that the operation is successful, and the value **false** indicates the opposite.|
| Promise\<boolean\> | Promise used to return the result. The value **true** indicates that the operation is successful, and the value **false** indicates the opposite.|
**Example**
**Example**
...
@@ -601,8 +622,8 @@ Sets the role types supported by a specified port, which can be **powerRole** (f
...
@@ -601,8 +622,8 @@ Sets the role types supported by a specified port, which can be **powerRole** (f
| Promise\<boolean\> | Promise used to return the result. The value **true** indicates that the operation is successful, and the value **false** indicates the opposite.|
| Promise\<boolean\> | Promise used to return the result. The value **true** indicates that the operation is successful, and the value **false** indicates the opposite.|
@@ -15,27 +15,27 @@ HiSysEvent allows you to query system events by specifying search criteria. For
...
@@ -15,27 +15,27 @@ HiSysEvent allows you to query system events by specifying search criteria. For
>
>
> For details about the **HiSysEventRecord** argument in the **OnQuery()** method of **HiSysEventQueryCallback**, see Table 5 in [HiSysEvent Listening](subsys-dfx-hisysevent-listening.md).
> For details about the **HiSysEventRecord** argument in the **OnQuery()** method of **HiSysEventQueryCallback**, see Table 5 in [HiSysEvent Listening](subsys-dfx-hisysevent-listening.md).
**Table 1** Description of the HiSysEvent query API
**Table 1** Description of the HiSysEvent query API
| API| Description|
| API | Description |
| -------- | -------- |
| --- | ----------- |
| int32_t HiSysEventManager::Query(struct QueryArg& arg, std::vector<QueryRule>& rules, std::shared_ptr<HiSysEventQueryCallback> callback) | Queries system events by specifying search criteria such as the time segment, event domain, and event name.<br>Input arguments:<br>- **arg**: event query parameter.<br>- **rules**: rules for event filtering.<br>- **callback**: callback object for event query.<br>Return value:<br>- **0**: Query is successful.<br>- A negative value: Query has failed.|
| int32_t HiSysEventManager::Query(struct QueryArg& arg, std::vector<QueryRule>& rules, std::shared_ptr<HiSysEventQueryCallback> callback) | Queries system events by specifying search criteria such as the time segment, event domain, and event name.<br>Input arguments:<br>- **arg**: event query parameter.<br>- **rules**: rules for event filtering.<br>- **callback**: callback object for event query.<br>Return value:<br>- **0**: Query is successful.<br>- A negative value: Query has failed.|
**Table 2** Description of QueryArg
**Table 2** Description of QueryArg
| Attribute| Description|
| Attribute | Description |
| -------- | -------- |
| --------- | ----------- |
| beginTime | Start time, in the **long long int** format.|
| beginTime | Start time, in the **long long int** format.|
| endTime | End time, in the **long long int** format.|
| endTime | End time, in the **long long int** format.|
| maxEvents | Maximum number of returned events, in the **int** format.|
| maxEvents | Maximum number of returned events, in the **int** format.|
**Table 3** Description of QueryRule
**Table 3** Description of QueryRule
| API| Description|
| API| Description|
| -------- | -------- |
| -------- | -------- |
| QueryRule(const std::string& domain, const std::vector<std::string>& eventList) | Constructor used to create a **QueryRule** object.<br>Input arguments:<br>- **domain**: domain to which the event of the **QueryRule** object belongs, in the string format. By default, an empty string indicates that the domain is successfully matched.<br>- **eventList**: event name list, in the **std::vector<std::string>** format. By default, an empty string indicates that the event names on the list are successfully matched.|
| QueryRule(const std::string& domain, const std::vector<std::string>& eventList) | Constructor used to create a **QueryRule** object.<br>Input arguments:<br>- **domain**: domain to which the event of the **QueryRule** object belongs, in the string format. By default, an empty string indicates that the domain is successfully matched.<br>- **eventList**: event name list, in the **std::vector<std::string>** format. By default, an empty string indicates that the event names on the list are successfully matched.|
**Table 4** Description of HiSysEventQueryCallback
**Table 4** Description of HiSysEventQueryCallback
| API| Description|
| API| Description|
| -------- | -------- |
| -------- | -------- |
...
@@ -60,7 +60,7 @@ HiSysEvent allows you to query system events by specifying search criteria. For
...
@@ -60,7 +60,7 @@ HiSysEvent allows you to query system events by specifying search criteria. For