导航:首页 > 文档加密 > 串口通信编程实践pdf

串口通信编程实践pdf

发布时间:2023-11-16 16:11:05

❶ 能给我c/c++串口通信典型应用实例编程实践的电子版吗,还有源代码

我当时用的这个人的代码:

/*
Mole:SerialPort.H
Purpose:

Copyright(c)1999-2008byPJNaughter.

Allrightsreserved.

Copyright/UsageDetails:

(commercial,shareware,freewareorotherwise)
.
.Ifyouwanttodistributesource
codewithyourapplication,.Thisis
.

*/


/////////////////////Macros/Structsetc////////////////////////////////////

#pragmaonce

#ifndef__SERIALPORT_H__
#define__SERIALPORT_H__

#ifndefCSERIALPORT_EXT_CLASS
#defineCSERIALPORT_EXT_CLASS
#endif


///////////////////////////Classes///////////////////////////////////////////

classCSERIALPORT_EXT_CLASSCSerialException:publicCException
{
public:
//Constructors/Destructors
CSerialException(DWORDdwError);

//Methods
#ifdef_DEBUG
virtualvoidDump(CDumpContext&dc)const;
#endif
virtualBOOLGetErrorMessage(__out_ecount_z(nMaxError)LPTSTRlpszError,__inUINTnMaxError,__out_optPUINTpnHelpContext=NULL);
CStringGetErrorMessage();

//Datamembers
DWORDm_dwError;

protected:
DECLARE_DYNAMIC(CSerialException)
};

classCSERIALPORT_EXT_CLASSCSerialPort
{
public:
//Enums
enumFlowControl
{
NoFlowControl,
CtsRtsFlowControl,
CtsDtrFlowControl,
DsrRtsFlowControl,
DsrDtrFlowControl,
XonXoffFlowControl
};

enumParity
{
NoParity=0,
OddParity=1,
EvenParity=2,
MarkParity=3,
SpaceParity=4
};

enumStopBits
{
OneStopBit,
OnePointFiveStopBits,
TwoStopBits
};

//Constructors/Destructors
CSerialPort();
virtual~CSerialPort();

//GeneralMethods
voidOpen(intnPort,DWORDdwBaud=9600,Parityparity=NoParity,BYTEDataBits=8,
StopBitsstopBits=OneStopBit,FlowControlfc=NoFlowControl,BOOLbOverlapped=FALSE);
voidOpen(LPCTSTRpszPort,DWORDdwBaud=9600,Parityparity=NoParity,BYTEDataBits=8,
StopBitsstopBits=OneStopBit,FlowControlfc=NoFlowControl,BOOLbOverlapped=FALSE);
voidClose();
voidAttach(HANDLEhComm);
HANDLEDetach();
operatorHANDLE()const{returnm_hComm;};
BOOLIsOpen()const{returnm_hComm!=INVALID_HANDLE_VALUE;};
#ifdef_DEBUG
voidDump(CDumpContext&dc)const;
#endif

//Reading/WritingMethods
DWORDRead(void*lpBuf,DWORDdwCount);
voidRead(void*lpBuf,DWORDdwCount,OVERLAPPED&overlapped,DWORD*pBytesRead=NULL);
voidReadEx(void*lpBuf,DWORDdwCount);
DWORDWrite(constvoid*lpBuf,DWORDdwCount);
voidWrite(constvoid*lpBuf,DWORDdwCount,OVERLAPPED&overlapped,DWORD*pBytesWritten=NULL);
voidWriteEx(constvoid*lpBuf,DWORDdwCount);
voidTransmitChar(charcChar);
voidGetOverlappedResult(OVERLAPPED&overlapped,DWORD&dwBytesTransferred,BOOLbWait);
voidCancelIo();
DWORDBytesWaiting();
BOOLDataWaiting(DWORDdwTimeout);

//ConfigurationMethods
voidGetConfig(COMMCONFIG&config);
staticvoidGetDefaultConfig(intnPort,COMMCONFIG&config);
voidSetConfig(COMMCONFIG&Config);
staticvoidSetDefaultConfig(intnPort,COMMCONFIG&config);

//MiscRS232Methods
voidClearBreak();
voidSetBreak();
voidClearError(DWORD&dwErrors);
voidGetStatus(COMSTAT&stat);
voidGetState(DCB&dcb);
voidSetState(DCB&dcb);
voidEscape(DWORDdwFunc);
voidClearDTR();
voidClearRTS();
voidSetDTR();
voidSetRTS();
voidSetXOFF();
voidSetXON();
voidGetProperties(COMMPROP&properties);
voidGetModemStatus(DWORD&dwModemStatus);

//Timeouts
voidSetTimeouts(COMMTIMEOUTS&timeouts);
voidGetTimeouts(COMMTIMEOUTS&timeouts);
voidSet0Timeout();
voidSet0WriteTimeout();
voidSet0ReadTimeout();

//EventMethods
voidSetMask(DWORDdwMask);
voidGetMask(DWORD&dwMask);
voidWaitEvent(DWORD&dwMask);
BOOLWaitEvent(DWORD&dwMask,OVERLAPPED&overlapped);

//QueueMethods
voidFlush();
voidPurge(DWORDdwFlags);
();
voidTerminateOutstandingReads();
voidClearWriteBuffer();
voidClearReadBuffer();
voidSetup(DWORDdwInQueue,DWORDdwOutQueue);

//Overridables
virtualvoidOnCompletion(DWORDdwErrorCode,DWORDdwCount,LPOVERLAPPEDlpOverlapped);

//Staticmethods
(DWORDdwError=0);

protected:
//Typedefs
typedefBOOL(WINAPICANCELIO)(HANDLE);
typedefCANCELIO*LPCANCELIO;

//Staticmethods
staticvoidWINAPI_OnCompletion(DWORDdwErrorCode,DWORDdwCount,LPOVERLAPPEDlpOverlapped);

//Membervariables
HANDLEm_hComm;//Handletothecommsport
HANDLEm_hEvent;//
HINSTANCEm_hKernel32;//Kernel32handle
LPCANCELIOm_lpfnCancelIo;//CancelIOfunctionpointer
};

#endif//__SERIALPORT_H__

❷ 求c++串口通信实例源代码

推荐看书

Visual C++_Turbo C串口通信编程实践

需要 pdf 文档 可以联系
希望能解决您的问题。

阅读全文

与串口通信编程实践pdf相关的资料

热点内容
有两个项目要部署在云服务器上 浏览:930
信源编译码器的作用 浏览:919
remove命令linux 浏览:599
php发送邮件链接 浏览:34
创维冰箱压缩机 浏览:869
nginxopenssl交叉编译 浏览:750
相机卡无法创建新文件夹 浏览:225
单片机照明控制系统程序代码 浏览:10
服务编程一体化 浏览:471
tx小霸王服务器是什么意思 浏览:545
计算机编程工龄工资怎么算 浏览:491
macandroid配置环境变量 浏览:854
做项目文件夹的图标 浏览:327
数控车床车轴编程教程 浏览:728
怎么解压截图软件 浏览:885
算法符号椭圆 浏览:174
网络蚂蚁app是什么 浏览:273
php面向对象编程开发 浏览:798
唱吧如何解绑其他app 浏览:318
程序员去工厂好吗 浏览:497