#if !defined(AFX_RS232THREAD_H__F668C981_9AA9_11D4_A856_0010B503CEA7__INCLUDED_)
#define AFX_RS232THREAD_H__F668C981_9AA9_11D4_A856_0010B503CEA7__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// Rs232Thread.h : header file
//

#define WM_RS232_DISCONNECT		(WM_USER + 0x101)
#define WM_RS232_SAVING_FILE	(WM_USER + 0x102)
#define WM_RS232_START_DEBUG	(WM_USER + 0x103)

/////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////
// CRs232Wnd window

class CRs232Wnd : public CWnd
{
// Construction
public:
	CRs232Wnd();

// Attributes
public:
	BOOL Create();
	void BeginSavingFile(char * p);
	void EndSavingFile();
	void StartDebug();

// Operations
public:

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CRs232Wnd)
	public:
	virtual BOOL DestroyWindow();
	//}}AFX_VIRTUAL

// Implementation
public:
	virtual ~CRs232Wnd();

	// Generated message map functions
protected:
	//{{AFX_MSG(CRs232Wnd)
	afx_msg void OnClose();
	//}}AFX_MSG
#if _MSC_VER >= 1300
	afx_msg LRESULT OnData(WPARAM wParam, LPARAM lParam);
	afx_msg LRESULT OnError(WPARAM wParam, LPARAM lParam);
#else
	afx_msg void OnData(WPARAM wParam, LPARAM lParam);
	afx_msg void OnError(WPARAM wParam, LPARAM lParam);
#endif
	DECLARE_MESSAGE_MAP()

protected:
	BOOL m_bDebug;
	BOOL m_bSavingFile;
	int  m_iCountFile;
	int  m_iTotalFile;
	char * m_pFileBuf;

	int  m_iCountH55;
	int  m_iCountHaa;
	int  m_iCountHff;
	int  m_iCountH00;

	CEdit * m_pEdit;

protected:
	static void CheckProtocol(int iVal, int & iCountHxx);
};



/////////////////////////////////////////////////////////////////////////////
// CRs232Thread thread

class CRs232Thread : public CWinThread
{
	DECLARE_DYNCREATE(CRs232Thread)
public:
	CRs232Thread(); 

	void operator delete(void* p);

// Attributes
public:
	static HANDLE m_hEventThreadKilled;
	static HANDLE m_hEventThreadCreated;
	static HANDLE m_hEventProtocol;

	static void PrepareEvent();
	static void UnprepareEvent();

// Operations
public:

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CRs232Thread)
	public:
	virtual BOOL InitInstance();
	virtual int ExitInstance();
	//}}AFX_VIRTUAL

// Implementation
public:
	virtual ~CRs232Thread();

	// Generated message map functions
	//{{AFX_MSG(CRs232Thread)
		// NOTE - the ClassWizard will add and remove member functions here.
	//}}AFX_MSG
	afx_msg void OnDisconnect(WPARAM wParam = 0, LPARAM lParam = 0);
	afx_msg void OnSavingFile(WPARAM wParam, LPARAM lParam);
	afx_msg void OnStartDebug(WPARAM wParam = 0, LPARAM lParam = 0);
	DECLARE_MESSAGE_MAP()

protected:
	CRs232Wnd m_wndRs232;
};

/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_RS232THREAD_H__F668C981_9AA9_11D4_A856_0010B503CEA7__INCLUDED_)
