mrDarker
2025-09-12 49cab6105eccb35d8b18a12f8ea29c05a857471b
SourceCode/Bond/SGMeasurement/CCLinkPerformance/CCLinkIEControl.h
@@ -4,66 +4,66 @@
#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测试
   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;
   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)
   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();
        }
    };
      // 转换为字符串,用于调试
      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);
   // 读取目标站点CPU类型
   // short ReadCPUCodeEx(const StationIdentifier& station, short& nCPUCode);
    // 板模式获取/设置
    int SetBoardModeEx(CCLinkIEControlMode mode);
    CCLinkIEControlMode GetBoardModeEx();
   // 板模式获取/设置
   int SetBoardModeEx(CCLinkIEControlMode mode);
   CCLinkIEControlMode GetBoardModeEx();
    // 获取板状态
    int GetBoardStatusEx(BoardStatus& status);
   // 获取板状态
   int GetBoardStatusEx(BoardStatus& status);
    // 读取LED状态
    int ReadLedStatus(LedStatus& outLedStatus);
   // 读取LED状态
   int ReadLedStatus(LedStatus& outLedStatus);
    int ReadDataEx(const StationIdentifier& station, DeviceType enDevType, long devNo, long size, void* pData);
   int ReadDataEx(const StationIdentifier& station, DeviceType enDevType, long devNo, long size, void* pData);
private:
    static CCLinkIEControlMode ConvertToCCLinkIEControlMode(short nMode);
    static int ValidateBoardStatus(const BoardStatus& status);
   static CCLinkIEControlMode ConvertToCCLinkIEControlMode(short nMode);
   static int ValidateBoardStatus(const BoardStatus& status);
};