Knowledge Base Nr: 00078 SerialCom.cpp - http://www.swe-kaiser.de
Downloads:
Win32: SerialCom.h: interface for the CSerialCom class.
#if !defined(AFX_SERIALCOM_H__95148BF0_2F70_11D5_96E9_0010B53CEFC1__INCLUDED_)
#define AFX_SERIALCOM_H__95148BF0_2F70_11D5_96E9_0010B53CEFC1__INCLUDED_
#include <windows.h>
class CSerialCom
{
public:
CSerialCom(char* szPort, int nBaudRate, char cParity, int nByteSize, int nStopBits);
virtual ~CSerialCom();
FILE* GetLogFileFP() { return m_fpLogfile; }
void SetLogFileFP(FILE* fp) { m_fpLogfile = fp; }
int Write(const char* lpszParam, int nParamLen);
int WriteWithRetries(const char* lpszParam, int nParamLen, int nRetries = 0, int nDelay = 100);
int Free();
int Purge();
int Init();
int Read(char* szReceive, int* nRecvLen, int nTimeOutMS = 0, char* szEndOfData = NULL);
void SetDelays(unsigned long dwSendDelay, unsigned long dwReadDelay) { m_dwSLEEPSEND = dwSendDelay; m_dwSLEEPRECV = dwReadDelay; }
protected:
void WriteLog(const char *szHeader, const char* szFormat, ...);
private:
char m_szPort[20];
int m_nBaudRate;
int m_nByteSize;
char m_cParity;
int m_nStopBits;
unsigned long m_dwSLEEPSEND;
unsigned long m_dwSLEEPRECV;
HANDLE m_hndPort;
FILE* m_fpLogfile;
};
#endif // !defined(AFX_SERIALCOM_H__95148BF0_2F70_11D5_96E9_0010B53CEFC1__INCLUDED_)