LAPTOP-SNT8I5JK\Boounion
2025-02-15 f8971cfc3abcc23fd2a5541a7bf698389d5e9300
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#include "stdafx.h"
#include "CMaster.h"
 
namespace SERVO {
    CMaster* g_pMaster = NULL;
    void CALLBACK MasterTimerProc(HWND hWnd, UINT nMsg, UINT nTimerid, DWORD dwTime)
    {
        if (g_pMaster != NULL) {
            g_pMaster->onTimer(nTimerid);
        }
    }
 
    CMaster::CMaster()
    {
 
    }
 
    CMaster::~CMaster()
    {
        for (auto item : m_listEquipment) {
            delete item;
        }
        m_listEquipment.clear();
    }
 
    int CMaster::init()
    {
        LOGI("<Master>ÕýÔÚ³õʼ»¯...");
 
 
        //     cclink
        if (m_cclink.Connect(CC_LINK_IE_CONTROL_CHANNEL(1)) != 0) {
            LOGE("Á¬½ÓCC-Linkʧ°Ü.");
            return -1;
        }
        else {
            LOGI("Á¬½ÓCC-Link³É¹¦.");
            BoardVersion version{};
            int nRet = m_cclink.GetBoardVersion(version);
            if (nRet == 0) {
                LOGI("°æ±¾ÐÅÏ¢£º%s.", version.toString().c_str());
            }
            else {
                LOGE("»ñÈ¡CC-Link°æ±¾ÐÅϢʧ°Ü.");
            }
 
            BoardStatus status;
            nRet = m_cclink.GetBoardStatus(status);
            if (nRet == 0) {
                LOGI("״̬£º%s.", status.toString().c_str());
            }
            else {
                LOGE("»ñÈ¡CC-Link״̬ʧ°Ü.");
            }
        }
 
 
        // ³õʼ»¯Ìí¼Ó¸÷×ÓÉ豸
        {
            CEFEM* pEquipment = new CEFEM();
            pEquipment->setName("EFEM(ROBOT)");
            pEquipment->setDescription("EFEM(ROBOT).");
            pEquipment->setReadBitBlock(0x4000, 0x45ff);
            pEquipment->setStation(1, 2);
            addEquipment(pEquipment);
            LOGE("ÒÑÌí¼Ó¡°EFEM(ROBOT)¡±.");
        }
        /*
        {
            CBonder* pBonder = new CBonder();
            pBonder->setName("Bonder 1");
            pBonder->setDescription("Bonder 1.");
            pBonder->setReadBitBlock(0x4600, 0x4bff);
            pBonder->setStation(1, 3);
            addEquipment(pBonder);
            LOGE("ÒÑÌí¼Ó¡°Bonder 1¡±.");
        }
        */
 
        // ¶¨Ê±Æ÷
        g_pMaster = this;
        SetTimer(NULL, 1, 250, (TIMERPROC)MasterTimerProc);
 
 
        LOGI("<Master>³õʼ»¯Íê³É.");
        return 0;
    }
 
    int CMaster::term()
    {
        return 0;
    }
 
    int CMaster::addEquipment(CEquipment* pEquipment)
    {
        m_listEquipment.push_back(pEquipment);
        return 0;
    }
 
    void CMaster::onTimer(UINT nTimerid)
    {
        for (auto item : m_listEquipment) {
            item->onTimer(nTimerid);
        }
 
 
        // ÒÔÏÂΪ²âÊÔ´úÂë
        static int i = 0;
        i++;
        if (i % (4 * 1) == 0) {
 
            for (auto item : m_listEquipment) {
                const StationIdentifier& station = item->getStation();
                MemoryBlock& block = item->getReadBitBlock();
 
                char szBuffer[1024];
                int nRet = m_cclink.ReadData2(station, (short)block.type,
                    block.start, block.size, szBuffer);
                for (unsigned int i = 0; i < block.size; i++) {
                    if(szBuffer[i] != 0)
                        TRACE("%d[%x]\n", i, szBuffer[i]);
                }
                TRACE("nRet=%d\n", nRet);
            }
        }
    }
}