资源简介
Unicode串口通信Demo,文件太大我把编译的删除了,请自己编译,用23串口连接试试效果。

代码片段和文件信息
#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);
// if the port is still opened: close it
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(L“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
wchar_t parity // parity
UINT databits // databits
UINT stopbits // stopbits
DWORD dwCommEvents // EV_RXCHAR EV_CTS etc
UINT writebuffersize // size to the writebuffer
UINT g2DTR_RTS) // DTR & RTS Control
{
assert(portnr > 0 && portnr < 10);
assert(pPortOwner != NULL);
// if the thread is alive: Kill
if (m_bThreadAlive)
{
do
{
SetEvent(m_hShutdownEvent);
} while (m_bThreadAlive);
TRACE(L“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_csCommunicationSync);
// set buffersize for writing and save the owner
m_pOwner = pPortOwner;
if (m_szWriteBuffer != NULL)
delete [] m_szWriteBuffer;
m_szWriteBuffer = new wchar_t[writebuffersize];
m_nPortNr = portnr;
m_nWriteBufferSize = writebuffersize;
m_dwCommEvents = dwCommEvents;
BOOL bResult = FALSE;
wchar_t *szPort = new wchar_t[50];
wchar_t *szBaud = new wchar_t[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 por
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2012-07-30 15:24 Unicode_Demo\
目录 0 2012-07-30 15:24 Unicode_Demo\Debug\
目录 0 2012-07-27 17:04 Unicode_Demo\Unicode_Demo\
目录 0 2012-07-30 15:24 Unicode_Demo\Unicode_Demo\Debug\
文件 3236 2012-07-27 17:04 Unicode_Demo\Unicode_Demo\ReadMe.txt
文件 2014 2012-07-30 11:47 Unicode_Demo\Unicode_Demo\Resource.h
文件 19890 2012-07-30 11:24 Unicode_Demo\Unicode_Demo\SerialPort.cpp
文件 3139 2012-07-27 17:26 Unicode_Demo\Unicode_Demo\SerialPort.h
文件 106344 2012-07-30 13:28 Unicode_Demo\Unicode_Demo\Unicode_Demo.aps
文件 2071 2012-07-27 17:04 Unicode_Demo\Unicode_Demo\Unicode_Demo.cpp
文件 478 2012-07-27 17:04 Unicode_Demo\Unicode_Demo\Unicode_Demo.h
文件 11964 2012-07-30 13:28 Unicode_Demo\Unicode_Demo\Unicode_Demo.rc
文件 6048 2012-07-27 17:09 Unicode_Demo\Unicode_Demo\Unicode_Demo.vcxproj
文件 2209 2012-07-27 17:09 Unicode_Demo\Unicode_Demo\Unicode_Demo.vcxproj.filters
文件 143 2012-07-27 17:04 Unicode_Demo\Unicode_Demo\Unicode_Demo.vcxproj.user
文件 5560 2012-07-30 13:30 Unicode_Demo\Unicode_Demo\Unicode_DemoDlg.cpp
文件 1097 2012-07-30 11:50 Unicode_Demo\Unicode_Demo\Unicode_DemoDlg.h
目录 0 2012-07-27 17:04 Unicode_Demo\Unicode_Demo\res\
文件 67777 2009-08-31 02:31 Unicode_Demo\Unicode_Demo\res\Unicode_Demo.ico
文件 680 2012-07-27 17:04 Unicode_Demo\Unicode_Demo\res\Unicode_Demo.rc2
文件 145 2012-07-27 17:04 Unicode_Demo\Unicode_Demo\stdafx.cpp
文件 1632 2012-07-27 17:04 Unicode_Demo\Unicode_Demo\stdafx.h
文件 234 2012-07-27 17:04 Unicode_Demo\Unicode_Demo\targetver.h
文件 903 2012-07-27 17:04 Unicode_Demo\Unicode_Demo.sln
文件 19968 2012-07-30 13:30 Unicode_Demo\Unicode_Demo.suo
文件 47104 2012-07-30 15:08 Unicode_Demo\readMe.doc
- 上一篇:软件测试论文免费
- 下一篇:Gradle3.0自动化项目构建技术精讲+实战.docx
相关资源
- UNICODE GBK双向码表二进制文件
- 常用编码(UnicodeUTF-8GBK)转换工具
- 中文转化unicoder码的方法
- 程序员输入法unicode版
- 维吾尔文字符集unicode编码表
- 维吾尔文unicode编码表
- vcredist2010_x64
- 字库工具 guitool(Trial) Setup 1.13.rar
- DFM文件Unicode汉字转换器 V1.3
- 通用规范汉字表8105字及化学元素周期
- vc2010下编译好的gdal2.2.4库,支持wms、
- EzCad2.7.0_UNICODE(20120326)新狗
- UDP socket 多线程
- 用VC2010编写的基于TCPIP的Modbus网络通讯
- 12*1216*16完整点阵字库包含所有unicod
- SBASparse Bundle Adjustment的VC2010版本
- 使用winring监控cpu温度
- 一个可以解码并实时播放H264的播放器
- VC2010结合ArcGIS Engine 10开发
- Arial Unicode Ms字体包
- vc2010中tab control使用
- WDK/DDK USBVIEW 源码 VC2010编译环境 内含
- ExStudPE v1.6.4 Beta3 Unlimited Unicode (MIX
-
vc2010使用minibl
ink控件开发浏览器简 - qt-4.8.4-x64-msvc2010.zip
- qt下支持中文的串口调试助手
- VC2010编写的工控仪表 界面完美 绝对可
- qt-4.8.4-x64-msvc2010.z01
- mpeg音频编码
- 字库 BinUnicode码OEMCP(GBK)互转
评论
共有 条评论