86 lines
2.5 KiB
C++
86 lines
2.5 KiB
C++
#include "PowderCarClient.h"
|
|
#include "Modbus.h"
|
|
#include "../config/ConfigManager.h"
|
|
|
|
PowderCarClient::PowderCarClient(CommunicationCfg* pconfig) :TcpClient(pconfig)
|
|
{
|
|
m_Freq = 100;
|
|
m_PrintStorageCar1Connect = ConfigManager::GetInstance()->GetIoCfgWrapper()->m_PrintStorageCar1Connect;
|
|
m_PrintStorageCar2Connect = ConfigManager::GetInstance()->GetIoCfgWrapper()->m_PrintStorageCar2Connect;
|
|
m_CleanStorageCar1Connect = ConfigManager::GetInstance()->GetIoCfgWrapper()->m_CleanStorageCar1Connect;
|
|
m_CleanStorageCar2Connect = ConfigManager::GetInstance()->GetIoCfgWrapper()->m_CleanStorageCar2Connect;
|
|
}
|
|
|
|
|
|
PowderCarClient::~PowderCarClient()
|
|
{
|
|
Shutdown();
|
|
}
|
|
|
|
void PowderCarClient::InitCommand()
|
|
{
|
|
for (int i = 1; i <= 4; i++) {
|
|
Command* weihtValue = new ReadModbus(i, 0x0606, 2);
|
|
weihtValue->m_Fun = &PowderCarClient::PorcWeightValue;
|
|
weihtValue->m_Ref = this;
|
|
weihtValue->isNeedDel = false;
|
|
m_CycleCommands.push_back(weihtValue);
|
|
m_WeightValues[i] = 0.0f;
|
|
}
|
|
}
|
|
|
|
void PowderCarClient::PorcWeightValue(void* pobject, Command* pcommand)
|
|
{
|
|
if (pobject == NULL)return;
|
|
PowderCarClient* pcc = (PowderCarClient*)pobject;
|
|
unsigned char* rseq = pcommand->m_RespSeq;
|
|
unsigned char addr = rseq[0];
|
|
|
|
if (pcc->m_WeightValues.find(addr) == pcc->m_WeightValues.end())return;
|
|
|
|
EnterCriticalSection(&pcc->m_ValueCS);
|
|
int value = (((rseq[3] & 0xff) << 24) + ((rseq[4] & 0xff) << 16) + ((rseq[5] & 0xff) << 8) + (rseq[6] & 0xff));
|
|
pcc->m_WeightValues[addr] = (float)value / 10.0f;
|
|
LeaveCriticalSection(&pcc->m_ValueCS);
|
|
}
|
|
|
|
void PowderCarClient::GetWeightValue(float& pcar1, float& pcar2, float &ccar1, float &ccar2)
|
|
{
|
|
EnterCriticalSection(&m_ValueCS);
|
|
pcar1=m_WeightValues[1];
|
|
pcar2 = m_WeightValues[2];
|
|
ccar1 = m_WeightValues[3];
|
|
ccar2 = m_WeightValues[4];
|
|
LeaveCriticalSection(&m_ValueCS);
|
|
}
|
|
|
|
void PowderCarClient::CycleBegin()
|
|
{
|
|
if (m_PrintStorageCar1Connect && m_PrintStorageCar1Connect->IsActive()) {
|
|
m_CycleCommands[0]->isNeedSend = true;
|
|
}
|
|
else {
|
|
m_CycleCommands[0]->isNeedSend = false;
|
|
}
|
|
|
|
if (m_PrintStorageCar2Connect && m_PrintStorageCar2Connect->IsActive()) {
|
|
m_CycleCommands[1]->isNeedSend = true;
|
|
}
|
|
else {
|
|
m_CycleCommands[1]->isNeedSend = false;
|
|
}
|
|
|
|
if (m_CleanStorageCar1Connect && m_CleanStorageCar1Connect->IsActive()) {
|
|
m_CycleCommands[2]->isNeedSend = true;
|
|
}
|
|
else {
|
|
m_CycleCommands[2]->isNeedSend = false;
|
|
}
|
|
|
|
if (m_CleanStorageCar2Connect && m_CleanStorageCar2Connect->IsActive()) {
|
|
m_CycleCommands[3]->isNeedSend = true;
|
|
}
|
|
else {
|
|
m_CycleCommands[3]->isNeedSend = false;
|
|
}
|
|
} |