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