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