From b8c35c05be4be6881804d6d0eb4ba2b74ae33308 Mon Sep 17 00:00:00 2001
From: LAPTOP-SNT8I5JK\Boounion <Chenluhua@qq.com>
Date: 星期四, 13 三月 2025 15:41:50 +0800
Subject: [PATCH] 1.增加CEqCimMessageCmdStep(发送Cim消息)和CEqCimMessageClearStep(清除消息)
---
SourceCode/Bond/Servo/CStep.cpp | 178 +++++++++++++++--------------------------------------------
1 files changed, 45 insertions(+), 133 deletions(-)
diff --git a/SourceCode/Bond/Servo/CStep.cpp b/SourceCode/Bond/Servo/CStep.cpp
index 3873ddf..dbbf161 100644
--- a/SourceCode/Bond/Servo/CStep.cpp
+++ b/SourceCode/Bond/Servo/CStep.cpp
@@ -3,37 +3,22 @@
namespace SERVO {
-#define TIMEOUT 15
-
- unsigned __stdcall StepWorkThreadFunction(LPVOID lpParam)
- {
- CStep* pScale = (CStep*)lpParam;
- return pScale->WorkingProc();
- }
CStep::CStep()
{
- m_nWordThreadAddr = 0;
- m_hWorkStop = nullptr;
- m_hWorkThreadHandle = nullptr;
- m_hSignalOn = ::CreateEvent(NULL, TRUE, FALSE, NULL);
- m_hSignalOff = ::CreateEvent(NULL, TRUE, FALSE, NULL);
- m_nCurStep = 0;
+ m_listener = {nullptr};
m_pCclink = nullptr;
InitializeCriticalSection(&m_criticalSection);
}
CStep::~CStep()
{
- ASSERT(m_hSignalOn);
- CloseHandle(m_hSignalOn);
- m_hSignalOn = nullptr;
-
- ASSERT(m_hSignalOff);
- CloseHandle(m_hSignalOff);
- m_hSignalOff = nullptr;
-
DeleteCriticalSection(&m_criticalSection);
+ }
+
+ void CStep::setListener(StepListener listener)
+ {
+ m_listener.onEvent = listener.onEvent;
}
void CStep::setCcLink(CCCLinkIEControl* pCcLink)
@@ -41,129 +26,56 @@
m_pCclink = pCcLink;
}
+ void CStep::setEquipment(CEquipment* pEquipment)
+ {
+ m_pEquipment = pEquipment;
+ }
+
+ CEquipment* CStep::getEquipment()
+ {
+ return m_pEquipment;
+ }
+
+ void CStep::setName(const char* pszName)
+ {
+ m_strName = pszName;
+ }
+
+ std::string& CStep::getName()
+ {
+ return m_strName;
+ }
+
+ void CStep::getAttributeVector(CAttributeVector& attrubutes)
+ {
+ attrubutes.clear();
+ attrubutes.addAttribute(new CAttribute("Network",
+ std::to_string(m_station.nNetNo).c_str(), ""));
+ attrubutes.addAttribute(new CAttribute("Station",
+ std::to_string(m_station.nStNo).c_str(), ""));
+ }
+
void CStep::init()
{
- if (m_hWorkStop != nullptr) return;
- m_hWorkStop = ::CreateEvent(NULL, TRUE, FALSE, NULL);
- m_hWorkThreadHandle = (HANDLE)_beginthreadex(NULL, 0, SERVO::StepWorkThreadFunction, this,
- 0, &m_nWordThreadAddr);
+
}
void CStep::term()
{
- ASSERT(m_hWorkStop);
- SetEvent(m_hWorkStop);
- if (m_hWorkThreadHandle != NULL) {
- WaitForSingleObject(m_hWorkThreadHandle, INFINITE);
- CloseHandle(m_hWorkThreadHandle);
- m_hWorkThreadHandle = NULL;
- }
- CloseHandle(m_hWorkStop);
- m_hWorkStop = NULL;
+
}
- unsigned CStep::WorkingProc()
+ void CStep::convertString(const char* pszBuffer, int size, std::string& strOut)
{
- HANDLE hEvent = ::CreateEvent(NULL, TRUE, FALSE, NULL);
- BOOL bReadOk = FALSE;
-
- int nBeginAddr = 0x0;
- while (1) {
-RESET:
- resetStep();
-
- // 待退出信号或时间到
- HANDLE hEvents[] = { m_hWorkStop, m_hSignalOn };
- int nRet = WaitForMultipleObjects(2, hEvents, FALSE, INFINITE);
- if (nRet == WAIT_OBJECT_0) {
- ResetEvent(m_hWorkStop);
- break;
- }
-
- else if (nRet == WAIT_OBJECT_0 + 1) {
- ResetEvent(m_hSignalOn);
-
- // 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);
-
- // 2.给对方写ON
- nextStep();
- m_pCclink->SetBitDevice(station, DeviceType::B, 0x30);
-
-
- // 3.等待对方OFF
- nextStep();
- int nStep3Ret = ::WaitForSingleObject(m_hSignalOff, TIMEOUT * 1000);
- if (nStep3Ret == WAIT_TIMEOUT) {
- timeout();
- m_pCclink->ResetBitDevice(station, DeviceType::B, 0x30);
- goto RESET;
- }
- ResetEvent(m_hSignalOff);
-
-
- // 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);
-
-
- // 6.完成
- nextStep();
- TRACE("m_nCurStep:%d\n", m_nCurStep);
- }
+ strOut.clear();
+ int nLength = 0;
+ for (int i = 0; i < size; i++) {
+ if (pszBuffer[i] == '\0') break;
+ nLength++;
}
-
- if (hEvent != nullptr) {
- CloseHandle(hEvent);
+ if (nLength > 0) {
+ strOut = std::string(pszBuffer, nLength);
}
-
- // _endthreadex(0);
- TRACE("CStep::WorkingProc 线程退出\n");
- return 0;
- }
-
- void CStep::onSignal(BOOL bSignal)
- {
- Lock();
- if (m_nCurStep == 0 && bSignal) {
- SetEvent(m_hSignalOn);
- }
- else if (m_nCurStep == 3 && !bSignal) {
- SetEvent(m_hSignalOff);
- }
-
- Unlock();
- }
-
- void CStep::resetStep()
- {
- Lock();
- m_nCurStep = 0;
- Unlock();
- }
-
- void CStep::nextStep()
- {
- Lock();
- m_nCurStep++;
- Unlock();
- }
-
- void CStep::timeout()
- {
- TRACE(">>>>>>>>>>>>>>>> timeout:%d\n", m_nCurStep);
}
}
--
Gitblit v1.9.3