• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2025 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
16/* *
17 * @addtogroup HdiSerial
18 *
19 *
20 * @brief Provides unified APIs for serial services to access serial drivers.
21 *
22 * A serial service can obtain a serial driver object or agent and then call APIs provided by this object or agent to
23 * access different types of serial devices based on the serial IDs, thereby obtaining serial information,
24 * subscribing to or unsubscribing from serial data, enabling or disabling a serial,
25 * setting the serial data reporting mode, and setting serial options such as the accuracy and measurement range.
26 *
27 * @since 5.1
28 */
29
30/* *
31 * @file ISerialInterface.idl
32 *
33 * @brief Declares the APIs provided by the serial module for obtaining serial information, subscribing to or
34 * unsubscribing from serial data, enabling or disabling a serial, setting the serial data reporting mode,
35 * and setting serial options such as the accuracy and measurement range.
36 *
37 * @since 5.1
38 * @version 1.0
39 */
40
41package ohos.hdi.usb.serial.v1_0;
42import ohos.hdi.usb.serial.v1_0.SerialTypes;
43
44/* *
45 * @brief Defines the functions for performing basic operations on serial.
46 *
47 * The operations include obtaining serial port list information, opening and closing serial port,
48 * reading or writing serial port data, and setting or obtaining serial port properties.
49 */
50interface ISerialInterface {
51
52    /**
53     * @brief Open and configure the serial port.
54     *
55     * Initializes and opens a serial communication port and sets communication parameters such as baud rate and parity.
56     *
57     * @param portId Indicates the Serial port device portId.
58     *
59     * @return Returns 0 if the setting is successful; returns a negative number otherwise.
60     *
61     * @since 5.1
62     *
63     * @version 1.0
64     */
65    SerialOpen([in]int portId);
66
67    /**
68     * @brief Close the serial port and release resources.
69     *
70     * Terminate the connection to the serial port, ensuring that the port and associated resources are released
71     * after all data transfers are complete.
72     *
73     * @param portId Indicates the Serial port device portId.
74     *
75     * @return Returns 0 if the setting is successful; returns a negative number otherwise.
76     *
77     * @since 5.1
78     *
79     * @version 1.0
80     */
81    SerialClose([in]int portId);
82
83    /**
84     * @brief Read data from the serial port.
85     *
86     * @param portId Indicates the Serial port device portId
87     * @param data Indicates the pointer to the buffer for receiving the data.
88     *
89     * @return Returns the size of the data that is successfully read; returns a negative number if the reading fails.
90     *
91     * @since 5.1
92     *
93     * @version 1.0
94     */
95    SerialRead([in] int portId, [out] unsigned char []data, [in] unsigned int size, [in] unsigned int timeout);
96
97    /**
98     * @brief Read data from the serial port.
99     *
100     * @param portId Indicates the Serial port device portId
101     * @param data Indicates the pointer to the data to write.
102     *
103     * @return Returns the size of the data that is successfully write;  returns a negative number if the reading fails.
104     *
105     * @since 5.1
106     *
107     * @version 1.0
108     */
109    SerialWrite([in] int portId, [in] unsigned char []data, [in] unsigned int size, [in] unsigned int timeout);
110
111    /**
112     * @brief Sets the SERIAL attribute.
113     *
114     * SERIAL attributes include data bits, stop bits, parity bit, CTS, RTS, and receiving and transmitting FIFO.
115     *
116     * @param portId Indicates the Serial port device portId
117     * @param attribute Indicates the pointer to the SERIAL attribute to set.
118     *
119     * @return Returns 0 if the setting is successful; returns a negative number otherwise.
120     *
121     * @since 5.1
122     *
123     * @version 1.0
124    */
125    SerialSetAttribute([in] int portId, [in] struct SerialAttribute attribute);
126
127    /**
128     * @brief Obtains the SERIAL attribute.
129     *
130     * SERIAL attributes include data bits, stop bits, parity bit, CTS, RTS, and receiving and transmitting FIFO.
131     *
132     * @param portId Indicates the Serial port device portId
133     * @param attribute Indicates the pointer to the obtained SERIAL attribute.
134     *
135     * @return Returns 0 if the setting is successful; returns a negative number otherwise.
136     *
137     * @since 5.1
138     *
139     * @version 1.0
140     */
141    SerialGetAttribute([in] int portId, [out] struct SerialAttribute attribute);
142
143    /**
144     * @brief Obtains the SERIAL Port list.
145     *
146     * @param portId Indicates the Serial port device portId
147     *
148     * @return Returns 0 if the setting is successful; returns a negative number otherwise.
149     *
150     * @since 5.1
151     *
152     * @version 1.0
153     */
154    SerialGetPortList([out] struct SerialPort[] portList);
155}
156
157
158