GrpcPrint/PrintS/PLC/Command/CoverParamCommand.h
2024-03-19 17:45:12 +08:00

75 lines
2.2 KiB
C++

#pragma once
#include "../SysParam.h"
class CoverParamCommand:public PLCCommand
{
public:
CoverParamCommand(PLCReveiver* receiver,SysParam* layerThick , SysParam* powderCount, SysParam* isCoverDebug,SysParam* isFirst):PLCCommand(receiver) {
m_CtrlCommand = new S7Command(S7_COMMAND_WRITE, 4);
TS7DataItem* pItem = m_CtrlCommand->getDataItems();
pItem[0].Area = S7AreaDB;
pItem[0].DBNumber = layerThick->GetDBNumber();
pItem[0].Start = layerThick->GetAddr();
pItem[0].WordLen = S7WLByte;
pItem[0].Amount = 4;
unsigned char* tempLayerThick = new unsigned char[4];
pItem[0].pdata = tempLayerThick;
m_LayerThick = tempLayerThick;
pItem[1].Area = S7AreaDB;
pItem[1].DBNumber = powderCount->GetDBNumber();
pItem[1].Start = powderCount->GetAddr();
pItem[1].WordLen = S7WLByte;
pItem[1].Amount = 2;
unsigned char* tempPowderCount = new unsigned char[2];
pItem[1].pdata = tempPowderCount;
m_PowderCount = tempPowderCount;
pItem[2].Area = S7AreaDB;
pItem[2].DBNumber = isCoverDebug->GetDBNumber();
pItem[2].Start = isCoverDebug->GetAddr();
pItem[2].WordLen = S7WLBit;
pItem[2].Amount = 1;
bool* tempIsDebug = new bool[1];
pItem[2].pdata = tempIsDebug;
m_IsDebug = tempIsDebug;
pItem[3].Area = S7AreaDB;
pItem[3].DBNumber = isFirst->GetDBNumber();
pItem[3].Start = isFirst->GetAddr();
pItem[3].WordLen = S7WLBit;
pItem[3].Amount = 1;
bool* tempIsFirst = new bool[1];
pItem[3].pdata = tempIsFirst;
m_IsFirst = tempIsFirst;
m_CtrlCommand->m_Ref = this;
m_CtrlCommand->isNeedDel = false;
}
~CoverParamCommand() {
if (m_CtrlCommand)delete m_CtrlCommand;
}
void SetValue(float layerThick, short powderCount, bool isDebug,bool isFirst)
{
S7FloatData s7LayerThick;
S7WordData s7PowderCount;
s7LayerThick.fValue = layerThick;
m_LayerThick[3] = s7LayerThick.data[0];
m_LayerThick[2] = s7LayerThick.data[1];
m_LayerThick[1] = s7LayerThick.data[2];
m_LayerThick[0] = s7LayerThick.data[3];
s7PowderCount.wValue = powderCount;
m_PowderCount[1] = s7PowderCount.data[0];
m_PowderCount[0] = s7PowderCount.data[1];
*m_IsDebug = isDebug;
*m_IsFirst = isFirst;
}
private:
unsigned char* m_LayerThick;
unsigned char* m_PowderCount;
bool* m_IsDebug;
bool* m_IsFirst;
};