⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 doc.cpp

📁 《WinCE.NET嵌入式工业用控制器及自动控制系统设计》的源代码
💻 CPP
字号:
// Doc.cpp : implementation of the CDoc class
//

#include "stdafx.h"
#include "Demo8000.h"

#include "Doc.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

#include "ModbusThread.cpp"   // add by Yeh

/////////////////////////////////////////////////////////////////////////////
// CDoc

IMPLEMENT_DYNCREATE(CDoc, CDocument)

BEGIN_MESSAGE_MAP(CDoc, CDocument)
	//{{AFX_MSG_MAP(CDoc)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDoc construction/destruction

CDoc::CDoc()
{
	// TODO: add one-time construction code here
//----------------- add by Yeh -------------------
	if(read_sys_table() != 0) return;
	set_initial_TAG();

	// TODO: add construction code here
	// This is the flag that tells the
	// thread to quit.
	m_bTCPSlaveKill = FALSE;
	m_bControlKill = FALSE;
	m_bRTUMasterKill = FALSE;

	// NULL the pointer to the thread so
	// we know it hasn't been created.
	m_pTCPSlaveThread = NULL;
	m_pControlThread = NULL;
	m_pRTUMasterThread = NULL;

	if( m_pTCPSlaveThread == NULL )
	{
		// Store the window handle and the Kill flag.
		m_TCPSlaveThreadInfo.hWnd = NULL;
		m_TCPSlaveThreadInfo.Para_1 = NULL;
		m_TCPSlaveThreadInfo.Para_2 = NULL;
		m_TCPSlaveThreadInfo.lpKillThread = &m_bTCPSlaveKill;

		// Start the thread.
		m_pTCPSlaveThread =
			AfxBeginThread(TCPSlaveThreadProc, (LPVOID) &m_TCPSlaveThreadInfo);
	}			

	if( m_pControlThread == NULL )
	{
		// Store the window handle and the Kill flag.
		m_ControlThreadInfo.hWnd = NULL;
		m_ControlThreadInfo.Para_1 = NULL;
		m_ControlThreadInfo.Para_2 = NULL;
		m_ControlThreadInfo.lpKillThread = &m_bControlKill;

		// Start the thread.
		m_pControlThread =
			AfxBeginThread(ControlThreadProc, (LPVOID) &m_ControlThreadInfo);
	}			

	if( m_pRTUMasterThread == NULL )
	{
		// Store the window handle and the Kill flag.
		m_RTUMasterThreadInfo.hWnd = NULL;
		m_RTUMasterThreadInfo.Para_1 = NULL;
		m_RTUMasterThreadInfo.Para_2 = NULL;
		m_RTUMasterThreadInfo.lpKillThread = &m_bRTUMasterKill;

		// Start the thread.
		m_pRTUMasterThread =
			AfxBeginThread(RTUMasterThreadProc, (LPVOID) &m_RTUMasterThreadInfo);
	}			
//--------------- end of add ----------------------

}

CDoc::~CDoc()
{
HANDLE hThread;
BOOL flag;

flag= false;
if(m_pTCPSlaveThread != NULL)
{
	hThread =m_pTCPSlaveThread->m_hThread;
	// Set the flag to kill the thread to TRUE;
	m_bTCPSlaveKill = TRUE;
	// Wait for the thread to end.
	::WaitForSingleObject( hThread, 5000 );
}

if(flag==false && m_pControlThread != NULL)
{
	hThread =m_pControlThread->m_hThread;
	// Set the flag to kill the thread to TRUE;
	m_bControlKill = TRUE;
	// Wait for the thread to end.
	::WaitForSingleObject( hThread, 5000 );
}
}

BOOL CDoc::OnNewDocument()
{
	if (!CDocument::OnNewDocument())
		return FALSE;

	// TODO: add reinitialization code here
	// (SDI documents will reuse this document)

	return TRUE;
}



/////////////////////////////////////////////////////////////////////////////
// CDoc serialization

void CDoc::Serialize(CArchive& ar)
{
	if (ar.IsStoring())
	{
		// TODO: add storing code here
	}
	else
	{
		// TODO: add loading code here
	}
}

/////////////////////////////////////////////////////////////////////////////
// CDoc diagnostics

#ifdef _DEBUG
void CDoc::AssertValid() const
{
	CDocument::AssertValid();
}

void CDoc::Dump(CDumpContext& dc) const
{
	CDocument::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CDoc commands

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -