configure: Check whether clock_gettime is available.
[libserialport/gsi.git] / libserialport.h.in
blob8962ef8d942eb5fb6f368408b62feea9998a2a97
1 /*
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/>.
22 /**
23 * @mainpage libserialport API
25 * Introduction
26 * ============
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
38 * latest information.
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.
49 * API information
50 * ===============
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.
62 * The following subsections will help explain the principles of the API.
64 * Headers
65 * -------
67 * To use libserialport functions in your code, you should include the
68 * libserialport.h header, i.e. "#include <libserialport.h>".
70 * Namespace
71 * ---------
73 * All identifiers defined by the public libserialport headers use the prefix
74 * sp_ (for functions and data types) or SP_ (for macros and constants).
76 * Functions
77 * ---------
79 * The functions provided by the library are documented in detail in
80 * the following sections:
82 * - @ref Enumeration (obtaining a list of serial ports on the system)
83 * - @ref Ports (opening, closing and getting information about ports)
84 * - @ref Configuration (baud rate, parity, etc.)
85 * - @ref Signals (modem control lines, breaks, etc.)
86 * - @ref Data (reading and writing data, and buffer management)
87 * - @ref Waiting (waiting for ports to be ready, integrating with event loops)
88 * - @ref Errors (getting error and debugging information)
90 * Data structures
91 * ---------------
93 * The library defines three data structures:
95 * - @ref sp_port, which represents a serial port.
96 * See @ref Enumeration.
97 * - @ref sp_port_config, which represents a port configuration.
98 * See @ref Configuration.
99 * - @ref sp_event_set, which represents a set of events.
100 * See @ref Waiting.
102 * All these structures are allocated and freed by library functions. It is
103 * the caller's responsibility to ensure that the correct calls are made to
104 * free allocated structures after use.
106 * Return codes and error handling
107 * -------------------------------
109 * Most functions have return type @ref sp_return and can return only four
110 * possible error values:
112 * - @ref SP_ERR_ARG means that a function was called with invalid
113 * arguments. This implies a bug in the caller. The arguments passed would
114 * be invalid regardless of the underlying OS or serial device involved.
116 * - @ref SP_ERR_FAIL means that the OS reported a failure. The error code or
117 * message provided by the OS can be obtained by calling sp_last_error_code()
118 * or sp_last_error_message().
120 * - @ref SP_ERR_SUPP indicates that there is no support for the requested
121 * operation in the current OS, driver or device. No error message is
122 * available from the OS in this case. There is either no way to request
123 * the operation in the first place, or libserialport does not know how to
124 * do so in the current version.
126 * - @ref SP_ERR_MEM indicates that a memory allocation failed.
128 * All of these error values are negative.
130 * Calls that succeed return @ref SP_OK, which is equal to zero. Some functions
131 * declared @ref sp_return can also return a positive value for a successful
132 * numeric result, e.g. sp_blocking_read() or sp_blocking_write().
134 * An error message is only available via sp_last_error_message() in the case
135 * where SP_ERR_FAIL was returned by the previous function call. The error
136 * message returned is that provided by the OS, using the current language
137 * settings. It is an error to call sp_last_error_code() or
138 * sp_last_error_message() except after a previous function call returned
139 * SP_ERR_FAIL. The library does not define its own error codes or messages
140 * to accompany other return codes.
142 * Thread safety
143 * -------------
145 * Certain combinations of calls can be made concurrently, as follows.
147 * - Calls using different ports may always be made concurrently, i.e.
148 * it is safe for separate threads to handle their own ports.
150 * - Calls using the same port may be made concurrently when one call
151 * is a read operation and one call is a write operation, i.e. it is safe
152 * to use separate "reader" and "writer" threads for the same port. See
153 * below for which operations meet these definitions.
155 * Read operations:
157 * - sp_blocking_read()
158 * - sp_blocking_read_next()
159 * - sp_nonblocking_read()
160 * - sp_input_waiting()
161 * - sp_flush() with @ref SP_BUF_INPUT only.
162 * - sp_wait() with @ref SP_EVENT_RX_READY only.
164 * Write operations:
166 * - sp_blocking_write()
167 * - sp_nonblocking_write()
168 * - sp_output_waiting()
169 * - sp_drain()
170 * - sp_flush() with @ref SP_BUF_OUTPUT only.
171 * - sp_wait() with @ref SP_EVENT_TX_READY only.
173 * If two calls, on the same port, do not fit into one of these categories
174 * each, then they may not be made concurrently.
176 * Debugging
177 * ---------
179 * The library can output extensive tracing and debugging information. The
180 * simplest way to use this is to set the environment variable
181 * LIBSERIALPORT_DEBUG to any value; messages will then be output to the
182 * standard error stream.
184 * This behaviour is implemented by a default debug message handling
185 * callback. An alternative callback can be set using sp_set_debug_handler(),
186 * in order to e.g. redirect the output elsewhere or filter it.
188 * No guarantees are made about the content of the debug output; it is chosen
189 * to suit the needs of the developers and may change between releases.
191 * @anchor Porting
192 * Porting
193 * -------
195 * The following guidelines may help when porting existing OS-specific code
196 * to use libserialport.
198 * ### Porting from Unix-like systems ###
200 * There are two main differences to note when porting code written for Unix.
202 * The first is that Unix traditionally provides a wide range of functionality
203 * for dealing with serial devices at the OS level; this is exposed through the
204 * termios API and dates to the days when serial terminals were common. If your
205 * code relies on many of these facilities you will need to adapt it, because
206 * libserialport provides only a raw binary channel with no special handling.
208 * The second relates to blocking versus non-blocking I/O behaviour. In
209 * Unix-like systems this is normally specified by setting the O_NONBLOCK
210 * flag on the file descriptor, affecting the semantics of subsequent read()
211 * and write() calls.
213 * In libserialport, blocking and nonblocking operations are both available at
214 * any time. If your existing code Ń•ets O_NONBLOCK, you should use
215 * sp_nonblocking_read() and sp_nonblocking_write() to get the same behaviour
216 * as your existing read() and write() calls. If it does not, you should use
217 * sp_blocking_read() and sp_blocking_write() instead. You may also find
218 * sp_blocking_read_next() useful, which reproduces the semantics of a blocking
219 * read() with VTIME = 0 and VMIN = 1 set in termios.
221 * Finally, you should take care if your program uses custom signal handlers.
222 * The blocking calls provided by libserialport will restart system calls that
223 * return with EINTR, so you will need to make your own arrangements if you
224 * need to interrupt blocking operations when your signal handlers are called.
225 * This is not an issue if you only use the default handlers.
227 * ### Porting from Windows ###
229 * The main consideration when porting from Windows is that there is no
230 * direct equivalent for overlapped I/O operations.
232 * If your program does not use overlapped I/O, you can simply use
233 * sp_blocking_read() and sp_blocking_write() as direct equivalents for
234 * ReadFile() and WriteFile(). You may also find sp_blocking_read_next()
235 * useful, which reproduces the special semantics of ReadFile() with
236 * ReadIntervalTimeout and ReadTotalTimeoutMultiplier set to MAXDWORD
237 * and 0 < ReadTotalTimeoutConstant < MAXDWORD.
239 * If your program makes use of overlapped I/O to continue work while a serial
240 * operation is in progress, then you can achieve the same results using
241 * sp_nonblocking_read() and sp_nonblocking_write().
243 * Generally, overlapped I/O is combined with either waiting for completion
244 * once there is no more background work to do (using WaitForSingleObject() or
245 * WaitForMultipleObjects()), or periodically checking for completion with
246 * GetOverlappedResult(). If the aim is to start a new operation for further
247 * data once the previous one has completed, you can instead simply call the
248 * nonblocking functions again with the next data. If you need to wait for
249 * completion, use sp_wait() to determine when the port is ready to send or
250 * receive further data.
253 #ifndef LIBSERIALPORT_LIBSERIALPORT_H
254 #define LIBSERIALPORT_LIBSERIALPORT_H
256 #ifdef __cplusplus
257 extern "C" {
258 #endif
260 #include <stddef.h>
262 /** Return values. */
263 enum sp_return {
264 /** Operation completed successfully. */
265 SP_OK = 0,
266 /** Invalid arguments were passed to the function. */
267 SP_ERR_ARG = -1,
268 /** A system error occurred while executing the operation. */
269 SP_ERR_FAIL = -2,
270 /** A memory allocation failed while executing the operation. */
271 SP_ERR_MEM = -3,
272 /** The requested operation is not supported by this system or device. */
273 SP_ERR_SUPP = -4
276 /** Port access modes. */
277 enum sp_mode {
278 /** Open port for read access. */
279 SP_MODE_READ = 1,
280 /** Open port for write access. */
281 SP_MODE_WRITE = 2,
282 /** Open port for read and write access. @since 0.1.1 */
283 SP_MODE_READ_WRITE = 3
286 /** Port events. */
287 enum sp_event {
288 /** Data received and ready to read. */
289 SP_EVENT_RX_READY = 1,
290 /** Ready to transmit new data. */
291 SP_EVENT_TX_READY = 2,
292 /** Error occurred. */
293 SP_EVENT_ERROR = 4
296 /** Buffer selection. */
297 enum sp_buffer {
298 /** Input buffer. */
299 SP_BUF_INPUT = 1,
300 /** Output buffer. */
301 SP_BUF_OUTPUT = 2,
302 /** Both buffers. */
303 SP_BUF_BOTH = 3
306 /** Parity settings. */
307 enum sp_parity {
308 /** Special value to indicate setting should be left alone. */
309 SP_PARITY_INVALID = -1,
310 /** No parity. */
311 SP_PARITY_NONE = 0,
312 /** Odd parity. */
313 SP_PARITY_ODD = 1,
314 /** Even parity. */
315 SP_PARITY_EVEN = 2,
316 /** Mark parity. */
317 SP_PARITY_MARK = 3,
318 /** Space parity. */
319 SP_PARITY_SPACE = 4
322 /** RTS pin behaviour. */
323 enum sp_rts {
324 /** Special value to indicate setting should be left alone. */
325 SP_RTS_INVALID = -1,
326 /** RTS off. */
327 SP_RTS_OFF = 0,
328 /** RTS on. */
329 SP_RTS_ON = 1,
330 /** RTS used for flow control. */
331 SP_RTS_FLOW_CONTROL = 2
334 /** CTS pin behaviour. */
335 enum sp_cts {
336 /** Special value to indicate setting should be left alone. */
337 SP_CTS_INVALID = -1,
338 /** CTS ignored. */
339 SP_CTS_IGNORE = 0,
340 /** CTS used for flow control. */
341 SP_CTS_FLOW_CONTROL = 1
344 /** DTR pin behaviour. */
345 enum sp_dtr {
346 /** Special value to indicate setting should be left alone. */
347 SP_DTR_INVALID = -1,
348 /** DTR off. */
349 SP_DTR_OFF = 0,
350 /** DTR on. */
351 SP_DTR_ON = 1,
352 /** DTR used for flow control. */
353 SP_DTR_FLOW_CONTROL = 2
356 /** DSR pin behaviour. */
357 enum sp_dsr {
358 /** Special value to indicate setting should be left alone. */
359 SP_DSR_INVALID = -1,
360 /** DSR ignored. */
361 SP_DSR_IGNORE = 0,
362 /** DSR used for flow control. */
363 SP_DSR_FLOW_CONTROL = 1
366 /** XON/XOFF flow control behaviour. */
367 enum sp_xonxoff {
368 /** Special value to indicate setting should be left alone. */
369 SP_XONXOFF_INVALID = -1,
370 /** XON/XOFF disabled. */
371 SP_XONXOFF_DISABLED = 0,
372 /** XON/XOFF enabled for input only. */
373 SP_XONXOFF_IN = 1,
374 /** XON/XOFF enabled for output only. */
375 SP_XONXOFF_OUT = 2,
376 /** XON/XOFF enabled for input and output. */
377 SP_XONXOFF_INOUT = 3
380 /** Standard flow control combinations. */
381 enum sp_flowcontrol {
382 /** No flow control. */
383 SP_FLOWCONTROL_NONE = 0,
384 /** Software flow control using XON/XOFF characters. */
385 SP_FLOWCONTROL_XONXOFF = 1,
386 /** Hardware flow control using RTS/CTS signals. */
387 SP_FLOWCONTROL_RTSCTS = 2,
388 /** Hardware flow control using DTR/DSR signals. */
389 SP_FLOWCONTROL_DTRDSR = 3
392 /** Input signals. */
393 enum sp_signal {
394 /** Clear to send. */
395 SP_SIG_CTS = 1,
396 /** Data set ready. */
397 SP_SIG_DSR = 2,
398 /** Data carrier detect. */
399 SP_SIG_DCD = 4,
400 /** Ring indicator. */
401 SP_SIG_RI = 8
405 * Transport types.
407 * @since 0.1.1
409 enum sp_transport {
410 /** Native platform serial port. @since 0.1.1 */
411 SP_TRANSPORT_NATIVE,
412 /** USB serial port adapter. @since 0.1.1 */
413 SP_TRANSPORT_USB,
414 /** Bluetooth serial port adapter. @since 0.1.1 */
415 SP_TRANSPORT_BLUETOOTH
419 * @struct sp_port
420 * An opaque structure representing a serial port.
422 struct sp_port;
425 * @struct sp_port_config
426 * An opaque structure representing the configuration for a serial port.
428 struct sp_port_config;
431 * @struct sp_event_set
432 * A set of handles to wait on for events.
434 struct sp_event_set {
435 /** Array of OS-specific handles. */
436 void *handles;
437 /** Array of bitmasks indicating which events apply for each handle. */
438 enum sp_event *masks;
439 /** Number of handles. */
440 unsigned int count;
444 * @defgroup Enumeration Port enumeration
446 * Enumerating the serial ports of a system.
448 * @{
452 * Obtain a pointer to a new sp_port structure representing the named port.
454 * The user should allocate a variable of type "struct sp_port *" and pass a
455 * pointer to this to receive the result.
457 * The result should be freed after use by calling sp_free_port().
459 * @param[in] portname The OS-specific name of a serial port. Must not be NULL.
460 * @param[out] port_ptr If any error is returned, the variable pointed to by
461 * port_ptr will be set to NULL. Otherwise, it will be set
462 * to point to the newly allocated port. Must not be NULL.
464 * @return SP_OK upon success, a negative error code otherwise.
466 * @since 0.1.0
468 enum sp_return sp_get_port_by_name(const char *portname, struct sp_port **port_ptr);
471 * Free a port structure obtained from sp_get_port_by_name() or sp_copy_port().
473 * @param[in] port Pointer to a port structure. Must not be NULL.
475 * @since 0.1.0
477 void sp_free_port(struct sp_port *port);
480 * List the serial ports available on the system.
482 * The result obtained is an array of pointers to sp_port structures,
483 * terminated by a NULL. The user should allocate a variable of type
484 * "struct sp_port **" and pass a pointer to this to receive the result.
486 * The result should be freed after use by calling sp_free_port_list().
487 * If a port from the list is to be used after freeing the list, it must be
488 * copied first using sp_copy_port().
490 * @param[out] list_ptr If any error is returned, the variable pointed to by
491 * list_ptr will be set to NULL. Otherwise, it will be set
492 * to point to the newly allocated array. Must not be NULL.
494 * @return SP_OK upon success, a negative error code otherwise.
496 * @since 0.1.0
498 enum sp_return sp_list_ports(struct sp_port ***list_ptr);
501 * Make a new copy of an sp_port structure.
503 * The user should allocate a variable of type "struct sp_port *" and pass a
504 * pointer to this to receive the result.
506 * The copy should be freed after use by calling sp_free_port().
508 * @param[in] port Pointer to a port structure. Must not be NULL.
509 * @param[out] copy_ptr If any error is returned, the variable pointed to by
510 * copy_ptr will be set to NULL. Otherwise, it will be set
511 * to point to the newly allocated copy. Must not be NULL.
513 * @return SP_OK upon success, a negative error code otherwise.
515 * @since 0.1.0
517 enum sp_return sp_copy_port(const struct sp_port *port, struct sp_port **copy_ptr);
520 * Free a port list obtained from sp_list_ports().
522 * This will also free all the sp_port structures referred to from the list;
523 * any that are to be retained must be copied first using sp_copy_port().
525 * @param[in] ports Pointer to a list of port structures. Must not be NULL.
527 * @since 0.1.0
529 void sp_free_port_list(struct sp_port **ports);
532 * @}
533 * @defgroup Ports Port handling
535 * Opening, closing and querying ports.
537 * @{
541 * Open the specified serial port.
543 * @param[in] port Pointer to a port structure. Must not be NULL.
544 * @param[in] flags Flags to use when opening the serial port.
546 * @return SP_OK upon success, a negative error code otherwise.
548 * @since 0.1.0
550 enum sp_return sp_open(struct sp_port *port, enum sp_mode flags);
553 * Close the specified serial port.
555 * @param[in] port Pointer to a port structure. Must not be NULL.
557 * @return SP_OK upon success, a negative error code otherwise.
559 * @since 0.1.0
561 enum sp_return sp_close(struct sp_port *port);
564 * Get the name of a port.
566 * The name returned is whatever is normally used to refer to a port on the
567 * current operating system; e.g. for Windows it will usually be a "COMn"
568 * device name, and for Unix it will be a device path beginning with "/dev/".
570 * @param[in] port Pointer to a port structure. Must not be NULL.
572 * @return The port name, or NULL if an invalid port is passed. The name
573 * string is part of the port structure and may not be used after
574 * the port structure has been freed.
576 * @since 0.1.0
578 char *sp_get_port_name(const struct sp_port *port);
581 * Get a description for a port, to present to end user.
583 * @param[in] port Pointer to a port structure. Must not be NULL.
585 * @return The port description, or NULL if an invalid port is passed.
586 * The description string is part of the port structure and may not
587 * be used after the port structure has been freed.
589 * @since 0.1.1
591 char *sp_get_port_description(const struct sp_port *port);
594 * Get the transport type used by a port.
596 * @param[in] port Pointer to a port structure. Must not be NULL.
598 * @return The port transport type.
600 * @since 0.1.1
602 enum sp_transport sp_get_port_transport(const struct sp_port *port);
605 * Get the USB bus number and address on bus of a USB serial adapter port.
607 * @param[in] port Pointer to a port structure. Must not be NULL.
608 * @param[out] usb_bus Pointer to a variable to store the USB bus.
609 * Can be NULL (in that case it will be ignored).
610 * @param[out] usb_address Pointer to a variable to store the USB address.
611 * Can be NULL (in that case it will be ignored).
613 * @return SP_OK upon success, a negative error code otherwise.
615 * @since 0.1.1
617 enum sp_return sp_get_port_usb_bus_address(const struct sp_port *port,
618 int *usb_bus, int *usb_address);
621 * Get the USB Vendor ID and Product ID of a USB serial adapter port.
623 * @param[in] port Pointer to a port structure. Must not be NULL.
624 * @param[out] usb_vid Pointer to a variable to store the USB VID.
625 * Can be NULL (in that case it will be ignored).
626 * @param[out] usb_pid Pointer to a variable to store the USB PID.
627 * Can be NULL (in that case it will be ignored).
629 * @return SP_OK upon success, a negative error code otherwise.
631 * @since 0.1.1
633 enum sp_return sp_get_port_usb_vid_pid(const struct sp_port *port, int *usb_vid, int *usb_pid);
636 * Get the USB manufacturer string of a USB serial adapter port.
638 * @param[in] port Pointer to a port structure. Must not be NULL.
640 * @return The port manufacturer string, or NULL if an invalid port is passed.
641 * The manufacturer string is part of the port structure and may not
642 * be used after the port structure has been freed.
644 * @since 0.1.1
646 char *sp_get_port_usb_manufacturer(const struct sp_port *port);
649 * Get the USB product string of a USB serial adapter port.
651 * @param[in] port Pointer to a port structure. Must not be NULL.
653 * @return The port product string, or NULL if an invalid port is passed.
654 * The product string is part of the port structure and may not be
655 * used after the port structure has been freed.
657 * @since 0.1.1
659 char *sp_get_port_usb_product(const struct sp_port *port);
662 * Get the USB serial number string of a USB serial adapter port.
664 * @param[in] port Pointer to a port structure. Must not be NULL.
666 * @return The port serial number, or NULL if an invalid port is passed.
667 * The serial number string is part of the port structure and may
668 * not be used after the port structure has been freed.
670 * @since 0.1.1
672 char *sp_get_port_usb_serial(const struct sp_port *port);
675 * Get the MAC address of a Bluetooth serial adapter port.
677 * @param[in] port Pointer to a port structure. Must not be NULL.
679 * @return The port MAC address, or NULL if an invalid port is passed.
680 * The MAC address string is part of the port structure and may not
681 * be used after the port structure has been freed.
683 * @since 0.1.1
685 char *sp_get_port_bluetooth_address(const struct sp_port *port);
688 * Get the operating system handle for a port.
690 * The type of the handle depends on the operating system. On Unix based
691 * systems, the handle is a file descriptor of type "int". On Windows, the
692 * handle is of type "HANDLE". The user should allocate a variable of the
693 * appropriate type and pass a pointer to this to receive the result.
695 * To obtain a valid handle, the port must first be opened by calling
696 * sp_open() using the same port structure.
698 * After the port is closed or the port structure freed, the handle may
699 * no longer be valid.
701 * @warning This feature is provided so that programs may make use of
702 * OS-specific functionality where desired. Doing so obviously
703 * comes at a cost in portability. It also cannot be guaranteed
704 * that direct usage of the OS handle will not conflict with the
705 * library's own usage of the port. Be careful.
707 * @param[in] port Pointer to a port structure. Must not be NULL.
708 * @param[out] result_ptr If any error is returned, the variable pointed to by
709 * result_ptr will have unknown contents and should not
710 * be used. Otherwise, it will be set to point to the
711 * OS handle. Must not be NULL.
713 * @return SP_OK upon success, a negative error code otherwise.
715 * @since 0.1.0
717 enum sp_return sp_get_port_handle(const struct sp_port *port, void *result_ptr);
720 * @}
722 * @defgroup Configuration Configuration
724 * Setting and querying serial port parameters.
725 * @{
729 * Allocate a port configuration structure.
731 * The user should allocate a variable of type "struct sp_port_config *" and
732 * pass a pointer to this to receive the result. The variable will be updated
733 * to point to the new configuration structure. The structure is opaque and
734 * must be accessed via the functions provided.
736 * All parameters in the structure will be initialised to special values which
737 * are ignored by sp_set_config().
739 * The structure should be freed after use by calling sp_free_config().
741 * @param[out] config_ptr If any error is returned, the variable pointed to by
742 * config_ptr will be set to NULL. Otherwise, it will
743 * be set to point to the allocated config structure.
744 * Must not be NULL.
746 * @return SP_OK upon success, a negative error code otherwise.
748 * @since 0.1.0
750 enum sp_return sp_new_config(struct sp_port_config **config_ptr);
753 * Free a port configuration structure.
755 * @param[in] config Pointer to a configuration structure. Must not be NULL.
757 * @since 0.1.0
759 void sp_free_config(struct sp_port_config *config);
762 * Get the current configuration of the specified serial port.
764 * The user should allocate a configuration structure using sp_new_config()
765 * and pass this as the config parameter. The configuration structure will
766 * be updated with the port configuration.
768 * Any parameters that are configured with settings not recognised or
769 * supported by libserialport, will be set to special values that are
770 * ignored by sp_set_config().
772 * @param[in] port Pointer to a port structure. Must not be NULL.
773 * @param[out] config Pointer to a configuration structure that will hold
774 * the result. Upon errors the contents of the config
775 * struct will not be changed. Must not be NULL.
777 * @return SP_OK upon success, a negative error code otherwise.
779 * @since 0.1.0
781 enum sp_return sp_get_config(struct sp_port *port, struct sp_port_config *config);
784 * Set the configuration for the specified serial port.
786 * For each parameter in the configuration, there is a special value (usually
787 * -1, but see the documentation for each field). These values will be ignored
788 * and the corresponding setting left unchanged on the port.
790 * Upon errors, the configuration of the serial port is unknown since
791 * partial/incomplete config updates may have happened.
793 * @param[in] port Pointer to a port structure. Must not be NULL.
794 * @param[in] config Pointer to a configuration structure. Must not be NULL.
796 * @return SP_OK upon success, a negative error code otherwise.
798 * @since 0.1.0
800 enum sp_return sp_set_config(struct sp_port *port, const struct sp_port_config *config);
803 * Set the baud rate for the specified serial port.
805 * @param[in] port Pointer to a port structure. Must not be NULL.
806 * @param[in] baudrate Baud rate in bits per second.
808 * @return SP_OK upon success, a negative error code otherwise.
810 * @since 0.1.0
812 enum sp_return sp_set_baudrate(struct sp_port *port, int baudrate);
815 * Get the baud rate from a port configuration.
817 * The user should allocate a variable of type int and
818 * pass a pointer to this to receive the result.
820 * @param[in] config Pointer to a configuration structure. Must not be NULL.
821 * @param[out] baudrate_ptr Pointer to a variable to store the result. Must not be NULL.
823 * @return SP_OK upon success, a negative error code otherwise.
825 * @since 0.1.0
827 enum sp_return sp_get_config_baudrate(const struct sp_port_config *config, int *baudrate_ptr);
830 * Set the baud rate in a port configuration.
832 * @param[in] config Pointer to a configuration structure. Must not be NULL.
833 * @param[in] baudrate Baud rate in bits per second, or -1 to retain the current setting.
835 * @return SP_OK upon success, a negative error code otherwise.
837 * @since 0.1.0
839 enum sp_return sp_set_config_baudrate(struct sp_port_config *config, int baudrate);
842 * Set the data bits for the specified serial port.
844 * @param[in] port Pointer to a port structure. Must not be NULL.
845 * @param[in] bits Number of data bits.
847 * @return SP_OK upon success, a negative error code otherwise.
849 * @since 0.1.0
851 enum sp_return sp_set_bits(struct sp_port *port, int bits);
854 * Get the data bits 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] bits_ptr Pointer to a variable to store the result. Must not be NULL.
862 * @return SP_OK upon success, a negative error code otherwise.
864 * @since 0.1.0
866 enum sp_return sp_get_config_bits(const struct sp_port_config *config, int *bits_ptr);
869 * Set the data bits in a port configuration.
871 * @param[in] config Pointer to a configuration structure. Must not be NULL.
872 * @param[in] bits Number of data bits, or -1 to retain the current setting.
874 * @return SP_OK upon success, a negative error code otherwise.
876 * @since 0.1.0
878 enum sp_return sp_set_config_bits(struct sp_port_config *config, int bits);
881 * Set the parity setting for the specified serial port.
883 * @param[in] port Pointer to a port structure. Must not be NULL.
884 * @param[in] parity Parity setting.
886 * @return SP_OK upon success, a negative error code otherwise.
888 * @since 0.1.0
890 enum sp_return sp_set_parity(struct sp_port *port, enum sp_parity parity);
893 * Get the parity setting from a port configuration.
895 * The user should allocate a variable of type enum sp_parity 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] parity_ptr Pointer to a variable to store the result. Must not be NULL.
901 * @return SP_OK upon success, a negative error code otherwise.
903 * @since 0.1.0
905 enum sp_return sp_get_config_parity(const struct sp_port_config *config, enum sp_parity *parity_ptr);
908 * Set the parity setting in a port configuration.
910 * @param[in] config Pointer to a configuration structure. Must not be NULL.
911 * @param[in] parity Parity setting, or -1 to retain the current setting.
913 * @return SP_OK upon success, a negative error code otherwise.
915 * @since 0.1.0
917 enum sp_return sp_set_config_parity(struct sp_port_config *config, enum sp_parity parity);
920 * Set the stop bits for the specified serial port.
922 * @param[in] port Pointer to a port structure. Must not be NULL.
923 * @param[in] stopbits Number of stop bits.
925 * @return SP_OK upon success, a negative error code otherwise.
927 * @since 0.1.0
929 enum sp_return sp_set_stopbits(struct sp_port *port, int stopbits);
932 * Get the stop bits from a port configuration.
934 * The user should allocate a variable of type int 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] stopbits_ptr Pointer to a variable to store the result. Must not be NULL.
940 * @return SP_OK upon success, a negative error code otherwise.
942 * @since 0.1.0
944 enum sp_return sp_get_config_stopbits(const struct sp_port_config *config, int *stopbits_ptr);
947 * Set the stop bits in a port configuration.
949 * @param[in] config Pointer to a configuration structure. Must not be NULL.
950 * @param[in] stopbits Number of stop bits, or -1 to retain the current setting.
952 * @return SP_OK upon success, a negative error code otherwise.
954 * @since 0.1.0
956 enum sp_return sp_set_config_stopbits(struct sp_port_config *config, int stopbits);
959 * Set the RTS pin behaviour for the specified serial port.
961 * @param[in] port Pointer to a port structure. Must not be NULL.
962 * @param[in] rts RTS pin mode.
964 * @return SP_OK upon success, a negative error code otherwise.
966 * @since 0.1.0
968 enum sp_return sp_set_rts(struct sp_port *port, enum sp_rts rts);
971 * Get the RTS pin behaviour from a port configuration.
973 * The user should allocate a variable of type enum sp_rts 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] rts_ptr Pointer to a variable to store the result. Must not be NULL.
979 * @return SP_OK upon success, a negative error code otherwise.
981 * @since 0.1.0
983 enum sp_return sp_get_config_rts(const struct sp_port_config *config, enum sp_rts *rts_ptr);
986 * Set the RTS pin behaviour in a port configuration.
988 * @param[in] config Pointer to a configuration structure. Must not be NULL.
989 * @param[in] rts RTS pin mode, or -1 to retain the current setting.
991 * @return SP_OK upon success, a negative error code otherwise.
993 * @since 0.1.0
995 enum sp_return sp_set_config_rts(struct sp_port_config *config, enum sp_rts rts);
998 * Set the CTS pin behaviour for the specified serial port.
1000 * @param[in] port Pointer to a port structure. Must not be NULL.
1001 * @param[in] cts CTS pin mode.
1003 * @return SP_OK upon success, a negative error code otherwise.
1005 * @since 0.1.0
1007 enum sp_return sp_set_cts(struct sp_port *port, enum sp_cts cts);
1010 * Get the CTS pin behaviour from a port configuration.
1012 * The user should allocate a variable of type enum sp_cts 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] cts_ptr Pointer to a variable to store the result. Must not be NULL.
1018 * @return SP_OK upon success, a negative error code otherwise.
1020 * @since 0.1.0
1022 enum sp_return sp_get_config_cts(const struct sp_port_config *config, enum sp_cts *cts_ptr);
1025 * Set the CTS pin behaviour in a port configuration.
1027 * @param[in] config Pointer to a configuration structure. Must not be NULL.
1028 * @param[in] cts CTS pin mode, or -1 to retain the current setting.
1030 * @return SP_OK upon success, a negative error code otherwise.
1032 * @since 0.1.0
1034 enum sp_return sp_set_config_cts(struct sp_port_config *config, enum sp_cts cts);
1037 * Set the DTR pin behaviour for the specified serial port.
1039 * @param[in] port Pointer to a port structure. Must not be NULL.
1040 * @param[in] dtr DTR pin mode.
1042 * @return SP_OK upon success, a negative error code otherwise.
1044 * @since 0.1.0
1046 enum sp_return sp_set_dtr(struct sp_port *port, enum sp_dtr dtr);
1049 * Get the DTR pin behaviour from a port configuration.
1051 * The user should allocate a variable of type enum sp_dtr 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] dtr_ptr Pointer to a variable to store the result. Must not be NULL.
1057 * @return SP_OK upon success, a negative error code otherwise.
1059 * @since 0.1.0
1061 enum sp_return sp_get_config_dtr(const struct sp_port_config *config, enum sp_dtr *dtr_ptr);
1064 * Set the DTR pin behaviour in a port configuration.
1066 * @param[in] config Pointer to a configuration structure. Must not be NULL.
1067 * @param[in] dtr DTR pin mode, or -1 to retain the current setting.
1069 * @return SP_OK upon success, a negative error code otherwise.
1071 * @since 0.1.0
1073 enum sp_return sp_set_config_dtr(struct sp_port_config *config, enum sp_dtr dtr);
1076 * Set the DSR pin behaviour for the specified serial port.
1078 * @param[in] port Pointer to a port structure. Must not be NULL.
1079 * @param[in] dsr DSR pin mode.
1081 * @return SP_OK upon success, a negative error code otherwise.
1083 * @since 0.1.0
1085 enum sp_return sp_set_dsr(struct sp_port *port, enum sp_dsr dsr);
1088 * Get the DSR pin behaviour from a port configuration.
1090 * The user should allocate a variable of type enum sp_dsr 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] dsr_ptr Pointer to a variable to store the result. Must not be NULL.
1096 * @return SP_OK upon success, a negative error code otherwise.
1098 * @since 0.1.0
1100 enum sp_return sp_get_config_dsr(const struct sp_port_config *config, enum sp_dsr *dsr_ptr);
1103 * Set the DSR pin behaviour in a port configuration.
1105 * @param[in] config Pointer to a configuration structure. Must not be NULL.
1106 * @param[in] dsr DSR pin mode, or -1 to retain the current setting.
1108 * @return SP_OK upon success, a negative error code otherwise.
1110 * @since 0.1.0
1112 enum sp_return sp_set_config_dsr(struct sp_port_config *config, enum sp_dsr dsr);
1115 * Set the XON/XOFF configuration for the specified serial port.
1117 * @param[in] port Pointer to a port structure. Must not be NULL.
1118 * @param[in] xon_xoff XON/XOFF mode.
1120 * @return SP_OK upon success, a negative error code otherwise.
1122 * @since 0.1.0
1124 enum sp_return sp_set_xon_xoff(struct sp_port *port, enum sp_xonxoff xon_xoff);
1127 * Get the XON/XOFF configuration from a port configuration.
1129 * The user should allocate a variable of type enum sp_xonxoff 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] xon_xoff_ptr Pointer to a variable to store the result. Must not be NULL.
1135 * @return SP_OK upon success, a negative error code otherwise.
1137 * @since 0.1.0
1139 enum sp_return sp_get_config_xon_xoff(const struct sp_port_config *config, enum sp_xonxoff *xon_xoff_ptr);
1142 * Set the XON/XOFF configuration in a port configuration.
1144 * @param[in] config Pointer to a configuration structure. Must not be NULL.
1145 * @param[in] xon_xoff XON/XOFF mode, or -1 to retain the current setting.
1147 * @return SP_OK upon success, a negative error code otherwise.
1149 * @since 0.1.0
1151 enum sp_return sp_set_config_xon_xoff(struct sp_port_config *config, enum sp_xonxoff xon_xoff);
1154 * Set the flow control type in a port configuration.
1156 * This function is a wrapper that sets the RTS, CTS, DTR, DSR and
1157 * XON/XOFF settings as necessary for the specified flow control
1158 * type. For more fine-grained control of these settings, use their
1159 * individual configuration functions.
1161 * @param[in] config Pointer to a configuration structure. Must not be NULL.
1162 * @param[in] flowcontrol Flow control setting to use.
1164 * @return SP_OK upon success, a negative error code otherwise.
1166 * @since 0.1.0
1168 enum sp_return sp_set_config_flowcontrol(struct sp_port_config *config, enum sp_flowcontrol flowcontrol);
1171 * Set the flow control type for the specified serial port.
1173 * This function is a wrapper that sets the RTS, CTS, DTR, DSR and
1174 * XON/XOFF settings as necessary for the specified flow control
1175 * type. For more fine-grained control of these settings, use their
1176 * individual configuration functions.
1178 * @param[in] port Pointer to a port structure. Must not be NULL.
1179 * @param[in] flowcontrol Flow control setting to use.
1181 * @return SP_OK upon success, a negative error code otherwise.
1183 * @since 0.1.0
1185 enum sp_return sp_set_flowcontrol(struct sp_port *port, enum sp_flowcontrol flowcontrol);
1188 * @}
1190 * @defgroup Data Data handling
1192 * Reading, writing, and flushing data.
1194 * @{
1198 * Read bytes from the specified serial port, blocking until complete.
1200 * @warning If your program runs on Unix, defines its own signal handlers, and
1201 * needs to abort blocking reads when these are called, then you
1202 * should not use this function. It repeats system calls that return
1203 * with EINTR. To be able to abort a read from a signal handler, you
1204 * should implement your own blocking read using sp_nonblocking_read()
1205 * together with a blocking method that makes sense for your program.
1206 * E.g. you can obtain the file descriptor for an open port using
1207 * sp_get_port_handle() and use this to call select() or pselect(),
1208 * with appropriate arrangements to return if a signal is received.
1210 * @param[in] port Pointer to a port structure. Must not be NULL.
1211 * @param[out] buf Buffer in which to store the bytes read. Must not be NULL.
1212 * @param[in] count Requested number of bytes to read.
1213 * @param[in] timeout_ms Timeout in milliseconds, or zero to wait indefinitely.
1215 * @return The number of bytes read on success, or a negative error code. If
1216 * the number of bytes returned is less than that requested, the
1217 * timeout was reached before the requested number of bytes was
1218 * available. If timeout is zero, the function will always return
1219 * either the requested number of bytes or a negative error code.
1221 * @since 0.1.0
1223 enum sp_return sp_blocking_read(struct sp_port *port, void *buf, size_t count, unsigned int timeout_ms);
1226 * Read bytes from the specified serial port, returning as soon as any data is
1227 * available.
1229 * @warning If your program runs on Unix, defines its own signal handlers, and
1230 * needs to abort blocking reads when these are called, then you
1231 * should not use this function. It repeats system calls that return
1232 * with EINTR. To be able to abort a read from a signal handler, you
1233 * should implement your own blocking read using sp_nonblocking_read()
1234 * together with a blocking method that makes sense for your program.
1235 * E.g. you can obtain the file descriptor for an open port using
1236 * sp_get_port_handle() and use this to call select() or pselect(),
1237 * with appropriate arrangements to return if a signal is received.
1239 * @param[in] port Pointer to a port structure. Must not be NULL.
1240 * @param[out] buf Buffer in which to store the bytes read. Must not be NULL.
1241 * @param[in] count Maximum number of bytes to read. Must not be zero.
1242 * @param[in] timeout_ms Timeout in milliseconds, or zero to wait indefinitely.
1244 * @return The number of bytes read on success, or a negative error code. If
1245 * the result is zero, the timeout was reached before any bytes were
1246 * available. If timeout_ms is zero, the function will always return
1247 * either at least one byte, or a negative error code.
1249 * @since 0.1.1
1251 enum sp_return sp_blocking_read_next(struct sp_port *port, void *buf, size_t count, unsigned int timeout_ms);
1254 * Read bytes from the specified serial port, without blocking.
1256 * @param[in] port Pointer to a port structure. Must not be NULL.
1257 * @param[out] buf Buffer in which to store the bytes read. Must not be NULL.
1258 * @param[in] count Maximum number of bytes to read.
1260 * @return The number of bytes read on success, or a negative error code. The
1261 * number of bytes returned may be any number from zero to the maximum
1262 * that was requested.
1264 * @since 0.1.0
1266 enum sp_return sp_nonblocking_read(struct sp_port *port, void *buf, size_t count);
1269 * Write bytes to the specified serial port, blocking until complete.
1271 * Note that this function only ensures that the accepted bytes have been
1272 * written to the OS; they may be held in driver or hardware buffers and not
1273 * yet physically transmitted. To check whether all written bytes have actually
1274 * been transmitted, use the sp_output_waiting() function. To wait until all
1275 * written bytes have actually been transmitted, use the sp_drain() function.
1277 * @warning If your program runs on Unix, defines its own signal handlers, and
1278 * needs to abort blocking writes when these are called, then you
1279 * should not use this function. It repeats system calls that return
1280 * with EINTR. To be able to abort a write from a signal handler, you
1281 * should implement your own blocking write using sp_nonblocking_write()
1282 * together with a blocking method that makes sense for your program.
1283 * E.g. you can obtain the file descriptor for an open port using
1284 * sp_get_port_handle() and use this to call select() or pselect(),
1285 * with appropriate arrangements to return if a signal is received.
1287 * @param[in] port Pointer to a port structure. Must not be NULL.
1288 * @param[in] buf Buffer containing the bytes to write. Must not be NULL.
1289 * @param[in] count Requested number of bytes to write.
1290 * @param[in] timeout_ms Timeout in milliseconds, or zero to wait indefinitely.
1292 * @return The number of bytes written on success, or a negative error code.
1293 * If the number of bytes returned is less than that requested, the
1294 * timeout was reached before the requested number of bytes was
1295 * written. If timeout is zero, the function will always return
1296 * either the requested number of bytes or a negative error code. In
1297 * the event of an error there is no way to determine how many bytes
1298 * were sent before the error occurred.
1300 * @since 0.1.0
1302 enum sp_return sp_blocking_write(struct sp_port *port, const void *buf, size_t count, unsigned int timeout_ms);
1305 * Write bytes to the specified serial port, without blocking.
1307 * Note that this function only ensures that the accepted bytes have been
1308 * written to the OS; they may be held in driver or hardware buffers and not
1309 * yet physically transmitted. To check whether all written bytes have actually
1310 * been transmitted, use the sp_output_waiting() function. To wait until all
1311 * written bytes have actually been transmitted, use the sp_drain() function.
1313 * @param[in] port Pointer to a port structure. Must not be NULL.
1314 * @param[in] buf Buffer containing the bytes to write. Must not be NULL.
1315 * @param[in] count Maximum number of bytes to write.
1317 * @return The number of bytes written on success, or a negative error code.
1318 * The number of bytes returned may be any number from zero to the
1319 * maximum that was requested.
1321 * @since 0.1.0
1323 enum sp_return sp_nonblocking_write(struct sp_port *port, const void *buf, size_t count);
1326 * Gets the number of bytes waiting in the input buffer.
1328 * @param[in] port Pointer to a port structure. Must not be NULL.
1330 * @return Number of bytes waiting on success, a negative error code otherwise.
1332 * @since 0.1.0
1334 enum sp_return sp_input_waiting(struct sp_port *port);
1337 * Gets the number of bytes waiting in the output buffer.
1339 * @param[in] port Pointer to a port structure. Must not be NULL.
1341 * @return Number of bytes waiting on success, a negative error code otherwise.
1343 * @since 0.1.0
1345 enum sp_return sp_output_waiting(struct sp_port *port);
1348 * Flush serial port buffers. Data in the selected buffer(s) is discarded.
1350 * @param[in] port Pointer to a port structure. Must not be NULL.
1351 * @param[in] buffers Which buffer(s) to flush.
1353 * @return SP_OK upon success, a negative error code otherwise.
1355 * @since 0.1.0
1357 enum sp_return sp_flush(struct sp_port *port, enum sp_buffer buffers);
1360 * Wait for buffered data to be transmitted.
1362 * @warning If your program runs on Unix, defines its own signal handlers, and
1363 * needs to abort draining the output buffer when when these are
1364 * called, then you should not use this function. It repeats system
1365 * calls that return with EINTR. To be able to abort a drain from a
1366 * signal handler, you would need to implement your own blocking
1367 * drain by polling the result of sp_output_waiting().
1369 * @param[in] port Pointer to a port structure. Must not be NULL.
1371 * @return SP_OK upon success, a negative error code otherwise.
1373 * @since 0.1.0
1375 enum sp_return sp_drain(struct sp_port *port);
1378 * @}
1380 * @defgroup Waiting Waiting
1382 * Waiting for events and timeout handling.
1384 * @{
1388 * Allocate storage for a set of events.
1390 * The user should allocate a variable of type struct sp_event_set *,
1391 * then pass a pointer to this variable to receive the result.
1393 * The result should be freed after use by calling sp_free_event_set().
1395 * @param[out] result_ptr If any error is returned, the variable pointed to by
1396 * result_ptr will be set to NULL. Otherwise, it will
1397 * be set to point to the event set. Must not be NULL.
1399 * @return SP_OK upon success, a negative error code otherwise.
1401 * @since 0.1.0
1403 enum sp_return sp_new_event_set(struct sp_event_set **result_ptr);
1406 * Add events to a struct sp_event_set for a given port.
1408 * The port must first be opened by calling sp_open() using the same port
1409 * structure.
1411 * After the port is closed or the port structure freed, the results may
1412 * no longer be valid.
1414 * @param[in,out] event_set Event set to update. Must not be NULL.
1415 * @param[in] port Pointer to a port structure. Must not be NULL.
1416 * @param[in] mask Bitmask of events to be waited for.
1418 * @return SP_OK upon success, a negative error code otherwise.
1420 * @since 0.1.0
1422 enum sp_return sp_add_port_events(struct sp_event_set *event_set,
1423 const struct sp_port *port, enum sp_event mask);
1426 * Wait for any of a set of events to occur.
1428 * @param[in] event_set Event set to wait on. Must not be NULL.
1429 * @param[in] timeout_ms Timeout in milliseconds, or zero to wait indefinitely.
1431 * @return SP_OK upon success, a negative error code otherwise.
1433 * @since 0.1.0
1435 enum sp_return sp_wait(struct sp_event_set *event_set, unsigned int timeout_ms);
1438 * Free a structure allocated by sp_new_event_set().
1440 * @param[in] event_set Event set to free. Must not be NULL.
1442 * @since 0.1.0
1444 void sp_free_event_set(struct sp_event_set *event_set);
1447 * @}
1449 * @defgroup Signals Signals
1451 * Port signalling operations.
1453 * @{
1457 * Gets the status of the control signals for the specified port.
1459 * The user should allocate a variable of type "enum sp_signal" and pass a
1460 * pointer to this variable to receive the result. The result is a bitmask
1461 * in which individual signals can be checked by bitwise OR with values of
1462 * the sp_signal enum.
1464 * @param[in] port Pointer to a port structure. Must not be NULL.
1465 * @param[out] signal_mask Pointer to a variable to receive the result.
1466 * Must not be NULL.
1468 * @return SP_OK upon success, a negative error code otherwise.
1470 * @since 0.1.0
1472 enum sp_return sp_get_signals(struct sp_port *port, enum sp_signal *signal_mask);
1475 * Put the port transmit line into the break state.
1477 * @param[in] port Pointer to a port structure. Must not be NULL.
1479 * @return SP_OK upon success, a negative error code otherwise.
1481 * @since 0.1.0
1483 enum sp_return sp_start_break(struct sp_port *port);
1486 * Take the port transmit line out of the break state.
1488 * @param[in] port Pointer to a port structure. Must not be NULL.
1490 * @return SP_OK upon success, a negative error code otherwise.
1492 * @since 0.1.0
1494 enum sp_return sp_end_break(struct sp_port *port);
1497 * @}
1499 * @defgroup Errors Errors
1501 * Obtaining error information.
1503 * @{
1507 * Get the error code for a failed operation.
1509 * In order to obtain the correct result, this function should be called
1510 * straight after the failure, before executing any other system operations.
1511 * The result is thread-specific, and only valid when called immediately
1512 * after a previous call returning SP_ERR_FAIL.
1514 * @return The system's numeric code for the error that caused the last
1515 * operation to fail.
1517 * @since 0.1.0
1519 int sp_last_error_code(void);
1522 * Get the error message for a failed operation.
1524 * In order to obtain the correct result, this function should be called
1525 * straight after the failure, before executing other system operations.
1526 * The result is thread-specific, and only valid when called immediately
1527 * after a previous call returning SP_ERR_FAIL.
1529 * @return The system's message for the error that caused the last
1530 * operation to fail. This string may be allocated by the function,
1531 * and should be freed after use by calling sp_free_error_message().
1533 * @since 0.1.0
1535 char *sp_last_error_message(void);
1538 * Free an error message returned by sp_last_error_message().
1540 * @param[in] message The error message string to free. Must not be NULL.
1542 * @since 0.1.0
1544 void sp_free_error_message(char *message);
1547 * Set the handler function for library debugging messages.
1549 * Debugging messages are generated by the library during each operation,
1550 * to help in diagnosing problems. The handler will be called for each
1551 * message. The handler can be set to NULL to ignore all debug messages.
1553 * The handler function should accept a format string and variable length
1554 * argument list, in the same manner as e.g. printf().
1556 * The default handler is sp_default_debug_handler().
1558 * @param[in] handler The handler function to use. Can be NULL (in that case
1559 * all debug messages will be ignored).
1561 * @since 0.1.0
1563 void sp_set_debug_handler(void (*handler)(const char *format, ...));
1566 * Default handler function for library debugging messages.
1568 * This function prints debug messages to the standard error stream if the
1569 * environment variable LIBSERIALPORT_DEBUG is set. Otherwise, they are
1570 * ignored.
1572 * @param[in] format The format string to use. Must not be NULL.
1573 * @param[in] ... The variable length argument list to use.
1575 * @since 0.1.0
1577 void sp_default_debug_handler(const char *format, ...);
1579 /** @} */
1582 * @defgroup Versions Versions
1584 * Version number querying functions, definitions, and macros.
1586 * This set of API calls returns two different version numbers related
1587 * to libserialport. The "package version" is the release version number of the
1588 * libserialport tarball in the usual "major.minor.micro" format, e.g. "0.1.0".
1590 * The "library version" is independent of that; it is the libtool version
1591 * number in the "current:revision:age" format, e.g. "2:0:0".
1592 * See http://www.gnu.org/software/libtool/manual/libtool.html#Libtool-versioning for details.
1594 * Both version numbers (and/or individual components of them) can be
1595 * retrieved via the API calls at runtime, and/or they can be checked at
1596 * compile/preprocessor time using the respective macros.
1598 * @{
1602 * Package version macros (can be used for conditional compilation).
1605 /** The libserialport package 'major' version number. */
1606 #undef SP_PACKAGE_VERSION_MAJOR
1608 /** The libserialport package 'minor' version number. */
1609 #undef SP_PACKAGE_VERSION_MINOR
1611 /** The libserialport package 'micro' version number. */
1612 #undef SP_PACKAGE_VERSION_MICRO
1614 /** The libserialport package version ("major.minor.micro") as string. */
1615 #undef SP_PACKAGE_VERSION_STRING
1618 * Library/libtool version macros (can be used for conditional compilation).
1621 /** The libserialport libtool 'current' version number. */
1622 #undef SP_LIB_VERSION_CURRENT
1624 /** The libserialport libtool 'revision' version number. */
1625 #undef SP_LIB_VERSION_REVISION
1627 /** The libserialport libtool 'age' version number. */
1628 #undef SP_LIB_VERSION_AGE
1630 /** The libserialport libtool version ("current:revision:age") as string. */
1631 #undef SP_LIB_VERSION_STRING
1634 * Get the major libserialport package version number.
1636 * @return The major package version number.
1638 * @since 0.1.0
1640 int sp_get_major_package_version(void);
1643 * Get the minor libserialport package version number.
1645 * @return The minor package version number.
1647 * @since 0.1.0
1649 int sp_get_minor_package_version(void);
1652 * Get the micro libserialport package version number.
1654 * @return The micro package version number.
1656 * @since 0.1.0
1658 int sp_get_micro_package_version(void);
1661 * Get the libserialport package version number as a string.
1663 * @return The package version number string. The returned string is
1664 * static and thus should NOT be free'd by the caller.
1666 * @since 0.1.0
1668 const char *sp_get_package_version_string(void);
1671 * Get the "current" part of the libserialport library version number.
1673 * @return The "current" library version number.
1675 * @since 0.1.0
1677 int sp_get_current_lib_version(void);
1680 * Get the "revision" part of the libserialport library version number.
1682 * @return The "revision" library version number.
1684 * @since 0.1.0
1686 int sp_get_revision_lib_version(void);
1689 * Get the "age" part of the libserialport library version number.
1691 * @return The "age" library version number.
1693 * @since 0.1.0
1695 int sp_get_age_lib_version(void);
1698 * Get the libserialport library version number as a string.
1700 * @return The library version number string. The returned string is
1701 * static and thus should NOT be free'd by the caller.
1703 * @since 0.1.0
1705 const char *sp_get_lib_version_string(void);
1707 /** @} */
1709 #ifdef __cplusplus
1711 #endif
1713 #endif