www.pudn.com > HPMapx.rar > SerialPort.h


// SerialPort.h 
 
#ifndef __SERIALPORT_H__ 
#define __SERIALPORT_H__ 
 
#pragma once 
// CE Communication Port Class Modified by brent 
 
struct COMM_SET 
{ 
	HWND	pPortOwner; 
	UINT	portnr; 
	UINT	baud; 
	char	parity; 
	UINT	databits; 
	UINT	stopbits; 
	DWORD	dwCommEvents; 
	 
	COMM_SET(HWND p) 
	{ 
		portnr		= 8; 
		baud		= 4800; 
		databits	= 8; 
		parity		= 'N'; 
		stopbits	= 1; 
		pPortOwner	= p; 
	} 
}; 
 
const CHAR CH_BEGIN = 0x01; 
const CHAR CH_EXIT  = 0x00; 
 
class CCommCE   
{ 
public:	 
	CCommCE() 		{m_hComm=NULL; m_iThreadFlag=CH_EXIT;hOwnerWnd=NULL;} 
	virtual ~CCommCE()	{m_iThreadFlag = CH_EXIT;CloseComm();	} 
	 
	 
	bool	Open(COMM_SET &nCommSet,int nPort=8); 
	bool	IsOpen()	{ return m_iThreadFlag==CH_BEGIN;	} 
	void	Close()		{ StopMonitor();	CloseComm();	} 
	LPCTSTR GetLastError()	{ return strErrorMessage;		} 
	HWND	GetOwerWindow()	{ return hOwnerWnd;			} 
private: 
 
	HANDLE			m_hComm; 
	CHAR			m_iThreadFlag; 
	CWinThread*		m_Thread; 
	CString			strErrorMessage; 
	HWND			hOwnerWnd; 
public: 
 
	static void ReadData(CCommCE* nPort); 
	static UINT CommThread( LPVOID pParam); 
private: 
	bool	StartMonitor(); 
	bool	StopMonitor()	{m_iThreadFlag = CH_EXIT;return true;	} 
	void	CloseComm()	{if(m_hComm != NULL){CloseHandle(m_hComm);m_hComm = NULL;}} 
 
}; 
 
#endif __SERIALPORT_H__