• 大小: 12.08MB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-06-15
  • 语言: C/C++
  • 标签: C++  Ymodem  

资源简介

该资源是根据项目需要,实现Ymodem传输数据,包括注册表的修改,为本人自己独立在协议基础上开发,为完整MFC工程,对于学习开发MFC和C++的人士具有一定的参考价值!里面思路清晰,代码注释详细!

资源截图

代码片段和文件信息

// Serial.cpp: implementation of the CSerial class.
//
//////////////////////////////////////////////////////////////////////

#include “stdafx.h“
#include “Serial.h“

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

#define RECVBUF_SIZE 1024

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CSerial::CSerial()
{
m_hComm = INVALID_HANDLE_VALUE; /* 串口操作句柄无效 */
hRecvThread = NULL;
m_ExitThreadEvent = NULL; /* 串口接收线程退出事件无效 */
memset(&dcb 0x00 sizeof(dcb));
}

CSerial::~CSerial()
{
ClosePort();
}


/*******************************************************************************************
函数名称: CCeSerial::CommRecvTread
描    述: 串口接收线程
输入参数: LPVOID lparam: 线程参数创建线程时传入
输出参数: 无
返    回: 0: 线程退出 返回值没特殊含义
********************************************************************************************/
DWORD CSerial::CommRecvTread(LPVOID lparam)
{
CSerial *pSerialPort = (CSerial *)lparam;
DWORD dwLength = 0;
DWORD dwError = 0;
DWORD dwByte = 0;
DWORD dwMask = EV_RXCHAR;
DWORD dwReadBytes = pSerialPort->m_RecvLength;
BYTE *recvBuf = new BYTE[dwReadBytes];
COMSTAT comStat;
OVERLAPPED olWait olRead;
memset(&olWait0sizeof(olWait));
memset(&olRead0sizeof(olRead)); 
olWait.hEvent = CreateEvent(NULLTRUEFALSENULL);
olRead.hEvent = CreateEvent(NULLTRUEFALSENULL);

if (pSerialPort->m_hComm)
{
pSerialPort->m_criticalSection.Lock();
ClearCommError(pSerialPort->m_hComm &dwError &comStat);
PurgeComm(pSerialPort->m_hComm PURGE_RXCLEAR | PURGE_TXCLEAR | PURGE_RXABORT | PURGE_TXABORT);
pSerialPort->m_criticalSection.Unlock();
}

while(TRUE)
{ /* 等待线程退出事件 */
if (WaitForSingleobject(pSerialPort->m_ExitThreadEvent 0) == WAIT_object_0)
break;
WaitCommEvent(pSerialPort->m_hComm &dwMask &olWait);
if(GetOverlappedResult(pSerialPort->m_hComm &olWait &dwByte TRUE) == FALSE)
{
if(GetLastError() != ERROR_IO_PENDING)
{
//return 0x30;
break;
}
//return 0x35;
break;
}
//Clear the error flag
dwError = 0;
memset(&comStat0sizeof(comStat));
ClearCommError(pSerialPort->m_hComm &dwError &comStat);
if(!comStat.cbInQue)
continue;

ZeroMemory(recvBuf pSerialPort->m_RecvLength);
if (pSerialPort->m_hComm != INVALID_HANDLE_VALUE)
{                                       /* 从串口读取数据 */
pSerialPort->m_criticalSection.Lock();
BOOL fReadState = ReadFile(pSerialPort->m_hComm recvBuf dwReadBytes &dwLength &olRead);
pSerialPort->m_criticalSection.Unlock();

if(GetOverlappedResult(pSerialPort->m_hComm &olRead &dwLength TRUE) == FALSE)
{
break;
}else{
if(dwLength != 0)         /* 接收成功调用回调函数 */
pSerialPort->OnCommRecv(pSerialPort->m_UserParam recvBuf dwLength);

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件     184320  2012-08-01 22:32  Witium_YModem_Suc_2012_08_01\Witium_YModem\XYModem\debug\XYModem.exe

     文件    2965308  2012-08-01 22:32  Witium_YModem_Suc_2012_08_01\Witium_YModem\XYModem\debug\XYModem.ilk

     文件    3689472  2012-08-01 20:09  Witium_YModem_Suc_2012_08_01\Witium_YModem\XYModem\debug\XYModem.pdb

     文件      65536  2012-07-26 22:33  Witium_YModem_Suc_2012_08_01\Witium_YModem\XYModem\release\XYModem.exe

     文件    3255296  2012-07-26 22:33  Witium_YModem_Suc_2012_08_01\Witium_YModem\XYModem\release\XYModem.pdb

     文件       9798  2012-08-01 22:32  Witium_YModem_Suc_2012_08_01\Witium_YModem\XYModem\XYModem\Debug\BuildLog.htm

     文件         60  2012-08-01 22:32  Witium_YModem_Suc_2012_08_01\Witium_YModem\XYModem\XYModem\Debug\mt.dep

     文件      22133  2012-08-01 17:08  Witium_YModem_Suc_2012_08_01\Witium_YModem\XYModem\XYModem\Debug\Serial.obj

     文件     336154  2012-07-27 10:59  Witium_YModem_Suc_2012_08_01\Witium_YModem\XYModem\XYModem\Debug\stdafx.obj

     文件     740352  2012-08-01 22:32  Witium_YModem_Suc_2012_08_01\Witium_YModem\XYModem\XYModem\Debug\vc80.idb

     文件     724992  2012-08-01 22:32  Witium_YModem_Suc_2012_08_01\Witium_YModem\XYModem\XYModem\Debug\vc80.pdb

     文件        664  2012-07-26 18:12  Witium_YModem_Suc_2012_08_01\Witium_YModem\XYModem\XYModem\Debug\XYModem.exe.embed.manifest

     文件        728  2012-07-26 18:12  Witium_YModem_Suc_2012_08_01\Witium_YModem\XYModem\XYModem\Debug\XYModem.exe.embed.manifest.res

     文件        629  2012-08-01 22:32  Witium_YModem_Suc_2012_08_01\Witium_YModem\XYModem\XYModem\Debug\XYModem.exe.intermediate.manifest

     文件      24165  2012-08-01 18:36  Witium_YModem_Suc_2012_08_01\Witium_YModem\XYModem\XYModem\Debug\XYModem.obj

     文件   13697024  2012-07-27 10:59  Witium_YModem_Suc_2012_08_01\Witium_YModem\XYModem\XYModem\Debug\XYModem.pch

     文件      24044  2012-08-01 20:09  Witium_YModem_Suc_2012_08_01\Witium_YModem\XYModem\XYModem\Debug\XYModem.res

     文件     102976  2012-08-01 22:32  Witium_YModem_Suc_2012_08_01\Witium_YModem\XYModem\XYModem\Debug\XYModemDlg.obj

     文件      23637  2012-07-31 22:13  Witium_YModem_Suc_2012_08_01\Witium_YModem\XYModem\XYModem\Debug\YModem.obj

     文件       2763  2012-05-16 10:11  Witium_YModem_Suc_2012_08_01\Witium_YModem\XYModem\XYModem\ReadMe.txt

     文件       8098  2012-07-26 22:33  Witium_YModem_Suc_2012_08_01\Witium_YModem\XYModem\XYModem\Release\BuildLog.htm

     文件         60  2012-07-26 22:33  Witium_YModem_Suc_2012_08_01\Witium_YModem\XYModem\XYModem\Release\mt.dep

     文件      27571  2012-07-24 22:36  Witium_YModem_Suc_2012_08_01\Witium_YModem\XYModem\XYModem\Release\Serial.obj

     文件    1973718  2012-07-24 22:36  Witium_YModem_Suc_2012_08_01\Witium_YModem\XYModem\XYModem\Release\stdafx.obj

     文件     412672  2012-07-26 22:33  Witium_YModem_Suc_2012_08_01\Witium_YModem\XYModem\XYModem\Release\vc80.idb

     文件     749568  2012-07-26 22:33  Witium_YModem_Suc_2012_08_01\Witium_YModem\XYModem\XYModem\Release\vc80.pdb

     文件        619  2012-07-26 22:33  Witium_YModem_Suc_2012_08_01\Witium_YModem\XYModem\XYModem\Release\XYModem.exe.intermediate.manifest

     文件      26659  2012-07-26 22:33  Witium_YModem_Suc_2012_08_01\Witium_YModem\XYModem\XYModem\Release\XYModem.obj

     文件   14614528  2012-07-24 22:36  Witium_YModem_Suc_2012_08_01\Witium_YModem\XYModem\XYModem\Release\XYModem.pch

     文件      23952  2012-07-24 22:36  Witium_YModem_Suc_2012_08_01\Witium_YModem\XYModem\XYModem\Release\XYModem.res

............此处省略39个文件信息

评论

共有 条评论