提交 | 用户 | age
|
4b03ae
|
1 |
|
418cb3
|
2 |
// MultiTerminal2Doc.cpp: CMTerm1Doc 类的实现
|
4b03ae
|
3 |
//
|
Q |
4 |
|
|
5 |
#include "pch.h"
|
|
6 |
#include "framework.h"
|
|
7 |
// SHARED_HANDLERS 可以在实现预览、缩略图和搜索筛选器句柄的
|
|
8 |
// ATL 项目中进行定义,并允许与该项目共享文档代码。
|
|
9 |
#ifndef SHARED_HANDLERS
|
0ed438
|
10 |
#include "MTerm1.h"
|
4b03ae
|
11 |
#endif
|
Q |
12 |
|
0ed438
|
13 |
#include "MTerm1Doc.h"
|
4b03ae
|
14 |
|
418cb3
|
15 |
#include "MTerm1View.h"
|
Q |
16 |
#include "MTerm1LdsView.h"
|
|
17 |
#include "MTerm1BldView.h"
|
|
18 |
#include "MTerm1BnlView.h"
|
|
19 |
|
|
20 |
#include "MTerm1CoilView.h"
|
|
21 |
#include "MTerm1DataView.h"
|
|
22 |
|
|
23 |
#include "MTerm1CtrlView.h"
|
|
24 |
#include "MTerm1TestView.h"
|
|
25 |
#include "MTerm1ProgTxt.h"
|
|
26 |
#include "MTerm1CommDevView.h"
|
4b03ae
|
27 |
#include <propkey.h>
|
418cb3
|
28 |
|
Q |
29 |
#include "DialogCommSet1.h"
|
|
30 |
#include "DialogStatusShow.h"
|
|
31 |
#include "DialogSysRegSet.h"
|
|
32 |
#include "DialogFactCfg.h"
|
|
33 |
#include "DialogDateTime.h"
|
|
34 |
#include "DialogEventLog.h"
|
|
35 |
//#include "HvSerialPort.h"
|
|
36 |
#include <functional>
|
4b03ae
|
37 |
|
Q |
38 |
#ifdef _DEBUG
|
|
39 |
#define new DEBUG_NEW
|
|
40 |
#endif
|
|
41 |
|
0ed438
|
42 |
// CMTerm1Doc
|
418cb3
|
43 |
CMTerm1Doc::stTypeNameDef CMTerm1Doc::CoilTypeNameDef[] =
|
Q |
44 |
{
|
|
45 |
{KLCoilTypeX,"X"},
|
|
46 |
{KLCoilTypeY,"Y"},
|
|
47 |
{KLCoilTypeR,"R"},
|
|
48 |
{KLCoilTypeLX,"LX"},
|
|
49 |
{KLCoilTypeLY,"LY"},
|
|
50 |
{KLCoilTypeLR,"LR"},
|
|
51 |
{KLCoilTypeSR,"SR"},
|
|
52 |
{KLCoilTypeC,"C"},
|
|
53 |
{KLCoilTypeT,"T"},
|
4ed7fc
|
54 |
{KLCoilTypeP,"P"},
|
Z |
55 |
{KLCoilTypeE,"E"},
|
418cb3
|
56 |
};
|
Q |
57 |
int CMTerm1Doc::nCoilTypeDefCount = sizeof(CMTerm1Doc::CoilTypeNameDef) / sizeof(stTypeNameDef);
|
|
58 |
|
|
59 |
CMTerm1Doc::stTypeNameDef CMTerm1Doc::DataTypeNameDef[] =
|
|
60 |
{
|
|
61 |
{KLDataTypeDEC,"K"},
|
|
62 |
{KLDataTypeHEX,"H"},
|
|
63 |
{KLDataTypeWX,"WX"},
|
|
64 |
{KLDataTypeWY,"WY"},
|
|
65 |
{KLDataTypeWR,"WR"},
|
|
66 |
{KLDataTypeDT,"DT"},
|
|
67 |
{KLDataTypeWLX,"WLX"},
|
|
68 |
{KLDataTypeWLY,"WLY"},
|
|
69 |
{KLDataTypeSDT,"SDT"},
|
|
70 |
{KLDataTypeWSR,"WSR"},
|
|
71 |
{KLDataTypeEV,"EV"},
|
|
72 |
{KLDataTypeSV,"SV"},
|
|
73 |
{KLDataTypeLD,"LD"},
|
|
74 |
};
|
|
75 |
int CMTerm1Doc::nDataTypeDefCount = sizeof(CMTerm1Doc::DataTypeNameDef) / sizeof(stTypeNameDef);
|
|
76 |
|
|
77 |
CMTerm1Doc::stOpDef CMTerm1Doc::OpDef[] =
|
|
78 |
{
|
|
79 |
{OP_NOP,"NOP",0},
|
|
80 |
{OP_ST,"ST",1,KLParamCoil},
|
|
81 |
{OP_ST_,"ST/",1,KLParamCoil},
|
|
82 |
{OP_AN,"AN",1,KLParamCoil},
|
|
83 |
{OP_AN_,"AN/",1,KLParamCoil},
|
|
84 |
{OP_OR,"OR",1,KLParamCoil},
|
|
85 |
{OP_OR_,"OR/",1,KLParamCoil},
|
|
86 |
{OP_NOT,"NOT"},
|
|
87 |
{OP_ANS,"ANS"},
|
|
88 |
{OP_ORS,"ORS"}
|
|
89 |
,
|
|
90 |
{OP_PSHS,"PSHS"},
|
|
91 |
{OP_RDS,"RDS"},
|
|
92 |
{OP_POPS,"POPS"},
|
|
93 |
{OP_OUT,"OUT",1,KLParamCoil},
|
|
94 |
{OP_SET,"SET",1,KLParamCoil},
|
|
95 |
{OP_RESET,"RESET",1,KLParamCoil},
|
|
96 |
{OP_DF,"DF"},
|
|
97 |
{OP_DF_,"DF/"},
|
|
98 |
{OP_ST_EQ,"ST=",2,KLParamWord,"="},
|
|
99 |
{OP_ST_LT,"ST<",2,KLParamWord,"<"},
|
|
100 |
{OP_ST_GT,"ST>",2,KLParamWord,">"},
|
|
101 |
{OP_ST_LE,"ST<=",2,KLParamWord,"<="},
|
|
102 |
{OP_ST_GE,"ST>=",2,KLParamWord,">="},
|
|
103 |
{OP_ST_NE,"ST<>",2,KLParamWord,"<>"},
|
|
104 |
{OP_AN_EQ,"AN=",2,KLParamWord,"="},
|
|
105 |
{OP_AN_LT,"AN<",2,KLParamWord,"<"},
|
|
106 |
{OP_AN_GT,"AN>",2,KLParamWord,">"},
|
|
107 |
{OP_AN_LE,"AN<=",2,KLParamWord,"<="},
|
|
108 |
{OP_AN_GE,"AN>=",2,KLParamWord,">="},
|
|
109 |
{OP_AN_NE,"AN<>",2,KLParamWord,"<>"},
|
|
110 |
{OP_OR_EQ,"OR=",2,KLParamWord,"="},
|
|
111 |
{OP_OR_LT,"OR<",2,KLParamWord,"<"},
|
|
112 |
{OP_OR_GT,"OR>",2,KLParamWord,">"},
|
|
113 |
{OP_OR_LE,"OR<=",2,KLParamWord,"<="},
|
|
114 |
{OP_OR_GE,"OR>=",2,KLParamWord,">="},
|
|
115 |
{OP_OR_NE,"OR<>",2,KLParamWord,"<>"},
|
|
116 |
|
|
117 |
{OP_TML,"TML",2,KLParamWord,"TML"},
|
|
118 |
{OP_TMR,"TMR",2,KLParamWord,"TMR"},
|
|
119 |
{OP_TMX,"TMX",2,KLParamWord,"TMX"},
|
|
120 |
{OP_TMY,"TMY",2,KLParamWord,"TMY"},
|
|
121 |
|
|
122 |
{OP_MV,"MV",2,KLParamWord,"MV"},
|
|
123 |
{OP_INC,"INC",1,KLParamWord,"+1"},
|
|
124 |
{OP_ADD2,"ADD2",2,KLParamWord,"+"},
|
|
125 |
{OP_ADD3,"ADD3",3,KLParamWord,"+"},
|
|
126 |
{OP_DEC,"DEC",1,KLParamWord,"-1"},
|
|
127 |
{OP_SUB2,"SUB2",2,KLParamWord,"-"},
|
|
128 |
{OP_SUB3,"SUB3",3,KLParamWord,"-"},
|
|
129 |
{OP_MUL,"MUL",3,KLParamWord,"X"},
|
|
130 |
{OP_DIV,"DIV",3,KLParamWord,"/"},
|
|
131 |
|
|
132 |
};
|
|
133 |
int CMTerm1Doc::nOpDefCount = sizeof(CMTerm1Doc::OpDef) / sizeof(stOpDef);
|
4b03ae
|
134 |
|
0ed438
|
135 |
IMPLEMENT_DYNCREATE(CMTerm1Doc, CDocument)
|
4b03ae
|
136 |
|
0ed438
|
137 |
BEGIN_MESSAGE_MAP(CMTerm1Doc, CDocument)
|
418cb3
|
138 |
ON_COMMAND(ID_UPLOAD_FROM_PLC, &CMTerm1Doc::OnUploadFromPlc)
|
Q |
139 |
ON_COMMAND(ID_ONLINE, &CMTerm1Doc::OnOnline)
|
|
140 |
ON_UPDATE_COMMAND_UI(ID_ONLINE, &CMTerm1Doc::OnUpdateOnline)
|
|
141 |
ON_COMMAND(ID_OFFLINE, &CMTerm1Doc::OnOffline)
|
|
142 |
ON_UPDATE_COMMAND_UI(ID_OFFLINE, &CMTerm1Doc::OnUpdateOffline)
|
|
143 |
ON_COMMAND(ID_PLC_RUN, &CMTerm1Doc::OnPlcRun)
|
|
144 |
ON_UPDATE_COMMAND_UI(ID_PLC_RUN, &CMTerm1Doc::OnUpdatePlcRun)
|
|
145 |
ON_COMMAND(ID_DOWNLOAD_TO_PLC, &CMTerm1Doc::OnDownloadToPlc)
|
|
146 |
ON_UPDATE_COMMAND_UI(ID_DOWNLOAD_TO_PLC, &CMTerm1Doc::OnUpdateDownloadToPlc)
|
|
147 |
|
|
148 |
ON_COMMAND(ID_COMUNICATION_SET, &CMTerm1Doc::OnComunicationSet)
|
|
149 |
ON_COMMAND(ID_PLC_SYSREG_SET, &CMTerm1Doc::OnPlcSysregSet)
|
|
150 |
|
|
151 |
ON_COMMAND(ID_MENU_VIEW_LDS, &CMTerm1Doc::OnMenuViewLds)
|
|
152 |
ON_COMMAND(ID_MENU_VIEW_BLD, &CMTerm1Doc::OnMenuViewBld)
|
|
153 |
ON_COMMAND(ID_MENU_VIEW_BNL, &CMTerm1Doc::OnMenuViewBnl)
|
|
154 |
ON_COMMAND(ID_MENU_SHOW_CONSOLE, &CMTerm1Doc::OnMenuShowConsole)
|
|
155 |
|
|
156 |
ON_COMMAND(ID_MENU_COMM_TEST, &CMTerm1Doc::OnMenuCommTest)
|
|
157 |
|
|
158 |
|
|
159 |
ON_COMMAND(ID_SIMULATE, &CMTerm1Doc::OnSimulate)
|
|
160 |
ON_UPDATE_COMMAND_UI(ID_SIMULATE, &CMTerm1Doc::OnUpdateSimulate)
|
|
161 |
ON_COMMAND(ID_MENU_STATUS_SHOW, &CMTerm1Doc::OnMenuStatusShow)
|
|
162 |
ON_COMMAND(ID_MENU_FACT_CFG, &CMTerm1Doc::OnMenuFactCfg)
|
|
163 |
ON_COMMAND(ID_MENU_DATETIME_SET, &CMTerm1Doc::OnMenuDatetimeSet)
|
|
164 |
ON_COMMAND(ID_MENU_EVENT_LOG, &CMTerm1Doc::OnMenuEventLog)
|
4b03ae
|
165 |
END_MESSAGE_MAP()
|
Q |
166 |
|
|
167 |
|
0ed438
|
168 |
// CMTerm1Doc 构造/析构
|
4b03ae
|
169 |
|
0ed438
|
170 |
CMTerm1Doc::CMTerm1Doc() noexcept
|
4b03ae
|
171 |
{
|
Q |
172 |
// TODO: 在此添加一次性构造代码
|
|
173 |
|
418cb3
|
174 |
KLink1::stCallBackFuncs callbackfuncs;
|
Q |
175 |
// callbackfuncs.OpenFunc = std::bind(&HvSerialPort::Open, &myHvSerialPort1);
|
|
176 |
// callbackfuncs.CloseFunc = std::bind(&HvSerialPort::Close, &myHvSerialPort1);
|
|
177 |
// callbackfuncs.ClearBufFunc = std::bind(&HvSerialPort::ClearBuf, &myHvSerialPort1);
|
|
178 |
|
|
179 |
// callbackfuncs.SendPkgFunc = std::bind(&HvSerialPort::Send, &myHvSerialPort1, std::placeholders::_1, std::placeholders::_2);
|
|
180 |
// callbackfuncs.RecvPkgFunc = std::bind(&HvSerialPort::Recv, &myHvSerialPort1, std::placeholders::_1, std::placeholders::_2);
|
|
181 |
|
|
182 |
// MyKLink1.SetCallBackFuncs(&callbackfuncs);
|
|
183 |
|
|
184 |
// StartTime = myHvSerialPort1.GetTimemS();
|
4b03ae
|
185 |
}
|
Q |
186 |
|
0ed438
|
187 |
CMTerm1Doc::~CMTerm1Doc()
|
4b03ae
|
188 |
{
|
Q |
189 |
}
|
418cb3
|
190 |
/*
|
Q |
191 |
int CMTerm1Doc::SendPacket(void * pBuf, int Len)
|
|
192 |
{
|
|
193 |
return myHvSerialPort1.Send((char *)pBuf, Len);
|
|
194 |
}
|
|
195 |
int CMTerm1Doc::RecvPacket(void * pBuf, int Len)
|
|
196 |
{
|
|
197 |
int j = 0;
|
|
198 |
j = myHvSerialPort1.Recv((char *)pBuf, Len);
|
|
199 |
if (j <= 0)
|
|
200 |
{
|
|
201 |
CString s1;
|
|
202 |
s1.Format(_T("Read %d R=%d %s"), Len, j, myHvSerialPort1.m_strResult);
|
|
203 |
SysLog(s1);
|
|
204 |
}
|
|
205 |
return j;
|
|
206 |
}
|
|
207 |
*/
|
4b03ae
|
208 |
|
d34256
|
209 |
/// <summary>
|
Z |
210 |
/// 处理新文档的创建事件
|
|
211 |
/// </summary>
|
|
212 |
/// <returns></returns>
|
0ed438
|
213 |
BOOL CMTerm1Doc::OnNewDocument()
|
4b03ae
|
214 |
{
|
Q |
215 |
if (!CDocument::OnNewDocument())
|
d34256
|
216 |
{
|
4b03ae
|
217 |
return FALSE;
|
d34256
|
218 |
|
Z |
219 |
}
|
4b03ae
|
220 |
|
Q |
221 |
// TODO: 在此添加重新初始化代码
|
|
222 |
// (SDI 文档将重用该文档)
|
d34256
|
223 |
//LoadFromFile(_T("0prog1.txt"));
|
418cb3
|
224 |
return TRUE;
|
d34256
|
225 |
|
418cb3
|
226 |
}
|
d34256
|
227 |
|
Z |
228 |
/// <summary>
|
|
229 |
/// 处理打开的文档
|
|
230 |
/// </summary>
|
|
231 |
/// <param name="lpszPathName">指向要打开的文件路径的指针</param>
|
|
232 |
/// <returns></returns>
|
418cb3
|
233 |
BOOL CMTerm1Doc::OnOpenDocument(LPCTSTR lpszPathName)
|
Q |
234 |
{
|
|
235 |
// if (!CDocument::OnOpenDocument(lpszPathName))
|
|
236 |
// return FALSE;
|
0ed438
|
237 |
|
d34256
|
238 |
CString s1;//日志信息
|
418cb3
|
239 |
s1.Format(_T("OnOpenDocument %s"), lpszPathName);
|
Q |
240 |
SysLog(s1);
|
d34256
|
241 |
|
Z |
242 |
//加载文件内容
|
418cb3
|
243 |
LoadFromFile(lpszPathName);
|
4b03ae
|
244 |
return TRUE;
|
Q |
245 |
}
|
|
246 |
|
d34256
|
247 |
/// <summary>
|
Z |
248 |
/// 处理保存文档的事件
|
|
249 |
/// </summary>
|
|
250 |
/// <param name="lpszPathName">指向要打开的文件路径的指针</param>
|
|
251 |
/// <returns></returns>
|
418cb3
|
252 |
BOOL CMTerm1Doc::OnSaveDocument(LPCTSTR lpszPathName)
|
Q |
253 |
{
|
|
254 |
// TODO: 在此添加专用代码和/或调用基类
|
|
255 |
CString s1;
|
|
256 |
s1.Format(_T("OnSaveDocument %s"), lpszPathName);
|
|
257 |
SysLog(s1);
|
d34256
|
258 |
|
Z |
259 |
//0912-zxd-Modify
|
|
260 |
int result = SaveToFile(lpszPathName);
|
|
261 |
return result == 1 ? TRUE : FALSE;
|
418cb3
|
262 |
// return CDocument::OnSaveDocument(lpszPathName);
|
Q |
263 |
}
|
4b03ae
|
264 |
|
d34256
|
265 |
/// <summary>
|
Z |
266 |
/// 处理关闭文档的事件
|
|
267 |
/// </summary>
|
418cb3
|
268 |
void CMTerm1Doc::OnCloseDocument()
|
Q |
269 |
{
|
|
270 |
// TODO: 在此添加专用代码和/或调用基类
|
|
271 |
// CString s1;
|
|
272 |
// s1.Format(_T("OnCloseDocument %s"));
|
|
273 |
// SysLog(s1);
|
|
274 |
CDocument::OnCloseDocument();
|
|
275 |
}
|
4b03ae
|
276 |
|
d34256
|
277 |
/// <summary>
|
Z |
278 |
/// CMTerm1Doc 序列化
|
|
279 |
/// </summary>
|
|
280 |
/// <param name="ar"></param>
|
0ed438
|
281 |
void CMTerm1Doc::Serialize(CArchive& ar)
|
4b03ae
|
282 |
{
|
418cb3
|
283 |
CString s1;
|
4b03ae
|
284 |
if (ar.IsStoring())
|
Q |
285 |
{
|
|
286 |
// TODO: 在此添加存储代码
|
418cb3
|
287 |
ar.GetFile();
|
Q |
288 |
s1.Format(_T("Serialize Saving"));
|
|
289 |
SysLog(s1);
|
4b03ae
|
290 |
}
|
Q |
291 |
else
|
|
292 |
{
|
|
293 |
// TODO: 在此添加加载代码
|
418cb3
|
294 |
s1.Format(_T("Serialize Loading"));
|
Q |
295 |
SysLog(s1);
|
4b03ae
|
296 |
}
|
Q |
297 |
}
|
|
298 |
|
|
299 |
#ifdef SHARED_HANDLERS
|
|
300 |
|
|
301 |
// 缩略图的支持
|
0ed438
|
302 |
void CMTerm1Doc::OnDrawThumbnail(CDC& dc, LPRECT lprcBounds)
|
4b03ae
|
303 |
{
|
Q |
304 |
// 修改此代码以绘制文档数据
|
|
305 |
dc.FillSolidRect(lprcBounds, RGB(255, 255, 255));
|
|
306 |
|
|
307 |
CString strText = _T("TODO: implement thumbnail drawing here");
|
|
308 |
LOGFONT lf;
|
|
309 |
|
|
310 |
CFont* pDefaultGUIFont = CFont::FromHandle((HFONT) GetStockObject(DEFAULT_GUI_FONT));
|
|
311 |
pDefaultGUIFont->GetLogFont(&lf);
|
|
312 |
lf.lfHeight = 36;
|
|
313 |
|
|
314 |
CFont fontDraw;
|
|
315 |
fontDraw.CreateFontIndirect(&lf);
|
|
316 |
|
|
317 |
CFont* pOldFont = dc.SelectObject(&fontDraw);
|
|
318 |
dc.DrawText(strText, lprcBounds, DT_CENTER | DT_WORDBREAK);
|
|
319 |
dc.SelectObject(pOldFont);
|
|
320 |
}
|
|
321 |
|
|
322 |
// 搜索处理程序的支持
|
0ed438
|
323 |
void CMTerm1Doc::InitializeSearchContent()
|
4b03ae
|
324 |
{
|
Q |
325 |
CString strSearchContent;
|
|
326 |
// 从文档数据设置搜索内容。
|
|
327 |
// 内容部分应由“;”分隔
|
|
328 |
|
|
329 |
// 例如: strSearchContent = _T("point;rectangle;circle;ole object;");
|
|
330 |
SetSearchContent(strSearchContent);
|
|
331 |
}
|
|
332 |
|
d34256
|
333 |
/// <summary>
|
Z |
334 |
/// 设置文档的搜索内容
|
|
335 |
/// </summary>
|
|
336 |
/// <param name="value">要搜索内容的字符串值</param>
|
0ed438
|
337 |
void CMTerm1Doc::SetSearchContent(const CString& value)
|
4b03ae
|
338 |
{
|
Q |
339 |
if (value.IsEmpty())
|
|
340 |
{
|
|
341 |
RemoveChunk(PKEY_Search_Contents.fmtid, PKEY_Search_Contents.pid);
|
|
342 |
}
|
|
343 |
else
|
|
344 |
{
|
|
345 |
CMFCFilterChunkValueImpl *pChunk = nullptr;
|
|
346 |
ATLTRY(pChunk = new CMFCFilterChunkValueImpl);
|
|
347 |
if (pChunk != nullptr)
|
|
348 |
{
|
|
349 |
pChunk->SetTextValue(PKEY_Search_Contents, value, CHUNK_TEXT);
|
|
350 |
SetChunkValue(pChunk);
|
|
351 |
}
|
|
352 |
}
|
|
353 |
}
|
|
354 |
|
|
355 |
#endif // SHARED_HANDLERS
|
|
356 |
|
0ed438
|
357 |
// CMTerm1Doc 诊断
|
4b03ae
|
358 |
|
Q |
359 |
#ifdef _DEBUG
|
d34256
|
360 |
/// <summary>
|
Z |
361 |
/// 验证对象的有效性
|
|
362 |
/// </summary>
|
0ed438
|
363 |
void CMTerm1Doc::AssertValid() const
|
4b03ae
|
364 |
{
|
Q |
365 |
CDocument::AssertValid();
|
|
366 |
}
|
d34256
|
367 |
/// <summary>
|
Z |
368 |
/// 诊断信息的输出
|
|
369 |
/// </summary>
|
|
370 |
/// <param name="dc"></param>
|
0ed438
|
371 |
void CMTerm1Doc::Dump(CDumpContext& dc) const
|
4b03ae
|
372 |
{
|
Q |
373 |
CDocument::Dump(dc);
|
|
374 |
}
|
|
375 |
#endif //_DEBUG
|
|
376 |
|
|
377 |
|
d34256
|
378 |
/// <summary>
|
Z |
379 |
/// 加载指定的文件
|
|
380 |
/// </summary>
|
|
381 |
/// <param name="sFilePathName">需要加载的文件的路径名</param>
|
|
382 |
/// <returns></returns>
|
418cb3
|
383 |
int CMTerm1Doc::LoadFromFile(CString sFilePathName)
|
Q |
384 |
{
|
d34256
|
385 |
CFile file1;//打开指定的文件
|
418cb3
|
386 |
CFileException e;
|
Q |
387 |
bool r = file1.Open(sFilePathName, CFile::modeRead, &e);
|
|
388 |
if (r)
|
|
389 |
{
|
|
390 |
int l = (int)file1.GetLength();
|
|
391 |
CStringA s1A;
|
|
392 |
file1.Read(s1A.GetBuffer(l + 2048), l);
|
|
393 |
file1.Close();
|
|
394 |
s1A.ReleaseBuffer(l);
|
d34256
|
395 |
|
Z |
396 |
TransFileToProg(s1A);//文件内容转换为Prog格式
|
|
397 |
UpdateAllViews(NULL);//更新所有的视图,以反映新加载的内容
|
418cb3
|
398 |
}
|
Q |
399 |
return 0;
|
|
400 |
}
|
|
401 |
|
d34256
|
402 |
/// <summary>
|
Z |
403 |
/// 保存文件
|
|
404 |
/// </summary>
|
|
405 |
/// <param name="sFilePathName">需要保存的文件的路径名</param>
|
|
406 |
/// <returns></returns>
|
418cb3
|
407 |
int CMTerm1Doc::SaveToFile(CString sFilePathName)
|
Q |
408 |
{
|
|
409 |
CString s1;
|
|
410 |
CFile file1;
|
|
411 |
CFileException e;
|
d34256
|
412 |
|
Z |
413 |
bool r = file1.Open(sFilePathName, CFile::modeReadWrite, &e);//读写模式打开文件
|
418cb3
|
414 |
if (r)
|
Q |
415 |
{
|
d34256
|
416 |
|
418cb3
|
417 |
CStringA s1A;
|
Q |
418 |
CStringA sSectionNameA;
|
|
419 |
|
|
420 |
//写入系统配置
|
d34256
|
421 |
GetSectionTxt(SectionSysCfg, sSectionNameA); //获取系统配置的文本表示
|
418cb3
|
422 |
s1A = "[" + sSectionNameA + "]\r\n";
|
d34256
|
423 |
file1.Write(s1A, s1A.GetLength());//将获取到的文本内容写入文件
|
418cb3
|
424 |
|
Q |
425 |
//写入程序
|
d34256
|
426 |
GetSectionTxt(SectionProg, sSectionNameA); //获取程序的文本表示
|
418cb3
|
427 |
s1A = "[" + sSectionNameA + "]\r\n";
|
d34256
|
428 |
file1.Write(s1A, s1A.GetLength());//获取到的文本内容写入文件
|
418cb3
|
429 |
|
d34256
|
430 |
TransToTxt(s1A);//将程序内容转换为文本格式
|
Z |
431 |
file1.Write(s1A, s1A.GetLength());//将转换后的文本内容写入文件
|
418cb3
|
432 |
|
Q |
433 |
//写入注释
|
d34256
|
434 |
GetSectionTxt(SectionAnno, sSectionNameA); //获取注释的文本表示
|
418cb3
|
435 |
s1A = "[" + sSectionNameA + "]\r\n";
|
Q |
436 |
file1.Write(s1A, s1A.GetLength());
|
d34256
|
437 |
//循环遍历所有注释,并将其写入文件
|
418cb3
|
438 |
for (int i = 0; i < nCoilAnnoCount; i++)
|
Q |
439 |
{
|
|
440 |
if (mCoilAnnos[i].sAnno.IsEmpty()) { continue; }
|
d34256
|
441 |
s1 = mCoilAnnos[i].sCoilName + _T("\t") + mCoilAnnos[i].sAnno + _T("\r\n");
|
418cb3
|
442 |
s1A = s1;
|
Q |
443 |
file1.Write(s1A, s1A.GetLength());
|
|
444 |
}
|
|
445 |
//写入触点监控列表
|
d34256
|
446 |
GetSectionTxt(SectionCoilList, sSectionNameA); //获取触点监控列表的文本表示
|
418cb3
|
447 |
s1A = "[" + sSectionNameA + "]\r\n";
|
Q |
448 |
file1.Write(s1A, s1A.GetLength());
|
d34256
|
449 |
|
418cb3
|
450 |
//写入数据监控列表
|
d34256
|
451 |
GetSectionTxt(SectionDataList, sSectionNameA); //获取数据监控列表的文本表示
|
418cb3
|
452 |
s1A = "[" + sSectionNameA + "]\r\n";
|
Q |
453 |
file1.Write(s1A, s1A.GetLength());
|
|
454 |
|
|
455 |
file1.Close();
|
d34256
|
456 |
return 1;
|
418cb3
|
457 |
}
|
d34256
|
458 |
else//文件打开失败
|
Z |
459 |
{
|
|
460 |
return 0;
|
|
461 |
}
|
418cb3
|
462 |
}
|
Q |
463 |
|
d34256
|
464 |
/// <summary>
|
Z |
465 |
/// 根据文本匹配类型的Key并返回
|
|
466 |
/// </summary>
|
|
467 |
/// <param name="txt"></param>
|
|
468 |
/// <returns></returns>
|
418cb3
|
469 |
int CMTerm1Doc::TxtToSection(CStringA txt)
|
Q |
470 |
{
|
|
471 |
for (int i = 0; i < nSectionDefCount; i++) {
|
|
472 |
if (SectionDef[i].SectionName == txt) {
|
|
473 |
return SectionDef[i].nSectionType;
|
|
474 |
}
|
|
475 |
}
|
|
476 |
return SectionNone;
|
|
477 |
}
|
|
478 |
|
d34256
|
479 |
/// <summary>
|
Z |
480 |
/// 根据Key匹配类型的文本,通过txt传递,返回查询执行结果
|
|
481 |
/// </summary>
|
|
482 |
/// <param name="nSectionType"></param>
|
|
483 |
/// <param name="txt"></param>
|
|
484 |
/// <returns></returns>
|
418cb3
|
485 |
int CMTerm1Doc::GetSectionTxt(int nSectionType, CStringA & txt)
|
Q |
486 |
{
|
|
487 |
for (int i = 0; i < nSectionDefCount; i++) {
|
|
488 |
if (SectionDef[i].nSectionType == nSectionType) {
|
|
489 |
txt = SectionDef[i].SectionName;
|
|
490 |
return true;
|
|
491 |
}
|
|
492 |
}
|
|
493 |
return false;
|
|
494 |
}
|
|
495 |
|
d34256
|
496 |
/// <summary>
|
Z |
497 |
///
|
|
498 |
/// </summary>
|
|
499 |
/// <param name="nSectionType">Section类型</param>
|
|
500 |
/// <param name="nSectionLine">行号</param>
|
|
501 |
/// <param name="nSectionLines">行数</param>
|
|
502 |
/// <returns></returns>
|
418cb3
|
503 |
int CMTerm1Doc::GetSectionPos(int nSectionType, int * nSectionLine, int * nSectionLines)
|
Q |
504 |
{
|
|
505 |
for (int i = 0; i < nSectionCount; i++) {
|
|
506 |
if (Sections[i].nSectionType == nSectionType) {
|
|
507 |
*nSectionLine = Sections[i].nSectionLineNo;
|
|
508 |
*nSectionLines = Sections[i].nLines;
|
|
509 |
return true;
|
|
510 |
}
|
|
511 |
}
|
|
512 |
return false;
|
|
513 |
}
|
|
514 |
|
d34256
|
515 |
/// <summary>
|
Z |
516 |
/// 文本表示的操作转换为其相应的操作类型、参数数量和参数类型
|
|
517 |
/// </summary>
|
|
518 |
/// <param name="optxt">表示操作的字符串</param>
|
|
519 |
/// <param name="ParamCount">返回与给定操作相对应的参数数量</param>
|
|
520 |
/// <param name="ParamType">返回与给定操作相对应的参数类型</param>
|
|
521 |
/// <returns>-1:匹配失败</returns>
|
418cb3
|
522 |
int CMTerm1Doc::TxtToOp(CStringA optxt, int* ParamCount, int* ParamType)
|
Q |
523 |
{
|
|
524 |
for (int i = 0; i < nOpDefCount; i++){
|
|
525 |
if (OpDef[i].OpTxt == optxt) {
|
|
526 |
*ParamCount = OpDef[i].nParamCount;
|
|
527 |
*ParamType = OpDef[i].nParamType;
|
|
528 |
return OpDef[i].nOpType1;
|
|
529 |
}
|
|
530 |
}
|
|
531 |
return -1;
|
|
532 |
}
|
d34256
|
533 |
|
Z |
534 |
/// <summary>
|
|
535 |
/// 操作类型转换为其相应的文本表示
|
|
536 |
/// </summary>
|
|
537 |
/// <param name="nOp">操作类型</param>
|
|
538 |
/// <param name="OpTxt">操作文本</param>
|
|
539 |
/// <returns></returns>
|
418cb3
|
540 |
int CMTerm1Doc::OpToTxt(int nOp, CStringA & OpTxt)
|
Q |
541 |
{
|
|
542 |
for (int i = 0; i < nOpDefCount; i++){
|
|
543 |
if (OpDef[i].nOpType1 == nOp) {
|
|
544 |
OpTxt = OpDef[i].OpTxt;
|
|
545 |
return true;
|
|
546 |
}
|
|
547 |
}
|
|
548 |
return false;
|
|
549 |
}
|
|
550 |
|
d34256
|
551 |
/// <summary>
|
Z |
552 |
/// 操作类型转换为其相应的前台展示文本
|
|
553 |
/// </summary>
|
|
554 |
/// <param name="nOp">操作类型</param>
|
|
555 |
/// <param name="OpShowTxt">前台展示文本</param>
|
|
556 |
/// <returns></returns>
|
418cb3
|
557 |
int CMTerm1Doc::OpToShowTxt(int nOp, CStringA & OpShowTxt)
|
Q |
558 |
{
|
|
559 |
for (int i = 0; i < nOpDefCount; i++) {
|
|
560 |
if (OpDef[i].nOpType1 == nOp) {
|
|
561 |
OpShowTxt = OpDef[i].ShowTxt;
|
|
562 |
return true;
|
|
563 |
}
|
|
564 |
}
|
|
565 |
return false;
|
|
566 |
}
|
|
567 |
|
d34256
|
568 |
/// <summary>
|
Z |
569 |
/// 文本转线圈类型
|
|
570 |
/// </summary>
|
|
571 |
/// <param name="Typetxt">线圈类型</param>
|
|
572 |
/// <param name="nCoilType">线圈类型</param>
|
|
573 |
/// <param name="nCoilAddr">线圈地址</param>
|
|
574 |
/// <returns></returns>
|
418cb3
|
575 |
int CMTerm1Doc::TxtToCoilType(CStringA Typetxt, int* nCoilType, int* nCoilAddr)
|
Q |
576 |
{
|
|
577 |
Typetxt.MakeUpper();
|
|
578 |
for (int i = 0; i < nCoilTypeDefCount; i++)
|
|
579 |
{
|
|
580 |
if (Typetxt.Find( CoilTypeNameDef[i].TypeTxt)==0) {
|
|
581 |
*nCoilType = CoilTypeNameDef[i].nType;
|
|
582 |
*nCoilAddr = atoi(Typetxt.Mid(CoilTypeNameDef[i].TypeTxt.GetLength()));
|
df0321
|
583 |
return true;
|
418cb3
|
584 |
return CoilTypeNameDef[i].nType;
|
Q |
585 |
}
|
|
586 |
}
|
|
587 |
return false;;
|
|
588 |
}
|
|
589 |
|
d34256
|
590 |
/// <summary>
|
Z |
591 |
/// 线圈类型转文本
|
|
592 |
/// </summary>
|
|
593 |
/// <param name="nType">线圈类型</param>
|
|
594 |
/// <param name="typeTxt">线圈文本</param>
|
|
595 |
/// <returns></returns>
|
418cb3
|
596 |
int CMTerm1Doc::CoilTypeToTxt(int nType, CStringA & typeTxt)
|
Q |
597 |
{
|
|
598 |
for (int i = 0; i < nCoilTypeDefCount; i++)
|
|
599 |
{
|
|
600 |
if (CoilTypeNameDef[i].nType == nType){
|
|
601 |
typeTxt = CoilTypeNameDef[i].TypeTxt;
|
|
602 |
return true;
|
|
603 |
}
|
|
604 |
}
|
|
605 |
return false;
|
|
606 |
}
|
|
607 |
|
d34256
|
608 |
/// <summary>
|
Z |
609 |
///
|
|
610 |
/// </summary>
|
|
611 |
/// <param name="Typetxt"></param>
|
|
612 |
/// <param name="nDataType"></param>
|
|
613 |
/// <param name="nDataAddr"></param>
|
|
614 |
/// <returns></returns>
|
418cb3
|
615 |
int CMTerm1Doc::TxtToDataType(CStringA Typetxt, int * nDataType, int* nDataAddr)
|
Q |
616 |
{
|
|
617 |
Typetxt.MakeUpper();
|
|
618 |
for (int i = 0; i < nDataTypeDefCount; i++)
|
|
619 |
{
|
|
620 |
if (Typetxt.Find(DataTypeNameDef[i].TypeTxt) == 0) {
|
|
621 |
*nDataType = DataTypeNameDef[i].nType;
|
|
622 |
*nDataAddr = atoi(Typetxt.Mid(DataTypeNameDef[i].TypeTxt.GetLength()));
|
|
623 |
return true;
|
|
624 |
}
|
|
625 |
}
|
df0321
|
626 |
*nDataType = KLDataTypeDEC;
|
Q |
627 |
*nDataAddr = atoi(Typetxt);
|
418cb3
|
628 |
return false;
|
Q |
629 |
}
|
|
630 |
|
|
631 |
|
d34256
|
632 |
/// <summary>
|
Z |
633 |
///
|
|
634 |
/// </summary>
|
|
635 |
/// <param name="nType"></param>
|
|
636 |
/// <param name="typeTxt"></param>
|
|
637 |
/// <returns></returns>
|
418cb3
|
638 |
int CMTerm1Doc::DataTypeToTxt(int nType, CStringA & typeTxt)
|
Q |
639 |
{
|
|
640 |
for (int i = 0; i < nDataTypeDefCount; i++)
|
|
641 |
{
|
|
642 |
if (DataTypeNameDef[i].nType == nType) {
|
|
643 |
typeTxt = DataTypeNameDef[i].TypeTxt;
|
|
644 |
return true;
|
|
645 |
}
|
|
646 |
}
|
|
647 |
return false;
|
|
648 |
}
|
|
649 |
|
d34256
|
650 |
/// <summary>
|
Z |
651 |
/// 获取与特定类型和地址相对应的线圈注释
|
|
652 |
/// </summary>
|
|
653 |
/// <param name="nType"></param>
|
|
654 |
/// <param name="nAddr"></param>
|
|
655 |
/// <param name="sAnno"></param>
|
|
656 |
/// <returns></returns>
|
418cb3
|
657 |
int CMTerm1Doc::GetAnno(unsigned short nType, unsigned short nAddr, CString & sAnno)
|
Q |
658 |
{
|
|
659 |
// TODO: 在此处添加实现代码.
|
|
660 |
// 二分法 查找。
|
|
661 |
// map.
|
|
662 |
for (int i = 0; i < nCoilAnnoCount; i++) {
|
|
663 |
if (mCoilAnnos[i].nType == nType && mCoilAnnos[i].nAddr == nAddr) {
|
|
664 |
sAnno = mCoilAnnos[i].sAnno;
|
|
665 |
return 1;
|
|
666 |
}
|
|
667 |
}
|
|
668 |
return 0;
|
|
669 |
}
|
|
670 |
|
d34256
|
671 |
/// <summary>
|
Z |
672 |
/// 设置或更新特定线圈的注释
|
|
673 |
/// </summary>
|
|
674 |
/// <param name="sCoilName"></param>
|
|
675 |
/// <param name="sAnno"></param>
|
|
676 |
/// <returns></returns>
|
418cb3
|
677 |
int CMTerm1Doc::SetAnno(CString sCoilName, CString sAnno)
|
Q |
678 |
{
|
|
679 |
// TODO: 在此处添加实现代码.
|
|
680 |
// 二分法 查找。
|
|
681 |
// map.
|
|
682 |
int bValid = 0;
|
|
683 |
int nType = 0, nAddr = 0;
|
|
684 |
CStringA s1A;
|
|
685 |
s1A = sCoilName;
|
|
686 |
if (TxtToCoilType(s1A, &nType, &nAddr) || TxtToDataType(s1A, &nType, &nAddr)) {
|
|
687 |
bValid = 1;
|
|
688 |
}
|
|
689 |
if (!bValid) return false;
|
|
690 |
|
|
691 |
for (int i = 0; i < nCoilAnnoCount; i++) {
|
|
692 |
if (mCoilAnnos[i].nType == nType && mCoilAnnos[i].nAddr == nAddr) {
|
|
693 |
mCoilAnnos[i].sAnno = sAnno;
|
|
694 |
return 1;
|
|
695 |
}
|
|
696 |
}
|
|
697 |
mCoilAnnos[nCoilAnnoCount].nType = nType;
|
|
698 |
mCoilAnnos[nCoilAnnoCount].nAddr = nAddr;
|
|
699 |
mCoilAnnos[nCoilAnnoCount].sCoilName = sCoilName;
|
|
700 |
mCoilAnnos[nCoilAnnoCount].sAnno = sAnno;
|
|
701 |
nCoilAnnoCount++;
|
|
702 |
return 2;
|
|
703 |
}
|
|
704 |
|
d34256
|
705 |
/// <summary>
|
Z |
706 |
/// 直接使用类型和地址参数来设置或更新特定线圈的注释
|
|
707 |
/// </summary>
|
|
708 |
/// <param name="nType">类型</param>
|
|
709 |
/// <param name="nAddr">地址</param>
|
|
710 |
/// <param name="sCoilName">线圈名称</param>
|
|
711 |
/// <param name="sAnno">线圈注释</param>
|
|
712 |
/// <returns></returns>
|
418cb3
|
713 |
int CMTerm1Doc::SetAnno(unsigned short nType, unsigned short nAddr, CString sCoilName, CString sAnno)
|
Q |
714 |
{
|
|
715 |
// TODO: 在此处添加实现代码.
|
|
716 |
// 二分法? 查找。
|
|
717 |
// map.
|
|
718 |
for (int i = 0; i < nCoilAnnoCount; i++) {
|
|
719 |
if (mCoilAnnos[i].nType == nType && mCoilAnnos[i].nAddr == nAddr) {
|
|
720 |
mCoilAnnos[i].sAnno = sAnno;
|
|
721 |
return 1;
|
|
722 |
}
|
|
723 |
}
|
|
724 |
mCoilAnnos[nCoilAnnoCount].nType = nType;
|
|
725 |
mCoilAnnos[nCoilAnnoCount].nAddr = nAddr;
|
|
726 |
mCoilAnnos[nCoilAnnoCount].sCoilName = sCoilName;
|
|
727 |
mCoilAnnos[nCoilAnnoCount].sAnno = sAnno;
|
|
728 |
nCoilAnnoCount++;
|
|
729 |
return 0;
|
|
730 |
}
|
d34256
|
731 |
|
Z |
732 |
/// <summary>
|
|
733 |
/// 转换文本行为Prog格式
|
|
734 |
/// </summary>
|
|
735 |
/// <param name="txtLines">文本行集合</param>
|
|
736 |
/// <param name="StartLine">开始行</param>
|
|
737 |
/// <param name="ProgLines">程序行</param>
|
|
738 |
/// <returns></returns>
|
418cb3
|
739 |
int CMTerm1Doc::TransLinesToProg(const CStringArray & txtLines, int StartLine , int ProgLines)
|
Q |
740 |
{
|
|
741 |
CString s1;
|
|
742 |
int txtLineCount = (int)txtLines.GetSize();
|
|
743 |
|
|
744 |
//读取程序 章节
|
|
745 |
int nProgStartLine = 0;
|
|
746 |
int nProgLines = 0;
|
|
747 |
|
|
748 |
nProgStartLine = StartLine;
|
|
749 |
if (ProgLines == -1) nProgLines = txtLineCount;
|
|
750 |
else nProgLines = ProgLines;
|
|
751 |
int nProgPos = 0;
|
|
752 |
|
d34256
|
753 |
//逐行读取并转化
|
418cb3
|
754 |
for (int i = nProgStartLine; i < nProgStartLine + nProgLines; i++)
|
Q |
755 |
{
|
|
756 |
CString sLine;
|
|
757 |
sLine = txtLines.GetAt(i);
|
d34256
|
758 |
//清除空格和制表符
|
418cb3
|
759 |
sLine.Trim();
|
Q |
760 |
sLine.Replace(_T("\t"), _T(" "));
|
|
761 |
sLine.Replace(_T(" "), _T(" "));
|
|
762 |
sLine.Replace(_T(" "), _T(" "));
|
d34256
|
763 |
|
Z |
764 |
//使用空格分隔字符串,并将其存储在 strarr2 数组中
|
418cb3
|
765 |
CStringArray strarr2;
|
Q |
766 |
DivideStringToArray(sLine, _T(" "), strarr2);
|
d34256
|
767 |
|
Z |
768 |
if (strarr2.GetSize() == 0)
|
|
769 |
{
|
|
770 |
continue;
|
|
771 |
}
|
|
772 |
|
|
773 |
//从数组中提取指令,并将其转换为大写形式
|
418cb3
|
774 |
CString sCmd;
|
Q |
775 |
sCmd = strarr2.GetAt(0);
|
|
776 |
sCmd.MakeUpper();
|
d34256
|
777 |
|
Z |
778 |
//使用 TxtToOp 函数将指令文本转换为操作类型。
|
418cb3
|
779 |
CStringA s1A;
|
Q |
780 |
s1A = sCmd;
|
|
781 |
int nParamCount, nParamType;
|
|
782 |
int nType, nAddr;
|
|
783 |
int k = TxtToOp(s1A, &nParamCount, &nParamType);
|
d34256
|
784 |
|
418cb3
|
785 |
if (k >= 0)
|
Q |
786 |
{
|
d34256
|
787 |
//根据参数类型,使用 TxtToCoilType 或 TxtToDataType 函数将参数文本转换为参数类型和地址
|
418cb3
|
788 |
Progs[nProgPos].nOpType1 = k;
|
Q |
789 |
for (int j = 0; j < 3 && j < nParamCount && j < strarr2.GetSize() - 1; j++)
|
|
790 |
{
|
|
791 |
s1A = strarr2.GetAt(j + 1);
|
|
792 |
s1A.MakeUpper();
|
|
793 |
Progs[nProgPos].Params[j].sParamStr = s1A;
|
|
794 |
if (nParamType == KLParamCoil) {
|
|
795 |
TxtToCoilType(s1A, &nType, &nAddr);
|
|
796 |
Progs[nProgPos].Params[j].nParamType = nType;
|
|
797 |
Progs[nProgPos].Params[j].nParamAddr = nAddr;
|
|
798 |
}
|
|
799 |
else if (nParamType == KLParamWord) {
|
|
800 |
TxtToDataType(s1A, &nType, &nAddr);
|
|
801 |
Progs[nProgPos].Params[j].nParamType = nType;
|
|
802 |
Progs[nProgPos].Params[j].nParamAddr = nAddr;
|
|
803 |
}
|
d34256
|
804 |
else {
|
418cb3
|
805 |
|
Q |
806 |
}
|
|
807 |
}
|
|
808 |
Progs[nProgPos].nParamCount = (int)strarr2.GetSize() - 1;
|
|
809 |
Progs[nProgPos].PairTo = 0;
|
|
810 |
nProgPos++;
|
|
811 |
}
|
|
812 |
}
|
d34256
|
813 |
|
Z |
814 |
|
418cb3
|
815 |
m_nProgSteps = nProgPos;
|
Q |
816 |
// 先扫描分开的程序段
|
|
817 |
int stpos[100] = { 0 };
|
|
818 |
int nSts = 0;
|
|
819 |
int StackDeeps[512] = { 0 };
|
|
820 |
int nCurStackDeep = 0;
|
|
821 |
// 查找匹配指令和地址
|
|
822 |
s1.Format(_T("DOC::Trans to Prog "));
|
|
823 |
SysLog(s1);
|
d34256
|
824 |
|
Z |
825 |
//匹配指令(错误,此处匹配指令使用数字
|
|
826 |
for (int i = 0; i < m_nProgSteps; i++)
|
|
827 |
{
|
418cb3
|
828 |
int nOpType = Progs[i].nOpType1;
|
Q |
829 |
int nParamCount = Progs[i].nParamCount;
|
|
830 |
switch (Progs[i].nOpType1)
|
|
831 |
{
|
|
832 |
case OP_ST:
|
|
833 |
case OP_ST_:
|
|
834 |
case OP_ST_EQ:
|
|
835 |
case OP_ST_NE:
|
|
836 |
case OP_ST_LT:
|
|
837 |
case OP_ST_GT:
|
|
838 |
case OP_ST_LE:
|
|
839 |
case OP_ST_GE:
|
|
840 |
|
|
841 |
nCurStackDeep++;
|
|
842 |
s1.Format(_T("St Deep %d pos %d "), nCurStackDeep, i);
|
|
843 |
//SysLog(s1);
|
|
844 |
stpos[nSts] = i;
|
|
845 |
nSts++;
|
|
846 |
break;
|
|
847 |
case OP_ANS:
|
|
848 |
case OP_ORS:
|
|
849 |
Progs[stpos[nSts - 1]].PairTo = i; // CMTerm1Doc::OP_ANS;
|
|
850 |
s1.Format(_T("Pair deep %d %d -- %d"), nCurStackDeep, stpos[nSts - 1], i);
|
|
851 |
//SysLog(s1);
|
|
852 |
nCurStackDeep--;
|
|
853 |
nSts--;
|
|
854 |
break;
|
|
855 |
case OP_PSHS:
|
|
856 |
break;
|
|
857 |
case OP_POPS:
|
|
858 |
break;
|
|
859 |
break;
|
|
860 |
default:
|
|
861 |
break;
|
|
862 |
}
|
|
863 |
StackDeeps[i] = nCurStackDeep;
|
|
864 |
}
|
d34256
|
865 |
|
418cb3
|
866 |
s1.Format(_T("Remaining STs %d"), nSts);
|
Q |
867 |
SysLog(s1);
|
d34256
|
868 |
|
418cb3
|
869 |
for (int i = 0; i < nSts; i++) {
|
Q |
870 |
s1.Format(_T("[%d] %d "), i, stpos[i]);
|
|
871 |
SysLog(s1);
|
|
872 |
}
|
|
873 |
s1.Format(_T("Pairs"));
|
|
874 |
SysLog(s1);
|
|
875 |
for (int i = 0; i < m_nProgSteps; i++) {
|
|
876 |
int nPairTo = Progs[i].PairTo;
|
|
877 |
if (nPairTo > 0) {
|
|
878 |
s1.Format(_T("%d -- %d type:%d"), i, nPairTo, Progs[nPairTo].nOpType1);
|
|
879 |
SysLog(s1);
|
|
880 |
}
|
|
881 |
}
|
|
882 |
TransProgToBin();
|
|
883 |
return 0;
|
|
884 |
}
|
|
885 |
|
|
886 |
int CMTerm1Doc::TransTxtToProg(CStringA ProgTxtA)
|
|
887 |
{
|
|
888 |
CString s1;
|
|
889 |
CString sProg;
|
|
890 |
sProg = ProgTxtA;
|
|
891 |
CStringArray txtLines;
|
|
892 |
sProg.Replace(_T("\r\n"), _T("\n"));
|
|
893 |
sProg.Replace(_T("\r"), _T("\n"));
|
|
894 |
|
|
895 |
DivideStringToArray(sProg, _T("\n"), txtLines);
|
|
896 |
|
|
897 |
TransLinesToProg(txtLines);
|
|
898 |
|
|
899 |
return 0;
|
|
900 |
}
|
|
901 |
|
|
902 |
int CMTerm1Doc::ReadAnnoFromTxt(CStringA AnnoTxtA)
|
|
903 |
{
|
|
904 |
// 读取注释章节
|
|
905 |
CString s1;
|
|
906 |
CString sProg;
|
|
907 |
sProg = AnnoTxtA;
|
|
908 |
CStringArray txtLines;
|
|
909 |
sProg.Replace(_T("\r\n"), _T("\n"));
|
|
910 |
sProg.Replace(_T("\r"), _T("\n"));
|
|
911 |
|
|
912 |
DivideStringToArray(sProg, _T("\n"), txtLines);
|
|
913 |
|
|
914 |
|
|
915 |
int txtLineCount = (int)txtLines.GetSize();
|
|
916 |
|
|
917 |
nCoilAnnoCount = 0;
|
|
918 |
int nAnnoSectionLine = 0;
|
|
919 |
int nAnnoStartLine = 0;
|
|
920 |
int nAnnoLines = 0;
|
|
921 |
|
|
922 |
int bAnnoSection = GetSectionPos(SectionAnno, &nAnnoSectionLine, &nAnnoLines);
|
|
923 |
if (bAnnoSection) { nAnnoStartLine = nAnnoSectionLine + 1; }
|
|
924 |
|
|
925 |
for (int i = nAnnoStartLine; i < nAnnoStartLine + nAnnoLines; i++)
|
|
926 |
{
|
|
927 |
CString sLine;
|
|
928 |
sLine = txtLines.GetAt(i);
|
|
929 |
sLine.Trim();
|
|
930 |
int DivPos = sLine.Find(_T("\t"));
|
|
931 |
if (DivPos < 1) continue;
|
|
932 |
|
|
933 |
CString sCoilName;
|
|
934 |
sCoilName = sLine.Left(DivPos);
|
|
935 |
sCoilName.MakeUpper();
|
|
936 |
CString sAnno;
|
|
937 |
sAnno = sLine.Mid(DivPos + 1);
|
|
938 |
|
|
939 |
// SetAnno(sCoilName, sAnno);
|
|
940 |
|
|
941 |
CStringA s1A;
|
|
942 |
s1A = sCoilName;
|
|
943 |
int nParamType, nAddr;
|
|
944 |
TxtToCoilType(s1A, &nParamType, &nAddr) || TxtToDataType(s1A, &nParamType, &nAddr);
|
|
945 |
|
|
946 |
mCoilAnnos[nCoilAnnoCount].nType = nParamType;
|
|
947 |
mCoilAnnos[nCoilAnnoCount].nAddr = nAddr;
|
|
948 |
mCoilAnnos[nCoilAnnoCount].sCoilName = sCoilName;
|
|
949 |
mCoilAnnos[nCoilAnnoCount].sAnno = sAnno;
|
|
950 |
|
|
951 |
nCoilAnnoCount++;
|
|
952 |
}
|
|
953 |
return 0;
|
|
954 |
}
|
|
955 |
|
d34256
|
956 |
/// <summary>
|
Z |
957 |
/// 解析文件为梯形图
|
|
958 |
/// </summary>
|
|
959 |
/// <param name="ProgTxtA">文本</param>
|
|
960 |
/// <returns></returns>
|
418cb3
|
961 |
int CMTerm1Doc::TransFileToProg(CStringA ProgTxtA)
|
Q |
962 |
{
|
|
963 |
CString s1;
|
|
964 |
CString sProg;
|
|
965 |
sProg = ProgTxtA;
|
|
966 |
CStringArray txtLines;
|
|
967 |
sProg.Replace(_T("\r\n"), _T("\n"));
|
|
968 |
sProg.Replace(_T("\r"), _T("\n"));
|
|
969 |
|
d34256
|
970 |
//分割文本字符串
|
418cb3
|
971 |
DivideStringToArray(sProg, _T("\n"), txtLines);
|
Q |
972 |
|
|
973 |
nSectionCount = 0;
|
|
974 |
int nCurSection = 0;
|
|
975 |
int txtLineCount = (int)txtLines.GetSize();
|
|
976 |
for (int i = 0; i < txtLineCount; i++)
|
|
977 |
{
|
|
978 |
CString sLine;
|
|
979 |
sLine = txtLines.GetAt(i);
|
|
980 |
sLine.Trim();
|
|
981 |
int nRightBracket;
|
|
982 |
if (sLine.Find(_T("[")) == 0 && (nRightBracket = sLine.Find(_T("]"))) > 1)
|
|
983 |
{ //找到 [ ] 标志
|
d34256
|
984 |
if (nSectionCount > 0)
|
Z |
985 |
{
|
418cb3
|
986 |
Sections[nSectionCount - 1].nLines = i - Sections[nSectionCount - 1].nSectionLineNo - 1;
|
Q |
987 |
s1.Format(_T("- Line %d Section %d Ends, %d Lines"), i, nSectionCount -1 ,Sections[nSectionCount - 1].nLines);
|
|
988 |
SysLog(s1);
|
|
989 |
}
|
|
990 |
CString sSectionName;
|
|
991 |
CStringA sSectionNameA;
|
|
992 |
sSectionName = sLine.Mid(1, nRightBracket - 1);
|
|
993 |
sSectionNameA = sSectionName;
|
|
994 |
int theSection = TxtToSection(sSectionNameA);
|
d34256
|
995 |
|
418cb3
|
996 |
s1.Format(_T("+ Line %d Section %d : [%s] type:%d "), i + 1, nSectionCount, sSectionName, theSection);
|
Q |
997 |
SysLog(s1);
|
|
998 |
Sections[nSectionCount].nSectionType = theSection;
|
|
999 |
Sections[nSectionCount].nSectionLineNo = i;
|
|
1000 |
nSectionCount++;
|
|
1001 |
}
|
|
1002 |
}
|
|
1003 |
if (nSectionCount > 0) {
|
|
1004 |
Sections[nSectionCount - 1].nLines = txtLineCount - Sections[nSectionCount - 1].nSectionLineNo - 1;
|
|
1005 |
s1.Format(_T("Section Ends at Line %d Lines %d "), txtLineCount, Sections[nSectionCount - 1].nLines);
|
|
1006 |
SysLog(s1);
|
|
1007 |
}
|
|
1008 |
|
|
1009 |
//读取程序 章节
|
|
1010 |
int nProgSectionLine = 0;
|
|
1011 |
int nProgStartLine = 0;
|
|
1012 |
int nProgLines = 0;
|
|
1013 |
|
|
1014 |
int bProgSection = GetSectionPos(SectionProg, &nProgSectionLine, &nProgLines);
|
|
1015 |
if (bProgSection) { nProgStartLine = nProgSectionLine + 1; }
|
|
1016 |
else { nProgStartLine = 0; nProgLines = txtLineCount; }
|
|
1017 |
|
|
1018 |
TransLinesToProg(txtLines,nProgStartLine,nProgLines);
|
|
1019 |
|
|
1020 |
// 读取注释章节
|
|
1021 |
nCoilAnnoCount = 0;
|
|
1022 |
int nAnnoSectionLine = 0;
|
|
1023 |
int nAnnoStartLine = 0;
|
|
1024 |
int nAnnoLines = 0;
|
|
1025 |
|
|
1026 |
int bAnnoSection = GetSectionPos(SectionAnno, &nAnnoSectionLine, &nAnnoLines);
|
d34256
|
1027 |
if (bAnnoSection)
|
Z |
1028 |
{
|
|
1029 |
nAnnoStartLine = nAnnoSectionLine + 1;
|
|
1030 |
}
|
418cb3
|
1031 |
|
Q |
1032 |
for (int i = nAnnoStartLine; i < nAnnoStartLine + nAnnoLines; i++)
|
|
1033 |
{
|
|
1034 |
CString sLine;
|
|
1035 |
sLine = txtLines.GetAt(i);
|
|
1036 |
sLine.Trim();
|
|
1037 |
int DivPos = sLine.Find(_T("\t"));
|
|
1038 |
if (DivPos < 1) continue;
|
|
1039 |
|
|
1040 |
CString sCoilName;
|
|
1041 |
sCoilName = sLine.Left(DivPos);
|
|
1042 |
sCoilName.MakeUpper();
|
|
1043 |
CString sAnno;
|
|
1044 |
sAnno = sLine.Mid(DivPos + 1);
|
|
1045 |
|
|
1046 |
// SetAnno(sCoilName, sAnno);
|
|
1047 |
|
|
1048 |
CStringA s1A;
|
|
1049 |
s1A = sCoilName;
|
|
1050 |
int nParamType,nAddr;
|
df0321
|
1051 |
TxtToCoilType(s1A, &nParamType,&nAddr)
|
Q |
1052 |
||TxtToDataType(s1A, &nParamType, &nAddr);
|
418cb3
|
1053 |
|
Q |
1054 |
mCoilAnnos[nCoilAnnoCount].nType = nParamType;
|
|
1055 |
mCoilAnnos[nCoilAnnoCount].nAddr = nAddr;
|
|
1056 |
mCoilAnnos[nCoilAnnoCount].sCoilName = sCoilName;
|
|
1057 |
mCoilAnnos[nCoilAnnoCount].sAnno = sAnno;
|
|
1058 |
|
|
1059 |
nCoilAnnoCount++;
|
|
1060 |
}
|
|
1061 |
|
|
1062 |
return 0;
|
|
1063 |
}
|
d34256
|
1064 |
|
Z |
1065 |
//文本段在此处组装
|
418cb3
|
1066 |
int CMTerm1Doc::TransToTxt(CStringA &ProgTxt)
|
Q |
1067 |
{
|
|
1068 |
CStringA s1, s2;
|
|
1069 |
for (int i = 0; i < m_nProgSteps; i++)
|
|
1070 |
{
|
|
1071 |
OpToTxt(Progs[i].nOpType1,s1);
|
|
1072 |
if (Progs[i].nParamCount > 0) { s1.Append("\t" + Progs[i].Params[0].sParamStr); }
|
|
1073 |
if (Progs[i].nParamCount > 1) { s1.Append("\t" + Progs[i].Params[1].sParamStr); }
|
|
1074 |
if (Progs[i].nParamCount > 2) { s1.Append("\t" + Progs[i].Params[2].sParamStr); }
|
|
1075 |
s1.Append("\r\n");
|
|
1076 |
s2 += s1;
|
|
1077 |
}
|
|
1078 |
ProgTxt = s2;
|
|
1079 |
return 0;
|
|
1080 |
}
|
|
1081 |
|
|
1082 |
int CMTerm1Doc::TransProgToBin()
|
|
1083 |
{
|
|
1084 |
CString s1;
|
df0321
|
1085 |
stBinProg15* pBinProg15;
|
418cb3
|
1086 |
stBinProg2 * pBinProg2;
|
Q |
1087 |
stBinProg3 * pBinProg3;
|
|
1088 |
nBinProgSteps = 0;
|
|
1089 |
for (int i = 0; i < m_nProgSteps; i++)
|
|
1090 |
{
|
|
1091 |
int nOpType = Progs[i].nOpType1;
|
|
1092 |
Progs[i].nBinStep = nBinProgSteps;
|
|
1093 |
int nParamType1 = Progs[i].Params[0].nParamType;
|
|
1094 |
int nParamAddr1 = Progs[i].Params[0].nParamAddr;
|
|
1095 |
int nParamType2, nParamAddr2;
|
|
1096 |
int nParamType3, nParamAddr3;
|
|
1097 |
if (Progs[i].nParamCount > 1) {
|
|
1098 |
nParamType2 = Progs[i].Params[1].nParamType;
|
|
1099 |
nParamAddr2 = Progs[i].Params[1].nParamAddr;
|
|
1100 |
}
|
|
1101 |
if (Progs[i].nParamCount > 2) {
|
|
1102 |
nParamType3 = Progs[i].Params[2].nParamType;
|
|
1103 |
nParamAddr3 = Progs[i].Params[2].nParamAddr;
|
|
1104 |
}
|
|
1105 |
switch (nOpType)
|
|
1106 |
{
|
|
1107 |
case OP_NONE:
|
|
1108 |
break;
|
|
1109 |
//case OP_NOP:
|
|
1110 |
break;
|
|
1111 |
//无参数 指令
|
|
1112 |
case OP_NOT:
|
|
1113 |
case OP_ANS:
|
|
1114 |
case OP_ORS:
|
|
1115 |
case OP_PSHS:
|
|
1116 |
case OP_RDS:
|
|
1117 |
case OP_POPS:
|
|
1118 |
case OP_DF:
|
|
1119 |
case OP_DF_:
|
|
1120 |
BinProgs[nBinProgSteps].nOp = nOpType;
|
|
1121 |
nBinProgSteps += 1;
|
|
1122 |
break;
|
|
1123 |
// 1参数指令
|
|
1124 |
case OP_ST:
|
|
1125 |
case OP_ST_:
|
|
1126 |
case OP_AN:
|
|
1127 |
case OP_AN_:
|
|
1128 |
case OP_OR:
|
|
1129 |
case OP_OR_:
|
|
1130 |
BinProgs[nBinProgSteps].nOp = nOpType;
|
|
1131 |
BinProgs[nBinProgSteps].nParamType = nParamType1;
|
|
1132 |
BinProgs[nBinProgSteps].nParamAddr = nParamAddr1;
|
|
1133 |
nBinProgSteps += 1;
|
|
1134 |
break;
|
|
1135 |
// 1 参数 输出
|
|
1136 |
case OP_OUT:
|
|
1137 |
case OP_SET:
|
|
1138 |
case OP_RESET:
|
|
1139 |
BinProgs[nBinProgSteps].nOp = nOpType;
|
|
1140 |
BinProgs[nBinProgSteps].nParamType = nParamType1;
|
|
1141 |
BinProgs[nBinProgSteps].nParamAddr = nParamAddr1;
|
|
1142 |
nBinProgSteps += 1;
|
|
1143 |
break;
|
|
1144 |
|
|
1145 |
// 比较指令
|
|
1146 |
case OP_ST_EQ:
|
|
1147 |
case OP_ST_NE:
|
|
1148 |
case OP_ST_LT:
|
|
1149 |
case OP_ST_GT:
|
|
1150 |
case OP_ST_LE:
|
|
1151 |
case OP_ST_GE:
|
|
1152 |
case OP_AN_EQ:
|
|
1153 |
case OP_AN_NE:
|
|
1154 |
case OP_AN_LT:
|
|
1155 |
case OP_AN_GT:
|
|
1156 |
case OP_AN_LE:
|
|
1157 |
case OP_AN_GE:
|
|
1158 |
case OP_OR_EQ:
|
|
1159 |
case OP_OR_NE:
|
|
1160 |
case OP_OR_LT:
|
|
1161 |
case OP_OR_GT:
|
|
1162 |
case OP_OR_LE:
|
|
1163 |
case OP_OR_GE:
|
|
1164 |
pBinProg2 = (stBinProg2 *)(&BinProgs[nBinProgSteps]);
|
|
1165 |
BinProgs[nBinProgSteps].nOp = nOpType;
|
|
1166 |
BinProgs[nBinProgSteps].nParamType = 0;
|
|
1167 |
BinProgs[nBinProgSteps].nParamAddr = nParamAddr1;
|
|
1168 |
BinProgs[nBinProgSteps+1].nOp = nParamType1;
|
|
1169 |
BinProgs[nBinProgSteps+1].nParamType = nParamType2;
|
|
1170 |
BinProgs[nBinProgSteps+1].nParamAddr = nParamAddr2;
|
|
1171 |
nBinProgSteps += 2;
|
|
1172 |
break;
|
|
1173 |
|
|
1174 |
// 定时器
|
|
1175 |
case OP_TML:
|
|
1176 |
case OP_TMR:
|
|
1177 |
case OP_TMX:
|
|
1178 |
case OP_TMY:
|
|
1179 |
pBinProg15 = (stBinProg15 *)(&BinProgs[nBinProgSteps]);
|
df0321
|
1180 |
|
418cb3
|
1181 |
BinProgs[nBinProgSteps].nOp = nOpType;
|
Q |
1182 |
BinProgs[nBinProgSteps].nParamType = nParamAddr1;
|
|
1183 |
BinProgs[nBinProgSteps].nParamAddr = nParamAddr2;
|
|
1184 |
BinProgs[nBinProgSteps + 1].nOp = nParamType2;
|
|
1185 |
BinProgs[nBinProgSteps + 1].nParamType = 0;
|
|
1186 |
BinProgs[nBinProgSteps + 1].nParamAddr = 0;
|
df0321
|
1187 |
pBinProg15->nOpNum = Progs[i].Params[0].nParamAddr;
|
Q |
1188 |
|
418cb3
|
1189 |
nBinProgSteps += 2;
|
Q |
1190 |
break;
|
|
1191 |
// 1 参数高级指令
|
|
1192 |
case OP_INC:
|
|
1193 |
case OP_DEC:
|
|
1194 |
pBinProg15 = (stBinProg15 *)(&BinProgs[nBinProgSteps]);
|
|
1195 |
pBinProg15->nOp = nOpType;
|
|
1196 |
pBinProg15->nOpNum = 0;
|
|
1197 |
pBinProg15->nParamType1 = nParamType1;
|
|
1198 |
pBinProg15->nParamAddr1 = nParamAddr1;
|
|
1199 |
pBinProg15->resvr1 = 0;
|
|
1200 |
pBinProg15->resvr2 = 0;
|
|
1201 |
nBinProgSteps += 2;
|
|
1202 |
break;
|
|
1203 |
// 2参数高级指令
|
|
1204 |
case OP_MV:
|
|
1205 |
case OP_ADD2:
|
|
1206 |
case OP_SUB2:
|
|
1207 |
pBinProg2 = (stBinProg2 *)(&BinProgs[nBinProgSteps]);
|
|
1208 |
pBinProg2->nOp = nOpType;
|
|
1209 |
pBinProg2->nOpNum = 0;
|
|
1210 |
pBinProg2->nParamType1 = nParamType1;
|
|
1211 |
pBinProg2->nParamAddr1 = nParamAddr1;
|
|
1212 |
pBinProg2->nParamType2 = nParamType2;
|
|
1213 |
pBinProg2->nParamAddr2 = nParamAddr2;
|
|
1214 |
nBinProgSteps += 2;
|
|
1215 |
|
|
1216 |
break;
|
|
1217 |
// 3 参数高级指令
|
|
1218 |
case OP_ADD3:
|
|
1219 |
case OP_SUB3:
|
|
1220 |
case OP_MUL:
|
|
1221 |
case OP_DIV:
|
|
1222 |
pBinProg3 = (stBinProg3 *)(&BinProgs[nBinProgSteps]);
|
|
1223 |
pBinProg3->nOp = nOpType;
|
|
1224 |
pBinProg3->nOpNum = 0;
|
|
1225 |
pBinProg3->nParamType1 = nParamType1;
|
|
1226 |
pBinProg3->nParamAddr1 = nParamAddr1;
|
|
1227 |
pBinProg3->nParamType2 = nParamType2;
|
|
1228 |
pBinProg3->nParamAddr2 = nParamAddr2;
|
|
1229 |
pBinProg3->nParamType3 = nParamType3;
|
|
1230 |
pBinProg3->nParamAddr3 = nParamAddr3;
|
|
1231 |
nBinProgSteps += 3;
|
|
1232 |
break;
|
|
1233 |
default:
|
|
1234 |
break;
|
|
1235 |
}
|
|
1236 |
}
|
|
1237 |
s1.Format(_T("%d steps to %d binSteps "), m_nProgSteps, nBinProgSteps);
|
|
1238 |
DbgLog(s1);
|
|
1239 |
|
|
1240 |
return 0;
|
|
1241 |
}
|
|
1242 |
|
|
1243 |
int CMTerm1Doc::TransBinToProg()
|
|
1244 |
{
|
df0321
|
1245 |
CString s1;
|
Q |
1246 |
//nBinProgSteps = 0;
|
|
1247 |
m_nProgSteps = 0;
|
|
1248 |
stBinProg2* pBinProg2;
|
|
1249 |
stBinProg15* pBinProg15;
|
|
1250 |
stBinProg3* pBinProg3;
|
|
1251 |
CStringA s1A;
|
|
1252 |
CString s2,s3;
|
|
1253 |
CStringA s2A, s3A;
|
|
1254 |
for (int i = 0; i < nBinProgSteps; i++)
|
|
1255 |
{
|
|
1256 |
int nOpType = BinProgs[i].nOp;
|
|
1257 |
int nParamType1 = BinProgs[i].nParamType;
|
|
1258 |
int nParamAddr1 = BinProgs[i].nParamAddr;
|
|
1259 |
// int nParamType1 = Progs[i].Params[0].nParamType;
|
|
1260 |
// int nParamAddr1 = Progs[i].Params[0].nParamAddr;
|
|
1261 |
int nParamType2, nParamAddr2;
|
|
1262 |
int nParamType3, nParamAddr3;
|
|
1263 |
CoilTypeToTxt(nParamType1, s1A);
|
|
1264 |
s1.Format(_T("%S%d"), s1A, nParamAddr1);
|
|
1265 |
Progs[m_nProgSteps].Params[0].nParamType = nParamType1;
|
|
1266 |
Progs[m_nProgSteps].Params[0].nParamAddr = nParamAddr1;
|
|
1267 |
Progs[m_nProgSteps].Params[0].sParamStr = s1;
|
418cb3
|
1268 |
|
df0321
|
1269 |
switch (nOpType)
|
Q |
1270 |
{
|
|
1271 |
case OP_NONE:
|
|
1272 |
break;
|
|
1273 |
//case OP_NOP:
|
|
1274 |
break;
|
|
1275 |
//无参数 指令
|
|
1276 |
case OP_NOT:
|
|
1277 |
case OP_ANS:
|
|
1278 |
case OP_ORS:
|
|
1279 |
case OP_PSHS:
|
|
1280 |
case OP_RDS:
|
|
1281 |
case OP_POPS:
|
|
1282 |
case OP_DF:
|
|
1283 |
case OP_DF_:
|
|
1284 |
Progs[m_nProgSteps].nOpType1 = nOpType;
|
|
1285 |
Progs[m_nProgSteps].nParamCount = 0;
|
|
1286 |
Progs[m_nProgSteps].Params[0].nParamType = nParamType1;
|
|
1287 |
Progs[m_nProgSteps].Params[0].nParamAddr = nParamAddr1;
|
|
1288 |
|
|
1289 |
//BinProgs[nBinProgSteps].nOp = nOpType;
|
|
1290 |
m_nProgSteps += 1;
|
|
1291 |
//nBinProgSteps += 1;
|
|
1292 |
break;
|
|
1293 |
// 1参数指令
|
|
1294 |
case OP_ST:
|
|
1295 |
case OP_ST_:
|
|
1296 |
case OP_AN:
|
|
1297 |
case OP_AN_:
|
|
1298 |
case OP_OR:
|
|
1299 |
case OP_OR_:
|
|
1300 |
Progs[m_nProgSteps].nOpType1 = nOpType;
|
|
1301 |
Progs[m_nProgSteps].nParamCount = 1;
|
|
1302 |
Progs[m_nProgSteps].Params[0].nParamType = nParamType1;
|
|
1303 |
Progs[m_nProgSteps].Params[0].nParamAddr = nParamAddr1;
|
|
1304 |
m_nProgSteps += 1;
|
|
1305 |
//i += 1;
|
|
1306 |
break;
|
|
1307 |
// 1 参数 输出
|
|
1308 |
case OP_OUT:
|
|
1309 |
case OP_SET:
|
|
1310 |
case OP_RESET:
|
|
1311 |
Progs[m_nProgSteps].nOpType1 = nOpType;
|
|
1312 |
Progs[m_nProgSteps].nParamCount = 1;
|
|
1313 |
Progs[m_nProgSteps].Params[0].nParamType = nParamType1;
|
|
1314 |
Progs[m_nProgSteps].Params[0].nParamAddr = nParamAddr1;
|
|
1315 |
m_nProgSteps += 1;
|
|
1316 |
//i += 1;
|
|
1317 |
break;
|
|
1318 |
|
|
1319 |
// 比较指令
|
|
1320 |
case OP_ST_EQ:
|
|
1321 |
case OP_ST_NE:
|
|
1322 |
case OP_ST_LT:
|
|
1323 |
case OP_ST_GT:
|
|
1324 |
case OP_ST_LE:
|
|
1325 |
case OP_ST_GE:
|
|
1326 |
case OP_AN_EQ:
|
|
1327 |
case OP_AN_NE:
|
|
1328 |
case OP_AN_LT:
|
|
1329 |
case OP_AN_GT:
|
|
1330 |
case OP_AN_LE:
|
|
1331 |
case OP_AN_GE:
|
|
1332 |
case OP_OR_EQ:
|
|
1333 |
case OP_OR_NE:
|
|
1334 |
case OP_OR_LT:
|
|
1335 |
case OP_OR_GT:
|
|
1336 |
case OP_OR_LE:
|
|
1337 |
case OP_OR_GE:
|
|
1338 |
pBinProg2 = (stBinProg2*)(&BinProgs[i]);
|
|
1339 |
|
|
1340 |
nParamType1 = pBinProg2->nParamType1;
|
|
1341 |
nParamAddr1 = pBinProg2->nParamAddr1;
|
|
1342 |
nParamType2 = pBinProg2->nParamType2;
|
|
1343 |
nParamAddr2 = pBinProg2->nParamAddr2;
|
|
1344 |
|
|
1345 |
DataTypeToTxt(nParamType1, s1A);
|
|
1346 |
s1.Format(_T("%S%d"), s1A, nParamAddr1);
|
|
1347 |
|
|
1348 |
DataTypeToTxt(nParamType2, s2A);
|
|
1349 |
s2.Format(_T("%S%d"), s2A, nParamAddr2);
|
|
1350 |
|
|
1351 |
Progs[m_nProgSteps].nOpType1 = nOpType;
|
|
1352 |
Progs[m_nProgSteps].nParamCount = 2;
|
|
1353 |
Progs[m_nProgSteps].Params[0].nParamType = nParamType1;
|
|
1354 |
Progs[m_nProgSteps].Params[0].nParamAddr = nParamAddr1;
|
|
1355 |
Progs[m_nProgSteps].Params[0].sParamStr = s1;
|
|
1356 |
|
|
1357 |
Progs[m_nProgSteps].Params[1].nParamType = nParamType2;
|
|
1358 |
Progs[m_nProgSteps].Params[1].nParamAddr = nParamAddr2;
|
|
1359 |
Progs[m_nProgSteps].Params[1].sParamStr = s2;
|
|
1360 |
|
|
1361 |
m_nProgSteps += 1;
|
|
1362 |
i += 1;
|
|
1363 |
break;
|
|
1364 |
|
|
1365 |
// 定时器
|
|
1366 |
case OP_TML:
|
|
1367 |
case OP_TMR:
|
|
1368 |
case OP_TMX:
|
|
1369 |
case OP_TMY:
|
|
1370 |
//pBinProg2 = (stBinProg2*)(&BinProgs[i]);
|
|
1371 |
|
|
1372 |
pBinProg15 = (stBinProg15*)(&BinProgs[i]);
|
|
1373 |
|
|
1374 |
nParamType1 = 0;
|
|
1375 |
nParamAddr1 = pBinProg15->nOpNum;
|
|
1376 |
nParamType2 = pBinProg15->nParamType1;
|
|
1377 |
nParamAddr2 = pBinProg15->nParamAddr1;
|
|
1378 |
//nParamAddr2 = pBinProg15->nParamAddr2;
|
|
1379 |
DataTypeToTxt(nParamType1, s1A);
|
|
1380 |
s1.Format(_T("%d"), nParamAddr1);
|
|
1381 |
|
|
1382 |
DataTypeToTxt(nParamType2, s2A);
|
|
1383 |
s2.Format(_T("%S%d"), s2A, nParamAddr2);
|
|
1384 |
|
|
1385 |
Progs[m_nProgSteps].nOpType1 = nOpType;
|
|
1386 |
Progs[m_nProgSteps].nParamCount = 2;
|
|
1387 |
Progs[m_nProgSteps].Params[0].nParamType = nParamType1;
|
|
1388 |
Progs[m_nProgSteps].Params[0].nParamAddr = nParamAddr1;
|
|
1389 |
Progs[m_nProgSteps].Params[0].sParamStr = s1;
|
|
1390 |
|
|
1391 |
Progs[m_nProgSteps].Params[1].nParamType = nParamType2;
|
|
1392 |
Progs[m_nProgSteps].Params[1].nParamAddr = nParamAddr2;
|
|
1393 |
Progs[m_nProgSteps].Params[1].sParamStr = s2;
|
|
1394 |
m_nProgSteps += 1;
|
|
1395 |
i += 1;
|
|
1396 |
|
|
1397 |
break;
|
|
1398 |
// 1 参数高级指令
|
|
1399 |
case OP_INC:
|
|
1400 |
case OP_DEC:
|
|
1401 |
pBinProg15 = (stBinProg15*)(&BinProgs[i]);
|
|
1402 |
nParamType1 = pBinProg15->nParamType1;
|
|
1403 |
nParamAddr1 = pBinProg15->nParamAddr1;
|
|
1404 |
|
|
1405 |
DataTypeToTxt(nParamType1, s1A);
|
|
1406 |
s1.Format(_T("%S%d"), s1A, nParamAddr1);
|
|
1407 |
|
|
1408 |
Progs[m_nProgSteps].nOpType1 = nOpType;
|
|
1409 |
Progs[m_nProgSteps].nParamCount = 1;
|
|
1410 |
Progs[m_nProgSteps].Params[0].nParamType = nParamType1;
|
|
1411 |
Progs[m_nProgSteps].Params[0].nParamAddr = nParamAddr1;
|
|
1412 |
Progs[m_nProgSteps].Params[0].sParamStr = s1;
|
|
1413 |
|
|
1414 |
m_nProgSteps += 1;
|
|
1415 |
i += 1;
|
|
1416 |
break;
|
|
1417 |
// 2参数高级指令
|
|
1418 |
case OP_MV:
|
|
1419 |
case OP_ADD2:
|
|
1420 |
case OP_SUB2:
|
|
1421 |
pBinProg2 = (stBinProg2*)(&BinProgs[i]);
|
|
1422 |
|
|
1423 |
nParamType1 = pBinProg2->nParamType1;
|
|
1424 |
nParamAddr1 = pBinProg2->nParamAddr1;
|
|
1425 |
nParamType2 = pBinProg2->nParamType2;
|
|
1426 |
nParamAddr2 = pBinProg2->nParamAddr2;
|
|
1427 |
|
|
1428 |
DataTypeToTxt(nParamType1, s1A);
|
|
1429 |
s1.Format(_T("%S%d"), s1A, nParamAddr1);
|
|
1430 |
|
|
1431 |
DataTypeToTxt(nParamType2, s2A);
|
|
1432 |
s2.Format(_T("%S%d"), s2A, nParamAddr2);
|
|
1433 |
|
|
1434 |
Progs[m_nProgSteps].nOpType1 = nOpType;
|
|
1435 |
Progs[m_nProgSteps].nParamCount = 2;
|
|
1436 |
Progs[m_nProgSteps].Params[0].nParamType = nParamType1;
|
|
1437 |
Progs[m_nProgSteps].Params[0].nParamAddr = nParamAddr1;
|
|
1438 |
Progs[m_nProgSteps].Params[0].sParamStr = s1;
|
|
1439 |
|
|
1440 |
Progs[m_nProgSteps].Params[1].nParamType = nParamType2;
|
|
1441 |
Progs[m_nProgSteps].Params[1].nParamAddr = nParamAddr2;
|
|
1442 |
Progs[m_nProgSteps].Params[1].sParamStr = s2;
|
|
1443 |
|
|
1444 |
m_nProgSteps += 1;
|
|
1445 |
i += 1;
|
|
1446 |
|
|
1447 |
break;
|
|
1448 |
// 3 参数高级指令
|
|
1449 |
case OP_ADD3:
|
|
1450 |
case OP_SUB3:
|
|
1451 |
case OP_MUL:
|
|
1452 |
case OP_DIV:
|
|
1453 |
pBinProg3 = (stBinProg3*)(&BinProgs[i]);
|
|
1454 |
nParamType1 = pBinProg3->nParamType1;
|
|
1455 |
nParamAddr1 = pBinProg3->nParamAddr1;
|
|
1456 |
nParamType2 = pBinProg3->nParamType2;
|
|
1457 |
nParamAddr2 = pBinProg3->nParamAddr2;
|
|
1458 |
nParamType3 = pBinProg3->nParamType3;
|
|
1459 |
nParamAddr3 = pBinProg3->nParamAddr3;
|
|
1460 |
|
|
1461 |
DataTypeToTxt(nParamType1, s1A);
|
|
1462 |
s1.Format(_T("%S%d"), s1A, nParamAddr1);
|
|
1463 |
|
|
1464 |
DataTypeToTxt(nParamType2, s2A);
|
|
1465 |
s2.Format(_T("%S%d"), s2A, nParamAddr2);
|
|
1466 |
DataTypeToTxt(nParamType3, s3A);
|
|
1467 |
s3.Format(_T("%S%d"), s3A, nParamAddr3);
|
|
1468 |
|
|
1469 |
Progs[m_nProgSteps].nOpType1 = nOpType;
|
|
1470 |
Progs[m_nProgSteps].nParamCount = 3;
|
|
1471 |
Progs[m_nProgSteps].Params[0].nParamType = nParamType1;
|
|
1472 |
Progs[m_nProgSteps].Params[0].nParamAddr = nParamAddr1;
|
|
1473 |
Progs[m_nProgSteps].Params[0].sParamStr = s1;
|
|
1474 |
Progs[m_nProgSteps].Params[1].nParamType = nParamType2;
|
|
1475 |
Progs[m_nProgSteps].Params[1].nParamAddr = nParamAddr2;
|
|
1476 |
Progs[m_nProgSteps].Params[1].sParamStr = s2;
|
|
1477 |
Progs[m_nProgSteps].Params[2].nParamType = nParamType3;
|
|
1478 |
Progs[m_nProgSteps].Params[2].nParamAddr = nParamAddr3;
|
|
1479 |
Progs[m_nProgSteps].Params[2].sParamStr = s3;
|
|
1480 |
m_nProgSteps += 1;
|
|
1481 |
i += 2;
|
|
1482 |
break;
|
|
1483 |
default:
|
|
1484 |
break;
|
|
1485 |
}
|
|
1486 |
|
|
1487 |
}
|
|
1488 |
s1.Format(_T("%d binsteps to %d Steps "), nBinProgSteps, m_nProgSteps );
|
|
1489 |
DbgLog(s1);
|
418cb3
|
1490 |
return 0;
|
Q |
1491 |
}
|
|
1492 |
|
|
1493 |
void CMTerm1Doc::OnUploadFromPlc()
|
|
1494 |
{
|
|
1495 |
// TODO: 在此添加命令处理程序代码
|
|
1496 |
int r;
|
|
1497 |
CString s1;
|
|
1498 |
if (!m_bOnline) {
|
|
1499 |
r = Connect();
|
df0321
|
1500 |
// MyKLink1.Open();
|
418cb3
|
1501 |
}
|
Q |
1502 |
if (!m_bOnline) return;
|
|
1503 |
r = MyKLink1.ReadRunStat(1,0,0,32,(unsigned short *)&MyKLink1.KMRunStat);
|
|
1504 |
|
df0321
|
1505 |
if (r != 0) {
|
Q |
1506 |
AfxMessageBox(_T("UploadFrom PLC Failed"));
|
|
1507 |
return;
|
|
1508 |
}
|
418cb3
|
1509 |
// AfxMessageBox(_T("UploadFrom PLC From Doc"));
|
Q |
1510 |
CString s2;
|
|
1511 |
s2.Format(_T("Cur Programs %d \r\n"), nBinProgSteps);
|
|
1512 |
unsigned short * pBinBuf2 = (unsigned short *)BinProgs;
|
|
1513 |
for (int i = 0; i < nBinProgSteps * 2; i += 8) {
|
|
1514 |
s1.Format(_T("%03X: "), i);
|
|
1515 |
for (int j = 0; j < 8 && i+j < nBinProgSteps * 2; j++) {
|
|
1516 |
s1.AppendFormat(_T("%04X "), pBinBuf2[i + j]);
|
|
1517 |
}
|
|
1518 |
s2 += s1 + _T("\r\n");
|
|
1519 |
}
|
|
1520 |
DbgLog(s2);
|
|
1521 |
|
|
1522 |
int nBinSteps = MyKLink1.KMRunStat.nBinProgSize;
|
|
1523 |
s1.Format(_T("program to upload Size %d "), nBinSteps);
|
|
1524 |
DbgLog(s1);
|
|
1525 |
|
|
1526 |
USHORT Buf3[2048];
|
|
1527 |
s2.Empty();
|
|
1528 |
int nUploadSize = nBinSteps *2;
|
|
1529 |
int nSteps = 64;
|
|
1530 |
for (int i = 0; i < nUploadSize; i += nSteps) {
|
|
1531 |
if (i + nSteps > nUploadSize) { nSteps = nUploadSize - i; }
|
|
1532 |
s1.Format(_T("2 Uploading %d to %d "), i, i + nSteps);
|
|
1533 |
DbgLog(s1);
|
|
1534 |
int r = MyKLink1.ReadProgram(1, 2, i, nSteps*2 , Buf3+i);
|
|
1535 |
s1.Format(_T("Download r = %d "), r);
|
|
1536 |
DbgLog(s1);
|
|
1537 |
//Update Progress Bar
|
|
1538 |
}
|
|
1539 |
s2.Format(_T(" Uploaded from bank 2 \r\n"));
|
|
1540 |
for (int i = 0; i < nBinSteps * 2; i += 8) {
|
|
1541 |
s1.Format(_T("%03X: "), i);
|
|
1542 |
for (int j = 0; j < 8 && i + j < nBinSteps * 2; j++) {
|
|
1543 |
s1.AppendFormat(_T("%04X "), Buf3[i + j]);
|
|
1544 |
}
|
|
1545 |
s2 += s1 + _T("\r\n");
|
|
1546 |
}
|
|
1547 |
DbgLog(s2);
|
|
1548 |
|
|
1549 |
for (int i = 0; i < nBinSteps * 2; i++)
|
|
1550 |
{
|
|
1551 |
((USHORT *)BinProgs)[i] = Buf3[i];
|
|
1552 |
}
|
|
1553 |
nBinProgSteps = nBinSteps;
|
|
1554 |
TransBinToProg();
|
|
1555 |
UpdateAllViews(NULL);
|
|
1556 |
}
|
|
1557 |
|
|
1558 |
int CMTerm1Doc::DownloadToPLC()
|
|
1559 |
{
|
|
1560 |
// TODO: 在此处添加实现代码.
|
|
1561 |
int r;
|
|
1562 |
CString s1;
|
|
1563 |
if (!m_bOnline) {
|
|
1564 |
r=Connect();
|
df0321
|
1565 |
// MyKLink1.Open();
|
418cb3
|
1566 |
}
|
Q |
1567 |
if (!m_bOnline) return 0;
|
|
1568 |
|
|
1569 |
if (m_bPlcRunning) {
|
df0321
|
1570 |
r = AfxMessageBox(_T("PLC运行中,是否停止以便下载程序?"), MB_YESNO);
|
418cb3
|
1571 |
if (r == IDYES) { StopPLC();}
|
Q |
1572 |
else { return 0; }
|
|
1573 |
}
|
|
1574 |
|
|
1575 |
// 下载程序
|
|
1576 |
s1.Format(_T("Start Download Program ..."));
|
|
1577 |
DbgLog(s1);
|
|
1578 |
r = MyKLink1.StartProgram(1,2);
|
|
1579 |
s1.Format(_T("Result = %d"),r);
|
|
1580 |
DbgLog(s1);
|
|
1581 |
int DownloadSize = nBinProgSteps;
|
|
1582 |
|
|
1583 |
int Steps = 16;
|
|
1584 |
for (int i = 0; i < DownloadSize; i += Steps) {
|
|
1585 |
//int Steps = 16;
|
|
1586 |
if (i + Steps > DownloadSize) { Steps = DownloadSize - i; }
|
df0321
|
1587 |
int n = 0;
|
Q |
1588 |
do {
|
|
1589 |
s1.Format(_T("Downloading %d to %d "), i, i + Steps);
|
|
1590 |
DbgLog(s1);
|
|
1591 |
r = MyKLink1.WriteProgram(1, 2, (i) * 4, Steps * 4, (USHORT*)&BinProgs[i]);
|
|
1592 |
s1.Format(_T("Download r = %d "), r);
|
|
1593 |
DbgLog(s1);
|
|
1594 |
n += 1;
|
|
1595 |
if (n > 10) break;
|
|
1596 |
} while (r != 0);
|
418cb3
|
1597 |
//Update Progress Bar
|
Q |
1598 |
}
|
|
1599 |
|
|
1600 |
s1.Format(_T("Finish Downloading "));
|
|
1601 |
DbgLog(s1);
|
|
1602 |
r = MyKLink1.FinishProgram(1,2,nBinProgSteps);
|
|
1603 |
s1.Format(_T("Download Finished r = %d "), r);
|
|
1604 |
DbgLog(s1);
|
|
1605 |
// 下载注释
|
|
1606 |
|
|
1607 |
|
|
1608 |
// 下载系统寄存器配置
|
|
1609 |
|
df0321
|
1610 |
//启动运行
|
Q |
1611 |
r = AfxMessageBox(_T("程序下载完成,是否启动运行?"), MB_YESNO);
|
|
1612 |
if (r == IDYES) { StartPLC(); }
|
|
1613 |
else { return 0; }
|
418cb3
|
1614 |
|
Q |
1615 |
return 0;
|
|
1616 |
}
|
|
1617 |
|
|
1618 |
void CMTerm1Doc::OnDownloadToPlc()
|
|
1619 |
{
|
|
1620 |
// TODO: 在此添加命令处理程序代码
|
|
1621 |
DownloadToPLC();
|
|
1622 |
}
|
|
1623 |
|
|
1624 |
void CMTerm1Doc::OnUpdateDownloadToPlc(CCmdUI *pCmdUI)
|
|
1625 |
{
|
|
1626 |
// TODO: 在此添加命令更新用户界面处理程序代码
|
|
1627 |
}
|
|
1628 |
|
|
1629 |
void CMTerm1Doc::OnOnline()
|
|
1630 |
{
|
|
1631 |
// TODO: 在此添加命令处理程序代码
|
|
1632 |
int r;
|
|
1633 |
if (!m_bOnline)
|
|
1634 |
{
|
|
1635 |
r = Connect();
|
df0321
|
1636 |
//MyKLink1.Open();
|
418cb3
|
1637 |
}
|
Q |
1638 |
if (!m_bOnline) return;
|
|
1639 |
// m_bOnline = true;
|
|
1640 |
UpdateAllViews(NULL, UpdataHint::UpdateStat);
|
|
1641 |
}
|
|
1642 |
|
|
1643 |
void CMTerm1Doc::OnUpdateOnline(CCmdUI *pCmdUI)
|
|
1644 |
{
|
|
1645 |
// TODO: 在此添加命令更新用户界面处理程序代码
|
|
1646 |
pCmdUI->SetCheck(m_bOnline == true);
|
|
1647 |
}
|
|
1648 |
|
|
1649 |
void CMTerm1Doc::OnOffline()
|
|
1650 |
{
|
|
1651 |
// TODO: 在此添加命令处理程序代码
|
|
1652 |
int r;
|
|
1653 |
if (m_bOnline)
|
|
1654 |
{
|
|
1655 |
r = DisConnect();
|
|
1656 |
MyKLink1.Close();
|
|
1657 |
}
|
|
1658 |
m_bOnline = false;
|
|
1659 |
UpdateAllViews(NULL, UpdataHint::UpdateStat);
|
|
1660 |
}
|
|
1661 |
|
|
1662 |
void CMTerm1Doc::OnUpdateOffline(CCmdUI *pCmdUI)
|
|
1663 |
{
|
|
1664 |
// TODO: 在此添加命令更新用户界面处理程序代码
|
|
1665 |
pCmdUI->SetCheck(m_bOnline == false);
|
|
1666 |
}
|
|
1667 |
|
|
1668 |
void CMTerm1Doc::OnSimulate()
|
|
1669 |
{
|
|
1670 |
// TODO: 在此添加命令处理程序代码
|
df0321
|
1671 |
CString s1;
|
Q |
1672 |
unsigned short* p1 = (unsigned short *)&BinProgs;
|
418cb3
|
1673 |
if (!m_bSimulate) {
|
df0321
|
1674 |
|
Q |
1675 |
s1.Format(_T("启动PLC模拟\r\n"));
|
|
1676 |
SysLog(s1);
|
418cb3
|
1677 |
m_bSimulate = true;
|
df0321
|
1678 |
s1.Empty();
|
Q |
1679 |
for (int i = 0; i < nBinProgSteps; i++) {
|
|
1680 |
s1.AppendFormat(_T("%04X %04X "), p1[i*2],p1[i*2+1]);
|
|
1681 |
}
|
|
1682 |
SysLog(s1);
|
|
1683 |
s1.Format(_T("Download %d program to sim PLC"),nBinProgSteps);
|
|
1684 |
SysLog(s1);
|
|
1685 |
myKMachine1.Download(BinProgs, nBinProgSteps);
|
418cb3
|
1686 |
m_bOnline = true;
|
df0321
|
1687 |
myKMachine1.StartPLC();
|
Q |
1688 |
s1.Format(_T("Start sim PLC"));
|
|
1689 |
SysLog(s1);
|
418cb3
|
1690 |
StartPLC();
|
Q |
1691 |
}
|
|
1692 |
else {
|
df0321
|
1693 |
StopPLC();
|
418cb3
|
1694 |
m_bSimulate = false;
|
Q |
1695 |
m_bOnline = false;
|
df0321
|
1696 |
|
418cb3
|
1697 |
}
|
Q |
1698 |
UpdateAllViews(NULL, UpdataHint::UpdateStat);
|
|
1699 |
}
|
|
1700 |
|
|
1701 |
void CMTerm1Doc::OnUpdateSimulate(CCmdUI *pCmdUI)
|
|
1702 |
{
|
|
1703 |
// TODO: 在此添加命令更新用户界面处理程序代码
|
|
1704 |
pCmdUI->SetCheck(m_bSimulate == true);
|
|
1705 |
}
|
|
1706 |
|
|
1707 |
int CMTerm1Doc::StartPLC()
|
|
1708 |
{
|
|
1709 |
// TODO: 在此处添加实现代码.
|
df0321
|
1710 |
if (m_bSimulate) {
|
Q |
1711 |
for (int i = 0; i < KLDataWXCount; i++) {
|
|
1712 |
KMem.WX[i] = 0;
|
|
1713 |
}
|
|
1714 |
for (int i = 0; i < KLDataWYCount; i++) {
|
|
1715 |
KMem.WY[i] = 0;
|
|
1716 |
}
|
|
1717 |
for (int i = 0; i < KLDataWRCount; i++) {
|
|
1718 |
KMem.WR[i] = 0;
|
|
1719 |
}
|
|
1720 |
for (int i = 0; i < KLDataDTCount; i++) {
|
|
1721 |
KMem.DT[i] = 0;
|
|
1722 |
}
|
|
1723 |
for (int i = 0; i < TOTALTIMERS; i++) {
|
|
1724 |
KMem.Timers[i] = { 0 };
|
|
1725 |
}
|
|
1726 |
nScanCount = 0;
|
|
1727 |
m_bPlcRunning = 1;
|
|
1728 |
}else {
|
|
1729 |
MyKLink1.ChangeMode(1, 1);
|
|
1730 |
m_bPlcRunning = 1;
|
418cb3
|
1731 |
}
|
Q |
1732 |
return 0;
|
|
1733 |
}
|
|
1734 |
|
|
1735 |
|
|
1736 |
int CMTerm1Doc::StopPLC()
|
|
1737 |
{
|
|
1738 |
// TODO: 在此处添加实现代码.
|
df0321
|
1739 |
if (m_bSimulate) {
|
Q |
1740 |
m_bPlcRunning = false;
|
|
1741 |
}
|
|
1742 |
else {
|
|
1743 |
MyKLink1.ChangeMode(1, 0);
|
|
1744 |
m_bPlcRunning = false;
|
|
1745 |
}
|
418cb3
|
1746 |
|
Q |
1747 |
return 0;
|
|
1748 |
}
|
|
1749 |
|
|
1750 |
void CMTerm1Doc::OnPlcRun()
|
|
1751 |
{
|
|
1752 |
// TODO: 在此添加命令处理程序代码
|
|
1753 |
if (m_bPlcRunning) { StopPLC(); }
|
|
1754 |
else
|
|
1755 |
{
|
|
1756 |
StartPLC();
|
|
1757 |
}
|
|
1758 |
UpdateAllViews(NULL, UpdataHint::UpdateStat);
|
|
1759 |
}
|
|
1760 |
|
|
1761 |
void CMTerm1Doc::OnUpdatePlcRun(CCmdUI *pCmdUI)
|
|
1762 |
{
|
|
1763 |
// TODO: 在此添加命令更新用户界面处理程序代码
|
|
1764 |
pCmdUI->SetCheck(m_bPlcRunning == true);
|
|
1765 |
if (!m_bPlcRunning) pCmdUI->SetText(_T("PLC模式[PROG]"));
|
|
1766 |
else pCmdUI->SetText(_T("PLC模式[RUN]"));
|
|
1767 |
}
|
|
1768 |
|
|
1769 |
|
|
1770 |
int CMTerm1Doc::SetCommParam()
|
|
1771 |
{
|
|
1772 |
// TODO: 在此处添加实现代码.
|
|
1773 |
CString s1;
|
|
1774 |
s1.Format(_T("Doc SetupComm"));
|
|
1775 |
SysLog(s1);
|
|
1776 |
MyKLink1.SetCommParam();
|
|
1777 |
return 0;
|
|
1778 |
/*
|
|
1779 |
CDialogCommSet1 dialog1;
|
|
1780 |
INT_PTR r = dialog1.DoModal();
|
|
1781 |
if (r == IDOK )
|
|
1782 |
{
|
|
1783 |
nComPort=dialog1.m_nComNum;
|
|
1784 |
nBaud=dialog1.m_nBaudRate;
|
|
1785 |
ComSettings=dialog1.m_Settings;
|
|
1786 |
s1.Format(_T("dialog return port %d baud %d setting %S"),
|
|
1787 |
nComPort, nBaud, ComSettings);
|
|
1788 |
SysLog(s1);
|
|
1789 |
m_bCommParamSet = true;
|
|
1790 |
}
|
|
1791 |
else
|
|
1792 |
{
|
|
1793 |
return -1;
|
|
1794 |
}
|
|
1795 |
return 0;
|
|
1796 |
*/
|
|
1797 |
}
|
|
1798 |
|
|
1799 |
int CMTerm1Doc::Connect()
|
|
1800 |
{
|
|
1801 |
// TODO: 在此处添加实现代码.
|
|
1802 |
CString s1;
|
|
1803 |
unsigned short buf1[32];
|
|
1804 |
int res = MyKLink1.Connect();
|
|
1805 |
unsigned short len1;
|
|
1806 |
int j=MyKLink1.GetInfo(1, &len1, buf1);
|
df0321
|
1807 |
s1.Format(_T("GetInfo = %d %d \r\n"), j,len1);
|
Q |
1808 |
if (j==0 && len1 > 0) {
|
|
1809 |
for (int i = 0; i < len1/2; i++) {
|
|
1810 |
s1.AppendFormat(_T("%04X "), buf1[i]);
|
|
1811 |
}
|
|
1812 |
s1 += _T("\r\n");
|
|
1813 |
pKMInfoBlock pinfob = (pKMInfoBlock)buf1;
|
|
1814 |
|
|
1815 |
s1.AppendFormat(_T(" DeviceType %04X \r\n"),pinfob->nDeviceTypeVer);
|
|
1816 |
s1.AppendFormat(_T(" nProgVer %04X \r\n"), pinfob->nProgVer);
|
|
1817 |
s1.AppendFormat(_T(" nKLinkVer %04X \r\n"), pinfob->nKLinkVer);
|
|
1818 |
s1.AppendFormat(_T(" nKBusVer %04X \r\n"), pinfob->nKBusVer);
|
|
1819 |
s1.AppendFormat(_T(" nCapacity1 %d k\r\n"), pinfob->nCapacity1);
|
|
1820 |
s1.AppendFormat(_T(" nCapacity2 %d k\r\n"), pinfob->nCapacity2);
|
|
1821 |
s1.AppendFormat(_T(" nDInput %d \r\n"), pinfob->nDInput);
|
|
1822 |
s1.AppendFormat(_T(" nDOutput %d \r\n"), pinfob->nDOutput);
|
|
1823 |
s1.AppendFormat(_T(" nAInput %d \r\n"), pinfob->nAInput);
|
|
1824 |
s1.AppendFormat(_T(" nAOutput %d \r\n"), pinfob->nAOutput);
|
|
1825 |
s1.AppendFormat(_T(" nHInput %d \r\n"), pinfob->nHInput);
|
|
1826 |
s1.AppendFormat(_T(" nHOutput %d \r\n"), pinfob->nHOutput);
|
|
1827 |
s1.AppendFormat(_T(" nExt1 %d \r\n"), pinfob->nExt1);
|
|
1828 |
s1.AppendFormat(_T(" nExt2 %d \r\n"), pinfob->nExt2);
|
|
1829 |
s1.AppendFormat(_T(" nLogSize %d \r\n"), pinfob->nLogSize);
|
|
1830 |
s1.AppendFormat(_T(" nPorts %d \r\n"), pinfob->nPorts);
|
|
1831 |
s1.AppendFormat(_T(" nManSize %d \r\n"), pinfob->nManSize);
|
|
1832 |
s1.AppendFormat(_T(" nAbility %d \r\n"), pinfob->nAbility);
|
|
1833 |
s1.AppendFormat(_T(" nSwitchBits %d \r\n"), pinfob->nSwitchBits);
|
|
1834 |
|
|
1835 |
}
|
|
1836 |
SysLog(s1);
|
|
1837 |
int r = MyKLink1.ReadRunStat(1, 0, 0, 32, (unsigned short*)&MyKLink1.KMRunStat);
|
|
1838 |
s1.Format(_T("GetRunStat = %d %d \r\n"), r, 32);
|
|
1839 |
KLink1::stRunStat RunStat1 = MyKLink1.KMRunStat;
|
|
1840 |
|
|
1841 |
s1.AppendFormat(_T(" Sign1 %04X \r\n"), RunStat1.Sign1);
|
|
1842 |
s1.AppendFormat(_T(" Seq1 %d \r\n"), RunStat1.Seq1);
|
|
1843 |
s1.AppendFormat(_T(" PowerCount %d \r\n"), RunStat1.PowerCount);
|
|
1844 |
s1.AppendFormat(_T(" Reserved1 %d \r\n"), RunStat1.Reserved1);
|
|
1845 |
s1.AppendFormat(_T(" UpTime %d \r\n"), RunStat1.UpTime);
|
|
1846 |
s1.AppendFormat(_T(" UserData1 %d \r\n"), RunStat1.UserData1);
|
|
1847 |
s1.AppendFormat(_T(" WorkMode %d \r\n"), RunStat1.WorkMode);
|
|
1848 |
s1.AppendFormat(_T(" WorkMode2 %d \r\n"), RunStat1.WorkMode2);
|
|
1849 |
s1.AppendFormat(_T(" nBinProgBank %d \r\n"), RunStat1.nBinProgBank);
|
|
1850 |
s1.AppendFormat(_T(" nBinProgSize %d \r\n"), RunStat1.nBinProgSize);
|
|
1851 |
s1.AppendFormat(_T(" bLEDFlick %d \r\n"), RunStat1.bLEDFlick);
|
|
1852 |
s1.AppendFormat(_T(" Reserved2 %d \r\n"), RunStat1.Reserved2);
|
|
1853 |
s1.AppendFormat(_T(" CRC1 %04X \r\n"), RunStat1.CRC1);
|
|
1854 |
s1.AppendFormat(_T(" EndSign1 %04X \r\n"), RunStat1.EndSign1);
|
|
1855 |
|
|
1856 |
unsigned char value;
|
|
1857 |
r = MyKLink1.GetMode(1, 0, &value);
|
|
1858 |
if (r == KLink1::KL_OK) { m_bPlcRunning = value; }
|
|
1859 |
|
|
1860 |
|
418cb3
|
1861 |
SysLog(s1);
|
Q |
1862 |
// m_static_connect.SetCtlColor(RGB(0, 255, 0));
|
|
1863 |
/*
|
|
1864 |
if (!m_bCommParamSet)
|
|
1865 |
{
|
|
1866 |
if (SetCommParam()) return -1;
|
|
1867 |
}
|
|
1868 |
if (m_bOnline) return 0;
|
|
1869 |
|
|
1870 |
myHvSerialPort1.m_nPort = nComPort;
|
|
1871 |
myHvSerialPort1.m_nBaudRate = nBaud;
|
|
1872 |
myHvSerialPort1.m_Settings = "8,N,1";
|
|
1873 |
int r = myHvSerialPort1.Open();
|
|
1874 |
s1.Format(_T("Open %s = %d"), myHvSerialPort1.m_strResult, r);
|
|
1875 |
SysLog(s1);
|
|
1876 |
if (r == myHvSerialPort1.R_OK)
|
|
1877 |
{
|
|
1878 |
m_bOnline = true;
|
|
1879 |
// MyKLink1.Open();
|
|
1880 |
// m_static_connect.SetCtlColor(RGB(0, 255, 0));
|
|
1881 |
return 0;
|
|
1882 |
}
|
|
1883 |
*/
|
|
1884 |
m_bOnline = true;
|
|
1885 |
return 0;
|
|
1886 |
}
|
|
1887 |
|
|
1888 |
int CMTerm1Doc::DisConnect()
|
|
1889 |
{
|
|
1890 |
// TODO: 在此处添加实现代码.
|
|
1891 |
if (!m_bOnline) return -1;
|
|
1892 |
// myHvSerialPort1.Close();
|
|
1893 |
MyKLink1.Close();
|
|
1894 |
m_bOnline = false;
|
|
1895 |
return 0;
|
|
1896 |
}
|
|
1897 |
|
|
1898 |
void CMTerm1Doc::OnComunicationSet()
|
|
1899 |
{
|
|
1900 |
// TODO: 在此添加命令处理程序代码
|
|
1901 |
SetCommParam();
|
|
1902 |
|
|
1903 |
}
|
|
1904 |
|
|
1905 |
void CMTerm1Doc::OnPlcSysregSet()
|
|
1906 |
{
|
|
1907 |
// TODO: 在此添加命令处理程序代码
|
|
1908 |
CDialogSysRegSet dialog1;
|
|
1909 |
INT_PTR r = dialog1.DoModal();
|
|
1910 |
if (r == IDOK)
|
|
1911 |
{
|
|
1912 |
|
|
1913 |
}
|
|
1914 |
}
|
|
1915 |
|
|
1916 |
void CMTerm1Doc::OnMenuFactCfg()
|
|
1917 |
{
|
|
1918 |
// TODO: 在此添加命令处理程序代码
|
|
1919 |
CDialogFactCfg dialog1;
|
|
1920 |
INT_PTR r = dialog1.DoModal();
|
|
1921 |
if (r == IDOK)
|
|
1922 |
{
|
|
1923 |
|
|
1924 |
}
|
|
1925 |
}
|
|
1926 |
|
|
1927 |
|
|
1928 |
CView * CMTerm1Doc::FindView(CRuntimeClass * pClass)
|
|
1929 |
{
|
|
1930 |
CView* pView=NULL;
|
|
1931 |
POSITION pos = GetFirstViewPosition();
|
|
1932 |
while (pos != NULL)
|
|
1933 |
{
|
|
1934 |
pView = GetNextView(pos);
|
|
1935 |
if (pView->IsKindOf(pClass))
|
|
1936 |
break;
|
|
1937 |
}
|
|
1938 |
if (!pView->IsKindOf(pClass))
|
|
1939 |
{
|
|
1940 |
//AfxMessageBox("Connt Locate the View.");
|
|
1941 |
return NULL;
|
|
1942 |
}
|
|
1943 |
return pView;
|
|
1944 |
}
|
|
1945 |
///*
|
|
1946 |
void CMTerm1Doc::OnMenuViewLds()
|
|
1947 |
{
|
|
1948 |
// TODO: 在此添加命令处理程序代码
|
|
1949 |
CString s1;
|
|
1950 |
CView * pView;
|
|
1951 |
pView = FindView(RUNTIME_CLASS(CMTerm1View));
|
|
1952 |
if (pView != NULL) {
|
|
1953 |
((CMDIFrameWndEx *)AfxGetMainWnd())->MDIActivate(pView->GetParent());
|
|
1954 |
// pView->SetActiveWindow();
|
|
1955 |
}
|
|
1956 |
else {
|
|
1957 |
s1 = GetTitle();
|
|
1958 |
//AfxMessageBox(s1);
|
|
1959 |
ASSERT_VALID(theApp.pDocTemplate);
|
|
1960 |
CFrameWnd * pFrame = theApp.pDocTemplate->CreateNewFrame(this, NULL);
|
|
1961 |
ASSERT_KINDOF(CFrameWnd, pFrame);
|
|
1962 |
theApp.pDocTemplate->InitialUpdateFrame(pFrame, this);
|
|
1963 |
}
|
|
1964 |
}
|
|
1965 |
|
|
1966 |
|
|
1967 |
void CMTerm1Doc::OnMenuViewBld()
|
|
1968 |
{
|
|
1969 |
// TODO: 在此添加命令处理程序代码
|
|
1970 |
CString s1;
|
|
1971 |
CView * pView;
|
|
1972 |
pView = FindView(RUNTIME_CLASS(CMTerm1BldView));
|
|
1973 |
if (pView != NULL) {
|
|
1974 |
((CMDIFrameWndEx *)AfxGetMainWnd())->MDIActivate(pView->GetParent());
|
|
1975 |
// pView->SetActiveWindow();
|
|
1976 |
}
|
|
1977 |
else {
|
|
1978 |
s1 = GetTitle();
|
|
1979 |
//AfxMessageBox(s1);
|
|
1980 |
ASSERT_VALID(theApp.m_pBldViewTemplate);
|
|
1981 |
CFrameWnd * pFrame = theApp.m_pBldViewTemplate->CreateNewFrame(this, NULL);
|
|
1982 |
ASSERT_KINDOF(CFrameWnd, pFrame);
|
|
1983 |
theApp.m_pBldViewTemplate->InitialUpdateFrame(pFrame, this);
|
|
1984 |
}
|
|
1985 |
}
|
|
1986 |
|
|
1987 |
|
|
1988 |
void CMTerm1Doc::OnMenuViewBnl()
|
|
1989 |
{
|
|
1990 |
// TODO: 在此添加命令处理程序代码
|
|
1991 |
CString s1;
|
|
1992 |
CView * pView;
|
|
1993 |
pView = FindView(RUNTIME_CLASS(CMTerm1BnlView));
|
|
1994 |
if (pView != NULL) {
|
|
1995 |
((CMDIFrameWndEx *)AfxGetMainWnd())->MDIActivate(pView->GetParent());
|
|
1996 |
// pView->SetActiveWindow();
|
|
1997 |
}
|
|
1998 |
else {
|
|
1999 |
s1 = GetTitle();
|
|
2000 |
//AfxMessageBox(s1);
|
|
2001 |
ASSERT_VALID(theApp.m_pBnlViewTemplate);
|
|
2002 |
CFrameWnd * pFrame = theApp.m_pBnlViewTemplate->CreateNewFrame(this, NULL);
|
|
2003 |
ASSERT_KINDOF(CFrameWnd, pFrame);
|
|
2004 |
theApp.m_pBnlViewTemplate->InitialUpdateFrame(pFrame, this);
|
|
2005 |
}
|
|
2006 |
}
|
|
2007 |
//*/
|
d34256
|
2008 |
|
418cb3
|
2009 |
void CMTerm1Doc::OnMenuShowConsole()
|
Q |
2010 |
{
|
|
2011 |
// TODO: 在此添加命令处理程序代码
|
|
2012 |
CString s1;
|
|
2013 |
CView * pView;
|
|
2014 |
pView = FindView(RUNTIME_CLASS(CMTerm1CtrlView));
|
|
2015 |
if (pView != NULL) {
|
|
2016 |
((CMDIFrameWndEx *)AfxGetMainWnd())->MDIActivate(pView->GetParent());
|
|
2017 |
// pView->SetActiveWindow();
|
|
2018 |
}
|
|
2019 |
else {
|
|
2020 |
s1 = GetTitle();
|
|
2021 |
//AfxMessageBox(s1);
|
|
2022 |
ASSERT_VALID(theApp.m_pCtrlViewTemplate);
|
|
2023 |
CFrameWnd * pFrame = theApp.m_pCtrlViewTemplate->CreateNewFrame(this, NULL);
|
|
2024 |
ASSERT_KINDOF(CFrameWnd, pFrame);
|
d34256
|
2025 |
theApp.m_pCtrlViewTemplate->InitialUpdateFrame(pFrame, this);
|
418cb3
|
2026 |
}
|
Q |
2027 |
}
|
|
2028 |
|
|
2029 |
|
|
2030 |
void CMTerm1Doc::OnMenuCommTest()
|
|
2031 |
{
|
|
2032 |
// TODO: 在此添加命令处理程序代码
|
|
2033 |
CString s1;
|
|
2034 |
CView * pView;
|
|
2035 |
pView = FindView(RUNTIME_CLASS(CMTerm1CommDevView));
|
|
2036 |
if (pView != NULL) {
|
|
2037 |
((CMDIFrameWndEx *)AfxGetMainWnd())->MDIActivate(pView->GetParent());
|
|
2038 |
// pView->SetActiveWindow();
|
|
2039 |
}
|
|
2040 |
else {
|
|
2041 |
s1 = GetTitle();
|
|
2042 |
//AfxMessageBox(s1);
|
|
2043 |
ASSERT_VALID(theApp.m_pCommDevViewTemplate);
|
|
2044 |
CFrameWnd * pFrame = theApp.m_pCommDevViewTemplate->CreateNewFrame(this, NULL);
|
|
2045 |
ASSERT_KINDOF(CFrameWnd, pFrame);
|
|
2046 |
theApp.m_pCommDevViewTemplate->InitialUpdateFrame(pFrame, this);
|
|
2047 |
}
|
|
2048 |
|
|
2049 |
}
|
|
2050 |
|
|
2051 |
const unsigned short bitMasks[16] =
|
|
2052 |
{
|
|
2053 |
0x1 << 0, 0x1 << 1, 0x1 << 2, 0x1 << 3, 0x1 << 4, 0x1 << 5, 0x1 << 6, 0x1 << 7,
|
|
2054 |
0x1 << 8, 0x1 << 9, 0x1 << 10, 0x1 << 11, 0x1 << 12, 0x1 << 13, 0x1 << 14, 0x1 << 15,
|
|
2055 |
};
|
|
2056 |
|
|
2057 |
inline void SetAddrBit(unsigned short * pW, unsigned char bitAddr)
|
|
2058 |
{
|
|
2059 |
(*pW) |= bitMasks[bitAddr & 0xf];
|
|
2060 |
}
|
|
2061 |
|
|
2062 |
inline void ResetBit(unsigned short * pW, unsigned char bitAddr)
|
|
2063 |
{
|
|
2064 |
(*pW) &= ~bitMasks[bitAddr & 0xf];
|
|
2065 |
}
|
|
2066 |
|
|
2067 |
static inline void SetBitValue(unsigned short * pW, unsigned char bitAddr, unsigned char Value)
|
|
2068 |
{
|
|
2069 |
if (Value) { SetAddrBit(pW, bitAddr); }
|
|
2070 |
else { ResetBit(pW, bitAddr); }
|
|
2071 |
}
|
|
2072 |
|
|
2073 |
static inline unsigned char GetBitValue(unsigned short W, unsigned char bitAddr)
|
|
2074 |
{
|
|
2075 |
if (W&bitMasks[bitAddr & 0xf]) return 1;
|
|
2076 |
else return 0;
|
|
2077 |
}
|
|
2078 |
|
|
2079 |
int CMTerm1Doc::GetCoilValue(int nCoilType, int nCoilAddr)
|
|
2080 |
{
|
|
2081 |
// TODO: 在此处添加实现代码.
|
|
2082 |
|
|
2083 |
if (m_bOnline && 0)
|
|
2084 |
{
|
|
2085 |
unsigned char value = 0;
|
|
2086 |
MyKLink1.ReadBit(1, nCoilType, nCoilAddr, &value);
|
|
2087 |
return value;
|
|
2088 |
}
|
|
2089 |
int nWordAddr = nCoilAddr >> 4;
|
|
2090 |
int nBitAddr = nCoilAddr & 0x0F;
|
|
2091 |
|
|
2092 |
switch (nCoilType)
|
|
2093 |
{
|
|
2094 |
case KLCoilTypeX:
|
|
2095 |
if (nCoilAddr >= KLCoilXCount) return 0;
|
|
2096 |
return GetBitValue(KMem.WX[nWordAddr], nBitAddr);
|
|
2097 |
break;
|
|
2098 |
case KLCoilTypeY:
|
|
2099 |
if (nCoilAddr >= KLCoilYCount) return 0;
|
|
2100 |
return GetBitValue(KMem.WY[nWordAddr], nBitAddr);
|
|
2101 |
break;
|
|
2102 |
case KLCoilTypeR:
|
|
2103 |
if (nCoilAddr >= KLCoilRCount) return 0;
|
|
2104 |
return GetBitValue(KMem.WR[nWordAddr], nBitAddr);
|
|
2105 |
break;
|
|
2106 |
case KLCoilTypeLX:
|
|
2107 |
if (nCoilAddr >= KLCoilLXCount) return 0;
|
|
2108 |
return GetBitValue(KMem.WLX[nWordAddr], nBitAddr);
|
|
2109 |
break;
|
|
2110 |
case KLCoilTypeLY:
|
|
2111 |
if (nCoilAddr >= KLCoilLYCount) return 0;
|
|
2112 |
return GetBitValue(KMem.WLY[nWordAddr], nBitAddr);
|
|
2113 |
break;
|
|
2114 |
case KLCoilTypeT:
|
|
2115 |
if (nCoilAddr >= KLCoilTCount) return 0;
|
|
2116 |
return GetBitValue(KMem.WT[nWordAddr], nBitAddr);
|
|
2117 |
break;
|
|
2118 |
case KLCoilTypeC:
|
|
2119 |
if (nCoilAddr >= KLCoilCCount) return 0;
|
|
2120 |
return GetBitValue(KMem.WC[nWordAddr], nBitAddr);
|
|
2121 |
break;
|
|
2122 |
case KLCoilTypeLR:
|
|
2123 |
if (nCoilAddr >= KLCoilLRCount) return 0;
|
|
2124 |
return GetBitValue(KMem.WLR[nWordAddr], nBitAddr);
|
|
2125 |
break;
|
|
2126 |
case KLCoilTypeSR:
|
|
2127 |
if (nCoilAddr >= KLCoilSRCount) return 0;
|
|
2128 |
return GetBitValue(KMem.WSR[nWordAddr], nBitAddr);
|
|
2129 |
break;
|
|
2130 |
}
|
|
2131 |
return 0;
|
|
2132 |
}
|
|
2133 |
|
|
2134 |
|
|
2135 |
int CMTerm1Doc::SetCoilValue(int nCoilType, int nCoilAddr, int nCoilValue)
|
|
2136 |
{
|
|
2137 |
// TODO: 在此处添加实现代码.
|
|
2138 |
if (m_bSimulate) {
|
|
2139 |
return myKMachine1.SetCoilValue(nCoilType, nCoilAddr, nCoilValue);
|
|
2140 |
}else
|
|
2141 |
if (m_bOnline)
|
|
2142 |
{
|
|
2143 |
unsigned char value =nCoilValue;
|
|
2144 |
int res = 0;
|
|
2145 |
res = MyKLink1.WriteBit(1, nCoilType, nCoilAddr, value);
|
|
2146 |
return res;
|
|
2147 |
}
|
|
2148 |
|
|
2149 |
int nWordAddr = nCoilAddr >> 4;
|
|
2150 |
int nBitAddr = nCoilAddr & 0x0F;
|
|
2151 |
|
|
2152 |
switch (nCoilType)
|
|
2153 |
{
|
|
2154 |
case KLCoilTypeX:
|
|
2155 |
if (nCoilAddr >= KLCoilXCount) return 0;
|
|
2156 |
SetBitValue(&KMem.WX[nWordAddr], nBitAddr, nCoilValue);
|
|
2157 |
break;
|
|
2158 |
case KLCoilTypeY:
|
|
2159 |
if (nCoilAddr >= KLCoilYCount) return 0;
|
|
2160 |
SetBitValue(&KMem.WY[nWordAddr], nBitAddr, nCoilValue);
|
|
2161 |
break;
|
|
2162 |
case KLCoilTypeR:
|
|
2163 |
if (nCoilAddr >= KLCoilRCount) return 0;
|
|
2164 |
SetBitValue(&KMem.WR[nWordAddr], nBitAddr, nCoilValue);
|
|
2165 |
break;
|
|
2166 |
case KLCoilTypeLX:
|
|
2167 |
if (nCoilAddr >= KLCoilLXCount) return 0;
|
|
2168 |
SetBitValue(&KMem.WLX[nWordAddr], nBitAddr, nCoilValue);
|
|
2169 |
break;
|
|
2170 |
case KLCoilTypeLY:
|
|
2171 |
if (nCoilAddr >= KLCoilLYCount) return 0;
|
|
2172 |
SetBitValue(&KMem.WLY[nWordAddr], nBitAddr, nCoilValue);
|
|
2173 |
break;
|
|
2174 |
case KLCoilTypeT:
|
|
2175 |
if (nCoilAddr >= KLCoilTCount) return 0;
|
|
2176 |
SetBitValue(&KMem.WT[nWordAddr], nBitAddr, nCoilValue);
|
|
2177 |
break;
|
|
2178 |
case KLCoilTypeC:
|
|
2179 |
if (nCoilAddr >= KLCoilCCount) return 0;
|
|
2180 |
SetBitValue(&KMem.WC[nWordAddr], nBitAddr, nCoilValue);
|
|
2181 |
break;
|
|
2182 |
case KLCoilTypeLR:
|
|
2183 |
if (nCoilAddr >= KLCoilLRCount) return 0;
|
|
2184 |
SetBitValue(&KMem.WLR[nWordAddr], nBitAddr, nCoilValue);
|
|
2185 |
break;
|
|
2186 |
case KLCoilTypeSR:
|
|
2187 |
if (nCoilAddr >= KLCoilSRCount) return 0;
|
|
2188 |
SetBitValue(&KMem.WSR[nWordAddr], nBitAddr, nCoilValue);
|
|
2189 |
|
|
2190 |
break;
|
|
2191 |
}
|
|
2192 |
if (m_bOnline)
|
|
2193 |
{
|
|
2194 |
// MyKLink1.WriteBit(1, nCoilType, nCoilAddr, nCoilValue);
|
|
2195 |
}
|
|
2196 |
return 0;
|
|
2197 |
}
|
|
2198 |
|
|
2199 |
int CMTerm1Doc::GetVarData(int nDataType, int nDataAddr)
|
|
2200 |
{
|
|
2201 |
// TODO: 在此处添加实现代码.
|
|
2202 |
unsigned short nCount;
|
|
2203 |
if (m_bOnline && 0)
|
|
2204 |
{
|
|
2205 |
unsigned short value[20];
|
|
2206 |
unsigned short svalue = 0;
|
|
2207 |
if (nDataType == KLDataTypeDEC || nDataType == KLDataTypeHEX){
|
|
2208 |
return nDataAddr;
|
|
2209 |
}
|
|
2210 |
|
|
2211 |
MyKLink1.ReadDataWord(1, nDataType, nDataAddr, 2, &nCount, value);// (unsigned char *)&KMem.DT[nDataAddr]);
|
|
2212 |
svalue = value[0];
|
|
2213 |
return svalue;
|
|
2214 |
}
|
|
2215 |
|
|
2216 |
switch (nDataType)
|
|
2217 |
{
|
|
2218 |
case KLDataTypeDEC:
|
|
2219 |
case KLDataTypeHEX:
|
|
2220 |
return nDataAddr;
|
|
2221 |
break;
|
|
2222 |
case KLDataTypeWX:
|
|
2223 |
if (nDataAddr >= KLDataWXCount) return 0;
|
|
2224 |
return KMem.WX[nDataAddr];
|
|
2225 |
break;
|
|
2226 |
case KLDataTypeWY:
|
|
2227 |
if (nDataAddr >= KLDataWYCount) return 0;
|
|
2228 |
return KMem.WY[nDataAddr];
|
|
2229 |
break;
|
|
2230 |
case KLDataTypeWR:
|
|
2231 |
if (nDataAddr >= KLDataWRCount) return 0;
|
|
2232 |
return KMem.WR[nDataAddr];
|
|
2233 |
break;
|
|
2234 |
case KLDataTypeWLX:
|
|
2235 |
if (nDataAddr >= KLDataWLCount) return 0;
|
|
2236 |
return KMem.WLX[nDataAddr];
|
|
2237 |
break;
|
|
2238 |
case KLDataTypeWLY:
|
|
2239 |
if (nDataAddr >= KLDataWLCount) return 0;
|
|
2240 |
return KMem.WLY[nDataAddr];
|
|
2241 |
break;
|
|
2242 |
case KLDataTypeDT:
|
|
2243 |
if (nDataAddr >= KLDataDTCount) return 0;
|
|
2244 |
return (signed short)KMem.DT[nDataAddr];
|
|
2245 |
break;
|
|
2246 |
case KLDataTypeSDT:
|
|
2247 |
if (nDataAddr >= KLDataSDTCount) return 0;
|
|
2248 |
return KMem.SDT[nDataAddr];
|
|
2249 |
break;
|
|
2250 |
case KLDataTypeWSR:
|
|
2251 |
if (nDataAddr >= KLCoilLRCount) return 0;
|
|
2252 |
return KMem.WSR[nDataAddr];
|
|
2253 |
break;
|
|
2254 |
case KLDataTypeSV:
|
|
2255 |
if (nDataAddr >= KLDataSVCount) return 0;
|
|
2256 |
return KMem.SV[nDataAddr];
|
|
2257 |
break;
|
|
2258 |
case KLDataTypeEV:
|
|
2259 |
if (nDataAddr >= KLDataEVCount) return 0;
|
|
2260 |
return KMem.EV[nDataAddr];
|
|
2261 |
break;
|
|
2262 |
case KLDataTypeLD:
|
|
2263 |
if (nDataAddr >= KLDataLDCount) return 0;
|
|
2264 |
return KMem.DT[nDataAddr];
|
|
2265 |
break;
|
|
2266 |
case KLDataSysCfg:
|
|
2267 |
if (nDataAddr >= KLCoilSRCount) return 0;
|
|
2268 |
return KMem.SDT[nDataAddr];
|
|
2269 |
break;
|
|
2270 |
case KLDataTypeFlash:
|
|
2271 |
if (nDataAddr >= KLCoilSRCount) return 0;
|
|
2272 |
return KMem.SDT[nDataAddr];
|
|
2273 |
break;
|
|
2274 |
case KLDataTypeTest:
|
|
2275 |
if (nDataAddr >= KLCoilSRCount) return 0;
|
|
2276 |
return KMem.SDT[nDataAddr];
|
|
2277 |
break;
|
|
2278 |
}
|
|
2279 |
return 0;
|
|
2280 |
}
|
|
2281 |
|
|
2282 |
|
|
2283 |
int CMTerm1Doc::SetVarData(int nDataType, int nDataAddr, int nDataValue)
|
|
2284 |
{
|
|
2285 |
// TODO: 在此处添加实现代码.
|
|
2286 |
|
|
2287 |
if (m_bSimulate) {
|
|
2288 |
return myKMachine1.SetVarData(nDataType, nDataAddr, nDataValue);
|
|
2289 |
}else
|
|
2290 |
if (m_bOnline)
|
|
2291 |
{
|
|
2292 |
// unsigned char value[20];
|
|
2293 |
unsigned short svalue[10];
|
|
2294 |
svalue[0]=nDataValue;
|
|
2295 |
int res = 0;
|
|
2296 |
res = MyKLink1.WriteDataWord(1, nDataType, nDataAddr, 2, svalue);
|
|
2297 |
return res;
|
|
2298 |
}
|
|
2299 |
|
|
2300 |
switch (nDataType)
|
|
2301 |
{
|
|
2302 |
// case KLDataTypeDEC:
|
|
2303 |
// case KLDataTypeHEX:
|
|
2304 |
// break;
|
|
2305 |
case KLDataTypeWX:
|
|
2306 |
if (nDataAddr >= KLDataWXCount) return 0;
|
|
2307 |
KMem.WX[nDataAddr] = nDataValue;
|
|
2308 |
break;
|
|
2309 |
case KLDataTypeWY:
|
|
2310 |
if (nDataAddr >= KLDataWYCount) return 0;
|
|
2311 |
KMem.WY[nDataAddr] = nDataValue;
|
|
2312 |
break;
|
|
2313 |
case KLDataTypeWR:
|
|
2314 |
if (nDataAddr >= KLDataWRCount) return 0;
|
|
2315 |
KMem.WR[nDataAddr] = nDataValue;
|
|
2316 |
break;
|
|
2317 |
case KLDataTypeWLX:
|
|
2318 |
if (nDataAddr >= KLDataWLCount) return 0;
|
|
2319 |
KMem.WLX[nDataAddr] = nDataValue;
|
|
2320 |
break;
|
|
2321 |
case KLDataTypeWLY:
|
|
2322 |
if (nDataAddr >= KLDataWLCount) return 0;
|
|
2323 |
KMem.WLY[nDataAddr] = nDataValue;
|
|
2324 |
break;
|
|
2325 |
case KLDataTypeDT:
|
|
2326 |
if (nDataAddr >= KLDataDTCount) return 0;
|
|
2327 |
KMem.DT[nDataAddr] = nDataValue;
|
|
2328 |
break;
|
|
2329 |
case KLDataTypeSDT:
|
|
2330 |
if (nDataAddr >= KLDataSDTCount) return 0;
|
|
2331 |
KMem.SDT[nDataAddr] = nDataValue;
|
|
2332 |
break;
|
|
2333 |
case KLDataTypeWSR:
|
|
2334 |
if (nDataAddr >= KLCoilLRCount) return 0;
|
|
2335 |
KMem.WSR[nDataAddr] = nDataValue;
|
|
2336 |
break;
|
|
2337 |
case KLDataTypeSV:
|
|
2338 |
if (nDataAddr >= KLDataSVCount) return 0;
|
|
2339 |
KMem.SV[nDataAddr] = nDataValue;
|
|
2340 |
break;
|
|
2341 |
case KLDataTypeEV:
|
|
2342 |
if (nDataAddr >= KLDataEVCount) return 0;
|
|
2343 |
KMem.EV[nDataAddr] = nDataValue;
|
|
2344 |
break;
|
|
2345 |
case KLDataTypeLD:
|
|
2346 |
if (nDataAddr >= KLDataLDCount) return 0;
|
|
2347 |
KMem.DT[nDataAddr] = nDataValue;
|
|
2348 |
break;
|
|
2349 |
case KLDataSysCfg:
|
|
2350 |
if (nDataAddr >= KLCoilSRCount) return 0;
|
|
2351 |
KMem.SDT[nDataAddr] = nDataValue;
|
|
2352 |
break;
|
|
2353 |
case KLDataTypeFlash:
|
|
2354 |
if (nDataAddr >= KLCoilSRCount) return 0;
|
|
2355 |
KMem.SDT[nDataAddr] = nDataValue;
|
|
2356 |
break;
|
|
2357 |
case KLDataTypeTest:
|
|
2358 |
if (nDataAddr >= KLCoilSRCount) return 0;
|
|
2359 |
KMem.SDT[nDataAddr] = nDataValue;
|
|
2360 |
break;
|
|
2361 |
}
|
|
2362 |
|
|
2363 |
return 0;
|
|
2364 |
}
|
|
2365 |
|
|
2366 |
|
|
2367 |
|
|
2368 |
int CMTerm1Doc::AddMonitorCoil(int nCoilType, int nCoilAddr, int nCount)
|
|
2369 |
{
|
|
2370 |
// TODO: 在此处添加实现代码.
|
|
2371 |
return 0;
|
|
2372 |
}
|
|
2373 |
|
|
2374 |
|
|
2375 |
int CMTerm1Doc::AddMonitorData(int nDataType, int nDataAddr, int nDataCount)
|
|
2376 |
{
|
|
2377 |
// TODO: 在此处添加实现代码.
|
|
2378 |
return 0;
|
|
2379 |
}
|
|
2380 |
|
|
2381 |
|
|
2382 |
int CMTerm1Doc::ClearMonitor()
|
|
2383 |
{
|
|
2384 |
// TODO: 在此处添加实现代码.
|
|
2385 |
return 0;
|
|
2386 |
}
|
|
2387 |
|
|
2388 |
|
|
2389 |
int CMTerm1Doc::DoPLCMonitor()
|
|
2390 |
{
|
|
2391 |
// TODO: 在此处添加实现代码.
|
|
2392 |
CString s1;
|
|
2393 |
if (m_bSimulate) {
|
|
2394 |
int nDataType = MyKLink1.KLDataTypeWX;
|
|
2395 |
int nDataAddr = 0;
|
|
2396 |
int nDataCount = 4;
|
|
2397 |
// int res;
|
|
2398 |
for (int i = 0; i < nDataCount; i++) {
|
|
2399 |
KMem.WX[i] = myKMachine1.KMem.WX[i];
|
|
2400 |
}
|
|
2401 |
|
|
2402 |
nDataType = MyKLink1.KLDataTypeWY;
|
|
2403 |
nDataAddr = 0;
|
|
2404 |
nDataCount = 4;
|
|
2405 |
for (int i = 0; i < nDataCount; i++) {
|
|
2406 |
KMem.WY[i] = myKMachine1.KMem.WY[i];
|
|
2407 |
}
|
|
2408 |
|
df0321
|
2409 |
nDataType = MyKLink1.KLDataTypeWLX;
|
Q |
2410 |
nDataAddr = 0;
|
|
2411 |
nDataCount = 4;
|
|
2412 |
for (int i = 0; i < nDataCount; i++) {
|
|
2413 |
KMem.WLX[i] = myKMachine1.KMem.WLX[i];
|
|
2414 |
}
|
|
2415 |
|
|
2416 |
nDataType = MyKLink1.KLDataTypeWLY;
|
|
2417 |
nDataAddr = 0;
|
|
2418 |
nDataCount = 4;
|
|
2419 |
for (int i = 0; i < nDataCount; i++) {
|
|
2420 |
KMem.WLY[i] = myKMachine1.KMem.WLY[i];
|
|
2421 |
}
|
|
2422 |
|
418cb3
|
2423 |
nDataType = MyKLink1.KLDataTypeWR;
|
Q |
2424 |
nDataAddr = 0;
|
|
2425 |
nDataCount = 10;
|
|
2426 |
for (int i = 0; i < nDataCount; i++) {
|
|
2427 |
KMem.WR[i] = myKMachine1.KMem.WR[i];
|
|
2428 |
}
|
|
2429 |
|
|
2430 |
nDataType = MyKLink1.KLDataTypeDT;
|
|
2431 |
nDataAddr = 0;
|
|
2432 |
nDataCount = 80;
|
|
2433 |
for (int i = 0; i < nDataCount; i++) {
|
|
2434 |
KMem.DT[i] = myKMachine1.KMem.DT[i];
|
|
2435 |
}
|
|
2436 |
|
|
2437 |
nDataType = MyKLink1.KLDataTypeSV;
|
|
2438 |
nDataAddr = 0;
|
|
2439 |
nDataCount = 40;
|
|
2440 |
for (int i = 0; i < nDataCount; i++) {
|
|
2441 |
KMem.SV[i] = myKMachine1.KMem.SV[i];
|
|
2442 |
}
|
|
2443 |
|
|
2444 |
//res = MyKLink1.ReadDataWord(1, nDataCount, nDataType, nDataAddr, KMem.SV);// (unsigned char *)&KMem.DT[nDataAddr]);
|
|
2445 |
|
|
2446 |
nDataType = MyKLink1.KLDataTypeEV;
|
|
2447 |
nDataAddr = 0;
|
|
2448 |
nDataCount = 40;
|
|
2449 |
for (int i = 0; i < nDataCount; i++) {
|
|
2450 |
KMem.EV[i] = myKMachine1.KMem.EV[i];
|
|
2451 |
}
|
|
2452 |
|
|
2453 |
// res = MyKLink1.ReadDataWord(1, nDataCount, nDataType, nDataAddr, KMem.EV);// (unsigned char *)&KMem.DT[nDataAddr]);
|
|
2454 |
|
|
2455 |
}else if (m_bOnline)
|
|
2456 |
{
|
|
2457 |
int nDataType = MyKLink1.KLDataTypeWX;
|
|
2458 |
int nDataAddr = 0;
|
|
2459 |
int nDataCount = 4;
|
|
2460 |
unsigned short nCount;
|
|
2461 |
int res;
|
|
2462 |
res = MyKLink1.ReadDataWord(1, nDataType, nDataAddr, nDataCount, &nCount, KMem.WX);// (unsigned char *)&KMem.DT[nDataAddr]);
|
|
2463 |
if (res != MyKLink1.KL_OK) {
|
|
2464 |
s1.Format(_T("R:= %d %s \r\n"), res, MyKLink1.m_resultStr);
|
|
2465 |
SysLog(s1);
|
|
2466 |
}
|
|
2467 |
|
|
2468 |
nDataType = MyKLink1.KLDataTypeWY;
|
|
2469 |
nDataAddr = 0;
|
|
2470 |
nDataCount = 4;
|
|
2471 |
res = MyKLink1.ReadDataWord(1, nDataType, nDataAddr, nDataCount, &nCount, KMem.WY);// (unsigned char *)&KMem.DT[nDataAddr]);
|
|
2472 |
if (res != MyKLink1.KL_OK) {
|
|
2473 |
s1.Format(_T("R:= %d %s \r\n"), res, MyKLink1.m_resultStr);
|
|
2474 |
SysLog(s1);
|
|
2475 |
}
|
df0321
|
2476 |
|
Q |
2477 |
nDataType = MyKLink1.KLDataTypeWLX;
|
|
2478 |
nDataAddr = 0;
|
|
2479 |
nDataCount = 4;
|
|
2480 |
res = MyKLink1.ReadDataWord(1, nDataType, nDataAddr, nDataCount, &nCount, KMem.WLX);// (unsigned char *)&KMem.DT[nDataAddr]);
|
|
2481 |
if (res != MyKLink1.KL_OK) {
|
|
2482 |
s1.Format(_T("R:= %d %s \r\n"), res, MyKLink1.m_resultStr);
|
|
2483 |
SysLog(s1);
|
|
2484 |
}
|
|
2485 |
|
|
2486 |
nDataType = MyKLink1.KLDataTypeWLY;
|
|
2487 |
nDataAddr = 0;
|
|
2488 |
nDataCount = 4;
|
|
2489 |
res = MyKLink1.ReadDataWord(1, nDataType, nDataAddr, nDataCount, &nCount, KMem.WLY);// (unsigned char *)&KMem.DT[nDataAddr]);
|
|
2490 |
if (res != MyKLink1.KL_OK) {
|
|
2491 |
s1.Format(_T("R:= %d %s \r\n"), res, MyKLink1.m_resultStr);
|
|
2492 |
SysLog(s1);
|
|
2493 |
}
|
|
2494 |
|
418cb3
|
2495 |
nDataType = MyKLink1.KLDataTypeWR;
|
Q |
2496 |
nDataAddr = 0;
|
|
2497 |
nDataCount = 10;
|
|
2498 |
res = MyKLink1.ReadDataWord(1, nDataType, nDataAddr, nDataCount, &nCount, KMem.WR);// (unsigned char *)&KMem.DT[nDataAddr]);
|
|
2499 |
if (res != MyKLink1.KL_OK) {
|
|
2500 |
s1.Format(_T("R:= %d %s \r\n"), res, MyKLink1.m_resultStr);
|
|
2501 |
SysLog(s1);
|
|
2502 |
}
|
|
2503 |
nDataType = MyKLink1.KLDataTypeDT;
|
|
2504 |
nDataAddr = 0;
|
|
2505 |
nDataCount = 80;
|
|
2506 |
res = MyKLink1.ReadDataWord(1, nDataType, nDataAddr, nDataCount, &nCount, KMem.DT);// (unsigned char *)&KMem.DT[nDataAddr]);
|
|
2507 |
if (res != MyKLink1.KL_OK) {
|
|
2508 |
s1.Format(_T("R:= %d %s \r\n"), res, MyKLink1.m_resultStr);
|
|
2509 |
SysLog(s1);
|
|
2510 |
}
|
|
2511 |
nDataType = MyKLink1.KLDataTypeSV;
|
|
2512 |
nDataAddr = 0;
|
|
2513 |
nDataCount = 40;
|
|
2514 |
res = MyKLink1.ReadDataWord(1, nDataType, nDataAddr, nDataCount, &nCount, KMem.SV);// (unsigned char *)&KMem.DT[nDataAddr]);
|
|
2515 |
if (res != MyKLink1.KL_OK) {
|
|
2516 |
s1.Format(_T("R:= %d %s \r\n"), res, MyKLink1.m_resultStr);
|
|
2517 |
SysLog(s1);
|
|
2518 |
}
|
|
2519 |
nDataType = MyKLink1.KLDataTypeEV;
|
|
2520 |
nDataAddr = 0;
|
|
2521 |
nDataCount = 40;
|
|
2522 |
res = MyKLink1.ReadDataWord(1, nDataType, nDataAddr, nDataCount, &nCount, KMem.EV);// (unsigned char *)&KMem.DT[nDataAddr]);
|
|
2523 |
if (res != MyKLink1.KL_OK) {
|
|
2524 |
s1.Format(_T("R:= %d %s \r\n"), res, MyKLink1.m_resultStr);
|
|
2525 |
SysLog(s1);
|
|
2526 |
}
|
|
2527 |
}
|
|
2528 |
|
|
2529 |
return 0;
|
|
2530 |
}
|
|
2531 |
|
|
2532 |
void CMTerm1Doc::OnTimer(UINT_PTR nIDEvent)
|
|
2533 |
{
|
|
2534 |
CString s1;
|
|
2535 |
// s1.Format(_T("Doc::OntTimer"));
|
|
2536 |
// SysLog(s1);
|
|
2537 |
if (m_bSimulate && m_bPlcRunning)
|
|
2538 |
{
|
|
2539 |
//ProcessPLCProg(Progs, m_nProgSteps);
|
|
2540 |
myKMachine1.ProcPLC();
|
|
2541 |
|
|
2542 |
// update PLC Stat
|
|
2543 |
}
|
|
2544 |
}
|
|
2545 |
|
|
2546 |
void CMTerm1Doc::OnMenuStatusShow()
|
|
2547 |
{
|
|
2548 |
// TODO: 在此添加命令处理程序代码
|
|
2549 |
CDialogStatusShow dialog1;
|
|
2550 |
INT_PTR r = dialog1.DoModal();
|
|
2551 |
if (r == IDOK)
|
|
2552 |
{
|
|
2553 |
|
|
2554 |
}
|
|
2555 |
}
|
|
2556 |
|
|
2557 |
void CMTerm1Doc::OnMenuDatetimeSet()
|
|
2558 |
{
|
|
2559 |
// TODO: 在此添加命令处理程序代码
|
|
2560 |
CDialogDateTime dialog1;
|
|
2561 |
INT_PTR r = dialog1.DoModal();
|
|
2562 |
if (r == IDOK)
|
|
2563 |
{
|
|
2564 |
|
|
2565 |
}
|
|
2566 |
}
|
|
2567 |
|
|
2568 |
void CMTerm1Doc::OnMenuEventLog()
|
|
2569 |
{
|
|
2570 |
// TODO: 在此添加命令处理程序代码
|
|
2571 |
CDialogEventLog dialog1;
|
|
2572 |
INT_PTR r = dialog1.DoModal();
|
|
2573 |
if (r == IDOK)
|
|
2574 |
{
|
|
2575 |
|
|
2576 |
}
|
|
2577 |
}
|