#include "stdafx.h"
#include <stdio.h>
HANDLE hcom;
DWORD nobr;
DWORD nobw;
COMMTIMEOUTS comTimeOuts;
DCB dcb;
DWORD dwEvtMask;
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
void init(void)
{
//set COMMTIMEOUTS
comTimeOuts.ReadIntervalTimeout = MAXDWORD;
comTimeOuts.ReadTotalTimeoutConstant = 0;
comTimeOuts.ReadTotalTimeoutMultiplier = 0;
comTimeOuts.WriteTotalTimeoutConstant = 5000;
comTimeOuts.WriteTotalTimeoutMultiplier = 50;
SetCommTimeouts(hcom , &comTimeOuts);
GetCommState(hcom, &dcb);
dcb.BaudRate = CBR_38400;
dcb.fBinary = true;
dcb.fParity = false;
dcb.fOutxCtsFlow = false;
dcb.fOutxDsrFlow = false;
dcb.fDtrControl = DTR_CONTROL_DISABLE;
dcb.fDsrSensitivity = false;
dcb.fTXContinueOnXoff = false;
dcb.fOutX = false;
dcb.fInX = false;
dcb.fErrorChar = false;
dcb.fNull = false;
dcb.fRtsControl = RTS_CONTROL_DISABLE;
dcb.fAbortOnError = false;
dcb.ByteSize = 8;
dcb.Parity = NOPARITY;
dcb.StopBits = ONESTOPBIT;
SetCommState(hcom, &dcb);
}
CL800DEV_API bool __stdcall XCreateFile(char* fileName)
{
hcom = CreateFile(fileName,
GENERIC_READ |GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
if( hcom == INVALID_HANDLE_VALUE)
return false;
else
init();
return true;
}
CL800DEV_API int __stdcall XCloseHandle(void)
{
if(hcom)
{
CloseHandle(hcom);
return true;
}return false;
}
CL800DEV_API int __stdcall XWriteFile(LPCVOID lpBuffer,
DWORD nNumberOfBytesToWrite,
LPDWORD lpNumberOfBytesWritten)
{
return WriteFile(hcom, lpBuffer, nNumberOfBytesToWrite, lpNumberOfBytesWritten,NULL);
}
CL800DEV_API int __stdcall XReadFile(LPVOID lpBuffer,
DWORD nNumberOfBytesToRead,
LPDWORD lpNumberOfBytesRead)
{
return ReadFile(hcom, lpBuffer, nNumberOfBytesToRead, lpNumberOfBytesRead , NULL);
}