]>
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 | ||
e8ffaee9 ML |
20 | #ifndef SERIALPORT_H |
21 | #define SERIALPORT_H | |
22 | ||
74510d4b ML |
23 | #include <stddef.h> |
24 | #ifdef _WIN32 | |
25 | #include <windows.h> | |
26 | #endif | |
27 | ||
28 | /* A serial port. */ | |
29 | struct sp_port { | |
30 | /* Name used to open the port */ | |
31 | char *name; | |
32 | /* OS-specific port handle */ | |
33 | #ifdef _WIN32 | |
34 | HANDLE hdl; | |
35 | #else | |
36 | int fd; | |
37 | #endif | |
38 | }; | |
39 | ||
40 | /* Return values. */ | |
41 | enum { | |
42 | /* Operation completed successfully. */ | |
43 | SP_OK = 0, | |
44 | /* A system error occured while executing the operation. */ | |
45 | SP_ERR_FAIL = -1, | |
46 | /* Invalid arguments were passed to the function. */ | |
47 | SP_ERR_ARG = -2 | |
48 | }; | |
49 | ||
50 | /* Port access modes. */ | |
51 | enum { | |
52 | /* Open port for read/write access. */ | |
53 | SP_MODE_RDWR = 1, | |
54 | /* Open port for read access only. */ | |
55 | SP_MODE_RDONLY = 2, | |
56 | /* Open port in non-blocking mode. */ | |
57 | SP_MODE_NONBLOCK = 4 | |
58 | }; | |
59 | ||
60 | /* Parity settings. */ | |
61 | enum { | |
62 | /* No parity. */ | |
63 | SP_PARITY_NONE = 0, | |
64 | /* Even parity. */ | |
65 | SP_PARITY_EVEN = 1, | |
66 | /* Odd parity. */ | |
67 | SP_PARITY_ODD = 2 | |
68 | }; | |
69 | ||
ac74fdaf ML |
70 | /* Flow control settings. */ |
71 | enum { | |
72 | /* No flow control. */ | |
73 | SP_FLOW_NONE = 0, | |
74 | /* Hardware (RTS/CTS) flow control. */ | |
75 | SP_FLOW_HARDWARE = 1, | |
76 | /* Software (XON/XOFF) flow control. */ | |
77 | SP_FLOW_SOFTWARE = 2 | |
78 | }; | |
79 | ||
3b63f34d ML |
80 | char **sp_list_ports(void); |
81 | void sp_free_port_list(char **ports); | |
74510d4b ML |
82 | int sp_open(struct sp_port *port, char *portname, int flags); |
83 | int sp_close(struct sp_port *port); | |
84 | int sp_flush(struct sp_port *port); | |
85 | int sp_write(struct sp_port *port, const void *buf, size_t count); | |
86 | int sp_read(struct sp_port *port, void *buf, size_t count); | |
87 | int sp_set_params(struct sp_port *port, int baudrate, int bits, int parity, | |
88 | int stopbits, int flowcontrol, int rts, int dtr); | |
89 | int sp_last_error_code(void); | |
90 | char *sp_last_error_message(void); | |
91 | void sp_free_error_message(char *message); | |
e8ffaee9 ML |
92 | |
93 | #endif /* SERIALPORT_H */ |