]> sigrok.org Git - libserialport.git/blame - libserialport.h
libserialport: Allow C++ frontends to use the lib easily.
[libserialport.git] / libserialport.h
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
32/* A serial port. */
33struct sp_port {
34 /* Name used to open the port */
35 char *name;
36 /* OS-specific port handle */
37#ifdef _WIN32
38 HANDLE hdl;
39#else
40 int fd;
41#endif
42};
43
44/* Return values. */
45enum {
46 /* Operation completed successfully. */
47 SP_OK = 0,
74510d4b 48 /* Invalid arguments were passed to the function. */
e9a2f9c9
ML
49 SP_ERR_ARG = -1,
50 /* A system error occured while executing the operation. */
51 SP_ERR_FAIL = -2,
52 /* A memory allocation failed while executing the operation. */
f92f1f0c 53 SP_ERR_MEM = -3,
74510d4b
ML
54};
55
56/* Port access modes. */
57enum {
58 /* Open port for read/write access. */
59 SP_MODE_RDWR = 1,
60 /* Open port for read access only. */
61 SP_MODE_RDONLY = 2,
62 /* Open port in non-blocking mode. */
f92f1f0c 63 SP_MODE_NONBLOCK = 4,
74510d4b
ML
64};
65
66/* Parity settings. */
67enum {
68 /* No parity. */
69 SP_PARITY_NONE = 0,
70 /* Even parity. */
71 SP_PARITY_EVEN = 1,
72 /* Odd parity. */
f92f1f0c 73 SP_PARITY_ODD = 2,
74510d4b
ML
74};
75
ac74fdaf
ML
76/* Flow control settings. */
77enum {
78 /* No flow control. */
79 SP_FLOW_NONE = 0,
80 /* Hardware (RTS/CTS) flow control. */
81 SP_FLOW_HARDWARE = 1,
82 /* Software (XON/XOFF) flow control. */
f92f1f0c 83 SP_FLOW_SOFTWARE = 2,
ac74fdaf
ML
84};
85
77f262c4 86int sp_get_port_by_name(const char *portname, struct sp_port **port_ptr);
e3b2f7a4 87void sp_free_port(struct sp_port *port);
77f262c4 88int sp_list_ports(struct sp_port ***list_ptr);
32b5ac05 89int sp_copy_port(const struct sp_port *port, struct sp_port **copy_ptr);
d54e9004
ML
90void sp_free_port_list(struct sp_port **ports);
91int sp_open(struct sp_port *port, int flags);
74510d4b
ML
92int sp_close(struct sp_port *port);
93int sp_flush(struct sp_port *port);
94int sp_write(struct sp_port *port, const void *buf, size_t count);
95int sp_read(struct sp_port *port, void *buf, size_t count);
96int sp_set_params(struct sp_port *port, int baudrate, int bits, int parity,
97 int stopbits, int flowcontrol, int rts, int dtr);
98int sp_last_error_code(void);
99char *sp_last_error_message(void);
100void sp_free_error_message(char *message);
e8ffaee9 101
5ef8a1ed
UH
102#ifdef __cplusplus
103}
104#endif
105
f92f1f0c 106#endif /* LIBSERIALPORT_H */