资源简介
第三方串口类,用于扩展MFC的串口功能,下面是这个类的英文描述:
This class can read, write and watch one serial port. It sends messages to its owner when something happends on the port. The class creates a thread for reading and writing so the main program is not blocked.
代码片段和文件信息
/*
** FILENAME CSerialPort.cpp
**
** PURPOSE This class can read write and watch one serial port.
** It sends messages to its owner when something happends on the port
** The class creates a thread for reading and writing so the main
** program is not blocked.
**
** CREATION DATE 15-09-1997
** LAST MODIFICATION 12-11-1997
**
** AUTHOR Remon Spekreijse
**
**
*/
#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_bThreadAlive = FALSE;
m_nWriteSize = 1;
}
//
// Delete dynamic memory
//
CSerialPort::~CSerialPort()
{
do
{
SetEvent(m_hShutdownEvent);
} while (m_bThreadAlive);
if (m_hComm != NULL)
{
CloseHandle(m_hComm);
m_hComm = NULL;
}
// Close Handles
if(m_hShutdownEvent!=NULL)
CloseHandle( m_hShutdownEvent);
if(m_ov.hEvent!=NULL)
CloseHandle( m_ov.hEvent );
if(m_hWriteEvent!=NULL)
CloseHandle( m_hWriteEvent );
TRACE(“Thread ended\n“);
delete [] m_szWriteBuffer;
}
//
// Initialize the port. This can be port 1 to 4.
//
//
//parity:
// n=none
// e=even
// o=odd
// m=mark
// s=space
//data:
// 5678
//stop:
// 11.52
//
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
DWORD ReadIntervalTimeout
DWORD ReadTotalTimeoutMultiplier
DWORD ReadTotalTimeoutConstant
DWORD WriteTotalTimeoutMultiplier
DWORD WriteTotalTimeoutConstant )
{
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);
else
m_ov.hEvent = CreateEvent(NULL TRUE FALSE NULL);
if (m_hWriteEvent != NULL)
ResetEvent(m_hWriteEvent);
else
m_hWriteEvent = CreateEvent(NULL TRUE FALSE NULL);
if (m_hShutdownEvent != NULL)
ResetEvent(m_hShutdownEvent);
else
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_csCommuni
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 21522 2014-10-02 15:55 SerialPort.cpp
文件 4222 2014-10-02 13:22 SerialPort.h
- 上一篇:文件系统.cpp
- 下一篇:openssl c语言应用
相关资源
- MFCJunior U盘SD卡寿命测试工具
- 控制台嵌入MFC
- Visual C++ MFC Web 浏览器
- 文件传输,用MFC实现
- MFC漂亮的进度条
- VC++ MFC 如何用 CZip CUnzip类压缩解压缩
- MFC添加进度条
- MFC图元的组合,拆分,移动源代码
- Vc++6.0MFC入门教程,很好的资源。
- VC++6.0 MFC 超简易计算器
- MFC开发的与服务器通讯程序
- 用MFC画直线椭圆矩型可选择线条颜色
- MFC交通灯控制车辆运行的模拟程序
- DES加密算法MFC实现
- MFC 之 TabCtrl
- DES加密和RSA加密程序mfc源代码
- 实现三维坐标变换、投影变换,C++实
- MFC实现文件传输
- 生命游戏 mfc版本 环境vs2008
- MFC CComboBox 实现自动补全
- MFC写的棋盘,可以保存坐标数据
- MFC 菜鸟教程……适合初学者
- MFCdownload
- VC++MFC编程
- OpenGL载入3ds模型并在MFC视图窗口显示
- 用MFC编写的数据包校验与常用校验算
- mfc + d3d实现的视频播放器
- [原创]使用MFC实现文档打印
- MFC GroupBox自绘控件,可以方便改变边
- MFC_unicode相关链接库
评论
共有 条评论