资源简介
基于MFC的串口调试助手,已经测试通过!
代码片段和文件信息
#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\n“);
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\n“);
}
// 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_Com2\Debug\SerialPort.obj
文件 105401 2011-02-22 15:44 Test_Com2\Debug\StdAfx.obj
文件 122929 2011-05-08 11:45 Test_Com2\Debug\Test_Com2.exe
文件 271136 2011-05-08 11:45 Test_Com2\Debug\Test_Com2.ilk
文件 16544 2011-05-08 11:10 Test_Com2\Debug\Test_Com2.obj
文件 5503668 2011-02-22 15:44 Test_Com2\Debug\Test_Com2.pch
文件 451584 2011-05-08 11:45 Test_Com2\Debug\Test_Com2.pdb
文件 3796 2011-05-05 13:33 Test_Com2\Debug\Test_Com2.res
文件 51617 2011-05-08 11:45 Test_Com2\Debug\Test_Com2Dlg.obj
文件 222208 2011-05-08 11:47 Test_Com2\Debug\vc60.idb
文件 380928 2011-05-08 11:45 Test_Com2\Debug\vc60.pdb
文件 3597 2005-05-25 09:16 Test_Com2\ReadMe.txt
文件 1078 2011-02-22 15:41 Test_Com2\res\Test_Com2.ico
文件 401 2011-02-22 15:41 Test_Com2\res\Test_Com2.rc2
文件 1193 2011-02-24 22:25 Test_Com2\resource.h
文件 18441 2011-02-26 15:53 Test_Com2\SerialPort.cpp
文件 2747 2011-02-26 15:51 Test_Com2\SerialPort.h
文件 211 2011-02-22 15:41 Test_Com2\StdAfx.cpp
文件 1054 2011-02-22 15:41 Test_Com2\StdAfx.h
文件 37708 2011-05-05 13:33 Test_Com2\Test_Com2.aps
文件 1905 2011-05-08 11:48 Test_Com2\Test_Com2.clw
文件 2105 2011-02-22 15:41 Test_Com2\Test_Com2.cpp
文件 4342 2011-02-23 17:17 Test_Com2\Test_Com2.dsp
文件 541 2011-02-22 15:41 Test_Com2\Test_Com2.dsw
文件 1357 2011-02-22 15:41 Test_Com2\Test_Com2.h
文件 74752 2011-05-08 11:50 Test_Com2\Test_Com2.ncb
文件 49664 2011-05-08 11:50 Test_Com2\Test_Com2.opt
文件 252 2011-05-08 11:47 Test_Com2\Test_Com2.plg
文件 9386 2011-05-05 13:33 Test_Com2\Test_Com2.rc
文件 10922 2011-05-08 11:45 Test_Com2\Test_Com2Dlg.cpp
............此处省略7个文件信息
- 上一篇:基于MFC五子棋包含网络对战
- 下一篇:VC++小游戏 弹球游戏
相关资源
- 基于MFC的TCP调试助手源码95706
- 基于mfc的多线程文件传输
- 通信过程中的RS编译码程序(c语言)
- MFC数字钟(基于VC6.0)
- VC++MFC小游戏实例教程(实例)+MFC类库
- 串口通讯技术实现--两台pc机通过串口
- C++语言编写串口调试助手
- GD32F103 在线串口Ymodem协议升级IAP
- ChartCtrl控件库(可在VS2019中使用)
- 商品库存管理系统 C++ MFC
- qt 串口助手源码
- 使用QWT库实现接收串口数据,并根据
- Qt5串口通信-windows
- 串口实验(接收与发送)
- STM32 LIN通信数据发送实现 测试通过
- 程序案例 利用LabVIEW实现串口通讯
- STM32(神舟III号 串口1发送实验程序)
- STM32429的串口收发程序
- atmega128 串口通讯(RS485.c)
- arduino I2C设备扫描并串口返回地址(
- stm32双机spi通信
- 串口调试助手(测试STM32串口)
- N76E003串口收发
- rs485通信双工,可直接用,波特率可达
- cubeMX设计实现stm32f407上的CAN及485的通
- mfc 调用redis
- TCP/IP与串口调试
- MFC视频播放器源码(支持avi/wma/mp3等格
- mfc绘图大全(画直线、矩形、椭圆)
- MFC控件重绘
川公网安备 51152502000135号
评论
共有 条评论