]>
Commit | Line | Data |
---|---|---|
74510d4b ML |
1 | /* |
2 | * This file is part of the libserialport project. | |
3 | * | |
4 | * Copyright (C) 2013 Martin Ling <martin-libserialport@earth.li> | |
5 | * | |
6 | * This program is free software: you can redistribute it and/or modify | |
7 | * it under the terms of the GNU Lesser General Public License as | |
8 | * published by the Free Software Foundation, either version 3 of the | |
9 | * License, or (at your option) any later version. | |
10 | * | |
11 | * This program is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | * GNU General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU Lesser General Public License | |
17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
18 | */ | |
19 | ||
cd5f5281 | 20 | /** |
cf9d365c UH |
21 | * @mainpage libserialport API |
22 | * | |
23 | * Introduction | |
24 | * ============ | |
25 | * | |
26 | * libserialport is a minimal library written in C that is intended to take | |
27 | * care of the OS-specific details when writing software that uses serial ports. | |
28 | * | |
29 | * By writing your serial code to use libserialport, you enable it to work | |
30 | * transparently on any platform supported by the library. | |
31 | * | |
32 | * The operations that are supported are: | |
33 | * | |
34 | * - @ref Enumeration (obtaining a list of serial ports on the system) | |
35 | * - @ref Ports | |
36 | * - @ref Configuration (baud rate, parity, etc.) | |
0151b157 | 37 | * - @ref Signals (modem control lines, breaks, etc.) |
cf9d365c | 38 | * - @ref Data |
6f1186aa | 39 | * - @ref Waiting |
cf9d365c UH |
40 | * - @ref Errors |
41 | * | |
42 | * libserialport is an open source project released under the LGPL3+ license. | |
43 | * | |
44 | * API principles | |
45 | * ============== | |
46 | * | |
47 | * The API is simple, and designed to be a minimal wrapper around the serial | |
48 | * port support in each OS. | |
49 | * | |
50 | * Most functions take a pointer to a struct sp_port, which represents a serial | |
51 | * port. These structures are always allocated and freed by the library, using | |
52 | * the functions in the @ref Enumeration "Enumeration" section. | |
53 | * | |
0151b157 ML |
54 | * Most functions have return type @ref sp_return and can return only four |
55 | * possible error values: | |
cf9d365c | 56 | * |
6aabf62a ML |
57 | * - @ref SP_ERR_ARG means that a function was called with invalid |
58 | * arguments. This implies a bug in the caller. The arguments passed would | |
59 | * be invalid regardless of the underlying OS or serial device involved. | |
60 | * | |
61 | * - @ref SP_ERR_FAIL means that the OS reported a failure. The error code or | |
62 | * message provided by the OS can be obtained by calling sp_last_error_code() | |
63 | * or sp_last_error_message(). | |
64 | * | |
65 | * - @ref SP_ERR_SUPP indicates that there is no support for the requested | |
66 | * operation in the current OS, driver or device. No error message is | |
67 | * available from the OS in this case. There is either no way to request | |
68 | * the operation in the first place, or libserialport does not know how to | |
69 | * do so in the current version. | |
70 | * | |
71 | * - @ref SP_ERR_MEM indicates that a memory allocation failed. | |
72 | * | |
73 | * All of these error values are negative. | |
cf9d365c | 74 | * |
0151b157 ML |
75 | * Calls that succeed return @ref SP_OK, which is equal to zero. Some functions |
76 | * declared @ref sp_return can also return a positive value for a successful | |
0a1ab8bf | 77 | * numeric result, e.g. sp_blocking_read() or sp_blocking_write(). |
cf9d365c | 78 | */ |
cd5f5281 | 79 | |
8645feda UH |
80 | #ifndef LIBSERIALPORT_LIBSERIALPORT_H |
81 | #define LIBSERIALPORT_LIBSERIALPORT_H | |
e8ffaee9 | 82 | |
5ef8a1ed UH |
83 | #ifdef __cplusplus |
84 | extern "C" { | |
85 | #endif | |
86 | ||
74510d4b | 87 | #include <stddef.h> |
74510d4b | 88 | |
cd5f5281 | 89 | /** Return values. */ |
eb6ed20f | 90 | enum sp_return { |
cd5f5281 | 91 | /** Operation completed successfully. */ |
74510d4b | 92 | SP_OK = 0, |
cd5f5281 | 93 | /** Invalid arguments were passed to the function. */ |
e9a2f9c9 | 94 | SP_ERR_ARG = -1, |
cfa5af67 | 95 | /** A system error occurred while executing the operation. */ |
e9a2f9c9 | 96 | SP_ERR_FAIL = -2, |
cd5f5281 | 97 | /** A memory allocation failed while executing the operation. */ |
f92f1f0c | 98 | SP_ERR_MEM = -3, |
6aabf62a | 99 | /** The requested operation is not supported by this system or device. */ |
79a80046 | 100 | SP_ERR_SUPP = -4 |
74510d4b ML |
101 | }; |
102 | ||
cd5f5281 | 103 | /** Port access modes. */ |
eb6ed20f | 104 | enum sp_mode { |
a036341b ML |
105 | /** Open port for read access. */ |
106 | SP_MODE_READ = 1, | |
107 | /** Open port for write access. */ | |
276ef1b9 | 108 | SP_MODE_WRITE = 2, |
13efecf8 | 109 | /** Open port for read and write access. @since 0.1.1 */ |
276ef1b9 | 110 | SP_MODE_READ_WRITE = 3 |
74510d4b ML |
111 | }; |
112 | ||
6f1186aa ML |
113 | /** Port events. */ |
114 | enum sp_event { | |
144a598f | 115 | /** Data received and ready to read. */ |
6f1186aa | 116 | SP_EVENT_RX_READY = 1, |
144a598f | 117 | /** Ready to transmit new data. */ |
6f1186aa | 118 | SP_EVENT_TX_READY = 2, |
144a598f | 119 | /** Error occurred. */ |
79a80046 | 120 | SP_EVENT_ERROR = 4 |
6f1186aa ML |
121 | }; |
122 | ||
fd8fd11a ML |
123 | /** Buffer selection. */ |
124 | enum sp_buffer { | |
125 | /** Input buffer. */ | |
126 | SP_BUF_INPUT = 1, | |
127 | /** Output buffer. */ | |
128 | SP_BUF_OUTPUT = 2, | |
129 | /** Both buffers. */ | |
79a80046 | 130 | SP_BUF_BOTH = 3 |
fd8fd11a ML |
131 | }; |
132 | ||
cd5f5281 | 133 | /** Parity settings. */ |
eb6ed20f | 134 | enum sp_parity { |
c200f5c1 | 135 | /** Special value to indicate setting should be left alone. */ |
eb6ed20f | 136 | SP_PARITY_INVALID = -1, |
cd5f5281 | 137 | /** No parity. */ |
74510d4b | 138 | SP_PARITY_NONE = 0, |
cd5f5281 | 139 | /** Odd parity. */ |
20e63a77 ML |
140 | SP_PARITY_ODD = 1, |
141 | /** Even parity. */ | |
142 | SP_PARITY_EVEN = 2, | |
e432ce60 ML |
143 | /** Mark parity. */ |
144 | SP_PARITY_MARK = 3, | |
145 | /** Space parity. */ | |
79a80046 | 146 | SP_PARITY_SPACE = 4 |
74510d4b ML |
147 | }; |
148 | ||
cd5f5281 | 149 | /** RTS pin behaviour. */ |
eb6ed20f | 150 | enum sp_rts { |
c200f5c1 | 151 | /** Special value to indicate setting should be left alone. */ |
eb6ed20f | 152 | SP_RTS_INVALID = -1, |
cd5f5281 | 153 | /** RTS off. */ |
d514a26f | 154 | SP_RTS_OFF = 0, |
cd5f5281 | 155 | /** RTS on. */ |
d514a26f | 156 | SP_RTS_ON = 1, |
cd5f5281 | 157 | /** RTS used for flow control. */ |
79a80046 | 158 | SP_RTS_FLOW_CONTROL = 2 |
d514a26f ML |
159 | }; |
160 | ||
cd5f5281 | 161 | /** CTS pin behaviour. */ |
eb6ed20f | 162 | enum sp_cts { |
c200f5c1 | 163 | /** Special value to indicate setting should be left alone. */ |
eb6ed20f | 164 | SP_CTS_INVALID = -1, |
cd5f5281 | 165 | /** CTS ignored. */ |
d514a26f | 166 | SP_CTS_IGNORE = 0, |
cd5f5281 | 167 | /** CTS used for flow control. */ |
79a80046 | 168 | SP_CTS_FLOW_CONTROL = 1 |
d514a26f ML |
169 | }; |
170 | ||
cd5f5281 | 171 | /** DTR pin behaviour. */ |
eb6ed20f | 172 | enum sp_dtr { |
c200f5c1 | 173 | /** Special value to indicate setting should be left alone. */ |
eb6ed20f | 174 | SP_DTR_INVALID = -1, |
cd5f5281 | 175 | /** DTR off. */ |
d514a26f | 176 | SP_DTR_OFF = 0, |
cd5f5281 | 177 | /** DTR on. */ |
d514a26f | 178 | SP_DTR_ON = 1, |
cd5f5281 | 179 | /** DTR used for flow control. */ |
79a80046 | 180 | SP_DTR_FLOW_CONTROL = 2 |
d514a26f ML |
181 | }; |
182 | ||
cd5f5281 | 183 | /** DSR pin behaviour. */ |
eb6ed20f | 184 | enum sp_dsr { |
c200f5c1 | 185 | /** Special value to indicate setting should be left alone. */ |
eb6ed20f | 186 | SP_DSR_INVALID = -1, |
cd5f5281 | 187 | /** DSR ignored. */ |
d514a26f | 188 | SP_DSR_IGNORE = 0, |
cd5f5281 | 189 | /** DSR used for flow control. */ |
79a80046 | 190 | SP_DSR_FLOW_CONTROL = 1 |
d514a26f ML |
191 | }; |
192 | ||
cd5f5281 | 193 | /** XON/XOFF flow control behaviour. */ |
eb6ed20f | 194 | enum sp_xonxoff { |
c200f5c1 | 195 | /** Special value to indicate setting should be left alone. */ |
eb6ed20f | 196 | SP_XONXOFF_INVALID = -1, |
cd5f5281 | 197 | /** XON/XOFF disabled. */ |
d514a26f | 198 | SP_XONXOFF_DISABLED = 0, |
cd5f5281 | 199 | /** XON/XOFF enabled for input only. */ |
d514a26f | 200 | SP_XONXOFF_IN = 1, |
cd5f5281 | 201 | /** XON/XOFF enabled for output only. */ |
d514a26f | 202 | SP_XONXOFF_OUT = 2, |
cd5f5281 | 203 | /** XON/XOFF enabled for input and output. */ |
79a80046 | 204 | SP_XONXOFF_INOUT = 3 |
ac74fdaf ML |
205 | }; |
206 | ||
cd5f5281 | 207 | /** Standard flow control combinations. */ |
eb6ed20f | 208 | enum sp_flowcontrol { |
cd5f5281 | 209 | /** No flow control. */ |
18fc2dd1 | 210 | SP_FLOWCONTROL_NONE = 0, |
cd5f5281 | 211 | /** Software flow control using XON/XOFF characters. */ |
18fc2dd1 | 212 | SP_FLOWCONTROL_XONXOFF = 1, |
cd5f5281 | 213 | /** Hardware flow control using RTS/CTS signals. */ |
18fc2dd1 | 214 | SP_FLOWCONTROL_RTSCTS = 2, |
cd5f5281 | 215 | /** Hardware flow control using DTR/DSR signals. */ |
79a80046 | 216 | SP_FLOWCONTROL_DTRDSR = 3 |
18fc2dd1 ML |
217 | }; |
218 | ||
8cf7c697 ML |
219 | /** Input signals. */ |
220 | enum sp_signal { | |
221 | /** Clear to send. */ | |
222 | SP_SIG_CTS = 1, | |
223 | /** Data set ready. */ | |
224 | SP_SIG_DSR = 2, | |
225 | /** Data carrier detect. */ | |
226 | SP_SIG_DCD = 4, | |
227 | /** Ring indicator. */ | |
79a80046 | 228 | SP_SIG_RI = 8 |
8cf7c697 ML |
229 | }; |
230 | ||
13efecf8 UH |
231 | /** |
232 | * Transport types. | |
233 | * | |
234 | * @since 0.1.1 | |
235 | */ | |
a93fb468 | 236 | enum sp_transport { |
13efecf8 | 237 | /** Native platform serial port. @since 0.1.1 */ |
a93fb468 | 238 | SP_TRANSPORT_NATIVE, |
13efecf8 | 239 | /** USB serial port adapter. @since 0.1.1 */ |
a93fb468 | 240 | SP_TRANSPORT_USB, |
13efecf8 | 241 | /** Bluetooth serial port adapter. @since 0.1.1 */ |
79a80046 | 242 | SP_TRANSPORT_BLUETOOTH |
a93fb468 AJ |
243 | }; |
244 | ||
0a1ab8bf UH |
245 | /** |
246 | * @struct sp_port | |
247 | * An opaque structure representing a serial port. | |
248 | */ | |
1c5aae9d | 249 | struct sp_port; |
eb6ed20f | 250 | |
0a1ab8bf UH |
251 | /** |
252 | * @struct sp_port_config | |
253 | * An opaque structure representing the configuration for a serial port. | |
254 | */ | |
9b1502ef | 255 | struct sp_port_config; |
eb6ed20f | 256 | |
6f1186aa ML |
257 | /** |
258 | * @struct sp_event_set | |
259 | * A set of handles to wait on for events. | |
260 | */ | |
261 | struct sp_event_set { | |
262 | /** Array of OS-specific handles. */ | |
263 | void *handles; | |
264 | /** Array of bitmasks indicating which events apply for each handle. */ | |
265 | enum sp_event *masks; | |
266 | /** Number of handles. */ | |
267 | unsigned int count; | |
268 | }; | |
269 | ||
091e75fe | 270 | /** |
144a598f UH |
271 | * @defgroup Enumeration Port enumeration |
272 | * | |
273 | * Enumerating the serial ports of a system. | |
274 | * | |
275 | * @{ | |
276 | */ | |
091e75fe | 277 | |
cd5f5281 | 278 | /** |
cf9d365c UH |
279 | * Obtain a pointer to a new sp_port structure representing the named port. |
280 | * | |
281 | * The user should allocate a variable of type "struct sp_port *" and pass a | |
282 | * pointer to this to receive the result. | |
283 | * | |
284 | * The result should be freed after use by calling sp_free_port(). | |
285 | * | |
35578b06 UH |
286 | * @param[in] portname The OS-specific name of a serial port. Must not be NULL. |
287 | * @param[out] port_ptr If any error is returned, the variable pointed to by | |
288 | * port_ptr will be set to NULL. Otherwise, it will be set | |
289 | * to point to the newly allocated port. Must not be NULL. | |
f36c6395 ML |
290 | * |
291 | * @return SP_OK upon success, a negative error code otherwise. | |
1652aa86 UH |
292 | * |
293 | * @since 0.1.0 | |
cf9d365c | 294 | */ |
eb6ed20f | 295 | enum sp_return sp_get_port_by_name(const char *portname, struct sp_port **port_ptr); |
cd5f5281 ML |
296 | |
297 | /** | |
cf9d365c | 298 | * Free a port structure obtained from sp_get_port_by_name() or sp_copy_port(). |
1652aa86 | 299 | * |
35578b06 UH |
300 | * @param[in] port Pointer to a port structure. Must not be NULL. |
301 | * | |
1652aa86 | 302 | * @since 0.1.0 |
cf9d365c | 303 | */ |
e3b2f7a4 | 304 | void sp_free_port(struct sp_port *port); |
cd5f5281 ML |
305 | |
306 | /** | |
cf9d365c UH |
307 | * List the serial ports available on the system. |
308 | * | |
309 | * The result obtained is an array of pointers to sp_port structures, | |
310 | * terminated by a NULL. The user should allocate a variable of type | |
311 | * "struct sp_port **" and pass a pointer to this to receive the result. | |
312 | * | |
313 | * The result should be freed after use by calling sp_free_port_list(). | |
314 | * If a port from the list is to be used after freeing the list, it must be | |
315 | * copied first using sp_copy_port(). | |
316 | * | |
35578b06 UH |
317 | * @param[out] list_ptr If any error is returned, the variable pointed to by |
318 | * list_ptr will be set to NULL. Otherwise, it will be set | |
319 | * to point to the newly allocated array. Must not be NULL. | |
f36c6395 ML |
320 | * |
321 | * @return SP_OK upon success, a negative error code otherwise. | |
1652aa86 UH |
322 | * |
323 | * @since 0.1.0 | |
cf9d365c | 324 | */ |
eb6ed20f | 325 | enum sp_return sp_list_ports(struct sp_port ***list_ptr); |
cd5f5281 ML |
326 | |
327 | /** | |
35578b06 | 328 | * Make a new copy of an sp_port structure. |
cf9d365c UH |
329 | * |
330 | * The user should allocate a variable of type "struct sp_port *" and pass a | |
331 | * pointer to this to receive the result. | |
332 | * | |
333 | * The copy should be freed after use by calling sp_free_port(). | |
334 | * | |
35578b06 UH |
335 | * @param[in] port Pointer to a port structure. Must not be NULL. |
336 | * @param[out] copy_ptr If any error is returned, the variable pointed to by | |
337 | * copy_ptr will be set to NULL. Otherwise, it will be set | |
338 | * to point to the newly allocated copy. Must not be NULL. | |
f36c6395 ML |
339 | * |
340 | * @return SP_OK upon success, a negative error code otherwise. | |
1652aa86 UH |
341 | * |
342 | * @since 0.1.0 | |
cf9d365c | 343 | */ |
eb6ed20f | 344 | enum sp_return sp_copy_port(const struct sp_port *port, struct sp_port **copy_ptr); |
cd5f5281 ML |
345 | |
346 | /** | |
cf9d365c UH |
347 | * Free a port list obtained from sp_list_ports(). |
348 | * | |
349 | * This will also free all the sp_port structures referred to from the list; | |
350 | * any that are to be retained must be copied first using sp_copy_port(). | |
1652aa86 | 351 | * |
35578b06 UH |
352 | * @param[in] ports Pointer to a list of port structures. Must not be NULL. |
353 | * | |
1652aa86 | 354 | * @since 0.1.0 |
cf9d365c | 355 | */ |
d54e9004 | 356 | void sp_free_port_list(struct sp_port **ports); |
e96d8bd2 | 357 | |
091e75fe | 358 | /** |
cf9d365c | 359 | * @} |
144a598f UH |
360 | * @defgroup Ports Port handling |
361 | * | |
362 | * Opening, closing and querying ports. | |
363 | * | |
cf9d365c UH |
364 | * @{ |
365 | */ | |
091e75fe | 366 | |
cd5f5281 | 367 | /** |
cf9d365c UH |
368 | * Open the specified serial port. |
369 | * | |
35578b06 UH |
370 | * @param[in] port Pointer to a port structure. Must not be NULL. |
371 | * @param[in] flags Flags to use when opening the serial port. | |
cf9d365c | 372 | * |
f36c6395 | 373 | * @return SP_OK upon success, a negative error code otherwise. |
1652aa86 UH |
374 | * |
375 | * @since 0.1.0 | |
cf9d365c | 376 | */ |
eb6ed20f | 377 | enum sp_return sp_open(struct sp_port *port, enum sp_mode flags); |
cd5f5281 ML |
378 | |
379 | /** | |
cf9d365c UH |
380 | * Close the specified serial port. |
381 | * | |
35578b06 UH |
382 | * @param[in] port Pointer to a port structure. Must not be NULL. |
383 | * | |
f36c6395 | 384 | * @return SP_OK upon success, a negative error code otherwise. |
1652aa86 UH |
385 | * |
386 | * @since 0.1.0 | |
cf9d365c | 387 | */ |
eb6ed20f | 388 | enum sp_return sp_close(struct sp_port *port); |
e96d8bd2 | 389 | |
0151b157 ML |
390 | /** |
391 | * Get the name of a port. | |
392 | * | |
393 | * The name returned is whatever is normally used to refer to a port on the | |
394 | * current operating system; e.g. for Windows it will usually be a "COMn" | |
395 | * device name, and for Unix it will be a device path beginning with "/dev/". | |
396 | * | |
35578b06 | 397 | * @param[in] port Pointer to a port structure. Must not be NULL. |
0151b157 ML |
398 | * |
399 | * @return The port name, or NULL if an invalid port is passed. The name | |
35578b06 UH |
400 | * string is part of the port structure and may not be used after |
401 | * the port structure has been freed. | |
1652aa86 UH |
402 | * |
403 | * @since 0.1.0 | |
0151b157 ML |
404 | */ |
405 | char *sp_get_port_name(const struct sp_port *port); | |
406 | ||
a93fb468 AJ |
407 | /** |
408 | * Get a description for a port, to present to end user. | |
409 | * | |
35578b06 | 410 | * @param[in] port Pointer to a port structure. Must not be NULL. |
a93fb468 AJ |
411 | * |
412 | * @return The port description, or NULL if an invalid port is passed. | |
35578b06 UH |
413 | * The description string is part of the port structure and may not |
414 | * be used after the port structure has been freed. | |
a93fb468 | 415 | * |
3f2f48fc | 416 | * @since 0.1.1 |
a93fb468 | 417 | */ |
f1480939 | 418 | char *sp_get_port_description(const struct sp_port *port); |
a93fb468 AJ |
419 | |
420 | /** | |
421 | * Get the transport type used by a port. | |
422 | * | |
35578b06 | 423 | * @param[in] port Pointer to a port structure. Must not be NULL. |
a93fb468 AJ |
424 | * |
425 | * @return The port transport type. | |
426 | * | |
3f2f48fc | 427 | * @since 0.1.1 |
a93fb468 | 428 | */ |
ad036cc8 | 429 | enum sp_transport sp_get_port_transport(const struct sp_port *port); |
a93fb468 AJ |
430 | |
431 | /** | |
432 | * Get the USB bus number and address on bus of a USB serial adapter port. | |
433 | * | |
35578b06 | 434 | * @param[in] port Pointer to a port structure. Must not be NULL. |
ff6da776 UH |
435 | * @param[out] usb_bus Pointer to a variable to store the USB bus. |
436 | * Can be NULL (in that case it will be ignored). | |
437 | * @param[out] usb_address Pointer to a variable to store the USB address. | |
438 | * Can be NULL (in that case it will be ignored). | |
a93fb468 AJ |
439 | * |
440 | * @return SP_OK upon success, a negative error code otherwise. | |
441 | * | |
3f2f48fc | 442 | * @since 0.1.1 |
a93fb468 AJ |
443 | */ |
444 | enum sp_return sp_get_port_usb_bus_address(const struct sp_port *port, | |
445 | int *usb_bus, int *usb_address); | |
446 | ||
447 | /** | |
448 | * Get the USB Vendor ID and Product ID of a USB serial adapter port. | |
449 | * | |
35578b06 | 450 | * @param[in] port Pointer to a port structure. Must not be NULL. |
9eb9f071 UH |
451 | * @param[out] usb_vid Pointer to a variable to store the USB VID. |
452 | * Can be NULL (in that case it will be ignored). | |
453 | * @param[out] usb_pid Pointer to a variable to store the USB PID. | |
454 | * Can be NULL (in that case it will be ignored). | |
a93fb468 AJ |
455 | * |
456 | * @return SP_OK upon success, a negative error code otherwise. | |
457 | * | |
3f2f48fc | 458 | * @since 0.1.1 |
a93fb468 AJ |
459 | */ |
460 | enum sp_return sp_get_port_usb_vid_pid(const struct sp_port *port, int *usb_vid, int *usb_pid); | |
461 | ||
462 | /** | |
463 | * Get the USB manufacturer string of a USB serial adapter port. | |
464 | * | |
35578b06 | 465 | * @param[in] port Pointer to a port structure. Must not be NULL. |
a93fb468 AJ |
466 | * |
467 | * @return The port manufacturer string, or NULL if an invalid port is passed. | |
35578b06 UH |
468 | * The manufacturer string is part of the port structure and may not |
469 | * be used after the port structure has been freed. | |
a93fb468 | 470 | * |
3f2f48fc | 471 | * @since 0.1.1 |
a93fb468 AJ |
472 | */ |
473 | char *sp_get_port_usb_manufacturer(const struct sp_port *port); | |
474 | ||
475 | /** | |
476 | * Get the USB product string of a USB serial adapter port. | |
477 | * | |
35578b06 | 478 | * @param[in] port Pointer to a port structure. Must not be NULL. |
a93fb468 AJ |
479 | * |
480 | * @return The port product string, or NULL if an invalid port is passed. | |
35578b06 UH |
481 | * The product string is part of the port structure and may not be |
482 | * used after the port structure has been freed. | |
a93fb468 | 483 | * |
3f2f48fc | 484 | * @since 0.1.1 |
a93fb468 AJ |
485 | */ |
486 | char *sp_get_port_usb_product(const struct sp_port *port); | |
487 | ||
488 | /** | |
489 | * Get the USB serial number string of a USB serial adapter port. | |
490 | * | |
35578b06 | 491 | * @param[in] port Pointer to a port structure. Must not be NULL. |
a93fb468 AJ |
492 | * |
493 | * @return The port serial number, or NULL if an invalid port is passed. | |
35578b06 UH |
494 | * The serial number string is part of the port structure and may |
495 | * not be used after the port structure has been freed. | |
a93fb468 | 496 | * |
3f2f48fc | 497 | * @since 0.1.1 |
a93fb468 AJ |
498 | */ |
499 | char *sp_get_port_usb_serial(const struct sp_port *port); | |
500 | ||
501 | /** | |
e33dcf90 | 502 | * Get the MAC address of a Bluetooth serial adapter port. |
a93fb468 | 503 | * |
35578b06 | 504 | * @param[in] port Pointer to a port structure. Must not be NULL. |
a93fb468 | 505 | * |
e33dcf90 | 506 | * @return The port MAC address, or NULL if an invalid port is passed. |
35578b06 UH |
507 | * The MAC address string is part of the port structure and may not |
508 | * be used after the port structure has been freed. | |
a93fb468 | 509 | * |
3f2f48fc | 510 | * @since 0.1.1 |
a93fb468 AJ |
511 | */ |
512 | char *sp_get_port_bluetooth_address(const struct sp_port *port); | |
513 | ||
0151b157 ML |
514 | /** |
515 | * Get the operating system handle for a port. | |
516 | * | |
517 | * The type of the handle depends on the operating system. On Unix based | |
518 | * systems, the handle is a file descriptor of type "int". On Windows, the | |
519 | * handle is of type "HANDLE". The user should allocate a variable of the | |
520 | * appropriate type and pass a pointer to this to receive the result. | |
521 | * | |
522 | * To obtain a valid handle, the port must first be opened by calling | |
523 | * sp_open() using the same port structure. | |
524 | * | |
525 | * After the port is closed or the port structure freed, the handle may | |
526 | * no longer be valid. | |
527 | * | |
528 | * @warning This feature is provided so that programs may make use of | |
529 | * OS-specific functionality where desired. Doing so obviously | |
530 | * comes at a cost in portability. It also cannot be guaranteed | |
531 | * that direct usage of the OS handle will not conflict with the | |
532 | * library's own usage of the port. Be careful. | |
533 | * | |
35578b06 UH |
534 | * @param[in] port Pointer to a port structure. Must not be NULL. |
535 | * @param[out] result_ptr If any error is returned, the variable pointed to by | |
ff6da776 UH |
536 | * result_ptr will have unknown contents and should not |
537 | * be used. Otherwise, it will be set to point to the | |
538 | * OS handle. Must not be NULL. | |
35578b06 | 539 | * |
0151b157 | 540 | * @return SP_OK upon success, a negative error code otherwise. |
1652aa86 UH |
541 | * |
542 | * @since 0.1.0 | |
0151b157 ML |
543 | */ |
544 | enum sp_return sp_get_port_handle(const struct sp_port *port, void *result_ptr); | |
545 | ||
cd5f5281 | 546 | /** |
cf9d365c | 547 | * @} |
144a598f UH |
548 | * |
549 | * @defgroup Configuration Configuration | |
550 | * | |
551 | * Setting and querying serial port parameters. | |
cf9d365c UH |
552 | * @{ |
553 | */ | |
e96d8bd2 | 554 | |
9b1502ef ML |
555 | /** |
556 | * Allocate a port configuration structure. | |
557 | * | |
558 | * The user should allocate a variable of type "struct sp_config *" and pass a | |
559 | * pointer to this to receive the result. The variable will be updated to | |
560 | * point to the new configuration structure. The structure is opaque and must | |
561 | * be accessed via the functions provided. | |
562 | * | |
563 | * All parameters in the structure will be initialised to special values which | |
564 | * are ignored by sp_set_config(). | |
565 | * | |
566 | * The structure should be freed after use by calling sp_free_config(). | |
567 | * | |
ff6da776 UH |
568 | * @param[out] config_ptr If any error is returned, the variable pointed to by |
569 | * config_ptr will be set to NULL. Otherwise, it will | |
570 | * be set to point to the allocated config structure. | |
35578b06 | 571 | * Must not be NULL. |
9b1502ef ML |
572 | * |
573 | * @return SP_OK upon success, a negative error code otherwise. | |
1652aa86 UH |
574 | * |
575 | * @since 0.1.0 | |
9b1502ef ML |
576 | */ |
577 | enum sp_return sp_new_config(struct sp_port_config **config_ptr); | |
578 | ||
579 | /** | |
580 | * Free a port configuration structure. | |
581 | * | |
35578b06 | 582 | * @param[in] config Pointer to a configuration structure. Must not be NULL. |
1652aa86 UH |
583 | * |
584 | * @since 0.1.0 | |
9b1502ef ML |
585 | */ |
586 | void sp_free_config(struct sp_port_config *config); | |
587 | ||
cd5f5281 | 588 | /** |
cf9d365c UH |
589 | * Get the current configuration of the specified serial port. |
590 | * | |
9b1502ef ML |
591 | * The user should allocate a configuration structure using sp_new_config() |
592 | * and pass this as the config parameter. The configuration structure will | |
593 | * be updated with the port configuration. | |
cf9d365c | 594 | * |
9b1502ef ML |
595 | * Any parameters that are configured with settings not recognised or |
596 | * supported by libserialport, will be set to special values that are | |
597 | * ignored by sp_set_config(). | |
cf9d365c | 598 | * |
35578b06 UH |
599 | * @param[in] port Pointer to a port structure. Must not be NULL. |
600 | * @param[out] config Pointer to a configuration structure that will hold | |
ff6da776 UH |
601 | * the result. Upon errors the contents of the config |
602 | * struct will not be changed. Must not be NULL. | |
35578b06 | 603 | * |
f36c6395 | 604 | * @return SP_OK upon success, a negative error code otherwise. |
1652aa86 UH |
605 | * |
606 | * @since 0.1.0 | |
cf9d365c | 607 | */ |
eb6ed20f | 608 | enum sp_return sp_get_config(struct sp_port *port, struct sp_port_config *config); |
cd5f5281 ML |
609 | |
610 | /** | |
cf9d365c UH |
611 | * Set the configuration for the specified serial port. |
612 | * | |
9b1502ef ML |
613 | * For each parameter in the configuration, there is a special value (usually |
614 | * -1, but see the documentation for each field). These values will be ignored | |
615 | * and the corresponding setting left unchanged on the port. | |
cf9d365c | 616 | * |
ff6da776 UH |
617 | * Upon errors, the configuration of the serial port is unknown since |
618 | * partial/incomplete config updates may have happened. | |
619 | * | |
35578b06 UH |
620 | * @param[in] port Pointer to a port structure. Must not be NULL. |
621 | * @param[in] config Pointer to a configuration structure. Must not be NULL. | |
622 | * | |
f36c6395 | 623 | * @return SP_OK upon success, a negative error code otherwise. |
1652aa86 UH |
624 | * |
625 | * @since 0.1.0 | |
cf9d365c | 626 | */ |
eb6ed20f | 627 | enum sp_return sp_set_config(struct sp_port *port, const struct sp_port_config *config); |
cd5f5281 ML |
628 | |
629 | /** | |
cf9d365c UH |
630 | * Set the baud rate for the specified serial port. |
631 | * | |
35578b06 UH |
632 | * @param[in] port Pointer to a port structure. Must not be NULL. |
633 | * @param[in] baudrate Baud rate in bits per second. | |
cf9d365c | 634 | * |
f36c6395 | 635 | * @return SP_OK upon success, a negative error code otherwise. |
1652aa86 UH |
636 | * |
637 | * @since 0.1.0 | |
cf9d365c | 638 | */ |
eb6ed20f | 639 | enum sp_return sp_set_baudrate(struct sp_port *port, int baudrate); |
cd5f5281 ML |
640 | |
641 | /** | |
9b1502ef ML |
642 | * Get the baud rate from a port configuration. |
643 | * | |
35578b06 UH |
644 | * The user should allocate a variable of type int and |
645 | * pass a pointer to this to receive the result. | |
9b1502ef | 646 | * |
35578b06 UH |
647 | * @param[in] config Pointer to a configuration structure. Must not be NULL. |
648 | * @param[out] baudrate_ptr Pointer to a variable to store the result. Must not be NULL. | |
9b1502ef ML |
649 | * |
650 | * @return SP_OK upon success, a negative error code otherwise. | |
1652aa86 UH |
651 | * |
652 | * @since 0.1.0 | |
9b1502ef ML |
653 | */ |
654 | enum sp_return sp_get_config_baudrate(const struct sp_port_config *config, int *baudrate_ptr); | |
655 | ||
656 | /** | |
657 | * Set the baud rate in a port configuration. | |
658 | * | |
35578b06 UH |
659 | * @param[in] config Pointer to a configuration structure. Must not be NULL. |
660 | * @param[in] baudrate Baud rate in bits per second, or -1 to retain the current setting. | |
9b1502ef ML |
661 | * |
662 | * @return SP_OK upon success, a negative error code otherwise. | |
1652aa86 UH |
663 | * |
664 | * @since 0.1.0 | |
9b1502ef ML |
665 | */ |
666 | enum sp_return sp_set_config_baudrate(struct sp_port_config *config, int baudrate); | |
667 | ||
668 | /** | |
669 | * Set the data bits for the specified serial port. | |
cf9d365c | 670 | * |
35578b06 UH |
671 | * @param[in] port Pointer to a port structure. Must not be NULL. |
672 | * @param[in] bits Number of data bits. | |
cf9d365c | 673 | * |
f36c6395 | 674 | * @return SP_OK upon success, a negative error code otherwise. |
1652aa86 UH |
675 | * |
676 | * @since 0.1.0 | |
cf9d365c | 677 | */ |
eb6ed20f | 678 | enum sp_return sp_set_bits(struct sp_port *port, int bits); |
cd5f5281 ML |
679 | |
680 | /** | |
9b1502ef ML |
681 | * Get the data bits from a port configuration. |
682 | * | |
35578b06 UH |
683 | * The user should allocate a variable of type int and |
684 | * pass a pointer to this to receive the result. | |
9b1502ef | 685 | * |
35578b06 UH |
686 | * @param[in] config Pointer to a configuration structure. Must not be NULL. |
687 | * @param[out] bits_ptr Pointer to a variable to store the result. Must not be NULL. | |
9b1502ef ML |
688 | * |
689 | * @return SP_OK upon success, a negative error code otherwise. | |
1652aa86 UH |
690 | * |
691 | * @since 0.1.0 | |
9b1502ef ML |
692 | */ |
693 | enum sp_return sp_get_config_bits(const struct sp_port_config *config, int *bits_ptr); | |
694 | ||
695 | /** | |
696 | * Set the data bits in a port configuration. | |
697 | * | |
35578b06 UH |
698 | * @param[in] config Pointer to a configuration structure. Must not be NULL. |
699 | * @param[in] bits Number of data bits, or -1 to retain the current setting. | |
9b1502ef ML |
700 | * |
701 | * @return SP_OK upon success, a negative error code otherwise. | |
1652aa86 UH |
702 | * |
703 | * @since 0.1.0 | |
9b1502ef ML |
704 | */ |
705 | enum sp_return sp_set_config_bits(struct sp_port_config *config, int bits); | |
706 | ||
707 | /** | |
708 | * Set the parity setting for the specified serial port. | |
cf9d365c | 709 | * |
35578b06 UH |
710 | * @param[in] port Pointer to a port structure. Must not be NULL. |
711 | * @param[in] parity Parity setting. | |
cf9d365c | 712 | * |
f36c6395 | 713 | * @return SP_OK upon success, a negative error code otherwise. |
1652aa86 UH |
714 | * |
715 | * @since 0.1.0 | |
cf9d365c | 716 | */ |
eb6ed20f | 717 | enum sp_return sp_set_parity(struct sp_port *port, enum sp_parity parity); |
cd5f5281 ML |
718 | |
719 | /** | |
9b1502ef ML |
720 | * Get the parity setting from a port configuration. |
721 | * | |
35578b06 UH |
722 | * The user should allocate a variable of type enum sp_parity and |
723 | * pass a pointer to this to receive the result. | |
9b1502ef | 724 | * |
35578b06 UH |
725 | * @param[in] config Pointer to a configuration structure. Must not be NULL. |
726 | * @param[out] parity_ptr Pointer to a variable to store the result. Must not be NULL. | |
9b1502ef ML |
727 | * |
728 | * @return SP_OK upon success, a negative error code otherwise. | |
1652aa86 UH |
729 | * |
730 | * @since 0.1.0 | |
9b1502ef ML |
731 | */ |
732 | enum sp_return sp_get_config_parity(const struct sp_port_config *config, enum sp_parity *parity_ptr); | |
733 | ||
734 | /** | |
735 | * Set the parity setting in a port configuration. | |
736 | * | |
35578b06 UH |
737 | * @param[in] config Pointer to a configuration structure. Must not be NULL. |
738 | * @param[in] parity Parity setting, or -1 to retain the current setting. | |
9b1502ef ML |
739 | * |
740 | * @return SP_OK upon success, a negative error code otherwise. | |
1652aa86 UH |
741 | * |
742 | * @since 0.1.0 | |
9b1502ef ML |
743 | */ |
744 | enum sp_return sp_set_config_parity(struct sp_port_config *config, enum sp_parity parity); | |
745 | ||
746 | /** | |
747 | * Set the stop bits for the specified serial port. | |
cf9d365c | 748 | * |
35578b06 UH |
749 | * @param[in] port Pointer to a port structure. Must not be NULL. |
750 | * @param[in] stopbits Number of stop bits. | |
cf9d365c | 751 | * |
f36c6395 | 752 | * @return SP_OK upon success, a negative error code otherwise. |
1652aa86 UH |
753 | * |
754 | * @since 0.1.0 | |
cf9d365c | 755 | */ |
eb6ed20f | 756 | enum sp_return sp_set_stopbits(struct sp_port *port, int stopbits); |
cd5f5281 ML |
757 | |
758 | /** | |
9b1502ef | 759 | * Get the stop bits from a port configuration. |
cf9d365c | 760 | * |
35578b06 UH |
761 | * The user should allocate a variable of type int and |
762 | * pass a pointer to this to receive the result. | |
cf9d365c | 763 | * |
35578b06 UH |
764 | * @param[in] config Pointer to a configuration structure. Must not be NULL. |
765 | * @param[out] stopbits_ptr Pointer to a variable to store the result. Must not be NULL. | |
cf9d365c | 766 | * |
f36c6395 | 767 | * @return SP_OK upon success, a negative error code otherwise. |
1652aa86 UH |
768 | * |
769 | * @since 0.1.0 | |
cf9d365c | 770 | */ |
9b1502ef ML |
771 | enum sp_return sp_get_config_stopbits(const struct sp_port_config *config, int *stopbits_ptr); |
772 | ||
773 | /** | |
774 | * Set the stop bits in a port configuration. | |
775 | * | |
35578b06 UH |
776 | * @param[in] config Pointer to a configuration structure. Must not be NULL. |
777 | * @param[in] stopbits Number of stop bits, or -1 to retain the current setting. | |
9b1502ef ML |
778 | * |
779 | * @return SP_OK upon success, a negative error code otherwise. | |
1652aa86 UH |
780 | * |
781 | * @since 0.1.0 | |
9b1502ef ML |
782 | */ |
783 | enum sp_return sp_set_config_stopbits(struct sp_port_config *config, int stopbits); | |
18fc2dd1 | 784 | |
cd5f5281 | 785 | /** |
9b1502ef | 786 | * Set the RTS pin behaviour for the specified serial port. |
cf9d365c | 787 | * |
35578b06 UH |
788 | * @param[in] port Pointer to a port structure. Must not be NULL. |
789 | * @param[in] rts RTS pin mode. | |
cf9d365c | 790 | * |
f36c6395 | 791 | * @return SP_OK upon success, a negative error code otherwise. |
1652aa86 UH |
792 | * |
793 | * @since 0.1.0 | |
cf9d365c | 794 | */ |
eb6ed20f | 795 | enum sp_return sp_set_rts(struct sp_port *port, enum sp_rts rts); |
cd5f5281 ML |
796 | |
797 | /** | |
9b1502ef ML |
798 | * Get the RTS pin behaviour from a port configuration. |
799 | * | |
35578b06 UH |
800 | * The user should allocate a variable of type enum sp_rts and |
801 | * pass a pointer to this to receive the result. | |
9b1502ef | 802 | * |
35578b06 UH |
803 | * @param[in] config Pointer to a configuration structure. Must not be NULL. |
804 | * @param[out] rts_ptr Pointer to a variable to store the result. Must not be NULL. | |
9b1502ef ML |
805 | * |
806 | * @return SP_OK upon success, a negative error code otherwise. | |
1652aa86 UH |
807 | * |
808 | * @since 0.1.0 | |
9b1502ef ML |
809 | */ |
810 | enum sp_return sp_get_config_rts(const struct sp_port_config *config, enum sp_rts *rts_ptr); | |
811 | ||
812 | /** | |
813 | * Set the RTS pin behaviour in a port configuration. | |
814 | * | |
35578b06 UH |
815 | * @param[in] config Pointer to a configuration structure. Must not be NULL. |
816 | * @param[in] rts RTS pin mode, or -1 to retain the current setting. | |
9b1502ef ML |
817 | * |
818 | * @return SP_OK upon success, a negative error code otherwise. | |
1652aa86 UH |
819 | * |
820 | * @since 0.1.0 | |
9b1502ef ML |
821 | */ |
822 | enum sp_return sp_set_config_rts(struct sp_port_config *config, enum sp_rts rts); | |
823 | ||
824 | /** | |
825 | * Set the CTS pin behaviour for the specified serial port. | |
cf9d365c | 826 | * |
35578b06 UH |
827 | * @param[in] port Pointer to a port structure. Must not be NULL. |
828 | * @param[in] cts CTS pin mode. | |
cf9d365c | 829 | * |
f36c6395 | 830 | * @return SP_OK upon success, a negative error code otherwise. |
1652aa86 UH |
831 | * |
832 | * @since 0.1.0 | |
cf9d365c | 833 | */ |
eb6ed20f | 834 | enum sp_return sp_set_cts(struct sp_port *port, enum sp_cts cts); |
cd5f5281 ML |
835 | |
836 | /** | |
9b1502ef ML |
837 | * Get the CTS pin behaviour from a port configuration. |
838 | * | |
35578b06 UH |
839 | * The user should allocate a variable of type enum sp_cts and |
840 | * pass a pointer to this to receive the result. | |
9b1502ef | 841 | * |
35578b06 UH |
842 | * @param[in] config Pointer to a configuration structure. Must not be NULL. |
843 | * @param[out] cts_ptr Pointer to a variable to store the result. Must not be NULL. | |
9b1502ef ML |
844 | * |
845 | * @return SP_OK upon success, a negative error code otherwise. | |
1652aa86 UH |
846 | * |
847 | * @since 0.1.0 | |
9b1502ef ML |
848 | */ |
849 | enum sp_return sp_get_config_cts(const struct sp_port_config *config, enum sp_cts *cts_ptr); | |
850 | ||
851 | /** | |
852 | * Set the CTS pin behaviour in a port configuration. | |
853 | * | |
35578b06 UH |
854 | * @param[in] config Pointer to a configuration structure. Must not be NULL. |
855 | * @param[in] cts CTS pin mode, or -1 to retain the current setting. | |
9b1502ef ML |
856 | * |
857 | * @return SP_OK upon success, a negative error code otherwise. | |
1652aa86 UH |
858 | * |
859 | * @since 0.1.0 | |
9b1502ef ML |
860 | */ |
861 | enum sp_return sp_set_config_cts(struct sp_port_config *config, enum sp_cts cts); | |
862 | ||
863 | /** | |
864 | * Set the DTR pin behaviour for the specified serial port. | |
cf9d365c | 865 | * |
35578b06 UH |
866 | * @param[in] port Pointer to a port structure. Must not be NULL. |
867 | * @param[in] dtr DTR pin mode. | |
cf9d365c | 868 | * |
f36c6395 | 869 | * @return SP_OK upon success, a negative error code otherwise. |
1652aa86 UH |
870 | * |
871 | * @since 0.1.0 | |
cf9d365c | 872 | */ |
eb6ed20f | 873 | enum sp_return sp_set_dtr(struct sp_port *port, enum sp_dtr dtr); |
cd5f5281 ML |
874 | |
875 | /** | |
9b1502ef ML |
876 | * Get the DTR pin behaviour from a port configuration. |
877 | * | |
35578b06 UH |
878 | * The user should allocate a variable of type enum sp_dtr and |
879 | * pass a pointer to this to receive the result. | |
9b1502ef | 880 | * |
35578b06 UH |
881 | * @param[in] config Pointer to a configuration structure. Must not be NULL. |
882 | * @param[out] dtr_ptr Pointer to a variable to store the result. Must not be NULL. | |
9b1502ef ML |
883 | * |
884 | * @return SP_OK upon success, a negative error code otherwise. | |
1652aa86 UH |
885 | * |
886 | * @since 0.1.0 | |
9b1502ef ML |
887 | */ |
888 | enum sp_return sp_get_config_dtr(const struct sp_port_config *config, enum sp_dtr *dtr_ptr); | |
889 | ||
890 | /** | |
891 | * Set the DTR pin behaviour in a port configuration. | |
892 | * | |
35578b06 UH |
893 | * @param[in] config Pointer to a configuration structure. Must not be NULL. |
894 | * @param[in] dtr DTR pin mode, or -1 to retain the current setting. | |
9b1502ef ML |
895 | * |
896 | * @return SP_OK upon success, a negative error code otherwise. | |
1652aa86 UH |
897 | * |
898 | * @since 0.1.0 | |
9b1502ef ML |
899 | */ |
900 | enum sp_return sp_set_config_dtr(struct sp_port_config *config, enum sp_dtr dtr); | |
901 | ||
902 | /** | |
903 | * Set the DSR pin behaviour for the specified serial port. | |
cf9d365c | 904 | * |
35578b06 UH |
905 | * @param[in] port Pointer to a port structure. Must not be NULL. |
906 | * @param[in] dsr DSR pin mode. | |
cf9d365c | 907 | * |
f36c6395 | 908 | * @return SP_OK upon success, a negative error code otherwise. |
1652aa86 UH |
909 | * |
910 | * @since 0.1.0 | |
cf9d365c | 911 | */ |
eb6ed20f | 912 | enum sp_return sp_set_dsr(struct sp_port *port, enum sp_dsr dsr); |
cd5f5281 ML |
913 | |
914 | /** | |
9b1502ef ML |
915 | * Get the DSR pin behaviour from a port configuration. |
916 | * | |
35578b06 UH |
917 | * The user should allocate a variable of type enum sp_dsr and |
918 | * pass a pointer to this to receive the result. | |
9b1502ef | 919 | * |
35578b06 UH |
920 | * @param[in] config Pointer to a configuration structure. Must not be NULL. |
921 | * @param[out] dsr_ptr Pointer to a variable to store the result. Must not be NULL. | |
9b1502ef ML |
922 | * |
923 | * @return SP_OK upon success, a negative error code otherwise. | |
1652aa86 UH |
924 | * |
925 | * @since 0.1.0 | |
9b1502ef ML |
926 | */ |
927 | enum sp_return sp_get_config_dsr(const struct sp_port_config *config, enum sp_dsr *dsr_ptr); | |
928 | ||
929 | /** | |
930 | * Set the DSR pin behaviour in a port configuration. | |
931 | * | |
35578b06 UH |
932 | * @param[in] config Pointer to a configuration structure. Must not be NULL. |
933 | * @param[in] dsr DSR pin mode, or -1 to retain the current setting. | |
9b1502ef ML |
934 | * |
935 | * @return SP_OK upon success, a negative error code otherwise. | |
1652aa86 UH |
936 | * |
937 | * @since 0.1.0 | |
9b1502ef ML |
938 | */ |
939 | enum sp_return sp_set_config_dsr(struct sp_port_config *config, enum sp_dsr dsr); | |
940 | ||
941 | /** | |
942 | * Set the XON/XOFF configuration for the specified serial port. | |
cf9d365c | 943 | * |
35578b06 UH |
944 | * @param[in] port Pointer to a port structure. Must not be NULL. |
945 | * @param[in] xon_xoff XON/XOFF mode. | |
cf9d365c | 946 | * |
f36c6395 | 947 | * @return SP_OK upon success, a negative error code otherwise. |
1652aa86 UH |
948 | * |
949 | * @since 0.1.0 | |
cf9d365c | 950 | */ |
eb6ed20f | 951 | enum sp_return sp_set_xon_xoff(struct sp_port *port, enum sp_xonxoff xon_xoff); |
e96d8bd2 | 952 | |
9b1502ef ML |
953 | /** |
954 | * Get the XON/XOFF configuration from a port configuration. | |
955 | * | |
35578b06 UH |
956 | * The user should allocate a variable of type enum sp_xonxoff and |
957 | * pass a pointer to this to receive the result. | |
9b1502ef | 958 | * |
35578b06 UH |
959 | * @param[in] config Pointer to a configuration structure. Must not be NULL. |
960 | * @param[out] xon_xoff_ptr Pointer to a variable to store the result. Must not be NULL. | |
9b1502ef ML |
961 | * |
962 | * @return SP_OK upon success, a negative error code otherwise. | |
1652aa86 UH |
963 | * |
964 | * @since 0.1.0 | |
9b1502ef ML |
965 | */ |
966 | enum sp_return sp_get_config_xon_xoff(const struct sp_port_config *config, enum sp_xonxoff *xon_xoff_ptr); | |
967 | ||
968 | /** | |
969 | * Set the XON/XOFF configuration in a port configuration. | |
970 | * | |
35578b06 UH |
971 | * @param[in] config Pointer to a configuration structure. Must not be NULL. |
972 | * @param[in] xon_xoff XON/XOFF mode, or -1 to retain the current setting. | |
9b1502ef ML |
973 | * |
974 | * @return SP_OK upon success, a negative error code otherwise. | |
1652aa86 UH |
975 | * |
976 | * @since 0.1.0 | |
9b1502ef ML |
977 | */ |
978 | enum sp_return sp_set_config_xon_xoff(struct sp_port_config *config, enum sp_xonxoff xon_xoff); | |
979 | ||
980 | /** | |
981 | * Set the flow control type in a port configuration. | |
982 | * | |
983 | * This function is a wrapper that sets the RTS, CTS, DTR, DSR and | |
984 | * XON/XOFF settings as necessary for the specified flow control | |
985 | * type. For more fine-grained control of these settings, use their | |
986 | * individual configuration functions. | |
987 | * | |
35578b06 UH |
988 | * @param[in] config Pointer to a configuration structure. Must not be NULL. |
989 | * @param[in] flowcontrol Flow control setting to use. | |
9b1502ef ML |
990 | * |
991 | * @return SP_OK upon success, a negative error code otherwise. | |
1652aa86 UH |
992 | * |
993 | * @since 0.1.0 | |
9b1502ef ML |
994 | */ |
995 | enum sp_return sp_set_config_flowcontrol(struct sp_port_config *config, enum sp_flowcontrol flowcontrol); | |
996 | ||
997 | /** | |
998 | * Set the flow control type for the specified serial port. | |
999 | * | |
1000 | * This function is a wrapper that sets the RTS, CTS, DTR, DSR and | |
1001 | * XON/XOFF settings as necessary for the specified flow control | |
1002 | * type. For more fine-grained control of these settings, use their | |
1003 | * individual configuration functions. | |
1004 | * | |
35578b06 UH |
1005 | * @param[in] port Pointer to a port structure. Must not be NULL. |
1006 | * @param[in] flowcontrol Flow control setting to use. | |
9b1502ef ML |
1007 | * |
1008 | * @return SP_OK upon success, a negative error code otherwise. | |
1652aa86 UH |
1009 | * |
1010 | * @since 0.1.0 | |
9b1502ef ML |
1011 | */ |
1012 | enum sp_return sp_set_flowcontrol(struct sp_port *port, enum sp_flowcontrol flowcontrol); | |
1013 | ||
091e75fe | 1014 | /** |
cf9d365c | 1015 | * @} |
144a598f UH |
1016 | * |
1017 | * @defgroup Data Data handling | |
1018 | * | |
1019 | * Reading, writing, and flushing data. | |
1020 | * | |
cf9d365c | 1021 | * @{ |
144a598f | 1022 | */ |
091e75fe ML |
1023 | |
1024 | /** | |
2007ce5e ML |
1025 | * Read bytes from the specified serial port, blocking until complete. |
1026 | * | |
b87deb7c ML |
1027 | * @warning If your program runs on Unix, defines its own signal handlers, and |
1028 | * needs to abort blocking reads when these are called, then you | |
1029 | * should not use this function. It repeats system calls that return | |
1030 | * with EINTR. To be able to abort a read from a signal handler, you | |
1031 | * should implement your own blocking read using sp_nonblocking_read() | |
2007ce5e ML |
1032 | * together with a blocking method that makes sense for your program. |
1033 | * E.g. you can obtain the file descriptor for an open port using | |
1034 | * sp_get_port_handle() and use this to call select() or pselect(), | |
1035 | * with appropriate arrangements to return if a signal is received. | |
cf9d365c | 1036 | * |
35578b06 UH |
1037 | * @param[in] port Pointer to a port structure. Must not be NULL. |
1038 | * @param[out] buf Buffer in which to store the bytes read. Must not be NULL. | |
1039 | * @param[in] count Requested number of bytes to read. | |
1b91c6ea | 1040 | * @param[in] timeout_ms Timeout in milliseconds, or zero to wait indefinitely. |
e3dcf906 ML |
1041 | * |
1042 | * @return The number of bytes read on success, or a negative error code. If | |
1043 | * the number of bytes returned is less than that requested, the | |
1044 | * timeout was reached before the requested number of bytes was | |
1045 | * available. If timeout is zero, the function will always return | |
1046 | * either the requested number of bytes or a negative error code. | |
1652aa86 UH |
1047 | * |
1048 | * @since 0.1.0 | |
e3dcf906 | 1049 | */ |
1b91c6ea | 1050 | enum sp_return sp_blocking_read(struct sp_port *port, void *buf, size_t count, unsigned int timeout_ms); |
e3dcf906 ML |
1051 | |
1052 | /** | |
1053 | * Read bytes from the specified serial port, without blocking. | |
cf9d365c | 1054 | * |
35578b06 UH |
1055 | * @param[in] port Pointer to a port structure. Must not be NULL. |
1056 | * @param[out] buf Buffer in which to store the bytes read. Must not be NULL. | |
1057 | * @param[in] count Maximum number of bytes to read. | |
cf9d365c | 1058 | * |
e3dcf906 ML |
1059 | * @return The number of bytes read on success, or a negative error code. The |
1060 | * number of bytes returned may be any number from zero to the maximum | |
1061 | * that was requested. | |
1652aa86 UH |
1062 | * |
1063 | * @since 0.1.0 | |
e3dcf906 ML |
1064 | */ |
1065 | enum sp_return sp_nonblocking_read(struct sp_port *port, void *buf, size_t count); | |
1066 | ||
1067 | /** | |
1068 | * Write bytes to the specified serial port, blocking until complete. | |
1069 | * | |
1070 | * Note that this function only ensures that the accepted bytes have been | |
1071 | * written to the OS; they may be held in driver or hardware buffers and not | |
1072 | * yet physically transmitted. To check whether all written bytes have actually | |
1073 | * been transmitted, use the sp_output_waiting() function. To wait until all | |
1074 | * written bytes have actually been transmitted, use the sp_drain() function. | |
1075 | * | |
b87deb7c ML |
1076 | * @warning If your program runs on Unix, defines its own signal handlers, and |
1077 | * needs to abort blocking writes when these are called, then you | |
1078 | * should not use this function. It repeats system calls that return | |
1079 | * with EINTR. To be able to abort a write from a signal handler, you | |
1080 | * should implement your own blocking write using sp_nonblocking_write() | |
2007ce5e ML |
1081 | * together with a blocking method that makes sense for your program. |
1082 | * E.g. you can obtain the file descriptor for an open port using | |
1083 | * sp_get_port_handle() and use this to call select() or pselect(), | |
1084 | * with appropriate arrangements to return if a signal is received. | |
1085 | * | |
35578b06 UH |
1086 | * @param[in] port Pointer to a port structure. Must not be NULL. |
1087 | * @param[in] buf Buffer containing the bytes to write. Must not be NULL. | |
1088 | * @param[in] count Requested number of bytes to write. | |
1b91c6ea | 1089 | * @param[in] timeout_ms Timeout in milliseconds, or zero to wait indefinitely. |
e3dcf906 | 1090 | * |
85987464 ML |
1091 | * @return The number of bytes written on success, or a negative error code. |
1092 | * If the number of bytes returned is less than that requested, the | |
e3dcf906 | 1093 | * timeout was reached before the requested number of bytes was |
85987464 | 1094 | * written. If timeout is zero, the function will always return |
e3dcf906 ML |
1095 | * either the requested number of bytes or a negative error code. In |
1096 | * the event of an error there is no way to determine how many bytes | |
cfa5af67 | 1097 | * were sent before the error occurred. |
1652aa86 UH |
1098 | * |
1099 | * @since 0.1.0 | |
cf9d365c | 1100 | */ |
1b91c6ea | 1101 | enum sp_return sp_blocking_write(struct sp_port *port, const void *buf, size_t count, unsigned int timeout_ms); |
091e75fe ML |
1102 | |
1103 | /** | |
e3dcf906 | 1104 | * Write bytes to the specified serial port, without blocking. |
cf9d365c | 1105 | * |
e3dcf906 ML |
1106 | * Note that this function only ensures that the accepted bytes have been |
1107 | * written to the OS; they may be held in driver or hardware buffers and not | |
1108 | * yet physically transmitted. To check whether all written bytes have actually | |
1109 | * been transmitted, use the sp_output_waiting() function. To wait until all | |
1110 | * written bytes have actually been transmitted, use the sp_drain() function. | |
cf9d365c | 1111 | * |
35578b06 UH |
1112 | * @param[in] port Pointer to a port structure. Must not be NULL. |
1113 | * @param[in] buf Buffer containing the bytes to write. Must not be NULL. | |
1114 | * @param[in] count Maximum number of bytes to write. | |
cf9d365c | 1115 | * |
f36c6395 | 1116 | * @return The number of bytes written on success, or a negative error code. |
e3dcf906 ML |
1117 | * The number of bytes returned may be any number from zero to the |
1118 | * maximum that was requested. | |
1652aa86 UH |
1119 | * |
1120 | * @since 0.1.0 | |
cf9d365c | 1121 | */ |
e3dcf906 | 1122 | enum sp_return sp_nonblocking_write(struct sp_port *port, const void *buf, size_t count); |
091e75fe | 1123 | |
3353c22f ML |
1124 | /** |
1125 | * Gets the number of bytes waiting in the input buffer. | |
1126 | * | |
35578b06 | 1127 | * @param[in] port Pointer to a port structure. Must not be NULL. |
3353c22f ML |
1128 | * |
1129 | * @return Number of bytes waiting on success, a negative error code otherwise. | |
1652aa86 UH |
1130 | * |
1131 | * @since 0.1.0 | |
3353c22f ML |
1132 | */ |
1133 | enum sp_return sp_input_waiting(struct sp_port *port); | |
1134 | ||
1135 | /** | |
1136 | * Gets the number of bytes waiting in the output buffer. | |
1137 | * | |
35578b06 | 1138 | * @param[in] port Pointer to a port structure. Must not be NULL. |
3353c22f ML |
1139 | * |
1140 | * @return Number of bytes waiting on success, a negative error code otherwise. | |
1652aa86 UH |
1141 | * |
1142 | * @since 0.1.0 | |
3353c22f ML |
1143 | */ |
1144 | enum sp_return sp_output_waiting(struct sp_port *port); | |
1145 | ||
091e75fe | 1146 | /** |
fd8fd11a ML |
1147 | * Flush serial port buffers. Data in the selected buffer(s) is discarded. |
1148 | * | |
35578b06 UH |
1149 | * @param[in] port Pointer to a port structure. Must not be NULL. |
1150 | * @param[in] buffers Which buffer(s) to flush. | |
cf9d365c | 1151 | * |
f36c6395 | 1152 | * @return SP_OK upon success, a negative error code otherwise. |
1652aa86 UH |
1153 | * |
1154 | * @since 0.1.0 | |
cf9d365c | 1155 | */ |
fd8fd11a | 1156 | enum sp_return sp_flush(struct sp_port *port, enum sp_buffer buffers); |
091e75fe | 1157 | |
69a3739c ML |
1158 | /** |
1159 | * Wait for buffered data to be transmitted. | |
1160 | * | |
2c827b21 ML |
1161 | * @warning If your program runs on Unix, defines its own signal handlers, and |
1162 | * needs to abort draining the output buffer when when these are | |
1163 | * called, then you should not use this function. It repeats system | |
1164 | * calls that return with EINTR. To be able to abort a drain from a | |
1165 | * signal handler, you would need to implement your own blocking | |
1166 | * drain by polling the result of sp_output_waiting(). | |
1167 | * | |
35578b06 | 1168 | * @param[in] port Pointer to a port structure. Must not be NULL. |
3f099f4f | 1169 | * |
f36c6395 | 1170 | * @return SP_OK upon success, a negative error code otherwise. |
1652aa86 UH |
1171 | * |
1172 | * @since 0.1.0 | |
69a3739c ML |
1173 | */ |
1174 | enum sp_return sp_drain(struct sp_port *port); | |
1175 | ||
6f1186aa ML |
1176 | /** |
1177 | * @} | |
144a598f UH |
1178 | * |
1179 | * @defgroup Waiting Waiting | |
1180 | * | |
1181 | * Waiting for events and timeout handling. | |
1182 | * | |
6f1186aa ML |
1183 | * @{ |
1184 | */ | |
1185 | ||
1186 | /** | |
1187 | * Allocate storage for a set of events. | |
1188 | * | |
1189 | * The user should allocate a variable of type struct sp_event_set *, | |
1190 | * then pass a pointer to this variable to receive the result. | |
1191 | * | |
1192 | * The result should be freed after use by calling sp_free_event_set(). | |
1193 | * | |
35578b06 UH |
1194 | * @param[out] result_ptr If any error is returned, the variable pointed to by |
1195 | * result_ptr will be set to NULL. Otherwise, it will | |
1196 | * be set to point to the event set. Must not be NULL. | |
1197 | * | |
6f1186aa | 1198 | * @return SP_OK upon success, a negative error code otherwise. |
1652aa86 UH |
1199 | * |
1200 | * @since 0.1.0 | |
6f1186aa ML |
1201 | */ |
1202 | enum sp_return sp_new_event_set(struct sp_event_set **result_ptr); | |
1203 | ||
1204 | /** | |
1205 | * Add events to a struct sp_event_set for a given port. | |
1206 | * | |
1207 | * The port must first be opened by calling sp_open() using the same port | |
1208 | * structure. | |
1209 | * | |
1210 | * After the port is closed or the port structure freed, the results may | |
1211 | * no longer be valid. | |
1212 | * | |
35578b06 UH |
1213 | * @param[in,out] event_set Event set to update. Must not be NULL. |
1214 | * @param[in] port Pointer to a port structure. Must not be NULL. | |
1215 | * @param[in] mask Bitmask of events to be waited for. | |
6f1186aa ML |
1216 | * |
1217 | * @return SP_OK upon success, a negative error code otherwise. | |
1652aa86 UH |
1218 | * |
1219 | * @since 0.1.0 | |
6f1186aa ML |
1220 | */ |
1221 | enum sp_return sp_add_port_events(struct sp_event_set *event_set, | |
1222 | const struct sp_port *port, enum sp_event mask); | |
1223 | ||
1224 | /** | |
1225 | * Wait for any of a set of events to occur. | |
1226 | * | |
35578b06 | 1227 | * @param[in] event_set Event set to wait on. Must not be NULL. |
1b91c6ea | 1228 | * @param[in] timeout_ms Timeout in milliseconds, or zero to wait indefinitely. |
6f1186aa ML |
1229 | * |
1230 | * @return SP_OK upon success, a negative error code otherwise. | |
1652aa86 UH |
1231 | * |
1232 | * @since 0.1.0 | |
6f1186aa | 1233 | */ |
1b91c6ea | 1234 | enum sp_return sp_wait(struct sp_event_set *event_set, unsigned int timeout_ms); |
6f1186aa ML |
1235 | |
1236 | /** | |
1237 | * Free a structure allocated by sp_new_event_set(). | |
1652aa86 | 1238 | * |
35578b06 UH |
1239 | * @param[in] event_set Event set to free. Must not be NULL. |
1240 | * | |
1652aa86 | 1241 | * @since 0.1.0 |
6f1186aa ML |
1242 | */ |
1243 | void sp_free_event_set(struct sp_event_set *event_set); | |
1244 | ||
90cc3ee6 ML |
1245 | /** |
1246 | * @} | |
144a598f UH |
1247 | * |
1248 | * @defgroup Signals Signals | |
1249 | * | |
1250 | * Port signalling operations. | |
1251 | * | |
90cc3ee6 ML |
1252 | * @{ |
1253 | */ | |
1254 | ||
8cf7c697 ML |
1255 | /** |
1256 | * Gets the status of the control signals for the specified port. | |
1257 | * | |
1258 | * The user should allocate a variable of type "enum sp_signal" and pass a | |
1259 | * pointer to this variable to receive the result. The result is a bitmask | |
1260 | * in which individual signals can be checked by bitwise OR with values of | |
1261 | * the sp_signal enum. | |
1262 | * | |
35578b06 UH |
1263 | * @param[in] port Pointer to a port structure. Must not be NULL. |
1264 | * @param[out] signal_mask Pointer to a variable to receive the result. | |
1265 | * Must not be NULL. | |
8cf7c697 | 1266 | * |
f36c6395 | 1267 | * @return SP_OK upon success, a negative error code otherwise. |
1652aa86 UH |
1268 | * |
1269 | * @since 0.1.0 | |
8cf7c697 | 1270 | */ |
f3ccf157 | 1271 | enum sp_return sp_get_signals(struct sp_port *port, enum sp_signal *signal_mask); |
8cf7c697 | 1272 | |
90cc3ee6 ML |
1273 | /** |
1274 | * Put the port transmit line into the break state. | |
1275 | * | |
35578b06 | 1276 | * @param[in] port Pointer to a port structure. Must not be NULL. |
3f099f4f | 1277 | * |
f36c6395 | 1278 | * @return SP_OK upon success, a negative error code otherwise. |
1652aa86 UH |
1279 | * |
1280 | * @since 0.1.0 | |
90cc3ee6 ML |
1281 | */ |
1282 | enum sp_return sp_start_break(struct sp_port *port); | |
1283 | ||
1284 | /** | |
1285 | * Take the port transmit line out of the break state. | |
1286 | * | |
35578b06 | 1287 | * @param[in] port Pointer to a port structure. Must not be NULL. |
3f099f4f | 1288 | * |
f36c6395 | 1289 | * @return SP_OK upon success, a negative error code otherwise. |
1652aa86 UH |
1290 | * |
1291 | * @since 0.1.0 | |
90cc3ee6 ML |
1292 | */ |
1293 | enum sp_return sp_end_break(struct sp_port *port); | |
1294 | ||
091e75fe | 1295 | /** |
cf9d365c | 1296 | * @} |
144a598f UH |
1297 | * |
1298 | * @defgroup Errors Errors | |
1299 | * | |
1300 | * Obtaining error information. | |
1301 | * | |
cf9d365c | 1302 | * @{ |
144a598f | 1303 | */ |
091e75fe | 1304 | |
cd5f5281 | 1305 | /** |
cf9d365c UH |
1306 | * Get the error code for a failed operation. |
1307 | * | |
1308 | * In order to obtain the correct result, this function should be called | |
1309 | * straight after the failure, before executing any other system operations. | |
1310 | * | |
1311 | * @return The system's numeric code for the error that caused the last | |
1312 | * operation to fail. | |
1652aa86 UH |
1313 | * |
1314 | * @since 0.1.0 | |
cf9d365c | 1315 | */ |
74510d4b | 1316 | int sp_last_error_code(void); |
cd5f5281 ML |
1317 | |
1318 | /** | |
cf9d365c UH |
1319 | * Get the error message for a failed operation. |
1320 | * | |
1321 | * In order to obtain the correct result, this function should be called | |
1322 | * straight after the failure, before executing other system operations. | |
1323 | * | |
1324 | * @return The system's message for the error that caused the last | |
1325 | * operation to fail. This string may be allocated by the function, | |
1326 | * and should be freed after use by calling sp_free_error_message(). | |
1652aa86 UH |
1327 | * |
1328 | * @since 0.1.0 | |
cf9d365c | 1329 | */ |
74510d4b | 1330 | char *sp_last_error_message(void); |
cd5f5281 ML |
1331 | |
1332 | /** | |
cf9d365c | 1333 | * Free an error message returned by sp_last_error_message(). |
1652aa86 | 1334 | * |
35578b06 UH |
1335 | * @param[in] message The error message string to free. Must not be NULL. |
1336 | * | |
1652aa86 | 1337 | * @since 0.1.0 |
cf9d365c | 1338 | */ |
74510d4b | 1339 | void sp_free_error_message(char *message); |
e8ffaee9 | 1340 | |
863b35e6 ML |
1341 | /** |
1342 | * Set the handler function for library debugging messages. | |
1343 | * | |
1344 | * Debugging messages are generated by the library during each operation, | |
1345 | * to help in diagnosing problems. The handler will be called for each | |
1346 | * message. The handler can be set to NULL to ignore all debug messages. | |
1347 | * | |
1348 | * The handler function should accept a format string and variable length | |
1349 | * argument list, in the same manner as e.g. printf(). | |
1350 | * | |
1351 | * The default handler is sp_default_debug_handler(). | |
1652aa86 | 1352 | * |
35578b06 UH |
1353 | * @param[in] handler The handler function to use. Can be NULL (in that case |
1354 | * all debug messages will be ignored). | |
1355 | * | |
1652aa86 | 1356 | * @since 0.1.0 |
863b35e6 ML |
1357 | */ |
1358 | void sp_set_debug_handler(void (*handler)(const char *format, ...)); | |
1359 | ||
1360 | /** | |
1361 | * Default handler function for library debugging messages. | |
1362 | * | |
1363 | * This function prints debug messages to the standard error stream if the | |
1364 | * environment variable LIBSERIALPORT_DEBUG is set. Otherwise, they are | |
1365 | * ignored. | |
1652aa86 | 1366 | * |
35578b06 UH |
1367 | * @param[in] format The format string to use. Must not be NULL. |
1368 | * @param[in] ... The variable length argument list to use. | |
1369 | * | |
1652aa86 | 1370 | * @since 0.1.0 |
863b35e6 ML |
1371 | */ |
1372 | void sp_default_debug_handler(const char *format, ...); | |
1373 | ||
cf9d365c | 1374 | /** @} */ |
091e75fe | 1375 | |
524b0e14 | 1376 | /** |
144a598f UH |
1377 | * @defgroup Versions Versions |
1378 | * | |
1379 | * Version number querying functions, definitions, and macros. | |
524b0e14 UH |
1380 | * |
1381 | * This set of API calls returns two different version numbers related | |
1382 | * to libserialport. The "package version" is the release version number of the | |
1383 | * libserialport tarball in the usual "major.minor.micro" format, e.g. "0.1.0". | |
1384 | * | |
1385 | * The "library version" is independent of that; it is the libtool version | |
1386 | * number in the "current:revision:age" format, e.g. "2:0:0". | |
1387 | * See http://www.gnu.org/software/libtool/manual/libtool.html#Libtool-versioning for details. | |
1388 | * | |
1389 | * Both version numbers (and/or individual components of them) can be | |
1390 | * retrieved via the API calls at runtime, and/or they can be checked at | |
1391 | * compile/preprocessor time using the respective macros. | |
1392 | * | |
1393 | * @{ | |
1394 | */ | |
1395 | ||
1396 | /* | |
1397 | * Package version macros (can be used for conditional compilation). | |
1398 | */ | |
1399 | ||
1400 | /** The libserialport package 'major' version number. */ | |
1401 | #define SP_PACKAGE_VERSION_MAJOR @SP_PACKAGE_VERSION_MAJOR@ | |
1402 | ||
1403 | /** The libserialport package 'minor' version number. */ | |
1404 | #define SP_PACKAGE_VERSION_MINOR @SP_PACKAGE_VERSION_MINOR@ | |
1405 | ||
1406 | /** The libserialport package 'micro' version number. */ | |
1407 | #define SP_PACKAGE_VERSION_MICRO @SP_PACKAGE_VERSION_MICRO@ | |
1408 | ||
1409 | /** The libserialport package version ("major.minor.micro") as string. */ | |
1410 | #define SP_PACKAGE_VERSION_STRING "@SP_PACKAGE_VERSION@" | |
1411 | ||
1412 | /* | |
1413 | * Library/libtool version macros (can be used for conditional compilation). | |
1414 | */ | |
1415 | ||
1416 | /** The libserialport libtool 'current' version number. */ | |
1417 | #define SP_LIB_VERSION_CURRENT @SP_LIB_VERSION_CURRENT@ | |
1418 | ||
1419 | /** The libserialport libtool 'revision' version number. */ | |
1420 | #define SP_LIB_VERSION_REVISION @SP_LIB_VERSION_REVISION@ | |
1421 | ||
1422 | /** The libserialport libtool 'age' version number. */ | |
1423 | #define SP_LIB_VERSION_AGE @SP_LIB_VERSION_AGE@ | |
1424 | ||
1425 | /** The libserialport libtool version ("current:revision:age") as string. */ | |
1426 | #define SP_LIB_VERSION_STRING "@SP_LIB_VERSION@" | |
1427 | ||
1428 | /** | |
1429 | * Get the major libserialport package version number. | |
1430 | * | |
1431 | * @return The major package version number. | |
1432 | * | |
1433 | * @since 0.1.0 | |
1434 | */ | |
1435 | int sp_get_major_package_version(void); | |
1436 | ||
1437 | /** | |
1438 | * Get the minor libserialport package version number. | |
1439 | * | |
1440 | * @return The minor package version number. | |
1441 | * | |
1442 | * @since 0.1.0 | |
1443 | */ | |
1444 | int sp_get_minor_package_version(void); | |
1445 | ||
1446 | /** | |
1447 | * Get the micro libserialport package version number. | |
1448 | * | |
1449 | * @return The micro package version number. | |
1450 | * | |
1451 | * @since 0.1.0 | |
1452 | */ | |
1453 | int sp_get_micro_package_version(void); | |
1454 | ||
1455 | /** | |
1456 | * Get the libserialport package version number as a string. | |
1457 | * | |
1458 | * @return The package version number string. The returned string is | |
1459 | * static and thus should NOT be free'd by the caller. | |
1460 | * | |
1461 | * @since 0.1.0 | |
1462 | */ | |
1463 | const char *sp_get_package_version_string(void); | |
1464 | ||
1465 | /** | |
1466 | * Get the "current" part of the libserialport library version number. | |
1467 | * | |
1468 | * @return The "current" library version number. | |
1469 | * | |
1470 | * @since 0.1.0 | |
1471 | */ | |
1472 | int sp_get_current_lib_version(void); | |
1473 | ||
1474 | /** | |
1475 | * Get the "revision" part of the libserialport library version number. | |
1476 | * | |
1477 | * @return The "revision" library version number. | |
1478 | * | |
1479 | * @since 0.1.0 | |
1480 | */ | |
1481 | int sp_get_revision_lib_version(void); | |
1482 | ||
1483 | /** | |
1484 | * Get the "age" part of the libserialport library version number. | |
1485 | * | |
1486 | * @return The "age" library version number. | |
1487 | * | |
1488 | * @since 0.1.0 | |
1489 | */ | |
1490 | int sp_get_age_lib_version(void); | |
1491 | ||
1492 | /** | |
1493 | * Get the libserialport library version number as a string. | |
1494 | * | |
1495 | * @return The library version number string. The returned string is | |
1496 | * static and thus should NOT be free'd by the caller. | |
1497 | * | |
1498 | * @since 0.1.0 | |
1499 | */ | |
1500 | const char *sp_get_lib_version_string(void); | |
1501 | ||
1502 | /** @} */ | |
1503 | ||
5ef8a1ed UH |
1504 | #ifdef __cplusplus |
1505 | } | |
1506 | #endif | |
1507 | ||
8645feda | 1508 | #endif |