From f2ec2ff2640e8f02507e6fa44cd1ba1487a303ea Mon Sep 17 00:00:00 2001
From: LAPTOP-SNT8I5JK\Boounion <Chenluhua@qq.com>
Date: 星期五, 21 二月 2025 09:15:43 +0800
Subject: [PATCH] 1.定义派生于CStep的类CEqModeStep,用于处理设备模式改变的事件。
---
SourceCode/Bond/Servo/CEqModeStep.cpp | 90 ++++++++++++++++++++++
SourceCode/Bond/Servo/Servo.vcxproj | 2
SourceCode/Bond/Servo/Servo.vcxproj.filters | 2
SourceCode/Bond/Servo/CCLinkPerformance/PerformanceMelsec.h | 6 +
SourceCode/Bond/Servo/CStep.h | 9 +
SourceCode/Bond/Servo/CEquipment.cpp | 8 -
SourceCode/Bond/Servo/CMaster.cpp | 12 +++
SourceCode/Bond/Servo/CEqModeStep.h | 24 ++++++
SourceCode/Bond/Servo/CEquipment.h | 2
SourceCode/Bond/Servo/CStep.cpp | 53 +++++++-----
10 files changed, 176 insertions(+), 32 deletions(-)
diff --git a/SourceCode/Bond/Servo/CCLinkPerformance/PerformanceMelsec.h b/SourceCode/Bond/Servo/CCLinkPerformance/PerformanceMelsec.h
index 21a8281..07a4b32 100644
--- a/SourceCode/Bond/Servo/CCLinkPerformance/PerformanceMelsec.h
+++ b/SourceCode/Bond/Servo/CCLinkPerformance/PerformanceMelsec.h
@@ -203,6 +203,12 @@
// 鑷畾涔夋瀯閫犲嚱鏁帮紝瑕嗙洊榛樿鍊�
explicit StationIdentifier(const short net, const short st) : nNetNo(net), nStNo(st) {}
+ StationIdentifier()
+ {
+ nNetNo = 0;
+ nStNo = 255;
+ }
+
// 灏嗏�滅綉缁滃彿鈥濆拰鈥滅珯鐐瑰彿鈥濈粍鍚堟垚涓�涓渶缁堢紪鐮�
short StationIdentifier::toNetworkStationCode() const {
return static_cast<short>(nStNo | ((nNetNo << 8) & 0xFF00));
diff --git a/SourceCode/Bond/Servo/CEqModeStep.cpp b/SourceCode/Bond/Servo/CEqModeStep.cpp
new file mode 100644
index 0000000..e869c74
--- /dev/null
+++ b/SourceCode/Bond/Servo/CEqModeStep.cpp
@@ -0,0 +1,90 @@
+#include "stdafx.h"
+#include "CEqModeStep.h"
+#include "Log.h"
+
+
+namespace SERVO {
+ CEqModeStep::CEqModeStep() : CStep()
+ {
+ m_nModeDev = 0;
+ m_nMode = 0;
+ }
+
+ CEqModeStep::~CEqModeStep()
+ {
+
+ }
+
+ int CEqModeStep::onReadData()
+ {
+ CStep::onReadData();
+
+ DWordContainer dc;
+ m_pCclink->ReadDWordData(m_station, DeviceType::W, m_nModeDev, 1, dc);
+ m_nMode = dc.at(0);
+ std::string strTemp;
+ LOGI("<CEqModeStep> Equipment Mode Changed<%s>\n",
+ getModeDescription(strTemp).c_str());
+
+ return 0;
+ }
+
+ int CEqModeStep::onComplete()
+ {
+ CStep::onComplete();
+ LOGI("<CEqModeStep> onComplete.");
+
+ return 0;
+ }
+
+ int CEqModeStep::onTimeout()
+ {
+ CStep::onTimeout();
+ LOGI("<CEqModeStep> onTimeout.");
+
+ return 0;
+ }
+
+ void CEqModeStep::setModeDev(int nDev)
+ {
+ m_nModeDev = nDev;
+ }
+
+ /*
+ 0: No Equipment Mode exist
+ 1: Normal Mode
+ 2 : Recovery(Force Clean Out) Mode
+ 3 : Skip Mode
+ 4 : Cold Run Mode
+ 5 : ETC."
+ */
+
+ std::string& CEqModeStep::getModeDescription(std::string& strDescription)
+ {
+ switch (m_nMode) {
+ case 0:
+ strDescription = _T("No Equipment Mode exist");
+ break;
+ case 1:
+ strDescription = _T("Normal Mode");
+ break;
+ case 2:
+ strDescription = _T("Recovery(Force Clean Out) Mode");
+ break;
+ case 3:
+ strDescription = _T("Skip Mode");
+ break;
+ case 4:
+ strDescription = _T("Cold Run Mode");
+ break;
+ case 5:
+ strDescription = _T("ETC.");
+ break;
+ default:
+ strDescription = _T("");
+ break;
+ }
+
+ return strDescription;
+ }
+}
diff --git a/SourceCode/Bond/Servo/CEqModeStep.h b/SourceCode/Bond/Servo/CEqModeStep.h
new file mode 100644
index 0000000..c91c5fa
--- /dev/null
+++ b/SourceCode/Bond/Servo/CEqModeStep.h
@@ -0,0 +1,24 @@
+#pragma once
+#include "CStep.h"
+
+
+namespace SERVO {
+ class CEqModeStep : public CStep
+ {
+ public:
+ CEqModeStep();
+ ~CEqModeStep();
+
+ public:
+ virtual int onReadData();
+ virtual int onComplete();
+ virtual int onTimeout();
+ void setModeDev(int nDev);
+ std::string& getModeDescription(std::string& strDescription);
+
+ private:
+ int m_nModeDev;
+ int m_nMode;
+ };
+}
+
diff --git a/SourceCode/Bond/Servo/CEquipment.cpp b/SourceCode/Bond/Servo/CEquipment.cpp
index fcc8002..b435ca9 100644
--- a/SourceCode/Bond/Servo/CEquipment.cpp
+++ b/SourceCode/Bond/Servo/CEquipment.cpp
@@ -67,12 +67,8 @@
void CEquipment::init()
{
- CStep* pStep = new CStep();
- if (addStep(0x360, pStep) == 0) {
- pStep->init();
- }
- else {
- delete pStep;
+ for (auto item : m_mapStep) {
+ item.second->init();
}
}
diff --git a/SourceCode/Bond/Servo/CEquipment.h b/SourceCode/Bond/Servo/CEquipment.h
index 731fcf9..a19fcca 100644
--- a/SourceCode/Bond/Servo/CEquipment.h
+++ b/SourceCode/Bond/Servo/CEquipment.h
@@ -1,7 +1,7 @@
#pragma once
#include "Log.h"
#include "CCLinkIEControl.h"
-#include "CStep.h"
+#include "CEqModeStep.h"
#include <map>
diff --git a/SourceCode/Bond/Servo/CMaster.cpp b/SourceCode/Bond/Servo/CMaster.cpp
index 2bbfe86..70cb1b8 100644
--- a/SourceCode/Bond/Servo/CMaster.cpp
+++ b/SourceCode/Bond/Servo/CMaster.cpp
@@ -71,6 +71,18 @@
pEquipment->setStation(0, 255);
addEquipment(pEquipment);
+
+ // 添加 step
+ {
+ CEqModeStep* pStep = new CEqModeStep();
+ pStep->setWriteSignalDev(0x30);
+ pStep->setModeDev(0x4a8c);
+ if (pEquipment->addStep(0x360, pStep) != 0) {
+ delete pStep;
+ }
+ }
+
+
pEquipment->init();
LOGE("已添加“EFEM(ROBOT)”.");
}
diff --git a/SourceCode/Bond/Servo/CStep.cpp b/SourceCode/Bond/Servo/CStep.cpp
index 3873ddf..74e072c 100644
--- a/SourceCode/Bond/Servo/CStep.cpp
+++ b/SourceCode/Bond/Servo/CStep.cpp
@@ -7,8 +7,8 @@
unsigned __stdcall StepWorkThreadFunction(LPVOID lpParam)
{
- CStep* pScale = (CStep*)lpParam;
- return pScale->WorkingProc();
+ CStep* pStep = (CStep*)lpParam;
+ return pStep->WorkingProc();
}
CStep::CStep()
@@ -20,6 +20,7 @@
m_hSignalOff = ::CreateEvent(NULL, TRUE, FALSE, NULL);
m_nCurStep = 0;
m_pCclink = nullptr;
+ m_nWriteSignalDev = 0;
InitializeCriticalSection(&m_criticalSection);
}
@@ -39,6 +40,11 @@
void CStep::setCcLink(CCCLinkIEControl* pCcLink)
{
m_pCclink = pCcLink;
+ }
+
+ void CStep::setWriteSignalDev(int dev)
+ {
+ m_nWriteSignalDev = dev;
}
void CStep::init()
@@ -86,23 +92,20 @@
// 1.读取数据
nextStep();
ASSERT(m_pCclink);
- StationIdentifier station(0, 255);
- DWordContainer dc;
- m_pCclink->ReadDWordData(station, DeviceType::W, 0x4a8c, 1, dc);
- int nState = dc.at(0);
- TRACE(">> nState:%d\n", nState);
+ onReadData();
+
// 2.给对方写ON
nextStep();
- m_pCclink->SetBitDevice(station, DeviceType::B, 0x30);
+ m_pCclink->SetBitDevice(m_station, DeviceType::B, m_nWriteSignalDev);
// 3.等待对方OFF
nextStep();
int nStep3Ret = ::WaitForSingleObject(m_hSignalOff, TIMEOUT * 1000);
if (nStep3Ret == WAIT_TIMEOUT) {
- timeout();
- m_pCclink->ResetBitDevice(station, DeviceType::B, 0x30);
+ m_pCclink->ResetBitDevice(m_station, DeviceType::B, m_nWriteSignalDev);
+ onTimeout();
goto RESET;
}
ResetEvent(m_hSignalOff);
@@ -110,18 +113,12 @@
// 4.给对方写OFF
nextStep();
- m_pCclink->ResetBitDevice(station, DeviceType::B, 0x30);
- TRACE("m_nCurStep:%d\n", m_nCurStep);
-
-
- // 5.对接CIM等
- nextStep();
- TRACE("m_nCurStep:%d\n", m_nCurStep);
+ m_pCclink->ResetBitDevice(m_station, DeviceType::B, m_nWriteSignalDev);
// 6.完成
nextStep();
- TRACE("m_nCurStep:%d\n", m_nCurStep);
+ onComplete();
}
}
@@ -147,6 +144,21 @@
Unlock();
}
+ int CStep::onReadData()
+ {
+ return 0;
+ }
+
+ int CStep::onComplete()
+ {
+ return 0;
+ }
+
+ int CStep::onTimeout()
+ {
+ return 0;
+ }
+
void CStep::resetStep()
{
Lock();
@@ -159,11 +171,6 @@
Lock();
m_nCurStep++;
Unlock();
- }
-
- void CStep::timeout()
- {
- TRACE(">>>>>>>>>>>>>>>> timeout:%d\n", m_nCurStep);
}
}
diff --git a/SourceCode/Bond/Servo/CStep.h b/SourceCode/Bond/Servo/CStep.h
index ec87aa0..052d4e4 100644
--- a/SourceCode/Bond/Servo/CStep.h
+++ b/SourceCode/Bond/Servo/CStep.h
@@ -12,18 +12,22 @@
public:
unsigned WorkingProc();
void setCcLink(CCCLinkIEControl* pCcLink);
+ virtual void setWriteSignalDev(int dev);
virtual void init();
virtual void CStep::term();
virtual void onSignal(BOOL bSignal);
+ virtual int onReadData();
+ virtual int onComplete();
+ virtual int onTimeout();
protected:
inline void Lock() { EnterCriticalSection(&m_criticalSection); }
inline void Unlock() { LeaveCriticalSection(&m_criticalSection); }
inline void nextStep();
inline void resetStep();
- void timeout();
- private:
+ protected:
+ StationIdentifier m_station;
CCCLinkIEControl* m_pCclink;
CRITICAL_SECTION m_criticalSection;
std::string strName;
@@ -33,6 +37,7 @@
HANDLE m_hSignalOn;
HANDLE m_hSignalOff;
int m_nCurStep;
+ int m_nWriteSignalDev; // 对方BIT地址
};
}
diff --git a/SourceCode/Bond/Servo/Servo.vcxproj b/SourceCode/Bond/Servo/Servo.vcxproj
index 1668acb..3e215be 100644
--- a/SourceCode/Bond/Servo/Servo.vcxproj
+++ b/SourceCode/Bond/Servo/Servo.vcxproj
@@ -200,6 +200,7 @@
<ClInclude Include="CBonder.h" />
<ClInclude Include="CCLinkPerformance\CCLinkIEControl.h" />
<ClInclude Include="CCLinkPerformance\PerformanceMelsec.h" />
+ <ClInclude Include="CEqModeStep.h" />
<ClInclude Include="CStep.h" />
<ClInclude Include="DevicePropertyDlg.h" />
<ClInclude Include="CEFEM.h" />
@@ -231,6 +232,7 @@
<ClCompile Include="CBonder.cpp" />
<ClCompile Include="CCLinkPerformance\CCLinkIEControl.cpp" />
<ClCompile Include="CCLinkPerformance\PerformanceMelsec.cpp" />
+ <ClCompile Include="CEqModeStep.cpp" />
<ClCompile Include="CStep.cpp" />
<ClCompile Include="DevicePropertyDlg.cpp" />
<ClCompile Include="CEFEM.cpp" />
diff --git a/SourceCode/Bond/Servo/Servo.vcxproj.filters b/SourceCode/Bond/Servo/Servo.vcxproj.filters
index b6912df..1580241 100644
--- a/SourceCode/Bond/Servo/Servo.vcxproj.filters
+++ b/SourceCode/Bond/Servo/Servo.vcxproj.filters
@@ -37,6 +37,7 @@
<ClCompile Include="ToolUnits.cpp" />
<ClCompile Include="DevicePropertyDlg.cpp" />
<ClCompile Include="CStep.cpp" />
+ <ClCompile Include="CEqModeStep.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="AlarmManager.h" />
@@ -72,6 +73,7 @@
<ClInclude Include="ToolUnits.h" />
<ClInclude Include="DevicePropertyDlg.h" />
<ClInclude Include="CStep.h" />
+ <ClInclude Include="CEqModeStep.h" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="Servo.rc" />
--
Gitblit v1.9.3