基于MFC的串口调试助手,已经测试通过!
代码片段和文件信息
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 26750 2011-02-26 15:53 Test_Com2DebugSerialPort.obj
文件 105401 2011-02-22 15:44 Test_Com2DebugStdAfx.obj
文件 122929 2011-05-08 11:45 Test_Com2DebugTest_Com2.exe
文件 271136 2011-05-08 11:45 Test_Com2DebugTest_Com2.ilk
文件 16544 2011-05-08 11:10 Test_Com2DebugTest_Com2.obj
文件 5503668 2011-02-22 15:44 Test_Com2DebugTest_Com2.pch
文件 451584 2011-05-08 11:45 Test_Com2DebugTest_Com2.pdb
文件 3796 2011-05-05 13:33 Test_Com2DebugTest_Com2.res
文件 51617 2011-05-08 11:45 Test_Com2DebugTest_Com2Dlg.obj
文件 222208 2011-05-08 11:47 Test_Com2Debugvc60.idb
文件 380928 2011-05-08 11:45 Test_Com2Debugvc60.pdb
文件 3597 2005-05-25 09:16 Test_Com2ReadMe.txt
文件 1078 2011-02-22 15:41 Test_Com2
esTest_Com2.ico
文件 401 2011-02-22 15:41 Test_Com2
esTest_Com2.rc2
文件 1193 2011-02-24 22:25 Test_Com2
esource.h
文件 18441 2011-02-26 15:53 Test_Com2SerialPort.cpp
文件 2747 2011-02-26 15:51 Test_Com2SerialPort.h
文件 211 2011-02-22 15:41 Test_Com2StdAfx.cpp
文件 1054 2011-02-22 15:41 Test_Com2StdAfx.h
文件 37708 2011-05-05 13:33 Test_Com2Test_Com2.aps
文件 1905 2011-05-08 11:48 Test_Com2Test_Com2.clw
文件 2105 2011-02-22 15:41 Test_Com2Test_Com2.cpp
文件 4342 2011-02-23 17:17 Test_Com2Test_Com2.dsp
文件 541 2011-02-22 15:41 Test_Com2Test_Com2.dsw
文件 1357 2011-02-22 15:41 Test_Com2Test_Com2.h
文件 74752 2011-05-08 11:50 Test_Com2Test_Com2.ncb
文件 49664 2011-05-08 11:50 Test_Com2Test_Com2.opt
文件 252 2011-05-08 11:47 Test_Com2Test_Com2.plg
文件 9386 2011-05-05 13:33 Test_Com2Test_Com2.rc
文件 10922 2011-05-08 11:45 Test_Com2Test_Com2Dlg.cpp
............此处省略7个文件信息
#include “stdafx.h“
#include “SerialPort.h“
#include
//
// Constructor
//
CSerialPort::CSerialPort()
{
m_hComm = NULL;
// initialize overlapped structure members to zero
m_ov.Offset = 0;
m_ov.OffsetHigh = 0;
// create events
m_ov.hEvent = NULL;
m_hWriteEvent = NULL;
m_hShutdownEvent = NULL;
m_szWriteBuffer = NULL;
m_nWriteSize=1;
m_bThreadAlive = FALSE;
}
//
// Delete dynamic memory
//
CSerialPort::~CSerialPort()
{
do
{
SetEvent(m_hShutdownEvent);
} while (m_bThreadAlive);
TRACE(“Thread ended
“);
delete [] m_szWriteBuffer;
}
//
// Initialize the port. This can be port 1 to 4.
//
BOOL CSerialPort::InitPort(CWnd* pPortOwner // the owner (CWnd) of the port (receives message)
UINT portnr // portnumber (1..4)
UINT baud // baudrate
char parity // parity
UINT databits // databits
UINT stopbits // stopbits
DWORD dwCommEvents // EV_RXCHAR EV_CTS etc
UINT writebuffersize) // size to the writebuffer
{
assert(portnr > 0 && portnr < 20);
assert(pPortOwner != NULL);
// if the thread is alive: Kill
if (m_bThreadAlive)
{
do
{
SetEvent(m_hShutdownEvent);
} while (m_bThreadAlive);
TRACE(“Thread ended
“);
}
// create events
if (m_ov.hEvent != NULL)
ResetEvent(m_ov.hEvent);
m_ov.hEvent = CreateEvent(NULL TRUE FALSE NULL);
if (m_hWriteEvent != NULL)
ResetEvent(m_hWriteEvent);
m_hWriteEvent = CreateEvent(NULL TRUE FALSE NULL);
if (m_hShutdownEvent != NULL)
ResetEvent(m_hShutdownEvent);
m_hShutdownEvent = CreateEvent(NULL TRUE FALSE NULL);
// initialize the event objects
m_hEventArray[0] = m_hShutdownEvent; // highest priority
m_hEventArray[1] = m_ov.hEvent;
m_hEventArray[2] = m_hWriteEvent;
// initialize critical section
InitializeCriticalSection(&m_csCommunicationSync);
// set buffersize for writing and save the owner
m_pOwner = pPortOwner;
if (m_szWriteBuffer != NULL)
delete [] m_szWriteBuffer;
m_szWriteBuffer = new char[writebuffersize];
m_nPortNr = portnr;
m_nWriteBufferSize = writebuffersize;
m_dwCommEvents = dwCommEvents;
BOOL bResult = FALSE;
char *szPort = new char[50];
char *szBaud = new char[50];
// now it critical!
EnterCriticalSection(&m_csCommunicationSync);
// if the port is already opened: close it
if (m_hComm != NULL)
{
CloseHandle(m_hComm);
m_hComm = NULL;
}
// prepare port strings
sprintf(szPort “COM%d“ portnr);
sprintf(szBaud “baud=%d parity=%c data=%d stop=%d“ baud parity databits stopbits);
// get a handle to the port
m_hComm = CreateFile(szPort // communication port string (COMX)
GENERIC_READ | GENERIC_WRITE // read/write types
0 // comm devices must be opened with exclusive access
NULL // no security attributes
OPEN_EXISTING // comm de
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 26750 2011-02-26 15:53 Test_Com2DebugSerialPort.obj
文件 105401 2011-02-22 15:44 Test_Com2DebugStdAfx.obj
文件 122929 2011-05-08 11:45 Test_Com2DebugTest_Com2.exe
文件 271136 2011-05-08 11:45 Test_Com2DebugTest_Com2.ilk
文件 16544 2011-05-08 11:10 Test_Com2DebugTest_Com2.obj
文件 5503668 2011-02-22 15:44 Test_Com2DebugTest_Com2.pch
文件 451584 2011-05-08 11:45 Test_Com2DebugTest_Com2.pdb
文件 3796 2011-05-05 13:33 Test_Com2DebugTest_Com2.res
文件 51617 2011-05-08 11:45 Test_Com2DebugTest_Com2Dlg.obj
文件 222208 2011-05-08 11:47 Test_Com2Debugvc60.idb
文件 380928 2011-05-08 11:45 Test_Com2Debugvc60.pdb
文件 3597 2005-05-25 09:16 Test_Com2ReadMe.txt
文件 1078 2011-02-22 15:41 Test_Com2
esTest_Com2.ico
文件 401 2011-02-22 15:41 Test_Com2
esTest_Com2.rc2
文件 1193 2011-02-24 22:25 Test_Com2
esource.h
文件 18441 2011-02-26 15:53 Test_Com2SerialPort.cpp
文件 2747 2011-02-26 15:51 Test_Com2SerialPort.h
文件 211 2011-02-22 15:41 Test_Com2StdAfx.cpp
文件 1054 2011-02-22 15:41 Test_Com2StdAfx.h
文件 37708 2011-05-05 13:33 Test_Com2Test_Com2.aps
文件 1905 2011-05-08 11:48 Test_Com2Test_Com2.clw
文件 2105 2011-02-22 15:41 Test_Com2Test_Com2.cpp
文件 4342 2011-02-23 17:17 Test_Com2Test_Com2.dsp
文件 541 2011-02-22 15:41 Test_Com2Test_Com2.dsw
文件 1357 2011-02-22 15:41 Test_Com2Test_Com2.h
文件 74752 2011-05-08 11:50 Test_Com2Test_Com2.ncb
文件 49664 2011-05-08 11:50 Test_Com2Test_Com2.opt
文件 252 2011-05-08 11:47 Test_Com2Test_Com2.plg
文件 9386 2011-05-05 13:33 Test_Com2Test_Com2.rc
文件 10922 2011-05-08 11:45 Test_Com2Test_Com2Dlg.cpp
............此处省略7个文件信息
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。
评论列表(条)