From 2fc5bbfe88adefb0d2f8ba55d800fe074264a539 Mon Sep 17 00:00:00 2001
From: LAPTOP-SNT8I5JK\Boounion <Chenluhua@qq.com>
Date: 星期五, 14 二月 2025 14:16:27 +0800
Subject: [PATCH] Merge branch 'liuyang' into clh
---
SourceCode/Bond/Servo/Servo.vcxproj | 12
SourceCode/Bond/Servo/CCLinkPerformance/PerformanceMelsec.h | 465 +++++++
SourceCode/Bond/Servo/CCLinkPerformance/PerformanceMelsec.cpp | 1355 ++++++++++++++++++++++
SourceCode/Bond/Servo/Servo.cpp | 19
SourceCode/Bond/Servo/stdafx.h | 3
SourceCode/Bond/Servo/SECSRuntimeManager.cpp | 682 +++++++++++
SourceCode/Bond/Servo/ServoDlg.cpp | 1
SourceCode/Bond/MELSECSDK/lib/MdFunc32.lib | 0
SourceCode/Bond/Servo/CCLinkPerformance/CCLinkIEControl.cpp | 81 +
SourceCode/Bond/Servo/Servo.vcxproj.filters | 204 +--
SourceCode/Bond/Servo/CCLinkPerformance/CCLinkIEControl.h | 68 +
Document/VID 表格.zip | 0
SourceCode/Bond/MELSECSDK/include/Mdfunc.h | 392 ++++++
SourceCode/Bond/Servo/SECSRuntimeManager.h | 221 +++
14 files changed, 3,365 insertions(+), 138 deletions(-)
diff --git "a/Document/VID \350\241\250\346\240\274.zip" "b/Document/VID \350\241\250\346\240\274.zip"
new file mode 100644
index 0000000..a5d8282
--- /dev/null
+++ "b/Document/VID \350\241\250\346\240\274.zip"
Binary files differ
diff --git a/SourceCode/Bond/MELSECSDK/include/Mdfunc.h b/SourceCode/Bond/MELSECSDK/include/Mdfunc.h
new file mode 100644
index 0000000..1ee3c8c
--- /dev/null
+++ b/SourceCode/Bond/MELSECSDK/include/Mdfunc.h
@@ -0,0 +1,392 @@
+#ifndef WINAPI
+ #define WINAPI
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+ SHORT WINAPI mdOpen( SHORT, SHORT, LPLONG );
+ SHORT WINAPI mdClose( LONG );
+ SHORT WINAPI mdSend( LONG, SHORT, SHORT, SHORT, PSHORT, LPVOID );
+ SHORT WINAPI mdReceive( LONG, SHORT, SHORT, SHORT, PSHORT, LPVOID );
+ SHORT WINAPI mdDevSet( LONG, SHORT, SHORT, SHORT );
+ SHORT WINAPI mdDevRst( LONG, SHORT, SHORT, SHORT );
+ SHORT WINAPI mdRandW( LONG, SHORT, LPVOID, LPVOID, SHORT );
+ SHORT WINAPI mdRandR( LONG, SHORT, LPVOID, LPVOID, SHORT );
+ SHORT WINAPI mdControl( LONG, SHORT, SHORT );
+ SHORT WINAPI mdTypeRead( LONG, SHORT, PSHORT );
+ SHORT WINAPI mdBdLedRead( LONG, PSHORT );
+ SHORT WINAPI mdBdModRead( LONG, PSHORT );
+ SHORT WINAPI mdBdModSet( LONG, SHORT );
+ SHORT WINAPI mdBdRst( LONG );
+ SHORT WINAPI mdBdSwRead( LONG, PSHORT );
+ SHORT WINAPI mdBdVerRead( LONG, PSHORT );
+ SHORT WINAPI mdInit( LONG );
+ SHORT WINAPI mdWaitBdEvent( LONG, PSHORT, LONG, PSHORT, PSHORT );
+ LONG WINAPI mdSendEx( LONG, LONG, LONG, LONG, LONG, LPLONG, LPVOID );
+ LONG WINAPI mdReceiveEx( LONG, LONG, LONG, LONG, LONG, LPLONG, LPVOID );
+ LONG WINAPI mdDevSetEx( LONG, LONG, LONG, LONG, LONG );
+ LONG WINAPI mdDevRstEx( LONG, LONG, LONG, LONG, LONG );
+ LONG WINAPI mdRandWEx( LONG, LONG, LONG, LPVOID, LPVOID, LONG );
+ LONG WINAPI mdRandREx( LONG, LONG, LONG, LPVOID, LPVOID, LONG );
+ LONG WINAPI mdRemBufWriteEx( LONG, LONG, LONG, LONG, LPLONG, LPVOID );
+ LONG WINAPI mdRemBufReadEx( LONG, LONG, LONG, LONG, LPLONG, LPVOID );
+ LONG WINAPI mdRemBufWriteIPEx( LONG, LONG, LONG, LPLONG, LPVOID );
+ LONG WINAPI mdRemBufReadIPEx( LONG, LONG, LONG, LPLONG, LPVOID );
+#ifdef __cplusplus
+}
+#endif
+
+#define mdopen mdOpen
+#define mdclose mdClose
+#define mdsend mdSend
+#define mdreceive mdReceive
+#define mddevset mdDevSet
+#define mddevrst mdDevRst
+#define mdrandw mdRandW
+#define mdrandr mdRandR
+#define mdcontrol mdControl
+#define mdtyperead mdTypeRead
+#define mdsendex mdSendEx
+#define mdreceiveex mdReceiveEx
+#define mddevsetex mdDevSetEx
+#define mddevrstex mdDevRstEx
+#define mdrandwex mdRandWEx
+#define mdrandrex mdRandREx
+
+#define DevX (1)
+#define DevLX(x) (DevX*1000+(x))
+#define DevY (2)
+#define DevLY(x) (DevY*1000+(x))
+#define DevL (3)
+#define DevM (4)
+#define DevSM (5)
+#define DevF (6)
+#define DevTT (7)
+#define DevTC (8)
+#define DevCT (9)
+#define DevCC (10)
+#define DevTN (11)
+#define DevCN (12)
+#define DevD (13)
+#define DevSD (14)
+#define DevTM (15)
+#define DevTS (16)
+#define DevTS2 (16002)
+#define DevTS3 (16003)
+#define DevCM (17)
+#define DevCS (18)
+#define DevCS2 (18002)
+#define DevCS3 (18003)
+#define DevA (19)
+#define DevZ (20)
+#define DevV (21)
+#define DevR (22)
+#define DevZR (220)
+#define DevB (23)
+#define DevLB(x) (DevB*1000+(x))
+#define DevW (24)
+#define DevLW(x) (DevW*1000+(x))
+#define DevQSB (25)
+#define DevLSB(x) (DevQSB*1000+(x))
+#define DevSTT (26)
+#define DevSTC (27)
+#define DevQSW (28)
+#define DevLSW(x) (DevQSW*1000+(x))
+#define DevSPG(x) (29*1000+(x))
+#define DevQV (30)
+#define DevMRB (33)
+#define DevMAB (34)
+#define DevSTN (35)
+#define DevWw (36)
+#define DevWr (37)
+#define DevLZ (38)
+#define DevRD (39)
+#define DevFS (40)
+#define DevLTT (41)
+#define DevLTC (42)
+#define DevLTN (43)
+#define DevLCT (44)
+#define DevLCC (45)
+#define DevLCN (46)
+#define DevLSTT (47)
+#define DevLSTC (48)
+#define DevLSTN (49)
+#define DevSPB (50)
+#define DevSPB1 (501)
+#define DevSPB2 (502)
+#define DevSPB3 (503)
+#define DevSPB4 (504)
+#define DevSPX (51)
+#define DevSPY (52)
+#define DevUSER (100)
+#define DevMAIL (101)
+#define DevMAILNC (102)
+#define DevER0 (22000)
+#define DevER1 (22001)
+#define DevER2 (22002)
+#define DevER3 (22003)
+#define DevER4 (22004)
+#define DevER5 (22005)
+#define DevER6 (22006)
+#define DevER7 (22007)
+#define DevER8 (22008)
+#define DevER9 (22009)
+#define DevER10 (22010)
+#define DevER11 (22011)
+#define DevER12 (22012)
+#define DevER13 (22013)
+#define DevER14 (22014)
+#define DevER15 (22015)
+#define DevER16 (22016)
+#define DevER17 (22017)
+#define DevER18 (22018)
+#define DevER19 (22019)
+#define DevER20 (22020)
+#define DevER21 (22021)
+#define DevER22 (22022)
+#define DevER23 (22023)
+#define DevER24 (22024)
+#define DevER25 (22025)
+#define DevER26 (22026)
+#define DevER27 (22027)
+#define DevER28 (22028)
+#define DevER29 (22029)
+#define DevER30 (22030)
+#define DevER31 (22031)
+#define DevER32 (22032)
+#define DevER33 (22033)
+#define DevER34 (22034)
+#define DevER35 (22035)
+#define DevER36 (22036)
+#define DevER37 (22037)
+#define DevER38 (22038)
+#define DevER39 (22039)
+#define DevER40 (22040)
+#define DevER41 (22041)
+#define DevER42 (22042)
+#define DevER43 (22043)
+#define DevER44 (22044)
+#define DevER45 (22045)
+#define DevER46 (22046)
+#define DevER47 (22047)
+#define DevER48 (22048)
+#define DevER49 (22049)
+#define DevER50 (22050)
+#define DevER51 (22051)
+#define DevER52 (22052)
+#define DevER53 (22053)
+#define DevER54 (22054)
+#define DevER55 (22055)
+#define DevER56 (22056)
+#define DevER57 (22057)
+#define DevER58 (22058)
+#define DevER59 (22059)
+#define DevER60 (22060)
+#define DevER61 (22061)
+#define DevER62 (22062)
+#define DevER63 (22063)
+#define DevER64 (22064)
+#define DevER65 (22065)
+#define DevER66 (22066)
+#define DevER67 (22067)
+#define DevER68 (22068)
+#define DevER69 (22069)
+#define DevER70 (22070)
+#define DevER71 (22071)
+#define DevER72 (22072)
+#define DevER73 (22073)
+#define DevER74 (22074)
+#define DevER75 (22075)
+#define DevER76 (22076)
+#define DevER77 (22077)
+#define DevER78 (22078)
+#define DevER79 (22079)
+#define DevER80 (22080)
+#define DevER81 (22081)
+#define DevER82 (22082)
+#define DevER83 (22083)
+#define DevER84 (22084)
+#define DevER85 (22085)
+#define DevER86 (22086)
+#define DevER87 (22087)
+#define DevER88 (22088)
+#define DevER89 (22089)
+#define DevER90 (22090)
+#define DevER91 (22091)
+#define DevER92 (22092)
+#define DevER93 (22093)
+#define DevER94 (22094)
+#define DevER95 (22095)
+#define DevER96 (22096)
+#define DevER97 (22097)
+#define DevER98 (22098)
+#define DevER99 (22099)
+#define DevER100 (22100)
+#define DevER101 (22101)
+#define DevER102 (22102)
+#define DevER103 (22103)
+#define DevER104 (22104)
+#define DevER105 (22105)
+#define DevER106 (22106)
+#define DevER107 (22107)
+#define DevER108 (22108)
+#define DevER109 (22109)
+#define DevER110 (22110)
+#define DevER111 (22111)
+#define DevER112 (22112)
+#define DevER113 (22113)
+#define DevER114 (22114)
+#define DevER115 (22115)
+#define DevER116 (22116)
+#define DevER117 (22117)
+#define DevER118 (22118)
+#define DevER119 (22119)
+#define DevER120 (22120)
+#define DevER121 (22121)
+#define DevER122 (22122)
+#define DevER123 (22123)
+#define DevER124 (22124)
+#define DevER125 (22125)
+#define DevER126 (22126)
+#define DevER127 (22127)
+#define DevER128 (22128)
+#define DevER129 (22129)
+#define DevER130 (22130)
+#define DevER131 (22131)
+#define DevER132 (22132)
+#define DevER133 (22133)
+#define DevER134 (22134)
+#define DevER135 (22135)
+#define DevER136 (22136)
+#define DevER137 (22137)
+#define DevER138 (22138)
+#define DevER139 (22139)
+#define DevER140 (22140)
+#define DevER141 (22141)
+#define DevER142 (22142)
+#define DevER143 (22143)
+#define DevER144 (22144)
+#define DevER145 (22145)
+#define DevER146 (22146)
+#define DevER147 (22147)
+#define DevER148 (22148)
+#define DevER149 (22149)
+#define DevER150 (22150)
+#define DevER151 (22151)
+#define DevER152 (22152)
+#define DevER153 (22153)
+#define DevER154 (22154)
+#define DevER155 (22155)
+#define DevER156 (22156)
+#define DevER157 (22157)
+#define DevER158 (22158)
+#define DevER159 (22159)
+#define DevER160 (22160)
+#define DevER161 (22161)
+#define DevER162 (22162)
+#define DevER163 (22163)
+#define DevER164 (22164)
+#define DevER165 (22165)
+#define DevER166 (22166)
+#define DevER167 (22167)
+#define DevER168 (22168)
+#define DevER169 (22169)
+#define DevER170 (22170)
+#define DevER171 (22171)
+#define DevER172 (22172)
+#define DevER173 (22173)
+#define DevER174 (22174)
+#define DevER175 (22175)
+#define DevER176 (22176)
+#define DevER177 (22177)
+#define DevER178 (22178)
+#define DevER179 (22179)
+#define DevER180 (22180)
+#define DevER181 (22181)
+#define DevER182 (22182)
+#define DevER183 (22183)
+#define DevER184 (22184)
+#define DevER185 (22185)
+#define DevER186 (22186)
+#define DevER187 (22187)
+#define DevER188 (22188)
+#define DevER189 (22189)
+#define DevER190 (22190)
+#define DevER191 (22191)
+#define DevER192 (22192)
+#define DevER193 (22193)
+#define DevER194 (22194)
+#define DevER195 (22195)
+#define DevER196 (22196)
+#define DevER197 (22197)
+#define DevER198 (22198)
+#define DevER199 (22199)
+#define DevER200 (22200)
+#define DevER201 (22201)
+#define DevER202 (22202)
+#define DevER203 (22203)
+#define DevER204 (22204)
+#define DevER205 (22205)
+#define DevER206 (22206)
+#define DevER207 (22207)
+#define DevER208 (22208)
+#define DevER209 (22209)
+#define DevER210 (22210)
+#define DevER211 (22211)
+#define DevER212 (22212)
+#define DevER213 (22213)
+#define DevER214 (22214)
+#define DevER215 (22215)
+#define DevER216 (22216)
+#define DevER217 (22217)
+#define DevER218 (22218)
+#define DevER219 (22219)
+#define DevER220 (22220)
+#define DevER221 (22221)
+#define DevER222 (22222)
+#define DevER223 (22223)
+#define DevER224 (22224)
+#define DevER225 (22225)
+#define DevER226 (22226)
+#define DevER227 (22227)
+#define DevER228 (22228)
+#define DevER229 (22229)
+#define DevER230 (22230)
+#define DevER231 (22231)
+#define DevER232 (22232)
+#define DevER233 (22233)
+#define DevER234 (22234)
+#define DevER235 (22235)
+#define DevER236 (22236)
+#define DevER237 (22237)
+#define DevER238 (22238)
+#define DevER239 (22239)
+#define DevER240 (22240)
+#define DevER241 (22241)
+#define DevER242 (22242)
+#define DevER243 (22243)
+#define DevER244 (22244)
+#define DevER245 (22245)
+#define DevER246 (22246)
+#define DevER247 (22247)
+#define DevER248 (22248)
+#define DevER249 (22249)
+#define DevER250 (22250)
+#define DevER251 (22251)
+#define DevER252 (22252)
+#define DevER253 (22253)
+#define DevER254 (22254)
+#define DevER255 (22255)
+#define DevER256 (22256)
+#define DevRBM (-32768)
+#define DevRAB (-32736)
+#define DevRX (-32735)
+#define DevRY (-32734)
+#define DevRW (-32732)
+#define DevARB (-32704)
+#define DevSB (-32669)
+#define DevSW (-32668)
+#define DevEM(x) (31*1000+(x))
+#define DevED(x) (32*1000+(x))
+
diff --git a/SourceCode/Bond/MELSECSDK/lib/MdFunc32.lib b/SourceCode/Bond/MELSECSDK/lib/MdFunc32.lib
new file mode 100644
index 0000000..58e9017
--- /dev/null
+++ b/SourceCode/Bond/MELSECSDK/lib/MdFunc32.lib
Binary files differ
diff --git a/SourceCode/Bond/Servo/CCLinkPerformance/CCLinkIEControl.cpp b/SourceCode/Bond/Servo/CCLinkPerformance/CCLinkIEControl.cpp
new file mode 100644
index 0000000..bc85cc4
--- /dev/null
+++ b/SourceCode/Bond/Servo/CCLinkPerformance/CCLinkIEControl.cpp
@@ -0,0 +1,81 @@
+#include "stdafx.h"
+#include "CCLinkIEControl.h"
+
+CCCLinkIEControl::CCCLinkIEControl() : CPerformanceMelsec(BoardType::CC_LINK_IE_CONTROL) {}
+
+CCCLinkIEControl::~CCCLinkIEControl() = default;
+
+int CCCLinkIEControl::SetBoardModeEx(CCLinkIEControlMode mode) {
+ return SetBoardMode(static_cast<short>(mode));
+}
+
+CCLinkIEControlMode CCCLinkIEControl::GetBoardModeEx() {
+ short nMode = 0;
+ const int nResult = GetBoardMode(nMode);
+ if (nResult != 0) {
+ return CCLinkIEControlMode::UNKNOWN;
+ }
+
+ return ConvertToCCLinkIEControlMode(nMode);
+}
+
+int CCCLinkIEControl::GetBoardStatusEx(BoardStatus& status) {
+ const int nResult = GetBoardStatus(status);
+ if (nResult != 0) {
+ return nResult;
+ }
+
+ return ValidateBoardStatus(status);
+}
+
+int CCCLinkIEControl::ReadLedStatus(LedStatus& outLedStatus) {
+ std::vector<short> vecLedBuffer;
+ const int nRet = ReadBoardLed(vecLedBuffer);
+ if (nRet != 0) {
+ return nRet;
+ }
+
+ if (vecLedBuffer.empty()) {
+ UpdateLastError(ERROR_CODE_INVALID_DATA);
+ return ERROR_CODE_INVALID_DATA;
+ }
+
+ // 瑙f瀽鍚勪綅鐘舵��
+ const short nBuffer = vecLedBuffer[0];
+ outLedStatus.bExtPw = (nBuffer & (1 << 15)) != 0;
+ outLedStatus.bRd = (nBuffer & (1 << 6)) != 0;
+ outLedStatus.bDLnk = (nBuffer & (1 << 5)) != 0;
+ outLedStatus.bPrm = (nBuffer & (1 << 4)) != 0;
+ outLedStatus.bErr = (nBuffer & (1 << 3)) != 0;
+ outLedStatus.bSd = (nBuffer & (1 << 2)) != 0;
+ outLedStatus.bMode = (nBuffer & (1 << 1)) != 0;
+ outLedStatus.bRun = (nBuffer & (1 << 0)) != 0;
+
+ return 0;
+}
+
+CCLinkIEControlMode CCCLinkIEControl::ConvertToCCLinkIEControlMode(const short nMode) {
+ switch (static_cast<CCLinkIEControlMode>(nMode)) {
+ case CCLinkIEControlMode::ONLINE: return CCLinkIEControlMode::ONLINE; // 鍦ㄧ嚎
+ case CCLinkIEControlMode::OFFLINE: return CCLinkIEControlMode::OFFLINE; // 绂荤嚎
+ case CCLinkIEControlMode::INTER_STATION_TEST: return CCLinkIEControlMode::INTER_STATION_TEST; // 绔欓棿娴嬭瘯
+ case CCLinkIEControlMode::LINE_TEST: return CCLinkIEControlMode::LINE_TEST; // 绾胯矾娴嬭瘯
+ case CCLinkIEControlMode::LOOPBACK_TEST: return CCLinkIEControlMode::LOOPBACK_TEST; // 鑷洖閫佹祴璇�
+ case CCLinkIEControlMode::HW_TEST: return CCLinkIEControlMode::HW_TEST; // H/W娴嬭瘯
+ case CCLinkIEControlMode::BUS_IF_TEST: return CCLinkIEControlMode::BUS_IF_TEST; // 鎬荤嚎I/F娴嬭瘯
+ default: return CCLinkIEControlMode::UNKNOWN;
+ }
+}
+
+int CCCLinkIEControl::ValidateBoardStatus(const BoardStatus& status) {
+ if (status.nStationValue < 1 || status.nStationValue > 120) {
+ return ERROR_CODE_STATION_OUT_OF_RANGE; // 绔欏彿瓒呭嚭鑼冨洿
+ }
+ if (status.nGroupValue < 0 || status.nGroupValue > 32) {
+ return ERROR_CODE_GROUP_OUT_OF_RANGE; // 缁勮秴鍑鸿寖鍥�
+ }
+ if (status.nNetworkValue < 1 || status.nNetworkValue > 239) {
+ return ERROR_CODE_NETWORK_OUT_OF_RANGE; // 缃戠粶鍙疯秴鍑鸿寖鍥�
+ }
+ return 0; // 鏍¢獙閫氳繃
+}
\ No newline at end of file
diff --git a/SourceCode/Bond/Servo/CCLinkPerformance/CCLinkIEControl.h b/SourceCode/Bond/Servo/CCLinkPerformance/CCLinkIEControl.h
new file mode 100644
index 0000000..a7006fd
--- /dev/null
+++ b/SourceCode/Bond/Servo/CCLinkPerformance/CCLinkIEControl.h
@@ -0,0 +1,68 @@
+#ifndef CCLINKIECONTROL_H
+#define CCLINKIECONTROL_H
+
+#include "PerformanceMelsec.h"
+
+enum class CCLinkIEControlMode : short {
+ UNKNOWN = 0x0194, // 鏈煡
+ ONLINE = 0x0000, // 鍦ㄧ嚎
+ OFFLINE = 0x0002, // 绂荤嚎
+ INTER_STATION_TEST = 0x0005, // 绔欓棿娴嬭瘯
+ LINE_TEST = 0x0006, // 绾胯矾娴嬭瘯
+ LOOPBACK_TEST = 0x0007, // 鑷洖閫佹祴璇�
+ HW_TEST = 0x0009, // H/W娴嬭瘯
+ BUS_IF_TEST = 0x000E // 鎬荤嚎I/F娴嬭瘯
+};
+
+class CCCLinkIEControl final : public CPerformanceMelsec {
+public:
+ CCCLinkIEControl();
+ ~CCCLinkIEControl() override;
+
+ struct LedStatus {
+ bool bExtPw; // 澶栭儴鐢垫簮鐘舵�� (b15)
+ bool bRd; // 鏁版嵁鎺ユ敹鐘舵�� (b6)
+ bool bDLnk; // 鏁版嵁閾炬帴鐘舵�� (b5)
+ bool bPrm; // 绠$悊鍔熻兘鐘舵�� (b4)
+ bool bErr; // 閿欒鐘舵�� (b3)
+ bool bSd; // 鏁版嵁鍙戦�佺姸鎬� (b2)
+ bool bMode; // 鍔ㄤ綔妯″紡 (b1)
+ bool bRun; // 杩愯鐘舵�� (b0)
+
+ // 杞崲涓哄瓧绗︿覆锛岀敤浜庤皟璇�
+ std::string ToString() const {
+ std::ostringstream oss;
+ oss << "CC-Link IE Control Network LED Status: {"
+ << "\n Ext Power: " << (bExtPw ? "ON" : "OFF")
+ << "\n Receive Data: " << (bRd ? "Receiving" : "Not Receiving")
+ << "\n Data Link: " << (bDLnk ? "Linked" : "Not Linked")
+ << "\n Management: " << (bPrm ? "Managing" : "Not Managing")
+ << "\n Error: " << (bErr ? "Error Detected" : "No Error")
+ << "\n Send Data: " << (bSd ? "Sending" : "Not Sending")
+ << "\n Mode: " << (bMode ? "Executing" : "Not Executing")
+ << "\n Run: " << (bRun ? "Running" : "Stopped")
+ << "\n}";
+ return oss.str();
+ }
+ };
+
+ // 璇诲彇鐩爣绔欑偣CPU绫诲瀷
+ // short ReadCPUCodeEx(const StationIdentifier& station, short& nCPUCode);
+
+ // 鏉挎ā寮忚幏鍙�/璁剧疆
+ int SetBoardModeEx(CCLinkIEControlMode mode);
+ CCLinkIEControlMode GetBoardModeEx();
+
+ // 鑾峰彇鏉跨姸鎬�
+ int GetBoardStatusEx(BoardStatus& status);
+
+ // 璇诲彇LED鐘舵��
+ int ReadLedStatus(LedStatus& outLedStatus);
+
+private:
+ static CCLinkIEControlMode ConvertToCCLinkIEControlMode(short nMode);
+ static int ValidateBoardStatus(const BoardStatus& status);
+};
+
+
+#endif //CCLINKIECONTROL_H
diff --git a/SourceCode/Bond/Servo/CCLinkPerformance/PerformanceMelsec.cpp b/SourceCode/Bond/Servo/CCLinkPerformance/PerformanceMelsec.cpp
new file mode 100644
index 0000000..1f6deab
--- /dev/null
+++ b/SourceCode/Bond/Servo/CCLinkPerformance/PerformanceMelsec.cpp
@@ -0,0 +1,1355 @@
+// PerformanceMelsec.cpp: implementation of the CPerformanceMelsec class.
+//
+//////////////////////////////////////////////////////////////////////
+#include "stdafx.h"
+#include "PerformanceMelsec.h"
+#include <windows.h>
+#include <iostream>
+#include <fstream>
+
+#ifdef _DEBUG
+#undef THIS_FILE
+static char THIS_FILE[] = __FILE__;
+#define new DEBUG_NEW
+#endif
+
+#ifdef _DEBUG
+#define LOG_ERROR(msg) \
+std::cerr << "[ERROR] " << __FILE__ << ":" << __LINE__ << " (" << __FUNCTION__ << ") - " << msg << std::endl;
+#define LOG_DEBUG(msg) \
+std::cout << "[DEBUG] " << __FILE__ << ":" << __LINE__ << " (" << __FUNCTION__ << ") - " << msg << std::endl;
+#else
+#define LOG_ERROR(msg)
+#define LOG_DEBUG(msg)
+#endif
+
+// 鍒濆鍖栭潤鎬佹垚鍛樺彉閲�
+std::unordered_map<int, std::string> CPerformanceMelsec::m_mapError = {
+ // 鏉垮潡SDK閿欒鐮�
+ {0, "No error, communication successful."},
+ {1, "Driver not started. The driver is not running."},
+ {2, "Timeout error (board response error). Request not completed within timeout."},
+ {66, "Already OPEN error. The specified channel is OPEN."},
+ {68, "Path error. The specified path is invalid."},
+ {69, "Unsupported function execution error."},
+ {70, "Station number error. The specified station number is invalid."},
+ {71, "No received data error (during RECV function)."},
+ {77, "Memory allocation error / insufficient memory resources."},
+ {85, "SEND/RECV channel number error."},
+ {100, "Board H/W resource busy."},
+ {101, "Routing exception."},
+ {102, "Board driver I/F error: Failed to send request data to the board driver."},
+ {103, "Board driver I/F error: Failed to receive response data from the board driver."},
+ {130, "Initial software component No. Error."},
+ {131, "Capacity error."},
+ {133, "Parameter error."},
+ {16385, "Specified target station number does not exist."},
+ {16386, "Received a request that the target station cannot process."},
+ {16418, "Failed to create the event history file."},
+ {16420, "Failed to access the event history file."},
+ {16421, "Another board driver is using the event history file."},
+ {16432, "The specified soft component type does not exist."},
+ {16433, "Soft component specification error: Out of range or invalid start I/O or block number."},
+ {16512, "Request data exception: Invalid data or unsupported module."},
+ {16685, "File association error: Failed to create the event history file."},
+ {16837, "File association error: Event history file does not exist."},
+ {18944, "Link association error: Network does not exist, unsupported CPU, or incorrect network No./station number."},
+ {-1, "Invalid path. The specified function is not supported for this path."},
+ {-2, "Start component No. error. The specified component is out of range."},
+ {-3, "Capacity error. The capacity exceeds the component range."},
+ {-6, "Component type error. The specified type during write is invalid."},
+ {-8, "Channel No. error. The channel specified is invalid."},
+ {-12, "Target path error. The specified path points to an invalid target."},
+ {-13, "Write protection area error. The specified range is protected."},
+ {-16, "Target path conflict. The path conflicts with write protection settings."},
+ {-17, "Device not found or target not responding."},
+ {-18, "Invalid target. The device does not support the operation."},
+ {-19, "Invalid path operation. An unsupported path operation was executed."},
+ {-31, "DLL library call failed or path not initialized."},
+ {-32, "Resource timeout error. Communication timed out or exceeded resource limits."},
+ {-33, "Communication timeout error. The target is not responding or timed out."},
+ {-34, "Unsupported communication target error. The specified network No. or station No. points to an unsupported model."},
+ {-35, "Registry access error."},
+ {-36, "Registry access error."},
+ {-37, "Communication initialization error. The settings for initializing the communication path are invalid."},
+ {-42, "Key information error. Authentication failed."},
+ {-43, "Marking event error. TC waiting event write was executed on the CPU."},
+ {-61, "Marking event error. TC waiting event write was executed on the CPU."},
+ {-62, "Event waiting timeout. The specified external event waiting timed out."},
+ {-63, "Timeout value is out of range."},
+ {-64, "Timeout value is out of range."},
+ {-65, "Event waiting timeout. The specified external event waiting timed out."},
+ {-66, "Timeout-induced resource shortage."},
+ {-67, "Irrelevant file access execution error."},
+ {-69, "Operation executed, but the module does not support the function."},
+ {-70, "The target event processing module returned a rejection."},
+ {-71, "The remote station did not return data correctly."},
+ {-72, "Pointer error. The specified pointer value is invalid."},
+ {-73, "Specified address error."},
+ {-2174, "Buffer data queue exception occurred. Read/write exception to device."},
+ {-7656, "Buffer data queue exception. Read/write exception to the device."},
+ {-7672, "Buffer data queue exception. Read/write exception to the device."},
+ {-11683, "Buffer data transfer error."},
+ {-11717, "Network No. error."},
+ {-11746, "Station No. error."},
+ {-12128, "Buffer data send/response error."},
+ {-18560, "Module mode setting error."},
+ {-18572, "Communication method error."},
+ {-25056, "Processor error."},
+ {-26334, "Duplicate program call or illegal CPU operation."},
+ {-26336, "Routing request error to a station without routing function support."},
+ {-27902, "Event register timeout error."},
+ {-28079, "Communication No. read error."},
+ {-28080, "Communication No. incorrect error."},
+ {-28136, "Unsupported function in fast mode error."},
+ {-28139, "Link disconnection error."},
+ {-28140, "Incorrect mode setting error."},
+ {-28141, "System reboot error."},
+ {-28142, "Mode error."},
+ {-28143, "Hardware self-diagnosis error."},
+ {-28144, "Hardware self-diagnosis error."},
+ {-28150, "Data reception interruption at remote station error."},
+ {-28151, "Data reception interruption at remote station error."},
+ {-28153, "Data reception interruption at remote station error."},
+ {-28154, "Abnormal data reception error."},
+ {-28158, "Driver WDT error."},
+ {-28160, "Hardware resource error."},
+ {-28622, "Dedicated instruction channel in-use error."},
+ {-28634, "Hardware self-diagnosis error."},
+ {-28636, "Hardware self-diagnosis error."},
+
+ // 鑷畾涔夐敊璇爜
+ {ERROR_CODE_UNKNOWN, "Error: Unknown error code."},
+ {ERROR_CODE_NOT_CONNECTED, "Error: Not connected to the device."},
+ {ERROR_CODE_INVALID_PARAM, "Error: Invalid parameter."},
+ {ERROR_CODE_INVALID_DATA, "Error: Invalid data provided."},
+ {ERROR_CODE_STATION_OUT_OF_RANGE, "Error: Station number is out of range."},
+ {ERROR_CODE_GROUP_OUT_OF_RANGE, "Error: Group number is out of range."},
+ {ERROR_CODE_NETWORK_OUT_OF_RANGE, "Error: Network number is out of range."}
+};
+
+//////////////////////////////////////////////////////////////////////
+// Construction/Destruction
+//////////////////////////////////////////////////////////////////////
+CPerformanceMelsec::CPerformanceMelsec(const BoardType enBoardType) {
+ m_nPath = 0;
+ m_enBoardType = enBoardType;
+ m_bConnected.store(false);
+}
+
+// 鏋愭瀯鍑芥暟
+CPerformanceMelsec::~CPerformanceMelsec() {
+ Disconnect();
+}
+
+// 鑾峰彇鏈�杩戠殑閿欒淇℃伅
+std::string CPerformanceMelsec::GetLastError() const {
+ return m_strLastError;
+}
+
+// 淇濆瓨閿欒淇℃伅
+bool CPerformanceMelsec::SaveErrorInfoToFile(const std::string& filename) {
+ // 鎵撳紑鏂囦欢
+ std::ofstream file(filename);
+ if (!file.is_open()) {
+ std::cerr << "Failed to open file for saving: " << filename << std::endl;
+ return false;
+ }
+
+ // 閬嶅巻闈欐�佹垚鍛樺彉閲� m_mapError 骞跺皢姣忎釜閿欒淇℃伅鍐欏叆鏂囦欢
+ for (const auto& entry : m_mapError) {
+ const int nCode = entry.first;
+ const std::string& strMessage = entry.second;
+ file << nCode << "|" << strMessage << "\n";
+ }
+ file.close();
+
+ return true;
+}
+
+// 鍔犺浇閿欒淇℃伅
+bool CPerformanceMelsec::LoadErrorInfoFromFile(const std::string& filename) {
+ std::ifstream inFile(filename);
+ if (!inFile.is_open()) {
+ std::cerr << "Failed to open file for loading: " << filename << std::endl;
+ return false;
+ }
+
+ m_mapError.clear();
+ std::string line;
+ while (std::getline(inFile, line)) {
+ std::istringstream iss(line);
+ int nCode = 0;
+ std::string strToken;
+ std::string strMessage;
+
+ // 浣跨敤鍒嗛殧绗� "|" 瑙f瀽姣忎竴琛�
+ if (std::getline(iss, strToken, '|')) {
+ nCode = std::stoi(strToken);
+ }
+
+ if (std::getline(iss, strToken)) {
+ strMessage = strToken;
+ }
+
+ if (!strMessage.empty()) {
+ m_mapError[nCode] = strMessage;
+ }
+ }
+
+ return true;
+}
+
+// 杩炴帴鍒癙LC
+int CPerformanceMelsec::Connect(const short nChannel, const short nMode) {
+ std::lock_guard<std::mutex> lock(m_mtx);
+
+ if (m_bConnected.load()) {
+ return 0;
+ }
+
+ const BoardType enBoardType = FindBoardTypeByChannel(nChannel);
+ if (enBoardType == BoardType::UNKNOWN || enBoardType != m_enBoardType) {
+ UpdateLastError(ERROR_CODE_INVALID_PARAM);
+ return ERROR_CODE_INVALID_PARAM;
+ }
+
+ // 杩炴帴PLC锛屾樉寮忕被鍨嬭浆鎹互鍖归厤 mdOpen 鐨勭鍚�
+ const short nRet = mdOpen(nChannel, nMode, &m_nPath);
+ if (nRet == 0) {
+ m_bConnected.store(true);
+ m_enBoardType = enBoardType;
+ } else {
+ UpdateLastError(nRet);
+ LOG_ERROR(m_strLastError);
+ }
+
+ return nRet;
+}
+
+// 鏂紑杩炴帴
+int CPerformanceMelsec::Disconnect() {
+ std::lock_guard<std::mutex> lock(m_mtx);
+
+ short nRet = 0;
+ if (m_bConnected.load()) {
+ nRet = mdClose(m_nPath);
+ m_bConnected.store(false);
+ m_nPath = 0;
+ }
+
+ UpdateLastError(nRet);
+ LOG_DEBUG("Close connect.");
+
+ return nRet;
+}
+
+// 鍙紪绋嬫帶鍒跺櫒杞厓浠朵俊鎭〃鐨勫垵濮嬪寲
+int CPerformanceMelsec::InitializeController() {
+ std::lock_guard<std::mutex> lock(m_mtx);
+
+ if (!m_bConnected.load()) {
+ UpdateLastError(ERROR_CODE_NOT_CONNECTED);
+ return ERROR_CODE_NOT_CONNECTED;
+ }
+
+ const short nRet = mdInit(m_nPath);
+ if (nRet != 0) {
+ UpdateLastError(nRet);
+ LOG_ERROR(m_strLastError);
+ }
+
+ return nRet;
+}
+
+// 鑾峰彇鐗堟湰淇℃伅
+int CPerformanceMelsec::GetBoardVersion(BoardVersion& version) {
+ if (!m_bConnected.load()) {
+ UpdateLastError(ERROR_CODE_NOT_CONNECTED);
+ return ERROR_CODE_NOT_CONNECTED;
+ }
+
+ // 鑾峰彇鐗堟湰淇℃伅
+ short buf[32] = {0};
+ const short nRet = mdBdVerRead(m_nPath, buf);
+ if (nRet != 0) {
+ UpdateLastError(nRet);
+ LOG_ERROR(m_strLastError);
+ return nRet;
+ }
+
+ // 濉厖鐗堟湰淇℃伅鍒扮粨鏋勪綋
+ version.fixedValue[0] = static_cast<char>(buf[0] & 0xFF);
+ version.fixedValue[1] = static_cast<char>((buf[0] >> 8) & 0xFF);
+
+ version.checksum[0] = static_cast<char>(buf[1] & 0xFF);
+ version.checksum[1] = static_cast<char>((buf[1] >> 8) & 0xFF);
+
+ version.swVersion[0] = static_cast<char>(buf[2] & 0xFF);
+ version.swVersion[1] = static_cast<char>((buf[2] >> 8) & 0xFF);
+
+ std::memcpy(version.date, &buf[3], 6);
+
+ version.reserved = static_cast<uint32_t>(buf[6]) | (static_cast<uint32_t>(buf[7]) << 16);
+
+ std::memcpy(version.swModel, &buf[8], 16);
+ std::memcpy(version.hwModel, &buf[16], 16);
+
+ version.twoPortMemory[0] = static_cast<char>(buf[18] & 0xFF);
+ version.twoPortMemory[1] = static_cast<char>((buf[18] >> 8) & 0xFF);
+
+ version.twoPortAttribute[0] = static_cast<char>(buf[19] & 0xFF);
+ version.twoPortAttribute[1] = static_cast<char>((buf[19] >> 8) & 0xFF);
+
+ version.availableBias[0] = static_cast<char>(buf[20] & 0xFF);
+ version.availableBias[1] = static_cast<char>((buf[20] >> 8) & 0xFF);
+
+ std::memcpy(version.moduleType, &buf[21], 10);
+
+ return nRet;
+}
+
+// 璇诲彇鐩爣绔欑偣CPU绫诲瀷
+int CPerformanceMelsec::ReadCPUCode(const StationIdentifier& station, short& nCPUCode) {
+ // 楠岃瘉绔欑偣鍙傛暟鍜屾暟鎹湁鏁堟��
+ int nRet = ValidateStation(station);
+ if (nRet != 0) {
+ UpdateLastError(nRet);
+ return nRet;
+ }
+
+ // 纭繚绾跨▼瀹夊叏鐨勬渶灏忛攣瀹氳寖鍥�
+ {
+ nCPUCode = 0;
+ std::lock_guard<std::mutex> lock(m_mtx);
+ nRet = mdTypeRead(m_nPath, CombineStation(station), &nCPUCode);
+ }
+
+ if (nRet != 0) {
+ UpdateLastError(nRet);
+ LOG_ERROR(m_strLastError);
+ }
+
+ return nRet;
+}
+
+// 鏉挎ā寮忚缃�
+int CPerformanceMelsec::SetBoardMode(const short nMode) {
+ // 妫�鏌ユ槸鍚﹀凡缁忚繛鎺�
+ if (!m_bConnected.load()) {
+ UpdateLastError(ERROR_CODE_NOT_CONNECTED);
+ return ERROR_CODE_NOT_CONNECTED;
+ }
+
+ // 纭繚绾跨▼瀹夊叏鐨勬渶灏忛攣瀹氳寖鍥�
+ short nRet = 0;
+ {
+ std::lock_guard<std::mutex> lock(m_mtx);
+ nRet = mdBdModSet(m_nPath, nMode);
+ }
+
+ if (nRet != 0) {
+ UpdateLastError(nRet);
+ LOG_ERROR(m_strLastError);
+ }
+
+ return nRet;
+}
+
+// 鑾峰彇鏉挎ā寮�
+int CPerformanceMelsec::GetBoardMode(short& nMode) {
+ // 妫�鏌ユ槸鍚﹀凡缁忚繛鎺�
+ if (!m_bConnected.load()) {
+ UpdateLastError(ERROR_CODE_NOT_CONNECTED);
+ return ERROR_CODE_NOT_CONNECTED;
+ }
+
+ short nRet = 0;
+ {
+ nMode = 0;
+ std::lock_guard<std::mutex> lock(m_mtx);
+ nRet = mdBdModRead(m_nPath, &nMode);
+ }
+
+ if (nRet != 0) {
+ UpdateLastError(nRet);
+ LOG_DEBUG("Raw Mode: " << nMode);
+ LOG_ERROR(m_strLastError);
+ }
+
+ return 0;
+}
+
+// 鏉垮浣�
+int CPerformanceMelsec::BoardReset() {
+ std::lock_guard<std::mutex> lock(m_mtx);
+ if (!m_bConnected.load()) {
+ UpdateLastError(ERROR_CODE_NOT_CONNECTED);
+ return ERROR_CODE_NOT_CONNECTED;
+ }
+
+ const short nRet = mdBdRst(m_nPath);
+ if (nRet != 0) {
+ UpdateLastError(nRet);
+ LOG_ERROR(m_strLastError);
+ }
+
+ return nRet;
+}
+
+// 鏉縇ED璇诲彇
+int CPerformanceMelsec::ReadBoardLed(std::vector<short>& vecLedBuffer) {
+ std::lock_guard<std::mutex> lock(m_mtx);
+ if (!m_bConnected.load()) {
+ UpdateLastError(ERROR_CODE_NOT_CONNECTED);
+ return ERROR_CODE_NOT_CONNECTED;
+ }
+
+ // 娓呯┖ LED 缂撳啿鍖�
+ vecLedBuffer.clear();
+ vecLedBuffer.resize(16, 0);
+
+ // 璋冪敤 SDK 鍑芥暟璇诲彇 LED 鏁版嵁
+ const short nRet = mdBdLedRead(m_nPath, vecLedBuffer.data());
+ if (nRet != 0) {
+ UpdateLastError(ERROR_CODE_NOT_CONNECTED);
+ LOG_ERROR("Error reading board LED, ErrorCode: " << nRet);
+ LOG_ERROR(m_strLastError);
+ }
+
+ return nRet;
+}
+
+// 鑾峰彇鏉跨姸鎬�
+int CPerformanceMelsec::GetBoardStatus(BoardStatus& status) {
+ std::lock_guard<std::mutex> lock(m_mtx);
+ if (!m_bConnected) {
+ UpdateLastError(ERROR_CODE_NOT_CONNECTED);
+ return ERROR_CODE_NOT_CONNECTED;
+ }
+
+ short buf[6] = {0};
+ const short nRet = mdBdSwRead(m_nPath, buf);
+ if (nRet != 0) {
+ UpdateLastError(nRet);
+ LOG_ERROR(m_strLastError);
+ }
+
+ // 灏� buf 鏄犲皠鍒扮粨鏋勪綋
+ status = BoardStatus::fromBuffer(buf);
+ return 0;
+}
+
+// 閫氱敤璇绘暟鎹�
+int CPerformanceMelsec::ReadData(const StationIdentifier& station, const short nDevType, const short nDevNo, short nSize, std::vector<short>& vecData) {
+ // 楠岃瘉绔欑偣鍙傛暟鍜屾暟鎹湁鏁堟��
+ int nRet = ValidateStationAndSize(station, nSize);
+ if (nRet != 0) {
+ UpdateLastError(nRet);
+ return nRet;
+ }
+
+ // 鍒濆鍖栬鍙栫紦鍐插尯
+ vecData.clear();
+ vecData.resize(nSize);
+
+ // 纭繚绾跨▼瀹夊叏鐨勬渶灏忛攣瀹氳寖鍥�
+ {
+ std::lock_guard<std::mutex> lock(m_mtx);
+ short* pData = vecData.data();
+ nRet = mdReceive(m_nPath, CombineStation(station), nDevType, nDevNo, &nSize, pData);
+ }
+
+ if (nRet != 0) {
+ UpdateLastError(nRet);
+ LOG_ERROR(m_strLastError);
+ }
+
+ if (nRet != 0) {
+ vecData.clear(); // 濡傛灉璇诲彇澶辫触锛屾竻绌虹紦鍐插尯
+ }
+
+ return nRet;
+}
+
+// 璇诲彇浣嶆暟鎹�
+int CPerformanceMelsec::ReadBitData(const StationIdentifier& station, const DeviceType enDevType, const short nDevNo, const short nBitCount, BitContainer& vecData) {
+ // 楠岃瘉绔欑偣鍙傛暟鍜屾暟鎹湁鏁堟��
+ int nRet = ValidateStationAndSize(station, nBitCount);
+ if (nRet != 0) {
+ UpdateLastError(nRet);
+ return nRet;
+ }
+
+ // 璁$畻闇�瑕佽鍙栫殑瀛楄妭澶у皬锛堟寜浣嶅榻愪负瀛楄妭鏁帮級
+ const short nDevType = CalculateDeviceType(station, enDevType);
+ const auto nSize = static_cast<short>((nBitCount + 7) / 8); // 鍚戜笂鍙栨暣
+ std::vector<short> vecTempBuffer((nSize + 1) / 2, 0); // 涓存椂缂撳啿鍖猴紝瀛楄妭瀵归綈
+ nRet = ReadData(station, nDevType, nDevNo, nSize, vecTempBuffer);
+
+ if (nRet == 0) {
+ std::lock_guard<std::mutex> lock(m_mtx); // 绾跨▼瀹夊叏淇濇姢
+ ConvertShortToUint8(vecTempBuffer, vecData);
+ }
+
+ return nRet;
+}
+
+// 璇诲彇瀛楁暟鎹�
+int CPerformanceMelsec::ReadWordData(const StationIdentifier& station, const DeviceType enDevType, const short nDevNo, const short nWordCount, WordContainer& vecData) {
+ // 楠岃瘉绔欑偣鍙傛暟鍜屾暟鎹湁鏁堟��
+ int nRet = ValidateStationAndSize(station, nWordCount);
+ if (nRet != 0) {
+ UpdateLastError(nRet);
+ return nRet;
+ }
+
+ const short nDevType = CalculateDeviceType(station, enDevType);
+ std::vector<short> vecTempBuffer(nWordCount, 0);
+ nRet = ReadData(station, nDevType, nDevNo, nWordCount, vecTempBuffer);
+
+ if (nRet == 0) {
+ vecData.clear();
+ vecData.assign(vecTempBuffer.begin(), vecTempBuffer.end());
+ }
+
+ return nRet;
+}
+
+// 璇诲彇鍙屽瓧鏁版嵁
+int CPerformanceMelsec::ReadDWordData(const StationIdentifier& station, const DeviceType enDevType, const short nDevNo, const short nDWordCount, DWordContainer& vecData) {
+ // 楠岃瘉绔欑偣鍙傛暟鍜屾暟鎹湁鏁堟��
+ int nRet = ValidateStationAndSize(station, nDWordCount);
+ if (nRet != 0) {
+ UpdateLastError(nRet);
+ return nRet;
+ }
+
+ const auto nSize = static_cast<short>(nDWordCount * 2); // 姣忎釜鍙屽瓧鍗犱袱涓瓧锛堟瘡涓弻瀛楀崰 4 瀛楄妭锛�
+ const short nDevType = CalculateDeviceType(station, enDevType);
+ std::vector<short> vecTempBuffer(nSize, 0);
+ nRet = ReadData(station, nDevType, nDevNo, nSize, vecTempBuffer);
+
+ if (nRet == 0) {
+ std::lock_guard<std::mutex> lock(m_mtx); // 绾跨▼瀹夊叏淇濇姢
+ ConvertShortToUint32(vecTempBuffer, vecData);
+ }
+
+ return nRet;
+}
+
+// 閫氱敤鍐欐暟鎹�
+int CPerformanceMelsec::WriteData(const StationIdentifier& station, const short nDevType, const short nDevNo, short nSize, short* pData) {
+ // 楠岃瘉绔欑偣鍙傛暟
+ int nRet = ValidateStation(station);
+ if (nRet != 0) {
+ UpdateLastError(nRet);
+ return nRet;
+ }
+
+ // 鏁版嵁鏈夋晥鎬�
+ if (nSize < 0 || pData == nullptr) {
+ UpdateLastError(ERROR_CODE_INVALID_PARAM);
+ return ERROR_CODE_INVALID_PARAM;
+ }
+
+ // 纭繚绾跨▼瀹夊叏鐨勬渶灏忛攣瀹氳寖鍥�
+ {
+ std::lock_guard<std::mutex> lock(m_mtx);
+ nRet = mdSend(m_nPath, CombineStation(station), nDevType, nDevNo, &nSize, pData);
+ }
+
+ if (nRet != 0) {
+ UpdateLastError(nRet);
+ LOG_ERROR(m_strLastError);
+ }
+
+ return nRet;
+}
+
+// 鍐欎綅鏁版嵁
+int CPerformanceMelsec::WriteBitData(const StationIdentifier& station, const DeviceType enDevType, const short nDevNo, const BitContainer& vecData) {
+ // 楠岃瘉绔欑偣鍙傛暟鍜屾暟鎹湁鏁堟��
+ const int nRet = ValidateStationAndData(station, vecData);
+ if (nRet != 0) {
+ UpdateLastError(nRet);
+ return nRet;
+ }
+
+ // 璁$畻闇�瑕佸啓鍏ョ殑瀛楄妭鏁帮紙浣嶆暟鎹渶瑕佹寜 8 浣嶅榻愪负瀛楄妭鏁帮級
+ const short nDevType = CalculateDeviceType(station, enDevType);
+ const auto nSize = static_cast<short>((vecData.size() + 7) / 8);
+ std::vector<short> vecBuffer(vecData.size() / 2 + vecData.size() % 2, 0);
+ {
+ std::lock_guard<std::mutex> lock(m_mtx); // 绾跨▼瀹夊叏淇濇姢
+ ConvertUint8ToShort(vecData, vecBuffer);
+ }
+
+ return WriteData(station, nDevType, nDevNo, nSize, vecBuffer.data());
+}
+
+// 鍐欏瓧鏁版嵁
+int CPerformanceMelsec::WriteWordData(const StationIdentifier& station, const DeviceType enDevType, const short nDevNo, const WordContainer& vecData) {
+ // 楠岃瘉绔欑偣鍙傛暟鍜屾暟鎹湁鏁堟��
+ const int nRet = ValidateStationAndData(station, vecData);
+ if (nRet != 0) {
+ UpdateLastError(nRet);
+ return nRet;
+ }
+
+ // 璁$畻闇�瑕佸啓鍏ョ殑瀛楄妭鏁帮紙姣忎釜瀛楀崰 2 瀛楄妭锛�
+ const short nDevType = CalculateDeviceType(station, enDevType);
+ const auto nSize = static_cast<short>(vecData.size() * sizeof(uint16_t));
+ const auto pData = const_cast<short*>(reinterpret_cast<const short*>(vecData.data()));
+
+ return WriteData(station, nDevType, nDevNo, nSize, pData);
+}
+
+// 鍐欏弻瀛楁暟鎹�
+int CPerformanceMelsec::WriteDWordData(const StationIdentifier& station, const DeviceType enDevType, const short nDevNo, const DWordContainer& vecData) {
+ // 楠岃瘉绔欑偣鍙傛暟鍜屾暟鎹湁鏁堟��
+ const int nRet = ValidateStationAndData(station, vecData);
+ if (nRet != 0) {
+ UpdateLastError(nRet);
+ return nRet;
+ }
+
+ // 璁$畻闇�瑕佸啓鍏ョ殑瀛楄妭鏁帮紙姣忎釜鍙屽瓧鍗� 4 瀛楄妭锛�
+ const short nDevType = CalculateDeviceType(station, enDevType);
+ const auto nSize = static_cast<short>(vecData.size() * sizeof(uint32_t));
+ std::vector<short> vecBuffer(vecData.size() * 2, 0);
+ {
+ std::lock_guard<std::mutex> lock(m_mtx); // 绾跨▼瀹夊叏淇濇姢
+ ConvertUint32ToShort(vecData, vecBuffer);
+ }
+
+ return WriteData(station, nDevType, nDevNo, nSize, vecBuffer.data());
+}
+
+// 鎵╁睍璇绘暟鎹�
+long CPerformanceMelsec::ReadDataEx(const StationIdentifier& station, long nDevType, long nDevNo, long nSize, std::vector<char>& vecData) {
+ // 楠岃瘉绔欑偣鍙傛暟鍜岃鍙栧ぇ灏忔槸鍚︽湁鏁�
+ long nRet = ValidateStation(station);
+ if (nRet != 0) {
+ UpdateLastError(nRet);
+ return nRet;
+ }
+
+ if (nSize < 0) {
+ UpdateLastError(ERROR_CODE_INVALID_PARAM);
+ return ERROR_CODE_INVALID_PARAM;
+ }
+
+ vecData.resize(nSize);
+ long nActualSize = (nSize + 1) / 2;
+ std::vector<short> vecBuffer(nActualSize, 0);
+
+ {
+ std::lock_guard<std::mutex> lock(m_mtx); // 绾跨▼瀹夊叏淇濇姢
+ nRet = mdReceiveEx(m_nPath, station.nNetNo, station.nStNo, nDevType, nDevNo, &nActualSize, vecBuffer.data());
+ }
+
+ if (nRet != 0) {
+ UpdateLastError(nRet);
+ LOG_ERROR(m_strLastError);
+ } else {
+ std::lock_guard<std::mutex> lock(m_mtx); // 绾跨▼瀹夊叏淇濇姢
+ ConvertShortToChar(vecBuffer, vecData);
+ }
+
+ return 0;
+}
+
+// 鎵╁睍鍐欐暟鎹�
+long CPerformanceMelsec::WriteDataEx(const StationIdentifier& station, long nDevType, long nDevNo, const std::vector<char>& vecData) {
+ // 楠岃瘉绔欑偣鍙傛暟鍜屾暟鎹湁鏁堟��
+ long nRet = ValidateStationAndData(station, vecData);
+ if (nRet != 0) {
+ UpdateLastError(nRet);
+ return nRet;
+ }
+
+ // 灏� vecData 杞崲涓� short 绫诲瀷鐨勭紦鍐插尯
+ long nSize = static_cast<long>(vecData.size());
+ std::vector<short> vecBuffer((nSize + 1) / 2, 0);
+
+ {
+ std::lock_guard<std::mutex> lock(m_mtx); // 绾跨▼瀹夊叏淇濇姢
+ ConvertCharToShort(vecData, vecBuffer);
+ nRet = mdSendEx(m_nPath, station.nNetNo, station.nStNo, nDevType, nDevNo, &nSize, vecBuffer.data());
+ }
+
+ // 閿欒澶勭悊鍜屾棩蹇楄褰�
+ if (nRet != 0) {
+ UpdateLastError(nRet);
+ LOG_ERROR(m_strLastError);
+ }
+
+ return nRet;
+}
+
+// 鎵╁睍杞厓浠堕殢鏈鸿鍙�
+long CPerformanceMelsec::ReadRandomDataEx(const StationIdentifier& station, const std::vector<SoftElement>& vecSoftElements, std::vector<char>& vecData) {
+ if (vecSoftElements.empty()) {
+ UpdateLastError(ERROR_INVALID_PARAMETER);
+ LOG_ERROR("Invalid parameters: soft elements are empty.");
+ return ERROR_INVALID_PARAMETER;
+ }
+
+ // 鍑嗗 dev 鏁版嵁
+ std::vector<short> devBuffer(vecSoftElements.size() * 3 + 1, 0); // 姣忎釜杞厓浠堕渶瑕� 3 涓� short锛屽鍔犱竴涓鏁板櫒
+ devBuffer[0] = static_cast<short>(vecSoftElements.size()); // 绗竴涓厓绱犳槸杞厓浠舵暟閲�
+ for (size_t i = 0; i < vecSoftElements.size(); ++i) {
+ const SoftElement& element = vecSoftElements[i];
+ devBuffer[i * 3 + 1] = element.nType; // 杞厓浠剁被鍨�
+ devBuffer[i * 3 + 2] = static_cast<short>(element.nStartNo); // 璧峰杞厓浠剁紪鍙�
+ devBuffer[i * 3 + 3] = element.nElementCount; // 鐐规暟
+ }
+
+ // 璁$畻璇诲彇鏁版嵁鎵�闇�缂撳啿鍖哄ぇ灏�
+ long nBufferSize = 0;
+ for (const auto& element : vecSoftElements) {
+ nBufferSize += element.nElementCount * 2; // 姣忎釜鐐瑰崰鐢� 2 涓瓧鑺�
+ }
+
+ // 閿佷繚鎶ゅ強璋冪敤 mdRandREx
+ long nRet = 0;
+ std::vector<short> vecBuffer(nBufferSize / 2, 0);
+ {
+ std::lock_guard<std::mutex> lock(m_mtx); // 纭繚绾跨▼瀹夊叏
+ nRet = mdRandREx(m_nPath, station.nNetNo, station.nStNo, devBuffer.data(), vecBuffer.data(), nBufferSize);
+ }
+
+ // 閿欒澶勭悊鍜屾棩蹇楄褰�
+ if (nRet != 0) {
+ UpdateLastError(nRet);
+ LOG_ERROR(m_strLastError);
+ return nRet;
+ }
+
+ // 灏嗚鍙栧埌鐨� short 鏁版嵁杞崲涓� char 鏁版嵁
+ vecData.resize(nBufferSize);
+ for (size_t i = 0; i < vecBuffer.size(); ++i) {
+ vecData[i * 2] = static_cast<char>(vecBuffer[i] & 0xFF); // 浣庡瓧鑺�
+ vecData[i * 2 + 1] = static_cast<char>((vecBuffer[i] >> 8) & 0xFF); // 楂樺瓧鑺�
+ }
+
+ return nRet;
+}
+
+// 鎵╁睍杞厓浠堕殢鏈哄啓鍏ワ紙鏀寔澶氫釜杞厓浠讹級
+long CPerformanceMelsec::WriteRandomDataEx(const StationIdentifier& station, const std::vector<SoftElement>& vecSoftElements, const std::vector<char>& vecData) {
+ if (vecSoftElements.empty() || vecData.empty()) {
+ UpdateLastError(ERROR_INVALID_PARAMETER);
+ LOG_ERROR("Invalid parameters: soft elements or data is empty.");
+ return ERROR_INVALID_PARAMETER;
+ }
+
+ // 鍑嗗 dev 鏁版嵁
+ std::vector<long> devBuffer(vecSoftElements.size() * 3 + 1, 0); // 姣忎釜杞厓浠堕渶瑕� 3 涓� long锛屽鍔犱竴涓鏁板櫒
+ devBuffer[0] = static_cast<long>(vecSoftElements.size()); // 绗竴涓厓绱犳槸杞厓浠舵暟閲�
+ for (size_t i = 0; i < vecSoftElements.size(); ++i) {
+ const SoftElement& element = vecSoftElements[i];
+ devBuffer[i * 3 + 1] = static_cast<long>(element.nType); // 杞厓浠剁被鍨�
+ devBuffer[i * 3 + 2] = element.nStartNo; // 璧峰杞厓浠剁紪鍙凤紙宸茬粡鏄� long 绫诲瀷锛屾棤闇�杞崲锛�
+ devBuffer[i * 3 + 3] = static_cast<long>(element.nElementCount); // 鐐规暟
+ }
+
+ // 閿佷繚鎶ゅ強璋冪敤 mdRandWEx
+ long nRet = 0;
+ std::vector<short> vecBuffer(vecData.size() / 2, 0);
+ {
+ std::lock_guard<std::mutex> lock(m_mtx); // 纭繚绾跨▼瀹夊叏
+ ConvertCharToShort(vecData, vecBuffer);
+ nRet = mdRandWEx(m_nPath, station.nNetNo, station.nStNo, devBuffer.data(), vecBuffer.data(), static_cast<long>(vecBuffer.size()));
+ }
+
+ // 閿欒澶勭悊鍜屾棩蹇楄褰�
+ if (nRet != 0) {
+ UpdateLastError(nRet);
+ LOG_ERROR(m_strLastError);
+ }
+
+ return nRet;
+}
+
+// 杩滅▼璁惧绔�/杩滅▼绔欑殑缂撳啿瀛樺偍鍣ㄨ鍙�
+long CPerformanceMelsec::ReadRemoteBuffer(const StationIdentifier& station, long nOffset, long nSize, std::vector<char>& vecData) {
+ // 楠岃瘉绔欑偣鍙傛暟鍜屾暟鎹湁鏁堟��
+ int nRet = ValidateStation(station);
+ if (nRet != 0) {
+ UpdateLastError(nRet);
+ return nRet;
+ }
+
+ if (nSize < 0) {
+ UpdateLastError(ERROR_CODE_INVALID_PARAM);
+ return ERROR_CODE_INVALID_PARAM;
+ }
+
+ long nActualSize = (nSize + 1) / 2;
+ std::vector<short> vecBuffer(nActualSize, 0);
+ {
+ std::lock_guard<std::mutex> lock(m_mtx); // 绾跨▼瀹夊叏淇濇姢
+ nRet = mdRemBufReadEx(m_nPath, station.nNetNo, station.nStNo, nOffset, &nActualSize, vecBuffer.data());
+ }
+
+ if (nRet != 0) {
+ UpdateLastError(nRet); // 鏇存柊閿欒鐮�
+ LOG_ERROR(m_strLastError);
+ } else {
+ std::lock_guard<std::mutex> lock(m_mtx); // 绾跨▼瀹夊叏淇濇姢
+ ConvertShortToChar(vecBuffer, vecData);
+ }
+
+ return nRet;
+}
+
+// 杩滅▼璁惧绔�/杩滅▼绔欑殑缂撳啿瀛樺偍鍣ㄥ啓鍏�
+long CPerformanceMelsec::WriteRemoteBuffer(const StationIdentifier& station, long nOffset, const std::vector<char>& vecData) {
+ // 楠岃瘉绔欑偣鍙傛暟鍜屾暟鎹湁鏁堟��
+ long nRet = ValidateStationAndData(station, vecData);
+ if (nRet != 0) {
+ UpdateLastError(nRet);
+ return nRet;
+ }
+
+ // 灏� vecData 杞崲涓� short 绫诲瀷鐨勭紦鍐插尯
+ long nSize = static_cast<long>(vecData.size());
+ std::vector<short> vecBuffer((nSize + 1) / 2, 0);
+
+ {
+ std::lock_guard<std::mutex> lock(m_mtx); // 绾跨▼瀹夊叏淇濇姢
+ ConvertCharToShort(vecData, vecBuffer);
+ nRet = mdRemBufWriteEx(m_nPath, station.nNetNo, station.nStNo, nOffset, &nSize, vecBuffer.data());
+ }
+
+ if (nRet != 0) {
+ UpdateLastError(nRet);
+ LOG_ERROR(m_strLastError);
+ }
+
+ return nRet;
+}
+
+// 杩滅▼绔欑殑缂撳啿瀛樺偍鍣ㄨ鍙� 瀵硅薄绔橧P鍦板潃鎸囧畾
+long CPerformanceMelsec::ReadRemoteBufferByIp(const std::string& strIP, long nOffset, long nSize, std::vector<char>& vecData) {
+ uint32_t nAddress = 0;
+ if (nSize < 0 || !ConvertIpStringToUint32(strIP, nAddress)) {
+ UpdateLastError(ERROR_CODE_INVALID_PARAM);
+ return ERROR_CODE_INVALID_PARAM;
+ }
+
+ // 灏嗙紦鍐插尯澶у皬璋冩暣涓� nSize
+ vecData.resize(nSize, 0);
+ std::vector<short> vecBuffer((nSize + 1) / 2, 0); // 杞崲涓� short 绫诲瀷
+
+ // 璋冪敤搴曞眰 SDK
+ long nRet = 0;
+ {
+ std::lock_guard<std::mutex> lock(m_mtx); // 绾跨▼瀹夊叏淇濇姢
+ nRet = mdRemBufReadIPEx(m_nPath, static_cast<long>(nAddress), nOffset, &nSize, vecBuffer.data());
+ }
+
+ if (nRet != 0) {
+ UpdateLastError(nRet);
+ LOG_ERROR(m_strLastError);
+ } else {
+ std::lock_guard<std::mutex> lock(m_mtx); // 绾跨▼瀹夊叏淇濇姢
+ ConvertShortToChar(vecBuffer, vecData);
+ }
+
+ return nRet;
+}
+
+// 杩滅▼绔欑殑缂撳啿瀛樺偍鍣ㄥ啓鍏� 瀵硅薄绔橧P鍦板潃鎸囧畾
+long CPerformanceMelsec::WriteRemoteBufferByIp(const std::string& strIP, long nOffset, const std::vector<char>& vecData) {
+ uint32_t nAddress = 0;
+ if (vecData.empty() || !ConvertIpStringToUint32(strIP, nAddress)) {
+ UpdateLastError(ERROR_CODE_INVALID_PARAM);
+ return ERROR_CODE_INVALID_PARAM;
+ }
+
+ // 杞崲 vecData 涓� short 绫诲瀷鐨勭紦鍐插尯
+ long nSize = static_cast<long>(vecData.size());
+ std::vector<short> vecBuffer((nSize + 1) / 2, 0);
+
+ long nRet = 0;
+ {
+ std::lock_guard<std::mutex> lock(m_mtx); // 绾跨▼瀹夊叏
+ ConvertCharToShort(vecData, vecBuffer);
+ nRet = mdRemBufWriteIPEx(m_nPath, static_cast<long>(nAddress), nOffset, &nSize, vecBuffer.data());
+ }
+
+ if (nRet != 0) {
+ UpdateLastError(nRet);
+ LOG_ERROR(m_strLastError);
+ }
+
+ return nRet;
+}
+
+// 璁剧疆(ON)瀵硅薄绔欑殑鎸囧畾浣嶈蒋鍏冧欢
+int CPerformanceMelsec::SetBitDevice(const StationIdentifier& station, const DeviceType enDevType, const short nDevNo) {
+ // 楠岃瘉绔欑偣鍙傛暟
+ int nRet = ValidateStation(station);
+ if (nRet != 0) {
+ UpdateLastError(nRet);
+ return nRet;
+ }
+
+ // 纭繚绾跨▼瀹夊叏鐨勬渶灏忛攣瀹氳寖鍥�
+ {
+ std::lock_guard<std::mutex> lock(m_mtx); // 绾跨▼瀹夊叏
+ const short nDevType = CalculateDeviceType(station, enDevType);
+ nRet = mdDevSet(m_nPath, CombineStation(station), nDevType, nDevNo);
+ }
+
+ if (nRet != 0) {
+ UpdateLastError(nRet);
+ LOG_ERROR(m_strLastError);
+ }
+
+ return nRet;
+}
+
+// 澶嶄綅(OFF)瀵硅薄绔欑殑鎸囧畾浣嶈蒋鍏冧欢
+int CPerformanceMelsec::ResetBitDevice(const StationIdentifier& station, const DeviceType enDevType, const short enDevNo) {
+ // 楠岃瘉绔欑偣鍙傛暟
+ int nRet = ValidateStation(station);
+ if (nRet != 0) {
+ UpdateLastError(nRet);
+ return nRet;
+ }
+
+ // 纭繚绾跨▼瀹夊叏鐨勬渶灏忛攣瀹氳寖鍥�
+ {
+ std::lock_guard<std::mutex> lock(m_mtx);
+ const short nDevType = CalculateDeviceType(station, enDevType);
+ nRet = mdDevRst(m_nPath, CombineStation(station), nDevType, enDevNo);
+ }
+
+ if (nRet != 0) {
+ UpdateLastError(nRet);
+ LOG_ERROR(m_strLastError);
+ }
+
+ return nRet;
+}
+
+// 鎵╁睍浣嶈蒋鍏冧欢璁剧疆
+long CPerformanceMelsec::SetBitDeviceEx(const StationIdentifier& station, long nDevType, long nDevNo) {
+ std::lock_guard<std::mutex> lock(m_mtx);
+
+ // 妫�鏌ュ弬鏁版湁鏁堟��
+ long nRet = ValidateStation(station);
+ if (nRet != 0) {
+ UpdateLastError(nRet);
+ return nRet;
+ }
+
+ nRet = mdDevSetEx(m_nPath, station.nNetNo, station.nStNo, nDevType, nDevNo);
+ if (nRet != 0) {
+ UpdateLastError(nRet);
+ LOG_ERROR(m_strLastError);
+ }
+
+ return nRet;
+}
+
+// 鎵╁睍浣嶈蒋鍏冧欢澶嶄綅
+long CPerformanceMelsec::ResetBitDeviceEx(const StationIdentifier& station, long nDevType, long nDevNo) {
+ std::lock_guard<std::mutex> lock(m_mtx);
+
+ // 妫�鏌ュ弬鏁版湁鏁堟��
+ long nRet = ValidateStation(station);
+ if (nRet != 0) {
+ UpdateLastError(nRet);
+ return nRet;
+ }
+
+ nRet = mdDevRstEx(m_nPath, station.nNetNo, station.nStNo, nDevType, nDevNo);
+ if (nRet != 0) {
+ UpdateLastError(nRet);
+ LOG_ERROR(m_strLastError);
+ }
+
+ return nRet;
+}
+
+// 鎵ц瀵硅薄绔欑殑CPU
+int CPerformanceMelsec::ControlCPU(const StationIdentifier& station, ControlCode enControlCode) {
+ // 楠岃瘉绔欑偣鍙傛暟鍜屾暟鎹湁鏁堟��
+ int nRet = ValidateStation(station);
+ if (nRet != 0) {
+ UpdateLastError(nRet);
+ return nRet;
+ }
+
+ // 楠岃瘉鎺у埗鐮佹槸鍚﹀悎娉�
+ const auto nControlCode = static_cast<short>(enControlCode);
+ if (nControlCode < 0 || nControlCode > 2) {
+ UpdateLastError(ERROR_CODE_INVALID_PARAM); // 鍙傛暟閿欒
+ return ERROR_CODE_INVALID_PARAM;
+ }
+
+ // 纭繚绾跨▼瀹夊叏鐨勬渶灏忛攣瀹氳寖鍥�
+ {
+ std::lock_guard<std::mutex> lock(m_mtx);
+ nRet = mdControl(m_nPath, CombineStation(station), nControlCode);
+ }
+
+ if (nRet != 0) {
+ UpdateLastError(nRet);
+ LOG_ERROR(m_strLastError);
+ }
+
+ return nRet;
+}
+
+// 浜嬩欢绛夊緟
+int CPerformanceMelsec::WaitForBoardEvent(std::vector<short> vecEventNumbers, const int nTimeoutMs, EventDetails& details) {
+ std::lock_guard<std::mutex> lock(m_mtx);
+
+ if (!m_bConnected.load()) {
+ UpdateLastError(ERROR_CODE_NOT_CONNECTED);
+ return ERROR_CODE_NOT_CONNECTED;
+ }
+
+ if (vecEventNumbers.empty() || vecEventNumbers.size() > 64) {
+ UpdateLastError(ERROR_CODE_INVALID_PARAM);
+ return ERROR_CODE_INVALID_PARAM;
+ }
+
+ // 绗� 0 涓厓绱犲瓨鍌ㄦ暟閲忥紝鏈�澶ф敮鎸� 64 涓簨浠�
+ std::array<short, 65> eventno = {0};
+ eventno[0] = static_cast<short>(vecEventNumbers.size());
+ std::copy(vecEventNumbers.begin(), vecEventNumbers.end(), eventno.begin() + 1);
+
+ // 鍒濆鍖栬緭鍑哄弬鏁�
+ details.nEventNo = 0;
+ details.details.fill(0);
+
+ const int nRet = mdWaitBdEvent(m_nPath, eventno.data(), nTimeoutMs, &details.nEventNo, details.details.data());
+ if (nRet != 0) {
+ UpdateLastError(nRet);
+ LOG_ERROR(m_strLastError);
+ }
+
+ return nRet;
+}
+
+//============================================杈呭姪鍑芥暟=======================================================
+// 鏇存柊鏈�杩戠殑閿欒淇℃伅
+void CPerformanceMelsec::UpdateLastError(const int nCode) {
+ if (nCode == 0) {
+ return;
+ }
+
+ // 妫�鏌ラ敊璇爜鏄惁瀛樺湪浜庢槧灏勮〃涓�
+ const auto it = m_mapError.find(nCode);
+ if (it != m_mapError.end()) {
+ // 濡傛灉鎵惧埌锛岀洿鎺ヨ繑鍥炲搴旇瑷�鐨勯敊璇俊鎭�
+ m_strLastError = it->second;
+ } else {
+ // 濡傛灉鏈壘鍒帮紝澶勭悊鐗规畩鑼冨洿
+ m_strLastError = "Unknown error.";
+ if (nCode == -28611 || nCode == -28612) {
+ // 绯荤粺鍑洪敊
+ m_strLastError = "System error.";
+ }
+
+ if (nCode >= -20480 && nCode <= -16384) {
+ // CC-Link 绯荤粺妫�娴嬪嚭鐨勯敊璇�
+ m_strLastError = "Error detected in the CC-Link system.";
+ }
+
+ if (nCode >= -12288 && nCode <= -8193) {
+ // CC-Link IE TSN 绯荤粺妫�娴嬪嚭鐨勯敊璇�
+ m_strLastError = "Error detected in the CC-Link IE TSN system.";
+ }
+
+ if (nCode >= -8192 && nCode <= -4097) {
+ // CC-Link IE 鎺у埗缃戠粶绯荤粺妫�娴嬪嚭鐨勯敊璇�
+ m_strLastError = "Error detected in the CC-Link IE control network system.";
+ }
+
+ if (nCode >= -4096 && nCode <= -257) {
+ // MELSECNET/10 鎴� MELSECNET/缃戠粶绯荤粺閿欒鑼冨洿
+ m_strLastError = "Errors detected in MELSECNET/10 or MELSECNET/network system.";
+ }
+
+ if (nCode >= 4096 && nCode <= 16383) {
+ // MELSEC 鏁版嵁閾炬帴搴撹寖鍥�
+ m_strLastError = "Internal error detected by MELSEC Data Link Library.";
+ }
+
+ if (nCode == 18944 || nCode == 18945) {
+ // 閾炬帴鍏宠仈鍑洪敊
+ m_strLastError = "Link association error: Network does not exist, unsupported CPU, or incorrect network No./station number.";
+ }
+
+ if (nCode >= 16384 && nCode <= 20479) {
+ // PLC CPU 妫�娴嬭寖鍥�
+ m_strLastError = "Errors detected by the programmable controller CPU in the target station.";
+ }
+
+ if (nCode >= 28416 && nCode <= 28671) {
+ // 鍐椾綑鍔熻兘妯″潡鑼冨洿
+ m_strLastError = "Error detected in the redundancy module of the target station.";
+ }
+ }
+}
+
+// 妫�鏌ヨ繛鎺ョ姸鎬佸拰绔欑偣鍙傛暟鏈夋晥鎬�
+int CPerformanceMelsec::ValidateStation(const StationIdentifier& station) const {
+ // 妫�鏌ユ槸鍚﹀凡杩炴帴
+ if (!m_bConnected.load()) {
+ return ERROR_CODE_NOT_CONNECTED;
+ }
+
+ // 妫�鏌ョ綉缁滃彿鍜岀珯鐐瑰彿鑼冨洿
+ if (station.nNetNo < 0 || station.nNetNo > 239 || station.nStNo < 0 || station.nStNo > 255) {
+ return ERROR_CODE_INVALID_PARAM;
+ }
+
+ return 0; // 鍙傛暟鏈夋晥
+}
+
+// 楠岃瘉绔欑偣鍙傛暟鍜屾暟鎹湁鏁堟��
+int CPerformanceMelsec::ValidateStationAndSize(const StationIdentifier& station, const short nCount) const {
+ // 楠岃瘉绔欑偣鍙傛暟
+ const int nRet = ValidateStation(station);
+ if (nRet != 0) {
+ return nRet; // 濡傛灉绔欑偣楠岃瘉澶辫触锛岃繑鍥炲搴旈敊璇爜
+ }
+
+ if (nCount <= 0) {
+ return ERROR_CODE_INVALID_PARAM;
+ }
+
+ return 0; // 楠岃瘉閫氳繃
+}
+
+// IP瀛楃涓茶浆uint32_t
+bool CPerformanceMelsec::ConvertIpStringToUint32(const std::string& strIP, uint32_t& nIP) {
+ nIP = 0;
+ std::stringstream ss(strIP);
+ std::string strSegment;
+ int nShift = 24;
+
+ while (std::getline(ss, strSegment, '.')) {
+ const auto nByte = static_cast<uint32_t>(std::stoi(strSegment));
+ if (nByte > 255) {
+ return false;
+ }
+ nIP |= (nByte << nShift);
+ nShift -= 8;
+ }
+
+ return true;
+}
+
+//============================================闈欐�佽緟鍔╁嚱鏁�====================================================
+// 寤舵椂锛屽苟涓旇浆鍙戠獥鍙f秷鎭�
+void CPerformanceMelsec::Delay(const unsigned int nDelayMs) {
+ MSG message;
+ // 濡傛灉寤惰繜鏃堕棿涓� 0锛屼粎澶勭悊涓�娆℃秷鎭槦鍒�
+ if (nDelayMs == 0) {
+ // 闈為樆濉炵殑妫�鏌ユ秷鎭槦鍒�
+ if (PeekMessage(&message, nullptr, 0, 0, PM_REMOVE)) {
+ TranslateMessage(&message); // 灏嗘秷鎭浆鍖栦负鏈夋晥鐨勭獥鍙f秷鎭�
+ DispatchMessage(&message); // 娲惧彂娑堟伅缁欑浉搴旂殑绐楀彛杩囩▼
+ }
+ return;
+ }
+
+ DWORD finish;
+ const DWORD start = GetTickCount(); // 鑾峰彇褰撳墠鐨勬椂闂存埑锛堜粠绯荤粺鍚姩浠ユ潵鐨勬绉掓暟锛�
+ do {
+ if (PeekMessage(&message, nullptr, 0, 0, PM_REMOVE)) {
+ TranslateMessage(&message); // 杞崲娑堟伅
+ DispatchMessage(&message); // 澶勭悊娑堟伅
+ }
+ Sleep(1); // 鏆傚仠 1 姣锛岄槻姝㈣繃搴﹀崰鐢� CPU
+ finish = GetTickCount(); // 鑾峰彇褰撳墠鐨勬椂闂存埑
+ } while ((finish - start) < nDelayMs); // 寰幆鐩村埌缁忚繃鐨勬椂闂村ぇ浜庢寚瀹氱殑寤惰繜鏃堕棿
+}
+
+BoardType CPerformanceMelsec::FindBoardTypeByChannel(const int nChannel) {
+ if (nChannel >= MELSECNET_CHANNEL(1) && nChannel <= MELSECNET_CHANNEL(4)) {
+ return BoardType::MELSECNET_H;
+ } else if (nChannel >= CC_LINK_CHANNEL(1) && nChannel <= CC_LINK_CHANNEL(4)) {
+ return BoardType::CC_LINK_VER_2;
+ } else if (nChannel >= CC_LINK_IE_CONTROL_CHANNEL(1) && nChannel <= CC_LINK_IE_CONTROL_CHANNEL(4)) {
+ return BoardType::CC_LINK_IE_CONTROL;
+ } else if (nChannel >= CC_LINK_IE_FIELD_CHANNEL(1) && nChannel <= CC_LINK_IE_FIELD_CHANNEL(4)) {
+ return BoardType::CC_LINK_IE_FIELD;
+ } else if (nChannel >= CC_LINK_IE_TSN_CHANNEL(1) && nChannel <= CC_LINK_IE_TSN_CHANNEL(4)) {
+ return BoardType::CC_LINK_IE_TSN;
+ }
+ return BoardType::UNKNOWN;
+}
+
+// 鍚堝苟缃戠粶鍙峰拰绔欑偣鍙�
+short CPerformanceMelsec::CombineStation(const StationIdentifier& station) {
+ return static_cast<short>(station.nStNo | ((station.nNetNo << 8) & 0xFF00));
+}
+
+// 璁$畻杞厓浠剁被鍨�
+short CPerformanceMelsec::CalculateDeviceType(const StationIdentifier& station, DeviceType enDevType) {
+ int nDevType = static_cast<int>(enDevType);
+
+ // 鏍规嵁杞厓浠剁被鍨嬬殑鐗瑰畾瑙勫垯杩涜璁$畻
+ if (enDevType == DeviceType::LX || enDevType == DeviceType::LY ||
+ enDevType == DeviceType::LB || enDevType == DeviceType::LW ||
+ enDevType == DeviceType::LSB || enDevType == DeviceType::LSW) {
+ // 缃戠粶鍙峰姞鍋忕Щ
+ nDevType += station.nNetNo;
+ } else if (enDevType == DeviceType::ER) {
+ // 鏂囦欢瀵勫瓨鍣ㄧ殑鍧楀彿鍔犲亸绉�
+ nDevType += 0;
+ } else if (enDevType == DeviceType::SPG) {
+ // 璧峰 I/O No. 梅 16 鐨勫��
+ nDevType += 0 / 16;
+ }
+
+ return static_cast<short>(nDevType);
+}
+
+// std::vector<char>杞崲涓簊td::vector<short>
+void CPerformanceMelsec::ConvertCharToShort(const std::vector<char>& vecChar, std::vector<short>& vecShort) {
+ vecShort.resize((vecChar.size() + 1) / 2, 0); // 璋冩暣 short 瀹瑰櫒澶у皬
+ for (size_t i = 0; i < vecChar.size(); i++) {
+ if (i % 2 == 0) {
+ vecShort[i / 2] = static_cast<unsigned char>(vecChar[i]); // 浣庡瓧鑺�
+ } else {
+ vecShort[i / 2] |= static_cast<unsigned char>(vecChar[i]) << 8; // 楂樺瓧鑺�
+ }
+ }
+}
+
+// std::vector<short>杞崲涓簊td::vector<char>
+void CPerformanceMelsec::ConvertShortToChar(const std::vector<short>& vecShort, std::vector<char>& vecChar) {
+ vecChar.resize(vecShort.size() * 2); // 璋冩暣 char 瀹瑰櫒澶у皬
+ for (size_t i = 0; i < vecShort.size(); i++) {
+ vecChar[i * 2] = static_cast<char>(vecShort[i] & 0xFF); // 浣庡瓧鑺�
+ vecChar[i * 2 + 1] = static_cast<char>((vecShort[i] >> 8) & 0xFF); // 楂樺瓧鑺�
+ }
+}
+
+// std::vector<uint8_t>杞崲涓簊td::vector<short>
+void CPerformanceMelsec::ConvertUint8ToShort(const std::vector<uint8_t>& vecUint8, std::vector<short>& vecShort) {
+ vecShort.resize((vecUint8.size() + 1) / 2, 0); // 璋冩暣 short 瀹瑰櫒澶у皬
+ for (size_t i = 0; i < vecUint8.size(); i++) {
+ if (i % 2 == 0) {
+ vecShort[i / 2] = static_cast<short>(vecUint8[i]); // 浣庡瓧鑺�
+ } else {
+ vecShort[i / 2] |= static_cast<short>(vecUint8[i] << 8); // 楂樺瓧鑺�
+ }
+ }
+}
+
+// std::vector<short>杞崲涓簊td::vector<uint8_t>
+void CPerformanceMelsec::ConvertShortToUint8(const std::vector<short>& vecShort, std::vector<uint8_t>& vecUint8) {
+ vecUint8.resize(vecShort.size() * 2); // 璋冩暣 uint8_t 瀹瑰櫒澶у皬
+ for (size_t i = 0; i < vecShort.size(); i++) {
+ vecUint8[i * 2] = static_cast<uint8_t>(vecShort[i] & 0xFF); // 浣庡瓧鑺�
+ vecUint8[i * 2 + 1] = static_cast<uint8_t>((vecShort[i] >> 8) & 0xFF); // 楂樺瓧鑺�
+ }
+}
+
+// std::vector<uint32_t>杞崲涓簊td::vector<short>
+void CPerformanceMelsec::ConvertUint32ToShort(const std::vector<uint32_t>& vecUint32, std::vector<short>& vecShort) {
+ vecShort.resize(vecUint32.size() * 2); // 姣忎釜 uint32_t 杞崲涓轰袱涓� short
+ for (size_t i = 0; i < vecUint32.size(); i++) {
+ vecShort[i * 2] = static_cast<short>(vecUint32[i] & 0xFFFF); // 浣�16浣�
+ vecShort[i * 2 + 1] = static_cast<short>((vecUint32[i] >> 16) & 0xFFFF); // 楂�16浣�
+ }
+}
+
+// std::vector<short>杞崲涓簊td::vector<uint32_t>
+void CPerformanceMelsec::ConvertShortToUint32(const std::vector<short>& vecShort, std::vector<uint32_t>& vecUint32) {
+ vecUint32.resize((vecShort.size() + 1) / 2, 0); // 姣忎袱涓� short 鍚堝苟涓轰竴涓� uint32_t
+ for (size_t i = 0; i < vecUint32.size(); i++) {
+ vecUint32[i] = (static_cast<uint32_t>(static_cast<uint16_t>(vecShort[i * 2 + 1])) << 16) | // 楂�16浣�
+ static_cast<uint32_t>(static_cast<uint16_t>(vecShort[i * 2])); // 浣�16浣�
+ }
+}
+
+//============================================妯℃澘杈呭姪鍑芥暟====================================================
+// 楠岃瘉绔欑偣鍙傛暟鍜屾暟鎹湁鏁堟��
+template <typename T>
+int CPerformanceMelsec::ValidateStationAndData(const StationIdentifier& station, const std::vector<T>& vecData) {
+ // 楠岃瘉绔欑偣鍙傛暟
+ const int nRet = ValidateStation(station);
+ if (nRet != 0) {
+ return nRet; // 濡傛灉绔欑偣楠岃瘉澶辫触锛岃繑鍥炲搴旈敊璇爜
+ }
+
+ // 楠岃瘉鏁版嵁鏄惁涓虹┖
+ if (vecData.empty()) {
+ return ERROR_CODE_INVALID_PARAM;
+ }
+
+ return 0; // 楠岃瘉閫氳繃
+}
+
+// 鐢变綆杞珮瀹瑰櫒鐨勬ā鏉匡紙鏁村瀷锛�
+template <typename T, typename U>
+void CPerformanceMelsec::ConvertLowToHigh(const std::vector<T>& vecLow, std::vector<U>& vecHigh) {
+ static_assert(std::is_integral<T>::value && std::is_integral<U>::value, "T and U must be integral types");
+
+ // 鑷姩璁$畻 nGroupSize
+ constexpr size_t nGroupSize = sizeof(U) / sizeof(T);
+
+ // 濡傛灉 T 鍜� U 鐨勫ぇ灏忕浉绛夛紝鐩存帴杞崲
+ if (sizeof(T) == sizeof(U)) {
+ vecHigh.assign(vecLow.begin(), vecLow.end());
+ return;
+ }
+
+ // 濡傛灉 U 鐨勫ぇ灏忔槸 T 鐨勫�嶆暟锛屾甯哥粍鍚�
+ static_assert(sizeof(U) > sizeof(T), "Size of U must be greater than or equal to size of T");
+
+ // 璁$畻瀹屾暣缁勭殑鏁伴噺
+ size_t nHighSize = (vecLow.size() + nGroupSize - 1) / nGroupSize; // 鍚戜笂鍙栨暣
+ vecHigh.resize(nHighSize, 0);
+
+ // 鍚堝苟浣庝綅鏁版嵁鍒伴珮浣嶆暟鎹�
+ for (size_t i = 0; i < vecLow.size(); i++) {
+ vecHigh[i / nGroupSize] |= (static_cast<U>(vecLow[i]) << ((i % nGroupSize) * CHAR_BIT * sizeof(T)));
+ }
+
+ return vecHigh;
+}
+
+// 鐢遍珮杞綆瀹瑰櫒鐨勬ā鏉匡紙鏁村瀷锛�
+template <typename T, typename U>
+void CPerformanceMelsec::ConvertHighToLow(const std::vector<T>& vecHigh, std::vector<U>& vecLow) {
+ static_assert(std::is_integral<T>::value && std::is_integral<U>::value, "T and U must be integral types");
+
+ // 鑷姩璁$畻 nGroupSize
+ constexpr size_t nGroupSize = sizeof(T) / sizeof(U);
+
+ // 濡傛灉 T 鍜� U 鐨勫ぇ灏忕浉绛夛紝鐩存帴杞崲
+ if (sizeof(T) == sizeof(U)) {
+ vecLow.assign(vecHigh.begin(), vecHigh.end());
+ return;
+ }
+
+ // 濡傛灉 T 鐨勫ぇ灏忔槸 U 鐨勫�嶆暟锛屾甯稿垎瑙�
+ static_assert(sizeof(T) > sizeof(U), "Size of T must be greater than or equal to size of U");
+
+ size_t nLowSize = vecHigh.size() * nGroupSize; // 浣庡鍣ㄧ殑澶у皬
+ vecLow.resize(nLowSize, 0);
+
+ // 鍒嗚В楂樹綅鏁版嵁鍒颁綆浣嶆暟鎹�
+ for (size_t i = 0; i < vecHigh.size(); i++) {
+ for (size_t j = 0; j < nGroupSize; j++) {
+ vecLow[i * nGroupSize + j] = static_cast<U>((vecHigh[i] >> (j * CHAR_BIT * sizeof(U))) & ((1ULL << (CHAR_BIT * sizeof(U))) - 1));
+ }
+ }
+
+ return vecLow;
+}
\ No newline at end of file
diff --git a/SourceCode/Bond/Servo/CCLinkPerformance/PerformanceMelsec.h b/SourceCode/Bond/Servo/CCLinkPerformance/PerformanceMelsec.h
new file mode 100644
index 0000000..903ca41
--- /dev/null
+++ b/SourceCode/Bond/Servo/CCLinkPerformance/PerformanceMelsec.h
@@ -0,0 +1,465 @@
+#ifndef PERFORMANCE_MELSEC_H
+#define PERFORMANCE_MELSEC_H
+
+#include <map>
+#include <array>
+#include <mutex>
+#include <string>
+#include <vector>
+#include <atomic>
+#include <sstream>
+#include <unordered_map>
+
+// 杩炴帴鍙傛暟
+#define PLC_MAX_RETRY 3 // 鏈�澶ч噸璇曟鏁帮細鍦ㄤ笌PLC閫氫俊鏃讹紝濡傛灉鍙戠敓閫氫俊閿欒锛屽皢鏈�澶氶噸璇�3娆�
+#define PLC_TIMEOUT 500 // 瓒呮椂鏃堕棿锛堟绉掞級锛氭瘡娆¢�氫俊鎿嶄綔鐨勮秴鏃剁瓑寰呮椂闂翠负500姣
+
+/*
+ * 缃戠粶閫氶亾锛氭寚瀹氶�氫俊鎵�浣跨敤鐨勭綉缁滈�氶亾鍙凤紝閫氬父鍦ㄥ閫氶亾閫氫俊涓缃�
+ * 51 鍒� 54 鏄� MELSECNET/H 鐨� 1-4 閫氶亾
+ * 81 鍒� 84 鏄� CC-Link 鐨� 1-4 閫氶亾
+ * 151 鍒� 154 鏄� CC-Link IE 鎺у埗鍣ㄧ綉缁滅殑 1-4 閫氶亾
+ * 181 鍒� 184 鏄� CC-Link IE 鐜板満缃戠粶鐨� 1-4 閫氶亾
+ * 281 鍒� 284 鏄� CC-Link IE TSN 缃戠粶鐨� 1-4 閫氶亾
+ **/
+#define MELSECNET_CHANNEL(x) (50 + (x)) // x 鑼冨洿锛�1~4
+#define CC_LINK_CHANNEL(x) (80 + (x)) // x 鑼冨洿锛�1~4
+#define CC_LINK_IE_CONTROL_CHANNEL(x) (150 + (x)) // x 鑼冨洿锛�1~4
+#define CC_LINK_IE_FIELD_CHANNEL(x) (180 + (x)) // x 鑼冨洿锛�1~4
+#define CC_LINK_IE_TSN_CHANNEL(x) (280 + (x)) // x 鑼冨洿锛�1~4
+
+// 鑷畾涔夐敊璇爜
+#define ERROR_CODE_UNKNOWN 0x00010000 // 鏈煡
+#define ERROR_CODE_NOT_CONNECTED 0x00020000 // 鏈繛鎺�
+#define ERROR_CODE_INVALID_PARAM 0x00030000 // 鍙傛暟鏃犳晥
+#define ERROR_CODE_INVALID_DATA 0x00040000 // 鏁版嵁鏃犳晥
+#define ERROR_CODE_STATION_OUT_OF_RANGE 0x00050000 // 绔欏彿瓒呭嚭鑼冨洿
+#define ERROR_CODE_GROUP_OUT_OF_RANGE 0x00060000 // 缁勫彿瓒呭嚭鑼冨洿
+#define ERROR_CODE_NETWORK_OUT_OF_RANGE 0x00070000 // 缃戠粶鍙疯秴鍑鸿寖鍥�
+
+// 鏉垮潡绫诲瀷
+enum class BoardType {
+ UNKNOWN = -1, // 鏈煡绫诲瀷
+ MELSECNET_H = MELSECNET_CHANNEL(1), // MELSECNET/H
+ CC_LINK_VER_2 = CC_LINK_CHANNEL(1), // CC-Link Ver. 2
+ CC_LINK_IE_CONTROL = CC_LINK_IE_CONTROL_CHANNEL(1), // CC-Link IE 鎺у埗缃戠粶
+ CC_LINK_IE_FIELD = CC_LINK_IE_FIELD_CHANNEL(1), // CC-Link IE 鐜板満缃戠粶
+ CC_LINK_IE_TSN = CC_LINK_IE_TSN_CHANNEL(1) // CC-Link IE TSN
+};
+
+// 杞厓浠剁被鍨嬫灇涓�
+enum class DeviceType {
+ /*
+ * ER銆丩X銆丩Y銆丩B銆丩W銆丩SB銆丩SW鍜孲PG杞厓浠堕兘鏄寖鍥村瀷
+ * ER锛欴evER0锝�256
+ * LX锛欴evLX1锝�255锛孌evLX(x) (DevX*1000+(x))
+ * LY锛欴evLY1锝�255锛孌evLY(x) (DevY*1000+(x))
+ * LB锛欴evLB1锝�255锛孌evLB(x) (DevB*1000+(x))
+ * LW锛欴evLW1锝�255锛孌evLW(x) (DevW*1000+(x))
+ * LSB锛欴evLSB1锝�255锛孌evLSB(x) (DevQSB*1000+(x))
+ * LSW锛欴evLSW1锝�255锛孌evLSW(x) (DevQSW*1000+(x))
+ * SPG锛欴evSPG0锝�255锛孌evSPG(x) (29*1000+(x))
+ * 鎵╁睍鏂囦欢瀵勫瓨鍣ㄤ唬鐮佹寚瀹�(10杩涘埗鏁�)鐨勫悗3浣嶆暟鍙婅蒋鍏冧欢鍚嶆寚瀹氱殑鏁板�间腑锛屽簲鎸囧畾鍧桸o.(0锝�256)
+ * 閾炬帴鐩存帴杞厓浠朵唬鐮佹寚瀹�(10杩涘埗鏁�)鐨勫悗3浣嶆暟鍙婅蒋鍏冧欢鍚嶆寚瀹氱殑鏁板�间腑锛屽簲鎸囧畾缃戠粶No.(1锝�255)
+ * 鏅鸿兘鍔熻兘妯″潡杞厓浠朵唬鐮佹寚瀹�(10杩涘埗鏁�)鐨勫悗3浣嶆暟鍙婅蒋鍏冧欢鍚嶆寚瀹氱殑鏁板�间腑锛屽簲鎸囧畾(璧峰I/ONo.梅16)鐨勫��
+ * 鎵╁睍鏂囦欢瀵勫瓨鍣ㄥ拰閾炬帴鐩存帴杞厓浠跺湪闅忔満璇诲彇(mdRandR銆乵dRandREx)鍑芥暟涓紝鍗充娇鎸囧畾瀹為檯涓嶅瓨鍦ㄧ殑杞厓浠朵篃鏈夊彲鑳芥甯哥粨鏉�
+ * MAIL鍜孧AILMC鍦⊿END鍔熻兘鍙奟ECV鍔熻兘涓紝涓庤蒋鍏冧欢璁块棶涓�鏍凤紝鎸囧畾鍚勫姛鑳藉搴旂殑杞厓浠剁被鍨嬶紝杩涜鏁版嵁鐨勫彂閫�(mdSend銆乵dSendEx)鎴栨暟鎹殑璇诲彇(mdReceive銆乵dReceiveEx)
+ **/
+
+ X = 0x0001, // 杈撳叆 (浣�)
+ Y = 0x0002, // 杈撳嚭 (浣�)
+ L = 0x0003, // 閿佸瓨缁х數鍣� (浣�)
+ M = 0x0004, // 鍐呴儴缁х數鍣� (浣�)
+ SM = 0x0005, // 鐗规畩缁х數鍣� (浣�)
+ F = 0x0006, // 鎶ヨ鍣� (浣�)
+ TT = 0x0007, // 瀹氭椂鍣� (瑙︾偣) (浣�)
+ TC = 0x0008, // 璁℃暟鍣� (绾垮湀) (浣�)
+ CT = 0x0009, // 璁℃暟鍣� (瑙︾偣) (浣�)
+ CC = 0x000A, // 璁℃暟鍣� (绾垮湀) (瀛�)
+ TN = 0x000B, // 瀹氭椂鍣� (褰撳墠鍊�) (瀛�)
+ CN = 0x000C, // 璁℃暟鍣� (褰撳墠鍊�) (瀛�)
+ D = 0x000D, // 鏁版嵁瀵勫瓨鍣� (瀛�)
+ SD = 0x000E, // 鐗规畩瀵勫瓨鍣� (瀛�)
+ TM = 0x000F, // 瀹氭椂鍣� (璁剧疆鍊间富) (瀛�)
+ TS = 0x0010, // 瀹氭椂鍣� (璁剧疆鍊间富1) (瀛�)
+ TS2 = 0x3E82, // 瀹氭椂鍣� (璁剧疆鍊间富2) (瀛�)
+ TS3 = 0x3E83, // 瀹氭椂鍣� (璁剧疆鍊间富3) (瀛�)
+ CM = 0x0011, // 璁℃暟鍣� (璁剧疆鍊间富) (瀛�)
+ CS = 0x0012, // 璁℃暟鍣� (璁剧疆鍊间富1) (瀛�)
+ CS2 = 0x4652, // 璁℃暟鍣� (璁剧疆鍊间富2) (瀛�)
+ CS3 = 0x4653, // 璁℃暟鍣� (璁剧疆鍊间富3) (瀛�)
+ A = 0x0013, // 绱姞鍣� (瀛�)
+ Z = 0x0014, // 鍙樺潃瀵勫瓨鍣� (瀛�)
+ V = 0x0015, // 鍙樺潃瀵勫瓨鍣� (瀛�)
+ R = 0x0016, // 鏂囦欢瀵勫瓨鍣� (鍧楀垏鎹㈡柟寮�) (瀛�)
+ ER = 0x55F0, // 鎵╁睍鏂囦欢瀵勫瓨鍣� (鍧楀垏鎹㈡柟寮�) (0x55F0锝�0x56F0) (瀛�) (鍦ㄩ殢鏈鸿鍙�(mdRandR銆乵dRandREx)鍑芥暟涓紝鍗充娇鎸囧畾瀹為檯涓嶅瓨鍦ㄧ殑杞厓浠朵篃鏈夊彲鑳芥甯哥粨鏉熴��(璇诲彇鏁版嵁涓嶆纭��))
+ ZR = 0x00DC, // 鏂囦欢瀵勫瓨鍣� (杩炲彿璁块棶鏂瑰紡) (瀛�)
+ B = 0x0017, // 閾炬帴缁х數鍣� (浣�)
+ W = 0x0018, // 閾炬帴瀵勫瓨鍣� (瀛�)
+ QSB = 0x0019, // 閾炬帴鐗规畩缁х數鍣� (浣�)
+ STT = 0x001A, // 绱瀹氭椂鍣� (瑙︾偣) (浣�)
+ STC = 0x001B, // 绱瀹氭椂鍣� (绾垮湀) (浣�)
+ QSW = 0x001C, // 閾炬帴鐗规畩瀵勫瓨鍣� (瀛�)
+ QV = 0x001E, // 鍙樺潃缁х數鍣� (浣�)
+ MRB = 0x0021, // 闅忔満璁块棶缂撳啿 (瀛�)
+ STN = 0x0023, // 绱瀹氭椂鍣� (褰撳墠鍊�) (瀛�)
+ LZ = 0x0026, // 瓒呴暱鍙樺潃瀵勫瓨鍣� (鍙屽瓧)
+ RD = 0x0027, // 鍒锋柊鏁版嵁瀵勫瓨鍣� (瀛�)
+ LTT = 0x0029, // 瓒呴暱瀹氭椂鍣� (瑙︾偣) (浣�)
+ LTC = 0x002A, // 瓒呴暱瀹氭椂鍣� (绾垮湀) (浣�)
+ LTN = 0x002B, // 瓒呴暱瀹氭椂鍣� (褰撳墠鍊�) (鍙屽瓧)
+ LCT = 0x002C, // 瓒呴暱璁℃暟鍣� (瑙︾偣) (浣�)
+ LCC = 0x002D, // 瓒呴暱璁℃暟鍣� (绾垮湀) (浣�)
+ LCN = 0x002E, // 瓒呴暱璁℃暟鍣� (褰撳墠鍊�) (鍙屽瓧)
+ LSTT = 0x002F, // 瓒呴暱绱瀹氭椂鍣� (瑙︾偣) (浣�)
+ LSTC = 0x0030, // 瓒呴暱绱瀹氭椂鍣� (绾垮湀) (浣�)
+ LSTN = 0x0031, // 瓒呴暱绱瀹氭椂鍣� (褰撳墠鍊�) (鍙屽瓧)
+ SPB = 0x0032, // 缂撳啿瀛樺偍鍣� (瀛�)
+ MAIL = 0x0065, // 鐗规畩杞厓浠剁被鍨嬶細閭欢绫诲瀷 (10杩涘埗 101)
+ MAILMC = 0x0066, // 鐗规畩杞厓浠剁被鍨嬶細鏃犵‘璁ら偖浠� (10杩涘埗 102)
+ LX = 0x03E9, // 閾炬帴鐩存帴杞厓浠� (閾炬帴杈撳叆) (0x03E9锝�0x04E7) (浣�)
+ LY = 0x07D1, // 閾炬帴鐩存帴杞厓浠� (閾炬帴杈撳嚭) (0x07D1锝�0x08CF) (浣�)
+ LB = 0x59D9, // 閾炬帴鐩存帴杞厓浠� (閾炬帴缁х數鍣�) (0x59D9锝�0x5AD7) (浣�)
+ LW = 0x5DC1, // 閾炬帴鐩存帴杞厓浠� (閾炬帴瀵勫瓨鍣�) (0x5DC1锝�0x5EBF) (瀛�)
+ LSB = 0x61A9, // 閾炬帴鐩存帴杞厓浠� (閾炬帴鐗规畩缁х數鍣�) (0x61A9锝�0x62A7) (浣�)
+ LSW = 0x6D61, // 閾炬帴鐩存帴杞厓浠� (閾炬帴鐗规畩瀵勫瓨鍣�) (0x6D61锝�0x6E5F) (瀛�)
+ SPG = 0x7148, // 鏅鸿兘鍔熻兘妯″潡杞厓浠� (0x7148锝�0x7247) (瀛�)
+};
+
+// 鏁版嵁绫诲瀷
+enum class DataType {
+ BIT = 1, // 浣� (1浣�)
+ WORD = 2, // 瀛� (16浣�)
+ DWORD =4 // 鍙屽瓧 (32浣�)
+};
+
+// 鎺у埗浠g爜
+enum class ControlCode {
+ RUN = 0, // 杩滅▼ RUN
+ STOP = 1, // 杩滅▼ STOP
+ PAUSE = 2 // 杩滅▼ PAUSE
+};
+
+// 鐗堟湰淇℃伅
+struct BoardVersion {
+ char fixedValue[2]; // 鍥哄畾鍊�
+ char checksum[2]; // 鏍¢獙鍜�
+ char swVersion[2]; // 杞欢鐗堟湰
+ char date[6]; // 鏃ユ湡 (鏍煎紡 YYMMDD)
+ uint32_t reserved; // 淇濈暀鍖哄煙 (4 瀛楄妭)
+ char swModel[16]; // 杞欢鍨嬪彿
+ char hwModel[16]; // 纭欢鍨嬪彿
+ char twoPortMemory[2]; // 涓ょ鍙e瓨鍌ㄥ櫒鍗犵敤瀹归噺
+ char twoPortAttribute[2]; // 涓ょ鍙e睘鎬�
+ char availableBias[2]; // 鍙娇鐢ㄥ亸缃�
+ char moduleType[10]; // 鏈哄瀷绫诲瀷
+
+ // 杈撳嚭缁撴瀯浣撳唴瀹逛负瀛楃涓� (渚夸簬璋冭瘯)
+ std::string toString() const {
+ std::ostringstream oss;
+ oss << "Fixed Value: " << fixedValue[0] << fixedValue[1] << "\n"
+ << "Checksum: " << checksum[0] << checksum[1] << "\n"
+ << "SW Version: " << swVersion[0] << swVersion[1] << "\n"
+ << "Date: " << std::string(date, 6) << "\n"
+ << "Reserved: " << reserved << "\n"
+ << "SW Model: " << std::string(swModel, 16) << "\n"
+ << "HW Model: " << std::string(hwModel, 16) << "\n"
+ << "Two Port Memory: " << twoPortMemory[0] << twoPortMemory[1] << "\n"
+ << "Two Port Attribute: " << twoPortAttribute[0] << twoPortAttribute[1] << "\n"
+ << "Available Bias: " << availableBias[0] << availableBias[1] << "\n"
+ << "Module Type: " << std::string(moduleType, 10) << "\n";
+ return oss.str();
+ }
+};
+
+// 绔欑偣鏍囪瘑绗︼紝榛樿浣跨敤鏈珯
+struct StationIdentifier {
+ /*
+ * [Network No.]
+ * 0 琛ㄧず鏈珯
+ * 1~239 琛ㄧず鏅�氱綉缁滃彿
+ **/
+
+ /*
+ * [Station No.]
+ * MELSECNET/H锛�1~64 琛ㄧず鍏朵粬绔欑偣锛�255 琛ㄧず鏈珯
+ * CC-Link 绯诲垪缃戠粶鐨勮寖鍥寸被浼硷紝鍖哄埆鍦ㄤ簬绔欏彿鐨勫彇鍊艰寖鍥�
+ * MELSECNET/H : 1~64(Other stations),255(Own station)
+ * CC-Link : 0~63(Other stations),255(Own station)
+ * CC-Link IE Controller : 1~120(Other stations),255(Own station)
+ * CC-Link IE Field : 0~120(Other stations),255(Own station)
+ * CC-Link IE TSN : 0~120(Other stations),255(Own station)
+ **/
+
+ /*
+ * 楂� 8 浣嶏紙缃戠粶鍙凤級锛� 鎸囧畾璁惧鎵�灞炵殑缃戠粶
+ * 浣� 8 浣嶏紙绔欑偣鍙凤級锛� 鎸囧畾璁惧鍦ㄧ綉缁滀腑鐨勭紪鍙�
+ * 鐢ㄤ竴涓弬鏁颁紶閫掕澶囩殑缃戠粶鍙峰拰绔欑偣鍙锋椂: nSt = station.nStNo | ((station.nNetNo << 8) & 0xFF00);
+ **/
+
+ short nNetNo = 0; // 缃戠粶缂栧彿锛歅LC鎵�杩炴帴鐨勭綉缁滅紪鍙凤紝0琛ㄧず榛樿缃戠粶
+ short nStNo = 255; // 绔欑偣缂栧彿锛氭寚瀹氫笌PLC杩炴帴鐨勭珯鐐圭紪鍙凤紝255閫氬父琛ㄧず骞挎挱鎴栨墍鏈夌珯鐐�
+
+ // 鑷畾涔夋瀯閫犲嚱鏁帮紝瑕嗙洊榛樿鍊�
+ explicit StationIdentifier(const short net, const short st) : nNetNo(net), nStNo(st) {}
+
+ // 灏嗏�滅綉缁滃彿鈥濆拰鈥滅珯鐐瑰彿鈥濈粍鍚堟垚涓�涓渶缁堢紪鐮�
+ short StationIdentifier::toNetworkStationCode() const {
+ return static_cast<short>(nStNo | ((nNetNo << 8) & 0xFF00));
+ }
+
+ // 閲嶈浇 < 杩愮畻绗︼紙鐢ㄤ簬鎺掑簭鎴栨瘮杈冿紝閫氬父鐢ㄤ簬 map 鎴� set 涓綔涓� key锛�
+ bool operator<(const StationIdentifier& other) const {
+ return std::tie(nNetNo, nStNo) <
+ std::tie(other.nNetNo, other.nStNo);
+ }
+
+ // 閲嶈浇 == 杩愮畻绗︼紙鐢ㄤ簬鐩哥瓑姣旇緝锛�
+ bool operator==(const StationIdentifier& other) const {
+ return std::tie(nNetNo, nStNo) ==
+ std::tie(other.nNetNo, other.nStNo);
+ }
+
+ // 閲嶈浇 = 杩愮畻绗︼紙鐢ㄤ簬璧嬪�硷級
+ StationIdentifier& operator=(const StationIdentifier& other) {
+ if (this != &other) {
+ nNetNo = other.nNetNo;
+ nStNo = other.nStNo;
+ }
+ return *this;
+ }
+};
+
+// 鏉跨姸鎬�
+struct BoardStatus {
+ short nStationValue = 0; // 绔欏彿鐨勮澶囧�� (buf[0])
+ short nGroupValue = 0; // 缁� No. 鐨勮澶囧�� (buf[1])
+ short nNetworkValue = 0; // 缃戠粶 No. 鐨勮澶囧�� (buf[2])
+ short nReserved1 = 0; // 淇濈暀瀛楁 (buf[3])
+ short nReserved2 = 0; // 淇濈暀瀛楁 (buf[4])
+ short nReserved3 = 0; // 淇濈暀瀛楁 (buf[5])
+
+ // 灏嗘暟缁勬槧灏勫埌缁撴瀯浣�
+ static BoardStatus fromBuffer(const short buf[6]) {
+ return {
+ buf[0],
+ buf[1],
+ buf[2],
+ buf[3],
+ buf[4],
+ buf[5]
+ };
+ }
+
+ // 灏嗙粨鏋勪綋鍐呭鏄犲皠鍒版暟缁�
+ void toBuffer(short buf[6]) const {
+ buf[0] = nStationValue;
+ buf[1] = nGroupValue;
+ buf[2] = nNetworkValue;
+ buf[3] = nReserved1;
+ buf[4] = nReserved2;
+ buf[5] = nReserved3;
+ }
+
+ // 璋冭瘯杈撳嚭
+ std::string toString() const {
+ std::ostringstream oss;
+ oss << "Station Value: " << nStationValue << "\n"
+ << "Group Value: " << nGroupValue << "\n"
+ << "Network Value: " << nNetworkValue << "\n"
+ << "Reserved1: " << nReserved1 << "\n"
+ << "Reserved2: " << nReserved2 << "\n"
+ << "Reserved3: " << nReserved3 << "\n";
+ return oss.str();
+ }
+};
+
+// 浜嬩欢璇︽儏
+struct EventDetails {
+ short nEventNo; // 鍙戠敓鐨勪簨浠跺彿
+ std::array<short, 4> details; // 瀛樺偍浜嬩欢璇︽儏淇℃伅
+
+ // 瑙f瀽浜嬩欢璇︽儏锛岃繑鍥炴牸寮忓寲瀛楃涓�
+ std::string toString() const {
+ std::ostringstream oss;
+ oss << "Details[0]: " << details[0] << ", "
+ << "Details[1]: " << details[1] << ", "
+ << "Details[2]: " << details[2] << ", "
+ << "Details[3]: " << details[3];
+ return oss.str();
+ }
+};
+
+// SoftElement 缁撴瀯浣撳畾涔�
+struct SoftElement {
+ short nType; // 杞厓浠剁被鍨�
+ short nElementCount; // 鐐规暟
+ long nStartNo; // 璧峰杞厓浠剁紪鍙�
+};
+
+// 閿欒淇℃伅
+struct ErrorInfo {
+ int nErrorCode = 0; // 閿欒鐮�
+ std::string strErrorMessageCn; // 涓枃鎻忚堪
+ std::string strErrorMessageEn; // 鑻辨枃鎻忚堪
+
+ // 灏嗙粨鏋勪綋搴忓垪鍖栦负瀛楃涓�
+ std::string toString() const {
+ std::ostringstream oss;
+ oss << nErrorCode << "|" << strErrorMessageCn << "|" << strErrorMessageEn;
+ return oss.str();
+ }
+
+ // 浠庡瓧绗︿覆鍙嶅簭鍒楀寲涓虹粨鏋勪綋
+ static ErrorInfo fromString(const std::string& line) {
+ ErrorInfo info;
+ std::istringstream iss(line);
+ std::string token;
+
+ // 浣跨敤鍒嗛殧绗� "|" 瑙f瀽瀛楃涓�
+ std::getline(iss, token, '|');
+ info.nErrorCode = std::stoi(token);
+
+ std::getline(iss, token, '|');
+ info.strErrorMessageCn = token;
+
+ std::getline(iss, token, '|');
+ info.strErrorMessageEn = token;
+
+ return info;
+ }
+};
+
+using BitContainer = std::vector<uint8_t>; // 姣忎釜鍏冪礌瀛樺偍 8 涓綅
+using WordContainer = std::vector<uint16_t>; // 姣忎釜鍏冪礌瀛樺偍 16 浣�
+using DWordContainer = std::vector<uint32_t>; // 姣忎釜鍏冪礌瀛樺偍 32 浣�
+
+// CPerformanceMelsec 绫诲0鏄�
+class CPerformanceMelsec {
+public:
+ // 鑾峰彇鏈�杩戠殑閿欒淇℃伅
+ std::string GetLastError() const;
+
+ // 閿欒淇℃伅鍔犺浇涓庝繚瀛樻帴鍙�
+ static bool LoadErrorInfoFromFile(const std::string& filename); // 浠庢枃浠跺姞杞介敊璇俊鎭�
+ static bool SaveErrorInfoToFile(const std::string& filename); // 淇濆瓨閿欒淇℃伅鍒版枃浠�
+
+ // 杩炴帴/鏂紑
+ int Connect(short nChannel, short nMode = -1);
+ int Disconnect();
+
+ // 鍒濆鍖栧彲缂栫▼鎺у埗鍣ㄨ蒋鍏冧欢淇℃伅琛�
+ int InitializeController();
+
+ // 鑾峰彇鐗堟湰淇℃伅
+ int GetBoardVersion(BoardVersion& version);
+
+ // 鏉垮浣�
+ int BoardReset();
+
+ // 鏉縇ED璇诲彇
+ int ReadBoardLed(std::vector<short>& vecLedBuffer);
+
+ // 璇诲彇鐩爣绔欑偣CPU绫诲瀷
+ int ReadCPUCode(const StationIdentifier& station, short& nCPUCode);
+
+ // 鏉挎ā寮忚幏鍙�/璁剧疆
+ int SetBoardMode(short nMode);
+ int GetBoardMode(short& nMode);
+
+ // 鑾峰彇鏉跨姸鎬�
+ int GetBoardStatus(BoardStatus& status);
+
+ // 璇诲啓鏁版嵁
+ int ReadData(const StationIdentifier& station, short nDevType, short nDevNo, short nSize, std::vector<short>& vecData);
+ int ReadBitData(const StationIdentifier& station, DeviceType enDevType, short nDevNo, short nBitCount, BitContainer& vecData);
+ int ReadWordData(const StationIdentifier& station, DeviceType enDevType, short nDevNo, short nWordCount, WordContainer& vecData);
+ int ReadDWordData(const StationIdentifier& station, DeviceType enDevType, short nDevNo, short nDWordCount, DWordContainer& vecData);
+ int WriteData(const StationIdentifier& station, short nDevType, short nDevNo, short nSize, short* pData);
+ int WriteBitData(const StationIdentifier& station, DeviceType enDevType, short nDevNo, const BitContainer& vecData);
+ int WriteWordData(const StationIdentifier& station, DeviceType enDevType, short nDevNo, const WordContainer& vecData);
+ int WriteDWordData(const StationIdentifier& station, DeviceType enDevType, short nDevNo, const DWordContainer& vecData);
+
+ // 鎵╁睍璇诲啓鏁版嵁
+ long ReadDataEx(const StationIdentifier& station, long nDevType, long nDevNo, long nSize, std::vector<char>& vecData);
+ long WriteDataEx(const StationIdentifier& station, long nDevType, long nDevNo, const std::vector<char>& vecData);
+
+ // 鎵╁睍杞厓浠堕殢鏈鸿鍐欙紙鏀寔澶氫釜杞厓浠讹級
+ long ReadRandomDataEx(const StationIdentifier& station, const std::vector<SoftElement>& vecSoftElements, std::vector<char>& vecData);
+ long WriteRandomDataEx(const StationIdentifier& station, const std::vector<SoftElement>& vecSoftElements, const std::vector<char>& vecData);
+
+ // 杩滅▼璁惧绔�/杩滅▼绔欑殑缂撳啿瀛樺偍鍣ㄨ鍐�
+ long ReadRemoteBuffer(const StationIdentifier& station, long nOffset, long nSize, std::vector<char>& vecData);
+ long WriteRemoteBuffer(const StationIdentifier& station, long nOffset, const std::vector<char>& vecData);
+ long ReadRemoteBufferByIp(const std::string& strIP, long nOffset, long nSize, std::vector<char>& vecData);
+ long WriteRemoteBufferByIp(const std::string& strIP, long nOffset, const std::vector<char>& vecData);
+
+ // 璁剧疆/澶嶄綅瀵硅薄绔欑殑鎸囧畾浣嶈蒋鍏冧欢
+ int SetBitDevice(const StationIdentifier& station, DeviceType enDevType, short nDevNo);
+ int ResetBitDevice(const StationIdentifier& station, DeviceType enDevType, short enDevNo);
+
+ // 鎵╁睍璁剧疆/澶嶄綅瀵硅薄绔欑殑鎸囧畾浣嶈蒋鍏冧欢
+ long SetBitDeviceEx(const StationIdentifier& station, long nDevType, long nDevNo);
+ long ResetBitDeviceEx(const StationIdentifier& station, long nDevType, long nDevNo);
+
+ // 鎵ц瀵硅薄绔欑殑CPU
+ int ControlCPU(const StationIdentifier& station, ControlCode enControlCode);
+
+ // 浜嬩欢绛夊緟锛寁ecEventNumbers[0, 64]锛宯TimeoutMs[-1, 2147483647]
+ // 鍚屾椂鍙戠敓浜嗗涓簨浠剁殑鎯呭喌涓嬶紝棣栧厛妫�娴嬪嚭鍏朵腑涓�涓簨浠躲�� 鍐嶆鎵ц浜嗘湰鍑芥暟鐨勬儏鍐典笅妫�娴嬪嚭鍏跺畠浜嬩欢銆�
+ int WaitForBoardEvent(std::vector<short> vecEventNumbers, int nTimeoutMs, EventDetails& details);
+
+private:
+ // 閿佸畾涓庤В閿侊紙澶氱嚎绋嬪悓姝ヤ繚鎶わ級
+ void Lock() { m_mtx.lock(); }
+ void Unlock() { m_mtx.unlock(); }
+
+protected:
+ // 鏋勯�犲嚱鏁�/鏋愭瀯鍑芥暟
+ explicit CPerformanceMelsec(BoardType enBoardType);
+ virtual ~CPerformanceMelsec();
+
+ // 杈呭姪鍑芥暟
+ void UpdateLastError(int nCode); // 鏇存柊鏈�杩戠殑閿欒淇℃伅
+ int ValidateStation(const StationIdentifier& station) const; // 妫�鏌ヨ繛鎺ョ姸鎬佸拰绔欑偣鍙傛暟鏈夋晥鎬�
+ int ValidateStationAndSize(const StationIdentifier& station, short nCount) const;
+
+ // 闈欐�佽緟鍔╁嚱鏁�
+ static void Delay(unsigned int nDelayMs); // 寤舵椂锛屽苟涓旇浆鍙戠獥鍙f秷鎭�
+ static BoardType FindBoardTypeByChannel(int nChannel); // 鏌ユ壘鏉垮潡绫诲瀷
+ static short CombineStation(const StationIdentifier& station); // 鍚堝苟缃戠粶鍙峰拰绔欑偣鍙�
+ static short CalculateDeviceType(const StationIdentifier& station, DeviceType enDevType); // 璁$畻杞厓浠剁被鍨�
+
+ // IP杞崲
+ static bool ConvertIpStringToUint32(const std::string& strIP, uint32_t& nIP);
+
+ // 瀹瑰櫒杞崲
+ static void ConvertCharToShort(const std::vector<char>& vecChar, std::vector<short>& vecShort);
+ static void ConvertShortToChar(const std::vector<short>& vecShort, std::vector<char>&vecChar);
+ static void ConvertUint8ToShort(const std::vector<uint8_t>& vecUint8, std::vector<short>& vecShort);
+ static void ConvertShortToUint8(const std::vector<short>& vecShort, std::vector<uint8_t>& vecUint8);
+ static void ConvertUint32ToShort(const std::vector<uint32_t>& vecUint32, std::vector<short>& vecShort);
+ static void ConvertShortToUint32(const std::vector<short>& vecShort, std::vector<uint32_t>& vecUint32);
+
+ // 妯℃澘杈呭姪鍑芥暟
+ template <typename T>
+ int ValidateStationAndData(const StationIdentifier& station, const std::vector<T>& vecData);
+
+ template <typename T, typename U>
+ void ConvertLowToHigh(const std::vector<T>& vecLow, std::vector<U>& vecHigh);
+
+ template <typename T, typename U>
+ void ConvertHighToLow(const std::vector<T>& vecHigh, std::vector<U>& vecLow);
+
+ // 鎴愬憳鍙橀噺
+ std::mutex m_mtx; // 浜掓枼閿佷繚鎶�
+ BoardType m_enBoardType; // 鏉垮潡绫诲瀷
+ long m_nPath; // 閫氫俊璺緞
+ std::atomic<bool> m_bConnected; // 鏄惁宸茶繛鎺�
+ std::string m_strLastError; // 鏈�杩戜竴娆¢敊璇俊鎭�
+
+ // 闈欐�佹垚鍛樺彉閲�
+ static std::unordered_map<int, std::string> m_mapError; // 閿欒鐮佹槧灏勮〃
+};
+
+#endif // PERFORMANCE_MELSEC_H
\ No newline at end of file
diff --git a/SourceCode/Bond/Servo/SECSRuntimeManager.cpp b/SourceCode/Bond/Servo/SECSRuntimeManager.cpp
new file mode 100644
index 0000000..be02efa
--- /dev/null
+++ b/SourceCode/Bond/Servo/SECSRuntimeManager.cpp
@@ -0,0 +1,682 @@
+#include "stdafx.h"
+#include "SECSRuntimeManager.h"
+
+// 常量
+const std::string DATABASE_FILE = R"(SECSDataManager.db)";
+
+// 静态成员初始化
+std::mutex SECSRuntimeManager::m_mutex;
+
+// 获取单例实例
+SECSRuntimeManager& SECSRuntimeManager::getInstance() {
+ static SECSRuntimeManager instance;
+ return instance;
+}
+
+// 构造函数
+SECSRuntimeManager::SECSRuntimeManager() {
+ m_pDB = new BL::SQLiteDatabase();
+}
+
+// 析构函数
+SECSRuntimeManager::~SECSRuntimeManager() {
+ termRuntimeSetting();
+
+ if (m_pDB != nullptr) {
+ delete m_pDB;
+ m_pDB = nullptr;
+ }
+}
+
+// 从数据库中获取整数
+int SECSRuntimeManager::getIntFromDB(const std::string& query) {
+ auto results = m_pDB->fetchResults(query);
+ if (!results.empty() && !results[0].empty()) {
+ // 转换第一个查询结果为整数
+ return std::stoi(results[0][0]);
+ }
+
+ return 0;
+}
+
+// 判断VID是否重复
+bool SECSRuntimeManager::isIDDuplicate(int nID) {
+ std::lock_guard<std::mutex> lock(m_mutex);
+ if (m_pDB == nullptr) {
+ return false;
+ }
+
+ // 定义要检查的表
+ std::vector<std::string> tables = { "SystemSV", "EqpSV", "SystemDV", "EqpDV", "SystemEC", "EqpEC" };
+
+ // 遍历表,检查是否有重复的 ID
+ for (const auto& table : tables) {
+ // 创建 SQL 查询
+ std::string checkSQL = "SELECT COUNT(*) FROM " + table + " WHERE ID = " + std::to_string(nID) + ";";
+
+ // 执行查询
+ auto results = m_pDB->fetchResults(checkSQL);
+ int count = (!results.empty() && !results[0].empty()) ? std::stoi(results[0][0]) : 0;
+
+ // 如果找到了重复的 ID,则返回 true
+ if (count > 0) {
+ return true;
+ }
+ }
+
+ // 如果没有重复,返回 false
+ return false;
+}
+
+// 判断名称是否重复
+bool SECSRuntimeManager::isNameDuplicate(const std::string& sName) {
+ std::lock_guard<std::mutex> lock(m_mutex);
+ if (m_pDB == nullptr) {
+ return false;
+ }
+
+ // 定义要检查的表
+ std::vector<std::string> tables = { "SystemSV", "EqpSV", "SystemDV", "EqpDV", "SystemEC", "EqpEC" };
+
+ // 遍历表,检查是否有重复的 Name
+ for (const auto& table : tables) {
+ // 创建 SQL 查询
+ std::string checkSQL = "SELECT COUNT(*) FROM " + table + " WHERE Name = '" + sName + "';";
+
+ // 执行查询
+ auto results = m_pDB->fetchResults(checkSQL);
+ int count = (!results.empty() && !results[0].empty()) ? std::stoi(results[0][0]) : 0;
+
+ // 如果找到了重复的 Name,则返回 true
+ if (count > 0) {
+ return true;
+ }
+ }
+
+ // 如果没有重复,返回 false
+ return false;
+}
+
+// 设置数据库连接
+void SECSRuntimeManager::setDatabase(BL::Database* db) {
+ std::lock_guard<std::mutex> lock(m_mutex);
+ m_pDB = db;
+}
+
+// 初始化SECS设置管理库
+bool SECSRuntimeManager::initRuntimeSetting() {
+ char path[MAX_PATH];
+ GetModuleFileName(NULL, path, MAX_PATH);
+ std::string exePath(path);
+ std::string dbFileDir = exePath.substr(0, exePath.find_last_of("\\/")) + "\\DB";
+ if (!CreateDirectory(dbFileDir.c_str(), NULL) && ERROR_ALREADY_EXISTS != GetLastError()) {
+ throw std::runtime_error("Failed to create database directory.");
+ }
+
+ std::string dbFilePath = dbFileDir + "\\" + DATABASE_FILE;
+ if (!m_pDB->connect(dbFilePath, true)) {
+ return false;
+ }
+
+ // 初始化 SystemSV 表
+ initSystemSVTable();
+
+ // 初始化 EqpSV 表
+ initEqpSVTable();
+
+ // 初始化 SystemDV 表
+ initSystemDVTable();
+
+ // 初始化 EqpDV 表
+ initEqpDVTable();
+
+ // 初始化 SystemEC 表
+ initSystemECTable();
+
+ // 初始化 EqpEC 表
+ initEqpECTable();
+
+ // 初始化 SystemECID 表
+ initSystemEventTable();
+
+ // 初始化 EqpECID 表
+ initEqpEventTable();
+
+ // 初始化 SystemEventLink 表
+ initEventLinkTable();
+
+ // 初始化 PPID 表
+ initPPIDTable();
+
+ // 初始化 RPTID 表
+ initRPTIDTable();
+
+ return true;
+}
+
+// 销毁SECS设置管理库
+void SECSRuntimeManager::termRuntimeSetting() {
+ if (m_pDB != nullptr) {
+ m_pDB->disconnect();
+ }
+}
+
+// 初始化 SystemSV 表
+void SECSRuntimeManager::initSystemSVTable() {
+ std::lock_guard<std::mutex> lock(m_mutex);
+ if (m_pDB == nullptr) {
+ throw std::runtime_error("Database not connected.");
+ }
+
+ // 创建 SystemSV 表(如果不存在)
+ std::string createTableSQL =
+ "CREATE TABLE IF NOT EXISTS SystemSV ("
+ "ID INTEGER PRIMARY KEY, "
+ "Name TEXT UNIQUE NOT NULL, "
+ "DataType TEXT NOT NULL, "
+ "Length INTEGER NULL, "
+ "Unit TEXT NULL, "
+ "Remark TEXT, "
+ "SystemID INTEGER);";
+
+ if (!m_pDB->executeQuery(createTableSQL)) {
+ throw std::runtime_error("Failed to create SystemSV table.");
+ }
+
+ // 预定义的 SV 数据
+ std::vector<std::tuple<int, std::string, std::string, int, std::string, std::string, int>> svData = {
+ {1, "SYS_LICENSE_CODE", "ASCII", 0, "NULL", "License code (Formal; Evaluation; NoLicense)", 1},
+ {2, "SYS_LICENSE_STATUS", "UINT_1", 0, "NULL", "License status(0:Unauthorized; 1:Authorized; 2:Evaluation; 3:Evaluation Expiring; 4:Trial; 5:Trial End)", 2},
+ {3, "GEM_CLOCK", "ASCII", 0, "NULL", "System Clock", 3},
+ {4, "SYS_SECS_COMM_MODE", "UINT_1", 0, "NULL", "SECS Communication Mode(0:HSMS Mode; 1:SECSI Mode)", 4},
+ {5, "SYS_SECS_DRIVER_CONNECT_STATE", "UINT_1", 0, "NULL", "Initial SECS Driver Connect State(0:Stop; 1:Start)", 5}
+ };
+
+ for (const auto& entry : svData) {
+ int nID, nLength, nSystemID;
+ std::string sName, sDataType, sRemark, sUnit;
+ std::tie(nID, sName, sDataType, nLength, sUnit, sRemark, nSystemID) = entry;
+
+ // 检查 Name 是否已存在
+ int count = getIntFromDB("SELECT COUNT(*) FROM SystemSV WHERE Name = '" + sName + "';");
+ if (count == 0) {
+ // 插入数据
+ std::string insertSQL = "INSERT INTO SystemSV (ID, Name, DataType, Length, Unit, Remark, SystemID) VALUES ("
+ + std::to_string(nID) + ", '"
+ + sName + "', '"
+ + sDataType + "', "
+ + (nLength > 0 ? std::to_string(nLength) : "NULL") + ", "
+ + ((sUnit == "NULL") ? "NULL" : "'" + sUnit + "'") + ", '"
+ + sRemark + "', "
+ + std::to_string(nSystemID) + ");";
+
+ if (!m_pDB->executeQuery(insertSQL)) {
+ throw std::runtime_error("Failed to insert SystemSV data.");
+ }
+ }
+ }
+}
+
+// 添加 SystemSV 数据
+int SECSRuntimeManager::addSystemSV(int nID, const std::string& sName, const std::string& sDataType, int nLength, const std::string& sUnit, const std::string& sRemark, int nSystemID) {
+ std::lock_guard<std::mutex> lock(m_mutex);
+ if (m_pDB == nullptr) {
+ return 1;
+ }
+
+ if (isIDDuplicate(nID)) {
+ return 2;
+ }
+
+ if (isNameDuplicate(sName)) {
+ return 3;
+ }
+
+ // 如果 Unit 是 "NULL" 字符串或者为空,则插入 NULL 值
+ std::string insertSQL = "INSERT INTO SystemSV (ID, Name, DataType, Length, Unit, Remark, SystemID) VALUES ("
+ + std::to_string(nID) + ", '"
+ + sName + "', '"
+ + sDataType + "', "
+ + (nLength > 0 ? std::to_string(nLength) : "NULL") + ", "
+ + ((sUnit == "NULL" || sUnit.empty()) ? "NULL" : "'" + sUnit + "'") + ", '"
+ + sRemark + "', "
+ + std::to_string(nSystemID) + ");";
+
+ if (!m_pDB->executeQuery(insertSQL)) {
+ return 4;
+ }
+
+ return 0;
+}
+
+// 更新指定 ID 的 SystemSV 数据
+int SECSRuntimeManager::updateIDSystemSV(int nID, int sNewID) {
+ std::lock_guard<std::mutex> lock(m_mutex);
+ if (m_pDB == nullptr) {
+ return 1;
+ }
+
+ // 检查是否存在该 ID
+ if (!isIDDuplicate(nID)) {
+ return 2;
+ }
+
+ if (isIDDuplicate(sNewID)) {
+ return 3;
+ }
+
+ // 构建更新的 SQL 语句
+ std::string updateSQL = "UPDATE SystemSV SET ID = " + std::to_string(sNewID) + " WHERE ID = " + std::to_string(nID) + ";";
+ if (!m_pDB->executeQuery(updateSQL)) {
+ return 4;
+ }
+
+ return 0;
+}
+
+// 更新所有 SystemSV 数据
+int SECSRuntimeManager::updateAllSystemSV(int nID, int sNewID, const std::string& sName, const std::string& sDataType, int nLength, const std::string& sUnit, const std::string& sRemark, int nSystemID) {
+ std::lock_guard<std::mutex> lock(m_mutex);
+ if (m_pDB == nullptr) {
+ return 1;
+ }
+
+ // 检查是否存在该 ID
+ if (!isIDDuplicate(nID)) {
+ return 2;
+ }
+
+ // 检查新的 ID 是否已存在,如果已存在,则返回错误代码 3。
+ if (isIDDuplicate(sNewID)) {
+ return 3;
+ }
+
+ // 构建更新的 SQL 语句
+ std::string updateSQL = "UPDATE SystemSV SET ";
+
+ bool firstField = true;
+
+ // 如果新的 ID 被提供,更新 ID
+ if (sNewID > 0) {
+ if (!firstField) {
+ updateSQL += ", ";
+ }
+ updateSQL += "ID = " + std::to_string(sNewID);
+ firstField = false;
+ }
+
+ // 更新 Name
+ if (!sName.empty()) {
+ if (!firstField) {
+ updateSQL += ", ";
+ }
+ updateSQL += "Name = '" + sName + "'";
+ firstField = false;
+ }
+
+ // 更新 DataType
+ if (!sDataType.empty()) {
+ if (!firstField) {
+ updateSQL += ", ";
+ }
+ updateSQL += "DataType = '" + sDataType + "'";
+ firstField = false;
+ }
+
+ // 更新 Length
+ if (nLength > 0) {
+ if (!firstField) {
+ updateSQL += ", ";
+ }
+ updateSQL += "Length = " + std::to_string(nLength);
+ firstField = false;
+ }
+
+ // 更新 Unit
+ if (sUnit != "NULL" && !sUnit.empty()) {
+ if (!firstField) {
+ updateSQL += ", ";
+ }
+ updateSQL += "Unit = '" + sUnit + "'";
+ firstField = false;
+ }
+ else if (sUnit == "NULL") {
+ if (!firstField) {
+ updateSQL += ", ";
+ }
+ updateSQL += "Unit = NULL";
+ firstField = false;
+ }
+
+ // 更新 Remark
+ if (!sRemark.empty()) {
+ if (!firstField) {
+ updateSQL += ", ";
+ }
+ updateSQL += "Remark = '" + sRemark + "'";
+ firstField = false;
+ }
+
+ // 更新 SystemID
+ if (nSystemID > 0) {
+ if (!firstField) {
+ updateSQL += ", ";
+ }
+ updateSQL += "SystemID = " + std::to_string(nSystemID);
+ }
+
+ // 添加 WHERE 子句来指定更新哪个记录
+ updateSQL += " WHERE ID = " + std::to_string(nID) + ";";
+
+ // 执行更新操作
+ if (!m_pDB->executeQuery(updateSQL)) {
+ return 4;
+ }
+
+ return 0;
+}
+
+// 删除指定 ID 的 SystemSV 数据
+int SECSRuntimeManager::deleteSystemSVByID(int nID) {
+ std::lock_guard<std::mutex> lock(m_mutex);
+ if (m_pDB == nullptr) {
+ return 1;
+ }
+
+ // 检查是否存在该 ID
+ if (!isIDDuplicate(nID)) {
+ return 2;
+ }
+
+ // 构建删除的 SQL 语句
+ std::string deleteSQL = "DELETE FROM SystemSV WHERE ID = " + std::to_string(nID) + ";";
+ if (!m_pDB->executeQuery(deleteSQL)) {
+ return 3;
+ }
+
+ return 0;
+}
+
+int SECSRuntimeManager::deleteAllSystemSV() {
+ std::lock_guard<std::mutex> lock(m_mutex);
+ if (m_pDB == nullptr) {
+ return 1;
+ }
+
+ // 构建删除所有数据的 SQL 语句
+ std::string deleteSQL = "DELETE FROM SystemSV;";
+ if (!m_pDB->executeQuery(deleteSQL)) {
+ return 2;
+ }
+
+ return 0; // 删除成功,返回 0 表示操作成功完成。
+}
+
+// 初始化 EqpSV 表
+void SECSRuntimeManager::initEqpSVTable() {
+ std::lock_guard<std::mutex> lock(m_mutex);
+ if (m_pDB == nullptr) {
+ throw std::runtime_error("Database not connected.");
+ }
+
+ // 创建 EqpSV 表
+ std::string createTableSQL =
+ "CREATE TABLE IF NOT EXISTS EqpSV ("
+ "ID INTEGER PRIMARY KEY, "
+ "Name TEXT UNIQUE NOT NULL, "
+ "DataType TEXT NOT NULL, "
+ "Length INTEGER NULL, "
+ "Unit TEXT NULL, "
+ "Remark TEXT, "
+ "SeqNo INTEGER);";
+
+ if (!m_pDB->executeQuery(createTableSQL)) {
+ throw std::runtime_error("Failed to create EqpSV table.");
+ }
+}
+
+// 添加 EqpSV 数据
+int SECSRuntimeManager::addEqpSV(int nID, const std::string& sName, const std::string& sDataType, int nLength, const std::string& sUnit, const std::string& sRemark, int nSeqNo) {
+ std::lock_guard<std::mutex> lock(m_mutex);
+ if (m_pDB == nullptr) {
+ return 1;
+ }
+
+ if (isIDDuplicate(nID)) {
+ return 2;
+ }
+
+ if (isNameDuplicate(sName)) {
+ return 3;
+ }
+
+ // 构建 SQL 插入语句,插入数据到 EqpSV 表中。
+ std::string insertSQL = "INSERT INTO EqpSV (ID, Name, DataType, Length, Unit, Remark, SeqNo) VALUES ("
+ + std::to_string(nID) + ", '"
+ + sName + "', '"
+ + sDataType + "', "
+ + ((nLength <= 0) ? "NULL" : std::to_string(nLength))+", "
+ + ((sUnit == "NULL" || sUnit.empty()) ? "NULL" : "'" + sUnit + "'")+", '"
+ + sRemark + "', "
+ + std::to_string(nSeqNo) + ");";
+
+ // 执行插入操作,若失败则抛出异常。
+ if (!m_pDB->executeQuery(insertSQL)) {
+ return 4;
+ }
+
+ return 0; // 插入成功,返回 0 表示操作成功完成。
+}
+
+// 初始化 SystemDV 表
+void SECSRuntimeManager::initSystemDVTable() {
+ std::lock_guard<std::mutex> lock(m_mutex);
+ if (m_pDB == nullptr) {
+ throw std::runtime_error("Database not connected.");
+ }
+
+ // 创建 SystemDV 表
+ std::string createTableSQL =
+ "CREATE TABLE IF NOT EXISTS SystemDV ("
+ "ID INTEGER PRIMARY KEY, "
+ "Name TEXT UNIQUE NOT NULL, "
+ "DataType TEXT NOT NULL, "
+ "Length INTEGER NULL, "
+ "Unit TEXT NULL, "
+ "Remark TEXT, "
+ "SystemID INTEGER);";
+
+ if (!m_pDB->executeQuery(createTableSQL)) {
+ throw std::runtime_error("Failed to create SystemDV table.");
+ }
+}
+
+// 初始化 EqpDV 表
+void SECSRuntimeManager::initEqpDVTable() {
+ std::lock_guard<std::mutex> lock(m_mutex);
+ if (m_pDB == nullptr) {
+ throw std::runtime_error("Database not connected.");
+ }
+
+ // 创建 EqpDV 表
+ std::string createTableSQL =
+ "CREATE TABLE IF NOT EXISTS EqpDV ("
+ "ID INTEGER PRIMARY KEY, "
+ "Name TEXT UNIQUE NOT NULL, "
+ "DataType TEXT NOT NULL, "
+ "Length INTEGER NULL, "
+ "Unit TEXT NULL, "
+ "Remark TEXT, "
+ "SeqNo INTEGER);";
+
+ if (!m_pDB->executeQuery(createTableSQL)) {
+ throw std::runtime_error("Failed to create EqpDV table.");
+ }
+}
+
+// 初始化 SystemEC 表
+void SECSRuntimeManager::initSystemECTable() {
+ std::lock_guard<std::mutex> lock(m_mutex);
+ if (m_pDB == nullptr) {
+ throw std::runtime_error("Database not connected.");
+ }
+
+ // 创建 SystemEC 表
+ std::string createTableSQL =
+ "CREATE TABLE IF NOT EXISTS SystemEC ("
+ "ID INTEGER PRIMARY KEY, "
+ "Name TEXT UNIQUE NOT NULL, "
+ "DataType TEXT NOT NULL, "
+ "MinValue INTEGER NULL, "
+ "MaxValue INTEGER NULL, "
+ "DefaultVal INTEGER NULL, "
+ "Unit TEXT NULL, "
+ "Remark TEXT, "
+ "SystemID INTEGER);";
+
+ if (!m_pDB->executeQuery(createTableSQL)) {
+ throw std::runtime_error("Failed to create SystemEC table.");
+ }
+}
+
+// 初始化 EqpEC 表
+void SECSRuntimeManager::initEqpECTable() {
+ std::lock_guard<std::mutex> lock(m_mutex);
+ if (m_pDB == nullptr) {
+ throw std::runtime_error("Database not connected.");
+ }
+
+ // 创建 EqpEC 表
+ std::string createTableSQL =
+ "CREATE TABLE IF NOT EXISTS EqpEC ("
+ "ID INTEGER PRIMARY KEY, "
+ "Name TEXT UNIQUE NOT NULL, "
+ "DataType TEXT NOT NULL, "
+ "MinValue INTEGER NULL, "
+ "MaxValue INTEGER NULL, "
+ "DefaultValue INTEGER NULL, "
+ "Unit TEXT NULL, "
+ "Remark TEXT, "
+ "SeqNo INTEGER NOT NULL, "
+ "Length INTEGER NOT NULL, "
+ "CanUpdateByHost INTEGER NOT NULL);";
+
+ if (!m_pDB->executeQuery(createTableSQL)) {
+ throw std::runtime_error("Failed to create EqpEC table.");
+ }
+}
+
+// 初始化 SystemEvent 表
+void SECSRuntimeManager::initSystemEventTable() {
+ std::lock_guard<std::mutex> lock(m_mutex);
+ if (m_pDB == nullptr) {
+ throw std::runtime_error("Database not connected.");
+ }
+
+ // 创建 SystemEvent 表
+ std::string createTableSQL =
+ "CREATE TABLE IF NOT EXISTS SystemEvent ("
+ "CEID INTEGER PRIMARY KEY, "
+ "Name TEXT UNIQUE NOT NULL, "
+ "Remark TEXT, "
+ "SystemID INTEGER);";
+
+ if (!m_pDB->executeQuery(createTableSQL)) {
+ throw std::runtime_error("Failed to create SystemEvent table.");
+ }
+}
+
+// 初始化 EqpEvent 表
+void SECSRuntimeManager::initEqpEventTable() {
+ std::lock_guard<std::mutex> lock(m_mutex);
+ if (m_pDB == nullptr) {
+ throw std::runtime_error("Database not connected.");
+ }
+
+ // 创建 EqpEvent 表
+ std::string createTableSQL =
+ "CREATE TABLE IF NOT EXISTS EqpEvent ("
+ "CEID INTEGER PRIMARY KEY AUTOINCREMENT, "
+ "Name TEXT UNIQUE NOT NULL, "
+ "Remark TEXT, "
+ "BitNo INTEGER);";
+
+ if (!m_pDB->executeQuery(createTableSQL)) {
+ throw std::runtime_error("Failed to create EqpEvent table.");
+ }
+}
+
+// 初始化 EventLink 表
+void SECSRuntimeManager::initEventLinkTable() {
+ std::lock_guard<std::mutex> lock(m_mutex);
+ if (m_pDB == nullptr) {
+ throw std::runtime_error("Database not connected.");
+ }
+
+ // 创建 EventLink 表
+ std::string createEventLinkSQL =
+ "CREATE TABLE IF NOT EXISTS EventLink ("
+ "CEID INTEGER, "
+ "RPTID INTEGER, "
+ "FOREIGN KEY (CEID) REFERENCES EqpEvent(CEID));";
+
+ if (!m_pDB->executeQuery(createEventLinkSQL)) {
+ throw std::runtime_error("Failed to create EventLink table.");
+ }
+}
+
+// 初始化 PPID 表
+void SECSRuntimeManager::initPPIDTable() {
+ std::lock_guard<std::mutex> lock(m_mutex);
+ if (m_pDB == nullptr) {
+ throw std::runtime_error("Database not connected.");
+ }
+
+ // 创建 EqpPPID 表
+ std::string createTableSQL =
+ "CREATE TABLE IF NOT EXISTS EqpPPID ("
+ "BitNo INTEGER PRIMARY KEY AUTOINCREMENT, "
+ "PPID INTEGER NULL);";
+ if (!m_pDB->executeQuery(createTableSQL)) {
+ throw std::runtime_error("Failed to create EqpPPID table.");
+ }
+
+ // 先检查表是否为空
+ int nCount = getIntFromDB("SELECT COUNT(*) FROM EqpPPID;");
+ if (nCount == 0) {
+ // 插入初始数据(512 行)
+ for (int nBitNo = 0; nBitNo < 512; ++nBitNo) {
+ std::string insertSQL = "INSERT INTO EqpPPID (BitNo) VALUES (" + std::to_string(nBitNo) + ");";
+ if (!m_pDB->executeQuery(insertSQL)) {
+ throw std::runtime_error("Failed to insert data into EqpPPID table.");
+ }
+ }
+ }
+}
+
+// 初始化 RPTID 表
+void SECSRuntimeManager::initRPTIDTable() {
+ std::lock_guard<std::mutex> lock(m_mutex);
+ if (m_pDB == nullptr) {
+ throw std::runtime_error("Database not connected.");
+ }
+
+ // 创建 RPTID 相关表
+ std::string createReportTableSQL =
+ "CREATE TABLE IF NOT EXISTS Report ("
+ "RPTID INTEGER PRIMARY KEY);";
+
+ std::string createReportVIDsTableSQL =
+ "CREATE TABLE IF NOT EXISTS ReportVIDs ("
+ "ID INTEGER PRIMARY KEY AUTOINCREMENT, "
+ "RPTID INTEGER NOT NULL, "
+ "VID INTEGER NOT NULL, "
+ "FOREIGN KEY (RPTID) REFERENCES Report(RPTID));";
+
+ if (!m_pDB->executeQuery(createReportTableSQL)) {
+ throw std::runtime_error("Failed to create Report table.");
+ }
+ if (!m_pDB->executeQuery(createReportVIDsTableSQL)) {
+ throw std::runtime_error("Failed to create ReportVIDs table.");
+ }
+}
\ No newline at end of file
diff --git a/SourceCode/Bond/Servo/SECSRuntimeManager.h b/SourceCode/Bond/Servo/SECSRuntimeManager.h
new file mode 100644
index 0000000..8493481
--- /dev/null
+++ b/SourceCode/Bond/Servo/SECSRuntimeManager.h
@@ -0,0 +1,221 @@
+锘�#ifndef SECS_RUNTIME_MANAGER_H
+#define SECS_RUNTIME_MANAGER_H
+
+#include <string>
+#include <vector>
+#include <mutex>
+#include "Database.h"
+
+class SECSRuntimeManager {
+public:
+ /**
+ * 鑾峰彇鍗曚緥瀹炰緥
+ * @return SECSRuntimeManager瀹炰緥鐨勫紩鐢�
+ */
+ static SECSRuntimeManager& getInstance();
+
+ /**
+ * 璁剧疆鏁版嵁搴撹繛鎺�
+ * @param db 鏁版嵁搴撹繛鎺ョ殑鎸囬拡
+ */
+ void setDatabase(BL::Database* db);
+
+ /**
+ * 鍒濆鍖朣ECS杩愯璁剧疆绠$悊搴�
+ * @return 鎴愬姛杩斿洖true锛屽け璐ヨ繑鍥瀎alse
+ */
+ bool initRuntimeSetting();
+
+ /**
+ * 閿�姣丼ECS杩愯璁剧疆绠$悊搴�
+ */
+ void termRuntimeSetting();
+
+ /**
+ * 鍒濆鍖朣ystemSV琛�
+ */
+ void initSystemSVTable();
+
+ /**
+ * 娣诲姞 SystemSV 鏁版嵁
+ * @param nID: 闇�瑕佹坊鍔犵殑 SystemSV 鐨� ID锛屽繀椤绘槸鍞竴鐨勩��
+ * @param sName: 闇�瑕佹坊鍔犵殑 SystemSV 鐨勫悕绉帮紝蹇呴』鏄敮涓�鐨勩��
+ * @param sDataType: 鏁版嵁绫诲瀷锛岃〃绀鸿绯荤粺鍊肩殑绫诲瀷锛屼緥濡� "ASCII"銆�"UINT_1" 绛夈��
+ * @param nLength: 绯荤粺鍊肩殑鏁版嵁闀垮害锛岄�氬父涓轰竴涓鏁存暟锛岀敤浜庤〃绀鸿鏁版嵁鐨勯暱搴︺��
+ * @param sUnit: 绯荤粺鍊肩殑鍗曚綅銆傚鏋滀负绌烘垨鑰呬负 "NULL"锛屽垯鎻掑叆鏁版嵁搴撲腑鐨� NULL 鍊笺��
+ * @param sRemark: 澶囨敞淇℃伅锛屾弿杩拌绯荤粺鍊肩殑鍏朵粬淇℃伅锛屽彲鐢ㄤ簬璇存槑璇ュ瓧娈电殑鐢ㄩ�旀垨鐗规�с��
+ * @param nSystemID: 璇ユ暟鎹墍灞炵殑绯荤粺 ID锛岀敤浜庝笌鍏朵粬琛ㄨ繘琛屽叧鑱斻��
+ * @return 1: 鏁版嵁搴撴湭杩炴帴銆�
+ * @return 2: ID 閲嶅锛屾棤娉曟彃鍏ユ暟鎹��
+ * @return 3: Name 閲嶅锛屾棤娉曟彃鍏ユ暟鎹��
+ * @return 4: 鎻掑叆鏁版嵁澶辫触銆�
+ * @return 0: 鎻掑叆鎴愬姛锛屾暟鎹凡娣诲姞鍒� SystemSV 琛ㄤ腑銆�
+ *
+ * 姝ゅ嚱鏁扮敤浜庡皢涓�鏉℃柊鐨勬暟鎹彃鍏ュ埌 SystemSV 琛ㄤ腑銆傚畠棣栧厛浼氭鏌ヤ紶鍏ョ殑 `ID` 鍜� `Name` 鏄惁宸插瓨鍦ㄤ簬琛ㄤ腑锛�
+ * 濡傛灉瀛樺湪鍒欒繑鍥炵浉搴旂殑閿欒浠g爜銆傚鏋� `Unit` 鍙傛暟涓� "NULL" 鎴栬�呬负绌猴紝鍑芥暟浼氬皢鍏惰浆鎹负鏁版嵁搴撲腑鐨� NULL 鍊笺��
+ * 鐒跺悗锛屾瀯閫犱竴涓� SQL 鎻掑叆璇彞骞舵墽琛屾彃鍏ユ搷浣溿�傚鏋滄彃鍏ュけ璐ワ紝鍒欐姏鍑哄紓甯搞��
+ * 濡傛灉涓�鍒囬『鍒╋紝杩斿洖 0 琛ㄧず鏁版嵁鎴愬姛鎻掑叆銆�
+ */
+ int addSystemSV(int nID, const std::string& sName, const std::string& sDataType, int nLength, const std::string& sUnit, const std::string& sRemark, int nSystemID);
+
+ /**
+ * 鏇存柊鎸囧畾 ID 鐨� SystemSV 鏁版嵁
+ * @param nID: 闇�瑕佹洿鏂扮殑 SystemSV 鐨勫綋鍓� ID銆�
+ * @param sNewID: 瑕佹洿鏂颁负鐨勬柊 ID銆�
+ * @return 1: 鏁版嵁搴撴湭杩炴帴銆�
+ * @return 2: 鏈壘鍒版寚瀹氱殑 ID銆�
+ * @return 3: 鏂扮殑 ID 宸茬粡瀛樺湪锛屾棤娉曟洿鏂般��
+ * @return 4: 鏇存柊鎿嶄綔澶辫触銆�
+ * @return 0: 鏇存柊鎴愬姛銆�
+ *
+ * 姝ゅ嚱鏁扮敤浜庢洿鏂� `SystemSV` 琛ㄤ腑鎸囧畾 `nID` 鐨勮褰曪紝灏嗗叾 `ID` 瀛楁鏇存柊涓� `sNewID`銆�
+ * 鍦ㄦ墽琛屾洿鏂板墠锛屽嚱鏁颁細妫�鏌ワ細
+ * 1. 褰撳墠鐨� `nID` 鏄惁瀛樺湪浜庤〃涓��
+ * 2. 鏂扮殑 `sNewID` 鏄惁宸茬粡瀛樺湪浜庤〃涓紝濡傛灉瀛樺湪锛屽垯鏃犳硶杩涜鏇存柊銆�
+ *
+ * 濡傛灉 `nID` 涓嶅瓨鍦紝鍒欒繑鍥為敊璇唬鐮� 2銆傚鏋� `sNewID` 宸茬粡瀛樺湪锛屽垯杩斿洖閿欒浠g爜 3銆�
+ * 濡傛灉鏁版嵁搴撴洿鏂板け璐ワ紝鍒欒繑鍥為敊璇唬鐮� 4銆傛垚鍔熸椂锛岃繑鍥� 0 琛ㄧず鎿嶄綔鎴愬姛銆�
+ */
+ int updateIDSystemSV(int nID, int sNewID);
+
+ /**
+ * 鏇存柊鎵�鏈� SystemSV 鏁版嵁
+ * @param nID: 闇�瑕佹洿鏂扮殑 SystemSV 鐨勫綋鍓� ID銆�
+ * @param sNewID: 瑕佹洿鏂颁负鐨勬柊 ID锛屽鏋滀负绌烘垨涓� -1锛屽垯涓嶆洿鏂� ID銆�
+ * @param sName: 鏂扮殑鍚嶇О锛屽鏋滀负绌猴紝鍒欎笉鏇存柊銆�
+ * @param sDataType: 鏂扮殑鏁版嵁绫诲瀷锛屽鏋滀负绌猴紝鍒欎笉鏇存柊銆�
+ * @param nLength: 鏂扮殑鏁版嵁闀垮害锛屽鏋滀负璐熷�兼垨闆讹紝鍒欎笉鏇存柊銆�
+ * @param sUnit: 鏂扮殑鍗曚綅锛屽鏋滀负绌烘垨 "NULL"锛屽垯涓嶆洿鏂般��
+ * @param sRemark: 鏂扮殑澶囨敞锛屽鏋滀负绌猴紝鍒欎笉鏇存柊銆�
+ * @param nSystemID: 鏂扮殑绯荤粺 ID锛屽鏋滀负璐熷�硷紝鍒欎笉鏇存柊銆�
+ * @return 1: 鏁版嵁搴撴湭杩炴帴銆�
+ * @return 2: 娌℃湁鎵惧埌璇� ID 瀵瑰簲鐨勮褰曘��
+ * @return 3: 鏂扮殑 ID 宸茬粡瀛樺湪锛屾棤娉曟洿鏂般��
+ * @return 4: 鏇存柊鎿嶄綔澶辫触銆�
+ * @return 0: 鏇存柊鎴愬姛銆�
+ *
+ * 姝ゅ嚱鏁扮敤浜庢洿鏂版寚瀹� `ID` 鐨� `SystemSV` 鏁版嵁銆傚鏋滄煇涓瓧娈典负绌猴紝鍒欒烦杩囪瀛楁鐨勬洿鏂般��
+ * 濡傛灉缁欏畾鐨� `ID` 涓嶅瓨鍦紝鍒欒繑鍥為敊璇唬鐮� 2銆傚鏋滄柊鐨� `ID` 宸茬粡瀛樺湪锛屽垯杩斿洖閿欒浠g爜 3銆�
+ *
+ * 濡傛灉瀛楁涓虹┖锛岃烦杩囪瀛楁鐨勬洿鏂般��
+ */
+ int updateAllSystemSV(int nID, int sNewID, const std::string& sName, const std::string& sDataType, int nLength, const std::string& sUnit, const std::string& sRemark, int nSystemID);
+
+ /**
+ * 鍒犻櫎鎸囧畾 ID 鐨� SystemSV 鏁版嵁
+ * @param nID: 闇�瑕佸垹闄ょ殑 SystemSV 鐨� ID銆�
+ * @return 1: 鏁版嵁搴撴湭杩炴帴銆�
+ * @return 2: 鏈壘鍒版寚瀹氱殑 ID 瀵瑰簲鐨勮褰曘��
+ * @return 3: 鍒犻櫎鎿嶄綔澶辫触銆�
+ * @return 0: 鍒犻櫎鎴愬姛銆�
+ *
+ * 姝ゅ嚱鏁扮敤浜庡垹闄� `SystemSV` 琛ㄤ腑鎸囧畾 `nID` 鐨勮褰曘�傚鏋滅粰瀹氱殑 `nID` 涓嶅瓨鍦紝鍒欒繑鍥為敊璇唬鐮� 2銆�
+ * 鍒犻櫎鎿嶄綔鎴愬姛鍚庯紝杩斿洖 0 琛ㄧず鍒犻櫎鎴愬姛銆�
+ */
+ int deleteSystemSVByID(int nID);
+
+ /**
+ * 鍒犻櫎鎵�鏈� SystemSV 鏁版嵁
+ * @return 1: 鏁版嵁搴撴湭杩炴帴銆�
+ * @return 2: 鍒犻櫎鎿嶄綔澶辫触銆�
+ * @return 0: 鍒犻櫎鎴愬姛銆�
+ *
+ * 姝ゅ嚱鏁扮敤浜庡垹闄� `SystemSV` 琛ㄤ腑鐨勬墍鏈夎褰曘�傚鏋滄暟鎹簱鏈繛鎺ワ紝鍒欒繑鍥為敊璇唬鐮� 1銆�
+ * 濡傛灉鍒犻櫎鎿嶄綔澶辫触锛屽垯杩斿洖閿欒浠g爜 2銆傚垹闄ゆ垚鍔熷悗锛岃繑鍥� 0 琛ㄧず鍒犻櫎鎴愬姛銆�
+ */
+ int deleteAllSystemSV();
+
+ /**
+ * 鍒濆鍖朎qp琛�
+ */
+ void initEqpSVTable();
+
+ /**
+ * 娣诲姞 EqpSV 鏁版嵁
+ * @param nID: 闇�瑕佹坊鍔犵殑 EqpSV 鐨� ID锛屽繀椤绘槸鍞竴鐨勩��
+ * @param sName: 闇�瑕佹坊鍔犵殑 EqpSV 鐨勫悕绉帮紝蹇呴』鏄敮涓�鐨勩��
+ * @param sDataType: 鏁版嵁绫诲瀷锛岃〃绀鸿璁惧鍊肩殑绫诲瀷锛屼緥濡� "ASCII"銆�"UINT_1" 绛夈��
+ * @param nLength: 璁惧鍊肩殑鏁版嵁闀垮害锛岄�氬父涓轰竴涓鏁存暟锛岀敤浜庤〃绀鸿鏁版嵁鐨勯暱搴︺��
+ * @param sUnit: 璁惧鍊肩殑鍗曚綅銆傚鏋滀负绌烘垨鑰呬负 "NULL"锛屽垯鎻掑叆鏁版嵁搴撲腑鐨� NULL 鍊笺��
+ * @param sRemark: 澶囨敞淇℃伅锛屾弿杩拌璁惧鍊肩殑鍏朵粬淇℃伅锛屽彲鐢ㄤ簬璇存槑璇ュ瓧娈电殑鐢ㄩ�旀垨鐗规�с��
+ * @param nSeqNo: 璇ユ暟鎹殑搴忓彿锛岀敤浜庢帓搴忋��
+ * @return 1: 鏁版嵁搴撴湭杩炴帴銆�
+ * @return 2: ID 閲嶅锛屾棤娉曟彃鍏ユ暟鎹��
+ * @return 3: Name 閲嶅锛屾棤娉曟彃鍏ユ暟鎹��
+ * @return 4: 鎻掑叆鏁版嵁澶辫触銆�
+ * @return 0: 鎻掑叆鎴愬姛锛屾暟鎹凡娣诲姞鍒� EqpSV 琛ㄤ腑銆�
+ *
+ * 姝ゅ嚱鏁扮敤浜庡皢涓�鏉℃柊鐨勬暟鎹彃鍏ュ埌 EqpSV 琛ㄤ腑銆傚畠棣栧厛浼氭鏌ヤ紶鍏ョ殑 `ID` 鍜� `Name` 鏄惁宸插瓨鍦ㄤ簬琛ㄤ腑锛�
+ * 濡傛灉瀛樺湪鍒欒繑鍥炵浉搴旂殑閿欒浠g爜銆傚鏋� `Unit` 鍙傛暟涓� "NULL" 鎴栬�呬负绌猴紝鍑芥暟浼氬皢鍏惰浆鎹负鏁版嵁搴撲腑鐨� NULL 鍊笺��
+ * 鐒跺悗锛屾瀯閫犱竴涓� SQL 鎻掑叆璇彞骞舵墽琛屾彃鍏ユ搷浣溿�傚鏋滄彃鍏ュけ璐ワ紝鍒欐姏鍑哄紓甯搞��
+ * 濡傛灉涓�鍒囬『鍒╋紝杩斿洖 0 琛ㄧず鏁版嵁鎴愬姛鎻掑叆銆�
+ */
+ int addEqpSV(int nID, const std::string& sName, const std::string& sDataType, int nLength, const std::string& sUnit, const std::string& sRemark, int nSeqNo);
+
+ /**
+ * 鍒濆鍖朣ystemDV琛�
+ */
+ void initSystemDVTable();
+
+ /**
+ * 鍒濆鍖朎qpDV琛�
+ */
+ void initEqpDVTable();
+
+ /**
+ * 鍒濆鍖朣ystemEC琛�
+ */
+ void initSystemECTable();
+
+ /**
+ * 鍒濆鍖朎qpEC琛�
+ */
+ void initEqpECTable();
+
+ /**
+ * 鍒濆鍖朣ystemEvent琛�
+ */
+ void initSystemEventTable();
+
+ /**
+ * 鍒濆鍖朎qpEvent琛�
+ */
+ void initEqpEventTable();
+
+ /**
+ * 鍒濆鍖朎ventLink琛�
+ */
+ void initEventLinkTable();
+
+ /**
+ * 鍒濆鍖朠PID琛�
+ */
+ void initPPIDTable();
+
+ /**
+ * 鍒濆鍖朢PTID琛�
+ */
+ void initRPTIDTable();
+
+private:
+ SECSRuntimeManager();
+ ~SECSRuntimeManager();
+
+ // 绂佹鎷疯礉鍜岃祴鍊�
+ SECSRuntimeManager(const SECSRuntimeManager&) = delete;
+ SECSRuntimeManager& operator=(const SECSRuntimeManager&) = delete;
+
+ // 浠庢暟鎹簱涓幏鍙栨暣鏁�
+ int getIntFromDB(const std::string& query);
+
+ // 鍒ゆ柇VID鏄惁閲嶅
+ bool isIDDuplicate(int nID);
+
+ // 鍒ゆ柇鍚嶇О鏄惁閲嶅
+ bool isNameDuplicate(const std::string& sName);
+
+ BL::Database* m_pDB;
+ static std::mutex m_mutex;
+};
+
+#endif // SECS_RUNTIME_MANAGER_H
\ No newline at end of file
diff --git a/SourceCode/Bond/Servo/Servo.cpp b/SourceCode/Bond/Servo/Servo.cpp
index 495b5e7..d1f502a 100644
--- a/SourceCode/Bond/Servo/Servo.cpp
+++ b/SourceCode/Bond/Servo/Servo.cpp
@@ -7,6 +7,7 @@
#include "ServoDlg.h"
#include "ServoGraph.h"
#include "AlarmManager.h"
+#include "SECSRuntimeManager.h"
// 声明全局变量,用于管理 GDI+ 初始化
ULONG_PTR g_diplusToken;
@@ -117,6 +118,21 @@
}
+ // 初始化SECS运行设置管理库
+ try {
+ if (!SECSRuntimeManager::getInstance().initRuntimeSetting()) {
+ AfxMessageBox("初始化SECS运行设置失败!");
+ return FALSE;
+ }
+ }
+ catch (const std::exception& ex) {
+ CString errorMsg;
+ errorMsg.Format(_T("初始化SECS运行设置失败:%s"), CString(ex.what()));
+ AfxMessageBox(errorMsg, MB_ICONERROR);
+ return FALSE;
+ }
+
+
CServoDlg dlg;
m_pMainWnd = &dlg;
INT_PTR nResponse = dlg.DoModal();
@@ -159,6 +175,9 @@
// 销毁报警表
AlarmManager::getInstance().termAlarmTable();
+ // 销毁SECS运行设置管理库
+ SECSRuntimeManager::getInstance().termRuntimeSetting();
+
return CWinApp::ExitInstance();
}
diff --git a/SourceCode/Bond/Servo/Servo.vcxproj b/SourceCode/Bond/Servo/Servo.vcxproj
index 769631b..1a138ec 100644
--- a/SourceCode/Bond/Servo/Servo.vcxproj
+++ b/SourceCode/Bond/Servo/Servo.vcxproj
@@ -21,7 +21,7 @@
<PropertyGroup Label="Globals">
<ProjectGuid>{66ADACE5-3166-4D1F-B30B-DE5E01FB01A2}</ProjectGuid>
<RootNamespace>Servo</RootNamespace>
- <WindowsTargetPlatformVersion>10.0.22000.0</WindowsTargetPlatformVersion>
+ <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
<Keyword>MFCProj</Keyword>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
@@ -115,7 +115,7 @@
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_WINDOWS;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
- <AdditionalIncludeDirectories>.;..;..\DatabaseSDK\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+ <AdditionalIncludeDirectories>.;..;..\DatabaseSDK\include;..\MELSECSDK\include;.\CCLinkPerformance;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
@@ -169,7 +169,7 @@
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>_WINDOWS;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
- <AdditionalIncludeDirectories>.;..;..\DatabaseSDK\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+ <AdditionalIncludeDirectories>.;..;..\DatabaseSDK\include;..\MELSECSDK\include;.\CCLinkPerformance;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
@@ -194,6 +194,8 @@
<ItemGroup>
<ClInclude Include="AlarmManager.h" />
<ClInclude Include="BlButton.h" />
+ <ClInclude Include="CCLinkPerformance\CCLinkIEControl.h" />
+ <ClInclude Include="CCLinkPerformance\PerformanceMelsec.h" />
<ClInclude Include="Common.h" />
<ClInclude Include="Configuration.h" />
<ClInclude Include="Context.h" />
@@ -204,6 +206,7 @@
<ClInclude Include="LogEdit.h" />
<ClInclude Include="Model.h" />
<ClInclude Include="Resource.h" />
+ <ClInclude Include="SECSRuntimeManager.h" />
<ClInclude Include="SecsTestDlg.h" />
<ClInclude Include="Servo.h" />
<ClInclude Include="ServoDlg.h" />
@@ -215,6 +218,8 @@
<ItemGroup>
<ClCompile Include="AlarmManager.cpp" />
<ClCompile Include="BlButton.cpp" />
+ <ClCompile Include="CCLinkPerformance\CCLinkIEControl.cpp" />
+ <ClCompile Include="CCLinkPerformance\PerformanceMelsec.cpp" />
<ClCompile Include="Configuration.cpp" />
<ClCompile Include="Context.cpp" />
<ClCompile Include="HsmsAction.cpp" />
@@ -223,6 +228,7 @@
<ClCompile Include="LogDlg.cpp" />
<ClCompile Include="LogEdit.cpp" />
<ClCompile Include="Model.cpp" />
+ <ClCompile Include="SECSRuntimeManager.cpp" />
<ClCompile Include="SecsTestDlg.cpp" />
<ClCompile Include="Servo.cpp" />
<ClCompile Include="ServoDlg.cpp" />
diff --git a/SourceCode/Bond/Servo/Servo.vcxproj.filters b/SourceCode/Bond/Servo/Servo.vcxproj.filters
index 55fdacc..58314be 100644
--- a/SourceCode/Bond/Servo/Servo.vcxproj.filters
+++ b/SourceCode/Bond/Servo/Servo.vcxproj.filters
@@ -1,144 +1,80 @@
锘�<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
- <Filter Include="婧愭枃浠�">
- <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
- <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
- </Filter>
- <Filter Include="澶存枃浠�">
- <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
- <Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
- </Filter>
- <Filter Include="璧勬簮鏂囦欢">
- <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
- <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
- </Filter>
+ <Natvis Include="$(MSBuildThisFileDirectory)..\..\natvis\wil.natvis" />
+ </ItemGroup>
+ <ItemGroup>
+ <Manifest Include="res\application.exe.manifest" />
+ </ItemGroup>
+ <ItemGroup>
+ <ClCompile Include="AlarmManager.cpp" />
+ <ClCompile Include="BlButton.cpp" />
+ <ClCompile Include="Configuration.cpp" />
+ <ClCompile Include="Context.cpp" />
+ <ClCompile Include="HsmsAction.cpp" />
+ <ClCompile Include="HsmsPassive.cpp" />
+ <ClCompile Include="Log.cpp" />
+ <ClCompile Include="LogDlg.cpp" />
+ <ClCompile Include="LogEdit.cpp" />
+ <ClCompile Include="Model.cpp" />
+ <ClCompile Include="SecsTestDlg.cpp" />
+ <ClCompile Include="Servo.cpp" />
+ <ClCompile Include="ServoDlg.cpp" />
+ <ClCompile Include="ServoGraph.cpp" />
+ <ClCompile Include="stdafx.cpp" />
+ <ClCompile Include="TerminalDisplayDlg.cpp" />
+ <ClCompile Include="SECSRuntimeManager.cpp" />
+ <ClCompile Include="CCLinkPerformance\CCLinkIEControl.cpp">
+ <Filter>CCLinkPerformance</Filter>
+ </ClCompile>
+ <ClCompile Include="CCLinkPerformance\PerformanceMelsec.cpp">
+ <Filter>CCLinkPerformance</Filter>
+ </ClCompile>
+ </ItemGroup>
+ <ItemGroup>
+ <ClInclude Include="AlarmManager.h" />
+ <ClInclude Include="BlButton.h" />
+ <ClInclude Include="Common.h" />
+ <ClInclude Include="Configuration.h" />
+ <ClInclude Include="Context.h" />
+ <ClInclude Include="HsmsAction.h" />
+ <ClInclude Include="HsmsPassive.h" />
+ <ClInclude Include="Log.h" />
+ <ClInclude Include="LogDlg.h" />
+ <ClInclude Include="LogEdit.h" />
+ <ClInclude Include="Model.h" />
+ <ClInclude Include="Resource.h" />
+ <ClInclude Include="SecsTestDlg.h" />
+ <ClInclude Include="Servo.h" />
+ <ClInclude Include="ServoDlg.h" />
+ <ClInclude Include="ServoGraph.h" />
+ <ClInclude Include="stdafx.h" />
+ <ClInclude Include="targetver.h" />
+ <ClInclude Include="TerminalDisplayDlg.h" />
+ <ClInclude Include="SECSRuntimeManager.h" />
+ <ClInclude Include="CCLinkPerformance\CCLinkIEControl.h">
+ <Filter>CCLinkPerformance</Filter>
+ </ClInclude>
+ <ClInclude Include="CCLinkPerformance\PerformanceMelsec.h">
+ <Filter>CCLinkPerformance</Filter>
+ </ClInclude>
+ </ItemGroup>
+ <ItemGroup>
+ <ResourceCompile Include="Servo.rc" />
+ </ItemGroup>
+ <ItemGroup>
+ <Image Include="res\Servo.ico" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="packages.config" />
+ <None Include="res\Servo.rc2" />
</ItemGroup>
<ItemGroup>
<Text Include="ReadMe.txt" />
</ItemGroup>
<ItemGroup>
- <ClInclude Include="Servo.h">
- <Filter>澶存枃浠�</Filter>
- </ClInclude>
- <ClInclude Include="ServoDlg.h">
- <Filter>澶存枃浠�</Filter>
- </ClInclude>
- <ClInclude Include="stdafx.h">
- <Filter>澶存枃浠�</Filter>
- </ClInclude>
- <ClInclude Include="targetver.h">
- <Filter>澶存枃浠�</Filter>
- </ClInclude>
- <ClInclude Include="Resource.h">
- <Filter>澶存枃浠�</Filter>
- </ClInclude>
- <ClInclude Include="ServoGraph.h">
- <Filter>澶存枃浠�</Filter>
- </ClInclude>
- <ClInclude Include="Model.h">
- <Filter>澶存枃浠�</Filter>
- </ClInclude>
- <ClInclude Include="BlButton.h">
- <Filter>澶存枃浠�</Filter>
- </ClInclude>
- <ClInclude Include="Common.h">
- <Filter>澶存枃浠�</Filter>
- </ClInclude>
- <ClInclude Include="LogDlg.h">
- <Filter>澶存枃浠�</Filter>
- </ClInclude>
- <ClInclude Include="LogEdit.h">
- <Filter>澶存枃浠�</Filter>
- </ClInclude>
- <ClInclude Include="Configuration.h">
- <Filter>澶存枃浠�</Filter>
- </ClInclude>
- <ClInclude Include="Log.h">
- <Filter>澶存枃浠�</Filter>
- </ClInclude>
- <ClInclude Include="HsmsPassive.h">
- <Filter>澶存枃浠�</Filter>
- </ClInclude>
- <ClInclude Include="HsmsAction.h">
- <Filter>澶存枃浠�</Filter>
- </ClInclude>
- <ClInclude Include="Context.h">
- <Filter>澶存枃浠�</Filter>
- </ClInclude>
- <ClInclude Include="SecsTestDlg.h">
- <Filter>澶存枃浠�</Filter>
- </ClInclude>
- <ClInclude Include="TerminalDisplayDlg.h">
- <ClInclude Include="AlarmManager.h">
- <Filter>澶存枃浠�</Filter>
- </ClInclude>
- </ItemGroup>
- <ItemGroup>
- <ClCompile Include="Servo.cpp">
- <Filter>婧愭枃浠�</Filter>
- </ClCompile>
- <ClCompile Include="ServoDlg.cpp">
- <Filter>婧愭枃浠�</Filter>
- </ClCompile>
- <ClCompile Include="stdafx.cpp">
- <Filter>婧愭枃浠�</Filter>
- </ClCompile>
- <ClCompile Include="ServoGraph.cpp">
- <Filter>婧愭枃浠�</Filter>
- </ClCompile>
- <ClCompile Include="Model.cpp">
- <Filter>婧愭枃浠�</Filter>
- </ClCompile>
- <ClCompile Include="BlButton.cpp">
- <Filter>婧愭枃浠�</Filter>
- </ClCompile>
- <ClCompile Include="LogDlg.cpp">
- <Filter>婧愭枃浠�</Filter>
- </ClCompile>
- <ClCompile Include="LogEdit.cpp">
- <Filter>婧愭枃浠�</Filter>
- </ClCompile>
- <ClCompile Include="Configuration.cpp">
- <Filter>婧愭枃浠�</Filter>
- </ClCompile>
- <ClCompile Include="Log.cpp">
- <Filter>婧愭枃浠�</Filter>
- </ClCompile>
- <ClCompile Include="HsmsPassive.cpp">
- <Filter>婧愭枃浠�</Filter>
- </ClCompile>
- <ClCompile Include="HsmsAction.cpp">
- <Filter>婧愭枃浠�</Filter>
- </ClCompile>
- <ClCompile Include="Context.cpp">
- <Filter>婧愭枃浠�</Filter>
- </ClCompile>
- <ClCompile Include="SecsTestDlg.cpp">
- <Filter>婧愭枃浠�</Filter>
- </ClCompile>
- <ClCompile Include="TerminalDisplayDlg.cpp">
- <ClCompile Include="AlarmManager.cpp">
- <Filter>婧愭枃浠�</Filter>
- </ClCompile>
- </ItemGroup>
- <ItemGroup>
- <ResourceCompile Include="Servo.rc">
- <Filter>璧勬簮鏂囦欢</Filter>
- </ResourceCompile>
- </ItemGroup>
- <ItemGroup>
- <None Include="res\Servo.rc2">
- <Filter>璧勬簮鏂囦欢</Filter>
- </None>
- <None Include="packages.config" />
- </ItemGroup>
- <ItemGroup>
- <Image Include="res\Servo.ico">
- <Filter>璧勬簮鏂囦欢</Filter>
- </Image>
- </ItemGroup>
- <ItemGroup>
- <Manifest Include="res\application.exe.manifest" />
+ <Filter Include="CCLinkPerformance">
+ <UniqueIdentifier>{77338295-9841-4706-8816-a958b1b5c465}</UniqueIdentifier>
+ </Filter>
</ItemGroup>
</Project>
\ No newline at end of file
diff --git a/SourceCode/Bond/Servo/ServoDlg.cpp b/SourceCode/Bond/Servo/ServoDlg.cpp
index 3f01d22..f8bfb36 100644
--- a/SourceCode/Bond/Servo/ServoDlg.cpp
+++ b/SourceCode/Bond/Servo/ServoDlg.cpp
@@ -9,7 +9,6 @@
#include "Common.h"
#include "Log.h"
#include "SecsTestDlg.h"
-#include "AlarmManager.h"
#include <chrono>
#include <thread>
#include <cmath>
diff --git a/SourceCode/Bond/Servo/stdafx.h b/SourceCode/Bond/Servo/stdafx.h
index 4768d25..d63dafa 100644
--- a/SourceCode/Bond/Servo/stdafx.h
+++ b/SourceCode/Bond/Servo/stdafx.h
@@ -38,6 +38,9 @@
#include <gdiplus.h>
using namespace Gdiplus;
+// CC-LINK模块
+#include "..\MELSECSDK\include\Mdfunc.h"
+#pragma comment(lib, "..\\MELSECSDK\\lib\\MdFunc32.lib")
// 数据库模块
#include "..\DatabaseSDK\include\Database.h"
--
Gitblit v1.9.3