283 lines
8.3 KiB
C++
283 lines
8.3 KiB
C++
|
#include "HBDPurifierClient.h"
|
||
|
#include "S7Command.h"
|
||
|
#include "../global.h"
|
||
|
|
||
|
HBDPurifierClient::HBDPurifierClient(CommunicationCfg* pconfig) :S7Client(pconfig)
|
||
|
{
|
||
|
}
|
||
|
|
||
|
|
||
|
HBDPurifierClient::~HBDPurifierClient()
|
||
|
{
|
||
|
Shutdown();
|
||
|
}
|
||
|
|
||
|
void HBDPurifierClient::InitCommand()
|
||
|
{
|
||
|
S7Command* pcommand = new S7Command(S7_COMMAND_READ_INFO, READ_ITEM_COUNT);
|
||
|
TS7DataItem* items = pcommand->getDataItems();
|
||
|
items[0].Area = S7AreaDB;
|
||
|
items[0].DBNumber = 1;
|
||
|
items[0].WordLen = S7WLByte;
|
||
|
items[0].Start = 111;
|
||
|
items[0].Amount = 5;
|
||
|
items[0].pdata = new unsigned char[5];
|
||
|
|
||
|
items[1].Area = S7AreaDB;
|
||
|
items[1].DBNumber = 1;
|
||
|
items[1].WordLen = S7WLDWord;
|
||
|
items[1].Start = 0;
|
||
|
items[1].Amount = 1;
|
||
|
items[1].pdata = new int[1];
|
||
|
|
||
|
items[2].Area = S7AreaDB;
|
||
|
items[2].DBNumber = 1;
|
||
|
items[2].WordLen = S7WLReal;
|
||
|
items[2].Start = 30;
|
||
|
items[2].Amount = 2;
|
||
|
items[2].pdata = new float[2];
|
||
|
|
||
|
items[3].Area = S7AreaDB;
|
||
|
items[3].DBNumber = 1;
|
||
|
items[3].WordLen = S7WLDWord;
|
||
|
items[3].Start = 224;
|
||
|
items[3].Amount = 2;
|
||
|
items[3].pdata = new int[2];
|
||
|
|
||
|
items[4].Area = S7AreaDB;
|
||
|
items[4].DBNumber = 1;
|
||
|
items[4].WordLen = S7WLByte;
|
||
|
items[4].Start = 135;
|
||
|
items[4].Amount = 2;
|
||
|
items[4].pdata = new unsigned char[2];
|
||
|
|
||
|
items[5].Area = S7AreaDB;
|
||
|
items[5].DBNumber = 1;
|
||
|
items[5].WordLen = S7WLByte;
|
||
|
items[5].Start = 120;
|
||
|
items[5].Amount = 2;
|
||
|
items[5].pdata = new unsigned char[2];
|
||
|
|
||
|
items[6].Area = S7AreaDB;
|
||
|
items[6].DBNumber = 1;
|
||
|
items[6].WordLen = S7WLDWord;
|
||
|
items[6].Start = 68;
|
||
|
items[6].Amount = 1;
|
||
|
items[6].pdata = new int[1];
|
||
|
|
||
|
pcommand->m_Ref = this;
|
||
|
pcommand->m_Fun = &HBDPurifierClient::ProcReadInfo;
|
||
|
pcommand->isNeedDel = false;
|
||
|
m_CycleCommands.push_back(pcommand);
|
||
|
}
|
||
|
|
||
|
void HBDPurifierClient::ProcReadInfo(void *pobject, Command* pcommand)
|
||
|
{
|
||
|
S7Command* s7Command = (S7Command*)pcommand;
|
||
|
TS7DataItem* pdataItems = s7Command->getDataItems();
|
||
|
int itemcount = s7Command->getItemCount();
|
||
|
if (pobject == NULL || itemcount != READ_ITEM_COUNT)return;
|
||
|
HBDPurifierClient* pc = (HBDPurifierClient*)pobject;
|
||
|
TS7DataItem pPurifier = pdataItems[0];
|
||
|
TS7DataItem pTemp = pdataItems[1];
|
||
|
TS7DataItem pDifPressure = pdataItems[2];
|
||
|
TS7DataItem pFilter = pdataItems[3];
|
||
|
TS7DataItem pValve = pdataItems[4];
|
||
|
TS7DataItem pExcept = pdataItems[5];
|
||
|
TS7DataItem pFilterAlarm = pdataItems[6];
|
||
|
|
||
|
EnterCriticalSection(&pc->m_ValueCS);
|
||
|
if (pPurifier.Result == 0) {
|
||
|
unsigned char* arr = (unsigned char*)pPurifier.pdata;
|
||
|
unsigned char mdata0 = arr[0];
|
||
|
unsigned char mdata1 = arr[1];
|
||
|
unsigned char mdata2 = arr[2];
|
||
|
unsigned char mdata3 = arr[3];
|
||
|
unsigned char mdata4 = arr[4];
|
||
|
|
||
|
pc->m_Stat.isDeoxygen = ((mdata0 & 0x80) > 0 ? true : false);
|
||
|
pc->m_Stat.isBlowBack = ((mdata2 & 0x80) > 0 ? true : false);
|
||
|
pc->m_Stat.isDedusting = ((mdata4 & 0x80) > 0 ? true : false);
|
||
|
}
|
||
|
if (pTemp.Result == 0) {
|
||
|
char* pchar = (char*)pTemp.pdata;
|
||
|
S7DWORDDATA temperature;
|
||
|
temperature.data[0] = pchar[3];
|
||
|
temperature.data[1] = pchar[2];
|
||
|
temperature.data[2] = pchar[1];
|
||
|
|
||
|
temperature.data[3] = pchar[0];
|
||
|
pc->m_Stat.temperature = temperature.iValue;
|
||
|
}
|
||
|
if (pDifPressure.Result == 0) {
|
||
|
char* pchar = (char*)pDifPressure.pdata;
|
||
|
S7FLOATDATA difpressure;
|
||
|
difpressure.data[0] = pchar[3];
|
||
|
difpressure.data[1] = pchar[2];
|
||
|
difpressure.data[2] = pchar[1];
|
||
|
difpressure.data[3] = pchar[0];
|
||
|
pc->m_Stat.difPressure = difpressure.fValue;
|
||
|
|
||
|
S7FLOATDATA jampressure;
|
||
|
jampressure.data[0] = pchar[7];
|
||
|
jampressure.data[1] = pchar[6];
|
||
|
jampressure.data[2] = pchar[5];
|
||
|
jampressure.data[3] = pchar[4];
|
||
|
pc->m_Stat.filterJamPressure = jampressure.fValue;
|
||
|
}
|
||
|
if (pFilter.Result == 0) {
|
||
|
char* pchar = (char*)pFilter.pdata;
|
||
|
S7DWORDDATA filterTime;
|
||
|
S7DWORDDATA spinFilterTime;
|
||
|
|
||
|
filterTime.data[0] = pchar[3];
|
||
|
filterTime.data[1] = pchar[2];
|
||
|
filterTime.data[2] = pchar[1];
|
||
|
filterTime.data[3] = pchar[0];
|
||
|
|
||
|
spinFilterTime.data[0] = pchar[7];
|
||
|
spinFilterTime.data[1] = pchar[6];
|
||
|
spinFilterTime.data[2] = pchar[5];
|
||
|
spinFilterTime.data[3] = pchar[4];
|
||
|
|
||
|
pc->m_Stat.filterTotalUseTime = filterTime.iValue;
|
||
|
pc->m_Stat.spinFilterTotalUseTime = spinFilterTime.iValue;
|
||
|
}
|
||
|
if (pValve.Result == 0) {
|
||
|
unsigned char* pchar = (unsigned char*)pValve.pdata;
|
||
|
pc->m_Stat.cycleEnter = HBDPurifierStat::ValveStat(pchar[0]);
|
||
|
pc->m_Stat.cycleExit = HBDPurifierStat::ValveStat(pchar[1]);
|
||
|
}
|
||
|
|
||
|
if (pExcept.Result == 0) {
|
||
|
unsigned char* pchar = (unsigned char*)pExcept.pdata;
|
||
|
unsigned char mdata0 = pchar[0];
|
||
|
unsigned char mdata1 = pchar[1];
|
||
|
pc->m_Stat.hasExcept = ((mdata0 & 0x01) > 0 ? true : false);
|
||
|
pc->m_Stat.isDifPressureAlarm = ((mdata1 & 0x01) > 0 ? true : false);
|
||
|
pc->m_Stat.isDeoxygenEnterCloseExcept = ((mdata1 & 0x02) > 0 ? true : false);
|
||
|
pc->m_Stat.isBlowBackEnterCloseExcept = ((mdata1 & 0x04) > 0 ? true : false);
|
||
|
pc->m_Stat.isDeoxygenExitCloseExcept = ((mdata1 & 0x08) > 0 ? true : false);
|
||
|
pc->m_Stat.isBlowBackExitCloseExcept = ((mdata1 & 0x10) > 0 ? true : false);
|
||
|
pc->m_Stat.isEnterGapOpenExcept = ((mdata1 & 0x20) > 0 ? true : false);
|
||
|
pc->m_Stat.isExitGapOpenExcept = ((mdata1 & 0x40) > 0 ? true : false);
|
||
|
pc->m_Stat.isOverTemp = ((mdata1 & 0x80) > 0 ? true : false);
|
||
|
}
|
||
|
|
||
|
if (pFilterAlarm.Result == 0)
|
||
|
{
|
||
|
char* pchar = (char*)pFilterAlarm.pdata;
|
||
|
S7DWORDDATA filterAlarmTime;
|
||
|
filterAlarmTime.data[0] = pchar[3];
|
||
|
filterAlarmTime.data[1] = pchar[2];
|
||
|
filterAlarmTime.data[2] = pchar[1];
|
||
|
filterAlarmTime.data[3] = pchar[0];
|
||
|
pc->m_Stat.spinFilterAlarmTime = filterAlarmTime.iValue;
|
||
|
}
|
||
|
LeaveCriticalSection(&pc->m_ValueCS);
|
||
|
}
|
||
|
|
||
|
void HBDPurifierClient::ProcWriteValue(void *pobject, Command* pcommand)
|
||
|
{
|
||
|
|
||
|
}
|
||
|
|
||
|
void HBDPurifierClient::SetDeoxygen(bool enable)
|
||
|
{
|
||
|
if (g_isDebug) {
|
||
|
m_Stat.isDeoxygen = enable;
|
||
|
}
|
||
|
if (!m_BaseStat.isConnected)return;
|
||
|
S7Command* pcommand = new S7Command(S7_COMMAND_WRITE, 1);
|
||
|
TS7DataItem* items = pcommand->getDataItems();
|
||
|
items[0].Area = S7AreaDB;
|
||
|
items[0].DBNumber = 1;
|
||
|
items[0].Start = 111 * 8 + 7;
|
||
|
items[0].WordLen = S7WLBit;
|
||
|
items[0].Amount = 1;
|
||
|
bool* tempv = new bool[1];
|
||
|
tempv[0] = enable;
|
||
|
items[0].pdata = tempv;
|
||
|
pcommand->m_Ref = this;
|
||
|
pcommand->m_Fun = &HBDPurifierClient::ProcWriteValue;
|
||
|
EnterCriticalSection(&m_RtcCS);
|
||
|
m_RTCommands.push(pcommand);
|
||
|
LeaveCriticalSection(&m_RtcCS);
|
||
|
|
||
|
}
|
||
|
|
||
|
void HBDPurifierClient::SetBlowBack(bool enable)
|
||
|
{
|
||
|
if (g_isDebug) {
|
||
|
m_Stat.isBlowBack = enable;
|
||
|
}
|
||
|
if (!m_BaseStat.isConnected)return;
|
||
|
S7Command* pcommand = new S7Command(S7_COMMAND_WRITE, 1);
|
||
|
TS7DataItem* items = pcommand->getDataItems();
|
||
|
items[0].Area = S7AreaDB;
|
||
|
items[0].DBNumber = 1;
|
||
|
items[0].Start = 113 * 8 + 7;
|
||
|
items[0].WordLen = S7WLBit;
|
||
|
items[0].Amount = 1;
|
||
|
bool* tempv = new bool[1];
|
||
|
tempv[0] = enable;
|
||
|
items[0].pdata = tempv;
|
||
|
pcommand->m_Ref = this;
|
||
|
pcommand->m_Fun = &HBDPurifierClient::ProcWriteValue;
|
||
|
EnterCriticalSection(&m_RtcCS);
|
||
|
m_RTCommands.push(pcommand);
|
||
|
LeaveCriticalSection(&m_RtcCS);
|
||
|
}
|
||
|
|
||
|
void HBDPurifierClient::SetDedusting(bool enable)
|
||
|
{
|
||
|
if (g_isDebug) {
|
||
|
m_Stat.isDedusting = enable;
|
||
|
m_Stat.cycleEnter = enable ? HBDPurifierStat::OpenPosition : HBDPurifierStat::ClosePosition;
|
||
|
m_Stat.cycleExit = enable ? HBDPurifierStat::OpenPosition : HBDPurifierStat::ClosePosition;
|
||
|
}
|
||
|
if (!m_BaseStat.isConnected)return;
|
||
|
S7Command* pcommand = new S7Command(S7_COMMAND_WRITE, 1);
|
||
|
TS7DataItem* items = pcommand->getDataItems();
|
||
|
items[0].Area = S7AreaDB;
|
||
|
items[0].DBNumber = 1;
|
||
|
items[0].Start = 115 * 8 + 7;
|
||
|
items[0].WordLen = S7WLBit;
|
||
|
items[0].Amount = 1;
|
||
|
bool* tempv = new bool[1];
|
||
|
tempv[0] = enable;
|
||
|
items[0].pdata = tempv;
|
||
|
pcommand->m_Ref = this;
|
||
|
pcommand->m_Fun = &HBDPurifierClient::ProcWriteValue;
|
||
|
EnterCriticalSection(&m_RtcCS);
|
||
|
m_RTCommands.push(pcommand);
|
||
|
LeaveCriticalSection(&m_RtcCS);
|
||
|
}
|
||
|
|
||
|
void HBDPurifierClient::ResetSpinFilterUseTime(bool enable)
|
||
|
{
|
||
|
if (!m_BaseStat.isConnected)return;
|
||
|
S7Command* pcommand = new S7Command(S7_COMMAND_WRITE, 1);
|
||
|
TS7DataItem* items = pcommand->getDataItems();
|
||
|
items[0].Area = S7AreaDB;
|
||
|
items[0].DBNumber = 1;
|
||
|
items[0].Start = 114 * 8 + 7;
|
||
|
items[0].WordLen = S7WLBit;
|
||
|
items[0].Amount = 1;
|
||
|
bool* tempv = new bool[1];
|
||
|
tempv[0] = enable;
|
||
|
items[0].pdata = tempv;
|
||
|
pcommand->m_Ref = this;
|
||
|
pcommand->m_Fun = &HBDPurifierClient::ProcWriteValue;
|
||
|
EnterCriticalSection(&m_RtcCS);
|
||
|
m_RTCommands.push(pcommand);
|
||
|
LeaveCriticalSection(&m_RtcCS);
|
||
|
}
|
||
|
|
||
|
void HBDPurifierClient::GetStat(HBDPurifierStat& stat)
|
||
|
{
|
||
|
EnterCriticalSection(&m_ValueCS);
|
||
|
memcpy_s(&stat, sizeof(HBDPurifierStat), &m_Stat, sizeof(HBDPurifierStat));
|
||
|
memcpy_s(&stat.baseStat, sizeof(BaseStat), &m_BaseStat, sizeof(BaseStat));
|
||
|
LeaveCriticalSection(&m_ValueCS);
|
||
|
}
|