243 lines
9.6 KiB
C++
Raw Normal View History

2024-04-18 11:59:51 +08:00
#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();
2024-05-06 10:49:15 +08:00
ExtCfg extCfg;
m_ExtCfg->GetCfg(extCfg);
m_LaserChillerClient = new ChillerClient(/*(*communicationCfg)["LASER_CHILLER"]*/nullptr, &extCfg.m_LaserChillerType);
2024-04-18 11:59:51 +08:00
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"]*/);
2024-05-06 10:49:15 +08:00
////map<string, CommunicationCfg*>* communicationCfg = ConfigManager::Instance()->GetCommunicationCfg();
2024-04-18 11:59:51 +08:00
//if (communicationCfg->find("PLATE_TEMP") != communicationCfg->end()) {
// m_TempCtrlClient = new TempCtrlClient((*communicationCfg)["PLATE_TEMP"]);
// m_TempCtrlClient->Init();
2024-05-06 10:49:15 +08:00
// ConfigManager::Instance()->AddComRefCfg(m_TempCtrlClient->GetConfig(), m_TempCtrlClient); //添加控制启停的
2024-04-18 11:59:51 +08:00
//}
//if (communicationCfg->find("OXYGEN") != communicationCfg->end()) {
// m_OxygenClient= new OxygenClient((*communicationCfg)["OXYGEN"]);
// m_OxygenClient->Init();
2024-05-06 10:49:15 +08:00
// ConfigManager::Instance()->AddComRefCfg(m_OxygenClient->GetConfig(), m_OxygenClient);
2024-04-18 11:59:51 +08:00
//}
//if (communicationCfg->find("LASER_CHILLER") != communicationCfg->end()) {
// m_LaserChillerClient = new ChillerClient((*communicationCfg)["LASER_CHILLER"],&m_ExtCfg->m_LaserChillerType);
// m_LaserChillerClient->Init();
2024-05-06 10:49:15 +08:00
// ConfigManager::Instance()->AddComRefCfg(m_LaserChillerClient->GetConfig(), m_LaserChillerClient);
2024-04-18 11:59:51 +08:00
//}
///*if (communicationCfg->find("PURIFIER_CHILLER") != communicationCfg->end()) {
// m_PurifierChillerClient = new ChillerClient((*communicationCfg)["PURIFIER_CHILLER"],&m_ExtCfg->m_PurifierChillerType);
// m_PurifierChillerClient->Init();
2024-05-06 10:49:15 +08:00
// ConfigManager::Instance()->AddComRefCfg(m_PurifierChillerClient->GetConfig(), m_PurifierChillerClient);
2024-04-18 11:59:51 +08:00
//}*/
//if (communicationCfg->find("UPS") != communicationCfg->end()) {
// m_UPSClient = new UPSClient((*communicationCfg)["UPS"]);
// m_UPSClient->Init();
2024-05-06 10:49:15 +08:00
// ConfigManager::Instance()->AddComRefCfg(m_UPSClient->GetConfig(), m_UPSClient);
2024-04-18 11:59:51 +08:00
//}
//if (communicationCfg->find("LASER1") != communicationCfg->end())
//{
// IPGLaserClientV1* client = new IPGLaserClientV1((*communicationCfg)["LASER1"], m_AlarmCfgWrapper->m_Laser1ComAlarm);
// m_LaserClients.push_back(client);
// client->Init();
2024-05-06 10:49:15 +08:00
// ConfigManager::Instance()->AddComRefCfg(client->GetConfig(), client);
2024-04-18 11:59:51 +08:00
//}
//if (communicationCfg->find("LASER2") != communicationCfg->end())
//{
// IPGLaserClientV1* client = new IPGLaserClientV1((*communicationCfg)["LASER2"], m_AlarmCfgWrapper->m_Laser2ComAlarm);
// m_LaserClients.push_back(client);
// client->Init();
2024-05-06 10:49:15 +08:00
// ConfigManager::Instance()->AddComRefCfg(client->GetConfig(), client);
2024-04-18 11:59:51 +08:00
//}
//if (communicationCfg->find("LASER3") != communicationCfg->end())
//{
// IPGLaserClientV1* client = new IPGLaserClientV1((*communicationCfg)["LASER3"], m_AlarmCfgWrapper->m_Laser3ComAlarm);
// m_LaserClients.push_back(client);
// client->Init();
2024-05-06 10:49:15 +08:00
// ConfigManager::Instance()->AddComRefCfg(client->GetConfig(), client);
2024-04-18 11:59:51 +08:00
//}
//if (communicationCfg->find("LASER4") != communicationCfg->end())
//{
// IPGLaserClientV1* client = new IPGLaserClientV1((*communicationCfg)["LASER4"], m_AlarmCfgWrapper->m_Laser4ComAlarm);
// m_LaserClients.push_back(client);
// client->Init();
2024-05-06 10:49:15 +08:00
// ConfigManager::Instance()->AddComRefCfg(client->GetConfig(), client);
2024-04-18 11:59:51 +08:00
//}
//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();
2024-05-06 10:49:15 +08:00
// ConfigManager::Instance()->AddComRefCfg(m_SimpleSupplyClient->GetConfig(), m_SimpleSupplyClient);
2024-04-18 11:59:51 +08:00
//}
///*if (communicationCfg->find("WEIGHT_CAR") != communicationCfg->end()) {
// m_PowderCarClient = new PowderCarClient((*communicationCfg)["WEIGHT_CAR"]);
// m_PowderCarClient->Init();
2024-05-06 10:49:15 +08:00
// ConfigManager::Instance()->AddComRefCfg(m_PowderCarClient->GetConfig(), m_PowderCarClient);
2024-04-18 11:59:51 +08:00
//}*/
//if (communicationCfg->find("POWER_METER") != communicationCfg->end()) {
// m_PowerMeterClient = new PowerMeterClient((*communicationCfg)["POWER_METER"]);
// m_PowerMeterClient->Init();
2024-05-06 10:49:15 +08:00
// ConfigManager::Instance()->AddComRefCfg(m_PowerMeterClient->GetConfig(), m_PowerMeterClient);
2024-04-18 11:59:51 +08:00
//}
//if (communicationCfg->find("SCANNER_POWER") != communicationCfg->end()) {
// m_ScannerPowerClient = new ScannerPowerClient((*communicationCfg)["SCANNER_POWER"]);
// //m_ScannerPowerClient->Init();
2024-05-06 10:49:15 +08:00
// ConfigManager::Instance()->AddComRefCfg(m_ScannerPowerClient->GetConfig(), m_ScannerPowerClient);
2024-04-18 11:59:51 +08:00
//}
}
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();
//}
}