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