From ce7f9f6df6e34cee1cbb9e776a814bc7548e8bd1 Mon Sep 17 00:00:00 2001
From: LAPTOP-SNT8I5JK\Boounion <Chenluhua@qq.com>
Date: 星期三, 28 五月 2025 17:47:55 +0800
Subject: [PATCH] 1.补允上次提交;
---
SourceCode/Bond/Servo/CMaster.cpp | 799 +++++++++++++++++++++++++++++++++++++++++++++++++-------
1 files changed, 689 insertions(+), 110 deletions(-)
diff --git a/SourceCode/Bond/Servo/CMaster.cpp b/SourceCode/Bond/Servo/CMaster.cpp
index f3a0c07..3bd5d26 100644
--- a/SourceCode/Bond/Servo/CMaster.cpp
+++ b/SourceCode/Bond/Servo/CMaster.cpp
@@ -2,8 +2,28 @@
#include "Common.h"
#include "CMaster.h"
+
namespace SERVO {
CMaster* g_pMaster = NULL;
+
+ unsigned __stdcall DispatchThreadFunction(LPVOID lpParam)
+ {
+ if (g_pMaster != NULL) {
+ return g_pMaster->DispatchProc();
+ }
+
+ return 0;
+ }
+
+ unsigned __stdcall ReadBitsThreadFunction(LPVOID lpParam)
+ {
+ if (g_pMaster != NULL) {
+ return g_pMaster->ReadBitsProc();
+ }
+
+ return 0;
+ }
+
void CALLBACK MasterTimerProc(HWND hWnd, UINT nMsg, UINT nTimerid, DWORD dwTime)
{
if (g_pMaster != NULL) {
@@ -13,36 +33,72 @@
CMaster::CMaster()
{
- m_listener = {nullptr, nullptr, nullptr};
+ m_listener = {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr};
+ m_bDataModify = FALSE;
+ m_hEventReadBitsThreadExit[0] = ::CreateEvent(NULL, TRUE, FALSE, NULL);
+ m_hEventReadBitsThreadExit[1] = ::CreateEvent(NULL, TRUE, FALSE, NULL);
+ m_hReadBitsThreadHandle = nullptr;
+ m_nReadBitsThreadAddr = 0;
+ m_hDispatchEvent = ::CreateEvent(NULL, TRUE, FALSE, NULL);
+ m_hEventDispatchThreadExit[0] = ::CreateEvent(NULL, TRUE, FALSE, NULL);
+ m_hEventDispatchThreadExit[1] = ::CreateEvent(NULL, TRUE, FALSE, NULL);
+ m_hDispatchThreadHandle = nullptr;
+ m_nDispatchThreadAddr = 0;
+ m_ullStartTime = 0;
+ m_ullRunTime = 0;
+ m_state = MASTERSTATE::READY;
+ m_pActiveRobotTask = nullptr;
+ InitializeCriticalSection(&m_criticalSection);
}
CMaster::~CMaster()
{
- for (auto item : m_listEquipment) {
- delete item;
+ if (m_hEventReadBitsThreadExit[0] != nullptr) {
+ ::CloseHandle(m_hEventReadBitsThreadExit[0]);
+ m_hEventReadBitsThreadExit[0] = nullptr;
}
- m_listEquipment.clear();
+
+ if (m_hEventReadBitsThreadExit[1] != nullptr) {
+ ::CloseHandle(m_hEventReadBitsThreadExit[1]);
+ m_hEventReadBitsThreadExit[1] = nullptr;
+ }
+
+ if (m_hDispatchEvent != nullptr) {
+ ::CloseHandle(m_hDispatchEvent);
+ m_hDispatchEvent = nullptr;
+ }
+
+ if (m_hEventDispatchThreadExit[0] != nullptr) {
+ ::CloseHandle(m_hEventDispatchThreadExit[0]);
+ m_hEventDispatchThreadExit[0] = nullptr;
+ }
+
+ if (m_hEventDispatchThreadExit[1] != nullptr) {
+ ::CloseHandle(m_hEventDispatchThreadExit[1]);
+ m_hEventDispatchThreadExit[1] = nullptr;
+ }
+
+ DeleteCriticalSection(&m_criticalSection);
}
void CMaster::setListener(MasterListener listener)
{
+ m_listener.onMasterStateChanged = listener.onMasterStateChanged;
m_listener.onEqAlive = listener.onEqAlive;
m_listener.onEqCimStateChanged = listener.onEqCimStateChanged;
- m_listener.onEqStepEvent = listener.onEqStepEvent;
+ m_listener.onEqAlarm = listener.onEqAlarm;
+ m_listener.onEqVcrEventReport = listener.onEqVcrEventReport;
+ m_listener.onEqDataChanged = listener.onEqDataChanged;
+ }
+
+ CRobotTask* CMaster::getActiveRobotTask()
+ {
+ return m_pActiveRobotTask;
}
int CMaster::init()
{
LOGI("<Master>正在初始化...");
-
-
- StepListener listener;
- listener.onEvent = [&](void* pStep, int code, void* pData) -> void {
- TRACE("<CEquipment>onEvent<%d, 0x%x>.\n", code, pData);
- if (m_listener.onEqStepEvent != nullptr) {
- m_listener.onEqStepEvent(this, (CStep*)pStep, code, pData);
- }
- };
// cclink
@@ -72,23 +128,87 @@
// 初始化添加各子设备
- addEFEM(listener);
+ CLoadPort* pPort1, * pPort2, * pPort3, * pPort4;
+ CBonder* pBonder1, * pBonder2;
+ CEFEM* pEfem;
+ CArm* pArm;
+ CArmTray* pArmTray1, * pArmTray2;
+ CFliper* pFliper;
+ CVacuumBake* pVacuumBake;
+ CAligner* pAligner;
+ CBakeCooling* pBakeCooling;
+ CMeasurement* pMeasurement;
- /*
- {
- CBonder* pBonder = new CBonder();
- pBonder->setName("Bonder 1");
- pBonder->setDescription("Bonder 1.");
- pBonder->setReadBitBlock(0x4600, 0x4bff);
- pBonder->setStation(1, 3);
- addEquipment(pBonder);
- LOGE("已添加“Bonder 1”.");
- }
- */
+ pPort1 = addLoadPort(0);
+ pPort2 = addLoadPort(1);
+ pPort3 = addLoadPort(2);
+ pPort4 = addLoadPort(3);
+ pEfem = addEFEM();
+ pArm = addArm();
+ pArmTray1 = addArmTray(0);
+ pArmTray2 = addArmTray(1);
+ pFliper = addFliper();
+ pVacuumBake = addVacuumBake();
+ pAligner = addAligner();
+ pBonder1 = addBonder(0);
+ pBonder2 = addBonder(1);
+ pBakeCooling = addBakeCooling();
+ pMeasurement = addMeasurement();
+
+ ASSERT(pEfem);
+ ASSERT(pFliper);
+ ASSERT(pVacuumBake);
+ ASSERT(pAligner);
+ ASSERT(pBonder1);
+ ASSERT(pBonder2);
+ ASSERT(pBakeCooling);
+ ASSERT(pMeasurement);
+
+ pEfem->setPort(0, pPort1);
+ pEfem->setPort(1, pPort1);
+ pEfem->setPort(2, pPort1);
+ pEfem->setPort(3, pPort1);
+ pEfem->setFliper(pFliper);
+ pEfem->setAligner(pAligner);
+ pEfem->setArmTray(0, pArmTray1);
+ pEfem->setArmTray(1, pArmTray2);
+ pPort1->setArm(pArm);
+ pPort2->setArm(pArm);
+ pPort3->setArm(pArm);
+ pPort4->setArm(pArm);
+ pArmTray1->setArm(pArm);
+ pArmTray2->setArm(pArm);
+ pFliper->setArm(pArm);
+ pVacuumBake->setArm(pArm);
+ pAligner->setArm(pArm);
+ pBonder1->setArm(pArm);
+ pBonder2->setArm(pArm);
+ pBakeCooling->setArm(pArm);
+ pMeasurement->setArm(pArm);
+
+ connectEquipments();
+
+
+
+
+
+ // 读缓存数据
+ readCache();
+
// 定时器
g_pMaster = this;
SetTimer(NULL, 1, 250, (TIMERPROC)MasterTimerProc);
+
+
+ // 调度线程
+ m_hDispatchThreadHandle = (HANDLE)_beginthreadex(NULL, 0, SERVO::DispatchThreadFunction, this,
+ 0, &m_nDispatchThreadAddr);
+
+
+ // 监控bit线程
+ m_hReadBitsThreadHandle = (HANDLE)_beginthreadex(NULL, 0, SERVO::ReadBitsThreadFunction, this,
+ 0, &m_nReadBitsThreadAddr);
LOGI("<Master>初始化完成.");
@@ -97,15 +217,174 @@
int CMaster::term()
{
+ SetEvent(m_hEventReadBitsThreadExit[0]);
+ SetEvent(m_hEventDispatchThreadExit[0]);
+ ::WaitForSingleObject(m_hEventReadBitsThreadExit[1], INFINITE);
+ ::WaitForSingleObject(m_hEventDispatchThreadExit[1], INFINITE);
+
LOGI("<Master>正在结束程序.");
for (auto item : m_listEquipment) {
item->term();
}
+ saveCache();
+
+
+ for (auto item : m_listEquipment) {
+ delete item;
+ }
+ m_listEquipment.clear();
+
return 0;
}
- int CMaster::addEquipment(CEquipment* pEquipment)
+ int CMaster::start()
+ {
+ if (m_state != MASTERSTATE::READY) {
+ return -1;
+ }
+
+ setState(MASTERSTATE::STARTING);
+ m_ullStartTime = GetTickCount64();
+
+ return 0;
+ }
+
+ int CMaster::stop()
+ {
+ // 运行时间为累加结果,本次停止时刷新;
+ if (m_state != MASTERSTATE::RUNNING) {
+ return -1;
+ }
+
+ m_ullRunTime += (GetTickCount64() - m_ullStartTime);
+ setState(MASTERSTATE::STOPPING);
+
+ return 0;
+ }
+
+ ULONGLONG CMaster::getRunTime()
+ {
+ if (m_state == MASTERSTATE::RUNNING)
+ return m_ullRunTime + (GetTickCount64() - m_ullStartTime);
+ else
+ return m_ullRunTime;
+ }
+
+ MASTERSTATE CMaster::getState()
+ {
+ return m_state;
+ }
+
+ unsigned CMaster::DispatchProc()
+ {
+ while (1) {
+ // 待退出信号或时间到
+ HANDLE hEvents[] = { m_hEventDispatchThreadExit[0], m_hDispatchEvent };
+ int nRet = WaitForMultipleObjects(2, hEvents, FALSE, 1000);
+ if (nRet == WAIT_OBJECT_0) {
+ break;
+ }
+
+
+ // 如果状态为STARTING,开始工作并切换到RUNNING状态
+ lock();
+ if (m_state == MASTERSTATE::STARTING) {
+ unlock();
+ Sleep(1000);
+ setState(MASTERSTATE::RUNNING);
+ continue;
+ }
+
+
+ // 处理完成当前事务后,切换到停止或就绪状态
+ else if (m_state == MASTERSTATE::STOPPING) {
+ unlock();
+ Sleep(1000);
+ setState(MASTERSTATE::READY);
+ continue;
+ }
+
+
+ // 调度逻辑处理
+ else if (m_state == MASTERSTATE::RUNNING) {
+ unlock();
+ LOGI("调度处理中...");
+ Sleep(1000);
+
+
+ // LoadPort -> Fliper(G2)
+
+
+ // LoadPort -> VacuumBake(G1)
+
+
+ // Fliper(G2) -> Aligner
+
+
+ // VacuumBake(G1) -> Aligner
+
+
+ // Aligner -> Bonder
+
+
+ // Bonder -> BakeCooling
+
+
+ // BakeCooling ->Measurement
+
+
+ // Measurement -> LoadPort
+
+
+
+
+
+ }
+ unlock();
+ }
+
+ SetEvent(m_hEventDispatchThreadExit[1]);
+
+
+ // _endthreadex(0);
+ TRACE("CMaster::DispatchProc 线程退出\n");
+ return 0;
+ }
+
+ unsigned CMaster::ReadBitsProc()
+ {
+ while (1) {
+ // 待退出信号或时间到
+ int nRet = ::WaitForSingleObject(m_hEventReadBitsThreadExit[0], 1000);
+ if (nRet == WAIT_OBJECT_0) {
+ break;
+ }
+
+ for (auto item : m_listEquipment) {
+ if (item->getID() == EQ_ID_Bonder1 ||
+ item->getID() == EQ_ID_Bonder2) {
+ const StationIdentifier& station = item->getStation();
+ MemoryBlock& block = item->getReadBitBlock();
+
+ int nRet = m_cclink.ReadData2(station, (DeviceType)block.type,
+ block.start, block.size, block.buffer);
+ if (0 == nRet) {
+ item->onReceiveLBData(block.buffer, block.size);
+ }
+ }
+ }
+ }
+
+ SetEvent(m_hEventReadBitsThreadExit[1]);
+
+
+ // _endthreadex(0);
+ TRACE("CMaster::ReadBitsProc 线程退出\n");
+ return 0;
+ }
+
+ int CMaster::addToEquipmentList(CEquipment* pEquipment)
{
EquipmentListener listener;
listener.onAlive = [&](void* pEquipment, BOOL bAlive) -> void {
@@ -120,11 +399,37 @@
m_listener.onEqCimStateChanged(this, p, bOn);
}
};
+ listener.onAlarm = [&](void* pEquipment, int state, int alarmId, int unitId, int level) -> void {
+ CEquipment* p = (CEquipment*)pEquipment;
+ if (m_listener.onEqAlarm != nullptr) {
+ m_listener.onEqAlarm(this, p, state, alarmId, unitId, level);
+ }
+ };
+ listener.onVcrEventReport = [&](void* pEquipment, void* pReport) -> void {
+ CEquipment* p = (CEquipment*)pEquipment;
+ CVcrEventReport* p2 = (CVcrEventReport*)pReport;
+ if (m_listener.onEqVcrEventReport != nullptr) {
+ m_listener.onEqVcrEventReport(this, p, p2);
+ }
+ };
+ listener.onDataChanged = [&](void* pEquipment, int code) -> void {
+ m_bDataModify = TRUE;
+ CEquipment* p = (CEquipment*)pEquipment;
+ if (m_listener.onEqDataChanged != nullptr) {
+ m_listener.onEqDataChanged(this, p, 0);
+ }
+ };
+
pEquipment->setListener(listener);
pEquipment->setCcLink(&m_cclink);
m_listEquipment.push_back(pEquipment);
return 0;
+ }
+
+ std::list<CEquipment*>& CMaster::getEquipmentList()
+ {
+ return m_listEquipment;
}
CEquipment* CMaster::getEquipment(int id)
@@ -136,93 +441,192 @@
return nullptr;
}
- int CMaster::addEFEM(StepListener& listener)
+ /*
+ * 添加LoadPort1
+ * index -- 0~3
+ */
+ CLoadPort* CMaster::addLoadPort(int index)
+ {
+ ASSERT(index == 0 || index == 1 || index == 2 || index == 3);
+
+
+ char szName[64];
+ sprintf_s(szName, 64, "LoadPort %d", index + 1);
+ CLoadPort* pEquipment = new CLoadPort();
+ pEquipment->setIndex(index);
+ pEquipment->setID(EQ_ID_LOADPORT1 + index);
+ pEquipment->setName(szName);
+ pEquipment->setDescription(szName);
+ addToEquipmentList(pEquipment);
+
+
+ pEquipment->init();
+ LOGE("已添加“%s”.", pEquipment->getName().c_str());
+
+
+ return pEquipment;
+ }
+
+ CFliper* CMaster::addFliper()
+ {
+ CFliper* pEquipment = new CFliper();
+ pEquipment->setID(EQ_ID_FLIPER);
+ pEquipment->setBaseAlarmId(BASE_ALARM_EFEM);
+ pEquipment->setName("Fliper(G2)");
+ pEquipment->setDescription("Fliper(G2).");
+ pEquipment->setReadBitBlock(0x4000, 0x45ff);
+ pEquipment->setStation(0, 255);
+ addToEquipmentList(pEquipment);
+
+
+ pEquipment->init();
+ LOGE("已添加“Fliper”.");
+ return pEquipment;
+ }
+
+ CVacuumBake* CMaster::addVacuumBake()
+ {
+ CVacuumBake* pEquipment = new CVacuumBake();
+ pEquipment->setID(EQ_ID_VACUUMBAKE);
+ pEquipment->setBaseAlarmId(BASE_ALARM_EFEM);
+ pEquipment->setName("VacuumBake(G1)");
+ pEquipment->setDescription("VacuumBake(G1).");
+ pEquipment->setReadBitBlock(0x4000, 0x45ff);
+ pEquipment->setStation(0, 255);
+ addToEquipmentList(pEquipment);
+
+
+ pEquipment->init();
+ LOGE("已添加“VacuumBake”.");
+
+ return pEquipment;
+ }
+
+ CAligner* CMaster::addAligner()
+ {
+ CAligner* pEquipment = new CAligner();
+ pEquipment->setID(EQ_ID_ALIGNER);
+ pEquipment->setBaseAlarmId(BASE_ALARM_EFEM);
+ pEquipment->setName("Aligner");
+ pEquipment->setDescription("Aligner.");
+ pEquipment->setReadBitBlock(0x4000, 0x45ff);
+ pEquipment->setStation(0, 255);
+ addToEquipmentList(pEquipment);
+
+
+ pEquipment->init();
+ LOGE("已添加“Aligner”.");
+
+ return pEquipment;
+ }
+
+ CEFEM* CMaster::addEFEM()
{
CEFEM* pEquipment = new CEFEM();
pEquipment->setID(EQ_ID_EFEM);
+ pEquipment->setBaseAlarmId(BASE_ALARM_EFEM);
pEquipment->setName("EFEM(ROBOT)");
pEquipment->setDescription("EFEM(ROBOT).");
- pEquipment->setReadBitBlock(0x4000, 0x45ff);
+ pEquipment->setReadBitBlock(0x3000, 0x3aff);
pEquipment->setStation(0, 255);
- addEquipment(pEquipment);
-
-
- // 添加 step
- {
- CEqModeStep* pStep = new CEqModeStep();
- pStep->setName("EQMode");
- pStep->setListener(listener);
- pStep->setWriteSignalDev(0x30);
- pStep->setModeDev(0x4a8c);
- if (pEquipment->addStep(0x360, pStep) != 0) {
- delete pStep;
- }
- }
- {
- CEqStatusStep* pStep = new CEqStatusStep();
- pStep->setName("EQStatus");
- pStep->setListener(listener);
- pStep->setWriteSignalDev(0x31);
- pStep->setStatusDev(0x4a68);
- if (pEquipment->addStep(0x361, pStep) != 0) {
- delete pStep;
- }
- }
- {
- CEqAlarmStep* pStep = new CEqAlarmStep();
- pStep->setName("EQAlarm1");
- pStep->setListener(listener);
- pStep->setWriteSignalDev(0x32);
- pStep->setAlarmDev(0x4c1d);
- if (pEquipment->addStep(0x362, pStep) != 0) {
- delete pStep;
- }
- }
- {
- CEqAlarmStep* pStep = new CEqAlarmStep();
- pStep->setName("EQAlarm2");
- pStep->setListener(listener);
- pStep->setWriteSignalDev(0x33);
- pStep->setAlarmDev(0x4c4a);
- if (pEquipment->addStep(0x363, pStep) != 0) {
- delete pStep;
- }
- }
- {
- CEqAlarmStep* pStep = new CEqAlarmStep();
- pStep->setName("EQAlarm3");
- pStep->setListener(listener);
- pStep->setWriteSignalDev(0x34);
- pStep->setAlarmDev(0x4c77);
- if (pEquipment->addStep(0x364, pStep) != 0) {
- delete pStep;
- }
- }
- {
- CEqAlarmStep* pStep = new CEqAlarmStep();
- pStep->setName("EQAlarm4");
- pStep->setListener(listener);
- pStep->setWriteSignalDev(0x35);
- pStep->setAlarmDev(0x4ca4);
- if (pEquipment->addStep(0x365, pStep) != 0) {
- delete pStep;
- }
- }
- {
- CEqAlarmStep* pStep = new CEqAlarmStep();
- pStep->setName("EQAlarm5");
- pStep->setListener(listener);
- pStep->setWriteSignalDev(0x36);
- pStep->setAlarmDev(0x4cd1);
- if (pEquipment->addStep(0x366, pStep) != 0) {
- delete pStep;
- }
- }
+ addToEquipmentList(pEquipment);
pEquipment->init();
LOGE("已添加“EFEM(ROBOT)”.");
- return 0;
+
+ return pEquipment;
+ }
+
+ CArm* CMaster::addArm()
+ {
+ CArm* pEquipment = new CArm();
+ pEquipment->setID(EQ_ID_ARM);
+ pEquipment->setBaseAlarmId(BASE_ALARM_EFEM);
+ pEquipment->setName("ARM");
+ pEquipment->setDescription("ARM.");
+ addToEquipmentList(pEquipment);
+
+
+ pEquipment->init();
+ LOGE("已添加“ARM”.");
+
+ return pEquipment;
+ }
+
+ CArmTray* CMaster::addArmTray(int index)
+ {
+ CArmTray* pEquipment = new CArmTray();
+ pEquipment->setID(index == 0 ? EQ_ID_ARM_TRAY1 : EQ_ID_ARM_TRAY2);
+ pEquipment->setBaseAlarmId(BASE_ALARM_EFEM);
+ pEquipment->setName(index == 0 ? "Arm Tray1" : "Arm Tray2");
+ pEquipment->setDescription(index == 0 ? "Arm Tray1." : "Arm Tray2.");
+ addToEquipmentList(pEquipment);
+
+
+ pEquipment->init();
+ LOGE("已添加“%s”.", pEquipment->getName().c_str());
+
+ return pEquipment;
+ }
+
+ /* 添加bonder1 或 bonder2
+ * index -- 0, bonder1
+ * index -- 1, bonder2
+ */
+ CBonder* CMaster::addBonder(int index)
+ {
+ ASSERT(index == 0 || index == 1);
+ CBonder* pEquipment = new CBonder();
+ pEquipment->setID(EQ_ID_Bonder1 + index);
+ pEquipment->setName(index == 0 ? "Bonder 1" : "Bonder 2");
+ pEquipment->setDescription(index == 0 ? "Bonder 1." : "Bonder 2.");
+ pEquipment->setStation(0, 255);
+ pEquipment->setReadBitBlock(index == 0 ? 0x3b00 : 0x4600,
+ index == 0 ? 0x5600 : 0x6100);
+ pEquipment->setIndex(index);
+ addToEquipmentList(pEquipment);
+
+
+ pEquipment->init();
+ LOGE("已添加“%s”.", pEquipment->getName().c_str());
+
+
+ return pEquipment;
+ }
+
+ CBakeCooling* CMaster::addBakeCooling()
+ {
+ CBakeCooling* pEquipment = new CBakeCooling();
+ pEquipment->setID(EQ_ID_BAKE_COOLING);
+ pEquipment->setBaseAlarmId(BASE_ALARM_EFEM);
+ pEquipment->setName("BakeCooling");
+ pEquipment->setDescription("BakeCooling.");
+ pEquipment->setReadBitBlock(0x4000, 0x45ff);
+ pEquipment->setStation(0, 255);
+ addToEquipmentList(pEquipment);
+
+ pEquipment->init();
+ LOGE("已添加“Aligner”.");
+
+ return pEquipment;
+ }
+
+ CMeasurement* CMaster::addMeasurement()
+ {
+ CMeasurement* pEquipment = new CMeasurement();
+ pEquipment->setID(EQ_ID_MEASUREMENT);
+ pEquipment->setBaseAlarmId(BASE_ALARM_EFEM);
+ pEquipment->setName("Measurement");
+ pEquipment->setDescription("Measurement.");
+ pEquipment->setReadBitBlock(0x6700, 0x6e00);
+ pEquipment->setStation(0, 255);
+ addToEquipmentList(pEquipment);
+
+ pEquipment->init();
+ LOGE("已添加“Measurement”.");
+
+ return pEquipment;
}
void CMaster::onTimer(UINT nTimerid)
@@ -235,18 +639,193 @@
// 按一定频率扫描LB数据
static int i = 0;
i++;
+ /*
if (i % (4 * 1) == 0) {
for (auto item : m_listEquipment) {
- const StationIdentifier& station = item->getStation();
- MemoryBlock& block = item->getReadBitBlock();
+ if (item->getID() == EQ_ID_Bonder1) {
+ const StationIdentifier& station = item->getStation();
+ MemoryBlock& block = item->getReadBitBlock();
- int nRet = m_cclink.ReadData2(station, (DeviceType)block.type,
- block.start, block.size, block.buffer);
- if (0 == nRet) {
- item->onReceiveLBData(block.buffer, block.size);
+ int nRet = m_cclink.ReadData2(station, (DeviceType)block.type,
+ block.start, block.size, block.buffer);
+ if (0 == nRet) {
+ item->onReceiveLBData(block.buffer, block.size);
+ }
}
}
}
+ */
+
+
+ // 自动保存缓存
+ if (i % (4 * 2) == 0) {
+ if (m_bDataModify) {
+ saveCacheAndBackups();
+ m_bDataModify = FALSE;
+ }
+ }
+
+ }
+
+ void CMaster::connectEquipments()
+ {
+ int nRet;
+ CLoadPort* pLoadPort1 = (CLoadPort*)getEquipment(EQ_ID_LOADPORT1);
+ CLoadPort* pLoadPort2 = (CLoadPort*)getEquipment(EQ_ID_LOADPORT2);
+ CLoadPort* pLoadPort3 = (CLoadPort*)getEquipment(EQ_ID_LOADPORT3);
+ CLoadPort* pLoadPort4 = (CLoadPort*)getEquipment(EQ_ID_LOADPORT4);
+ CFliper* pFliper = (CFliper*)getEquipment(EQ_ID_FLIPER);
+ CVacuumBake* pVacuumBake = (CVacuumBake*)getEquipment(EQ_ID_VACUUMBAKE);
+ CAligner* pAligner = (CAligner*)getEquipment(EQ_ID_ALIGNER);
+ CBonder* pBonder1 = (CBonder*)getEquipment(EQ_ID_Bonder1);
+ CBonder* pBonder2 = (CBonder*)getEquipment(EQ_ID_Bonder2);
+ CBakeCooling* pBakeCooling = (CBakeCooling*)getEquipment(EQ_ID_BAKE_COOLING);
+ CMeasurement* pMeasurement = (CMeasurement*)getEquipment(EQ_ID_MEASUREMENT);
+
+ nRet = pLoadPort1->getPin("Out1")->connectPin(pFliper->getPin("In1"));
+ if (nRet < 0) {
+ LOGE("连接LoadPort1-Fliper失败");
+ }
+ nRet = pLoadPort2->getPin("Out1")->connectPin(pFliper->getPin("In2"));
+ if (nRet < 0) {
+ LOGE("连接LoadPort1-Fliper失败");
+ }
+
+ nRet = pLoadPort1->getPin("Out2")->connectPin(pVacuumBake->getPin("In1"));
+ if (nRet < 0) {
+ LOGE("连接LoadPort1-VacuumBake失败");
+ }
+ nRet = pLoadPort2->getPin("Out2")->connectPin(pVacuumBake->getPin("In2"));
+ if (nRet < 0) {
+ LOGE("连接LoadPort1-VacuumBake失败");
+ }
+
+ nRet = pFliper->getPin("Out")->connectPin(pAligner->getPin("In1"));
+ if (nRet < 0) {
+ LOGE("连接Fliper-Aligner失败");
+ }
+
+ nRet = pVacuumBake->getPin("Out")->connectPin(pAligner->getPin("In2"));
+ if (nRet < 0) {
+ LOGE("连接VacuumBake-Aligner失败");
+ }
+
+ nRet = pAligner->getPin("Out1")->connectPin(pBonder1->getPin("In"));
+ if (nRet < 0) {
+ LOGE("连接Aligner-Bondere1失败");
+ }
+
+ nRet = pAligner->getPin("Out2")->connectPin(pBonder2->getPin("In"));
+ if (nRet < 0) {
+ LOGE("连接Aligner-Bondere2失败");
+ }
+
+ nRet = pBonder1->getPin("Out")->connectPin(pBakeCooling->getPin("In1"));
+ if (nRet < 0) {
+ LOGE("连接Bonder1-BakeCooling失败");
+ }
+
+ nRet = pBonder2->getPin("Out")->connectPin(pBakeCooling->getPin("In2"));
+ if (nRet < 0) {
+ LOGE("连接Bonder2-BakeCooling失败");
+ }
+
+ nRet = pBakeCooling->getPin("Out")->connectPin(pMeasurement->getPin("In"));
+ if (nRet < 0) {
+ LOGE("连接BakeCooling-LoadPort3失败");
+ }
+
+ nRet = pMeasurement->getPin("Out1")->connectPin(pLoadPort3->getPin("In"));
+ if (nRet < 0) {
+ LOGE("连接BakeCooling-LoadPort3失败");
+ }
+
+ nRet = pMeasurement->getPin("Out2")->connectPin(pLoadPort4->getPin("In"));
+ if (nRet < 0) {
+ LOGE("连接BakeCooling-LoadPort4失败");
+ }
+ }
+
+ int CMaster::saveCache()
+ {
+ CFile file;
+ if (!file.Open(m_strFilepath.c_str(), CFile::modeCreate | CFile::modeWrite)) {
+ return -1;
+ }
+
+ CArchive ar(&file, CArchive::store);
+ serialize(ar);
+ ar.Close();
+ file.Close();
+
+ return 0;
+ }
+
+ int CMaster::saveCacheAndBackups()
+ {
+ saveCache();
+
+
+ // 创建备份目录
+ CString strNewFile;
+ CString strFileDir = m_strFilepath.c_str();
+ int index = strFileDir.ReverseFind('\\');
+ ASSERT(index > 0);
+ strFileDir = strFileDir.Left(index);
+ strFileDir = strFileDir + _T("Backups");
+ ::CreateDirectory(strFileDir, nullptr);
+
+ CTime time = CTime::GetCurrentTime();
+ strNewFile.Format(_T("%s//Master_%d_%02d_%02d_%02d_%02d_%02d.dat"),
+ (LPTSTR)(LPCTSTR)strFileDir,
+ time.GetYear(), time.GetMonth(), time.GetDay(),
+ time.GetHour(), time.GetMinute(), time.GetSecond());
+ ::CopyFile(m_strFilepath.c_str(), strNewFile, FALSE);
+
+ return 0;
+ }
+
+ void CMaster::setCacheFilepath(const char* pszFilepath)
+ {
+ m_strFilepath = pszFilepath;
+ }
+
+ int CMaster::readCache()
+ {
+ try {
+ CFile file;
+ if (!file.Open(m_strFilepath.c_str(), CFile::modeRead)) {
+ return -1;
+ }
+
+ CArchive ar(&file, CArchive::load);
+ serialize(ar);
+ ar.Close();
+ file.Close();
+ }
+ catch (CFileException* e) {
+ TCHAR szErr[512];
+ e->GetErrorMessage(szErr, 512);
+ AfxMessageBox(szErr);
+ e->Delete();
+ }
+
+ return 0;
+ }
+
+ void CMaster::serialize(CArchive& ar)
+ {
+ for (auto item : m_listEquipment) {
+ item->serialize(ar);
+ }
+ }
+
+ void CMaster::setState(MASTERSTATE state)
+ {
+ m_state = state;
+ if (m_listener.onMasterStateChanged != nullptr) {
+ m_listener.onMasterStateChanged(this, m_state);
+ }
}
}
--
Gitblit v1.9.3