Add thread.
This commit is contained in:
@@ -13,8 +13,8 @@ extern CSo7_TCPIP* g_pSo7_TCPIP;
|
||||
|
||||
IMPLEMENT_DYNAMIC(CSo7_Util_PLC_TCPIP, CDialog)
|
||||
|
||||
CSo7_Util_PLC_TCPIP::CSo7_Util_PLC_TCPIP(CWnd* pParent /*=NULL*/)
|
||||
: CDialog(CSo7_Util_PLC_TCPIP::IDD, pParent)
|
||||
CSo7_Util_PLC_TCPIP::CSo7_Util_PLC_TCPIP(CWnd* pParent /*=NULL*/)
|
||||
: CDialog(CSo7_Util_PLC_TCPIP::IDD, pParent)
|
||||
{
|
||||
|
||||
}
|
||||
@@ -25,9 +25,9 @@ CSo7_Util_PLC_TCPIP::~CSo7_Util_PLC_TCPIP()
|
||||
|
||||
void CSo7_Util_PLC_TCPIP::DoDataExchange(CDataExchange* pDX)
|
||||
{
|
||||
CDialog::DoDataExchange(pDX);
|
||||
CDialog::DoDataExchange(pDX);
|
||||
DDX_Control(pDX, IDC_EDIT_MSG, m_edMSG);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@ BEGIN_MESSAGE_MAP(CSo7_Util_PLC_TCPIP, CDialog)
|
||||
ON_BN_CLICKED(IDC_BUTTON_PLC_TCPIP_CLEAR_MSG, &CSo7_Util_PLC_TCPIP::OnBnClickedButtonPlcTcpipClearMsg)
|
||||
ON_BN_CLICKED(IDCANCEL, &CSo7_Util_PLC_TCPIP::OnBnClickedCancel)
|
||||
ON_MESSAGE(WM_SOCKET,&CSo7_Util_PLC_TCPIP::OnSocket)
|
||||
ON_MESSAGE(WM_TCPIP_RECV_DATA,&CSo7_Util_PLC_TCPIP::OnTCPIPRecv)
|
||||
ON_BN_CLICKED(IDCANCEL, &CSo7_Util_PLC_TCPIP::OnBnClickedCancel)
|
||||
ON_BN_CLICKED(IDC_BUTTON_PLC_TCPIP_HANDSHAKING, &CSo7_Util_PLC_TCPIP::OnBnClickedButtonPlcTcpipHandshaking)
|
||||
END_MESSAGE_MAP()
|
||||
@@ -52,10 +53,10 @@ void CSo7_Util_PLC_TCPIP::OnBnClickedButtonPlcTcpipConnect()
|
||||
in_addr IPAddress;
|
||||
IPAddress.S_un.S_addr=inet_addr("192.168.0.5");
|
||||
TCPIP_RETURN_CODE rCode=g_pSo7_TCPIP->Connect(m_hWnd,IPAddress,9600);
|
||||
m_csMSG.Format(_T("Server:192.168.0.5[9600] Connect return code:%d."),rCode);
|
||||
m_csMSG.Format(_T("Server:192.168.0.5[9600] Connect ReturnCode:%d."),rCode);
|
||||
OutputWithScroll(m_csMSG,m_edMSG);
|
||||
rCode=g_pSo7_TCPIP->GetHostIPAddr(IPAddress);
|
||||
m_csMSG.Format(_T("Client:%d.%d.%d.%d return code:%d."),
|
||||
m_csMSG.Format(_T("Client:%d.%d.%d.%d ReturnCode:%d."),
|
||||
IPAddress.S_un.S_un_b.s_b1,IPAddress.S_un.S_un_b.s_b2,
|
||||
IPAddress.S_un.S_un_b.s_b3,IPAddress.S_un.S_un_b.s_b4,rCode);
|
||||
OutputWithScroll(m_csMSG,m_edMSG);
|
||||
@@ -65,7 +66,7 @@ void CSo7_Util_PLC_TCPIP::OnBnClickedButtonPlcTcpipConnect()
|
||||
void CSo7_Util_PLC_TCPIP::OnBnClickedButtonPlcTcpipDisconnect()
|
||||
{
|
||||
TCPIP_RETURN_CODE rCode=g_pSo7_TCPIP->DisConnect();
|
||||
m_csMSG.Format(_T("DisConnect return code:%d."),rCode);
|
||||
m_csMSG.Format(_T("[DisConnect] ReturnCode:%d."),rCode);
|
||||
OutputWithScroll(m_csMSG,m_edMSG);
|
||||
}
|
||||
|
||||
@@ -78,14 +79,14 @@ void CSo7_Util_PLC_TCPIP::OnBnClickedButtonPlcTcpipRead()
|
||||
void CSo7_Util_PLC_TCPIP::OnBnClickedButtonPlcTcpipHandshaking()
|
||||
{
|
||||
TCPIP_RETURN_CODE rCode=g_pSo7_TCPIP->Handshaking();
|
||||
m_csMSG.Format(_T("Handshaking return code:%d."),rCode);
|
||||
m_csMSG.Format(_T("[Handshaking] Send ReturnCode:%d."),rCode);
|
||||
OutputWithScroll(m_csMSG,m_edMSG);
|
||||
}
|
||||
|
||||
void CSo7_Util_PLC_TCPIP::OnBnClickedButtonPlcTcpipWrite()
|
||||
{
|
||||
TCPIP_RETURN_CODE rCode=g_pSo7_TCPIP->Send(1001,0);
|
||||
m_csMSG.Format(_T("Write return code:%d."),rCode);
|
||||
m_csMSG.Format(_T("Write ReturnCode:%d."),rCode);
|
||||
OutputWithScroll(m_csMSG,m_edMSG);
|
||||
}
|
||||
|
||||
@@ -131,3 +132,42 @@ LRESULT CSo7_Util_PLC_TCPIP::OnSocket(WPARAM w, LPARAM p)
|
||||
|
||||
return( lResult );
|
||||
}
|
||||
LRESULT CSo7_Util_PLC_TCPIP::OnTCPIPRecv(WPARAM w, LPARAM p)
|
||||
{
|
||||
LRESULT lResult=0;
|
||||
switch(w)
|
||||
{
|
||||
case TCPIP_CMD_HANDSHAKING:
|
||||
{
|
||||
if (g_pSo7_TCPIP)
|
||||
{
|
||||
m_csMSG.Format(_T(">> Handshaking status:%d."),g_pSo7_TCPIP->m_TCPIPData.s_status._handshaking);
|
||||
OutputWithScroll(m_csMSG,m_edMSG);
|
||||
}
|
||||
m_csMSG=_T("[Handshaking]");
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
m_csMSG=_T("[Unknown]");
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (g_pSo7_TCPIP)
|
||||
{
|
||||
CString csTmp;
|
||||
csTmp.Format(_T("ReturnCode:%d;"),p);
|
||||
m_csMSG+=csTmp;
|
||||
csTmp.Format(_T("RecvSize:%d;"),g_pSo7_TCPIP->m_TCPIPBuf[CH_RECV]._size);
|
||||
m_csMSG+=csTmp;
|
||||
m_csMSG+=_T("RecvData:");
|
||||
for (int i=0;i<g_pSo7_TCPIP->m_TCPIPBuf[CH_RECV]._size;i++)
|
||||
{
|
||||
csTmp.Format(_T("0x%X "),g_pSo7_TCPIP->m_TCPIPBuf[CH_RECV]._buffer[i]);
|
||||
m_csMSG+=csTmp;
|
||||
}
|
||||
}
|
||||
m_csMSG+=_T(".");
|
||||
OutputWithScroll(m_csMSG,m_edMSG);
|
||||
return( lResult );
|
||||
}
|
||||
|
||||
@@ -28,5 +28,6 @@ public:
|
||||
afx_msg void OnBnClickedButtonPlcTcpipClearMsg();
|
||||
afx_msg void OnBnClickedCancel();
|
||||
afx_msg LRESULT OnSocket(WPARAM w, LPARAM p);
|
||||
afx_msg LRESULT OnTCPIPRecv(WPARAM w, LPARAM p);
|
||||
afx_msg void OnBnClickedButtonPlcTcpipHandshaking();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user