资源简介
用它可以很轻松完成一般串口编程工作,几分钟就可搭好串口通信框架,使编程者可以将大部分精力放在数据处理上,而且我们可以对这个类进行改进,使其更加完善,相信您使用后一定会喜欢上它的
代码片段和文件信息
/*
Module : SERIALPORT.CPP
Purpose: Implementation for an MFC wrapper class for serial ports
Created: PJN / 31-05-1999
History: PJN / 03-06-1999 1. Fixed problem with code using CancelIo which does not exist on 95.
2. Fixed leaks which can occur in sample app when an exception is thrown
PJN / 16-06-1999 1. Fixed a bug whereby CString::ReleaseBuffer was not being called in
CSerialException::GetErrorMessage
PJN / 29-09-1999 1. Fixed a simple copy and paste bug in CSerialPort::SetDTR
Copyright (c) 1999 by PJ Naughter.
All rights reserved.
*/
///////////////////////////////// Includes //////////////////////////////////
#include “stdafx.h“
#include “serialport.h“
#include “winerror.h“
///////////////////////////////// defines /////////////////////////////////////
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//////////////////////////////// Implementation ///////////////////////////////
//Class which handles CancelIo function which must be constructed at run time
//since it is not imeplemented on NT 3.51 or Windows 95. To avoid the loader
//bringing up a message such as “Failed to load due to missing export...“ the
//function is constructed using GetProcAddress. The CSerialPort::CancelIo
//function then checks to see if the function pointer is NULL and if it is it
//throws an exception using the error code ERROR_CALL_NOT_IMPLEMENTED which
//is what 95 would have done if it had implemented a stub for it in the first
//place !!
class _SERIAL_PORT_DATA
{
public:
//Constructors /Destructors
_SERIAL_PORT_DATA();
~_SERIAL_PORT_DATA();
HINSTANCE m_hKernel32;
typedef BOOL (CANCELIO)(HANDLE);
typedef CANCELIO* LPCANCELIO;
LPCANCELIO m_lpfnCancelIo;
};
_SERIAL_PORT_DATA::_SERIAL_PORT_DATA()
{
m_hKernel32 = LoadLibrary(_T(“KERNEL32.DLL“));
VERIFY(m_hKernel32 != NULL);
m_lpfnCancelIo = (LPCANCELIO) GetProcAddress(m_hKernel32 “CancelIo“);
}
_SERIAL_PORT_DATA::~_SERIAL_PORT_DATA()
{
FreeLibrary(m_hKernel32);
m_hKernel32 = NULL;
}
//The local variable which handle the function pointers
_SERIAL_PORT_DATA _SerialPortData;
////////// Exception handling code
void AfxThrowSerialException(DWORD dwError /* = 0 */)
{
if (dwError == 0)
dwError = ::GetLastError();
CSerialException* pException = new CSerialException(dwError);
TRACE(_T(“Warning: throwing CSerialException for error %d\n“) dwError);
THROW(pException);
}
BOOL CSerialException::GetErrorMessage(LPTSTR pstrError UINT nMaxError PUINT pnHelpContext)
{
ASSERT(pstrError != NULL && AfxIsValidString(pstrError nMaxError));
if (pnHelpContext != NULL)
*pnHelpContext = 0;
LPTSTR lpBuffer;
BOOL bRet = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM
NULL m_dwError MAKELANGID(
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 4238 1999-05-31 23:48 serialport\serialport.h
文件 19021 1999-09-29 21:09 serialport\serialport.cpp
目录 0 2008-07-22 15:54 serialport
----------- --------- ---------- ----- ----
23259 3
相关资源
- 手动清除IIS日志
- GB∕T 31024.1-2014 合作式智能运输系统
- 串口网络调试助手sscom5.1.3.rar
- 基于MVC模式的扫雷游戏
- WMVCore(WindowsServer2008R2 x64能用的版本
- 唐老师宽带无线通信技术结课大作业
- 无线通信系统概述
- CP5711驱动
- USB转串口驱动-CH340
- 2du6光敏传感器参考手册
- 串口通信实验报告 含代码
- SpringMVC+uploadify实现文件上传带进度条
- VC2010调用Labview2014的DLL范例
- 非常好用的串口调试助手
- arduino与Unity串口通讯.docx
- STM32的GPIO口模拟串口通信.rar
- vc实现dicom读取与显示
- VC mirror driver源码
- 模拟IO,iic从机模式移植性强,串口中
- 调幅系统实验,通信专业
- PID调参软件通过串口,可以看波形
- 杨辉通信考研视频资料.docx
- c8051f020与max487通信
- 基于stm32的i2c通信
- 矩阵键盘+lcd12864液晶显示
- 基于labview串口调试助手
- 基于LABVIEW的USB接口多路高速数据采集
- lz0-052VCE 最全题库截止20181102
- JQ8900串口.zip
- 基于串口通信的上位机控制软件(l
评论
共有 条评论