LAPTOP-SNT8I5JK\Boounion
2025-09-19 334b16b4abb4cbe3d1d4e4f211efd6f4468ae09f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#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);
 
    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);
};
 
 
#endif //CCLINKIECONTROL_H