资源简介
控制台串口通讯程序 可以输入 16进制的字符 然后接受到的数据以16进制的格式显示出来 多线程异步 控制台串口通讯类 及其实例
代码片段和文件信息
#include “StdAfx.h“
#include “ConsoleSerialPort.h“
CConsoleSerialPort::CConsoleSerialPort(void)
{
m_comm=NULL;
m_overlapped.Offset=0;
m_overlapped.OffsetHigh=0;
m_overlapped.hEvent=NULL;
m_write_event=NULL;
m_shutdown_event=NULL;
m_sz_write_buffer=NULL;
m_n_write_size=1;
m_thread_alive=FALSE;
m_thread=NULL;
}
CConsoleSerialPort::CConsoleSerialPort(CContral * parent)
{
m_comm=NULL;
m_overlapped.Offset=0;
m_overlapped.OffsetHigh=0;
m_overlapped.hEvent=NULL;
m_write_event=NULL;
m_shutdown_event=NULL;
m_sz_write_buffer=NULL;
m_n_write_size=1;
m_thread_alive=FALSE;
m_thread=NULL;
m_parent=parent;
}
CConsoleSerialPort::~CConsoleSerialPort(void)
{
do
{
SetEvent(m_shutdown_event);
} while (m_thread_alive);
delete [] m_sz_write_buffer;
}
bool CConsoleSerialPort::init_port(unsigned int port /* =1 */ unsigned int baud/* =9600 */char parity/* =‘N‘ */ unsigned int databits/* =8 */unsigned int stopbits /* =1 */DWORD dwCommEvents /* = EV_RXCHAR */unsigned int write_buffer_size/* =1024 */)
{
assert(port>0&&port<9);
if (m_thread_alive)
{
do
{
SetEvent(m_shutdown_event);
} while (m_thread_alive);
}
if (m_overlapped.hEvent!=NULL)
ResetEvent(m_overlapped.hEvent);
m_overlapped.hEvent=CreateEvent(NULLTRUEFALSENULL);
if (m_write_event!=NULL)
ResetEvent(m_write_event);
m_write_event=CreateEvent(NULLTRUEFALSENULL);
if (m_shutdown_event!=NULL)
ResetEvent(m_shutdown_event);
m_shutdown_event=CreateEvent(NULLTRUEFALSENULL);
m_event_array[0]=m_shutdown_event;
m_event_array[1]=m_overlapped.hEvent;
m_event_array[2]=m_write_event;
InitializeCriticalSection(&m_mm_sync);
m_port=port;
if (m_sz_write_buffer!=NULL)
delete []m_sz_write_buffer;
m_sz_write_buffer=new char[write_buffer_size];
m_n_write_size=write_buffer_size;
m_dw_commEvents=dwCommEvents;
bool bResult=false;
WCHAR * szPort=new WCHAR[50];
WCHAR * szBaud=new WCHAR[50];
EnterCriticalSection(&m_mm_sync);
if (m_comm!=NULL)
{
CloseHandle(m_comm);
m_comm=NULL;
}
wsprintf(szPort_T(“COM%d“)port);
wsprintf(szBaud_T(“baud=%d parity=%c data=%d stop=%d“)baudparitydatabitsstopbits);
m_comm=CreateFile(szPortGENERIC_WRITE|GENERIC_READ0NULLOPEN_EXISTINGFILE_FLAG_OVERLAPPED0);
if (m_comm ==INVALID_HANDLE_VALUE)
{
delete [] szPort;
delete [] szBaud;
return false;
}
m_comm_time_out.ReadIntervalTimeout=1000;
m_comm_time_out.ReadTotalTimeoutMultiplier=1000;
m_comm_time_out.ReadTotalTimeoutConstant=1000;
m_comm_time_out.WriteTotalTimeoutMultiplier=1000;
m_comm_time_out.WriteTotalTimeoutConstant=1000;
if (SetCommTimeouts(m_comm&m_comm_time_out))
{
if (SetCommMask(m_commdwCommEvents))
{
if (GetCommState(m_comm&m_dcb))
{
m_dcb.EvtChar =‘q‘;
m_dcb.fRtsControl=RTS_CONTROL_ENABLE;
if (BuildCommDCB(szBaud&m_dcb))
{
if (SetCommState(m_comm&m_dcb))
;
else
process
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 743760 2011-02-20 02:01 Serialcommunication\Debug\msvcp100d.dll
文件 1505104 2011-02-20 02:01 Serialcommunication\Debug\msvcr100d.dll
文件 58368 2013-05-07 09:45 Serialcommunication\Debug\Serialcommunication.exe
文件 545124 2013-05-07 09:45 Serialcommunication\Debug\Serialcommunication.ilk
文件 691200 2013-05-07 09:45 Serialcommunication\Debug\Serialcommunication.pdb
文件 2359296 2013-05-07 09:45 Serialcommunication\ipch\serialcommunication-9a27186f\serialcommunication-6ef59e62.ipch
文件 10379 2013-05-07 09:42 Serialcommunication\Serialcommunication\ConsoleSerialPort.cpp
文件 1550 2013-05-06 13:55 Serialcommunication\Serialcommunication\ConsoleSerialPort.h
文件 9241 2013-05-04 15:58 Serialcommunication\Serialcommunication\ConsoleSerialPortback.cpp
文件 1412 2013-05-04 13:05 Serialcommunication\Serialcommunication\ConsoleSerialPortback.h
文件 1637 2013-05-03 13:54 Serialcommunication\Serialcommunication\ReadMe.txt
文件 1564 2013-05-05 08:36 Serialcommunication\Serialcommunication\Serialcommunication.cpp
文件 4546 2013-05-04 13:27 Serialcommunication\Serialcommunication\Serialcommunication.vcxproj
文件 1523 2013-05-04 12:47 Serialcommunication\Serialcommunication\Serialcommunication.vcxproj.filters
文件 143 2013-05-03 13:54 Serialcommunication\Serialcommunication\Serialcommunication.vcxproj.user
文件 18408 2013-05-04 10:08 Serialcommunication\Serialcommunication\SerialPort.cpp
文件 2791 2013-05-04 09:46 Serialcommunication\Serialcommunication\SerialPort.h
文件 224 2013-05-03 13:54 Serialcommunication\Serialcommunication\stdafx.cpp
文件 233 2013-05-03 13:54 Serialcommunication\Serialcommunication\stdafx.h
文件 236 2013-05-03 13:54 Serialcommunication\Serialcommunication\targetver.h
文件 10309632 2013-05-07 09:45 Serialcommunication\Serialcommunication.sdf
文件 924 2013-05-03 13:54 Serialcommunication\Serialcommunication.sln
..A..H. 18432 2013-05-07 09:45 Serialcommunication\Serialcommunication.suo
目录 0 2013-05-07 09:45 Serialcommunication\ipch\serialcommunication-9a27186f
目录 0 2013-05-07 09:45 Serialcommunication\Debug
目录 0 2013-05-07 09:45 Serialcommunication\ipch
目录 0 2013-05-07 09:46 Serialcommunication\Serialcommunication
目录 0 2013-05-07 09:45 Serialcommunication
----------- --------- ---------- ----- ----
16285727 28
............此处省略1个文件信息
- 上一篇:C++实现的二维图形变换源代码
- 下一篇:stm32f103zet6+摄像头颜色识别
相关资源
- STM32F103RCT语音模块LD3320 STM32与51单片
- 串口通讯VC例程源码
- 虚拟串口软件及串口通讯proteus仿真
- YAT3串口通讯工具
- 龚建伟串口通讯电子书(清晰版)
- 虚拟串口神器——Virtual Serial Port Dr
- gps,电子罗盘串口通讯
- CPort控件包括中文说明书及安装方法
- 松下伺服电机PANATERM串口通讯程序
- STM32F103RCT6 多串口通讯程序
- Stm32+AS608指纹模块串口通讯
- 串口通讯类SerialPort类
- VS串口通讯
- Labview视觉检测&数据库读写&串口通讯
- modbus串口通讯程序,源程序
- LD3320语音识别模块与Arduino软串口通讯
- 温湿度监测和串口通讯
- 51单片机串口通讯
- pyqt5串口通讯助手
- Labview与单片机串口通讯
- mscomm串口通讯
- delphi电子秤串口通讯程序
- 串口通讯Demo
- Atmega16 串口程序
- 串口通讯+modbus通讯协议
- modbus rtu 串口通信
- opencv+串口通讯
- STM32F407 串口通讯
- 含有串口通讯的LabVIEW万用表上位机
- STorM32-BGC串口通讯协议
评论
共有 条评论