• 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 */
15import tag from '../@ohos.nfc.tag';
16import { AsyncCallback } from '../basic';
17
18/**
19 * Controls tag read and write.
20 *
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 * @since 7
25 * @syscap SystemCapability.Communication.NFC.Tag
26 */
27export interface TagSession {
28  /**
29   * Obtains the tag information.
30   *
31   * @returns Returns the tag information, which is a {@link TagInfo} object.
32   * @permission ohos.permission.NFC_TAG
33   * @since 7
34   * @deprecated since 9
35   * @useinstead ohos.nfc.tag/tag#getTagInfo
36   */
37  getTagInfo(): tag.TagInfo;
38
39  /**
40   * Connects to a tag.
41   *
42   * <p>This method must be called before data is read from or written to the tag.
43   *
44   * @returns Returns {@code true} if the connection is set up; returns {@code false} otherwise.
45   * @permission ohos.permission.NFC_TAG
46   * @since 7
47   * @deprecated since 9
48   * @useinstead tagSession.TagSession#connect
49   */
50  connectTag(): boolean;
51
52  /**
53   * Connects to a tag. Must be called before data is read from or written to the tag.
54   *
55   * @throws { BusinessError } 201 - Permission denied.
56   * @throws { BusinessError } 801 - Capability not supported.
57   * @throws { BusinessError } 3100201 - Tag running state is abnormal in service.
58   * @permission ohos.permission.NFC_TAG
59   * @since 9
60   */
61  connect(): void;
62
63  /**
64   * Resets a connection with a tag and restores the default timeout duration for writing data to the tag.
65   *
66   * @permission ohos.permission.NFC_TAG
67   * @since 7
68   * @deprecated since 9
69   * @useinstead tagSession.TagSession#resetConnection
70   */
71  reset(): void;
72
73  /**
74   * Resets a connection with a tag and restores the default timeout duration for writing data to the tag.
75   *
76   * @throws { BusinessError } 201 - Permission denied.
77   * @throws { BusinessError } 801 - Capability not supported.
78   * @throws { BusinessError } 3100201 - Tag running state is abnormal in service.
79   * @permission ohos.permission.NFC_TAG
80   * @since 9
81   */
82  resetConnection(): void;
83
84  /**
85   * Checks whether a connection has been set up with a tag.
86   *
87   * @returns Returns {@code true} if a connection has been set up with the tag;
88   * returns {@code false} otherwise.
89   * @since 7
90   * @deprecated since 9
91   * @useinstead tagSession.TagSession#isConnected
92   */
93  isTagConnected(): boolean;
94
95  /**
96   * Checks whether a connection has been set up with a tag.
97   *
98   * @returns Returns true if tag connected, otherwise false.
99   * @throws { BusinessError } 801 - Capability not supported.
100   * @since 9
101   */
102   isConnected(): boolean;
103
104  /**
105   * Sets the timeout duration (ms) for sending data to a tag.
106   *
107   * <p>If data is not sent to the tag within the duration, data sending fails.
108   *
109   * @param timeout Indicates the timeout duration to be set.
110   * @returns Returns {@code true} if the setting is successful; returns {@code false} otherwise.
111   * @permission ohos.permission.NFC_TAG
112   * @since 7
113   * @deprecated since 9
114   * @useinstead tagSession.TagSession#setTimeout
115   */
116  setSendDataTimeout(timeout: number): boolean;
117
118  /**
119   * Sets the timeout duration (ms) for sending data to a tag.
120   *
121   * @param timeout Indicates the timeout duration to be set.
122   * @throws { BusinessError } 201 - Permission denied.
123   * @throws { BusinessError } 401 - The parameter check failed.
124   * @throws { BusinessError } 801 - Capability not supported.
125   * @throws { BusinessError } 3100201 - Tag running state is abnormal in service.
126   * @permission ohos.permission.NFC_TAG
127   * @since 9
128   */
129   setTimeout(timeout: number): void;
130
131  /**
132   * Queries the timeout duration (ms) for sending data to a tag.
133   *
134   * @returns Returns the timeout duration.
135   * @permission ohos.permission.NFC_TAG
136   * @since 7
137   * @deprecated since 9
138   * @useinstead tagSession.TagSession#getTimeout
139   */
140  getSendDataTimeout(): number;
141
142  /**
143   * Obtains the timeout duration (ms) for sending data to a tag.
144   *
145   * @returns Returns the timeout duration.
146   * @throws { BusinessError } 201 - Permission denied.
147   * @throws { BusinessError } 801 - Capability not supported.
148   * @throws { BusinessError } 3100201 - Tag running state is abnormal in service.
149   * @permission ohos.permission.NFC_TAG
150   * @since 9
151   */
152  getTimeout(): number;
153
154  /**
155   * Writes data to a tag.
156   *
157   * @param data Indicates the data to be written to the tag.
158   * @returns Returns bytes received in response. Or bytes with a length of 0 if the
159   * data fails to be written to the tag.
160   *
161   * @permission ohos.permission.NFC_TAG
162   * @since 7
163   * @deprecated since 9
164   * @useinstead tagSession.TagSession#transmit
165   */
166  sendData(data: number[]): Promise<number[]>;
167  sendData(data: number[], callback: AsyncCallback<number[]>): void;
168
169  /**
170   * Writes data to a tag.
171   *
172   * @param data Indicates the data to be written to the tag.
173   * @returns Returns bytes received in response. Or bytes with a length of 0 if the
174   * data fails to be written to the tag.
175   * @throws { BusinessError } 201 - Permission denied.
176   * @throws { BusinessError } 401 - The parameter check failed.
177   * @throws { BusinessError } 801 - Capability not supported.
178   * @throws { BusinessError } 3100201 - Tag running state is abnormal in service.
179   * @permission ohos.permission.NFC_TAG
180   * @since 9
181   */
182  transmit(data: number[]): Promise<number[]>;
183  transmit(data: number[], callback: AsyncCallback<number[]>): void;
184
185  /**
186   * Queries the maximum length of data that can be sent to a tag.
187   *
188   * @returns Returns the maximum length of the data to be sent to the tag.
189   *
190   * @permission ohos.permission.NFC_TAG
191   * @since 7
192   * @deprecated since 9
193   * @useinstead tagSession.TagSession#getMaxTransmitSize
194   */
195  getMaxSendLength(): number;
196
197  /**
198   * Obtains the maximum length of data that can be sent to a tag.
199   *
200   * @returns Returns the maximum length of the data to be sent to the tag.
201   * @throws { BusinessError } 201 - Permission denied.
202   * @throws { BusinessError } 801 - Capability not supported.
203   * @throws { BusinessError } 3100201 - Tag running state is abnormal in service.
204   * @permission ohos.permission.NFC_TAG
205   * @since 9
206   */
207   getMaxTransmitSize(): number;
208}
209