2013-04-28 02:35:45 +04:00
|
|
|
/*
|
|
|
|
* This file is part of the libserialport project.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013 Martin Ling <martin-libserialport@earth.li>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2013-11-14 20:33:53 +04:00
|
|
|
#ifndef LIBSERIALPORT_H
|
|
|
|
#define LIBSERIALPORT_H
|
2013-10-27 19:42:08 +04:00
|
|
|
|
2013-11-15 00:58:03 +04:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2013-04-28 02:35:45 +04:00
|
|
|
#include <stddef.h>
|
|
|
|
#ifdef _WIN32
|
|
|
|
#include <windows.h>
|
|
|
|
#endif
|
|
|
|
|
2013-11-15 01:16:11 +04:00
|
|
|
/* Package version macros (e.g. for conditional compilation). */
|
|
|
|
#define SP_PACKAGE_VERSION_MAJOR @SP_PACKAGE_VERSION_MAJOR@
|
|
|
|
#define SP_PACKAGE_VERSION_MINOR @SP_PACKAGE_VERSION_MINOR@
|
|
|
|
#define SP_PACKAGE_VERSION_STRING "@SP_PACKAGE_VERSION@"
|
|
|
|
|
|
|
|
/* Library/libtool version macros (e.g. for conditional compilation). */
|
|
|
|
#define SP_LIB_VERSION_CURRENT @SP_LIB_VERSION_CURRENT@
|
|
|
|
#define SP_LIB_VERSION_REVISION @SP_LIB_VERSION_REVISION@
|
|
|
|
#define SP_LIB_VERSION_AGE @SP_LIB_VERSION_AGE@
|
|
|
|
#define SP_LIB_VERSION_STRING "@SP_LIB_VERSION@"
|
|
|
|
|
2013-04-28 02:35:45 +04:00
|
|
|
/* A serial port. */
|
|
|
|
struct sp_port {
|
|
|
|
/* Name used to open the port */
|
|
|
|
char *name;
|
|
|
|
/* OS-specific port handle */
|
|
|
|
#ifdef _WIN32
|
|
|
|
HANDLE hdl;
|
|
|
|
#else
|
|
|
|
int fd;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2013-11-14 22:41:28 +04:00
|
|
|
/* Configuration for a serial port. */
|
|
|
|
struct sp_port_config {
|
|
|
|
int baudrate;
|
|
|
|
int bits;
|
|
|
|
int parity;
|
|
|
|
int stopbits;
|
|
|
|
int flowcontrol;
|
|
|
|
int rts;
|
2013-11-15 01:12:17 +04:00
|
|
|
int cts;
|
2013-11-14 22:41:28 +04:00
|
|
|
int dtr;
|
2013-11-15 01:12:17 +04:00
|
|
|
int dsr;
|
|
|
|
int xon_xoff;
|
2013-11-14 22:41:28 +04:00
|
|
|
};
|
|
|
|
|
2013-04-28 02:35:45 +04:00
|
|
|
/* Return values. */
|
|
|
|
enum {
|
|
|
|
/* Operation completed successfully. */
|
|
|
|
SP_OK = 0,
|
|
|
|
/* Invalid arguments were passed to the function. */
|
2013-11-04 00:21:36 +04:00
|
|
|
SP_ERR_ARG = -1,
|
|
|
|
/* A system error occured while executing the operation. */
|
|
|
|
SP_ERR_FAIL = -2,
|
|
|
|
/* A memory allocation failed while executing the operation. */
|
2013-11-14 20:33:53 +04:00
|
|
|
SP_ERR_MEM = -3,
|
2013-04-28 02:35:45 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Port access modes. */
|
|
|
|
enum {
|
|
|
|
/* Open port for read/write access. */
|
|
|
|
SP_MODE_RDWR = 1,
|
|
|
|
/* Open port for read access only. */
|
|
|
|
SP_MODE_RDONLY = 2,
|
|
|
|
/* Open port in non-blocking mode. */
|
2013-11-14 20:33:53 +04:00
|
|
|
SP_MODE_NONBLOCK = 4,
|
2013-04-28 02:35:45 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Parity settings. */
|
|
|
|
enum {
|
|
|
|
/* No parity. */
|
|
|
|
SP_PARITY_NONE = 0,
|
|
|
|
/* Even parity. */
|
|
|
|
SP_PARITY_EVEN = 1,
|
|
|
|
/* Odd parity. */
|
2013-11-14 20:33:53 +04:00
|
|
|
SP_PARITY_ODD = 2,
|
2013-04-28 02:35:45 +04:00
|
|
|
};
|
|
|
|
|
2013-11-15 01:12:17 +04:00
|
|
|
/* RTS pin behaviour. */
|
2013-10-27 21:24:12 +04:00
|
|
|
enum {
|
2013-11-15 01:12:17 +04:00
|
|
|
SP_RTS_OFF = 0,
|
|
|
|
SP_RTS_ON = 1,
|
|
|
|
SP_RTS_FLOW_CONTROL = 2
|
|
|
|
};
|
|
|
|
|
|
|
|
/* CTS pin behaviour. */
|
|
|
|
enum {
|
|
|
|
SP_CTS_IGNORE = 0,
|
|
|
|
SP_CTS_FLOW_CONTROL = 1
|
|
|
|
};
|
|
|
|
|
|
|
|
/* DTR pin behaviour. */
|
|
|
|
enum {
|
|
|
|
SP_DTR_OFF = 0,
|
|
|
|
SP_DTR_ON = 1,
|
|
|
|
SP_DTR_FLOW_CONTROL = 2
|
|
|
|
};
|
|
|
|
|
|
|
|
/* DSR pin behaviour. */
|
|
|
|
enum {
|
|
|
|
SP_DSR_IGNORE = 0,
|
|
|
|
SP_DSR_FLOW_CONTROL = 1
|
|
|
|
};
|
|
|
|
|
|
|
|
/* XON/XOFF flow control behaviour. */
|
|
|
|
enum {
|
|
|
|
SP_XONXOFF_DISABLED = 0,
|
|
|
|
SP_XONXOFF_IN = 1,
|
|
|
|
SP_XONXOFF_OUT = 2,
|
|
|
|
SP_XONXOFF_INOUT = 3
|
2013-10-27 21:24:12 +04:00
|
|
|
};
|
|
|
|
|
2013-11-04 02:15:54 +04:00
|
|
|
int sp_get_port_by_name(const char *portname, struct sp_port **port_ptr);
|
2013-11-04 02:27:59 +04:00
|
|
|
void sp_free_port(struct sp_port *port);
|
2013-11-04 02:15:54 +04:00
|
|
|
int sp_list_ports(struct sp_port ***list_ptr);
|
2013-11-04 17:42:55 +04:00
|
|
|
int sp_copy_port(const struct sp_port *port, struct sp_port **copy_ptr);
|
2013-11-04 01:17:21 +04:00
|
|
|
void sp_free_port_list(struct sp_port **ports);
|
|
|
|
int sp_open(struct sp_port *port, int flags);
|
2013-04-28 02:35:45 +04:00
|
|
|
int sp_close(struct sp_port *port);
|
|
|
|
int sp_flush(struct sp_port *port);
|
|
|
|
int sp_write(struct sp_port *port, const void *buf, size_t count);
|
|
|
|
int sp_read(struct sp_port *port, void *buf, size_t count);
|
2013-11-14 22:41:28 +04:00
|
|
|
int sp_set_config(struct sp_port *port, struct sp_port_config *config);
|
2013-04-28 02:35:45 +04:00
|
|
|
int sp_last_error_code(void);
|
|
|
|
char *sp_last_error_message(void);
|
|
|
|
void sp_free_error_message(char *message);
|
2013-10-27 19:42:08 +04:00
|
|
|
|
2013-11-15 00:58:03 +04:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-11-14 20:33:53 +04:00
|
|
|
#endif /* LIBSERIALPORT_H */
|