導航:首頁 > 文檔加密 > 串口通信編程實踐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相關的資料

熱點內容
mfc深入淺出從mfc設計到mfc編程 瀏覽:77
螢石雲伺服器連接設置 瀏覽:323
中國名著pdf 瀏覽:590
華為伺服器設備序列號怎麼看 瀏覽:317
跑永輝生活配送用什麼app 瀏覽:147
ug識別符號命令在哪裡 瀏覽:717
pdf文件改文字 瀏覽:732
查詢qq號劍靈伺服器地址 瀏覽:552
國家反詐中心app為什麼要刷臉 瀏覽:303
iphone怎麼修改dns伺服器地址 瀏覽:85
bandizip解壓位置 瀏覽:168
伺服器的防火牆如何訪問 瀏覽:306
javagoto關鍵字 瀏覽:847
廣州少兒編程加盟排名榜 瀏覽:122
51單片機th0 瀏覽:290
冠軍交易pdf 瀏覽:208
excelword轉換成pdf 瀏覽:389
安卓10制空霸權怎麼打開 瀏覽:263
視唱練耳用什麼app好 瀏覽:589
有兩個項目要部署在雲伺服器上 瀏覽:930