mrDarker
2025-08-07 47372488fddbcab4ab7b261d84a6b0f772a9bc34
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
 
// PLCConnectorView.h : CPLCConnectorView Å¬·¡½ºÀÇ ÀÎÅÍÆäÀ̽º
//
 
 
#pragma once
#include "acteasyif1.h"
#include <vector>
#include "afxwin.h"
#include "SharedMemoryDefine.h"
 
 
#define Print_Delay        40
#define MaxPrintCount  2000
typedef struct _PLCWRITE_DATA
{
    TCHAR WriteAddress[PLC_READ_ADDRESS_LENGTH];
    DWORD EndTickCount;
    WORD WriteValue;
} PLCWRITE_DATA, *PPLCWRITE_DATA;
 
class CPLCConnectorView : public CFormView
{
protected: // serialization¿¡¼­¸¸ ¸¸µé¾îÁý´Ï´Ù.
    CPLCConnectorView();
    DECLARE_DYNCREATE(CPLCConnectorView)
 
public:
    enum{ IDD = IDD_PLCCONNECTOR_FORM };
 
// Æ¯¼ºÀÔ´Ï´Ù.
public:
    CPLCConnectorDoc* GetDocument() const;
 
// ÀÛ¾÷ÀÔ´Ï´Ù.
public:
 
// ÀçÁ¤ÀÇÀÔ´Ï´Ù.
public:
    virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
protected:
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV Áö¿øÀÔ´Ï´Ù.
    virtual void OnInitialUpdate(); // »ý¼º ÈĠóÀ½ È£ÃâµÇ¾ú½À´Ï´Ù.
 
// ±¸ÇöÀÔ´Ï´Ù.
public:
    virtual ~CPLCConnectorView();
#ifdef _DEBUG
    virtual void AssertValid() const;
    virtual void Dump(CDumpContext& dc) const;
#endif
 
protected:
 
// »ý¼ºµÈ ¸Þ½ÃÁö ¸Ê ÇÔ¼ö
protected:
    afx_msg void OnFilePrintPreview();
    afx_msg void OnRButtonUp(UINT nFlags, CPoint point);
    afx_msg void OnContextMenu(CWnd* pWnd, CPoint point);
        //ÇÁ·Î±×·¥ Á¾·á
    LRESULT afx_msg OnExitProgram(WPARAM wParam, LPARAM lParam);
    DECLARE_MESSAGE_MAP()
public:
    static bool m_bThreadEnd;
    static bool m_bThreadEnd2;
private:
    //¹°·ùµ¥ÀÌÅÍ Àбâ´Â µ¿±âÈ­·Î µ¿ÀÛÇÑ´Ù.
    //¹°·ùµ¥ÀÌÅ͸¦ ÀоîµéÀÎÈÄ ¼­¹ö¿¡ ¾Ë·ÁÁÖ±â À§ÇÑ À̺¥Æ® °´Ã¼
    CEvent    m_ReadEvent_1,m_ReadEvent_2,m_ReadEvent_3;
    //¹°·ù µ¥ÀÌÅ͸¦ ´ã°í Àִ PLC ÁÖ¼Ò °ª
    TCHAR m_AddressToReadLongData[PLC_READ_ADDRESS_LENGTH];
    //¹°·ù µ¥ÀÌÅÍÀÇ Å©±â
    UINT    m_SizeOfLongData; 
 
    //±ä »çÀÌÁî µ¥ÀÌÅÍ PLC¿¡ ¾²±â
    TCHAR m_AddressToWriteLongData[PLC_READ_ADDRESS_LENGTH];
    //¹°·ù µ¥ÀÌÅÍÀÇ Å©±â
    UINT    m_SizeOfWriteLongData; 
 
    //PLC SignalÀ» ÀоîµéÀÏ ÁÖ¼Ò°¡ ¼³Á¤µÊ
    TCHAR m_AddressToReadSignal0[PLC_READ_ADDRESS_LENGTH];
    TCHAR m_AddressToReadSignal1[PLC_READ_ADDRESS_LENGTH];
    TCHAR m_AddressToReadSignal2[PLC_READ_ADDRESS_LENGTH];
    TCHAR m_AddressToReadSignal3[PLC_READ_ADDRESS_LENGTH];
    TCHAR m_AddressToReadSignal4[PLC_READ_ADDRESS_LENGTH];
 
    WORD m_lReadPLCWORD0;    //ÀоîµéÀΠ2byte PLC ½Ã±×³Î °ª
    WORD m_lReadPLCWORD1;    //ÀоîµéÀΠ2byte PLC ½Ã±×³Î °ª
    WORD m_lReadPLCWORD2;    //ÀоîµéÀΠ2byte PLC ½Ã±×³Î °ª
    WORD m_lReadPLCWORD3;    //ÀоîµéÀΠ2byte PLC ½Ã±×³Î °ª
    WORD m_lReadPLCWORD4;    //ÀоîµéÀΠ2byte PLC ½Ã±×³Î °ª
 
    //PLC Read SignalÀ» »ç¿ëÇÒ Áö ¿©ºÎ°¡ ¼³Á¤µÈ Ç÷¡±×
    BOOL m_bUseReadSignal[MAX_READSIGNAL];
 
    //PLC Connector »ç¿ë ¸ðµå : 0 MC Protocol, 1: MX Componnet
    unsigned char m_nPLCConnectMode;
 
    //MC Protocol IPÁÖ¼Ò
    DWORD m_dwAddress;
    //MC Protocol Port
    int m_nPort;
    //MX Component Station ¹øÈ£
    long m_StationNumber;
    //°øÀ¯¸Þ¸ð¸® ¸Ê ÆÄÀÏ
    HANDLE m_hMap;
    //64bit ¼­¹ö¿Í Åë½ÅÇϱâ À§ÇÑ °øÀ¯ ¸Þ¸ð¸® ¸Ê ÆÄÀÏ
    char* m_pSharedMemory;
 
