TCPIP SERVER

This commit is contained in:
TAO Cheng
2014-11-12 15:40:40 +08:00
parent cba2694c0c
commit c78c3c6f28
5 changed files with 125 additions and 60 deletions
@@ -24,7 +24,10 @@ IMPLEMENT_DYNAMIC(CSo7_Util_PLC_TCPIP_SERVER, CDialog)
CSo7_Util_PLC_TCPIP_SERVER::CSo7_Util_PLC_TCPIP_SERVER(CWnd* pParent /*=NULL*/)
: CDialog(CSo7_Util_PLC_TCPIP_SERVER::IDD, pParent)
{
for(int i=0;i<MAX_CCD_ADDR;i++)
{
m_CCDData_D10000[i]=0;
}
}
CSo7_Util_PLC_TCPIP_SERVER::~CSo7_Util_PLC_TCPIP_SERVER()
@@ -152,7 +155,15 @@ void CSo7_Util_PLC_TCPIP_SERVER::OnBnClickedButtonPlcTcpipServerUpdatestate()
GetDlgItem(IDC_EDIT_PLC_TCPIP_SERVER_PLC_STATE)->GetWindowText(str);
cTempValue=T2A(str);
g_pSo7_TCPIP_Server->m_TCPIPServerState._PLCRunningState=static_cast<BYTE>(atoi(cTempValue));
BYTE DM_Data[4]={0,0,0,0};
g_pSo7_TCPIP_Server->DM5000[0]=static_cast<short>(g_pSo7_TCPIP_Server->m_TCPIPServerState._PLCRunningState);
for (int i=1;i<=8;i++)
{
DM_Data[0]=g_pSo7_TCPIP_Server->m_TCPIPServerState._PLCSensorState[(i-1)*2];
DM_Data[1]=g_pSo7_TCPIP_Server->m_TCPIPServerState._PLCSensorState[(i-1)*2+1];
g_pSo7_TCPIP_Server->DM5000[i]=(DM_Data[0]<<8)+DM_Data[1];
}
}
@@ -201,11 +212,29 @@ void CSo7_Util_PLC_TCPIP_SERVER::m_UpdateListControl(int _type)
{
csTmp=m_DataList.GetItemText(iRow,iCol);
cTmp=T2A(csTmp);
if (g_pSo7_TCPIP_Server)
{
g_pSo7_TCPIP_Server->m_CCDData_D10000[iRow]=atoi(cTmp);
}
m_CCDData_D10000[iRow]=atoi(cTmp);
}
for (int iRow=0;iRow<MAX_CCD_ADDR;iRow++)
{
m_CCDData_D10000[iRow];
}
if (g_pSo7_TCPIP_Server)
{
int iData(0);
BYTE DM_Data[4]={0,0,0,0};
int StartAddr(60);
for (int i=0;i<MAX_CCD_ADDR;i++)
{
iData=m_CCDData_D10000[i];
DM_Data[0]=(iData>>24) & 0x0ff;
DM_Data[1]=(iData>>16) & 0x0ff;
DM_Data[2]=(iData>>8) & 0x0ff;
DM_Data[3]=iData & 0x0ff;
g_pSo7_TCPIP_Server->DM10000[StartAddr+2*i]=(DM_Data[2]<<8)+DM_Data[3];
g_pSo7_TCPIP_Server->DM10000[StartAddr+2*i+1]=(DM_Data[0]<<8)+DM_Data[1];
}
}
break;
}
default:break;
@@ -224,6 +253,18 @@ void CSo7_Util_PLC_TCPIP_SERVER::OnBnClickedCancel()
CDialog::OnCancel();
}
//=====================================================================================
BOOL CSo7_Util_PLC_TCPIP_SERVER::PreTranslateMessage(MSG* pMsg)
{
if(pMsg->message==WM_KEYDOWN)
{
if(pMsg->wParam==VK_RETURN || pMsg->wParam==VK_ESCAPE)
{
return TRUE;
}
}
return CDialog::PreTranslateMessage(pMsg);
}
//=====================================================================================
//Print message on edit control
void CSo7_Util_PLC_TCPIP_SERVER::OutputWithScroll(const CString &strNewText,CEdit &edtOutput)
{
@@ -16,6 +16,7 @@ public:
CString m_csMSG;
CEdit m_edMSG;
int m_CCDData_D10000[MAX_CCD_ADDR];
protected:
CEditableListCtrl m_DataList;
@@ -30,6 +31,7 @@ public:
afx_msg void OnBnClickedButtonPlcTcpipServerUpdatestate();
afx_msg void OnBnClickedButtonClearMsg();
afx_msg void OnBnClickedCancel();
afx_msg BOOL PreTranslateMessage(MSG* pMsg);
LRESULT OnSocket(WPARAM w, LPARAM p);