]> sigrok.org Git - libserialport.git/blame - libserialport.h.in
Add sp_get_config() function.
[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
f92f1f0c
UH
20#ifndef LIBSERIALPORT_H
21#define LIBSERIALPORT_H
e8ffaee9 22
5ef8a1ed
UH
23#ifdef __cplusplus
24extern "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. */
44struct 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. */
56struct sp_port_config {
57 int baudrate;
58 int bits;
59 int parity;
60 int stopbits;
d1202734 61 int rts;
d514a26f 62 int cts;
d1202734 63 int dtr;
d514a26f
ML
64 int dsr;
65 int xon_xoff;
d1202734
ML
66};
67
74510d4b
ML
68/* Return values. */
69enum {
70 /* Operation completed successfully. */
71 SP_OK = 0,
74510d4b 72 /* Invalid arguments were passed to the function. */
e9a2f9c9
ML
73 SP_ERR_ARG = -1,
74 /* A system error occured while executing the operation. */
75 SP_ERR_FAIL = -2,
76 /* A memory allocation failed while executing the operation. */
f92f1f0c 77 SP_ERR_MEM = -3,
74510d4b
ML
78};
79
80/* Port access modes. */
81enum {
82 /* Open port for read/write access. */
83 SP_MODE_RDWR = 1,
84 /* Open port for read access only. */
85 SP_MODE_RDONLY = 2,
86 /* Open port in non-blocking mode. */
f92f1f0c 87 SP_MODE_NONBLOCK = 4,
74510d4b
ML
88};
89
90/* Parity settings. */
91enum {
92 /* No parity. */
93 SP_PARITY_NONE = 0,
94 /* Even parity. */
95 SP_PARITY_EVEN = 1,
96 /* Odd parity. */
f92f1f0c 97 SP_PARITY_ODD = 2,
74510d4b
ML
98};
99
d514a26f 100/* RTS pin behaviour. */
ac74fdaf 101enum {
d514a26f
ML
102 SP_RTS_OFF = 0,
103 SP_RTS_ON = 1,
104 SP_RTS_FLOW_CONTROL = 2
105};
106
107/* CTS pin behaviour. */
108enum {
109 SP_CTS_IGNORE = 0,
110 SP_CTS_FLOW_CONTROL = 1
111};
112
113/* DTR pin behaviour. */
114enum {
115 SP_DTR_OFF = 0,
116 SP_DTR_ON = 1,
117 SP_DTR_FLOW_CONTROL = 2
118};
119
120/* DSR pin behaviour. */
121enum {
122 SP_DSR_IGNORE = 0,
123 SP_DSR_FLOW_CONTROL = 1
124};
125
126/* XON/XOFF flow control behaviour. */
127enum {
128 SP_XONXOFF_DISABLED = 0,
129 SP_XONXOFF_IN = 1,
130 SP_XONXOFF_OUT = 2,
131 SP_XONXOFF_INOUT = 3
ac74fdaf
ML
132};
133
18fc2dd1
ML
134/* Standard flow control combinations. */
135enum {
136 SP_FLOWCONTROL_NONE = 0,
137 SP_FLOWCONTROL_XONXOFF = 1,
138 SP_FLOWCONTROL_RTSCTS = 2,
139 SP_FLOWCONTROL_DTRDSR = 3
140};
141
e96d8bd2 142/* Enumeration */
77f262c4 143int sp_get_port_by_name(const char *portname, struct sp_port **port_ptr);
e3b2f7a4 144void sp_free_port(struct sp_port *port);
77f262c4 145int sp_list_ports(struct sp_port ***list_ptr);
32b5ac05 146int sp_copy_port(const struct sp_port *port, struct sp_port **copy_ptr);
d54e9004 147void sp_free_port_list(struct sp_port **ports);
e96d8bd2
ML
148
149/* Opening & closing ports */
d54e9004 150int sp_open(struct sp_port *port, int flags);
74510d4b 151int sp_close(struct sp_port *port);
e96d8bd2
ML
152
153/* Reading, writing and flushing. */
74510d4b 154int sp_read(struct sp_port *port, void *buf, size_t count);
e96d8bd2
ML
155int sp_write(struct sp_port *port, const void *buf, size_t count);
156int sp_flush(struct sp_port *port);
157
18fc2dd1 158/* Basic port configuration */
067417af 159int sp_get_config(struct sp_port *port, struct sp_port_config *config);
d1202734 160int sp_set_config(struct sp_port *port, struct sp_port_config *config);
9069c2fb
ML
161int sp_set_baudrate(struct sp_port *port, int baudrate);
162int sp_set_bits(struct sp_port *port, int bits);
163int sp_set_parity(struct sp_port *port, int parity);
164int sp_set_stopbits(struct sp_port *port, int stopbits);
18fc2dd1
ML
165int sp_set_flowcontrol(struct sp_port *port, int flowcontrol);
166
167/* Advanced port configuration */
9069c2fb
ML
168int sp_set_rts(struct sp_port *port, int rts);
169int sp_set_cts(struct sp_port *port, int cts);
170int sp_set_dtr(struct sp_port *port, int dtr);
171int sp_set_dsr(struct sp_port *port, int dsr);
172int sp_set_xon_xoff(struct sp_port *port, int xon_xoff);
e96d8bd2
ML
173
174/* Error handling */
74510d4b
ML
175int sp_last_error_code(void);
176char *sp_last_error_message(void);
177void sp_free_error_message(char *message);
e8ffaee9 178
5ef8a1ed
UH
179#ifdef __cplusplus
180}
181#endif
182
f92f1f0c 183#endif /* LIBSERIALPORT_H */