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

📄 readme.wzd

📁 E:Visual_C__MFC扩展编程实例 实例52:使用串行或并行I/O
💻 WZD
字号:
/////////////////////////////////////////////////////////////////////
// Example files...
/////////////////////////////////////////////////////////////////////

WzdPrtIO.cpp -- CWzdPortIO, a class that handles multiple serial or
WzdPrtIO.h        parallel connections

WzdQue.cpp -- CWzdQueue, a CObList derived class that queues messages
WzdQue.h

/////////////////////////////////////////////////////////////////////
// Using CWzdPortIO for Parallel Communication....
/////////////////////////////////////////////////////////////////////

// 1) Embed CWzdPortIO and CWzdQueue in a window class such as CMainFrame:

	CWzdPortIO m_parallel;
	CWzdQueue m_queue;


// 2) Open the connection and start listening with:

	CFileException e;
	if (m_parallel.OpenLPT(
		1,			// LPT number (1,2,etc.)
		&e			// exception errors (defaults to NULL)
		))
	{
		char hello[]={"Hello!"};
		m_parallel.Send(
			hello,	// buffer to send
			7		// length of buffer to send
			);


		m_parallel.Listen(
		10,			// size of message header
		-1,			// position of size of message body in header
					// -1 means all message lengths are fixed
		&m_queue,	// CWzdQue to store new messages
		this,		// pWnd of window to send "new message" message
		WM_NEW_MESSAGE, // message to send
		0			// the user defined id of which port sent the message
		);
	}


// 3) Process messages received by this port by adding a WM_NEW_MESSAGE handler 
// to your class:

	ON_MESSAGE(WM_NEW_MESSAGE,OnNewMessage)
		:	:	:

LRESULT CMainFrame::OnNewMessage(WPARAM,LPARAM) 
{
	CWzdMsg *pMsg=NULL;
	while (pMsg=m_queue.Remove())
	{
		// pMsg contains:
		//		m_nID -- the user defined id of which port sent the message
		//		m_pHdr -- the message header
		//		m_pBody -- the message body
		//		m_len --	the total message length
		//		m_error --	any errors

		// make sure to delete the message after processing!
		delete pMsg;
	}
	return 0L;
}


/////////////////////////////////////////////////////////////////////
// Using CWzdPortIO for Serial Communication....
/////////////////////////////////////////////////////////////////////

// 1) Embed CWzdPortIO and CWzdQueue in a window class such as CMainFrame:

	CWzdPortIO m_serial;
	CWzdQueue m_queue;


// 2) Open the connection and start listening with:

void CMainFrame::OnTestSerial() 
{
	CFileException e;
	if (m_serial.OpenCOM(
		1,			// COM number (1,2,etc.)
		&e,			// exception errors (defaults to NULL)
		CBR_19200,	// baud rate, also CBR_1200, CBR_2400, etc.
		NOPARITY,	// parity, also EVENPARITY, ODDPARITY, MARKPARITY, SPACEPARITY
		8,			// number of bits in a byte
		ONESTOPBIT // stopbits, also ONE5STOPBITS, TWOSTOPBITS
		))

	{
		char hello[]={"Hello!"};
		m_serial.Send(
			hello,	// buffer to send
			7		// length of buffer to send
			);

		m_serial.Listen(
		10,			// size of message header
		-1,			// position of size of message body in header
					// -1 means all message lengths are fixed
		&m_queue,	// CWzdQue to store new messages
		this,		// pWnd of window to send "new message" message
		WM_NEW_MESSAGE, // message to send
		1			// the user defined id of which port sent the message
		);
	}
}

// 3) Process messages received by this port by adding a WM_NEW_MESSAGE handler 
// to your class (same as above):

	ON_MESSAGE(WM_NEW_MESSAGE,OnNewMessage)
		:	:	:

LRESULT CMainFrame::OnNewMessage(WPARAM,LPARAM) 
{
	CWzdMsg *pMsg=NULL;
	while (pMsg=m_queue.Remove())
	{
		// pMsg contains:
		//		m_nID -- the user defined id of which port sent the message
		//		m_pHdr -- the message header
		//		m_pBody -- the message body
		//		m_len --	the total message length
		//		m_error --	any errors

		// make sure to delete the message after processing!
		delete pMsg;
	}
	return 0L;
}

/////////////////////////////////////////////////////////////////////
// From: Visual C++ MFC Programming by Example by John E. Swanke
// Copyright (C) 1999 jeswanke. All rights reserved.
/////////////////////////////////////////////////////////////////////

⌨️ 快捷键说明

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