Commit c9ce172f authored by deuce's avatar deuce
Browse files

DLL-ify

parent 010380f0
......@@ -38,7 +38,7 @@
#include "comio.h"
#include "genwrap.h" /* msclock */
size_t comReadBuf(COM_HANDLE handle, char* buf, size_t buflen, const char* terminators, int timeout)
size_t COMIOCALL comReadBuf(COM_HANDLE handle, char* buf, size_t buflen, const char* terminators, int timeout)
{
BYTE ch;
size_t len=0;
......@@ -59,7 +59,7 @@ size_t comReadBuf(COM_HANDLE handle, char* buf, size_t buflen, const char* termi
return len;
}
size_t comReadLine(COM_HANDLE handle, char* buf, size_t buflen, int timeout)
size_t COMIOCALL comReadLine(COM_HANDLE handle, char* buf, size_t buflen, int timeout)
{
size_t len;
......
......@@ -42,6 +42,26 @@
#define COM_ERROR -1
#ifdef _WIN32
#ifdef __BORLANDC__
#define COMIOCALL __stdcall
#else
#define COMIOCALL
#endif
#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 COMIOCALL
#define COMIOEXPORT
#endif
#ifdef _WIN32
#include <windows.h>
......@@ -92,24 +112,24 @@
extern "C" {
#endif
char* comVersion(char* str, size_t len);
COM_HANDLE comOpen(const char* device);
BOOL comClose(COM_HANDLE);
long comGetBaudRate(COM_HANDLE);
BOOL comSetBaudRate(COM_HANDLE, ulong rate);
int comGetModemStatus(COM_HANDLE);
int comRaiseDTR(COM_HANDLE);
int comLowerDTR(COM_HANDLE);
BOOL comWriteByte(COM_HANDLE, BYTE);
int comWriteBuf(COM_HANDLE, const BYTE*, size_t buflen);
int comWriteString(COM_HANDLE, const char*);
BOOL comReadByte(COM_HANDLE, BYTE*);
size_t comReadBuf(COM_HANDLE, char* buf, size_t buflen
COMIOEXPORT char* COMIOCALL comVersion(char* str, size_t len);
COMIOEXPORT COM_HANDLE COMIOCALL comOpen(const char* device);
COMIOEXPORT BOOL COMIOCALL comClose(COM_HANDLE);
COMIOEXPORT long COMIOCALL comGetBaudRate(COM_HANDLE);
COMIOEXPORT BOOL COMIOCALL comSetBaudRate(COM_HANDLE, ulong rate);
COMIOEXPORT int COMIOCALL comGetModemStatus(COM_HANDLE);
COMIOEXPORT int COMIOCALL comRaiseDTR(COM_HANDLE);
COMIOEXPORT int COMIOCALL comLowerDTR(COM_HANDLE);
COMIOEXPORT BOOL COMIOCALL comWriteByte(COM_HANDLE, BYTE);
COMIOEXPORT int COMIOCALL comWriteBuf(COM_HANDLE, const BYTE*, size_t buflen);
COMIOEXPORT int COMIOCALL comWriteString(COM_HANDLE, const char*);
COMIOEXPORT BOOL COMIOCALL comReadByte(COM_HANDLE, BYTE*);
COMIOEXPORT size_t COMIOCALL comReadBuf(COM_HANDLE, char* buf, size_t buflen
,const char* terminators, int timeout /* in milliseconds */);
size_t comReadLine(COM_HANDLE, char* buf, size_t buflen
COMIOEXPORT size_t COMIOCALL comReadLine(COM_HANDLE, char* buf, size_t buflen
,int timeout /* in milliseconds */);
BOOL comPurgeInput(COM_HANDLE);
BOOL comPurgeOutput(COM_HANDLE);
COMIOEXPORT BOOL COMIOCALL comPurgeInput(COM_HANDLE);
COMIOEXPORT BOOL COMIOCALL comPurgeOutput(COM_HANDLE);
#if defined(__cplusplus)
}
......
......@@ -40,7 +40,7 @@
#include "comio.h"
#include "genwrap.h"
char* comVersion(char* str, size_t len)
char* COMIOCALL comVersion(char* str, size_t len)
{
char revision[16];
......@@ -50,7 +50,7 @@ char* comVersion(char* str, size_t len)
return str;
}
COM_HANDLE comOpen(const char* device)
COM_HANDLE COMIOCALL comOpen(const char* device)
{
COM_HANDLE handle;
struct termios t;
......@@ -101,12 +101,12 @@ Fun snippet from the FreeBSD manpage:
return handle;
}
BOOL comClose(COM_HANDLE handle)
BOOL COMIOCALL comClose(COM_HANDLE handle)
{
return (!close(handle));
}
long comGetBaudRate(COM_HANDLE handle)
long COMIOCALL comGetBaudRate(COM_HANDLE handle)
{
struct termios t;
speed_t in;
......@@ -124,7 +124,7 @@ long comGetBaudRate(COM_HANDLE handle)
return ((long)(in>out?in:out));
}
BOOL comSetBaudRate(COM_HANDLE handle, unsigned long rate)
BOOL COMIOCALL comSetBaudRate(COM_HANDLE handle, unsigned long rate)
{
struct termios t;
......@@ -139,7 +139,7 @@ BOOL comSetBaudRate(COM_HANDLE handle, unsigned long rate)
return TRUE;
}
int comGetModemStatus(COM_HANDLE handle)
int COMIOCALL comGetModemStatus(COM_HANDLE handle)
{
int status;
......@@ -149,24 +149,24 @@ int comGetModemStatus(COM_HANDLE handle)
return status;
}
BOOL comRaiseDTR(COM_HANDLE handle)
BOOL COMIOCALL comRaiseDTR(COM_HANDLE handle)
{
int flags = TIOCM_DTR;
return(ioctl(handle, TIOCMBIS, &flags)==0);
}
BOOL comLowerDTR(COM_HANDLE handle)
BOOL COMIOCALL comLowerDTR(COM_HANDLE handle)
{
int flags = TIOCM_DTR;
return(ioctl(handle, TIOCMBIC, &flags)==0);
}
BOOL comWriteByte(COM_HANDLE handle, BYTE ch)
BOOL COMIOCALL comWriteByte(COM_HANDLE handle, BYTE ch)
{
return(write(handle, &ch, 1)==1);
}
int comWriteBuf(COM_HANDLE handle, const BYTE* buf, size_t buflen)
int COMIOCALL comWriteBuf(COM_HANDLE handle, const BYTE* buf, size_t buflen)
{
return write(handle, buf, buflen);
}
......@@ -174,27 +174,27 @@ int comWriteBuf(COM_HANDLE handle, const BYTE* buf, size_t buflen)
/*
* TODO: This seem kinda dangerous for short writes...
*/
int comWriteString(COM_HANDLE handle, const char* str)
int COMIOCALL comWriteString(COM_HANDLE handle, const char* str)
{
return comWriteBuf(handle, (BYTE*)str, strlen(str));
}
BOOL comReadByte(COM_HANDLE handle, BYTE* ch)
BOOL COMIOCALL comReadByte(COM_HANDLE handle, BYTE* ch)
{
return(read(handle, ch, 1)==1);
}
BOOL comPurgeInput(COM_HANDLE handle)
BOOL COMIOCALL comPurgeInput(COM_HANDLE handle)
{
return(tcflush(handle, TCIFLUSH)==0);
}
BOOL comPurgeOutput(COM_HANDLE handle)
BOOL COMIOCALL comPurgeOutput(COM_HANDLE handle)
{
return(tcflush(handle, TCOFLUSH)==0);
}
BOOL comDrainOutput(COM_HANDLE handle)
BOOL COMIOCALL comDrainOutput(COM_HANDLE handle)
{
return(tcdrain(handle)==0);
}
......@@ -38,7 +38,7 @@
#include "comio.h"
#include "genwrap.h"
char* comVersion(char* str, size_t len)
char* COMIOCALL comVersion(char* str, size_t len)
{
char revision[16];
......@@ -48,7 +48,7 @@ char* comVersion(char* str, size_t len)
return str;
}
COM_HANDLE comOpen(const char* device)
COM_HANDLE COMIOCALL comOpen(const char* device)
{
COM_HANDLE handle;
COMMTIMEOUTS timeouts;
......@@ -85,12 +85,12 @@ COM_HANDLE comOpen(const char* device)
return handle;
}
BOOL comClose(COM_HANDLE handle)
BOOL COMIOCALL comClose(COM_HANDLE handle)
{
return CloseHandle(handle);
}
long comGetBaudRate(COM_HANDLE handle)
long COMIOCALL comGetBaudRate(COM_HANDLE handle)
{
DCB dcb;
......@@ -100,7 +100,7 @@ long comGetBaudRate(COM_HANDLE handle)
return dcb.BaudRate;
}
BOOL comSetBaudRate(COM_HANDLE handle, unsigned long rate)
BOOL COMIOCALL comSetBaudRate(COM_HANDLE handle, unsigned long rate)
{
DCB dcb;
......@@ -112,7 +112,7 @@ BOOL comSetBaudRate(COM_HANDLE handle, unsigned long rate)
return SetCommState(handle, &dcb);
}
int comGetModemStatus(COM_HANDLE handle)
int COMIOCALL comGetModemStatus(COM_HANDLE handle)
{
DWORD status=0;
......@@ -122,24 +122,24 @@ int comGetModemStatus(COM_HANDLE handle)
return COM_ERROR;
}
BOOL comRaiseDTR(COM_HANDLE handle)
BOOL COMIOCALL comRaiseDTR(COM_HANDLE handle)
{
return EscapeCommFunction(handle, SETDTR);
}
BOOL comLowerDTR(COM_HANDLE handle)
BOOL COMIOCALL comLowerDTR(COM_HANDLE handle)
{
return EscapeCommFunction(handle, CLRDTR);
}
BOOL comWriteByte(COM_HANDLE handle, BYTE ch)
BOOL COMIOCALL comWriteByte(COM_HANDLE handle, BYTE ch)
{
DWORD wr=0;
return WriteFile(handle, &ch, sizeof(ch), &wr, NULL) && wr==sizeof(BYTE);
}
int comWriteBuf(COM_HANDLE handle, const BYTE* buf, size_t buflen)
int COMIOCALL comWriteBuf(COM_HANDLE handle, const BYTE* buf, size_t buflen)
{
DWORD wr=0;
......@@ -149,24 +149,24 @@ int comWriteBuf(COM_HANDLE handle, const BYTE* buf, size_t buflen)
return wr;
}
int comWriteString(COM_HANDLE handle, const char* str)
int COMIOCALL comWriteString(COM_HANDLE handle, const char* str)
{
return comWriteBuf(handle, str, strlen(str));
}
BOOL comReadByte(COM_HANDLE handle, BYTE* ch)
BOOL COMIOCALL comReadByte(COM_HANDLE handle, BYTE* ch)
{
DWORD rd;
return ReadFile(handle, ch, sizeof(BYTE), &rd, NULL) && rd==sizeof(BYTE);
}
BOOL comPurgeInput(COM_HANDLE handle)
BOOL COMIOCALL comPurgeInput(COM_HANDLE handle)
{
return PurgeComm(handle, PURGE_RXCLEAR);
}
BOOL comPurgeOutput(COM_HANDLE handle)
BOOL COMIOCALL comPurgeOutput(COM_HANDLE handle)
{
return PurgeComm(handle, PURGE_TXCLEAR);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment