• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16import tag from '../@ohos.nfc.tag';
17import { AsyncCallback } from '../@ohos.base';
18
19/**
20 * Controls tag read and write.
21 * <p>Classes for different types of tags inherit from this abstract class to control connections to
22 * tags, read data from tags, and write data to tags.
23 *
24 * @typedef TagSession
25 * @syscap SystemCapability.Communication.NFC.Tag
26 * @since 7
27 */
28export interface TagSession {
29  /**
30   * Obtains the tag information.
31   *
32   * @permission ohos.permission.NFC_TAG
33   * @returns { tag.TagInfo } Returns the tag information, which is a {@link TagInfo} object.
34   * @syscap SystemCapability.Communication.NFC.Tag
35   * @since 7
36   * @deprecated since 9
37   * @useinstead ohos.nfc.tag/tag#getTagInfo
38   */
39  getTagInfo(): tag.TagInfo;
40
41  /**
42   * Connects to a tag.
43   * <p>This method must be called before data is read from or written to the tag.
44   *
45   * @permission ohos.permission.NFC_TAG
46   * @returns { boolean } Returns {@code true} if the connection is set up; returns {@code false} otherwise.
47   * @syscap SystemCapability.Communication.NFC.Tag
48   * @since 7
49   * @deprecated since 9
50   * @useinstead tagSession.TagSession#connect
51   */
52  connectTag(): boolean;
53
54  /**
55   * Connects to a tag. Must be called before data is read from or written to the tag.
56   *
57   * @permission ohos.permission.NFC_TAG
58   * @throws { BusinessError } 201 - Permission denied.
59   * @throws { BusinessError } 801 - Capability not supported.
60   * @throws { BusinessError } 3100201 - Tag running state is abnormal in service.
61   * @syscap SystemCapability.Communication.NFC.Tag
62   * @since 9
63   */
64  connect(): void;
65
66  /**
67   * Resets a connection with a tag and restores the default timeout duration for writing data to the tag.
68   *
69   * @permission ohos.permission.NFC_TAG
70   * @syscap SystemCapability.Communication.NFC.Tag
71   * @since 7
72   * @deprecated since 9
73   * @useinstead tagSession.TagSession#resetConnection
74   */
75  reset(): void;
76
77  /**
78   * Resets a connection with a tag and restores the default timeout duration for writing data to the tag.
79   *
80   * @permission ohos.permission.NFC_TAG
81   * @throws { BusinessError } 201 - Permission denied.
82   * @throws { BusinessError } 801 - Capability not supported.
83   * @throws { BusinessError } 3100201 - Tag running state is abnormal in service.
84   * @syscap SystemCapability.Communication.NFC.Tag
85   * @since 9
86   */
87  resetConnection(): void;
88
89  /**
90   * Checks whether a connection has been set up with a tag.
91   *
92   * @returns { boolean } Returns {@code true} if a connection has been set up with the tag;
93   * returns {@code false} otherwise.
94   * @syscap SystemCapability.Communication.NFC.Tag
95   * @since 7
96   * @deprecated since 9
97   * @useinstead tagSession.TagSession#isConnected
98   */
99  isTagConnected(): boolean;
100
101  /**
102   * Checks whether a connection has been set up with a tag.
103   *
104   * @returns { boolean } Returns true if tag connected, otherwise false.
105   * @throws { BusinessError } 801 - Capability not supported.
106   * @syscap SystemCapability.Communication.NFC.Tag
107   * @since 9
108   */
109  isConnected(): boolean;
110
111  /**
112   * Sets the timeout duration (ms) for sending data to a tag.
113   * <p>If data is not sent to the tag within the duration, data sending fails.
114   *
115   * @permission ohos.permission.NFC_TAG
116   * @param { number } timeout Indicates the timeout duration to be set.
117   * @returns { boolean } Returns {@code true} if the setting is successful; returns {@code false} otherwise.
118   * @syscap SystemCapability.Communication.NFC.Tag
119   * @since 7
120   * @deprecated since 9
121   * @useinstead tagSession.TagSession#setTimeout
122   */
123  setSendDataTimeout(timeout: number): boolean;
124
125  /**
126   * Sets the timeout duration (ms) for sending data to a tag.
127   *
128   * @permission ohos.permission.NFC_TAG
129   * @param { number } timeout Indicates the timeout duration to be set.
130   * @throws { BusinessError } 201 - Permission denied.
131   * @throws { BusinessError } 401 - The parameter check failed.
132   * @throws { BusinessError } 801 - Capability not supported.
133   * @throws { BusinessError } 3100201 - Tag running state is abnormal in service.
134   * @syscap SystemCapability.Communication.NFC.Tag
135   * @since 9
136   */
137  setTimeout(timeout: number): void;
138
139  /**
140   * Queries the timeout duration (ms) for sending data to a tag.
141   *
142   * @permission ohos.permission.NFC_TAG
143   * @returns { number } Returns the timeout duration.
144   * @syscap SystemCapability.Communication.NFC.Tag
145   * @since 7
146   * @deprecated since 9
147   * @useinstead tagSession.TagSession#getTimeout
148   */
149  getSendDataTimeout(): number;
150
151  /**
152   * Obtains the timeout duration (ms) for sending data to a tag.
153   *
154   * @permission ohos.permission.NFC_TAG
155   * @returns { number } Returns the timeout duration.
156   * @throws { BusinessError } 201 - Permission denied.
157   * @throws { BusinessError } 801 - Capability not supported.
158   * @throws { BusinessError } 3100201 - Tag running state is abnormal in service.
159   * @syscap SystemCapability.Communication.NFC.Tag
160   * @since 9
161   */
162  getTimeout(): number;
163
164  /**
165   * Writes data to a tag.
166   *
167   * @permission ohos.permission.NFC_TAG
168   * @param { number[] } data Indicates the data to be written to the tag.
169   * @returns { Promise<number[]> } Returns bytes received in response. Or bytes with a length of 0 if the
170   * data fails to be written to the tag.
171   * @syscap SystemCapability.Communication.NFC.Tag
172   * @since 7
173   * @deprecated since 9
174   * @useinstead tagSession.TagSession#transmit
175   */
176  sendData(data: number[]): Promise<number[]>;
177
178  /**
179   * Writes data to a tag.
180   *
181   * @permission ohos.permission.NFC_TAG
182   * @param { number[] } data Indicates the data to be written to the tag.
183   * @param { AsyncCallback<number[]> } callback The callback.
184   * data fails to be written to the tag.
185   * @syscap SystemCapability.Communication.NFC.Tag
186   * @since 7
187   * @deprecated since 9
188   * @useinstead tagSession.TagSession#transmit
189   */
190  sendData(data: number[], callback: AsyncCallback<number[]>): void;
191
192  /**
193   * Writes data to a tag.
194   *
195   * @permission ohos.permission.NFC_TAG
196   * @param { number[] } data Indicates the data to be written to the tag.
197   * @returns { Promise<number[]> } Returns bytes received in response. Or bytes with a length of 0 if the
198   * data fails to be written to the tag.
199   * @throws { BusinessError } 201 - Permission denied.
200   * @throws { BusinessError } 401 - The parameter check failed.
201   * @throws { BusinessError } 801 - Capability not supported.
202   * @throws { BusinessError } 3100201 - Tag running state is abnormal in service.
203   * @syscap SystemCapability.Communication.NFC.Tag
204   * @since 9
205   */
206  transmit(data: number[]): Promise<number[]>;
207
208  /**
209   * Writes data to a tag.
210   *
211   * @permission ohos.permission.NFC_TAG
212   * @param { number[] } data Indicates the data to be written to the tag.
213   * @param { AsyncCallback<number[]> } callback The callback.
214   * @throws { BusinessError } 201 - Permission denied.
215   * @throws { BusinessError } 401 - The parameter check failed.
216   * @throws { BusinessError } 801 - Capability not supported.
217   * @throws { BusinessError } 3100201 - Tag running state is abnormal in service.
218   * @syscap SystemCapability.Communication.NFC.Tag
219   * @since 9
220   */
221  transmit(data: number[], callback: AsyncCallback<number[]>): void;
222
223  /**
224   * Queries the maximum length of data that can be sent to a tag.
225   *
226   * @permission ohos.permission.NFC_TAG
227   * @returns { number } Returns the maximum length of the data to be sent to the tag.
228   * @syscap SystemCapability.Communication.NFC.Tag
229   * @since 7
230   * @deprecated since 9
231   * @useinstead tagSession.TagSession#getMaxTransmitSize
232   */
233  getMaxSendLength(): number;
234
235  /**
236   * Obtains the maximum length of data that can be sent to a tag.
237   *
238   * @permission ohos.permission.NFC_TAG
239   * @returns { number } Returns the maximum length of the data to be sent to the tag.
240   * @throws { BusinessError } 201 - Permission denied.
241   * @throws { BusinessError } 801 - Capability not supported.
242   * @throws { BusinessError } 3100201 - Tag running state is abnormal in service.
243   * @syscap SystemCapability.Communication.NFC.Tag
244   * @since 9
245   */
246  getMaxTransmitSize(): number;
247}
248