comio.h 4.89 KB
Newer Older
1 2 3 4 5 6
/* Synchronet Serial Communications (COM) I/O Library */

/****************************************************************************
 * @format.tab-size 4		(Plain Text/Source Code File Header)			*
 * @format.use-tabs true	(see http://www.synchro.net/ptsc_hdr.html)		*
 *																			*
7
 * Copyright Rob Swindell - http://www.synchro.net/copyright.html			*
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
 *																			*
 * This library 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 2			*
 * of the License, or (at your option) any later version.					*
 * See the GNU Lesser General Public License for more details: lgpl.txt or	*
 * http://www.fsf.org/copyleft/lesser.html									*
 *																			*
 * Anonymous FTP access to the most recent released source is available at	*
 * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net	*
 *																			*
 * Anonymous CVS access to the development source and modification history	*
 * is available at cvs.synchro.net:/cvsroot/sbbs, example:					*
 * cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs login			*
 *     (just hit return, no password is necessary)							*
 * cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs checkout src		*
 *																			*
 * For Synchronet coding style and modification guidelines, see				*
 * http://www.synchro.net/source.html										*
 *																			*
 * You are encouraged to submit any modifications (preferably in Unix diff	*
 * format) via e-mail to mods@synchro.net									*
 *																			*
 * Note: If this box doesn't appear square, then you need to fix your tabs.	*
 ****************************************************************************/

#ifndef _COMIO_H
#define _COMIO_H

37
#include <limits.h>	/* INT_MAX */
38 39 40
#include <gen_defs.h>	/* BOOL */

#define COM_ERROR						-1
41
#define COM_INFINITE_TIMEOUT	INT_MIN
42

deuce's avatar
DLL-ify  
deuce committed
43 44 45 46 47 48 49 50 51 52 53 54 55 56
#ifdef _WIN32
	#if defined(COMIO_IMPORTS) || defined(COMIO_EXPORTS)
		#if defined(COMIO_IMPORTS)
			#define COMIOEXPORT __declspec( dllimport )
		#else
			#define COMIOEXPORT __declspec( dllexport )
		#endif
	#else	/* self-contained executable */
		#define COMIOEXPORT
	#endif
#else
	#define COMIOEXPORT
#endif

57 58 59 60 61 62 63 64 65 66 67 68
#ifdef _WIN32
	#include <windows.h>

    #define COM_HANDLE					HANDLE
	#define COM_HANDLE_INVALID			INVALID_HANDLE_VALUE
	#define COM_ERROR_VALUE				GetLastError()
/* Modem Status bits */
	#define COM_CTS						MS_CTS_ON
	#define COM_DSR						MS_DSR_ON
	#define COM_RING					MS_RING_ON
	#define	COM_DCD						MS_RLSD_ON
#else
deuce's avatar
deuce committed
69 70
	#include <termios.h>

71 72 73
    #define COM_HANDLE					int
	#define COM_HANDLE_INVALID			-1
	#define COM_ERROR_VALUE				errno
deuce's avatar
deuce committed
74

rswindell's avatar
rswindell committed
75
/* Stuff we apparently don't care about... 
deuce's avatar
deuce committed
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
 *
 *	TIOCM_LE   Line Enable.
 *	TIOCM_DTR  Data Terminal Ready.
 *	TIOCM_RTS  Request To Send.
 *	TIOCM_ST   Secondary Transmit.
 *	TIOCM_SR   Secondary Receive.
 */

	#define COM_CTS						TIOCM_CTS  /* Clear To Send. */
#ifdef TIOCM_CAR
	#define COM_DCD						TIOCM_CAR  /* Carrier Detect. */
#else
	#define COM_DCD						TIOCM_CD   /* Carrier Detect (synonym). */
#endif
#ifdef TIOCM_RNG
	#define COM_RING					TIOCM_RNG  /* Ring Indication. */
#else
	#define COM_RING					TIOCM_RI   /* Ring Indication (synonym). */
#endif
	#define COM_DSR						TIOCM_DSR  /* Data Set Ready. */

97 98
#endif

99 100 101 102
#define COM_FLOW_CONTROL_NONE			0
#define COM_FLOW_CONTROL_RTS_CTS		(1<<0)
#define COM_FLOW_CONTROL_DTR_DSR		(1<<1)
#define COM_FLOW_CONTROL_XON_OFF		(1<<2)
103

104 105 106 107 108 109 110 111
/**************/
/* Prototypes */
/**************/

#if defined(__cplusplus)
extern "C" {
#endif

rswindell's avatar
rswindell committed
112 113 114 115 116
COMIOEXPORT char*		comVersion(char* str, size_t len);
COMIOEXPORT COM_HANDLE	comOpen(const char* device);
COMIOEXPORT BOOL		comClose(COM_HANDLE);
COMIOEXPORT long		comGetBaudRate(COM_HANDLE);
COMIOEXPORT BOOL		comSetBaudRate(COM_HANDLE, ulong rate);
117 118
COMIOEXPORT int			comGetFlowControl(COM_HANDLE);
COMIOEXPORT BOOL		comSetFlowControl(COM_HANDLE, int);
rswindell's avatar
rswindell committed
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
COMIOEXPORT int			comGetModemStatus(COM_HANDLE);
COMIOEXPORT int			comRaiseDTR(COM_HANDLE);
COMIOEXPORT int			comLowerDTR(COM_HANDLE);
COMIOEXPORT int			comRaiseRTS(COM_HANDLE);
COMIOEXPORT int			comLowerRTS(COM_HANDLE);
COMIOEXPORT BOOL		comWriteByte(COM_HANDLE, BYTE);
COMIOEXPORT int			comWriteBuf(COM_HANDLE, const BYTE*, size_t buflen);
COMIOEXPORT int			comWriteString(COM_HANDLE, const char*);
COMIOEXPORT BOOL		comReadByte(COM_HANDLE, BYTE*);
COMIOEXPORT size_t		comReadBuf(COM_HANDLE, char* buf, size_t buflen
							,const char* terminators, int timeout /* in milliseconds */);
COMIOEXPORT size_t		comReadLine(COM_HANDLE, char* buf, size_t buflen
							,int timeout /* in milliseconds */);
COMIOEXPORT BOOL		comPurgeInput(COM_HANDLE);
COMIOEXPORT BOOL		comPurgeOutput(COM_HANDLE);
134
COMIOEXPORT BOOL		comSetParity(COM_HANDLE, BOOL enable, BOOL odd);
135
COMIOEXPORT BOOL		comSetBits(COM_HANDLE, size_t byteSize, size_t stopBits);
136 137 138 139 140 141 142

#if defined(__cplusplus)
}
#endif


#endif /* Don't add anything after this #endif statement */