From 5efff0895ad06eb0c5f04df7efe67a22b358beb3 Mon Sep 17 00:00:00 2001
From: LAPTOP-SNT8I5JK\Boounion <Chenluhua@qq.com>
Date: 星期二, 18 二月 2025 16:10:23 +0800
Subject: [PATCH] Merge branch 'liuyang' into clh
---
SourceCode/Bond/Servo/CCLinkPerformance/PerformanceMelsec.h | 444 +++++++++++++++----------------
SourceCode/Bond/Servo/CCLinkPerformance/PerformanceMelsec.cpp | 59 +++-
SourceCode/Bond/Servo/CEquipment.cpp | 12
SourceCode/Bond/Servo/CMaster.cpp | 1
SourceCode/Bond/Servo/Model.cpp | 1
SourceCode/Bond/Servo/CEquipment.h | 3
SourceCode/Bond/Servo/SECSRuntimeManager.cpp | 168 ++++++++++++
SourceCode/Bond/Servo/ServoDlg.cpp | 19 +
SourceCode/Bond/Servo/Common.h | 1
SourceCode/Bond/Servo/SECSRuntimeManager.h | 121 +++++++
SourceCode/Bond/Servo/ServoDlg.h | 4
11 files changed, 579 insertions(+), 254 deletions(-)
diff --git a/SourceCode/Bond/Servo/CCLinkPerformance/PerformanceMelsec.cpp b/SourceCode/Bond/Servo/CCLinkPerformance/PerformanceMelsec.cpp
index 23c31e8..61f9245 100644
--- a/SourceCode/Bond/Servo/CCLinkPerformance/PerformanceMelsec.cpp
+++ b/SourceCode/Bond/Servo/CCLinkPerformance/PerformanceMelsec.cpp
@@ -483,15 +483,33 @@
return nRet;
}
- // 璁$畻闇�瑕佽鍙栫殑瀛楄妭澶у皬锛堟寜浣嶅榻愪负瀛楄妭鏁帮級
+ if (nDevNo % 8 != 0) {
+ nRet = -2;
+ 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); // 涓存椂缂撳啿鍖猴紝瀛楄妭瀵归綈
+ const auto nSize = static_cast<short>((static_cast<int>(nBitCount) + 15) / 16); // 璁$畻闇�瑕佽鍙栫殑瀛楁暟閲忥紙鍚戜笂鍙栨暣锛�
+
+ std::vector<short> vecTempBuffer(nSize, 0);
nRet = ReadData(station, nDevType, nDevNo, nSize, vecTempBuffer);
if (nRet == 0) {
- std::lock_guard<std::mutex> lock(m_mtx); // 绾跨▼瀹夊叏淇濇姢
- ConvertShortToUint8(vecTempBuffer, vecData);
+ vecData.clear();
+
+ // 灏嗗瓧鏁版嵁瑙f瀽涓轰綅鏁版嵁
+ for (short nIdx = 0; nIdx < nSize; ++nIdx) {
+ const short nCurrentValue = vecTempBuffer[nIdx];
+ // 閬嶅巻褰撳墠 short 涓殑姣忎竴浣�
+ for (int bitIdx = 0; bitIdx < 16; ++bitIdx) {
+ bool bBit = (nCurrentValue & (1 << bitIdx)) != 0;
+ vecData.push_back(bBit);
+ if (vecData.size() >= nBitCount) {
+ return nRet; // 濡傛灉宸茬粡璇诲彇瀹屾墍闇�鐨勪綅鏁帮紝鎻愬墠閫�鍑�
+ }
+ }
+ }
}
return nRet;
@@ -573,22 +591,35 @@
// 鍐欎綅鏁版嵁
int CPerformanceMelsec::WriteBitData(const StationIdentifier& station, const DeviceType enDevType, const short nDevNo, const BitContainer& vecData) {
// 楠岃瘉绔欑偣鍙傛暟鍜屾暟鎹湁鏁堟��
- const int nRet = ValidateStationAndData(station, vecData);
+ 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);
+ if (nDevNo % 8 != 0) {
+ nRet = -2;
+ UpdateLastError(nRet);
+ return nRet;
}
- return WriteData(station, nDevType, nDevNo, nSize, vecBuffer.data());
+ const short nDevType = CalculateDeviceType(station, enDevType);
+ const auto nSize = static_cast<short>((static_cast<int>(vecData.size()) + 15) / 16); // 璁$畻闇�瑕佸啓鍏ョ殑瀛楁暟閲忥紙鍚戜笂鍙栨暣锛�
+
+ // 鍑嗗涓存椂缂撳啿鍖烘潵瀛樺偍杞崲鍚庣殑 16 浣嶆暟鎹�
+ std::vector<short> vecTempBuffer(nSize, 0);
+ {
+ std::lock_guard<std::mutex> lock(m_mtx); // 绾跨▼瀹夊叏淇濇姢
+ // 灏嗕綅鏁版嵁鎸夊瓧鎵撳寘鍒颁复鏃剁紦鍐插尯
+ for (int i = 0; i < vecData.size(); ++i) {
+ if (vecData[i]) {
+ // 浣跨敤 & 0xFFFF 淇濊瘉涓嶄細瓒呰繃 16 浣嶏紝闃叉婧㈠嚭
+ vecTempBuffer[i / 16] |= static_cast<short>((1 << (i % 16)) & 0xFFFF);
+ }
+ }
+ }
+
+ return WriteData(station, nDevType, nDevNo, nSize, vecTempBuffer.data());
}
// 鍐欏瓧鏁版嵁
diff --git a/SourceCode/Bond/Servo/CCLinkPerformance/PerformanceMelsec.h b/SourceCode/Bond/Servo/CCLinkPerformance/PerformanceMelsec.h
index 31ba329..60dea51 100644
--- a/SourceCode/Bond/Servo/CCLinkPerformance/PerformanceMelsec.h
+++ b/SourceCode/Bond/Servo/CCLinkPerformance/PerformanceMelsec.h
@@ -10,151 +10,151 @@
#include <sstream>
#include <unordered_map>
-// 连接参数
-#define PLC_MAX_RETRY 3 // 最大重试次数:在与PLC通信时,如果发生通信错误,将最多重试3次
-#define PLC_TIMEOUT 500 // 超时时间(毫秒):每次通信操作的超时等待时间为500毫秒
+// 杩炴帴鍙傛暟
+#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 通道
+ * 缃戠粶閫氶亾锛氭寚瀹氶�氫俊鎵�浣跨敤鐨勭綉缁滈�氶亾鍙凤紝閫氬父鍦ㄥ閫氶亾閫氫俊涓缃�
+ * 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 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 // 网络号超出范围
+ // 鑷畾涔夐敊璇爜
+#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, // 未知类型
+ 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_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、LX、LY、LB、LW、LSB、LSW和SPG软元件都是范围型
- * ER:DevER0~256
- * LX:DevLX1~255,DevLX(x) (DevX*1000+(x))
- * LY:DevLY1~255,DevLY(x) (DevY*1000+(x))
- * LB:DevLB1~255,DevLB(x) (DevB*1000+(x))
- * LW:DevLW1~255,DevLW(x) (DevW*1000+(x))
- * LSB:DevLSB1~255,DevLSB(x) (DevQSB*1000+(x))
- * LSW:DevLSW1~255,DevLSW(x) (DevQSW*1000+(x))
- * SPG:DevSPG0~255,DevSPG(x) (29*1000+(x))
- * 扩展文件寄存器代码指定(10进制数)的后3位数及软元件名指定的数值中,应指定块No.(0~256)
- * 链接直接软元件代码指定(10进制数)的后3位数及软元件名指定的数值中,应指定网络No.(1~255)
- * 智能功能模块软元件代码指定(10进制数)的后3位数及软元件名指定的数值中,应指定(起始I/ONo.÷16)的值
- * 扩展文件寄存器和链接直接软元件在随机读取(mdRandR、mdRandREx)函数中,即使指定实际不存在的软元件也有可能正常结束
- * MAIL和MAILMC在SEND功能及RECV功能中,与软元件访问一样,指定各功能对应的软元件类型,进行数据的发送(mdSend、mdSendEx)或数据的读取(mdReceive、mdReceiveEx)
+ * 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、mdRandREx)函数中,即使指定实际不存在的软元件也有可能正常结束。(读取数据不正确。))
- 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) (字)
+ 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位)
+ BIT = 1, // 浣� (1浣�)
+ WORD = 2, // 瀛� (16浣�)
+ DWORD = 4 // 鍙屽瓧 (32浣�)
};
-// 控制代码
+// 鎺у埗浠g爜
enum class ControlCode {
- RUN = 0, // 远程 RUN
- STOP = 1, // 远程 STOP
- PAUSE = 2 // 远程 PAUSE
+ 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]; // 两端口存储器占用容量
- char twoPortAttribute[2]; // 两端口属性
- char availableBias[2]; // 可使用偏置
- char moduleType[10]; // 机型类型
+ 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"
@@ -172,61 +172,55 @@
}
};
-// 站点标识符,默认使用本站
+// 绔欑偣鏍囪瘑绗︼紝榛樿浣跨敤鏈珯
struct StationIdentifier {
/*
* [Network No.]
- * 0 表示本站
- * 1~239 表示普通网络号
+ * 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)
- **/
+ /*
+ * [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);
- **/
+ /*
+ * 楂� 8 浣嶏紙缃戠粶鍙凤級锛� 鎸囧畾璁惧鎵�灞炵殑缃戠粶
+ * 浣� 8 浣嶏紙绔欑偣鍙凤級锛� 鎸囧畾璁惧鍦ㄧ綉缁滀腑鐨勭紪鍙�
+ * 鐢ㄤ竴涓弬鏁颁紶閫掕澶囩殑缃戠粶鍙峰拰绔欑偣鍙锋椂: nSt = station.nStNo | ((station.nNetNo << 8) & 0xFF00);
+ **/
- short nNetNo = 0; // 网络编号:PLC所连接的网络编号,0表示默认网络
- short nStNo = 255; // 站点编号:指定与PLC连接的站点编号,255通常表示广播或所有站点
+ short nNetNo = 0; // 缃戠粶缂栧彿锛歅LC鎵�杩炴帴鐨勭綉缁滅紪鍙凤紝0琛ㄧず榛樿缃戠粶
+ short nStNo = 255; // 绔欑偣缂栧彿锛氭寚瀹氫笌PLC杩炴帴鐨勭珯鐐圭紪鍙凤紝255閫氬父琛ㄧず骞挎挱鎴栨墍鏈夌珯鐐�
- StationIdentifier()
- {
- nNetNo = 0;
- nStNo = 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)
+ // 閲嶈浇 < 杩愮畻绗︼紙鐢ㄤ簬鎺掑簭鎴栨瘮杈冿紝閫氬父鐢ㄤ簬 map 鎴� set 涓綔涓� key锛�
bool operator<(const StationIdentifier& other) const {
return std::tie(nNetNo, nStNo) <
- std::tie(other.nNetNo, other.nStNo);
+ std::tie(other.nNetNo, other.nStNo);
}
- // 重载 == 运算符(用于相等比较)
+ // 閲嶈浇 == 杩愮畻绗︼紙鐢ㄤ簬鐩哥瓑姣旇緝锛�
bool operator==(const StationIdentifier& other) const {
return std::tie(nNetNo, nStNo) ==
- std::tie(other.nNetNo, other.nStNo);
+ std::tie(other.nNetNo, other.nStNo);
}
- // 重载 = 运算符(用于赋值)
+ // 閲嶈浇 = 杩愮畻绗︼紙鐢ㄤ簬璧嬪�硷級
StationIdentifier& operator=(const StationIdentifier& other) {
if (this != &other) {
nNetNo = other.nNetNo;
@@ -236,16 +230,16 @@
}
};
-// 板状态
+// 鏉跨姸鎬�
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])
+ 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],
@@ -257,7 +251,7 @@
};
}
- // 将结构体内容映射到数组
+ // 灏嗙粨鏋勪綋鍐呭鏄犲皠鍒版暟缁�
void toBuffer(short buf[6]) const {
buf[0] = nStationValue;
buf[1] = nGroupValue;
@@ -267,7 +261,7 @@
buf[5] = nReserved3;
}
- // 调试输出
+ // 璋冭瘯杈撳嚭
std::string toString() const {
std::ostringstream oss;
oss << "Station Value: " << nStationValue << "\n"
@@ -280,12 +274,12 @@
}
};
-// 事件详情
+// 浜嬩欢璇︽儏
struct EventDetails {
- short nEventNo; // 发生的事件号
- std::array<short, 4> details; // 存储事件详情信息
+ short nEventNo; // 鍙戠敓鐨勪簨浠跺彿
+ std::array<short, 4> details; // 瀛樺偍浜嬩欢璇︽儏淇℃伅
- // 解析事件详情,返回格式化字符串
+ // 瑙f瀽浜嬩欢璇︽儏锛岃繑鍥炴牸寮忓寲瀛楃涓�
std::string toString() const {
std::ostringstream oss;
oss << "Details[0]: " << details[0] << ", "
@@ -296,33 +290,33 @@
}
};
-// SoftElement 结构体定义
+// SoftElement 缁撴瀯浣撳畾涔�
struct SoftElement {
- short nType; // 软元件类型
- short nElementCount; // 点数
- long nStartNo; // 起始软元件编号
+ short nType; // 杞厓浠剁被鍨�
+ short nElementCount; // 鐐规暟
+ long nStartNo; // 璧峰杞厓浠剁紪鍙�
};
-// 错误信息
+// 閿欒淇℃伅
struct ErrorInfo {
- int nErrorCode = 0; // 错误码
- std::string strErrorMessageCn; // 中文描述
- std::string strErrorMessageEn; // 英文描述
+ 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);
@@ -336,47 +330,47 @@
}
};
-using BitContainer = std::vector<uint8_t>; // 每个元素存储 8 个位
-using WordContainer = std::vector<uint16_t>; // 每个元素存储 16 位
-using DWordContainer = std::vector<uint32_t>; // 每个元素存储 32 位
+using BitContainer = std::vector<bool>; // 姣忎釜鍏冪礌瀛樺偍 1 浣�
+using WordContainer = std::vector<uint16_t>; // 姣忎釜鍏冪礌瀛樺偍 16 浣�
+using DWordContainer = std::vector<uint32_t>; // 姣忎釜鍏冪礌瀛樺偍 32 浣�
-// CPerformanceMelsec 类声明
+// CPerformanceMelsec 绫诲0鏄�
class CPerformanceMelsec {
public:
- // 获取最近的错误信息
+ // 鑾峰彇鏈�杩戠殑閿欒淇℃伅
std::string GetLastError() const;
- // 错误信息加载与保存接口
- static bool LoadErrorInfoFromFile(const std::string& filename); // 从文件加载错误信息
- static bool SaveErrorInfoToFile(const std::string& filename); // 保存错误信息到文件
+ // 閿欒淇℃伅鍔犺浇涓庝繚瀛樻帴鍙�
+ 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();
- // 板LED读取
+ // 鏉縇ED璇诲彇
int ReadBoardLed(std::vector<short>& vecLedBuffer);
- // 读取目标站点CPU类型
+ // 璇诲彇鐩爣绔欑偣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);
@@ -386,68 +380,68 @@
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
+ // 鎵ц瀵硅薄绔欑殑CPU
int ControlCPU(const StationIdentifier& station, ControlCode enControlCode);
- // 事件等待,vecEventNumbers[0, 64],nTimeoutMs[-1, 2147483647]
- // 同时发生了多个事件的情况下,首先检测出其中一个事件。 再次执行了本函数的情况下检测出其它事件。
+ // 浜嬩欢绛夊緟锛寁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; // 检查连接状态和站点参数有效性
+ // 杈呭姪鍑芥暟
+ void UpdateLastError(int nCode); // 鏇存柊鏈�杩戠殑閿欒淇℃伅
+ int ValidateStation(const StationIdentifier& station) const; // 妫�鏌ヨ繛鎺ョ姸鎬佸拰绔欑偣鍙傛暟鏈夋晥鎬�
int ValidateStationAndSize(const StationIdentifier& station, short nCount) const;
- // 静态辅助函数
- static void Delay(unsigned int nDelayMs); // 延时,并且转发窗口消息
- static BoardType FindBoardTypeByChannel(int nChannel); // 查找板块类型
- static short CombineStation(const StationIdentifier& station); // 合并网络号和站点号
- static short CalculateDeviceType(const StationIdentifier& station, DeviceType enDevType); // 计算软元件类型
+ // 闈欐�佽緟鍔╁嚱鏁�
+ 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转换
+ // 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 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);
@@ -457,15 +451,15 @@
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; // 最近一次错误信息
+ // 鎴愬憳鍙橀噺
+ 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; // 错误码映射表
+ // 闈欐�佹垚鍛樺彉閲�
+ 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/CEquipment.cpp b/SourceCode/Bond/Servo/CEquipment.cpp
index 29a448d..2101fc0 100644
--- a/SourceCode/Bond/Servo/CEquipment.cpp
+++ b/SourceCode/Bond/Servo/CEquipment.cpp
@@ -5,7 +5,7 @@
namespace SERVO {
- CEquipment::CEquipment()
+ CEquipment::CEquipment() : m_nID(0), m_strName(""), m_strDescription(""), m_station(0, 255)
{
m_listener = { nullptr, nullptr };
m_alive = {FALSE, 0, FALSE};
@@ -34,6 +34,16 @@
}
+ void CEquipment::setID(int nID)
+ {
+ m_nID = nID;
+ }
+
+ int CEquipment::getID()
+ {
+ return m_nID;
+ }
+
void CEquipment::setName(const char* pszName)
{
m_strName = pszName;
diff --git a/SourceCode/Bond/Servo/CEquipment.h b/SourceCode/Bond/Servo/CEquipment.h
index 044fcd8..3799c16 100644
--- a/SourceCode/Bond/Servo/CEquipment.h
+++ b/SourceCode/Bond/Servo/CEquipment.h
@@ -39,6 +39,8 @@
public:
virtual const char* getClassName() = 0;
virtual void setListener(EquipmentListener listener);
+ void setID(int nID);
+ int getID();
void setName(const char* pszName);
std::string& getName();
void setDescription(const char* pszDescription);
@@ -65,6 +67,7 @@
protected:
EquipmentListener m_listener;
+ int m_nID;
std::string m_strName;
std::string m_strDescription;
CRITICAL_SECTION m_criticalSection;
diff --git a/SourceCode/Bond/Servo/CMaster.cpp b/SourceCode/Bond/Servo/CMaster.cpp
index d33f26f..c7e1a14 100644
--- a/SourceCode/Bond/Servo/CMaster.cpp
+++ b/SourceCode/Bond/Servo/CMaster.cpp
@@ -64,6 +64,7 @@
// 初始化添加各子设备
{
CEFEM* pEquipment = new CEFEM();
+ pEquipment->setID(1);
pEquipment->setName("EFEM(ROBOT)");
pEquipment->setDescription("EFEM(ROBOT).");
pEquipment->setReadBitBlock(0x4000, 0x45ff);
diff --git a/SourceCode/Bond/Servo/Common.h b/SourceCode/Bond/Servo/Common.h
index 50370d7..c33f6a0 100644
--- a/SourceCode/Bond/Servo/Common.h
+++ b/SourceCode/Bond/Servo/Common.h
@@ -7,6 +7,7 @@
#define RX_CODE_PASSIVE_STATUS_CHANGED 1001
#define RX_CODE_MES_MESSAGE 1002
#define RX_HSMS_TERMINAL_TEXT 1003
+#define RX_CODE_EQ_ALIVE 1004
/* Channel Name */
diff --git a/SourceCode/Bond/Servo/Model.cpp b/SourceCode/Bond/Servo/Model.cpp
index 4382df1..66cf9a7 100644
--- a/SourceCode/Bond/Servo/Model.cpp
+++ b/SourceCode/Bond/Servo/Model.cpp
@@ -93,6 +93,7 @@
masterListener.onEqAlive = [&](void* pMaster, SERVO::CEquipment* pEquipment, BOOL bAlive) -> void {
LOGI("<CModel>Equipment onAlive:%s(%s).\n", pEquipment->getName().c_str(),
bAlive ? _T("ON") : _T("OFF"));
+ notifyPtr(RX_CODE_EQ_ALIVE, pEquipment);
};
masterListener.onEqCimStateChanged = [&](void* pMaster, SERVO::CEquipment* pEquipment, BOOL bOn) -> void {
diff --git a/SourceCode/Bond/Servo/SECSRuntimeManager.cpp b/SourceCode/Bond/Servo/SECSRuntimeManager.cpp
index be02efa..bb382a2 100644
--- a/SourceCode/Bond/Servo/SECSRuntimeManager.cpp
+++ b/SourceCode/Bond/Servo/SECSRuntimeManager.cpp
@@ -249,6 +249,28 @@
return 0;
}
+// 获取指定 ID 的 SystemSV 数据
+std::vector<std::vector<std::string>> SECSRuntimeManager::getSystemSVByID(int nID) {
+ std::lock_guard<std::mutex> lock(m_mutex);
+ if (m_pDB == nullptr) {
+ return {};
+ }
+
+ std::string query = "SELECT * FROM SystemSV WHERE ID = " + std::to_string(nID) + ";";
+ return m_pDB->fetchResults(query);
+}
+
+// 获取所有 SystemSV 数据
+std::vector<std::vector<std::string>> SECSRuntimeManager::getAllSystemSV() {
+ std::lock_guard<std::mutex> lock(m_mutex);
+ if (m_pDB == nullptr) {
+ return {};
+ }
+
+ std::string query = "SELECT * FROM SystemSV;";
+ return m_pDB->fetchResults(query);
+}
+
// 更新指定 ID 的 SystemSV 数据
int SECSRuntimeManager::updateIDSystemSV(int nID, int sNewID) {
std::lock_guard<std::mutex> lock(m_mutex);
@@ -468,6 +490,152 @@
return 0; // 插入成功,返回 0 表示操作成功完成。
}
+// 查找指定 ID 的 EqpSV 数据
+std::vector<std::vector<std::string>> SECSRuntimeManager::getEqpSVByID(int nID) {
+ std::lock_guard<std::mutex> lock(m_mutex);
+ if (m_pDB == nullptr) {
+ return {};
+ }
+
+ // 查询 SQL 语句
+ std::string querySQL = "SELECT * FROM EqpSV WHERE ID = " + std::to_string(nID) + ";";
+ return m_pDB->fetchResults(querySQL); // 直接返回查询结果
+}
+
+// 查找所有 EqpSV 数据
+std::vector<std::vector<std::string>> SECSRuntimeManager::getAllEqpSV() {
+ std::lock_guard<std::mutex> lock(m_mutex);
+ if (m_pDB == nullptr) {
+ return {};
+ }
+
+ // 查询 SQL 语句,获取所有数据
+ std::string querySQL = "SELECT * FROM EqpSV;";
+ return m_pDB->fetchResults(querySQL); // 直接返回查询结果
+}
+
+// 更新指定 ID 的 EqpSV 数据
+int SECSRuntimeManager::updateEqpSV(int nID, int nNewID, 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; // 如果数据库未连接,返回 1
+ }
+
+ // 检查是否存在该 ID
+ if (!isIDDuplicate(nID)) {
+ return 2; // 如果 ID 不存在,返回错误代码 2
+ }
+
+ // 检查新的 ID 是否已存在
+ if (isIDDuplicate(nNewID) && nNewID != nID) {
+ return 3; // 如果新 ID 已存在,返回错误代码 3
+ }
+
+ // 构建更新 SQL 语句
+ std::string updateSQL = "UPDATE EqpSV SET ";
+
+ bool firstField = true;
+
+ // 如果新的 ID 被提供,更新 ID
+ if (nNewID > 0 && nNewID != nID) {
+ updateSQL += "ID = " + std::to_string(nNewID);
+ 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;
+ }
+
+ // 更新 SeqNo
+ if (nSeqNo > 0) {
+ if (!firstField) updateSQL += ", ";
+ updateSQL += "SeqNo = " + std::to_string(nSeqNo);
+ }
+
+ // 添加 WHERE 子句,更新指定 ID 的数据
+ updateSQL += " WHERE ID = " + std::to_string(nID) + ";";
+
+ // 执行更新操作
+ if (!m_pDB->executeQuery(updateSQL)) {
+ return 4; // 如果更新失败,返回错误代码 4
+ }
+
+ return 0; // 更新成功,返回 0
+}
+
+// 删除指定 ID 的 EqpSV 数据
+int SECSRuntimeManager::deleteEqpSVByID(int nID) {
+ std::lock_guard<std::mutex> lock(m_mutex);
+ if (m_pDB == nullptr) {
+ return 1;
+ }
+
+ // 检查是否存在该 ID
+ if (!isIDDuplicate(nID)) {
+ return 2; // 如果 ID 不存在,返回错误代码 2
+ }
+
+ // 构建删除 SQL 语句
+ std::string deleteSQL = "DELETE FROM EqpSV WHERE ID = " + std::to_string(nID) + ";";
+ if (!m_pDB->executeQuery(deleteSQL)) {
+ return 3; // 如果删除失败,返回错误代码 3
+ }
+
+ return 0; // 删除成功,返回 0
+}
+
+// 删除 EqpSV 表中的所有数据
+int SECSRuntimeManager::deleteAllEqpSV() {
+ std::lock_guard<std::mutex> lock(m_mutex);
+ if (m_pDB == nullptr) {
+ return 1;
+ }
+
+ // 构建删除所有数据的 SQL 语句
+ std::string deleteSQL = "DELETE FROM EqpSV;";
+ if (!m_pDB->executeQuery(deleteSQL)) {
+ return 2; // 如果删除失败,返回错误代码 2
+ }
+
+ return 0; // 删除成功,返回 0
+}
+
// 初始化 SystemDV 表
void SECSRuntimeManager::initSystemDVTable() {
std::lock_guard<std::mutex> lock(m_mutex);
diff --git a/SourceCode/Bond/Servo/SECSRuntimeManager.h b/SourceCode/Bond/Servo/SECSRuntimeManager.h
index 8493481..8c11a96 100644
--- a/SourceCode/Bond/Servo/SECSRuntimeManager.h
+++ b/SourceCode/Bond/Servo/SECSRuntimeManager.h
@@ -59,6 +59,29 @@
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銆�
+ * @return std::vector<std::vector<std::string>>: 杩斿洖涓�涓簩缁村瓧绗︿覆鍚戦噺锛岃〃绀烘煡璇㈢粨鏋溿�傛瘡琛屼唬琛ㄤ竴鏉¤褰曪紝姣忓垪浠h〃璇ヨ褰曠殑涓�涓瓧娈靛�笺��
+ * 濡傛灉鎸囧畾鐨� ID 瀛樺湪锛屽垯杩斿洖璇� ID 瀵瑰簲鐨勮褰曪紱濡傛灉涓嶅瓨鍦紝鍒欒繑鍥炵┖鐨勪簩缁村悜閲忋��
+ *
+ * 姝ゅ嚱鏁扮敤浜庨�氳繃鎸囧畾鐨� `ID` 浠� SystemSV 琛ㄤ腑鏌ユ壘瀵瑰簲鐨勬暟鎹�傞鍏堟牴鎹紶鍏ョ殑 `ID` 鏋勯�犳煡璇� SQL 璇彞锛�
+ * 鐒跺悗鎵ц鏌ヨ鎿嶄綔锛岃繑鍥炴煡璇㈢粨鏋溿�傛煡璇㈢粨鏋滄槸涓�涓簩缁村瓧绗︿覆鍚戦噺锛岃〃绀烘煡璇㈠埌鐨勮褰曘�傛瘡琛屾槸涓�涓�
+ * 瀛楃涓插悜閲忥紝姣忎釜鍏冪礌鏄琛屼腑鐨勪竴鍒楁暟鎹�傚鏋滄壘涓嶅埌瀵瑰簲鐨勬暟鎹紝鍑芥暟灏嗚繑鍥炰竴涓┖鐨勪簩缁村悜閲忋��
+ */
+ std::vector<std::vector<std::string>> getSystemSVByID(int nID);
+
+ /**
+ * 鑾峰彇鎵�鏈� SystemSV 鏁版嵁
+ * @return std::vector<std::vector<std::string>>: 杩斿洖涓�涓簩缁村瓧绗︿覆鍚戦噺锛岃〃绀烘煡璇㈢粨鏋溿�傛瘡琛屼唬琛ㄤ竴鏉¤褰曪紝姣忓垪浠h〃璇ヨ褰曠殑涓�涓瓧娈靛�笺��
+ * 濡傛灉琛ㄤ腑鏈夋暟鎹紝鍒欒繑鍥炴墍鏈夎褰曪紱濡傛灉琛ㄤ负绌猴紝鍒欒繑鍥炵┖鐨勪簩缁村悜閲忋��
+ *
+ * 姝ゅ嚱鏁扮敤浜庝粠 SystemSV 琛ㄤ腑鑾峰彇鎵�鏈夌殑鏁版嵁銆傞�氳繃鏋勯�� SQL 鏌ヨ璇彞鏉ラ�夋嫨鎵�鏈夎褰曪紝骞舵墽琛屾煡璇㈡搷浣溿��
+ * 杩斿洖鐨勭粨鏋滄槸涓�涓簩缁村瓧绗︿覆鍚戦噺锛岃〃绀鸿〃涓殑鎵�鏈夎褰曘�傛瘡琛屾暟鎹槸涓�涓瓧绗︿覆鍚戦噺锛屽叾涓寘鍚璁板綍鐨勫悇涓瓧娈点��
+ * 濡傛灉琛ㄤ腑娌℃湁鏁版嵁锛屽嚱鏁板皢杩斿洖涓�涓┖鐨勪簩缁村悜閲忋��
+ */
+ std::vector<std::vector<std::string>> getAllSystemSV();
+
+ /**
* 鏇存柊鎸囧畾 ID 鐨� SystemSV 鏁版嵁
* @param nID: 闇�瑕佹洿鏂扮殑 SystemSV 鐨勫綋鍓� ID銆�
* @param sNewID: 瑕佹洿鏂颁负鐨勬柊 ID銆�
@@ -126,7 +149,7 @@
int deleteAllSystemSV();
/**
- * 鍒濆鍖朎qp琛�
+ * 鍒濆鍖� EqpSV 琛�
*/
void initEqpSVTable();
@@ -152,48 +175,126 @@
*/
int addEqpSV(int nID, const std::string& sName, const std::string& sDataType, int nLength, const std::string& sUnit, const std::string& sRemark, int nSeqNo);
+
+ /**
+ * 鑾峰彇鎸囧畾 ID 鐨� EqpSV 鏁版嵁
+ * @param nID: 闇�瑕佹煡鎵剧殑 EqpSV 鐨� ID銆�
+ * @return std::vector<std::vector<std::string>>: 杩斿洖涓�涓簩缁村瓧绗︿覆鍚戦噺锛岃〃绀烘煡璇㈢粨鏋溿�傛瘡琛屼唬琛ㄤ竴鏉¤褰曪紝姣忓垪浠h〃璇ヨ褰曠殑涓�涓瓧娈靛�笺��
+ * 濡傛灉鎸囧畾鐨� ID 瀛樺湪锛屽垯杩斿洖璇� ID 瀵瑰簲鐨勮褰曪紱濡傛灉涓嶅瓨鍦紝鍒欒繑鍥炵┖鐨勪簩缁村悜閲忋��
+ *
+ * 姝ゅ嚱鏁扮敤浜庨�氳繃鎸囧畾鐨� `ID` 浠� EqpSV 琛ㄤ腑鏌ユ壘瀵瑰簲鐨勬暟鎹�傞鍏堟牴鎹紶鍏ョ殑 `ID` 鏋勯�犳煡璇� SQL 璇彞锛�
+ * 鐒跺悗鎵ц鏌ヨ鎿嶄綔锛岃繑鍥炴煡璇㈢粨鏋溿�傛煡璇㈢粨鏋滄槸涓�涓簩缁村瓧绗︿覆鍚戦噺锛岃〃绀烘煡璇㈠埌鐨勮褰曘�傛瘡琛屾槸涓�涓�
+ * 瀛楃涓插悜閲忥紝姣忎釜鍏冪礌鏄琛屼腑鐨勪竴鍒楁暟鎹�傚鏋滄壘涓嶅埌瀵瑰簲鐨勬暟鎹紝鍑芥暟灏嗚繑鍥炰竴涓┖鐨勪簩缁村悜閲忋��
+ */
+ std::vector<std::vector<std::string>> SECSRuntimeManager::getEqpSVByID(int nID);
+
+ /**
+ * 鑾峰彇鎵�鏈� EqpSV 鏁版嵁
+ * @return std::vector<std::vector<std::string>>: 杩斿洖涓�涓簩缁村瓧绗︿覆鍚戦噺锛岃〃绀烘煡璇㈢粨鏋溿�傛瘡琛屼唬琛ㄤ竴鏉¤褰曪紝姣忓垪浠h〃璇ヨ褰曠殑涓�涓瓧娈靛�笺��
+ * 濡傛灉琛ㄤ腑鏈夋暟鎹紝鍒欒繑鍥炴墍鏈夎褰曪紱濡傛灉琛ㄤ负绌猴紝鍒欒繑鍥炵┖鐨勪簩缁村悜閲忋��
+ *
+ * 姝ゅ嚱鏁扮敤浜庝粠 EqpSV 琛ㄤ腑鑾峰彇鎵�鏈夌殑鏁版嵁銆傞�氳繃鏋勯�� SQL 鏌ヨ璇彞鏉ラ�夋嫨鎵�鏈夎褰曪紝骞舵墽琛屾煡璇㈡搷浣溿��
+ * 杩斿洖鐨勭粨鏋滄槸涓�涓簩缁村瓧绗︿覆鍚戦噺锛岃〃绀鸿〃涓殑鎵�鏈夎褰曘�傛瘡琛屾暟鎹槸涓�涓瓧绗︿覆鍚戦噺锛屽叾涓寘鍚璁板綍鐨勫悇涓瓧娈点��
+ * 濡傛灉琛ㄤ腑娌℃湁鏁版嵁锛屽嚱鏁板皢杩斿洖涓�涓┖鐨勪簩缁村悜閲忋��
+ */
+ std::vector<std::vector<std::string>> SECSRuntimeManager::getAllEqpSV();
+
+ /**
+ * 鏇存柊鎸囧畾 ID 鐨� EqpSV 鏁版嵁
+ * @param nID: 闇�瑕佹洿鏂扮殑 EqpSV 鐨� ID锛屽繀椤绘槸宸插瓨鍦ㄧ殑 ID銆�
+ * @param nNewID: 鏇存柊鍚庣殑 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: 鏂� ID 閲嶅锛屾棤娉曟洿鏂版暟鎹��
+ * @return 4: 鏇存柊鏁版嵁澶辫触銆�
+ * @return 0: 鏇存柊鎴愬姛锛屾暟鎹凡鏇存柊鍒� EqpSV 琛ㄤ腑銆�
+ *
+ * 姝ゅ嚱鏁扮敤浜庢洿鏂版寚瀹� ID 鐨� EqpSV 鏁版嵁銆傞鍏堟鏌� `ID` 鏄惁瀛樺湪锛屽鏋滀笉瀛樺湪鍒欒繑鍥為敊璇唬鐮� 2銆�
+ * 鐒跺悗妫�鏌ユ柊鐨� `ID` 鏄惁宸插瓨鍦紝濡傛灉宸插瓨鍦ㄥ垯杩斿洖閿欒浠g爜 3銆傛帴涓嬫潵锛屾瀯閫犳洿鏂� SQL 璇彞锛屽寘鍚�
+ * 闇�瑕佹洿鏂扮殑瀛楁锛屽苟鎵ц鏇存柊鎿嶄綔銆傚鏋滄洿鏂板け璐ワ紝鍒欒繑鍥為敊璇唬鐮� 4銆傚鏋滀竴鍒囬『鍒╋紝杩斿洖 0 琛ㄧず
+ * 鏁版嵁鎴愬姛鏇存柊銆�
+ */
+ int updateEqpSV(int nID, int nNewID, const std::string& sName, const std::string& sDataType, int nLength, const std::string& sUnit, const std::string& sRemark, int nSeqNo);
+
/**
- * 鍒濆鍖朣ystemDV琛�
+ * 鏇存柊鎸囧畾 ID 鐨� EqpSV 鏁版嵁
+ * @param nID: 闇�瑕佹洿鏂扮殑 EqpSV 鐨勫綋鍓� ID銆�
+ * @param sNewID: 瑕佹洿鏂颁负鐨勬柊 ID銆�
+ * @return 1: 鏁版嵁搴撴湭杩炴帴銆�
+ * @return 2: 鏈壘鍒版寚瀹氱殑 ID銆�
+ * @return 3: 鏂扮殑 ID 宸茬粡瀛樺湪锛屾棤娉曟洿鏂般��
+ * @return 4: 鏇存柊鎿嶄綔澶辫触銆�
+ * @return 0: 鏇存柊鎴愬姛銆�
+ *
+ * 姝ゅ嚱鏁扮敤浜庢洿鏂� `EqpSV` 琛ㄤ腑鎸囧畾 `nID` 鐨勮褰曪紝灏嗗叾 `ID` 瀛楁鏇存柊涓� `sNewID`銆�
+ * 鍦ㄦ墽琛屾洿鏂板墠锛屽嚱鏁颁細妫�鏌ワ細
+ * 1. 褰撳墠鐨� `nID` 鏄惁瀛樺湪浜庤〃涓��
+ * 2. 鏂扮殑 `sNewID` 鏄惁宸茬粡瀛樺湪浜庤〃涓紝濡傛灉瀛樺湪锛屽垯鏃犳硶杩涜鏇存柊銆�
+ *
+ * 濡傛灉 `nID` 涓嶅瓨鍦紝鍒欒繑鍥為敊璇唬鐮� 2銆傚鏋� `sNewID` 宸茬粡瀛樺湪锛屽垯杩斿洖閿欒浠g爜 3銆�
+ * 濡傛灉鏁版嵁搴撴洿鏂板け璐ワ紝鍒欒繑鍥為敊璇唬鐮� 4銆傛垚鍔熸椂锛岃繑鍥� 0 琛ㄧず鎿嶄綔鎴愬姛銆�
+ */
+ int deleteEqpSVByID(int nID);
+
+ /**
+ * 鍒犻櫎鎵�鏈� EqpSV 鏁版嵁
+ * @return 1: 鏁版嵁搴撴湭杩炴帴銆�
+ * @return 2: 鍒犻櫎鎿嶄綔澶辫触銆�
+ * @return 0: 鍒犻櫎鎴愬姛銆�
+ *
+ * 姝ゅ嚱鏁扮敤浜庡垹闄� `EqpSV` 琛ㄤ腑鐨勬墍鏈夎褰曘�傚鏋滄暟鎹簱鏈繛鎺ワ紝鍒欒繑鍥為敊璇唬鐮� 1銆�
+ * 濡傛灉鍒犻櫎鎿嶄綔澶辫触锛屽垯杩斿洖閿欒浠g爜 2銆傚垹闄ゆ垚鍔熷悗锛岃繑鍥� 0 琛ㄧず鍒犻櫎鎴愬姛銆�
+ */
+ int deleteAllEqpSV();
+
+ /**
+ * 鍒濆鍖� SystemDV 琛�
*/
void initSystemDVTable();
/**
- * 鍒濆鍖朎qpDV琛�
+ * 鍒濆鍖� EqpDV 琛�
*/
void initEqpDVTable();
/**
- * 鍒濆鍖朣ystemEC琛�
+ * 鍒濆鍖� SystemEC 琛�
*/
void initSystemECTable();
/**
- * 鍒濆鍖朎qpEC琛�
+ * 鍒濆鍖� EqpEC 琛�
*/
void initEqpECTable();
/**
- * 鍒濆鍖朣ystemEvent琛�
+ * 鍒濆鍖� SystemEvent 琛�
*/
void initSystemEventTable();
/**
- * 鍒濆鍖朎qpEvent琛�
+ * 鍒濆鍖� EqpEvent 琛�
*/
void initEqpEventTable();
/**
- * 鍒濆鍖朎ventLink琛�
+ * 鍒濆鍖� EventLink 琛�
*/
void initEventLinkTable();
/**
- * 鍒濆鍖朠PID琛�
+ * 鍒濆鍖� PPID 琛�
*/
void initPPIDTable();
/**
- * 鍒濆鍖朢PTID琛�
+ * 鍒濆鍖� RPTID 琛�
*/
void initRPTIDTable();
diff --git a/SourceCode/Bond/Servo/ServoDlg.cpp b/SourceCode/Bond/Servo/ServoDlg.cpp
index 292467f..07bce45 100644
--- a/SourceCode/Bond/Servo/ServoDlg.cpp
+++ b/SourceCode/Bond/Servo/ServoDlg.cpp
@@ -144,6 +144,21 @@
ShowTerminalText(pszText);
}
}
+ else if (RX_CODE_EQ_ALIVE == code) {
+ // 通知设备状态
+ SERVO::CEquipment* pEquipment = nullptr;
+ if (pAny->getPtrValue("ptr", (void*&)pEquipment)) {
+ if (pEquipment != nullptr) {
+ int nID = pEquipment->getID();
+ BOOL bAlive = pEquipment->isAlive();
+ if (1 == nID) {
+ DeviceStatus status = bAlive ? DeviceStatus::ONLINE : DeviceStatus::OFFLINE;
+ UpdateDeviceStatus(INDICATE_ROBOT_ARM1, status);
+ UpdateDeviceStatus(INDICATE_ROBOT_ARM2, status);
+ }
+ }
+ }
+ }
pAny->release();
}, [&]() -> void {
// onComplete
@@ -660,12 +675,12 @@
COLORREF newFrameColor2;
switch (status) {
- case Online:
+ case ONLINE:
newBackgroundColor = RGB(255, 0, 0);
newFrameColor1 = RGB(22, 22, 22);
newFrameColor2 = RGB(255, 127, 39);
break;
- case Offline:
+ case OFFLINE:
newBackgroundColor = RGB(0, 255, 0);
newFrameColor1 = RGB(22, 22, 22);
newFrameColor2 = RGB(255, 127, 39);
diff --git a/SourceCode/Bond/Servo/ServoDlg.h b/SourceCode/Bond/Servo/ServoDlg.h
index b6bec04..88ed43d 100644
--- a/SourceCode/Bond/Servo/ServoDlg.h
+++ b/SourceCode/Bond/Servo/ServoDlg.h
@@ -9,8 +9,8 @@
#include "TerminalDisplayDlg.h"
enum DeviceStatus {
- Online, // 在线
- Offline, // 离线
+ ONLINE, // 在线
+ OFFLINE, // 离线
};
// CServoDlg 对话框
--
Gitblit v1.9.3