]> sigrok.org Git - libserialport.git/blob - libserialport.h.in
libserialport.h: Add package/lib version macros.
[libserialport.git] / libserialport.h.in
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
20 #ifndef LIBSERIALPORT_H
21 #define LIBSERIALPORT_H
22
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26
27 #include <stddef.h>
28 #ifdef _WIN32
29 #include <windows.h>
30 #endif
31
32 /* Package version macros (e.g. for conditional compilation). */
33 #define SP_PACKAGE_VERSION_MAJOR @SP_PACKAGE_VERSION_MAJOR@
34 #define SP_PACKAGE_VERSION_MINOR @SP_PACKAGE_VERSION_MINOR@
35 #define SP_PACKAGE_VERSION_STRING "@SP_PACKAGE_VERSION@"
36
37 /* Library/libtool version macros (e.g. for conditional compilation). */
38 #define SP_LIB_VERSION_CURRENT @SP_LIB_VERSION_CURRENT@
39 #define SP_LIB_VERSION_REVISION @SP_LIB_VERSION_REVISION@
40 #define SP_LIB_VERSION_AGE @SP_LIB_VERSION_AGE@
41 #define SP_LIB_VERSION_STRING "@SP_LIB_VERSION@"
42
43 /* A serial port. */
44 struct sp_port {
45         /* Name used to open the port */
46         char *name;
47         /* OS-specific port handle */
48 #ifdef _WIN32
49         HANDLE hdl;
50 #else
51         int fd;
52 #endif
53 };
54
55 /* Return values. */
56 enum {
57         /* Operation completed successfully. */
58         SP_OK = 0,
59         /* Invalid arguments were passed to the function. */
60         SP_ERR_ARG = -1,
61         /* A system error occured while executing the operation. */
62         SP_ERR_FAIL = -2,
63         /* A memory allocation failed while executing the operation. */
64         SP_ERR_MEM = -3,
65 };
66
67 /* Port access modes. */
68 enum {
69         /* Open port for read/write access. */
70         SP_MODE_RDWR = 1,
71         /* Open port for read access only. */
72         SP_MODE_RDONLY = 2,
73         /* Open port in non-blocking mode. */
74         SP_MODE_NONBLOCK = 4,
75 };
76
77 /* Parity settings. */
78 enum {
79         /* No parity. */
80         SP_PARITY_NONE = 0,
81         /* Even parity. */
82         SP_PARITY_EVEN = 1,
83         /* Odd parity. */
84         SP_PARITY_ODD = 2,
85 };
86
87 /* Flow control settings. */
88 enum {
89         /* No flow control. */
90         SP_FLOW_NONE = 0,
91         /* Hardware (RTS/CTS) flow control. */
92         SP_FLOW_HARDWARE = 1,
93         /* Software (XON/XOFF) flow control. */
94         SP_FLOW_SOFTWARE = 2,
95 };
96
97 int sp_get_port_by_name(const char *portname, struct sp_port **port_ptr);
98 void sp_free_port(struct sp_port *port);
99 int sp_list_ports(struct sp_port ***list_ptr);
100 int sp_copy_port(const struct sp_port *port, struct sp_port **copy_ptr);
101 void sp_free_port_list(struct sp_port **ports);
102 int sp_open(struct sp_port *port, int flags);
103 int sp_close(struct sp_port *port);
104 int sp_flush(struct sp_port *port);
105 int sp_write(struct sp_port *port, const void *buf, size_t count);
106 int sp_read(struct sp_port *port, void *buf, size_t count);
107 int sp_set_params(struct sp_port *port, int baudrate, int bits, int parity,
108                 int stopbits, int flowcontrol, int rts, int dtr);
109 int sp_last_error_code(void);
110 char *sp_last_error_message(void);
111 void sp_free_error_message(char *message);
112
113 #ifdef __cplusplus
114 }
115 #endif
116
117 #endif /* LIBSERIALPORT_H */