#include "ComServer.h" #include "../global.h" ComServer::ComServer() :m_TempCtrlClient(nullptr) , m_LaserChillerClient(nullptr) //, m_PurifierChillerClient(nullptr) ,m_UPSClient(nullptr) ,m_OxygenClient(nullptr) , m_SimpleSupplyClient(nullptr) //,m_PowderCarClient(nullptr) , m_PowerMeterClient(nullptr) , m_ScannerPowerClient(nullptr) { m_AlarmCfgWrapper = ConfigManager::Instance()->GetAlarmCfg(); } ComServer::~ComServer() { if (m_TempCtrlClient != nullptr) m_TempCtrlClient->SetRunFlag(false); if (m_PowerMeterClient != nullptr) m_PowerMeterClient->SetRunFlag(false); if (m_ScannerPowerClient)m_ScannerPowerClient->SetRunFlag(false); for (size_t i = 0; i < m_LaserClients.size(); i++) { m_LaserClients[i]->SetRunFlag(false); } if(m_OxygenClient)m_OxygenClient->SetRunFlag(false); if (m_LaserChillerClient)m_LaserChillerClient->SetRunFlag(false); //if (m_PurifierChillerClient)m_PurifierChillerClient->SetRunFlag(false); if (m_UPSClient)m_UPSClient->SetRunFlag(false); if (m_SimpleSupplyClient)m_SimpleSupplyClient->SetRunFlag(false); //if (m_PowderCarClient)m_PowderCarClient->SetRunFlag(false); if (m_TempCtrlClient)delete m_TempCtrlClient; if(m_OxygenClient)delete m_OxygenClient; if (m_UPSClient)delete m_UPSClient; if (m_LaserChillerClient)delete m_LaserChillerClient; //if (m_PurifierChillerClient)delete m_PurifierChillerClient; if (m_SimpleSupplyClient)delete m_SimpleSupplyClient; //if (m_PowderCarClient)delete m_PowderCarClient; if (m_ScannerPowerClient)delete m_ScannerPowerClient; if (m_PowerMeterClient)delete m_PowerMeterClient; for (size_t i = 0; i < m_LaserClients.size(); i++) { delete m_LaserClients[i]; } m_LaserClients.clear(); } void ComServer::Init() { m_MachineCfg = ConfigManager::Instance()->GetMachineCfg(); m_ExtCfg = ConfigManager::Instance()->GetExtCfg(); m_Machine = ConfigManager::Instance()->GetMachine(); WORD wVersionRequested = MAKEWORD(2, 2); CSocketHandle::InitLibrary(wVersionRequested); m_TempCtrlClient = new TempCtrlClient(/*(*communicationCfg)["PLATE_TEMP"]*/); m_TempCtrlClient->Init(); m_OxygenClient = new OxygenClient(/*(*communicationCfg)["OXYGEN"]*/); m_OxygenClient->Init(); ExtCfg extCfg; m_ExtCfg->GetCfg(extCfg); m_LaserChillerClient = new ChillerClient(/*(*communicationCfg)["LASER_CHILLER"]*/nullptr, &extCfg.m_LaserChillerType); m_LaserChillerClient->Init(); m_UPSClient = new UPSClient(/*(*communicationCfg)["UPS"]*/); m_UPSClient->Init(); IPGLaserClientV1* client1 = new IPGLaserClientV1(nullptr/*(*communicationCfg)["LASER1"]*//*, m_AlarmCfgWrapper->m_Laser1ComAlarm*/); m_LaserClients.push_back(client1); client1->Init(); IPGLaserClientV1* client2 = new IPGLaserClientV1(/*(*communicationCfg)["LASER2"]*/nullptr/*, m_AlarmCfgWrapper->m_Laser2ComAlarm*/); m_LaserClients.push_back(client2); client2->Init(); IPGLaserClientV1* client3 = new IPGLaserClientV1(/*(*communicationCfg)["LASER2"]*/nullptr/*, m_AlarmCfgWrapper->m_Laser2ComAlarm*/); m_LaserClients.push_back(client3); client3->Init(); IPGLaserClientV1* client4 = new IPGLaserClientV1(/*(*communicationCfg)["LASER2"]*/nullptr/*, m_AlarmCfgWrapper->m_Laser2ComAlarm*/); m_LaserClients.push_back(client4); client4->Init(); if (m_MachineCfg->m_SupplyMachineVersion == MachineCfg::VERSION_1_0) { m_SimpleSupplyClient = new PowderSupplySimpleClient(/*(*communicationCfg)["SIMPLE_SUPPLY"]*/); } else if (m_MachineCfg->m_SupplyMachineVersion == MachineCfg::VERSION_2_1) { m_SimpleSupplyClient = new PowderSupplySimpleClient2(/*(*communicationCfg)["SIMPLE_SUPPLY"]*/); } else if (m_MachineCfg->m_SupplyMachineVersion == MachineCfg::VERSION_2_2) { m_SimpleSupplyClient = new PowderSupplySimpleClient3(/*(*communicationCfg)["SIMPLE_SUPPLY"]*/); } else { m_SimpleSupplyClient = new PowderSupplySimpleClient2(/*(*communicationCfg)["SIMPLE_SUPPLY"]*/); } m_SimpleSupplyClient->Init(); m_PowerMeterClient = new PowerMeterClient(/*(*communicationCfg)["POWER_METER"]*/); m_PowerMeterClient->Init(); m_ScannerPowerClient = new ScannerPowerClient(/*(*communicationCfg)["SCANNER_POWER"]*/); ////map* communicationCfg = ConfigManager::Instance()->GetCommunicationCfg(); //if (communicationCfg->find("PLATE_TEMP") != communicationCfg->end()) { // m_TempCtrlClient = new TempCtrlClient((*communicationCfg)["PLATE_TEMP"]); // m_TempCtrlClient->Init(); // ConfigManager::Instance()->AddComRefCfg(m_TempCtrlClient->GetConfig(), m_TempCtrlClient); //添加控制启停的 //} //if (communicationCfg->find("OXYGEN") != communicationCfg->end()) { // m_OxygenClient= new OxygenClient((*communicationCfg)["OXYGEN"]); // m_OxygenClient->Init(); // ConfigManager::Instance()->AddComRefCfg(m_OxygenClient->GetConfig(), m_OxygenClient); //} //if (communicationCfg->find("LASER_CHILLER") != communicationCfg->end()) { // m_LaserChillerClient = new ChillerClient((*communicationCfg)["LASER_CHILLER"],&m_ExtCfg->m_LaserChillerType); // m_LaserChillerClient->Init(); // ConfigManager::Instance()->AddComRefCfg(m_LaserChillerClient->GetConfig(), m_LaserChillerClient); //} ///*if (communicationCfg->find("PURIFIER_CHILLER") != communicationCfg->end()) { // m_PurifierChillerClient = new ChillerClient((*communicationCfg)["PURIFIER_CHILLER"],&m_ExtCfg->m_PurifierChillerType); // m_PurifierChillerClient->Init(); // ConfigManager::Instance()->AddComRefCfg(m_PurifierChillerClient->GetConfig(), m_PurifierChillerClient); //}*/ //if (communicationCfg->find("UPS") != communicationCfg->end()) { // m_UPSClient = new UPSClient((*communicationCfg)["UPS"]); // m_UPSClient->Init(); // ConfigManager::Instance()->AddComRefCfg(m_UPSClient->GetConfig(), m_UPSClient); //} //if (communicationCfg->find("LASER1") != communicationCfg->end()) //{ // IPGLaserClientV1* client = new IPGLaserClientV1((*communicationCfg)["LASER1"], m_AlarmCfgWrapper->m_Laser1ComAlarm); // m_LaserClients.push_back(client); // client->Init(); // ConfigManager::Instance()->AddComRefCfg(client->GetConfig(), client); //} //if (communicationCfg->find("LASER2") != communicationCfg->end()) //{ // IPGLaserClientV1* client = new IPGLaserClientV1((*communicationCfg)["LASER2"], m_AlarmCfgWrapper->m_Laser2ComAlarm); // m_LaserClients.push_back(client); // client->Init(); // ConfigManager::Instance()->AddComRefCfg(client->GetConfig(), client); //} //if (communicationCfg->find("LASER3") != communicationCfg->end()) //{ // IPGLaserClientV1* client = new IPGLaserClientV1((*communicationCfg)["LASER3"], m_AlarmCfgWrapper->m_Laser3ComAlarm); // m_LaserClients.push_back(client); // client->Init(); // ConfigManager::Instance()->AddComRefCfg(client->GetConfig(), client); //} //if (communicationCfg->find("LASER4") != communicationCfg->end()) //{ // IPGLaserClientV1* client = new IPGLaserClientV1((*communicationCfg)["LASER4"], m_AlarmCfgWrapper->m_Laser4ComAlarm); // m_LaserClients.push_back(client); // client->Init(); // ConfigManager::Instance()->AddComRefCfg(client->GetConfig(), client); //} //if (communicationCfg->find("SIMPLE_SUPPLY") != communicationCfg->end()) { // if (m_MachineCfg->m_SupplyMachineVersion == MachineCfg::VERSION_1_0) { // m_SimpleSupplyClient = new PowderSupplySimpleClient((*communicationCfg)["SIMPLE_SUPPLY"]); // } // else if (m_MachineCfg->m_SupplyMachineVersion == MachineCfg::VERSION_2_1) { // m_SimpleSupplyClient = new PowderSupplySimpleClient2((*communicationCfg)["SIMPLE_SUPPLY"]); // } // else if (m_MachineCfg->m_SupplyMachineVersion == MachineCfg::VERSION_2_2) { // m_SimpleSupplyClient = new PowderSupplySimpleClient3((*communicationCfg)["SIMPLE_SUPPLY"]); // } // else { // m_SimpleSupplyClient = new PowderSupplySimpleClient2((*communicationCfg)["SIMPLE_SUPPLY"]); // } // m_SimpleSupplyClient->Init(); // ConfigManager::Instance()->AddComRefCfg(m_SimpleSupplyClient->GetConfig(), m_SimpleSupplyClient); //} ///*if (communicationCfg->find("WEIGHT_CAR") != communicationCfg->end()) { // m_PowderCarClient = new PowderCarClient((*communicationCfg)["WEIGHT_CAR"]); // m_PowderCarClient->Init(); // ConfigManager::Instance()->AddComRefCfg(m_PowderCarClient->GetConfig(), m_PowderCarClient); //}*/ //if (communicationCfg->find("POWER_METER") != communicationCfg->end()) { // m_PowerMeterClient = new PowerMeterClient((*communicationCfg)["POWER_METER"]); // m_PowerMeterClient->Init(); // ConfigManager::Instance()->AddComRefCfg(m_PowerMeterClient->GetConfig(), m_PowerMeterClient); //} //if (communicationCfg->find("SCANNER_POWER") != communicationCfg->end()) { // m_ScannerPowerClient = new ScannerPowerClient((*communicationCfg)["SCANNER_POWER"]); // //m_ScannerPowerClient->Init(); // ConfigManager::Instance()->AddComRefCfg(m_ScannerPowerClient->GetConfig(), m_ScannerPowerClient); //} } void ComServer::Startup() { //if (m_TempCtrlClient != nullptr) { // /*if (m_TempCtrlClient->GetConfig()->m_Enable)*/m_TempCtrlClient->Startup(); //} //if (m_OxygenClient) { // /*if (m_OxygenClient->GetConfig()->m_Enable)*/m_OxygenClient->Startup(); //} //if (m_LaserChillerClient) { // /*if (m_LaserChillerClient->GetConfig()->m_Enable)*/m_LaserChillerClient->Startup(); //} //if (m_UPSClient) { // /*if (m_UPSClient->GetConfig()->m_Enable)*/m_UPSClient->Startup(); //} //for (size_t i = 0; i < m_LaserClients.size(); i++) { // /*if (m_LaserClients[i]->GetConfig()->m_Enable)*/m_LaserClients[i]->Startup(); //} //if (m_SimpleSupplyClient) { // /*if (m_SimpleSupplyClient->GetConfig()->m_Enable)*/m_SimpleSupplyClient->Startup(); //} //if (m_ScannerPowerClient) { // /*if (m_ScannerPowerClient->GetConfig()->m_Enable)*/m_ScannerPowerClient->Startup(); //} //if (m_PowerMeterClient){ // /*if (m_PowerMeterClient->GetConfig()->m_Enable)*/m_PowerMeterClient->Startup(); //} }