• 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 HdiUsbUsbSerialDdk
18 * @{
19 *
20 * @brief Provides USB SERIAL DDK types and declares the macros, enumerated variables, and\n
21 * data structures required by the USB SERIAL DDK APIs.
22 *
23 * @syscap SystemCapability.Driver.UsbSerial.Extension
24 * @since 5.1
25 * @version 1.0
26 */
27
28/**
29 * @file IUsbSerialDdk.idl
30 *
31 * @brief Declares the USB SERIAL DDK APIs used by the USB serial host to access USB serial devices.
32 *
33 * @since 5.1
34 * @version 1.0
35 */
36package ohos.hdi.usb.usb_serial_ddk.v1_0;
37
38import ohos.hdi.usb.usb_serial_ddk.v1_0.UsbSerialDdkTypes;
39
40/* *
41 * @brief Declares the USB DDK APIs used by the USB host to access USB devices.
42 */
43interface IUsbSerialDdk
44{
45
46    /* *
47     * @brief Initializes the USB serial DDK.
48     *
49     * @return <b>0</b> if the operation is successful; a negative value otherwise.
50     * @since 5.1
51     * @version 1.0
52     */
53    Init();
54
55    /* *
56     * @brief Releases the DDK.
57     *
58     * @return <b>0</b> if the operation is successful; a negative value otherwise.
59     * @since 5.1
60     * @version 1.0
61     */
62    Release();
63
64    /**
65    * @brief Open USB serial device by deviceId.
66    *
67    * @param deviceId ID of the device to be operated.
68    * @param interfaceIndex Interface index, which corresponds to interface which supports USB Protocol ACM.
69    * @param dev Device handle.
70    * @return <b>0</b> if the operation is successful; a negative value otherwise.
71    * @since 5.1
72    * @version 1.0
73    */
74    Open([in] unsigned long deviceId, [in] unsigned long interfaceIndex, [out] struct UsbSerialDeviceHandle dev);
75
76    /**
77    * @brief Close USB serial device.
78    *
79    * @param dev Device handle.
80    * @return <b>0</b> if the operation is successful; a negative value otherwise.
81    * @since 5.1
82    * @version 1.0
83    */
84    Close([in] struct UsbSerialDeviceHandle dev);
85
86    /**
87    * @brief Read bytesRead into buff from UsbSerial device.
88    *
89    * @param dev Device handle.
90    * @param bufferSize Max buff size.
91    * @param buff Received data from a serial device.
92    * @return <b>0</b> if the operation is successful; a negative value otherwise.
93    * @since 5.1
94    * @version 1.0
95    */
96    Read([in] struct UsbSerialDeviceHandle dev, [in] unsigned int bufferSize, [out] List<unsigned char> buff);
97
98    /**
99    * @brief Write bytesWritten from buff to UsbSerial device.
100    *
101    * @param dev Device handle.
102    * @param buff Serial information write to device.
103    * @param bytesWritten Actual bytes written.
104    * @return <b>0</b> if the operation is successful; a negative value otherwise.
105    * @since 5.1
106    * @version 1.0
107    */
108    Write([in] struct UsbSerialDeviceHandle dev, [in] List<unsigned char> buff, [out] unsigned int bytesWritten);
109
110    /**
111    * @brief Set the serial port baud rate.
112    *
113    * @param dev Device handle.
114    * @param baudRate Serial port baud rate set to connect device.
115    * @return <b>0</b> if the operation is successful; a negative value otherwise.
116    * @since 5.1
117    * @version 1.0
118    */
119    SetBaudRate([in] struct UsbSerialDeviceHandle dev,  [in] unsigned int baudRate);
120
121    /**
122    * @brief Set the serial port parameters.
123    *
124    * @param dev Device handle.
125    * @param params Serial port params set to connect device.
126    * @return <b>0</b> if the operation is successful; a negative value otherwise.
127    * @since 5.1
128    * @version 1.0
129    */
130    SetParams([in] struct UsbSerialDeviceHandle dev, [in] struct UsbSerialParams params);
131
132    /**
133    * @brief Sets the read timeout (in milliseconds)/blocking mode
134    *
135    * @param dev Device handle.
136    * @param timeout Set to -1 to infinite timeout, 0 to return immediately with any data (non
137                    blocking, or >0 to wait for data for a specified number of milliseconds). Timeout will
138                    be rounded to the nearest 100ms (a Linux API restriction). Maximum value limited to
139                    25500ms (another Linux API restriction).
140    * @return <b>0</b> if the operation is successful; a negative value otherwise.
141    * @since 5.1
142    * @version 1.0
143    */
144    SetTimeout([in] struct UsbSerialDeviceHandle dev, [in] int timeout);
145
146    /**
147    * @brief Sets FlowControl params.
148    *
149    * @param dev Device handle.
150    * @param flowControl flow control mode.
151    * @return <b>0</b> if the operation is successful; a negative value otherwise.
152    * @since 5.1
153    * @version 1.0
154    */
155    SetFlowControl([in] struct UsbSerialDeviceHandle dev, [in] enum UsbSerialFlowControl flowControl);
156
157    /**
158    * @brief flush buffers after write.
159    *
160    * @param dev Device handle.
161    * @return <b>0</b> if the operation is successful; a negative value otherwise.
162    * @since 5.1
163    * @version 1.0
164    */
165    Flush([in] struct UsbSerialDeviceHandle dev);
166
167    /**
168    * @brief flush read buffers.
169    *
170    * @param dev Device handle.
171    * @return <b>0</b> if the operation is successful; a negative value otherwise.
172    * @since 5.1
173    * @version 1.0
174    */
175    FlushInput([in] struct UsbSerialDeviceHandle dev);
176
177    /**
178    * @brief flush write buffers.
179    *
180    * @param dev Device handle.
181    * @return <b>0</b> if the operation is successful; a negative value otherwise.
182    * @since 5.1
183    * @version 1.0
184    */
185    FlushOutput([in] struct UsbSerialDeviceHandle dev);
186}
187