Files
geomative/GeomativeStudio/cpp/Tools/OperPLC.cpp
T
coco df489d5640 a
2026-07-03 16:05:30 +08:00

121 lines
2.9 KiB
C++

// OperPLC.cpp: implementation of the COperPLC class.
//
//////////////////////////////////////////////////////////////////////
#include "geomative.h"
#include "OperPLC.h"
#include "FileOperTools.h"
#include "CtrlProtocolDef.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
extern int g_iUILanguage;
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
COperPLC* COperPLC::m_pOperPlc = NULL;
COperPLC::COperPLC()
{
}
COperPLC::~COperPLC()
{
}
COperPLC* COperPLC::GetInstance()
{
if (NULL == m_pOperPlc)
{
m_pOperPlc = new COperPLC;
}
return m_pOperPlc;
}
int COperPLC::ParsePlcOperResInfo(char* pData, int iLen)
{
if (iLen != sizeof(STRemPlcDataInfo))
{
return EN_PLC_RES_LEN_ERR;
}
STRemPlcDataInfo* pPlcInfo = (STRemPlcDataInfo*)pData;
if ( 1== pPlcInfo->ucResult)
return EN_PLC_RES_SUCCESS;
else
return EN_PLC_RES_FAILED;
}
void COperPLC::GetPlcCmdInfo(BYTE ucCmd, char* pData, int& iLen, int iMaxLen)
{
iLen = 0;
CString str = _T("");
if (iMaxLen < sizeof(STRemPlcDataInfo))
{
if (LANG_ZHCN == g_iUILanguage)
{
str.Format(_T("获取plc cmd长度错误.max_len=%d, should_len=%d"), iMaxLen, sizeof(STRemPlcDataInfo));
AfxMessageBox(str);
}
else
{
str.Format(_T("Get plc cmd length error.max_len=%d, should_len=%d"), iMaxLen, sizeof(STRemPlcDataInfo));
MessageBoxEx(NULL, str, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
}
return;
}
switch (ucCmd)
{
case EN_PLC_POWER_ON:
GetPowerOnCmd(pData,iLen);
break;
case EN_PLC_POWER_OFF:
GetPowerOffCmd(pData,iLen);
break;
default:
if (LANG_ZHCN == g_iUILanguage)
{
str.Format(_T("未知PLC命令(%d)"), ucCmd);
AfxMessageBox(str);
}
else
{
str.Format(_T("Unknow plc cmd(%d)"), ucCmd);
MessageBoxEx(NULL, str, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
}
break;
}
}
void COperPLC::GetPowerOffCmd(char* pCmdData,int& iCmdLen)
{
STRemPlcDataInfo* pPlcDataInfo = (STRemPlcDataInfo*)pCmdData;
iCmdLen = sizeof(STRemPlcDataInfo);
memset(pPlcDataInfo, 0, sizeof(STRemPlcDataInfo));
pPlcDataInfo->ucPacketIndex = 1;
pPlcDataInfo->ucCtrlK3 = 0;
pPlcDataInfo->ucCtrlK4 = 0;
//1,2,5,6设置成2
pPlcDataInfo->ucCtrlK1 = 2;
pPlcDataInfo->ucCtrlK2 = 2;
pPlcDataInfo->ucCtrlK5 = 2;
pPlcDataInfo->ucCtrlK6 = 2;
}
void COperPLC::GetPowerOnCmd(char* pCmdData,int& iCmdLen)
{
STRemPlcDataInfo* pPlcDataInfo = (STRemPlcDataInfo*)pCmdData;
iCmdLen = sizeof(STRemPlcDataInfo);
memset(pPlcDataInfo, 0, sizeof(STRemPlcDataInfo));
pPlcDataInfo->ucPacketIndex = 1;
pPlcDataInfo->ucCtrlK3 = 1;
pPlcDataInfo->ucCtrlK4 = 1;
//1,2,5,6设置成2
pPlcDataInfo->ucCtrlK1 = 2;
pPlcDataInfo->ucCtrlK2 = 2;
pPlcDataInfo->ucCtrlK5 = 2;
pPlcDataInfo->ucCtrlK6 = 2;
}