2 * This file is part of the libserialport project.
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>
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.
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.
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/>.
23 * @mainpage libserialport API
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.
31 * By writing your serial code to use libserialport, you enable it to work
32 * transparently on any platform supported by the library.
34 * libserialport is an open source project released under the LGPL3+ license.
36 * The library is maintained by the [sigrok](http://sigrok.org/) project. See
37 * the [libserialport homepage](http://sigrok.org/wiki/Libserialport) for the
40 * Source code is maintained in git at
41 * [git://sigrok.org/libserialport](http://sigrok.org/gitweb/?p=libserialport.git).
43 * Bugs are tracked at http://sigrok.org/bugzilla/.
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.
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.
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.
65 * Some simple example programs using libserialport are included in the
66 * @c examples directory in the source package:
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 * - @ref port_config.c - Accessing configuration settings of a port.
72 * These examples are linked with the API documentation. Each function
73 * in the API reference includes links to where it is used in an example
74 * program, and each appearance of a function in the examples links
75 * to that function's entry in the API reference.
80 * To use libserialport functions in your code, you should include the
81 * libserialport.h header, i.e.
83 * #include <libserialport.h>
89 * All identifiers defined by the public libserialport headers use the prefix
90 * @c sp_ (for functions and data types) or @c SP_ (for macros and constants).
95 * The functions provided by the library are documented in detail in
96 * the following sections:
98 * - @ref Enumeration (obtaining a list of serial ports on the system)
99 * - @ref Ports (opening, closing and getting information about ports)
100 * - @ref Configuration (baud rate, parity, etc.)
101 * - @ref Signals (modem control lines, breaks, etc.)
102 * - @ref Data (reading and writing data, and buffer management)
103 * - @ref Waiting (waiting for ports to be ready, integrating with event loops)
104 * - @ref Errors (getting error and debugging information)
109 * The library defines three data structures:
111 * - @ref sp_port, which represents a serial port.
112 * See @ref Enumeration.
113 * - @ref sp_port_config, which represents a port configuration.
114 * See @ref Configuration.
115 * - @ref sp_event_set, which represents a set of events.
118 * All these structures are allocated and freed by library functions. It is
119 * the caller's responsibility to ensure that the correct calls are made to
120 * free allocated structures after use.
122 * Return codes and error handling
123 * -------------------------------
125 * Most functions have return type @ref sp_return and can return only four
126 * possible error values:
128 * - @ref SP_ERR_ARG means that a function was called with invalid
129 * arguments. This implies a bug in the caller. The arguments passed would
130 * be invalid regardless of the underlying OS or serial device involved.
132 * - @ref SP_ERR_FAIL means that the OS reported a failure. The error code or
133 * message provided by the OS can be obtained by calling sp_last_error_code()
134 * or sp_last_error_message().
136 * - @ref SP_ERR_SUPP indicates that there is no support for the requested
137 * operation in the current OS, driver or device. No error message is
138 * available from the OS in this case. There is either no way to request
139 * the operation in the first place, or libserialport does not know how to
140 * do so in the current version.
142 * - @ref SP_ERR_MEM indicates that a memory allocation failed.
144 * All of these error values are negative.
146 * Calls that succeed return @ref SP_OK, which is equal to zero. Some functions
147 * declared @ref sp_return can also return a positive value for a successful
148 * numeric result, e.g. sp_blocking_read() or sp_blocking_write().
150 * An error message is only available via sp_last_error_message() in the case
151 * where @ref SP_ERR_FAIL was returned by the previous function call. The error
152 * message returned is that provided by the OS, using the current language
153 * settings. It is an error to call sp_last_error_code() or
154 * sp_last_error_message() except after a previous function call returned
155 * @ref SP_ERR_FAIL. The library does not define its own error codes or
156 * messages to accompany other return codes.
161 * Certain combinations of calls can be made concurrently, as follows.
163 * - Calls using different ports may always be made concurrently, i.e.
164 * it is safe for separate threads to handle their own ports.
166 * - Calls using the same port may be made concurrently when one call
167 * is a read operation and one call is a write operation, i.e. it is safe
168 * to use separate "reader" and "writer" threads for the same port. See
169 * below for which operations meet these definitions.
173 * - sp_blocking_read()
174 * - sp_blocking_read_next()
175 * - sp_nonblocking_read()
176 * - sp_input_waiting()
177 * - sp_flush() with @ref SP_BUF_INPUT only.
178 * - sp_wait() with @ref SP_EVENT_RX_READY only.
182 * - sp_blocking_write()
183 * - sp_nonblocking_write()
184 * - sp_output_waiting()
186 * - sp_flush() with @ref SP_BUF_OUTPUT only.
187 * - sp_wait() with @ref SP_EVENT_TX_READY only.
189 * If two calls, on the same port, do not fit into one of these categories
190 * each, then they may not be made concurrently.
195 * The library can output extensive tracing and debugging information. The
196 * simplest way to use this is to set the environment variable
197 * @c LIBSERIALPORT_DEBUG to any value; messages will then be output to the
198 * standard error stream.
200 * This behaviour is implemented by a default debug message handling
201 * callback. An alternative callback can be set using sp_set_debug_handler(),
202 * in order to e.g. redirect the output elsewhere or filter it.
204 * No guarantees are made about the content of the debug output; it is chosen
205 * to suit the needs of the developers and may change between releases.
211 * The following guidelines may help when porting existing OS-specific code
212 * to use libserialport.
214 * ### Porting from Unix-like systems ###
216 * There are two main differences to note when porting code written for Unix.
218 * The first is that Unix traditionally provides a wide range of functionality
219 * for dealing with serial devices at the OS level; this is exposed through the
220 * termios API and dates to the days when serial terminals were common. If your
221 * code relies on many of these facilities you will need to adapt it, because
222 * libserialport provides only a raw binary channel with no special handling.
224 * The second relates to blocking versus non-blocking I/O behaviour. In
225 * Unix-like systems this is normally specified by setting the @c O_NONBLOCK
226 * flag on the file descriptor, affecting the semantics of subsequent @c read()
227 * and @c write() calls.
229 * In libserialport, blocking and nonblocking operations are both available at
230 * any time. If your existing code Ń•ets @c O_NONBLOCK, you should use
231 * sp_nonblocking_read() and sp_nonblocking_write() to get the same behaviour
232 * as your existing @c read() and @c write() calls. If it does not, you should
233 * use sp_blocking_read() and sp_blocking_write() instead. You may also find
234 * sp_blocking_read_next() useful, which reproduces the semantics of a blocking
235 * read() with @c VTIME=0 and @c VMIN=1 set in termios.
237 * Finally, you should take care if your program uses custom signal handlers.
238 * The blocking calls provided by libserialport will restart system calls that
239 * return with @c EINTR, so you will need to make your own arrangements if you
240 * need to interrupt blocking operations when your signal handlers are called.
241 * This is not an issue if you only use the default handlers.
243 * ### Porting from Windows ###
245 * The main consideration when porting from Windows is that there is no
246 * direct equivalent for overlapped I/O operations.
248 * If your program does not use overlapped I/O, you can simply use
249 * sp_blocking_read() and sp_blocking_write() as direct equivalents for
250 * @c ReadFile() and @c WriteFile(). You may also find sp_blocking_read_next()
251 * useful, which reproduces the special semantics of @c ReadFile() with
252 * @c ReadIntervalTimeout and @c ReadTotalTimeoutMultiplier set to @c MAXDWORD
253 * and @c ReadTotalTimeoutConstant set to between @c 1 and @c MAXDWORD-1 .
255 * If your program makes use of overlapped I/O to continue work while a serial
256 * operation is in progress, then you can achieve the same results using
257 * sp_nonblocking_read() and sp_nonblocking_write().
259 * Generally, overlapped I/O is combined with either waiting for completion
260 * once there is no more background work to do (using @c WaitForSingleObject()
261 * or @c WaitForMultipleObjects()), or periodically checking for completion
262 * with @c GetOverlappedResult(). If the aim is to start a new operation for
263 * further data once the previous one has completed, you can instead simply
264 * call the nonblocking functions again with the next data. If you need to
265 * wait for completion, use sp_wait() to determine when the port is ready to
266 * send or receive further data.
269 #ifndef LIBSERIALPORT_LIBSERIALPORT_H
270 #define LIBSERIALPORT_LIBSERIALPORT_H
280 /* Microsoft Visual C/C++ compiler in use */
281 #ifdef LIBSERIALPORT_MSBUILD
282 /* Building the library - need to export DLL symbols */
283 #define SP_API __declspec(dllexport)
285 /* Using the library - need to import DLL symbols */
286 #define SP_API __declspec(dllimport)
289 /* Some other compiler in use */
290 #ifndef LIBSERIALPORT_ATBUILD
291 /* Not building the library itself - don't need any special prefixes. */
297 /** Return values. */
299 /** Operation completed successfully. */
301 /** Invalid arguments were passed to the function. */
303 /** A system error occurred while executing the operation. */
305 /** A memory allocation failed while executing the operation. */
307 /** The requested operation is not supported by this system or device. */
311 /** Port access modes. */
313 /** Open port for read access. */
315 /** Open port for write access. */
317 /** Open port for read and write access. @since 0.1.1 */
318 SP_MODE_READ_WRITE = 3
323 /** Data received and ready to read. */
324 SP_EVENT_RX_READY = 1,
325 /** Ready to transmit new data. */
326 SP_EVENT_TX_READY = 2,
327 /** Error occurred. */
331 /** Buffer selection. */
335 /** Output buffer. */
341 /** Parity settings. */
343 /** Special value to indicate setting should be left alone. */
344 SP_PARITY_INVALID = -1,
357 /** RTS pin behaviour. */
359 /** Special value to indicate setting should be left alone. */
365 /** RTS used for flow control. */
366 SP_RTS_FLOW_CONTROL = 2
369 /** CTS pin behaviour. */
371 /** Special value to indicate setting should be left alone. */
375 /** CTS used for flow control. */
376 SP_CTS_FLOW_CONTROL = 1
379 /** DTR pin behaviour. */
381 /** Special value to indicate setting should be left alone. */
387 /** DTR used for flow control. */
388 SP_DTR_FLOW_CONTROL = 2
391 /** DSR pin behaviour. */
393 /** Special value to indicate setting should be left alone. */
397 /** DSR used for flow control. */
398 SP_DSR_FLOW_CONTROL = 1
401 /** XON/XOFF flow control behaviour. */
403 /** Special value to indicate setting should be left alone. */
404 SP_XONXOFF_INVALID = -1,
405 /** XON/XOFF disabled. */
406 SP_XONXOFF_DISABLED = 0,
407 /** XON/XOFF enabled for input only. */
409 /** XON/XOFF enabled for output only. */
411 /** XON/XOFF enabled for input and output. */
415 /** Standard flow control combinations. */
416 enum sp_flowcontrol {
417 /** No flow control. */
418 SP_FLOWCONTROL_NONE = 0,
419 /** Software flow control using XON/XOFF characters. */
420 SP_FLOWCONTROL_XONXOFF = 1,
421 /** Hardware flow control using RTS/CTS signals. */
422 SP_FLOWCONTROL_RTSCTS = 2,
423 /** Hardware flow control using DTR/DSR signals. */
424 SP_FLOWCONTROL_DTRDSR = 3
427 /** Input signals. */
429 /** Clear to send. */
431 /** Data set ready. */
433 /** Data carrier detect. */
435 /** Ring indicator. */
445 /** Native platform serial port. @since 0.1.1 */
447 /** USB serial port adapter. @since 0.1.1 */
449 /** Bluetooth serial port adapter. @since 0.1.1 */
450 SP_TRANSPORT_BLUETOOTH
455 * An opaque structure representing a serial port.
460 * @struct sp_port_config
461 * An opaque structure representing the configuration for a serial port.
463 struct sp_port_config;
466 * @struct sp_event_set
467 * A set of handles to wait on for events.
469 struct sp_event_set {
470 /** Array of OS-specific handles. */
472 /** Array of bitmasks indicating which events apply for each handle. */
473 enum sp_event *masks;
474 /** Number of handles. */
479 * @defgroup Enumeration Port enumeration
481 * Enumerating the serial ports of a system.
483 * See @ref list_ports.c for a working example of port enumeration.
489 * Obtain a pointer to a new sp_port structure representing the named port.
491 * The user should allocate a variable of type "struct sp_port *" and pass a
492 * pointer to this to receive the result.
494 * The result should be freed after use by calling sp_free_port().
496 * @param[in] portname The OS-specific name of a serial port. Must not be NULL.
497 * @param[out] port_ptr If any error is returned, the variable pointed to by
498 * port_ptr will be set to NULL. Otherwise, it will be set
499 * to point to the newly allocated port. Must not be NULL.
501 * @return SP_OK upon success, a negative error code otherwise.
505 SP_API enum sp_return sp_get_port_by_name(const char *portname, struct sp_port **port_ptr);
508 * Free a port structure obtained from sp_get_port_by_name() or sp_copy_port().
510 * @param[in] port Pointer to a port structure. Must not be NULL.
514 SP_API void sp_free_port(struct sp_port *port);
517 * List the serial ports available on the system.
519 * The result obtained is an array of pointers to sp_port structures,
520 * terminated by a NULL. The user should allocate a variable of type
521 * "struct sp_port **" and pass a pointer to this to receive the result.
523 * The result should be freed after use by calling sp_free_port_list().
524 * If a port from the list is to be used after freeing the list, it must be
525 * copied first using sp_copy_port().
527 * @param[out] list_ptr If any error is returned, the variable pointed to by
528 * list_ptr will be set to NULL. Otherwise, it will be set
529 * to point to the newly allocated array. Must not be NULL.
531 * @return SP_OK upon success, a negative error code otherwise.
535 SP_API enum sp_return sp_list_ports(struct sp_port ***list_ptr);
538 * Make a new copy of an sp_port structure.
540 * The user should allocate a variable of type "struct sp_port *" and pass a
541 * pointer to this to receive the result.
543 * The copy should be freed after use by calling sp_free_port().
545 * @param[in] port Pointer to a port structure. Must not be NULL.
546 * @param[out] copy_ptr If any error is returned, the variable pointed to by
547 * copy_ptr will be set to NULL. Otherwise, it will be set
548 * to point to the newly allocated copy. Must not be NULL.
550 * @return SP_OK upon success, a negative error code otherwise.
554 SP_API enum sp_return sp_copy_port(const struct sp_port *port, struct sp_port **copy_ptr);
557 * Free a port list obtained from sp_list_ports().
559 * This will also free all the sp_port structures referred to from the list;
560 * any that are to be retained must be copied first using sp_copy_port().
562 * @param[in] ports Pointer to a list of port structures. Must not be NULL.
566 SP_API void sp_free_port_list(struct sp_port **ports);
570 * @defgroup Ports Port handling
572 * Opening, closing and querying ports.
574 * See @ref port_info.c for a working example of getting port information.
580 * Open the specified serial port.
582 * @param[in] port Pointer to a port structure. Must not be NULL.
583 * @param[in] flags Flags to use when opening the serial port.
585 * @return SP_OK upon success, a negative error code otherwise.
589 SP_API enum sp_return sp_open(struct sp_port *port, enum sp_mode flags);
592 * Close the specified serial port.
594 * @param[in] port Pointer to a port structure. Must not be NULL.
596 * @return SP_OK upon success, a negative error code otherwise.
600 SP_API enum sp_return sp_close(struct sp_port *port);
603 * Get the name of a port.
605 * The name returned is whatever is normally used to refer to a port on the
606 * current operating system; e.g. for Windows it will usually be a "COMn"
607 * device name, and for Unix it will be a device path beginning with "/dev/".
609 * @param[in] port Pointer to a port structure. Must not be NULL.
611 * @return The port name, or NULL if an invalid port is passed. The name
612 * string is part of the port structure and may not be used after
613 * the port structure has been freed.
617 SP_API char *sp_get_port_name(const struct sp_port *port);
620 * Get a description for a port, to present to end user.
622 * @param[in] port Pointer to a port structure. Must not be NULL.
624 * @return The port description, or NULL if an invalid port is passed.
625 * The description string is part of the port structure and may not
626 * be used after the port structure has been freed.
630 SP_API char *sp_get_port_description(const struct sp_port *port);
633 * Get the transport type used by a port.
635 * @param[in] port Pointer to a port structure. Must not be NULL.
637 * @return The port transport type.
641 SP_API enum sp_transport sp_get_port_transport(const struct sp_port *port);
644 * Get the USB bus number and address on bus of a USB serial adapter port.
646 * @param[in] port Pointer to a port structure. Must not be NULL.
647 * @param[out] usb_bus Pointer to a variable to store the USB bus.
648 * Can be NULL (in that case it will be ignored).
649 * @param[out] usb_address Pointer to a variable to store the USB address.
650 * Can be NULL (in that case it will be ignored).
652 * @return SP_OK upon success, a negative error code otherwise.
656 SP_API enum sp_return sp_get_port_usb_bus_address(const struct sp_port *port,
657 int *usb_bus, int *usb_address);
660 * Get the USB Vendor ID and Product ID of a USB serial adapter port.
662 * @param[in] port Pointer to a port structure. Must not be NULL.
663 * @param[out] usb_vid Pointer to a variable to store the USB VID.
664 * Can be NULL (in that case it will be ignored).
665 * @param[out] usb_pid Pointer to a variable to store the USB PID.
666 * Can be NULL (in that case it will be ignored).
668 * @return SP_OK upon success, a negative error code otherwise.
672 SP_API enum sp_return sp_get_port_usb_vid_pid(const struct sp_port *port, int *usb_vid, int *usb_pid);
675 * Get the USB manufacturer string of a USB serial adapter port.
677 * @param[in] port Pointer to a port structure. Must not be NULL.
679 * @return The port manufacturer string, or NULL if an invalid port is passed.
680 * The manufacturer string is part of the port structure and may not
681 * be used after the port structure has been freed.
685 SP_API char *sp_get_port_usb_manufacturer(const struct sp_port *port);
688 * Get the USB product string of a USB serial adapter port.
690 * @param[in] port Pointer to a port structure. Must not be NULL.
692 * @return The port product string, or NULL if an invalid port is passed.
693 * The product string is part of the port structure and may not be
694 * used after the port structure has been freed.
698 SP_API char *sp_get_port_usb_product(const struct sp_port *port);
701 * Get the USB serial number string of a USB serial adapter port.
703 * @param[in] port Pointer to a port structure. Must not be NULL.
705 * @return The port serial number, or NULL if an invalid port is passed.
706 * The serial number string is part of the port structure and may
707 * not be used after the port structure has been freed.
711 SP_API char *sp_get_port_usb_serial(const struct sp_port *port);
714 * Get the MAC address of a Bluetooth serial adapter port.
716 * @param[in] port Pointer to a port structure. Must not be NULL.
718 * @return The port MAC address, or NULL if an invalid port is passed.
719 * The MAC address string is part of the port structure and may not
720 * be used after the port structure has been freed.
724 SP_API char *sp_get_port_bluetooth_address(const struct sp_port *port);
727 * Get the operating system handle for a port.
729 * The type of the handle depends on the operating system. On Unix based
730 * systems, the handle is a file descriptor of type "int". On Windows, the
731 * handle is of type "HANDLE". The user should allocate a variable of the
732 * appropriate type and pass a pointer to this to receive the result.
734 * To obtain a valid handle, the port must first be opened by calling
735 * sp_open() using the same port structure.
737 * After the port is closed or the port structure freed, the handle may
738 * no longer be valid.
740 * @warning This feature is provided so that programs may make use of
741 * OS-specific functionality where desired. Doing so obviously
742 * comes at a cost in portability. It also cannot be guaranteed
743 * that direct usage of the OS handle will not conflict with the
744 * library's own usage of the port. Be careful.
746 * @param[in] port Pointer to a port structure. Must not be NULL.
747 * @param[out] result_ptr If any error is returned, the variable pointed to by
748 * result_ptr will have unknown contents and should not
749 * be used. Otherwise, it will be set to point to the
750 * OS handle. Must not be NULL.
752 * @return SP_OK upon success, a negative error code otherwise.
756 SP_API enum sp_return sp_get_port_handle(const struct sp_port *port, void *result_ptr);
761 * @defgroup Configuration Configuration
763 * Setting and querying serial port parameters.
768 * Allocate a port configuration structure.
770 * The user should allocate a variable of type "struct sp_port_config *" and
771 * pass a pointer to this to receive the result. The variable will be updated
772 * to point to the new configuration structure. The structure is opaque and
773 * must be accessed via the functions provided.
775 * All parameters in the structure will be initialised to special values which
776 * are ignored by sp_set_config().
778 * The structure should be freed after use by calling sp_free_config().
780 * @param[out] config_ptr If any error is returned, the variable pointed to by
781 * config_ptr will be set to NULL. Otherwise, it will
782 * be set to point to the allocated config structure.
785 * @return SP_OK upon success, a negative error code otherwise.
789 SP_API enum sp_return sp_new_config(struct sp_port_config **config_ptr);
792 * Free a port configuration structure.
794 * @param[in] config Pointer to a configuration structure. Must not be NULL.
798 SP_API void sp_free_config(struct sp_port_config *config);
801 * Get the current configuration of the specified serial port.
803 * The user should allocate a configuration structure using sp_new_config()
804 * and pass this as the config parameter. The configuration structure will
805 * be updated with the port configuration.
807 * Any parameters that are configured with settings not recognised or
808 * supported by libserialport, will be set to special values that are
809 * ignored by sp_set_config().
811 * @param[in] port Pointer to a port structure. Must not be NULL.
812 * @param[out] config Pointer to a configuration structure that will hold
813 * the result. Upon errors the contents of the config
814 * struct will not be changed. Must not be NULL.
816 * @return SP_OK upon success, a negative error code otherwise.
820 SP_API enum sp_return sp_get_config(struct sp_port *port, struct sp_port_config *config);
823 * Set the configuration for the specified serial port.
825 * For each parameter in the configuration, there is a special value (usually
826 * -1, but see the documentation for each field). These values will be ignored
827 * and the corresponding setting left unchanged on the port.
829 * Upon errors, the configuration of the serial port is unknown since
830 * partial/incomplete config updates may have happened.
832 * @param[in] port Pointer to a port structure. Must not be NULL.
833 * @param[in] config Pointer to a configuration structure. Must not be NULL.
835 * @return SP_OK upon success, a negative error code otherwise.
839 SP_API enum sp_return sp_set_config(struct sp_port *port, const struct sp_port_config *config);
842 * Set the baud rate for the specified serial port.
844 * @param[in] port Pointer to a port structure. Must not be NULL.
845 * @param[in] baudrate Baud rate in bits per second.
847 * @return SP_OK upon success, a negative error code otherwise.
851 SP_API enum sp_return sp_set_baudrate(struct sp_port *port, int baudrate);
854 * Get the baud rate from a port configuration.
856 * The user should allocate a variable of type int and
857 * pass a pointer to this to receive the result.
859 * @param[in] config Pointer to a configuration structure. Must not be NULL.
860 * @param[out] baudrate_ptr Pointer to a variable to store the result. Must not be NULL.
862 * @return SP_OK upon success, a negative error code otherwise.
866 SP_API enum sp_return sp_get_config_baudrate(const struct sp_port_config *config, int *baudrate_ptr);
869 * Set the baud rate in a port configuration.
871 * @param[in] config Pointer to a configuration structure. Must not be NULL.
872 * @param[in] baudrate Baud rate in bits per second, or -1 to retain the current setting.
874 * @return SP_OK upon success, a negative error code otherwise.
878 SP_API enum sp_return sp_set_config_baudrate(struct sp_port_config *config, int baudrate);
881 * Set the data bits for the specified serial port.
883 * @param[in] port Pointer to a port structure. Must not be NULL.
884 * @param[in] bits Number of data bits.
886 * @return SP_OK upon success, a negative error code otherwise.
890 SP_API enum sp_return sp_set_bits(struct sp_port *port, int bits);
893 * Get the data bits from a port configuration.
895 * The user should allocate a variable of type int and
896 * pass a pointer to this to receive the result.
898 * @param[in] config Pointer to a configuration structure. Must not be NULL.
899 * @param[out] bits_ptr Pointer to a variable to store the result. Must not be NULL.
901 * @return SP_OK upon success, a negative error code otherwise.
905 SP_API enum sp_return sp_get_config_bits(const struct sp_port_config *config, int *bits_ptr);
908 * Set the data bits in a port configuration.
910 * @param[in] config Pointer to a configuration structure. Must not be NULL.
911 * @param[in] bits Number of data bits, or -1 to retain the current setting.
913 * @return SP_OK upon success, a negative error code otherwise.
917 SP_API enum sp_return sp_set_config_bits(struct sp_port_config *config, int bits);
920 * Set the parity setting for the specified serial port.
922 * @param[in] port Pointer to a port structure. Must not be NULL.
923 * @param[in] parity Parity setting.
925 * @return SP_OK upon success, a negative error code otherwise.
929 SP_API enum sp_return sp_set_parity(struct sp_port *port, enum sp_parity parity);
932 * Get the parity setting from a port configuration.
934 * The user should allocate a variable of type enum sp_parity and
935 * pass a pointer to this to receive the result.
937 * @param[in] config Pointer to a configuration structure. Must not be NULL.
938 * @param[out] parity_ptr Pointer to a variable to store the result. Must not be NULL.
940 * @return SP_OK upon success, a negative error code otherwise.
944 SP_API enum sp_return sp_get_config_parity(const struct sp_port_config *config, enum sp_parity *parity_ptr);
947 * Set the parity setting in a port configuration.
949 * @param[in] config Pointer to a configuration structure. Must not be NULL.
950 * @param[in] parity Parity setting, or -1 to retain the current setting.
952 * @return SP_OK upon success, a negative error code otherwise.
956 SP_API enum sp_return sp_set_config_parity(struct sp_port_config *config, enum sp_parity parity);
959 * Set the stop bits for the specified serial port.
961 * @param[in] port Pointer to a port structure. Must not be NULL.
962 * @param[in] stopbits Number of stop bits.
964 * @return SP_OK upon success, a negative error code otherwise.
968 SP_API enum sp_return sp_set_stopbits(struct sp_port *port, int stopbits);
971 * Get the stop bits from a port configuration.
973 * The user should allocate a variable of type int and
974 * pass a pointer to this to receive the result.
976 * @param[in] config Pointer to a configuration structure. Must not be NULL.
977 * @param[out] stopbits_ptr Pointer to a variable to store the result. Must not be NULL.
979 * @return SP_OK upon success, a negative error code otherwise.
983 SP_API enum sp_return sp_get_config_stopbits(const struct sp_port_config *config, int *stopbits_ptr);
986 * Set the stop bits in a port configuration.
988 * @param[in] config Pointer to a configuration structure. Must not be NULL.
989 * @param[in] stopbits Number of stop bits, or -1 to retain the current setting.
991 * @return SP_OK upon success, a negative error code otherwise.
995 SP_API enum sp_return sp_set_config_stopbits(struct sp_port_config *config, int stopbits);
998 * Set the RTS pin behaviour for the specified serial port.
1000 * @param[in] port Pointer to a port structure. Must not be NULL.
1001 * @param[in] rts RTS pin mode.
1003 * @return SP_OK upon success, a negative error code otherwise.
1007 SP_API enum sp_return sp_set_rts(struct sp_port *port, enum sp_rts rts);
1010 * Get the RTS pin behaviour from a port configuration.
1012 * The user should allocate a variable of type enum sp_rts and
1013 * pass a pointer to this to receive the result.
1015 * @param[in] config Pointer to a configuration structure. Must not be NULL.
1016 * @param[out] rts_ptr Pointer to a variable to store the result. Must not be NULL.
1018 * @return SP_OK upon success, a negative error code otherwise.
1022 SP_API enum sp_return sp_get_config_rts(const struct sp_port_config *config, enum sp_rts *rts_ptr);
1025 * Set the RTS pin behaviour in a port configuration.
1027 * @param[in] config Pointer to a configuration structure. Must not be NULL.
1028 * @param[in] rts RTS pin mode, or -1 to retain the current setting.
1030 * @return SP_OK upon success, a negative error code otherwise.
1034 SP_API enum sp_return sp_set_config_rts(struct sp_port_config *config, enum sp_rts rts);
1037 * Set the CTS pin behaviour for the specified serial port.
1039 * @param[in] port Pointer to a port structure. Must not be NULL.
1040 * @param[in] cts CTS pin mode.
1042 * @return SP_OK upon success, a negative error code otherwise.
1046 SP_API enum sp_return sp_set_cts(struct sp_port *port, enum sp_cts cts);
1049 * Get the CTS pin behaviour from a port configuration.
1051 * The user should allocate a variable of type enum sp_cts and
1052 * pass a pointer to this to receive the result.
1054 * @param[in] config Pointer to a configuration structure. Must not be NULL.
1055 * @param[out] cts_ptr Pointer to a variable to store the result. Must not be NULL.
1057 * @return SP_OK upon success, a negative error code otherwise.
1061 SP_API enum sp_return sp_get_config_cts(const struct sp_port_config *config, enum sp_cts *cts_ptr);
1064 * Set the CTS pin behaviour in a port configuration.
1066 * @param[in] config Pointer to a configuration structure. Must not be NULL.
1067 * @param[in] cts CTS pin mode, or -1 to retain the current setting.
1069 * @return SP_OK upon success, a negative error code otherwise.
1073 SP_API enum sp_return sp_set_config_cts(struct sp_port_config *config, enum sp_cts cts);
1076 * Set the DTR pin behaviour for the specified serial port.
1078 * @param[in] port Pointer to a port structure. Must not be NULL.
1079 * @param[in] dtr DTR pin mode.
1081 * @return SP_OK upon success, a negative error code otherwise.
1085 SP_API enum sp_return sp_set_dtr(struct sp_port *port, enum sp_dtr dtr);
1088 * Get the DTR pin behaviour from a port configuration.
1090 * The user should allocate a variable of type enum sp_dtr and
1091 * pass a pointer to this to receive the result.
1093 * @param[in] config Pointer to a configuration structure. Must not be NULL.
1094 * @param[out] dtr_ptr Pointer to a variable to store the result. Must not be NULL.
1096 * @return SP_OK upon success, a negative error code otherwise.
1100 SP_API enum sp_return sp_get_config_dtr(const struct sp_port_config *config, enum sp_dtr *dtr_ptr);
1103 * Set the DTR pin behaviour in a port configuration.
1105 * @param[in] config Pointer to a configuration structure. Must not be NULL.
1106 * @param[in] dtr DTR pin mode, or -1 to retain the current setting.
1108 * @return SP_OK upon success, a negative error code otherwise.
1112 SP_API enum sp_return sp_set_config_dtr(struct sp_port_config *config, enum sp_dtr dtr);
1115 * Set the DSR pin behaviour for the specified serial port.
1117 * @param[in] port Pointer to a port structure. Must not be NULL.
1118 * @param[in] dsr DSR pin mode.
1120 * @return SP_OK upon success, a negative error code otherwise.
1124 SP_API enum sp_return sp_set_dsr(struct sp_port *port, enum sp_dsr dsr);
1127 * Get the DSR pin behaviour from a port configuration.
1129 * The user should allocate a variable of type enum sp_dsr and
1130 * pass a pointer to this to receive the result.
1132 * @param[in] config Pointer to a configuration structure. Must not be NULL.
1133 * @param[out] dsr_ptr Pointer to a variable to store the result. Must not be NULL.
1135 * @return SP_OK upon success, a negative error code otherwise.
1139 SP_API enum sp_return sp_get_config_dsr(const struct sp_port_config *config, enum sp_dsr *dsr_ptr);
1142 * Set the DSR pin behaviour in a port configuration.
1144 * @param[in] config Pointer to a configuration structure. Must not be NULL.
1145 * @param[in] dsr DSR pin mode, or -1 to retain the current setting.
1147 * @return SP_OK upon success, a negative error code otherwise.
1151 SP_API enum sp_return sp_set_config_dsr(struct sp_port_config *config, enum sp_dsr dsr);
1154 * Set the XON/XOFF configuration for the specified serial port.
1156 * @param[in] port Pointer to a port structure. Must not be NULL.
1157 * @param[in] xon_xoff XON/XOFF mode.
1159 * @return SP_OK upon success, a negative error code otherwise.
1163 SP_API enum sp_return sp_set_xon_xoff(struct sp_port *port, enum sp_xonxoff xon_xoff);
1166 * Get the XON/XOFF configuration from a port configuration.
1168 * The user should allocate a variable of type enum sp_xonxoff and
1169 * pass a pointer to this to receive the result.
1171 * @param[in] config Pointer to a configuration structure. Must not be NULL.
1172 * @param[out] xon_xoff_ptr Pointer to a variable to store the result. Must not be NULL.
1174 * @return SP_OK upon success, a negative error code otherwise.
1178 SP_API enum sp_return sp_get_config_xon_xoff(const struct sp_port_config *config, enum sp_xonxoff *xon_xoff_ptr);
1181 * Set the XON/XOFF configuration in a port configuration.
1183 * @param[in] config Pointer to a configuration structure. Must not be NULL.
1184 * @param[in] xon_xoff XON/XOFF mode, or -1 to retain the current setting.
1186 * @return SP_OK upon success, a negative error code otherwise.
1190 SP_API enum sp_return sp_set_config_xon_xoff(struct sp_port_config *config, enum sp_xonxoff xon_xoff);
1193 * Set the flow control type in a port configuration.
1195 * This function is a wrapper that sets the RTS, CTS, DTR, DSR and
1196 * XON/XOFF settings as necessary for the specified flow control
1197 * type. For more fine-grained control of these settings, use their
1198 * individual configuration functions.
1200 * @param[in] config Pointer to a configuration structure. Must not be NULL.
1201 * @param[in] flowcontrol Flow control setting to use.
1203 * @return SP_OK upon success, a negative error code otherwise.
1207 SP_API enum sp_return sp_set_config_flowcontrol(struct sp_port_config *config, enum sp_flowcontrol flowcontrol);
1210 * Set the flow control type for the specified serial port.
1212 * This function is a wrapper that sets the RTS, CTS, DTR, DSR and
1213 * XON/XOFF settings as necessary for the specified flow control
1214 * type. For more fine-grained control of these settings, use their
1215 * individual configuration functions.
1217 * @param[in] port Pointer to a port structure. Must not be NULL.
1218 * @param[in] flowcontrol Flow control setting to use.
1220 * @return SP_OK upon success, a negative error code otherwise.
1224 SP_API enum sp_return sp_set_flowcontrol(struct sp_port *port, enum sp_flowcontrol flowcontrol);
1229 * @defgroup Data Data handling
1231 * Reading, writing, and flushing data.
1237 * Read bytes from the specified serial port, blocking until complete.
1239 * @warning If your program runs on Unix, defines its own signal handlers, and
1240 * needs to abort blocking reads when these are called, then you
1241 * should not use this function. It repeats system calls that return
1242 * with EINTR. To be able to abort a read from a signal handler, you
1243 * should implement your own blocking read using sp_nonblocking_read()
1244 * together with a blocking method that makes sense for your program.
1245 * E.g. you can obtain the file descriptor for an open port using
1246 * sp_get_port_handle() and use this to call select() or pselect(),
1247 * with appropriate arrangements to return if a signal is received.
1249 * @param[in] port Pointer to a port structure. Must not be NULL.
1250 * @param[out] buf Buffer in which to store the bytes read. Must not be NULL.
1251 * @param[in] count Requested number of bytes to read.
1252 * @param[in] timeout_ms Timeout in milliseconds, or zero to wait indefinitely.
1254 * @return The number of bytes read on success, or a negative error code. If
1255 * the number of bytes returned is less than that requested, the
1256 * timeout was reached before the requested number of bytes was
1257 * available. If timeout is zero, the function will always return
1258 * either the requested number of bytes or a negative error code.
1262 SP_API enum sp_return sp_blocking_read(struct sp_port *port, void *buf, size_t count, unsigned int timeout_ms);
1265 * Read bytes from the specified serial port, returning as soon as any data is
1268 * @warning If your program runs on Unix, defines its own signal handlers, and
1269 * needs to abort blocking reads when these are called, then you
1270 * should not use this function. It repeats system calls that return
1271 * with EINTR. To be able to abort a read from a signal handler, you
1272 * should implement your own blocking read using sp_nonblocking_read()
1273 * together with a blocking method that makes sense for your program.
1274 * E.g. you can obtain the file descriptor for an open port using
1275 * sp_get_port_handle() and use this to call select() or pselect(),
1276 * with appropriate arrangements to return if a signal is received.
1278 * @param[in] port Pointer to a port structure. Must not be NULL.
1279 * @param[out] buf Buffer in which to store the bytes read. Must not be NULL.
1280 * @param[in] count Maximum number of bytes to read. Must not be zero.
1281 * @param[in] timeout_ms Timeout in milliseconds, or zero to wait indefinitely.
1283 * @return The number of bytes read on success, or a negative error code. If
1284 * the result is zero, the timeout was reached before any bytes were
1285 * available. If timeout_ms is zero, the function will always return
1286 * either at least one byte, or a negative error code.
1290 SP_API enum sp_return sp_blocking_read_next(struct sp_port *port, void *buf, size_t count, unsigned int timeout_ms);
1293 * Read bytes from the specified serial port, without blocking.
1295 * @param[in] port Pointer to a port structure. Must not be NULL.
1296 * @param[out] buf Buffer in which to store the bytes read. Must not be NULL.
1297 * @param[in] count Maximum number of bytes to read.
1299 * @return The number of bytes read on success, or a negative error code. The
1300 * number of bytes returned may be any number from zero to the maximum
1301 * that was requested.
1305 SP_API enum sp_return sp_nonblocking_read(struct sp_port *port, void *buf, size_t count);
1308 * Write bytes to the specified serial port, blocking until complete.
1310 * Note that this function only ensures that the accepted bytes have been
1311 * written to the OS; they may be held in driver or hardware buffers and not
1312 * yet physically transmitted. To check whether all written bytes have actually
1313 * been transmitted, use the sp_output_waiting() function. To wait until all
1314 * written bytes have actually been transmitted, use the sp_drain() function.
1316 * @warning If your program runs on Unix, defines its own signal handlers, and
1317 * needs to abort blocking writes when these are called, then you
1318 * should not use this function. It repeats system calls that return
1319 * with EINTR. To be able to abort a write from a signal handler, you
1320 * should implement your own blocking write using sp_nonblocking_write()
1321 * together with a blocking method that makes sense for your program.
1322 * E.g. you can obtain the file descriptor for an open port using
1323 * sp_get_port_handle() and use this to call select() or pselect(),
1324 * with appropriate arrangements to return if a signal is received.
1326 * @param[in] port Pointer to a port structure. Must not be NULL.
1327 * @param[in] buf Buffer containing the bytes to write. Must not be NULL.
1328 * @param[in] count Requested number of bytes to write.
1329 * @param[in] timeout_ms Timeout in milliseconds, or zero to wait indefinitely.
1331 * @return The number of bytes written on success, or a negative error code.
1332 * If the number of bytes returned is less than that requested, the
1333 * timeout was reached before the requested number of bytes was
1334 * written. If timeout is zero, the function will always return
1335 * either the requested number of bytes or a negative error code. In
1336 * the event of an error there is no way to determine how many bytes
1337 * were sent before the error occurred.
1341 SP_API enum sp_return sp_blocking_write(struct sp_port *port, const void *buf, size_t count, unsigned int timeout_ms);
1344 * Write bytes to the specified serial port, without blocking.
1346 * Note that this function only ensures that the accepted bytes have been
1347 * written to the OS; they may be held in driver or hardware buffers and not
1348 * yet physically transmitted. To check whether all written bytes have actually
1349 * been transmitted, use the sp_output_waiting() function. To wait until all
1350 * written bytes have actually been transmitted, use the sp_drain() function.
1352 * @param[in] port Pointer to a port structure. Must not be NULL.
1353 * @param[in] buf Buffer containing the bytes to write. Must not be NULL.
1354 * @param[in] count Maximum number of bytes to write.
1356 * @return The number of bytes written on success, or a negative error code.
1357 * The number of bytes returned may be any number from zero to the
1358 * maximum that was requested.
1362 SP_API enum sp_return sp_nonblocking_write(struct sp_port *port, const void *buf, size_t count);
1365 * Gets the number of bytes waiting in the input buffer.
1367 * @param[in] port Pointer to a port structure. Must not be NULL.
1369 * @return Number of bytes waiting on success, a negative error code otherwise.
1373 SP_API enum sp_return sp_input_waiting(struct sp_port *port);
1376 * Gets the number of bytes waiting in the output buffer.
1378 * @param[in] port Pointer to a port structure. Must not be NULL.
1380 * @return Number of bytes waiting on success, a negative error code otherwise.
1384 SP_API enum sp_return sp_output_waiting(struct sp_port *port);
1387 * Flush serial port buffers. Data in the selected buffer(s) is discarded.
1389 * @param[in] port Pointer to a port structure. Must not be NULL.
1390 * @param[in] buffers Which buffer(s) to flush.
1392 * @return SP_OK upon success, a negative error code otherwise.
1396 SP_API enum sp_return sp_flush(struct sp_port *port, enum sp_buffer buffers);
1399 * Wait for buffered data to be transmitted.
1401 * @warning If your program runs on Unix, defines its own signal handlers, and
1402 * needs to abort draining the output buffer when when these are
1403 * called, then you should not use this function. It repeats system
1404 * calls that return with EINTR. To be able to abort a drain from a
1405 * signal handler, you would need to implement your own blocking
1406 * drain by polling the result of sp_output_waiting().
1408 * @param[in] port Pointer to a port structure. Must not be NULL.
1410 * @return SP_OK upon success, a negative error code otherwise.
1414 SP_API enum sp_return sp_drain(struct sp_port *port);
1419 * @defgroup Waiting Waiting
1421 * Waiting for events and timeout handling.
1427 * Allocate storage for a set of events.
1429 * The user should allocate a variable of type struct sp_event_set *,
1430 * then pass a pointer to this variable to receive the result.
1432 * The result should be freed after use by calling sp_free_event_set().
1434 * @param[out] result_ptr If any error is returned, the variable pointed to by
1435 * result_ptr will be set to NULL. Otherwise, it will
1436 * be set to point to the event set. Must not be NULL.
1438 * @return SP_OK upon success, a negative error code otherwise.
1442 SP_API enum sp_return sp_new_event_set(struct sp_event_set **result_ptr);
1445 * Add events to a struct sp_event_set for a given port.
1447 * The port must first be opened by calling sp_open() using the same port
1450 * After the port is closed or the port structure freed, the results may
1451 * no longer be valid.
1453 * @param[in,out] event_set Event set to update. Must not be NULL.
1454 * @param[in] port Pointer to a port structure. Must not be NULL.
1455 * @param[in] mask Bitmask of events to be waited for.
1457 * @return SP_OK upon success, a negative error code otherwise.
1461 SP_API enum sp_return sp_add_port_events(struct sp_event_set *event_set,
1462 const struct sp_port *port, enum sp_event mask);
1465 * Wait for any of a set of events to occur.
1467 * @param[in] event_set Event set to wait on. Must not be NULL.
1468 * @param[in] timeout_ms Timeout in milliseconds, or zero to wait indefinitely.
1470 * @return SP_OK upon success, a negative error code otherwise.
1474 SP_API enum sp_return sp_wait(struct sp_event_set *event_set, unsigned int timeout_ms);
1477 * Free a structure allocated by sp_new_event_set().
1479 * @param[in] event_set Event set to free. Must not be NULL.
1483 SP_API void sp_free_event_set(struct sp_event_set *event_set);
1488 * @defgroup Signals Signals
1490 * Port signalling operations.
1496 * Gets the status of the control signals for the specified port.
1498 * The user should allocate a variable of type "enum sp_signal" and pass a
1499 * pointer to this variable to receive the result. The result is a bitmask
1500 * in which individual signals can be checked by bitwise OR with values of
1501 * the sp_signal enum.
1503 * @param[in] port Pointer to a port structure. Must not be NULL.
1504 * @param[out] signal_mask Pointer to a variable to receive the result.
1507 * @return SP_OK upon success, a negative error code otherwise.
1511 SP_API enum sp_return sp_get_signals(struct sp_port *port, enum sp_signal *signal_mask);
1514 * Put the port transmit line into the break state.
1516 * @param[in] port Pointer to a port structure. Must not be NULL.
1518 * @return SP_OK upon success, a negative error code otherwise.
1522 SP_API enum sp_return sp_start_break(struct sp_port *port);
1525 * Take the port transmit line out of the break state.
1527 * @param[in] port Pointer to a port structure. Must not be NULL.
1529 * @return SP_OK upon success, a negative error code otherwise.
1533 SP_API enum sp_return sp_end_break(struct sp_port *port);
1538 * @defgroup Errors Errors
1540 * Obtaining error information.
1546 * Get the error code for a failed operation.
1548 * In order to obtain the correct result, this function should be called
1549 * straight after the failure, before executing any other system operations.
1550 * The result is thread-specific, and only valid when called immediately
1551 * after a previous call returning SP_ERR_FAIL.
1553 * @return The system's numeric code for the error that caused the last
1554 * operation to fail.
1558 SP_API int sp_last_error_code(void);
1561 * Get the error message for a failed operation.
1563 * In order to obtain the correct result, this function should be called
1564 * straight after the failure, before executing other system operations.
1565 * The result is thread-specific, and only valid when called immediately
1566 * after a previous call returning SP_ERR_FAIL.
1568 * @return The system's message for the error that caused the last
1569 * operation to fail. This string may be allocated by the function,
1570 * and should be freed after use by calling sp_free_error_message().
1574 SP_API char *sp_last_error_message(void);
1577 * Free an error message returned by sp_last_error_message().
1579 * @param[in] message The error message string to free. Must not be NULL.
1583 SP_API void sp_free_error_message(char *message);
1586 * Set the handler function for library debugging messages.
1588 * Debugging messages are generated by the library during each operation,
1589 * to help in diagnosing problems. The handler will be called for each
1590 * message. The handler can be set to NULL to ignore all debug messages.
1592 * The handler function should accept a format string and variable length
1593 * argument list, in the same manner as e.g. printf().
1595 * The default handler is sp_default_debug_handler().
1597 * @param[in] handler The handler function to use. Can be NULL (in that case
1598 * all debug messages will be ignored).
1602 SP_API void sp_set_debug_handler(void (*handler)(const char *format, ...));
1605 * Default handler function for library debugging messages.
1607 * This function prints debug messages to the standard error stream if the
1608 * environment variable LIBSERIALPORT_DEBUG is set. Otherwise, they are
1611 * @param[in] format The format string to use. Must not be NULL.
1612 * @param[in] ... The variable length argument list to use.
1616 SP_API void sp_default_debug_handler(const char *format, ...);
1621 * @defgroup Versions Versions
1623 * Version number querying functions, definitions, and macros.
1625 * This set of API calls returns two different version numbers related
1626 * to libserialport. The "package version" is the release version number of the
1627 * libserialport tarball in the usual "major.minor.micro" format, e.g. "0.1.0".
1629 * The "library version" is independent of that; it is the libtool version
1630 * number in the "current:revision:age" format, e.g. "2:0:0".
1631 * See http://www.gnu.org/software/libtool/manual/libtool.html#Libtool-versioning for details.
1633 * Both version numbers (and/or individual components of them) can be
1634 * retrieved via the API calls at runtime, and/or they can be checked at
1635 * compile/preprocessor time using the respective macros.
1641 * Package version macros (can be used for conditional compilation).
1644 /** The libserialport package 'major' version number. */
1645 #define SP_PACKAGE_VERSION_MAJOR 0
1647 /** The libserialport package 'minor' version number. */
1648 #define SP_PACKAGE_VERSION_MINOR 1
1650 /** The libserialport package 'micro' version number. */
1651 #define SP_PACKAGE_VERSION_MICRO 1
1653 /** The libserialport package version ("major.minor.micro") as string. */
1654 #define SP_PACKAGE_VERSION_STRING "0.1.1"
1657 * Library/libtool version macros (can be used for conditional compilation).
1660 /** The libserialport libtool 'current' version number. */
1661 #define SP_LIB_VERSION_CURRENT 1
1663 /** The libserialport libtool 'revision' version number. */
1664 #define SP_LIB_VERSION_REVISION 0
1666 /** The libserialport libtool 'age' version number. */
1667 #define SP_LIB_VERSION_AGE 1
1669 /** The libserialport libtool version ("current:revision:age") as string. */
1670 #define SP_LIB_VERSION_STRING "1:0:1"
1673 * Get the major libserialport package version number.
1675 * @return The major package version number.
1679 SP_API int sp_get_major_package_version(void);
1682 * Get the minor libserialport package version number.
1684 * @return The minor package version number.
1688 SP_API int sp_get_minor_package_version(void);
1691 * Get the micro libserialport package version number.
1693 * @return The micro package version number.
1697 SP_API int sp_get_micro_package_version(void);
1700 * Get the libserialport package version number as a string.
1702 * @return The package version number string. The returned string is
1703 * static and thus should NOT be free'd by the caller.
1707 SP_API const char *sp_get_package_version_string(void);
1710 * Get the "current" part of the libserialport library version number.
1712 * @return The "current" library version number.
1716 SP_API int sp_get_current_lib_version(void);
1719 * Get the "revision" part of the libserialport library version number.
1721 * @return The "revision" library version number.
1725 SP_API int sp_get_revision_lib_version(void);
1728 * Get the "age" part of the libserialport library version number.
1730 * @return The "age" library version number.
1734 SP_API int sp_get_age_lib_version(void);
1737 * Get the libserialport library version number as a string.
1739 * @return The library version number string. The returned string is
1740 * static and thus should NOT be free'd by the caller.
1744 SP_API const char *sp_get_lib_version_string(void);
1749 * @example list_ports.c Getting a list of ports present on the system.
1750 * @example port_info.c Getting information on a particular serial port.
1751 * @example port_config.c Accessing configuration settings of a port.