The **nfctech** module provides methods for reading and writing tags that use different Near-Field Communication (NFC) technologies.
The **nfctech** module provides APIs for reading and writing tags that use different Near-Field Communication (NFC) technologies.
> **NOTE**
> **NOTE**
>
> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## **Modules to Import**
## **Modules to Import**
...
@@ -14,7 +13,7 @@ import tag from '@ohos.nfc.tag';
...
@@ -14,7 +13,7 @@ import tag from '@ohos.nfc.tag';
## NfcATag
## NfcATag
Provides access to NFC-A (ISO 14443-3A) properties and I/O operations. **NfcATag** inherits from **TagSession**.
Provides access to NFC-A (ISO 14443-3A) properties and I/O operations. This class inherits from **TagSession**.
**TagSession** is the base class of all NFC tag technologies. It provides common interfaces for establishing connections and transferring data. For more details, see [TagSession](js-apis-tagSession.md).
**TagSession** is the base class of all NFC tag technologies. It provides common interfaces for establishing connections and transferring data. For more details, see [TagSession](js-apis-tagSession.md).
...
@@ -74,7 +73,7 @@ console.log("atqa:" +atqa);
...
@@ -74,7 +73,7 @@ console.log("atqa:" +atqa);
## NfcBTag
## NfcBTag
Provides access to NFC-B (ISO 14443-3B) properties and I/O operations. **NfcBTag** inherits from **TagSession**.
Provides access to NFC-B (ISO 14443-3B) properties and I/O operations. This class inherits from **TagSession**.
**TagSession** is the base class of all NFC tag technologies. It provides common interfaces for establishing connections and transferring data. For more details, see [TagSession](js-apis-tagSession.md).
**TagSession** is the base class of all NFC tag technologies. It provides common interfaces for establishing connections and transferring data. For more details, see [TagSession](js-apis-tagSession.md).
Provides access to NFC-F(JIS 6319-4) properties and I/O operations. **NfcFTag** inherits from **TagSession**.
Provides access to NFC-F (JIS 6319-4) properties and I/O operations. This class inherits from **TagSession**.
**TagSession** is the base class of all NFC tag technologies. It provides common interfaces for establishing connections and transferring data. For more details, see [TagSession](js-apis-tagSession.md).
**TagSession** is the base class of all NFC tag technologies. It provides common interfaces for establishing connections and transferring data. For more details, see [TagSession](js-apis-tagSession.md).
...
@@ -144,7 +143,7 @@ The following describes the unique interfaces of **NfcFTag**.
...
@@ -144,7 +143,7 @@ The following describes the unique interfaces of **NfcFTag**.
Obtains the PMm (consisting of the IC code and manufacturer parameters) information from the tag instance.
Obtains the PMm (consisting of the IC code and manufacturer parameters) information from this NFC-F tag.
**Required permissions**: ohos.permission.NFC_TAG
**Required permissions**: ohos.permission.NFC_TAG
...
@@ -194,7 +193,7 @@ console.log("pmm:" +pmm);
...
@@ -194,7 +193,7 @@ console.log("pmm:" +pmm);
## NfcVTag
## NfcVTag
Provides access to NFC-V (ISO 15693) properties and I/O operations. **NfcVTag** inherits from **TagSession**.
Provides access to NFC-V (ISO 15693) properties and I/O operations. This class inherits from **TagSession**.
**TagSession** is the base class of all NFC tag technologies. It provides common interfaces for establishing connections and transferring data. For more details, see [TagSession](js-apis-tagSession.md).
**TagSession** is the base class of all NFC tag technologies. It provides common interfaces for establishing connections and transferring data. For more details, see [TagSession](js-apis-tagSession.md).
...
@@ -204,7 +203,7 @@ The following describes the unique interfaces of **NfcVTag**.
...
@@ -204,7 +203,7 @@ The following describes the unique interfaces of **NfcVTag**.
getResponseFlags(): number
getResponseFlags(): number
Obtains the response flags from the tag instance.
Obtains the response flags from this NFC-V tag.
**Required permissions**: ohos.permission.NFC_TAG
**Required permissions**: ohos.permission.NFC_TAG
...
@@ -230,7 +229,7 @@ console.log("flags:" +flags);
...
@@ -230,7 +229,7 @@ console.log("flags:" +flags);
getDsfId(): number
getDsfId(): number
Obtains the data storage format identifier (DSFID) from the tag instance.
Obtains the data storage format identifier (DSFID) from this NFC-V tag.
**Required permissions**: ohos.permission.NFC_TAG
**Required permissions**: ohos.permission.NFC_TAG
...
@@ -254,7 +253,7 @@ console.log("dsfId:" +dsfId);
...
@@ -254,7 +253,7 @@ console.log("dsfId:" +dsfId);
## IsoDepTag<sup>9+</sup>
## IsoDepTag<sup>9+</sup>
Provides access to ISO-DEP (ISO 14443-4) properties and I/O operations. **IsoDepTag** inherits from **TagSession**.
Provides access to ISO-DEP (ISO 14443-4) properties and I/O operations. This class inherits from **TagSession**.
**TagSession** is the base class of all NFC tag technologies. It provides common interfaces for establishing connections and transferring data. For more details, see [TagSession](js-apis-tagSession.md).
**TagSession** is the base class of all NFC tag technologies. It provides common interfaces for establishing connections and transferring data. For more details, see [TagSession](js-apis-tagSession.md).
Provides access to the tags in the NFC Data Exchange Format (NDEF). **NdefTag** inherits from **TagSession**.
Provides access to the tags in the NFC Data Exchange Format (NDEF). This class inherits from **TagSession**.
**TagSession** is the base class of all NFC tag technologies. It provides common interfaces for establishing connections and transferring data. For more details, see [TagSession](js-apis-tagSession.md).
**TagSession** is the base class of all NFC tag technologies. It provides common interfaces for establishing connections and transferring data. For more details, see [TagSession](js-apis-tagSession.md).
...
@@ -596,7 +595,7 @@ Reads the NDEF message from this tag. This API uses a promise to return the resu
...
@@ -596,7 +595,7 @@ Reads the NDEF message from this tag. This API uses a promise to return the resu
Converts the NFC Forum Type to a byte array defined in the NFC Forum.
Converts an NFC Forum Type to a byte array defined in the NFC Forum.
**Required permissions**: ohos.permission.NFC_TAG
**Required permissions**: ohos.permission.NFC_TAG
...
@@ -852,7 +851,7 @@ let ndefTypeString= tag.NdefTag(taginfo).getNdefTagTypeString(type);
...
@@ -852,7 +851,7 @@ let ndefTypeString= tag.NdefTag(taginfo).getNdefTagTypeString(type);
## MifareClassicTag <sup>9+</sup>
## MifareClassicTag <sup>9+</sup>
Provides access to MIFARE Classic properties and I/O operations. **MifareClassicTag** inherits from **TagSession**.
Provides access to MIFARE Classic properties and I/O operations. This class inherits from **TagSession**.
**TagSession** is the base class of all NFC tag technologies. It provides common interfaces for establishing connections and transferring data. For more details, see [TagSession](js-apis-tagSession.md).
**TagSession** is the base class of all NFC tag technologies. It provides common interfaces for establishing connections and transferring data. For more details, see [TagSession](js-apis-tagSession.md).
...
@@ -928,7 +927,7 @@ tag.MifareClassicTag(taginfo).authenticateSector(sectorIndex, key, function (err
...
@@ -928,7 +927,7 @@ tag.MifareClassicTag(taginfo).authenticateSector(sectorIndex, key, function (err
Writes data to a block on the tag. The size of a block is 16 bytes. This API uses an asynchronous callback to return the result.
Writes data to a block on the tag. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.NFC_TAG
**Required permissions**: ohos.permission.NFC_TAG
...
@@ -1427,10 +1426,10 @@ let size = tag.MifareClassicTag(taginfo).getTagSize();
...
@@ -1427,10 +1426,10 @@ let size = tag.MifareClassicTag(taginfo).getTagSize();
| **Name**| **Value**| **Description**|
| **Name**| **Value**| **Description**|
| -------- | -------- | -------- |
| -------- | -------- | -------- |
| MC_SIZE_MINI | 320 | Each tag has five sectors, and each sector has four blocks.|
| MC_SIZE_MINI | 320 | Each tag has 5 sectors, and each sector has 4 blocks.|
| MC_SIZE_1K | 1024 | Each tag has 16 sectors, and each sector has four blocks.|
| MC_SIZE_1K | 1024 | Each tag has 16 sectors, and each sector has 4 blocks.|
| MC_SIZE_2K | 2048 | Each tag has 32 sectors, and each sector has four blocks.|
| MC_SIZE_2K | 2048 | Each tag has 32 sectors, and each sector has 4 blocks.|
| MC_SIZE_4K | 4096 | Each tag has 40 sectors, and each sector has four blocks.|
| MC_SIZE_4K | 4096 | Each tag has 40 sectors, and each sector has 4 blocks.|
### MifareClassicTag.isEmulatedTag<sup>9+</sup>
### MifareClassicTag.isEmulatedTag<sup>9+</sup>
...
@@ -1521,7 +1520,7 @@ let index = tag.MifareClassicTag(taginfo).getSectorIndex(blockIndex);
...
@@ -1521,7 +1520,7 @@ let index = tag.MifareClassicTag(taginfo).getSectorIndex(blockIndex);
## MifareUltralightTag<sup>9+</sup>
## MifareUltralightTag<sup>9+</sup>
Provides access to MIFARE Ultralight properties and I/O operations. **MifareUltralightTag** inherits from **TagSession**.
Provides access to MIFARE Ultralight properties and I/O operations. This class inherits from **TagSession**.
**TagSession** is the base class of all NFC tag technologies. It provides common interfaces for establishing connections and transferring data. For more details, see [TagSession](js-apis-tagSession.md).
**TagSession** is the base class of all NFC tag technologies. It provides common interfaces for establishing connections and transferring data. For more details, see [TagSession](js-apis-tagSession.md).
...
@@ -1531,7 +1530,7 @@ The following describes the unique interfaces of **MifareUltralightTag**.
...
@@ -1531,7 +1530,7 @@ The following describes the unique interfaces of **MifareUltralightTag**.
Writes a page of data. The size of each page is 4 bytes. This API uses an asynchronous callback to return the result.
Writes a page of data. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.NFC_TAG
**Required permissions**: ohos.permission.NFC_TAG
...
@@ -1658,7 +1657,7 @@ tag.MifareUltralightTag(taginfo).writeSinglePages(pageIndex, data, function (err
...
@@ -1658,7 +1657,7 @@ tag.MifareUltralightTag(taginfo).writeSinglePages(pageIndex, data, function (err
getType(): MifareUltralightType
getType(): MifareUltralightType
Obtains the MIFARE Ultralight tag type, in bytes. For details, see [MifareUltralightType](#mifareultralighttype9).
Obtains the MIFARE Ultralight tag type, in bytes.
**Required permissions**: ohos.permission.NFC_TAG
**Required permissions**: ohos.permission.NFC_TAG
...
@@ -1689,7 +1688,7 @@ let type = tag.MifareUltralightType(taginfo).getType();
...
@@ -1689,7 +1688,7 @@ let type = tag.MifareUltralightType(taginfo).getType();
## NdefFormatableTag<sup>9+</sup>
## NdefFormatableTag<sup>9+</sup>
Provides methods for operating NDEF formattable tags. **NdefFormatableTag** inherits from **TagSession**.
Provides APIs for operating NDEF formattable tags. This class inherits from **TagSession**.
**TagSession** is the base class of all NFC tag technologies. It provides common interfaces for establishing connections and transferring data. For more details, see [TagSession](js-apis-tagSession.md).
**TagSession** is the base class of all NFC tag technologies. It provides common interfaces for establishing connections and transferring data. For more details, see [TagSession](js-apis-tagSession.md).
...
@@ -1709,7 +1708,7 @@ Formats this tag as an NDEF tag, and writes an NDEF message to the tag. This API
...
@@ -1709,7 +1708,7 @@ Formats this tag as an NDEF tag, and writes an NDEF message to the tag. This API
| message | [NdefMessage](#ndefmessage9) | Yes | NDEF message to write when the formatting is successful. If it is **null**, the tag is formatted only and no data will be written.|
| message | [NdefMessage](#ndefmessage9) | Yes | NDEF message to write when the formatting is successful. If this parameter is **null**, the tag is formatted only (no data will be written).|
**Return value**
**Return value**
...
@@ -1742,8 +1741,8 @@ Formats this tag as an NDEF tag, and writes an NDEF message to the tag. This API
...
@@ -1742,8 +1741,8 @@ Formats this tag as an NDEF tag, and writes an NDEF message to the tag. This API
| message | [NdefMessage](#ndefmessage9) | Yes | NDEF message to write when the formatting is successful. If it is **null**, the tag is formatted only and no data will be written.|
| message | [NdefMessage](#ndefmessage9) | Yes | NDEF message to write when the formatting is successful. If this parameter is **null**, the tag is formatted only.|
| callback: AsyncCallback\<number> | Callback invoked to return the result.|
| callback | AsyncCallback\<number> |Yes|Callback invoked to return the result.|
**Example**
**Example**
...
@@ -1771,7 +1770,7 @@ Formats this tag as an NDEF tag, writes an NDEF message to the NDEF tag, and the
...
@@ -1771,7 +1770,7 @@ Formats this tag as an NDEF tag, writes an NDEF message to the NDEF tag, and the
| message | [NdefMessage](#ndefmessage9) | Yes | NDEF message to write when the formatting is successful. If it is **null**, the tag is formatted only and no data will be written.|
| message | [NdefMessage](#ndefmessage9) | Yes | NDEF message to write when the formatting is successful. If this parameter is **null**, the tag is formatted only (no data will be written).|
**Return value**
**Return value**
...
@@ -1804,8 +1803,8 @@ Formats this tag as an NDEF tag, writes an NDEF message to the NDEF tag, and the
...
@@ -1804,8 +1803,8 @@ Formats this tag as an NDEF tag, writes an NDEF message to the NDEF tag, and the
| message | [NdefMessage](#ndefmessage9) | Yes | NDEF message to write when the formatting is successful. If it is **null**, the tag is formatted only and no data will be written.|
| message | [NdefMessage](#ndefmessage9) | Yes | NDEF message to write when the formatting is successful. If this parameter is **null**, the tag is formatted only.|
| callback: AsyncCallback\<number> | Callback invoked to return the result.|
| callback | AsyncCallback\<number> |Yes|Callback invoked to return the result.|
The **tagSession** module provides common APIs for establishing connections and transferring data.
The **tagSession** module provides common APIs for establishing connections and transferring data.
> **NOTE**
> **NOTE**<br>
>
> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## **Modules to Import**
## **Modules to Import**
...
@@ -18,7 +17,7 @@ Provides common APIs for establishing connections and transferring data. **tagSe
...
@@ -18,7 +17,7 @@ Provides common APIs for establishing connections and transferring data. **tagSe
A child class instance is required to access the following interfaces. You can use **get**XX**Tag()** to obtain a child class instance.
A child class instance is required to access the following interfaces. You can use **get**XX**Tag()** to obtain a child class instance.
The specific method varies with the NFC tag technology in use. For details, see [nfcTag](js-apis-nfcTag.md).
The specific API varies with the NFC tag technology in use. For details, see [NFC Tags](js-apis-nfcTag.md).
### tagSession.connectTag
### tagSession.connectTag
...
@@ -26,7 +25,7 @@ connectTag(): boolean;
...
@@ -26,7 +25,7 @@ connectTag(): boolean;
Connects to this tag.
Connects to this tag.
Call this method to set up a connection before reading data from or writing data to a tag.
Call this API to set up a connection before reading data from or writing data to a tag.
**Required permissions**: ohos.permission.NFC_TAG
**Required permissions**: ohos.permission.NFC_TAG
...
@@ -95,7 +94,7 @@ Checks whether the tag is connected.
...
@@ -95,7 +94,7 @@ Checks whether the tag is connected.
```js
```js
importtagfrom'@ohos.nfc.tag';
importtagfrom'@ohos.nfc.tag';
// tagInfo is an Object given by nfc service when tag is dispatched.
// tagInfo is an object given by the NFC service when a tag is dispatched.
The motion recognition module provides motion recognition and control capabilities. Currently, OpenHarmony supports recognition of pick-up, flip, shake, and rotation.
The motion module provides motion recognition and control capabilities. Currently, OpenHarmony supports recognition of pick-up, flip, shake, and rotation.
The motion recognition driver is developed based on the hardware driver foundation (HDF). It shields hardware differences and provides APIs for the Multimodal Sensor Data Platform (MSDP) to implement capabilities such as enabling or disabling motion recognition, and subscribing to or unsubscribing from motion recognition data.
The motion driver is developed based on the hardware driver foundation (HDF). It shields hardware differences and provides APIs for the Multimodal Sensor Data Platform (MSDP) to implement capabilities such as enabling or disabling motion recognition, and subscribing to or unsubscribing from motion recognition data.
The figure below shows the motion recognition driver architecture. The framework layer provides MSDP services, and interacts with the Motion Stub through the Motion Proxy in the User Hardware Driver Foundation (UHDF). The Motion Stub calls the Motion HDI Impl APIs to provide motion recognition capabilities for upper-layer services.
The figure below shows the motion driver architecture. The framework layer provides MSDP services, and interacts with the Motion Stub through the Motion Proxy in the User Hardware Driver Foundation (UHDF). The Motion Stub calls the Motion HDI Impl APIs to provide motion recognition capabilities for upper-layer services.
The figure below illustrates how a motion recognition driver works.
The figure below illustrates how a motion driver works.
**Figure 2** How a motion recognition driver works
**Figure 2** How a motion driver works
![](figures/motion_recognition_driver_work.png)
![](figures/motion_driver_work.png)
1. MSDP: The MSDP service obtains a Motion HDI service instance from the Motion Proxy and calls the Motion HDI API.
1. MSDP: The MSDP service obtains a Motion HDI service instance from the Motion Proxy and calls the Motion HDI API.
2. IDL: The IService Manager allocates a Motion HDI instance requested by the MSDP service, and the Motion Proxy forwards the instance to the MSDP service. After the MSDP service calls the HDI API provided by the Motion Proxy, Motion Stub is called through Inter-Process Communication (IPC) to invoke the Motion Service API. The code is automatically generated by a tool and does not need to be developed by the component vendor.
2. IDL: The IService Manager allocates a Motion HDI instance requested by the MSDP service, and the Motion Proxy forwards the instance to the MSDP service. After the MSDP service calls the HDI API provided by the Motion Proxy, Motion Stub is called through Inter-Process Communication (IPC) to invoke the Motion Service API. The code is automatically generated by a tool and does not need to be developed by the component vendor.
3. HDI Service: HDI Service consists of Motion Interface Driver, Motion Service, and Motion Impl. Motion Interface Driver provides the motion recognition driver code. A **HdfDriverEntry** structure is defined to implement the **Init**, **Bind**, and **Release** functions. The **HDF_INIT** macro is used to load the driver in the functions. Motion Service provides the motion recognition service interface class. The specific implementation is described in Motion Impl. The code of HDI Service must be developed by the component vendor.
3. HDI Service: HDI Service consists of Motion Interface Driver, Motion Service, and Motion Impl. Motion Interface Driver provides the motion driver code. A **HdfDriverEntry** structure is defined to implement the **Init**, **Bind**, and **Release** functions. The **HDF_INIT** macro is used to load the driver in the functions. Motion Service provides the motion recognition service interface class. The specific implementation is described in Motion Impl. The code of HDI Service must be developed by the component vendor.
## Development Guidelines
## Development Guidelines
### When to Use
### When to Use
The motion recognition driver provides capabilities for the MSDP service to enable or disable motion recognition and subscribe to or unsubscribe from motion recognition data. It can be used for motion recognition when a user picks up, flips, shakes, and rotates a device.
The motion driver provides capabilities for the MSDP service to enable or disable motion recognition and subscribe to or unsubscribe from motion recognition data. It can be used for motion recognition when a user picks up, flips, shakes, and rotates a device.
### Available APIs
### Available APIs
...
@@ -59,7 +59,7 @@ The motion recognition directory structure is as follows:
...
@@ -59,7 +59,7 @@ The motion recognition directory structure is as follows:
│ └── unittest\hdi # HDI unit test code for the motion recognition module.
│ └── unittest\hdi # HDI unit test code for the motion recognition module.
```
```
The following describes how to develop a user-mode motion recognition driver based on the HDF. For details, see [motion_interface_driver.cpp](https://gitee.com/openharmony/drivers_peripheral/blob/master/motion/hdi_service/motion_interface_driver.cpp).
The following describes how to develop a user-mode motion driver based on the HDF. For details, see [motion_interface_driver.cpp](https://gitee.com/openharmony/drivers_peripheral/blob/master/motion/hdi_service/motion_interface_driver.cpp).
To develop the user-mode driver for motion recognition, implement the **Bind**, **Init**, **Release**, and **Dispatch** functions. The **Bind** function provides service capabilities. The **Init** function initializes the driver before the driver is loaded. The **Release** function releases resources when the **Init** function fails.
To develop the user-mode driver for motion recognition, implement the **Bind**, **Init**, **Release**, and **Dispatch** functions. The **Bind** function provides service capabilities. The **Init** function initializes the driver before the driver is loaded. The **Release** function releases resources when the **Init** function fails.
...
@@ -99,7 +99,7 @@ int HdfMotionInterfaceDriverInit(struct HdfDeviceObject *deviceObject)
...
@@ -99,7 +99,7 @@ int HdfMotionInterfaceDriverInit(struct HdfDeviceObject *deviceObject)
returnHDF_SUCCESS;
returnHDF_SUCCESS;
}
}
// Bind the services provided by the motion recognition driver to the HDF.
// Bind the services provided by the motion driver to the HDF.
HUAWEI DevEco Studio For OpenHarmony(以下简称DevEco Studio)是基于IntelliJ IDEA Community开源版本打造,面向OpenHarmony全场景多设备的一站式集成开发环境(IDE),为开发者提供工程模板创建、开发、编译、调试、发布等E2E的OpenHarmony应用/服务开发。
HUAWEI DevEco Studio For OpenHarmony(以下简称DevEco Studio)是基于IntelliJ IDEA Community开源版本打造,面向OpenHarmony全场景多设备的一站式集成开发环境(IDE),为开发者提供工程模板创建、开发、编译、调试、发布等E2E的OpenHarmony应用/服务开发。
[DevEco Studio 3.0 Beta3](https://developer.harmonyos.com/cn/develop/deveco-studio#download_beta_openharmony) 作为支撑OpenHarmony应用和服务开发的IDE,具有以下能力特点:
更多工具体验和使用指导请见:[DevEco Studio (OpenHarmony) 使用指南](https://developer.harmonyos.com/cn/docs/documentation/doc-guides/ohos-deveco-studio-overview-0000001263280421)。
更多工具体验和使用指导请见:[DevEco Studio (OpenHarmony) 使用指南](https://developer.harmonyos.com/cn/docs/documentation/doc-guides/ohos-deveco-studio-overview-0000001263280421)。