提交 | 用户 | age
|
0ed438
|
1 |
|
Q |
2 |
// MultiTerminal2Doc.h: CMTerm2Doc 类的接口
|
|
3 |
//
|
|
4 |
|
|
5 |
|
|
6 |
#pragma once
|
|
7 |
#include "HvSerialPort.h"
|
65f713
|
8 |
#include "AnsiParser.h"
|
Q |
9 |
#include "DataParser1.h"
|
0ed438
|
10 |
#include "KDefine.h"
|
Q |
11 |
#include "KLink.h"
|
|
12 |
#include "KMachine.h"
|
|
13 |
|
418cb3
|
14 |
#include "../KLink1/KLink.h"
|
0a20f7
|
15 |
|
418cb3
|
16 |
#pragma comment(lib,"KLink1.lib")
|
0a20f7
|
17 |
|
0ed438
|
18 |
class CMTerm2Doc : public CDocument
|
Q |
19 |
{
|
|
20 |
protected: // 仅从序列化创建
|
|
21 |
CMTerm2Doc() noexcept;
|
|
22 |
DECLARE_DYNCREATE(CMTerm2Doc)
|
|
23 |
|
|
24 |
// 特性
|
|
25 |
public:
|
|
26 |
//通讯参数。
|
|
27 |
CAnsiParser MyAnsiParser1;
|
|
28 |
CDataParser1 MyDataParser1;
|
|
29 |
KLink MyKLink1;
|
|
30 |
// CSerialCom MySerialCom1;
|
|
31 |
HvSerialPort myHvSerialPort1;
|
|
32 |
KMachine myKMachine1;
|
418cb3
|
33 |
KLink1 MyKlink2;
|
0ed438
|
34 |
|
Q |
35 |
|
|
36 |
bool m_bCommParamSet = false;
|
|
37 |
int nComPort;
|
|
38 |
int nBaud;
|
|
39 |
CStringA ComSettings;
|
|
40 |
bool m_bOnline = false;
|
|
41 |
bool m_bSimulate = false;
|
|
42 |
bool m_bPlcRunning = false;
|
|
43 |
|
|
44 |
double StartTime;
|
|
45 |
//系统配置文件
|
|
46 |
|
|
47 |
//数据存储区
|
|
48 |
int m_nNum=15;
|
|
49 |
CString m_Str;
|
|
50 |
CString m_sMachineType = _T("KL20N16D");;
|
|
51 |
|
|
52 |
//程序存储
|
|
53 |
CString ProgTxt;
|
|
54 |
|
|
55 |
|
65f713
|
56 |
struct stTypeNameDef
|
0ed438
|
57 |
{
|
Q |
58 |
int nType;
|
|
59 |
CStringA TypeTxt;
|
|
60 |
};
|
65f713
|
61 |
static stTypeNameDef CoilTypeNameDef[];
|
0ed438
|
62 |
static int nCoilTypeDefCount;
|
Q |
63 |
|
65f713
|
64 |
static stTypeNameDef DataTypeNameDef[];
|
0ed438
|
65 |
static int nDataTypeDefCount;
|
Q |
66 |
|
|
67 |
stKMem KMem;
|
|
68 |
|
|
69 |
enum enParamTypes
|
|
70 |
{
|
|
71 |
KLParamCoil,
|
|
72 |
KLParamWord,
|
|
73 |
KLParamNum,
|
|
74 |
|
|
75 |
};
|
0a20f7
|
76 |
struct stOpDef
|
0ed438
|
77 |
{
|
Q |
78 |
int nOpType1;
|
|
79 |
CStringA OpTxt;
|
|
80 |
int nParamCount;
|
|
81 |
int nParamType;
|
|
82 |
CStringA ShowTxt;
|
|
83 |
};
|
0a20f7
|
84 |
static stOpDef OpDef[];
|
0ed438
|
85 |
|
0a20f7
|
86 |
static int nOpDefCount;
|
0ed438
|
87 |
struct stParam
|
Q |
88 |
{
|
|
89 |
CStringA sParamStr;
|
|
90 |
int nParamType;
|
|
91 |
int nParamAddr;
|
|
92 |
};
|
|
93 |
|
|
94 |
struct stProg
|
|
95 |
{
|
|
96 |
int nOpType1;
|
|
97 |
int nBinStep;
|
|
98 |
int nParamCount;
|
|
99 |
stParam Params[3];
|
|
100 |
int PairTo;
|
|
101 |
};
|
|
102 |
|
|
103 |
|
|
104 |
struct stCoilAnno
|
|
105 |
{
|
|
106 |
unsigned short nType;
|
|
107 |
unsigned short nAddr;
|
|
108 |
CString sCoilName;
|
|
109 |
CString sAnno;
|
|
110 |
};
|
|
111 |
stCoilAnno mCoilAnnos[10000]=
|
|
112 |
{
|
|
113 |
};
|
|
114 |
|
|
115 |
int nCoilAnnoCount = 0;
|
|
116 |
|
|
117 |
|
|
118 |
|
|
119 |
enum enSection {
|
|
120 |
SectionNone = 0,
|
|
121 |
SectionSysCfg = 1,
|
|
122 |
SectionProg = 2,
|
|
123 |
SectionAnno = 3,
|
|
124 |
SectionCoilList = 4,
|
|
125 |
SectionDataList = 5,
|
|
126 |
};
|
|
127 |
|
|
128 |
struct stSectionDef
|
|
129 |
{
|
|
130 |
int nSectionType;
|
|
131 |
CStringA SectionName;
|
|
132 |
};
|
|
133 |
stSectionDef SectionDef[5]=
|
|
134 |
{
|
|
135 |
{SectionSysCfg,"SYSCFG"},
|
|
136 |
{SectionProg,"PROG"},
|
|
137 |
{SectionAnno,"COMMENT"},
|
|
138 |
{SectionCoilList,"MONCOILLIST"},
|
|
139 |
{SectionDataList,"MONDATALIST"},
|
|
140 |
};
|
|
141 |
int nSectionDefCount = sizeof(SectionDef) / sizeof(stSectionDef);
|
|
142 |
int TxtToSection(CStringA txt);
|
|
143 |
int GetSectionTxt(int nSectionType, CStringA & txt);
|
|
144 |
int ScanSections();
|
|
145 |
|
|
146 |
struct stSection{
|
|
147 |
int nSectionType;
|
|
148 |
int nSectionLineNo;
|
|
149 |
int nLines;
|
|
150 |
};
|
|
151 |
stSection Sections[100] = { 0 };
|
|
152 |
int nSectionCount;
|
|
153 |
|
|
154 |
int GetSectionPos(int nSectionType, int * nSectionLine, int * nSectionLines);
|
|
155 |
|
|
156 |
// 操作
|
|
157 |
public:
|
|
158 |
int TxtToOp(CStringA optxt, int* ParamCount, int* ParamType);
|
|
159 |
int OpToTxt(int nOp, CStringA & OpTxt);
|
|
160 |
int OpToShowTxt(int nOp, CStringA & OpShowTxt);
|
|
161 |
|
|
162 |
int TxtToCoilType(CStringA Typetxt, int* nCoilType, int* CoilAddr);
|
|
163 |
int CoilTypeToTxt(int nType, CStringA & typeTxt);
|
|
164 |
|
|
165 |
int TxtToDataType(CStringA Typetxt, int * nDataType, int* nDataAddr);
|
|
166 |
int DataTypeToTxt(int nType, CStringA & typeTxt);
|
|
167 |
|
|
168 |
int TransLinesToProg(const CStringArray & txtLines, int StartLine = 0, int ProgLines = -1);
|
|
169 |
|
|
170 |
int TransFileToProg(CStringA ProgTxt);
|
|
171 |
int TransToTxt(CStringA &ProgTxt);
|
|
172 |
|
|
173 |
int TransTxtToProg(CStringA ProgTxtA);
|
|
174 |
int ReadAnnoFromTxt(CStringA AnnoTxtA);
|
|
175 |
|
|
176 |
int TransProgToBin();
|
|
177 |
int TransBinToProg();
|
|
178 |
|
|
179 |
|
|
180 |
int LoadFromFile(CString sFilePathName);
|
|
181 |
int SaveToFile(CString sFilePathName);
|
|
182 |
|
|
183 |
stProg Progs[2048] = { 0 };
|
|
184 |
int ProgTrace[2048] = { 0 };
|
|
185 |
int m_nProgSteps = 0;
|
|
186 |
stBinProg1 BinProgs[2000];
|
|
187 |
int nBinProgSteps = 0;
|
|
188 |
|
|
189 |
|
|
190 |
int nScanCount = 0;
|
|
191 |
int GetAnno(unsigned short nType, unsigned short nAddr, CString & sAnno);
|
|
192 |
int SetAnno(CString sCoilName, CString sAnno);
|
|
193 |
int SetAnno(unsigned short nType, unsigned short nAddr, CString sCoilName, CString sAnno);
|
|
194 |
|
|
195 |
// 重写
|
|
196 |
public:
|
|
197 |
virtual BOOL OnNewDocument();
|
|
198 |
virtual void Serialize(CArchive& ar);
|
|
199 |
#ifdef SHARED_HANDLERS
|
|
200 |
virtual void InitializeSearchContent();
|
|
201 |
virtual void OnDrawThumbnail(CDC& dc, LPRECT lprcBounds);
|
|
202 |
#endif // SHARED_HANDLERS
|
|
203 |
|
|
204 |
// 实现
|
|
205 |
public:
|
|
206 |
virtual ~CMTerm2Doc();
|
|
207 |
#ifdef _DEBUG
|
|
208 |
virtual void AssertValid() const;
|
|
209 |
virtual void Dump(CDumpContext& dc) const;
|
|
210 |
#endif
|
|
211 |
|
|
212 |
enum UpdataHint {
|
|
213 |
UpdateAll=0,
|
|
214 |
UpdateProg=1,
|
|
215 |
UpdateStat=2,
|
|
216 |
};
|
|
217 |
protected:
|
|
218 |
|
|
219 |
// 生成的消息映射函数
|
|
220 |
protected:
|
|
221 |
DECLARE_MESSAGE_MAP()
|
|
222 |
|
|
223 |
#ifdef SHARED_HANDLERS
|
|
224 |
// 用于为搜索处理程序设置搜索内容的 Helper 函数
|
|
225 |
void SetSearchContent(const CString& value);
|
|
226 |
#endif // SHARED_HANDLERS
|
|
227 |
public:
|
|
228 |
int SetCommParam();
|
|
229 |
int Connect();
|
|
230 |
int DisConnect();
|
|
231 |
int SendPacket(void * pBuf, int Len);
|
|
232 |
int RecvPacket(void * pBuf, int Len);
|
|
233 |
|
|
234 |
CView * CMTerm2Doc::FindView(CRuntimeClass * pClass);
|
|
235 |
|
|
236 |
virtual BOOL OnOpenDocument(LPCTSTR lpszPathName);
|
|
237 |
virtual BOOL OnSaveDocument(LPCTSTR lpszPathName);
|
|
238 |
virtual void OnCloseDocument();
|
|
239 |
|
|
240 |
afx_msg void OnUploadFromPlc();
|
|
241 |
afx_msg void OnOnline();
|
|
242 |
afx_msg void OnUpdateOnline(CCmdUI *pCmdUI);
|
|
243 |
afx_msg void OnOffline();
|
|
244 |
afx_msg void OnUpdateOffline(CCmdUI *pCmdUI);
|
|
245 |
afx_msg void OnPlcRun();
|
|
246 |
afx_msg void OnUpdatePlcRun(CCmdUI *pCmdUI);
|
|
247 |
afx_msg void OnDownloadToPlc();
|
|
248 |
afx_msg void OnUpdateDownloadToPlc(CCmdUI *pCmdUI);
|
|
249 |
afx_msg void OnComunicationSet();
|
|
250 |
afx_msg void OnPlcSysregSet();
|
|
251 |
|
|
252 |
afx_msg void OnMenuViewLds();
|
|
253 |
afx_msg void OnMenuViewBld();
|
|
254 |
afx_msg void OnMenuViewBnl();
|
|
255 |
afx_msg void OnMenuShowConsole();
|
|
256 |
|
|
257 |
afx_msg void OnMenuCommTest();
|
|
258 |
|
|
259 |
int GetCoilValue(int nCoilType, int nCoilAddr);
|
|
260 |
int SetCoilValue(int nCoilType, int nCoilAddr, int nCoilValue);
|
|
261 |
|
|
262 |
int GetVarData(int nDataType, int nDataAddr);
|
|
263 |
int SetVarData(int nDataType, int nDataAddr, int nDataValue);
|
|
264 |
|
|
265 |
|
|
266 |
void OnTimer(UINT_PTR nIDEvent);
|
|
267 |
|
|
268 |
int StartPLC();
|
|
269 |
int StopPLC();
|
|
270 |
|
|
271 |
|
|
272 |
afx_msg void OnSimulate();
|
|
273 |
afx_msg void OnUpdateSimulate(CCmdUI *pCmdUI);
|
|
274 |
int DownloadToPLC();
|
|
275 |
|
|
276 |
int AddMonitorCoil(int nCoilType, int nCoilAddr, int nCount);
|
|
277 |
int AddMonitorData(int nDataType, int nDataAddr, int nDataCount);
|
|
278 |
int ClearMonitor();
|
|
279 |
int DoPLCMonitor();
|
326d3e
|
280 |
afx_msg void OnMenuStatusShow();
|
65f713
|
281 |
afx_msg void OnMenuFactCfg();
|
b5e652
|
282 |
afx_msg void OnMenuDatetimeSet();
|
YC |
283 |
afx_msg void OnMenuEventLog();
|
0ed438
|
284 |
};
|