#ifndef __DppComm_H__INCLUDED_ #define __DppComm_H__INCLUDED_ #define WM_DPPCOMM_RCV_CHAR (WM_USER + 400) #define EV_THREAD_EXIT_EVENT 0 #define EV_READ_STATUS_EVENT 1 #define EV_WRITE_DATA_EVENT 2 static size_t m_SendBytes; static BOOL ExitEvent; class CDppComm { public: CDppComm(); virtual ~CDppComm(); BOOL Settings(CWnd* hPortWnd, UINT PortID = 1, UINT BaudRate = 115200, char Parity = 'N', UINT DataBits = 8, UINT StopBits = 1, DWORD dwCommEvents = EV_RXCHAR, UINT nBufferSize = 1024); BOOL OpenPort(); BOOL ClosePort(); BOOL IsPortOpen(); UINT GetComPortID(); void WriteData(unsigned char* string, size_t NumBytes); bool SendPacketRS232(unsigned char Buffer[], CDppComm *CommPort); protected: void GetCommErrStr(char* ErrorText); static UINT DppCommThread(LPVOID pParam); static void ReceiveByte(CDppComm* port, COMSTAT comStat); static void WriteByte(CDppComm* port); CWinThread* m_WinThread; CRITICAL_SECTION m_csCommunicationSync; BOOL m_bThreadRunning; HANDLE ghThreadExitEvent; HANDLE m_hDppComm; HANDLE m_hWriteEvent; HANDLE m_hEvents[3]; OVERLAPPED osIO; // overlapped structure for asynchronous IO COMMTIMEOUTS m_CommTimeouts; DCB m_dcb; CWnd* m_pOwner; unsigned char* m_szWriteBuffer; DWORD m_dwCommEvents; DWORD m_nWriteBufferSize; UINT PortIDSetting; BOOL PortIsOpen; }; #endif __DppComm_H__INCLUDED_