導航:首頁 > 源碼編譯 > cserialport源碼

cserialport源碼

發布時間:2023-01-31 13:50:20

⑴ error C3861: 'AfxSocketInit': identifier not found

我也出現這樣的錯誤,我用的是VS2005平台,
源代碼:BOOL CSerialPortApp::InitInstance()//初始化實例
{
if (!AfxSocketInit())
{
AfxMessageBox(IDP_SOCKETS_INIT_FAILED);//套接字初始化失敗
return FALSE;
}
//
error C3861: 'AfxSocketInit': identifier not found

我發現找不到它的定義,新手望指點!

⑵ 下面是我在書上看到的代碼。但我運行時,會提示應用程序發生異常,終止還是調試。哪位高手幫忙解釋一下

strtemp.Format("%c",bt);
這里有問題,如果你能保證傳過來的每一位元組數據都在ASCII表中能找到對應字元才能這樣處理,通常對於未知數據是將其按16進制進行格式化,每個位元組之間用空格分開:
strtemp.Format("%02X ",bt);

從安全性考慮,for(k=0;k<len;k++)這里還應當比較len是否大於2048,否則有可能越界,建議這里用堆分配
BYTE *rxdata = new BYTE[len + 1];

⑶ 如何用c語言編寫串口助手

用MFC寫,可用MScomm控制項,也可用官方發布的類CSerialPort。

⑷ 能給我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__
閱讀全文

與cserialport源碼相關的資料

熱點內容
怎麼雙向傳輸伺服器 瀏覽:286
電腦如何實現跨網段訪問伺服器 瀏覽:549
模塊化網頁源碼位元組跳動 瀏覽:485
梯度下降演算法中遇到的問題 瀏覽:605
伺服器連接電視怎麼接 瀏覽:323
phploop語句 瀏覽:500
交叉編譯工具鏈里的庫在哪 瀏覽:781
安卓手q換號怎麼改綁 瀏覽:399
nba球星加密貨幣 瀏覽:789
命令看網速 瀏覽:124
java堆分配 瀏覽:161
linuxbuiltin 瀏覽:560
cstpdf 瀏覽:941
texstudio編譯在哪 瀏覽:352
國家反詐中心app注冊登記表怎麼注冊 瀏覽:972
加密機默認埠 瀏覽:101
有哪個網站有免費的python源代碼 瀏覽:305
蘋果手機如何導入安卓電話 瀏覽:915
奧利奧雙重解壓 瀏覽:388
安卓賬號怎麼在蘋果手機上玩 瀏覽:798