]>
Commit | Line | Data |
---|---|---|
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 | ||
f92f1f0c UH |
20 | #ifndef LIBSERIALPORT_H |
21 | #define LIBSERIALPORT_H | |
e8ffaee9 | 22 | |
5ef8a1ed UH |
23 | #ifdef __cplusplus |
24 | extern "C" { | |
25 | #endif | |
26 | ||
74510d4b ML |
27 | #include <stddef.h> |
28 | #ifdef _WIN32 | |
29 | #include <windows.h> | |
30 | #endif | |
31 | ||
baba0759 UH |
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 | ||
74510d4b ML |
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 | ||
d1202734 ML |
55 | /* Configuration for a serial port. */ |
56 | struct sp_port_config { | |
57 | int baudrate; | |
58 | int bits; | |
59 | int parity; | |
60 | int stopbits; | |
61 | int flowcontrol; | |
62 | int rts; | |
d514a26f | 63 | int cts; |
d1202734 | 64 | int dtr; |
d514a26f ML |
65 | int dsr; |
66 | int xon_xoff; | |
d1202734 ML |
67 | }; |
68 | ||
74510d4b ML |
69 | /* Return values. */ |
70 | enum { | |
71 | /* Operation completed successfully. */ | |
72 | SP_OK = 0, | |
74510d4b | 73 | /* Invalid arguments were passed to the function. */ |
e9a2f9c9 ML |
74 | SP_ERR_ARG = -1, |
75 | /* A system error occured while executing the operation. */ | |
76 | SP_ERR_FAIL = -2, | |
77 | /* A memory allocation failed while executing the operation. */ | |
f92f1f0c | 78 | SP_ERR_MEM = -3, |
74510d4b ML |
79 | }; |
80 | ||
81 | /* Port access modes. */ | |
82 | enum { | |
83 | /* Open port for read/write access. */ | |
84 | SP_MODE_RDWR = 1, | |
85 | /* Open port for read access only. */ | |
86 | SP_MODE_RDONLY = 2, | |
87 | /* Open port in non-blocking mode. */ | |
f92f1f0c | 88 | SP_MODE_NONBLOCK = 4, |
74510d4b ML |
89 | }; |
90 | ||
91 | /* Parity settings. */ | |
92 | enum { | |
93 | /* No parity. */ | |
94 | SP_PARITY_NONE = 0, | |
95 | /* Even parity. */ | |
96 | SP_PARITY_EVEN = 1, | |
97 | /* Odd parity. */ | |
f92f1f0c | 98 | SP_PARITY_ODD = 2, |
74510d4b ML |
99 | }; |
100 | ||
d514a26f | 101 | /* RTS pin behaviour. */ |
ac74fdaf | 102 | enum { |
d514a26f ML |
103 | SP_RTS_OFF = 0, |
104 | SP_RTS_ON = 1, | |
105 | SP_RTS_FLOW_CONTROL = 2 | |
106 | }; | |
107 | ||
108 | /* CTS pin behaviour. */ | |
109 | enum { | |
110 | SP_CTS_IGNORE = 0, | |
111 | SP_CTS_FLOW_CONTROL = 1 | |
112 | }; | |
113 | ||
114 | /* DTR pin behaviour. */ | |
115 | enum { | |
116 | SP_DTR_OFF = 0, | |
117 | SP_DTR_ON = 1, | |
118 | SP_DTR_FLOW_CONTROL = 2 | |
119 | }; | |
120 | ||
121 | /* DSR pin behaviour. */ | |
122 | enum { | |
123 | SP_DSR_IGNORE = 0, | |
124 | SP_DSR_FLOW_CONTROL = 1 | |
125 | }; | |
126 | ||
127 | /* XON/XOFF flow control behaviour. */ | |
128 | enum { | |
129 | SP_XONXOFF_DISABLED = 0, | |
130 | SP_XONXOFF_IN = 1, | |
131 | SP_XONXOFF_OUT = 2, | |
132 | SP_XONXOFF_INOUT = 3 | |
ac74fdaf ML |
133 | }; |
134 | ||
77f262c4 | 135 | int sp_get_port_by_name(const char *portname, struct sp_port **port_ptr); |
e3b2f7a4 | 136 | void sp_free_port(struct sp_port *port); |
77f262c4 | 137 | int sp_list_ports(struct sp_port ***list_ptr); |
32b5ac05 | 138 | int sp_copy_port(const struct sp_port *port, struct sp_port **copy_ptr); |
d54e9004 ML |
139 | void sp_free_port_list(struct sp_port **ports); |
140 | int sp_open(struct sp_port *port, int flags); | |
74510d4b ML |
141 | int sp_close(struct sp_port *port); |
142 | int sp_flush(struct sp_port *port); | |
143 | int sp_write(struct sp_port *port, const void *buf, size_t count); | |
144 | int sp_read(struct sp_port *port, void *buf, size_t count); | |
d1202734 | 145 | int sp_set_config(struct sp_port *port, struct sp_port_config *config); |
74510d4b ML |
146 | int sp_last_error_code(void); |
147 | char *sp_last_error_message(void); | |
148 | void sp_free_error_message(char *message); | |
e8ffaee9 | 149 | |
5ef8a1ed UH |
150 | #ifdef __cplusplus |
151 | } | |
152 | #endif | |
153 | ||
f92f1f0c | 154 | #endif /* LIBSERIALPORT_H */ |