BOOL g_Comstate = false;
int port = 1;
CString c_return = "";
void OnConnect();
void OnBreack();
afx_msg LONG OnCommunication(WPARAM ch, LPARAM port);
ON_MESSAGE(WM_COMM_RXCHAR, OnCommunication)
LONG CPortView::OnCommunication(WPARAM ch, LPARAM port)
1、
if(!g_Comstate)
m_Commport.InitPort(this,port,9600,'n',8,1,EV_RXCHAR|EV_CTS,1024)
m_Commport.StartMonitoring();
m_Commport.WriteToPort((char *)(LPCTSTR)"(01X)");
2、
19200
3、
if(ch=='(')c_return="(";
else c_return+=(char)ch;
if(c_return == "(01helloa)");
return 0;
注:单击联机,监听返回,判断断开