mrDarker
2025-06-26 adf46e4da2f53d171cc5a0e95340d751ebacf763
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 ReadData2(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