    unsigned int m_ReadCount;
    unsigned int m_ReadCount2;
 
    BOOL        m_bUseAOISignal;
    TCHAR        m_strAOICaption[100];
    
 
    //PLC¿¡ °ªÀ» ¾²°í Å¸À̸Ӹ¦ »ý¼ºÇÏ¿© ¸®¼ÂÇϱâ À§ÇÑ Á¤º¸¸¦ ´ã°í Àִ ÄÁÅ×À̳Ê
    std::vector<PPLCWRITE_DATA> m_ListWriteData;
    //PLC ¸®¼Â ÀڷᱸÁ¶¸¦ Á¦¾îÇϴ itorator
    std::vector<PPLCWRITE_DATA>::iterator m_itorList;
public:
    void LoadINIFile(void);
    bool GetModulePath(CString& strPath);
    void InitValue(void);
    void SaveINIFile(void);
    afx_msg void OnDestroy();
    afx_msg void OnSetOption();
    //PLC·Î ºÎÅÍ 4byte¸¦ Àоî¿Â´Ù. ÇÔ¼ö¸í ¿À·ù
    LRESULT afx_msg OnPrintListPLCData(WPARAM wParam, LPARAM lParam);
    //¼­¹ö·Î ºÎÅÍ ¹°·ù µ¥ÀÌÅ͸¦ Àбâ À§ÇÑ ¿äûÀÌ ¿Ô´ÂÁö Ã¼Å©Çϴ ÇÔ¼ö
    bool CheckRequestToReadLongData(int nID);
 
    bool InitSharedMemory(void);
    //ÇÁ·Î±×·¥ Á¾·á
    void ExitPLCProgram(bool close = false);
    //ÇÁ·Î±×·¥ ÀÌ»ó½Ã ·Î±×¸¦ ÀÛ¼ºÇÑ´Ù.
    void WriteLocalLog(TCHAR* str,...);
    void WriteLocalLog(BOOL bFile, TCHAR* str,...);
 
    //PLC¿Í Á¢¼ÓÀ» Open
    bool OpenPLCConnection(void);
    //PLC CPU TypeÀ» ¾Ë¾Æ¿À´Â ÇÔ¼ö, ´Ü¼øÈ÷ Á¤»è ½ÃÀÛÇÏ¿´´ÂÁö ¾Ë¾Æº»´Ù.
    void GetPLCCPUType(void);
    //PLC¿Í Á¢¼ÓÀ» Á¾·áÇÑ´Ù.
    void ClosePLCConnection(void);
    
    //PLC¿¡ °ªÀ» ¾´´Ù.
    void WritePLCDataTimer(void);
    //PLC¿¡ °ªÀ» ¾´´Ù.
    void WritePLCData(void);
 
    bool CheckRequestToWritePLC(int iAddr);
 
    //¹°·ùµ¥ÀÌÅ͸¦ ÀбâÀ§ÇÑ ÇÔ¼ö
    void ReadLongData(int nID);
    //2byteÀб⸦ Çϱâ À§ÇÑ ÇÔ¼ö
    void ReadPLC(void);
    void ReadPLC2(void);
    //½Ã°£ÀÌ Áö³ª¸é timer ÈÄ ¸®¼Â
    void ResetPLCData();
 
    WORD GetWriteData(TCHAR* AddressToGetData);
 
    void ReadPLCSignal0(void);
    void ReadPLCSignal1(void);
    void ReadPLCSignal2(void);
    void ReadPLCSignal3(void);
    void ReadPLCSignal4(void);
 
    //PLC ¿¡·¯ ¹ß»ý½Ã À翬°á½Ãµµ
    void ReConnectionPLC(void);
 
    //PLC¿¡¼­ ½Ã±×³ÎÀ» °è¼Ó ¹Þ±â À§ÇÑ Worker ½º·¹µå ÇÔ¼ö
    static UINT ReadPLCWorkerThread(LPVOID pParam);
    static UINT ReadPLCWorkerThread2(LPVOID pParam);
    //PLC¿¡ °ª ¾²±â¸¦ Áö¿øÇϴ Worker ½º·¹µå ÇÔ¼ö
    static UINT WritePLCWorkerThread(LPVOID pParam);
 
    void AddLogList(CString strMsg);
 
    
private:
    bool m_bExit;
 
    CString m_RetVal;
    CString m_RetVal2;
    CString m_RetVal3;
 
    //MX Componet´Â ¼øÂ÷ Ã³¸®ÇؾßÇÔ
    //Àб⠽º·¹µå, ¾²±â ½º·¹µå ·£´ý Á¢±ÙÀ» Ã³¸®Çϱâ À§ÇÑ Å©¸®Æ¼Ä༽¼Ç
    CCriticalSection m_PLCSection;
    //PLC Connector ÀÌ»ó ¹ß»ý½Ã ·Î±×¸¦ ÀÛ¼ºÇϱâ À§ÇÑ Å©¸®Æ¼Ä༽¼Ç
    CCriticalSection m_LogSection;
public:
    CActeasyif1 m_MXComponent;
    CListBox m_ConnectorState;
 
 
    BOOL m_bAutoScroll;
    afx_msg void OnBnClickedCheckScroll();
    afx_msg void OnTimer(UINT_PTR nIDEvent);
    void RestString(char* RestPoint, int DataLength);
};
 
#ifndef _DEBUG  // PLCConnectorView.cppÀÇ µð¹ö±× ¹öÀü
inline CPLCConnectorDoc* CPLCConnectorView::GetDocument() const
   { return reinterpret_cast<CPLCConnectorDoc*>(m_pDocument); }
#endif