From 1823e5c63bac2246d066eb74318230952484c58a Mon Sep 17 00:00:00 2001
From: LAPTOP-SNT8I5JK\Boounion <Chenluhua@qq.com>
Date: 星期三, 19 三月 2025 16:41:07 +0800
Subject: [PATCH] 1.Pin的连接和发送数据。
---
SourceCode/Bond/Servo/CEquipment.cpp | 59 +++++++++++++++++++
SourceCode/Bond/Servo/CLoadPort.h | 4 +
SourceCode/Bond/Servo/CMaster.cpp | 23 +++++++
SourceCode/Bond/Servo/CMaster.h | 2
SourceCode/Bond/Servo/CEquipment.h | 7 ++
SourceCode/Bond/Servo/CLoadPort.cpp | 25 ++++++++
SourceCode/Bond/Servo/CBonder.h | 1
SourceCode/Bond/Servo/CBonder.cpp | 21 +++++++
SourceCode/Bond/Servo/Common.h | 4 +
9 files changed, 145 insertions(+), 1 deletions(-)
diff --git a/SourceCode/Bond/Servo/CBonder.cpp b/SourceCode/Bond/Servo/CBonder.cpp
index 03774a9..e67978f 100644
--- a/SourceCode/Bond/Servo/CBonder.cpp
+++ b/SourceCode/Bond/Servo/CBonder.cpp
@@ -34,6 +34,8 @@
{
// 加入Pin初始化代码
LOGI("<CBonder>initPins");
+ addPin(SERVO::PinType::INPUT, _T("In"));
+ addPin(SERVO::PinType::OUTPUT, _T("Out"));
}
void CBonder::onTimer(UINT nTimerid)
@@ -45,4 +47,23 @@
{
CEquipment::serialize(ar);
}
+
+ int CBonder::recvSample(CPin* pPin, CSample* pSample)
+ {
+ ASSERT(pPin);
+
+ CPin* pFromPin = pPin->getConnectedPin();
+ ASSERT(pFromPin);
+
+ CEquipment* pFromEq = pFromPin->getEquipment();
+ ASSERT(pFromEq);
+
+
+ LOGI("<CBonder><%s-%s>收到来自<%s.%s>的Sample",
+ this->getName().c_str(), pPin->getName().c_str(),
+ pFromEq->getName().c_str(), pFromPin->getName().c_str());
+
+ delete pSample;
+ return 0;
+ }
}
diff --git a/SourceCode/Bond/Servo/CBonder.h b/SourceCode/Bond/Servo/CBonder.h
index 846e49d..98a32f0 100644
--- a/SourceCode/Bond/Servo/CBonder.h
+++ b/SourceCode/Bond/Servo/CBonder.h
@@ -17,6 +17,7 @@
virtual void initPins();
virtual void onTimer(UINT nTimerid);
virtual void serialize(CArchive& ar);
+ virtual int recvSample(CPin* pPin, CSample* pSample);
};
}
diff --git a/SourceCode/Bond/Servo/CEquipment.cpp b/SourceCode/Bond/Servo/CEquipment.cpp
index deaee05..78c64d7 100644
--- a/SourceCode/Bond/Servo/CEquipment.cpp
+++ b/SourceCode/Bond/Servo/CEquipment.cpp
@@ -27,6 +27,16 @@
}
m_mapStep.clear();
+ for (auto item : m_inputPins) {
+ delete item;
+ }
+ m_inputPins.clear();
+
+ for (auto item : m_outputPins) {
+ delete item;
+ }
+ m_outputPins.clear();
+
DeleteCriticalSection(&m_criticalSection);
}
@@ -374,6 +384,55 @@
return m_bVCREnable[index];
}
+ CPin* CEquipment::addPin(PinType type, char* pszName)
+ {
+ // 不允许名字添加重复的pin
+ CPin* pPin = getPin(pszName);
+ if (pPin != nullptr) return nullptr;
+
+
+ // 添加到Pin列表,看是输入pin或输出pin
+ if (type == PinType::INPUT) {
+ pPin = new CPin(this, type, pszName);
+ m_inputPins.push_back(pPin);
+ return pPin;
+ }
+ else if (type == PinType::OUTPUT) {
+ pPin = new CPin(this, type, pszName);
+ m_outputPins.push_back(pPin);
+ return pPin;
+ }
+
+ return nullptr;
+ }
+
+ CPin* CEquipment::getPin(char* pszName)
+ {
+ for (auto item : m_inputPins) {
+ if (item->getName().compare(pszName) == 0) {
+ return item;
+ }
+ }
+
+ for (auto item : m_outputPins) {
+ if (item->getName().compare(pszName) == 0) {
+ return item;
+ }
+ }
+
+ return nullptr;
+ }
+
+ std::vector<CPin*>& CEquipment::getInputPins()
+ {
+ return m_inputPins;
+ }
+
+ std::vector<CPin*>& CEquipment::getOutputPins()
+ {
+ return m_outputPins;
+ }
+
int CEquipment::recvSample(CPin* pPin, CSample* pSample)
{
LOGI("<CEquipment>recvSample, pin:%s", pPin->getName().c_str());
diff --git a/SourceCode/Bond/Servo/CEquipment.h b/SourceCode/Bond/Servo/CEquipment.h
index 02f9345..ced2b57 100644
--- a/SourceCode/Bond/Servo/CEquipment.h
+++ b/SourceCode/Bond/Servo/CEquipment.h
@@ -13,6 +13,7 @@
#include "CEqCimMessageClearStep.h"
#include "CEqDateTimeSetCmdStep.h"
#include "CEqVCREnableStep.h"
+#include <vector>
#include <map>
@@ -81,6 +82,10 @@
virtual void onTimer(UINT nTimerid);
virtual void serialize(CArchive& ar);
virtual void onReceiveLBData(const char* pszData, size_t size);
+ virtual CPin* addPin(PinType type, char* pszName);
+ CPin* getPin(char* pszName);
+ std::vector<CPin*>& CEquipment::getInputPins();
+ std::vector<CPin*>& CEquipment::getOutputPins();
virtual int recvSample(CPin* pPin, CSample* pSample);
@@ -112,6 +117,8 @@
StationIdentifier m_station;
MemoryBlock m_blockReadBit;
MemoryBlock m_blockWriteBit;
+ std::vector<CPin*> m_inputPins;
+ std::vector<CPin*> m_outputPins;
// 以下为从CC-Link读取到的Bit标志位
private:
diff --git a/SourceCode/Bond/Servo/CLoadPort.cpp b/SourceCode/Bond/Servo/CLoadPort.cpp
index bda1be4..6386eec 100644
--- a/SourceCode/Bond/Servo/CLoadPort.cpp
+++ b/SourceCode/Bond/Servo/CLoadPort.cpp
@@ -34,6 +34,8 @@
{
// 加入Pin初始化代码
LOGI("<CLoadPort>initPins");
+ addPin(SERVO::PinType::INPUT, _T("In"));
+ addPin(SERVO::PinType::OUTPUT, _T("Out"));
}
void CLoadPort::onTimer(UINT nTimerid)
@@ -45,4 +47,27 @@
{
CEquipment::serialize(ar);
}
+
+ void CLoadPort::getAttributeVector(CAttributeVector& attrubutes)
+ {
+ __super::getAttributeVector(attrubutes);
+
+ for (auto item : m_inputPins) {
+ attrubutes.addAttribute(new CAttribute(item->getName().c_str(),
+ std::to_string((int)item->getType()).c_str(), ""));
+ }
+
+ for (auto item : m_outputPins) {
+ attrubutes.addAttribute(new CAttribute(item->getName().c_str(),
+ std::to_string((int)item->getType()).c_str(), ""));
+ }
+ }
+
+ void CLoadPort::outputPanel()
+ {
+ CPin* pOutPin = getPin("Out");
+
+ CSample* pSample = new CSample();
+ pOutPin->sendSample(pSample);
+ }
}
diff --git a/SourceCode/Bond/Servo/CLoadPort.h b/SourceCode/Bond/Servo/CLoadPort.h
index 15b2607..27ce307 100644
--- a/SourceCode/Bond/Servo/CLoadPort.h
+++ b/SourceCode/Bond/Servo/CLoadPort.h
@@ -17,6 +17,10 @@
virtual void initPins();
virtual void onTimer(UINT nTimerid);
virtual void serialize(CArchive& ar);
+ virtual void getAttributeVector(CAttributeVector& attrubutes);
+
+ public:
+ void outputPanel();
};
}
diff --git a/SourceCode/Bond/Servo/CMaster.cpp b/SourceCode/Bond/Servo/CMaster.cpp
index 8e84ca4..11c6d29 100644
--- a/SourceCode/Bond/Servo/CMaster.cpp
+++ b/SourceCode/Bond/Servo/CMaster.cpp
@@ -72,9 +72,14 @@
// 初始化添加各子设备
+ addLoadPort(0, listener);
+ addLoadPort(1, listener);
+ addLoadPort(2, listener);
+ addLoadPort(3, listener);
addEFEM(listener);
addBonder(0, listener);
addBonder(1, listener);
+ connectEquipments();
// 定时器
@@ -138,9 +143,10 @@
int CMaster::addLoadPort(int index, StepListener& listener)
{
ASSERT(index == 0 || index == 1 || index == 2 || index == 3);
- char szName[62];
+ char szName[64];
sprintf_s(szName, 64, "LoadPort %d", index + 1);
CLoadPort* pEquipment = new CLoadPort();
+ pEquipment->setID(EQ_ID_LOADPORT1 + index);
pEquipment->setName(szName);
pEquipment->setDescription(szName);
addToEquipmentList(pEquipment);
@@ -319,6 +325,7 @@
{
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(1, index == 0 ? 3 : 4);
@@ -491,4 +498,18 @@
}
}
}
+
+ void CMaster::connectEquipments()
+ {
+ CLoadPort* pLoadPort1 = (CLoadPort*)getEquipment(EQ_ID_LOADPORT1);
+ CBonder* pBonder1 = (CBonder*)getEquipment(EQ_ID_Bonder1);
+
+ int nRet = pLoadPort1->getPin("Out")->connectPin(pBonder1->getPin("In"));
+ if (nRet < 0) {
+ AfxMessageBox("连接失败");
+ }
+ else {
+ AfxMessageBox("连接成功");
+ }
+ }
}
diff --git a/SourceCode/Bond/Servo/CMaster.h b/SourceCode/Bond/Servo/CMaster.h
index dc96b8d..d73535e 100644
--- a/SourceCode/Bond/Servo/CMaster.h
+++ b/SourceCode/Bond/Servo/CMaster.h
@@ -37,6 +37,8 @@
int addLoadPort(int index, StepListener& listener);
int addEFEM(StepListener& listener);
int addBonder(int index, StepListener& listener);
+ void connectEquipments();
+
private:
MasterListener m_listener;
diff --git a/SourceCode/Bond/Servo/Common.h b/SourceCode/Bond/Servo/Common.h
index 1d1bee5..e113aa0 100644
--- a/SourceCode/Bond/Servo/Common.h
+++ b/SourceCode/Bond/Servo/Common.h
@@ -51,6 +51,10 @@
#define EQ_ID_EFEM 1
#define EQ_ID_Bonder1 2
#define EQ_ID_Bonder2 3
+#define EQ_ID_LOADPORT1 4
+#define EQ_ID_LOADPORT2 5
+#define EQ_ID_LOADPORT3 6
+#define EQ_ID_LOADPORT4 7
/* step name */
--
Gitblit v1.9.3