2 * This file is part of the libserialport project.
4 * Copyright (C) 2013 Martin Ling <martin-libserialport@earth.li>
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.
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.
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/>.
20 #ifndef LIBSERIALPORT_H
21 #define LIBSERIALPORT_H
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@"
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@"
45 /* Name used to open the port */
47 /* OS-specific port handle */
55 /* Configuration for a serial port. */
56 struct sp_port_config {
70 /* Operation completed successfully. */
72 /* Invalid arguments were passed to the function. */
74 /* A system error occured while executing the operation. */
76 /* A memory allocation failed while executing the operation. */
80 /* Port access modes. */
82 /* Open port for read/write access. */
84 /* Open port for read access only. */
86 /* Open port in non-blocking mode. */
90 /* Parity settings. */
100 /* RTS pin behaviour. */
104 SP_RTS_FLOW_CONTROL = 2
107 /* CTS pin behaviour. */
110 SP_CTS_FLOW_CONTROL = 1
113 /* DTR pin behaviour. */
117 SP_DTR_FLOW_CONTROL = 2
120 /* DSR pin behaviour. */
123 SP_DSR_FLOW_CONTROL = 1
126 /* XON/XOFF flow control behaviour. */
128 SP_XONXOFF_DISABLED = 0,
134 /* Standard flow control combinations. */
136 SP_FLOWCONTROL_NONE = 0,
137 SP_FLOWCONTROL_XONXOFF = 1,
138 SP_FLOWCONTROL_RTSCTS = 2,
139 SP_FLOWCONTROL_DTRDSR = 3
143 int sp_get_port_by_name(const char *portname, struct sp_port **port_ptr);
144 void sp_free_port(struct sp_port *port);
145 int sp_list_ports(struct sp_port ***list_ptr);
146 int sp_copy_port(const struct sp_port *port, struct sp_port **copy_ptr);
147 void sp_free_port_list(struct sp_port **ports);
149 /* Opening & closing ports */
150 int sp_open(struct sp_port *port, int flags);
151 int sp_close(struct sp_port *port);
153 /* Reading, writing and flushing. */
154 int sp_read(struct sp_port *port, void *buf, size_t count);
155 int sp_write(struct sp_port *port, const void *buf, size_t count);
156 int sp_flush(struct sp_port *port);
158 /* Basic port configuration */
159 int sp_get_config(struct sp_port *port, struct sp_port_config *config);
160 int sp_set_config(struct sp_port *port, const struct sp_port_config *config);
161 int sp_set_baudrate(struct sp_port *port, int baudrate);
162 int sp_set_bits(struct sp_port *port, int bits);
163 int sp_set_parity(struct sp_port *port, int parity);
164 int sp_set_stopbits(struct sp_port *port, int stopbits);
165 int sp_set_flowcontrol(struct sp_port *port, int flowcontrol);
167 /* Advanced port configuration */
168 int sp_set_rts(struct sp_port *port, int rts);
169 int sp_set_cts(struct sp_port *port, int cts);
170 int sp_set_dtr(struct sp_port *port, int dtr);
171 int sp_set_dsr(struct sp_port *port, int dsr);
172 int sp_set_xon_xoff(struct sp_port *port, int xon_xoff);
175 int sp_last_error_code(void);
176 char *sp_last_error_message(void);
177 void sp_free_error_message(char *message);
183 #endif /* LIBSERIALPORT_H */