提交 | 用户 | age
|
0ed438
|
1 |
|
Q |
2 |
// MultiTerminal2Doc.cpp: CMTerm2Doc 类的实现
|
|
3 |
//
|
|
4 |
|
|
5 |
#include "pch.h"
|
|
6 |
#include "framework.h"
|
|
7 |
// SHARED_HANDLERS 可以在实现预览、缩略图和搜索筛选器句柄的
|
|
8 |
// ATL 项目中进行定义,并允许与该项目共享文档代码。
|
|
9 |
#ifndef SHARED_HANDLERS
|
|
10 |
#include "MTerm2.h"
|
|
11 |
#endif
|
|
12 |
|
|
13 |
#include "MTerm2Doc.h"
|
|
14 |
|
|
15 |
#include "MTerm2View.h"
|
|
16 |
#include "MTerm2LdsView.h"
|
|
17 |
#include "MTerm2BldView.h"
|
|
18 |
#include "MTerm2BnlView.h"
|
|
19 |
|
|
20 |
#include "MTerm2CoilView.h"
|
|
21 |
#include "MTerm2DataView.h"
|
|
22 |
|
|
23 |
#include "MTerm2CtrlView.h"
|
|
24 |
#include "MTerm2TestView.h"
|
|
25 |
#include "MTerm2ProgTxt.h"
|
|
26 |
#include "MTerm2CommDevView.h"
|
|
27 |
#include <propkey.h>
|
|
28 |
|
|
29 |
#include "CDialogCommSet1.h"
|
|
30 |
#include "HvSerialPort.h"
|
|
31 |
#include <functional>
|
|
32 |
|
|
33 |
#ifdef _DEBUG
|
|
34 |
#define new DEBUG_NEW
|
|
35 |
#endif
|
|
36 |
|
|
37 |
// CMTerm2Doc
|
|
38 |
CMTerm2Doc::stTypeDef CMTerm2Doc::CoilTypeDef[] =
|
|
39 |
{
|
|
40 |
{KLCoilTypeX,"X"},
|
|
41 |
{KLCoilTypeY,"Y"},
|
|
42 |
{KLCoilTypeR,"R"},
|
|
43 |
{KLCoilTypeLX,"LX"},
|
|
44 |
{KLCoilTypeLY,"LY"},
|
|
45 |
{KLCoilTypeLR,"LR"},
|
|
46 |
{KLCoilTypeSR,"SR"},
|
|
47 |
{KLCoilTypeC,"C"},
|
|
48 |
{KLCoilTypeT,"T"},
|
|
49 |
};
|
|
50 |
int CMTerm2Doc::nCoilTypeDefCount = sizeof(CMTerm2Doc::CoilTypeDef) / sizeof(stTypeDef);
|
|
51 |
|
|
52 |
CMTerm2Doc::stTypeDef CMTerm2Doc::DataTypeDef[] =
|
|
53 |
{
|
|
54 |
{KLDataTypeDEC,"K"},
|
|
55 |
{KLDataTypeHEX,"H"},
|
|
56 |
{KLDataTypeWX,"WX"},
|
|
57 |
{KLDataTypeWY,"WY"},
|
|
58 |
{KLDataTypeWR,"WR"},
|
|
59 |
{KLDataTypeDT,"DT"},
|
|
60 |
{KLDataTypeWLX,"WLX"},
|
|
61 |
{KLDataTypeWLY,"WLY"},
|
|
62 |
{KLDataTypeSDT,"SDT"},
|
|
63 |
{KLDataTypeWSR,"WSR"},
|
|
64 |
{KLDataTypeEV,"EV"},
|
|
65 |
{KLDataTypeSV,"SV"},
|
|
66 |
{KLDataTypeLD,"LD"},
|
|
67 |
};
|
|
68 |
int CMTerm2Doc::nDataTypeDefCount = sizeof(CMTerm2Doc::DataTypeDef) / sizeof(stTypeDef);
|
|
69 |
|
0a20f7
|
70 |
CMTerm2Doc::stOpDef CMTerm2Doc::OpDef[] =
|
0ed438
|
71 |
{
|
Q |
72 |
{OP_NOP,"NOP",0},
|
|
73 |
{OP_ST,"ST",1,KLParamCoil},
|
|
74 |
{OP_ST_,"ST/",1,KLParamCoil},
|
|
75 |
{OP_AN,"AN",1,KLParamCoil},
|
|
76 |
{OP_AN_,"AN/",1,KLParamCoil},
|
|
77 |
{OP_OR,"OR",1,KLParamCoil},
|
|
78 |
{OP_OR_,"OR/",1,KLParamCoil},
|
|
79 |
{OP_NOT,"NOT"},
|
|
80 |
{OP_ANS,"ANS"},
|
|
81 |
{OP_ORS,"ORS"}
|
|
82 |
,
|
|
83 |
{OP_PSHS,"PSHS"},
|
|
84 |
{OP_RDS,"RDS"},
|
|
85 |
{OP_POPS,"POPS"},
|
|
86 |
{OP_OUT,"OUT",1,KLParamCoil},
|
|
87 |
{OP_SET,"SET",1,KLParamCoil},
|
|
88 |
{OP_RESET,"RESET",1,KLParamCoil},
|
|
89 |
{OP_DF,"DF"},
|
|
90 |
{OP_DF_,"DF/"},
|
|
91 |
{OP_ST_EQ,"ST=",2,KLParamWord,"="},
|
|
92 |
{OP_ST_LT,"ST<",2,KLParamWord,"<"},
|
|
93 |
{OP_ST_GT,"ST>",2,KLParamWord,">"},
|
|
94 |
{OP_ST_LE,"ST<=",2,KLParamWord,"<="},
|
|
95 |
{OP_ST_GE,"ST>=",2,KLParamWord,">="},
|
|
96 |
{OP_ST_NE,"ST<>",2,KLParamWord,"<>"},
|
|
97 |
{OP_AN_EQ,"AN=",2,KLParamWord,"="},
|
|
98 |
{OP_AN_LT,"AN<",2,KLParamWord,"<"},
|
|
99 |
{OP_AN_GT,"AN>",2,KLParamWord,">"},
|
|
100 |
{OP_AN_LE,"AN<=",2,KLParamWord,"<="},
|
|
101 |
{OP_AN_GE,"AN>=",2,KLParamWord,">="},
|
|
102 |
{OP_AN_NE,"AN<>",2,KLParamWord,"<>"},
|
|
103 |
{OP_OR_EQ,"OR=",2,KLParamWord,"="},
|
|
104 |
{OP_OR_LT,"OR<",2,KLParamWord,"<"},
|
|
105 |
{OP_OR_GT,"OR>",2,KLParamWord,">"},
|
|
106 |
{OP_OR_LE,"OR<=",2,KLParamWord,"<="},
|
|
107 |
{OP_OR_GE,"OR>=",2,KLParamWord,">="},
|
|
108 |
{OP_OR_NE,"OR<>",2,KLParamWord,"<>"},
|
|
109 |
|
|
110 |
{OP_TML,"TML",2,KLParamWord,"TML"},
|
|
111 |
{OP_TMR,"TMR",2,KLParamWord,"TMR"},
|
|
112 |
{OP_TMX,"TMX",2,KLParamWord,"TMX"},
|
|
113 |
{OP_TMY,"TMY",2,KLParamWord,"TMY"},
|
|
114 |
|
|
115 |
{OP_MV,"MV",2,KLParamWord,"MV"},
|
|
116 |
{OP_INC,"INC",1,KLParamWord,"+1"},
|
|
117 |
{OP_ADD2,"ADD2",2,KLParamWord,"+"},
|
|
118 |
{OP_ADD3,"ADD3",3,KLParamWord,"+"},
|
|
119 |
{OP_DEC,"DEC",1,KLParamWord,"-1"},
|
|
120 |
{OP_SUB2,"SUB2",2,KLParamWord,"-"},
|
|
121 |
{OP_SUB3,"SUB3",3,KLParamWord,"-"},
|
|
122 |
{OP_MUL,"MUL",3,KLParamWord,"X"},
|
|
123 |
{OP_DIV,"DIV",3,KLParamWord,"/"},
|
|
124 |
|
|
125 |
|
|
126 |
|
|
127 |
|
|
128 |
};
|
0a20f7
|
129 |
int CMTerm2Doc::nOpDefCount = sizeof(CMTerm2Doc::OpDef) / sizeof(stOpDef);
|
0ed438
|
130 |
|
Q |
131 |
IMPLEMENT_DYNCREATE(CMTerm2Doc, CDocument)
|
|
132 |
|
|
133 |
BEGIN_MESSAGE_MAP(CMTerm2Doc, CDocument)
|
|
134 |
ON_COMMAND(ID_UPLOAD_FROM_PLC, &CMTerm2Doc::OnUploadFromPlc)
|
|
135 |
ON_COMMAND(ID_ONLINE, &CMTerm2Doc::OnOnline)
|
|
136 |
ON_UPDATE_COMMAND_UI(ID_ONLINE, &CMTerm2Doc::OnUpdateOnline)
|
|
137 |
ON_COMMAND(ID_OFFLINE, &CMTerm2Doc::OnOffline)
|
|
138 |
ON_UPDATE_COMMAND_UI(ID_OFFLINE, &CMTerm2Doc::OnUpdateOffline)
|
|
139 |
ON_COMMAND(ID_PLC_RUN, &CMTerm2Doc::OnPlcRun)
|
|
140 |
ON_UPDATE_COMMAND_UI(ID_PLC_RUN, &CMTerm2Doc::OnUpdatePlcRun)
|
|
141 |
ON_COMMAND(ID_DOWNLOAD_TO_PLC, &CMTerm2Doc::OnDownloadToPlc)
|
|
142 |
ON_UPDATE_COMMAND_UI(ID_DOWNLOAD_TO_PLC, &CMTerm2Doc::OnUpdateDownloadToPlc)
|
|
143 |
|
|
144 |
ON_COMMAND(ID_COMUNICATION_SET, &CMTerm2Doc::OnComunicationSet)
|
|
145 |
ON_COMMAND(ID_PLC_SYSREG_SET, &CMTerm2Doc::OnPlcSysregSet)
|
|
146 |
|
|
147 |
ON_COMMAND(ID_MENU_VIEW_LDS, &CMTerm2Doc::OnMenuViewLds)
|
|
148 |
ON_COMMAND(ID_MENU_VIEW_BLD, &CMTerm2Doc::OnMenuViewBld)
|
|
149 |
ON_COMMAND(ID_MENU_VIEW_BNL, &CMTerm2Doc::OnMenuViewBnl)
|
|
150 |
ON_COMMAND(ID_MENU_SHOW_CONSOLE, &CMTerm2Doc::OnMenuShowConsole)
|
|
151 |
|
|
152 |
ON_COMMAND(ID_MENU_COMM_TEST, &CMTerm2Doc::OnMenuCommTest)
|
|
153 |
ON_COMMAND(ID_SIMULATE, &CMTerm2Doc::OnSimulate)
|
|
154 |
ON_UPDATE_COMMAND_UI(ID_SIMULATE, &CMTerm2Doc::OnUpdateSimulate)
|
|
155 |
END_MESSAGE_MAP()
|
|
156 |
|
|
157 |
|
|
158 |
// CMTerm2Doc 构造/析构
|
|
159 |
|
|
160 |
CMTerm2Doc::CMTerm2Doc() noexcept
|
|
161 |
{
|
|
162 |
// TODO: 在此添加一次性构造代码
|
|
163 |
|
|
164 |
MyKLink1.SetSendCallBackFunc(std::bind(&CMTerm2Doc::SendPacket, this, std::placeholders::_1, std::placeholders::_2));
|
|
165 |
MyKLink1.SetRecvCallBackFunc(std::bind(&CMTerm2Doc::RecvPacket, this, std::placeholders::_1, std::placeholders::_2));
|
|
166 |
StartTime = myHvSerialPort1.GetTimeMs();
|
|
167 |
}
|
|
168 |
|
|
169 |
CMTerm2Doc::~CMTerm2Doc()
|
|
170 |
{
|
|
171 |
}
|
|
172 |
|
|
173 |
int CMTerm2Doc::SendPacket(void * pBuf, int Len)
|
|
174 |
{
|
|
175 |
return myHvSerialPort1.Send((char *)pBuf, Len);
|
|
176 |
}
|
|
177 |
int CMTerm2Doc::RecvPacket(void * pBuf, int Len)
|
|
178 |
{
|
|
179 |
int j = myHvSerialPort1.Recv((char *)pBuf, Len);
|
|
180 |
if (j <= 0)
|
|
181 |
{
|
|
182 |
CString s1;
|
|
183 |
s1.Format(_T("Read %d R=%d %s"), Len, j, myHvSerialPort1.m_strResult);
|
|
184 |
SysLog(s1);
|
|
185 |
}
|
|
186 |
return j;
|
|
187 |
}
|
|
188 |
|
|
189 |
|
|
190 |
BOOL CMTerm2Doc::OnNewDocument()
|
|
191 |
{
|
|
192 |
if (!CDocument::OnNewDocument())
|
|
193 |
return FALSE;
|
|
194 |
|
|
195 |
// TODO: 在此添加重新初始化代码
|
|
196 |
// (SDI 文档将重用该文档)
|
|
197 |
// LoadFromFile(_T("0prog1.txt"));
|
|
198 |
return TRUE;
|
|
199 |
|
|
200 |
}
|
|
201 |
BOOL CMTerm2Doc::OnOpenDocument(LPCTSTR lpszPathName)
|
|
202 |
{
|
|
203 |
// if (!CDocument::OnOpenDocument(lpszPathName))
|
|
204 |
// return FALSE;
|
|
205 |
|
|
206 |
// TODO: 在此添加您专用的创建代码
|
|
207 |
CString s1;
|
|
208 |
s1.Format(_T("OnOpenDocument %s"), lpszPathName);
|
|
209 |
SysLog(s1);
|
|
210 |
LoadFromFile(lpszPathName);
|
|
211 |
return TRUE;
|
|
212 |
}
|
|
213 |
|
|
214 |
|
|
215 |
BOOL CMTerm2Doc::OnSaveDocument(LPCTSTR lpszPathName)
|
|
216 |
{
|
|
217 |
// TODO: 在此添加专用代码和/或调用基类
|
|
218 |
CString s1;
|
|
219 |
s1.Format(_T("OnSaveDocument %s"), lpszPathName);
|
|
220 |
SysLog(s1);
|
|
221 |
SaveToFile(lpszPathName);
|
|
222 |
return TRUE;
|
|
223 |
// return CDocument::OnSaveDocument(lpszPathName);
|
|
224 |
}
|
|
225 |
|
|
226 |
|
|
227 |
void CMTerm2Doc::OnCloseDocument()
|
|
228 |
{
|
|
229 |
// TODO: 在此添加专用代码和/或调用基类
|
|
230 |
// CString s1;
|
|
231 |
// s1.Format(_T("OnCloseDocument %s"));
|
|
232 |
// SysLog(s1);
|
|
233 |
CDocument::OnCloseDocument();
|
|
234 |
}
|
|
235 |
|
|
236 |
// CMTerm2Doc 序列化
|
|
237 |
|
|
238 |
void CMTerm2Doc::Serialize(CArchive& ar)
|
|
239 |
{
|
|
240 |
CString s1;
|
|
241 |
if (ar.IsStoring())
|
|
242 |
{
|
|
243 |
// TODO: 在此添加存储代码
|
|
244 |
ar.GetFile();
|
|
245 |
s1.Format(_T("Serialize Saving"));
|
|
246 |
SysLog(s1);
|
|
247 |
}
|
|
248 |
else
|
|
249 |
{
|
|
250 |
// TODO: 在此添加加载代码
|
|
251 |
s1.Format(_T("Serialize Loading"));
|
|
252 |
SysLog(s1);
|
|
253 |
}
|
|
254 |
}
|
|
255 |
|
|
256 |
#ifdef SHARED_HANDLERS
|
|
257 |
|
|
258 |
// 缩略图的支持
|
|
259 |
void CMTerm2Doc::OnDrawThumbnail(CDC& dc, LPRECT lprcBounds)
|
|
260 |
{
|
|
261 |
// 修改此代码以绘制文档数据
|
|
262 |
dc.FillSolidRect(lprcBounds, RGB(255, 255, 255));
|
|
263 |
|
|
264 |
CString strText = _T("TODO: implement thumbnail drawing here");
|
|
265 |
LOGFONT lf;
|
|
266 |
|
|
267 |
CFont* pDefaultGUIFont = CFont::FromHandle((HFONT) GetStockObject(DEFAULT_GUI_FONT));
|
|
268 |
pDefaultGUIFont->GetLogFont(&lf);
|
|
269 |
lf.lfHeight = 36;
|
|
270 |
|
|
271 |
CFont fontDraw;
|
|
272 |
fontDraw.CreateFontIndirect(&lf);
|
|
273 |
|
|
274 |
CFont* pOldFont = dc.SelectObject(&fontDraw);
|
|
275 |
dc.DrawText(strText, lprcBounds, DT_CENTER | DT_WORDBREAK);
|
|
276 |
dc.SelectObject(pOldFont);
|
|
277 |
}
|
|
278 |
|
|
279 |
// 搜索处理程序的支持
|
|
280 |
void CMTerm2Doc::InitializeSearchContent()
|
|
281 |
{
|
|
282 |
CString strSearchContent;
|
|
283 |
// 从文档数据设置搜索内容。
|
|
284 |
// 内容部分应由“;”分隔
|
|
285 |
|
|
286 |
// 例如: strSearchContent = _T("point;rectangle;circle;ole object;");
|
|
287 |
SetSearchContent(strSearchContent);
|
|
288 |
}
|
|
289 |
|
|
290 |
void CMTerm2Doc::SetSearchContent(const CString& value)
|
|
291 |
{
|
|
292 |
if (value.IsEmpty())
|
|
293 |
{
|
|
294 |
RemoveChunk(PKEY_Search_Contents.fmtid, PKEY_Search_Contents.pid);
|
|
295 |
}
|
|
296 |
else
|
|
297 |
{
|
|
298 |
CMFCFilterChunkValueImpl *pChunk = nullptr;
|
|
299 |
ATLTRY(pChunk = new CMFCFilterChunkValueImpl);
|
|
300 |
if (pChunk != nullptr)
|
|
301 |
{
|
|
302 |
pChunk->SetTextValue(PKEY_Search_Contents, value, CHUNK_TEXT);
|
|
303 |
SetChunkValue(pChunk);
|
|
304 |
}
|
|
305 |
}
|
|
306 |
}
|
|
307 |
|
|
308 |
#endif // SHARED_HANDLERS
|
|
309 |
|
|
310 |
// CMTerm2Doc 诊断
|
|
311 |
|
|
312 |
#ifdef _DEBUG
|
|
313 |
void CMTerm2Doc::AssertValid() const
|
|
314 |
{
|
|
315 |
CDocument::AssertValid();
|
|
316 |
}
|
|
317 |
|
|
318 |
void CMTerm2Doc::Dump(CDumpContext& dc) const
|
|
319 |
{
|
|
320 |
CDocument::Dump(dc);
|
|
321 |
}
|
|
322 |
#endif //_DEBUG
|
|
323 |
|
|
324 |
|
|
325 |
// CMTerm2Doc 命令
|
|
326 |
int CMTerm2Doc::LoadFromFile(CString sFilePathName)
|
|
327 |
{
|
|
328 |
// TODO: 在此处添加实现代码.
|
|
329 |
CFile file1;
|
|
330 |
CFileException e;
|
|
331 |
bool r = file1.Open(sFilePathName, CFile::modeRead, &e);
|
|
332 |
if (r)
|
|
333 |
{
|
|
334 |
int l = (int)file1.GetLength();
|
|
335 |
CStringA s1A;
|
|
336 |
file1.Read(s1A.GetBuffer(l + 2048), l);
|
|
337 |
file1.Close();
|
|
338 |
s1A.ReleaseBuffer(l);
|
|
339 |
TransFileToProg(s1A);
|
|
340 |
UpdateAllViews(NULL);
|
|
341 |
}
|
|
342 |
return 0;
|
|
343 |
}
|
|
344 |
|
|
345 |
|
|
346 |
int CMTerm2Doc::SaveToFile(CString sFilePathName)
|
|
347 |
{
|
|
348 |
// TODO: 在此处添加实现代码.
|
|
349 |
CString s1;
|
|
350 |
CFile file1;
|
|
351 |
CFileException e;
|
|
352 |
bool r = file1.Open(sFilePathName, CFile::modeReadWrite, &e);
|
|
353 |
if (r)
|
|
354 |
{
|
|
355 |
|
|
356 |
CStringA s1A;
|
|
357 |
CStringA sSectionNameA;
|
|
358 |
|
|
359 |
//写入系统配置
|
|
360 |
GetSectionTxt(SectionSysCfg, sSectionNameA); //
|
|
361 |
s1A = "[" + sSectionNameA + "]\r\n";
|
|
362 |
file1.Write(s1A, s1A.GetLength());
|
|
363 |
|
|
364 |
//写入程序
|
|
365 |
GetSectionTxt(SectionProg, sSectionNameA); //
|
|
366 |
s1A = "[" + sSectionNameA + "]\r\n";
|
|
367 |
file1.Write(s1A, s1A.GetLength());
|
|
368 |
|
|
369 |
TransToTxt(s1A);
|
|
370 |
file1.Write(s1A, s1A.GetLength());
|
|
371 |
|
|
372 |
//写入注释
|
|
373 |
GetSectionTxt(SectionAnno, sSectionNameA); //
|
|
374 |
s1A = "[" + sSectionNameA + "]\r\n";
|
|
375 |
file1.Write(s1A, s1A.GetLength());
|
|
376 |
for (int i = 0; i < nCoilAnnoCount; i++)
|
|
377 |
{
|
|
378 |
if (mCoilAnnos[i].sAnno.IsEmpty()) { continue; }
|
|
379 |
s1 = mCoilAnnos[i].sCoilName + _T("\t") + mCoilAnnos[i].sAnno+ _T("\r\n");
|
|
380 |
s1A = s1;
|
|
381 |
file1.Write(s1A, s1A.GetLength());
|
|
382 |
}
|
|
383 |
//写入触点监控列表
|
|
384 |
GetSectionTxt(SectionCoilList, sSectionNameA); //
|
|
385 |
s1A = "[" + sSectionNameA + "]\r\n";
|
|
386 |
file1.Write(s1A, s1A.GetLength());
|
|
387 |
//写入数据监控列表
|
|
388 |
GetSectionTxt(SectionDataList, sSectionNameA); //
|
|
389 |
s1A = "[" + sSectionNameA + "]\r\n";
|
|
390 |
file1.Write(s1A, s1A.GetLength());
|
|
391 |
|
|
392 |
file1.Close();
|
|
393 |
}
|
|
394 |
return 0;
|
|
395 |
}
|
|
396 |
|
|
397 |
int CMTerm2Doc::TxtToSection(CStringA txt)
|
|
398 |
{
|
|
399 |
for (int i = 0; i < nSectionDefCount; i++) {
|
|
400 |
if (SectionDef[i].SectionName == txt) {
|
|
401 |
return SectionDef[i].nSectionType;
|
|
402 |
}
|
|
403 |
}
|
|
404 |
return SectionNone;
|
|
405 |
}
|
|
406 |
|
|
407 |
int CMTerm2Doc::GetSectionTxt(int nSectionType, CStringA & txt)
|
|
408 |
{
|
|
409 |
for (int i = 0; i < nSectionDefCount; i++) {
|
|
410 |
if (SectionDef[i].nSectionType == nSectionType) {
|
|
411 |
txt = SectionDef[i].SectionName;
|
|
412 |
return true;
|
|
413 |
}
|
|
414 |
}
|
|
415 |
return false;
|
|
416 |
}
|
|
417 |
|
|
418 |
int CMTerm2Doc::GetSectionPos(int nSectionType, int * nSectionLine, int * nSectionLines)
|
|
419 |
{
|
|
420 |
for (int i = 0; i < nSectionCount; i++) {
|
|
421 |
if (Sections[i].nSectionType == nSectionType) {
|
|
422 |
*nSectionLine = Sections[i].nSectionLineNo;
|
|
423 |
*nSectionLines = Sections[i].nLines;
|
|
424 |
return true;
|
|
425 |
}
|
|
426 |
}
|
|
427 |
return false;
|
|
428 |
}
|
|
429 |
|
|
430 |
int CMTerm2Doc::TxtToOp(CStringA optxt, int* ParamCount, int* ParamType)
|
|
431 |
{
|
0a20f7
|
432 |
for (int i = 0; i < nOpDefCount; i++){
|
Q |
433 |
if (OpDef[i].OpTxt == optxt) {
|
|
434 |
*ParamCount = OpDef[i].nParamCount;
|
|
435 |
*ParamType = OpDef[i].nParamType;
|
|
436 |
return OpDef[i].nOpType1;
|
0ed438
|
437 |
}
|
Q |
438 |
}
|
|
439 |
return -1;
|
|
440 |
}
|
|
441 |
int CMTerm2Doc::OpToTxt(int nOp, CStringA & OpTxt)
|
|
442 |
{
|
0a20f7
|
443 |
for (int i = 0; i < nOpDefCount; i++){
|
Q |
444 |
if (OpDef[i].nOpType1 == nOp) {
|
|
445 |
OpTxt = OpDef[i].OpTxt;
|
0ed438
|
446 |
return true;
|
Q |
447 |
}
|
|
448 |
}
|
|
449 |
return false;
|
|
450 |
}
|
|
451 |
|
|
452 |
int CMTerm2Doc::OpToShowTxt(int nOp, CStringA & OpShowTxt)
|
|
453 |
{
|
0a20f7
|
454 |
for (int i = 0; i < nOpDefCount; i++) {
|
Q |
455 |
if (OpDef[i].nOpType1 == nOp) {
|
|
456 |
OpShowTxt = OpDef[i].ShowTxt;
|
0ed438
|
457 |
return true;
|
Q |
458 |
}
|
|
459 |
}
|
|
460 |
return false;
|
|
461 |
}
|
|
462 |
|
|
463 |
int CMTerm2Doc::TxtToCoilType(CStringA Typetxt, int* nCoilType, int* nCoilAddr)
|
|
464 |
{
|
|
465 |
Typetxt.MakeUpper();
|
|
466 |
for (int i = 0; i < nCoilTypeDefCount; i++)
|
|
467 |
{
|
|
468 |
if (Typetxt.Find( CoilTypeDef[i].TypeTxt)==0) {
|
|
469 |
*nCoilType = CoilTypeDef[i].nType;
|
|
470 |
*nCoilAddr = atoi(Typetxt.Mid(CoilTypeDef[i].TypeTxt.GetLength()));
|
|
471 |
return CoilTypeDef[i].nType;
|
|
472 |
}
|
|
473 |
}
|
|
474 |
return false;;
|
|
475 |
}
|
|
476 |
|
|
477 |
int CMTerm2Doc::CoilTypeToTxt(int nType, CStringA & typeTxt)
|
|
478 |
{
|
|
479 |
for (int i = 0; i < nCoilTypeDefCount; i++)
|
|
480 |
{
|
|
481 |
if (CoilTypeDef[i].nType == nType){
|
|
482 |
typeTxt = CoilTypeDef[i].TypeTxt;
|
|
483 |
return true;
|
|
484 |
}
|
|
485 |
}
|
|
486 |
return false;
|
|
487 |
}
|
|
488 |
|
|
489 |
int CMTerm2Doc::TxtToDataType(CStringA Typetxt, int * nDataType, int* nDataAddr)
|
|
490 |
{
|
|
491 |
Typetxt.MakeUpper();
|
|
492 |
for (int i = 0; i < nDataTypeDefCount; i++)
|
|
493 |
{
|
|
494 |
if (Typetxt.Find(DataTypeDef[i].TypeTxt) == 0) {
|
|
495 |
*nDataType = DataTypeDef[i].nType;
|
|
496 |
*nDataAddr = atoi(Typetxt.Mid(DataTypeDef[i].TypeTxt.GetLength()));
|
|
497 |
return true;
|
|
498 |
}
|
|
499 |
}
|
|
500 |
return false;
|
|
501 |
}
|
|
502 |
|
|
503 |
|
|
504 |
int CMTerm2Doc::DataTypeToTxt(int nType, CStringA & typeTxt)
|
|
505 |
{
|
|
506 |
for (int i = 0; i < nDataTypeDefCount; i++)
|
|
507 |
{
|
|
508 |
if (DataTypeDef[i].nType == nType) {
|
|
509 |
typeTxt = DataTypeDef[i].TypeTxt;
|
|
510 |
return true;
|
|
511 |
}
|
|
512 |
}
|
|
513 |
return false;
|
|
514 |
}
|
|
515 |
|
|
516 |
int CMTerm2Doc::GetAnno(unsigned short nType, unsigned short nAddr, CString & sAnno)
|
|
517 |
{
|
|
518 |
// TODO: 在此处添加实现代码.
|
|
519 |
// 二分法 查找。
|
|
520 |
// map.
|
|
521 |
for (int i = 0; i < nCoilAnnoCount; i++) {
|
|
522 |
if (mCoilAnnos[i].nType == nType && mCoilAnnos[i].nAddr == nAddr) {
|
|
523 |
sAnno = mCoilAnnos[i].sAnno;
|
|
524 |
return 1;
|
|
525 |
}
|
|
526 |
}
|
|
527 |
return 0;
|
|
528 |
}
|
|
529 |
|
|
530 |
int CMTerm2Doc::SetAnno(CString sCoilName, CString sAnno)
|
|
531 |
{
|
|
532 |
// TODO: 在此处添加实现代码.
|
|
533 |
// 二分法 查找。
|
|
534 |
// map.
|
|
535 |
int bValid = 0;
|
|
536 |
int nType = 0, nAddr = 0;
|
|
537 |
CStringA s1A;
|
|
538 |
s1A = sCoilName;
|
|
539 |
if (TxtToCoilType(s1A, &nType, &nAddr) || TxtToDataType(s1A, &nType, &nAddr)) {
|
|
540 |
bValid = 1;
|
|
541 |
}
|
|
542 |
if (!bValid) return false;
|
|
543 |
|
|
544 |
for (int i = 0; i < nCoilAnnoCount; i++) {
|
|
545 |
if (mCoilAnnos[i].nType == nType && mCoilAnnos[i].nAddr == nAddr) {
|
|
546 |
mCoilAnnos[i].sAnno = sAnno;
|
|
547 |
return 1;
|
|
548 |
}
|
|
549 |
}
|
|
550 |
mCoilAnnos[nCoilAnnoCount].nType = nType;
|
|
551 |
mCoilAnnos[nCoilAnnoCount].nAddr = nAddr;
|
|
552 |
mCoilAnnos[nCoilAnnoCount].sCoilName = sCoilName;
|
|
553 |
mCoilAnnos[nCoilAnnoCount].sAnno = sAnno;
|
|
554 |
nCoilAnnoCount++;
|
|
555 |
return 2;
|
|
556 |
}
|
|
557 |
|
|
558 |
int CMTerm2Doc::SetAnno(unsigned short nType, unsigned short nAddr, CString sCoilName, CString sAnno)
|
|
559 |
{
|
|
560 |
// TODO: 在此处添加实现代码.
|
|
561 |
// 二分法 查找。
|
|
562 |
// map.
|
|
563 |
for (int i = 0; i < nCoilAnnoCount; i++) {
|
|
564 |
if (mCoilAnnos[i].nType == nType && mCoilAnnos[i].nAddr == nAddr) {
|
|
565 |
mCoilAnnos[i].sAnno = sAnno;
|
|
566 |
return 1;
|
|
567 |
}
|
|
568 |
}
|
|
569 |
mCoilAnnos[nCoilAnnoCount].nType = nType;
|
|
570 |
mCoilAnnos[nCoilAnnoCount].nAddr = nAddr;
|
|
571 |
mCoilAnnos[nCoilAnnoCount].sCoilName = sCoilName;
|
|
572 |
mCoilAnnos[nCoilAnnoCount].sAnno = sAnno;
|
|
573 |
nCoilAnnoCount++;
|
|
574 |
return 0;
|
|
575 |
}
|
|
576 |
int CMTerm2Doc::TransLinesToProg(const CStringArray & txtLines, int StartLine , int ProgLines)
|
|
577 |
{
|
|
578 |
CString s1;
|
|
579 |
int txtLineCount = (int)txtLines.GetSize();
|
|
580 |
|
|
581 |
//读取程序 章节
|
|
582 |
int nProgStartLine = 0;
|
|
583 |
int nProgLines = 0;
|
|
584 |
|
|
585 |
nProgStartLine = StartLine;
|
|
586 |
if (ProgLines == -1) nProgLines = txtLineCount;
|
|
587 |
else nProgLines = ProgLines;
|
|
588 |
int nProgPos = 0;
|
|
589 |
|
|
590 |
for (int i = nProgStartLine; i < nProgStartLine + nProgLines; i++)
|
|
591 |
{
|
|
592 |
CString sLine;
|
|
593 |
sLine = txtLines.GetAt(i);
|
|
594 |
sLine.Trim();
|
|
595 |
sLine.Replace(_T("\t"), _T(" "));
|
|
596 |
sLine.Replace(_T(" "), _T(" "));
|
|
597 |
sLine.Replace(_T(" "), _T(" "));
|
|
598 |
CStringArray strarr2;
|
|
599 |
DivideStringToArray(sLine, _T(" "), strarr2);
|
|
600 |
if (strarr2.GetSize() == 0) continue;
|
|
601 |
CString sCmd;
|
|
602 |
sCmd = strarr2.GetAt(0);
|
|
603 |
sCmd.MakeUpper();
|
|
604 |
CStringA s1A;
|
|
605 |
s1A = sCmd;
|
|
606 |
int nParamCount, nParamType;
|
|
607 |
int nType, nAddr;
|
|
608 |
int k = TxtToOp(s1A, &nParamCount, &nParamType);
|
|
609 |
if (k >= 0)
|
|
610 |
{
|
|
611 |
Progs[nProgPos].nOpType1 = k;
|
|
612 |
for (int j = 0; j < 3 && j < nParamCount && j < strarr2.GetSize() - 1; j++)
|
|
613 |
{
|
|
614 |
s1A = strarr2.GetAt(j + 1);
|
|
615 |
s1A.MakeUpper();
|
|
616 |
Progs[nProgPos].Params[j].sParamStr = s1A;
|
|
617 |
if (nParamType == KLParamCoil) {
|
|
618 |
TxtToCoilType(s1A, &nType, &nAddr);
|
|
619 |
Progs[nProgPos].Params[j].nParamType = nType;
|
|
620 |
Progs[nProgPos].Params[j].nParamAddr = nAddr;
|
|
621 |
}
|
|
622 |
else if (nParamType == KLParamWord) {
|
|
623 |
TxtToDataType(s1A, &nType, &nAddr);
|
|
624 |
Progs[nProgPos].Params[j].nParamType = nType;
|
|
625 |
Progs[nProgPos].Params[j].nParamAddr = nAddr;
|
|
626 |
}
|
|
627 |
else {
|
|
628 |
|
|
629 |
}
|
|
630 |
}
|
|
631 |
Progs[nProgPos].nParamCount = (int)strarr2.GetSize() - 1;
|
|
632 |
Progs[nProgPos].PairTo = 0;
|
|
633 |
nProgPos++;
|
|
634 |
}
|
|
635 |
}
|
|
636 |
m_nProgSteps = nProgPos;
|
|
637 |
// 先扫描分开的程序段
|
|
638 |
int stpos[100] = { 0 };
|
|
639 |
int nSts = 0;
|
|
640 |
int StackDeeps[512] = { 0 };
|
|
641 |
int nCurStackDeep = 0;
|
|
642 |
// 查找匹配指令和地址
|
|
643 |
s1.Format(_T("DOC::Trans to Prog "));
|
|
644 |
SysLog(s1);
|
|
645 |
for (int i = 0; i < m_nProgSteps; i++) {
|
|
646 |
int nOpType = Progs[i].nOpType1;
|
|
647 |
int nParamCount = Progs[i].nParamCount;
|
|
648 |
switch (Progs[i].nOpType1)
|
|
649 |
{
|
|
650 |
case OP_ST:
|
|
651 |
case OP_ST_:
|
|
652 |
case OP_ST_EQ:
|
|
653 |
case OP_ST_NE:
|
|
654 |
case OP_ST_LT:
|
|
655 |
case OP_ST_GT:
|
|
656 |
case OP_ST_LE:
|
|
657 |
case OP_ST_GE:
|
|
658 |
|
|
659 |
nCurStackDeep++;
|
|
660 |
s1.Format(_T("St Deep %d pos %d "), nCurStackDeep, i);
|
|
661 |
//SysLog(s1);
|
|
662 |
stpos[nSts] = i;
|
|
663 |
nSts++;
|
|
664 |
break;
|
|
665 |
case OP_ANS:
|
|
666 |
case OP_ORS:
|
|
667 |
Progs[stpos[nSts - 1]].PairTo = i; // CMTerm2Doc::OP_ANS;
|
|
668 |
s1.Format(_T("Pair deep %d %d -- %d"), nCurStackDeep, stpos[nSts - 1], i);
|
|
669 |
//SysLog(s1);
|
|
670 |
nCurStackDeep--;
|
|
671 |
nSts--;
|
|
672 |
break;
|
|
673 |
case OP_PSHS:
|
|
674 |
break;
|
|
675 |
case OP_POPS:
|
|
676 |
break;
|
|
677 |
break;
|
|
678 |
default:
|
|
679 |
break;
|
|
680 |
}
|
|
681 |
StackDeeps[i] = nCurStackDeep;
|
|
682 |
}
|
|
683 |
s1.Format(_T("Remaining STs %d"), nSts);
|
|
684 |
SysLog(s1);
|
|
685 |
for (int i = 0; i < nSts; i++) {
|
|
686 |
s1.Format(_T("[%d] %d "), i, stpos[i]);
|
|
687 |
SysLog(s1);
|
|
688 |
}
|
|
689 |
s1.Format(_T("Pairs"));
|
|
690 |
SysLog(s1);
|
|
691 |
for (int i = 0; i < m_nProgSteps; i++) {
|
|
692 |
int nPairTo = Progs[i].PairTo;
|
|
693 |
if (nPairTo > 0) {
|
|
694 |
s1.Format(_T("%d -- %d type:%d"), i, nPairTo, Progs[nPairTo].nOpType1);
|
|
695 |
SysLog(s1);
|
|
696 |
}
|
|
697 |
}
|
|
698 |
TransProgToBin();
|
|
699 |
return 0;
|
|
700 |
}
|
|
701 |
|
|
702 |
int CMTerm2Doc::TransTxtToProg(CStringA ProgTxtA)
|
|
703 |
{
|
|
704 |
CString s1;
|
|
705 |
CString sProg;
|
|
706 |
sProg = ProgTxtA;
|
|
707 |
CStringArray txtLines;
|
|
708 |
sProg.Replace(_T("\r\n"), _T("\n"));
|
|
709 |
sProg.Replace(_T("\r"), _T("\n"));
|
|
710 |
|
|
711 |
DivideStringToArray(sProg, _T("\n"), txtLines);
|
|
712 |
|
|
713 |
TransLinesToProg(txtLines);
|
|
714 |
|
|
715 |
return 0;
|
|
716 |
}
|
|
717 |
|
|
718 |
int CMTerm2Doc::ReadAnnoFromTxt(CStringA AnnoTxtA)
|
|
719 |
{
|
|
720 |
// 读取注释章节
|
|
721 |
CString s1;
|
|
722 |
CString sProg;
|
|
723 |
sProg = AnnoTxtA;
|
|
724 |
CStringArray txtLines;
|
|
725 |
sProg.Replace(_T("\r\n"), _T("\n"));
|
|
726 |
sProg.Replace(_T("\r"), _T("\n"));
|
|
727 |
|
|
728 |
DivideStringToArray(sProg, _T("\n"), txtLines);
|
|
729 |
|
|
730 |
|
|
731 |
int txtLineCount = (int)txtLines.GetSize();
|
|
732 |
|
|
733 |
nCoilAnnoCount = 0;
|
|
734 |
int nAnnoSectionLine = 0;
|
|
735 |
int nAnnoStartLine = 0;
|
|
736 |
int nAnnoLines = 0;
|
|
737 |
|
|
738 |
int bAnnoSection = GetSectionPos(SectionAnno, &nAnnoSectionLine, &nAnnoLines);
|
|
739 |
if (bAnnoSection) { nAnnoStartLine = nAnnoSectionLine + 1; }
|
|
740 |
|
|
741 |
for (int i = nAnnoStartLine; i < nAnnoStartLine + nAnnoLines; i++)
|
|
742 |
{
|
|
743 |
CString sLine;
|
|
744 |
sLine = txtLines.GetAt(i);
|
|
745 |
sLine.Trim();
|
|
746 |
int DivPos = sLine.Find(_T("\t"));
|
|
747 |
if (DivPos < 1) continue;
|
|
748 |
|
|
749 |
CString sCoilName;
|
|
750 |
sCoilName = sLine.Left(DivPos);
|
|
751 |
sCoilName.MakeUpper();
|
|
752 |
CString sAnno;
|
|
753 |
sAnno = sLine.Mid(DivPos + 1);
|
|
754 |
|
|
755 |
// SetAnno(sCoilName, sAnno);
|
|
756 |
|
|
757 |
CStringA s1A;
|
|
758 |
s1A = sCoilName;
|
|
759 |
int nParamType, nAddr;
|
|
760 |
TxtToCoilType(s1A, &nParamType, &nAddr) || TxtToDataType(s1A, &nParamType, &nAddr);
|
|
761 |
|
|
762 |
mCoilAnnos[nCoilAnnoCount].nType = nParamType;
|
|
763 |
mCoilAnnos[nCoilAnnoCount].nAddr = nAddr;
|
|
764 |
mCoilAnnos[nCoilAnnoCount].sCoilName = sCoilName;
|
|
765 |
mCoilAnnos[nCoilAnnoCount].sAnno = sAnno;
|
|
766 |
|
|
767 |
nCoilAnnoCount++;
|
|
768 |
}
|
|
769 |
return 0;
|
|
770 |
}
|
|
771 |
|
|
772 |
int CMTerm2Doc::TransFileToProg(CStringA ProgTxtA)
|
|
773 |
{
|
|
774 |
CString s1;
|
|
775 |
CString sProg;
|
|
776 |
sProg = ProgTxtA;
|
|
777 |
CStringArray txtLines;
|
|
778 |
sProg.Replace(_T("\r\n"), _T("\n"));
|
|
779 |
sProg.Replace(_T("\r"), _T("\n"));
|
|
780 |
|
|
781 |
DivideStringToArray(sProg, _T("\n"), txtLines);
|
|
782 |
|
|
783 |
nSectionCount = 0;
|
|
784 |
int nCurSection = 0;
|
|
785 |
int txtLineCount = (int)txtLines.GetSize();
|
|
786 |
for (int i = 0; i < txtLineCount; i++)
|
|
787 |
{
|
|
788 |
CString sLine;
|
|
789 |
sLine = txtLines.GetAt(i);
|
|
790 |
sLine.Trim();
|
|
791 |
int nRightBracket;
|
|
792 |
if (sLine.Find(_T("[")) == 0 && (nRightBracket = sLine.Find(_T("]"))) > 1)
|
|
793 |
{ //找到 [ ] 标志
|
|
794 |
if (nSectionCount > 0) {
|
|
795 |
Sections[nSectionCount - 1].nLines = i - Sections[nSectionCount - 1].nSectionLineNo - 1;
|
|
796 |
s1.Format(_T("- Line %d Section %d Ends, %d Lines"), i, nSectionCount -1 ,Sections[nSectionCount - 1].nLines);
|
|
797 |
SysLog(s1);
|
|
798 |
}
|
|
799 |
CString sSectionName;
|
|
800 |
CStringA sSectionNameA;
|
|
801 |
sSectionName = sLine.Mid(1, nRightBracket - 1);
|
|
802 |
sSectionNameA = sSectionName;
|
|
803 |
int theSection = TxtToSection(sSectionNameA);
|
|
804 |
s1.Format(_T("+ Line %d Section %d : [%s] type:%d "), i + 1, nSectionCount, sSectionName, theSection);
|
|
805 |
SysLog(s1);
|
|
806 |
Sections[nSectionCount].nSectionType = theSection;
|
|
807 |
Sections[nSectionCount].nSectionLineNo = i;
|
|
808 |
nSectionCount++;
|
|
809 |
}
|
|
810 |
}
|
|
811 |
if (nSectionCount > 0) {
|
|
812 |
Sections[nSectionCount - 1].nLines = txtLineCount - Sections[nSectionCount - 1].nSectionLineNo - 1;
|
|
813 |
s1.Format(_T("Section Ends at Line %d Lines %d "), txtLineCount, Sections[nSectionCount - 1].nLines);
|
|
814 |
SysLog(s1);
|
|
815 |
}
|
|
816 |
|
|
817 |
//读取程序 章节
|
|
818 |
int nProgSectionLine = 0;
|
|
819 |
int nProgStartLine = 0;
|
|
820 |
int nProgLines = 0;
|
|
821 |
|
|
822 |
int bProgSection = GetSectionPos(SectionProg, &nProgSectionLine, &nProgLines);
|
|
823 |
if (bProgSection) { nProgStartLine = nProgSectionLine + 1; }
|
|
824 |
else { nProgStartLine = 0; nProgLines = txtLineCount; }
|
|
825 |
|
|
826 |
TransLinesToProg(txtLines,nProgStartLine,nProgLines);
|
|
827 |
|
|
828 |
// 读取注释章节
|
|
829 |
nCoilAnnoCount = 0;
|
|
830 |
int nAnnoSectionLine = 0;
|
|
831 |
int nAnnoStartLine = 0;
|
|
832 |
int nAnnoLines = 0;
|
|
833 |
|
|
834 |
int bAnnoSection = GetSectionPos(SectionAnno, &nAnnoSectionLine, &nAnnoLines);
|
|
835 |
if (bAnnoSection) { nAnnoStartLine = nAnnoSectionLine + 1; }
|
|
836 |
|
|
837 |
for (int i = nAnnoStartLine; i < nAnnoStartLine + nAnnoLines; i++)
|
|
838 |
{
|
|
839 |
CString sLine;
|
|
840 |
sLine = txtLines.GetAt(i);
|
|
841 |
sLine.Trim();
|
|
842 |
int DivPos = sLine.Find(_T("\t"));
|
|
843 |
if (DivPos < 1) continue;
|
|
844 |
|
|
845 |
CString sCoilName;
|
|
846 |
sCoilName = sLine.Left(DivPos);
|
|
847 |
sCoilName.MakeUpper();
|
|
848 |
CString sAnno;
|
|
849 |
sAnno = sLine.Mid(DivPos + 1);
|
|
850 |
|
|
851 |
// SetAnno(sCoilName, sAnno);
|
|
852 |
|
|
853 |
CStringA s1A;
|
|
854 |
s1A = sCoilName;
|
|
855 |
int nParamType,nAddr;
|
|
856 |
TxtToCoilType(s1A, &nParamType,&nAddr)||TxtToDataType(s1A, &nParamType, &nAddr);
|
|
857 |
|
|
858 |
mCoilAnnos[nCoilAnnoCount].nType = nParamType;
|
|
859 |
mCoilAnnos[nCoilAnnoCount].nAddr = nAddr;
|
|
860 |
mCoilAnnos[nCoilAnnoCount].sCoilName = sCoilName;
|
|
861 |
mCoilAnnos[nCoilAnnoCount].sAnno = sAnno;
|
|
862 |
|
|
863 |
nCoilAnnoCount++;
|
|
864 |
}
|
|
865 |
|
|
866 |
return 0;
|
|
867 |
}
|
|
868 |
int CMTerm2Doc::TransToTxt(CStringA &ProgTxt)
|
|
869 |
{
|
|
870 |
CStringA s1, s2;
|
|
871 |
for (int i = 0; i < m_nProgSteps; i++)
|
|
872 |
{
|
|
873 |
OpToTxt(Progs[i].nOpType1,s1);
|
|
874 |
if (Progs[i].nParamCount > 0) { s1.Append("\t" + Progs[i].Params[0].sParamStr); }
|
|
875 |
if (Progs[i].nParamCount > 1) { s1.Append("\t" + Progs[i].Params[1].sParamStr); }
|
|
876 |
if (Progs[i].nParamCount > 2) { s1.Append("\t" + Progs[i].Params[2].sParamStr); }
|
|
877 |
s1.Append("\r\n");
|
|
878 |
s2 += s1;
|
|
879 |
}
|
|
880 |
ProgTxt = s2;
|
|
881 |
return 0;
|
|
882 |
}
|
|
883 |
|
|
884 |
int CMTerm2Doc::TransProgToBin()
|
|
885 |
{
|
|
886 |
CString s1;
|
|
887 |
stBinProg2 * pBinProg2;
|
|
888 |
stBinProg15 * pBinProg15;
|
|
889 |
stBinProg3 * pBinProg3;
|
|
890 |
nBinProgSteps = 0;
|
|
891 |
for (int i = 0; i < m_nProgSteps; i++)
|
|
892 |
{
|
|
893 |
int nOpType = Progs[i].nOpType1;
|
|
894 |
Progs[i].nBinStep = nBinProgSteps;
|
|
895 |
int nParamType1 = Progs[i].Params[0].nParamType;
|
|
896 |
int nParamAddr1 = Progs[i].Params[0].nParamAddr;
|
|
897 |
int nParamType2, nParamAddr2;
|
|
898 |
int nParamType3, nParamAddr3;
|
|
899 |
if (Progs[i].nParamCount > 1) {
|
|
900 |
nParamType2 = Progs[i].Params[1].nParamType;
|
|
901 |
nParamAddr2 = Progs[i].Params[1].nParamAddr;
|
|
902 |
}
|
|
903 |
if (Progs[i].nParamCount > 2) {
|
|
904 |
nParamType3 = Progs[i].Params[2].nParamType;
|
|
905 |
nParamAddr3 = Progs[i].Params[2].nParamAddr;
|
|
906 |
}
|
|
907 |
switch (nOpType)
|
|
908 |
{
|
|
909 |
case OP_NONE:
|
|
910 |
break;
|
|
911 |
//case OP_NOP:
|
|
912 |
break;
|
|
913 |
//无参数 指令
|
|
914 |
case OP_NOT:
|
|
915 |
case OP_ANS:
|
|
916 |
case OP_ORS:
|
|
917 |
case OP_PSHS:
|
|
918 |
case OP_RDS:
|
|
919 |
case OP_POPS:
|
|
920 |
case OP_DF:
|
|
921 |
case OP_DF_:
|
|
922 |
BinProgs[nBinProgSteps].nOp = nOpType;
|
|
923 |
nBinProgSteps += 1;
|
|
924 |
break;
|
|
925 |
// 1参数指令
|
|
926 |
case OP_ST:
|
|
927 |
case OP_ST_:
|
|
928 |
case OP_AN:
|
|
929 |
case OP_AN_:
|
|
930 |
case OP_OR:
|
|
931 |
case OP_OR_:
|
|
932 |
BinProgs[nBinProgSteps].nOp = nOpType;
|
|
933 |
BinProgs[nBinProgSteps].nParamType = nParamType1;
|
|
934 |
BinProgs[nBinProgSteps].nParamAddr = nParamAddr1;
|
|
935 |
nBinProgSteps += 1;
|
|
936 |
break;
|
|
937 |
// 1 参数 输出
|
|
938 |
case OP_OUT:
|
|
939 |
case OP_SET:
|
|
940 |
case OP_RESET:
|
|
941 |
BinProgs[nBinProgSteps].nOp = nOpType;
|
|
942 |
BinProgs[nBinProgSteps].nParamType = nParamType1;
|
|
943 |
BinProgs[nBinProgSteps].nParamAddr = nParamAddr1;
|
|
944 |
nBinProgSteps += 1;
|
|
945 |
break;
|
|
946 |
|
|
947 |
// 比较指令
|
|
948 |
case OP_ST_EQ:
|
|
949 |
case OP_ST_NE:
|
|
950 |
case OP_ST_LT:
|
|
951 |
case OP_ST_GT:
|
|
952 |
case OP_ST_LE:
|
|
953 |
case OP_ST_GE:
|
|
954 |
case OP_AN_EQ:
|
|
955 |
case OP_AN_NE:
|
|
956 |
case OP_AN_LT:
|
|
957 |
case OP_AN_GT:
|
|
958 |
case OP_AN_LE:
|
|
959 |
case OP_AN_GE:
|
|
960 |
case OP_OR_EQ:
|
|
961 |
case OP_OR_NE:
|
|
962 |
case OP_OR_LT:
|
|
963 |
case OP_OR_GT:
|
|
964 |
case OP_OR_LE:
|
|
965 |
case OP_OR_GE:
|
|
966 |
pBinProg2 = (stBinProg2 *)(&BinProgs[nBinProgSteps]);
|
|
967 |
BinProgs[nBinProgSteps].nOp = nOpType;
|
|
968 |
BinProgs[nBinProgSteps].nParamType = 0;
|
|
969 |
BinProgs[nBinProgSteps].nParamAddr = nParamAddr1;
|
|
970 |
BinProgs[nBinProgSteps+1].nOp = nParamType1;
|
|
971 |
BinProgs[nBinProgSteps+1].nParamType = nParamType2;
|
|
972 |
BinProgs[nBinProgSteps+1].nParamAddr = nParamAddr2;
|
|
973 |
nBinProgSteps += 2;
|
|
974 |
break;
|
|
975 |
|
|
976 |
// 定时器
|
|
977 |
case OP_TML:
|
|
978 |
case OP_TMR:
|
|
979 |
case OP_TMX:
|
|
980 |
case OP_TMY:
|
|
981 |
pBinProg15 = (stBinProg15 *)(&BinProgs[nBinProgSteps]);
|
|
982 |
BinProgs[nBinProgSteps].nOp = nOpType;
|
|
983 |
BinProgs[nBinProgSteps].nParamType = nParamAddr1;
|
|
984 |
BinProgs[nBinProgSteps].nParamAddr = nParamAddr2;
|
|
985 |
BinProgs[nBinProgSteps + 1].nOp = nParamType2;
|
|
986 |
BinProgs[nBinProgSteps + 1].nParamType = 0;
|
|
987 |
BinProgs[nBinProgSteps + 1].nParamAddr = 0;
|
|
988 |
nBinProgSteps += 2;
|
|
989 |
break;
|
|
990 |
// 1 参数高级指令
|
|
991 |
case OP_INC:
|
|
992 |
case OP_DEC:
|
|
993 |
pBinProg15 = (stBinProg15 *)(&BinProgs[nBinProgSteps]);
|
|
994 |
pBinProg15->nOp = nOpType;
|
|
995 |
pBinProg15->nOpNum = 0;
|
|
996 |
pBinProg15->nParamType1 = nParamType1;
|
|
997 |
pBinProg15->nParamAddr1 = nParamAddr1;
|
|
998 |
pBinProg15->resvr1 = 0;
|
|
999 |
pBinProg15->resvr2 = 0;
|
|
1000 |
nBinProgSteps += 2;
|
|
1001 |
break;
|
|
1002 |
// 2参数高级指令
|
|
1003 |
case OP_MV:
|
|
1004 |
case OP_ADD2:
|
|
1005 |
case OP_SUB2:
|
|
1006 |
pBinProg2 = (stBinProg2 *)(&BinProgs[nBinProgSteps]);
|
|
1007 |
pBinProg2->nOp = nOpType;
|
|
1008 |
pBinProg2->nOpNum = 0;
|
|
1009 |
pBinProg2->nParamType1 = nParamType1;
|
|
1010 |
pBinProg2->nParamAddr1 = nParamAddr1;
|
|
1011 |
pBinProg2->nParamType2 = nParamType2;
|
|
1012 |
pBinProg2->nParamAddr2 = nParamAddr2;
|
|
1013 |
nBinProgSteps += 2;
|
|
1014 |
|
|
1015 |
break;
|
|
1016 |
// 3 参数高级指令
|
|
1017 |
case OP_ADD3:
|
|
1018 |
case OP_SUB3:
|
|
1019 |
case OP_MUL:
|
|
1020 |
case OP_DIV:
|
|
1021 |
pBinProg3 = (stBinProg3 *)(&BinProgs[nBinProgSteps]);
|
|
1022 |
pBinProg3->nOp = nOpType;
|
|
1023 |
pBinProg3->nOpNum = 0;
|
|
1024 |
pBinProg3->nParamType1 = nParamType1;
|
|
1025 |
pBinProg3->nParamAddr1 = nParamAddr1;
|
|
1026 |
pBinProg3->nParamType2 = nParamType2;
|
|
1027 |
pBinProg3->nParamAddr2 = nParamAddr2;
|
|
1028 |
pBinProg3->nParamType3 = nParamType3;
|
|
1029 |
pBinProg3->nParamAddr3 = nParamAddr3;
|
|
1030 |
nBinProgSteps += 3;
|
|
1031 |
break;
|
|
1032 |
default:
|
|
1033 |
break;
|
|
1034 |
}
|
|
1035 |
}
|
|
1036 |
s1.Format(_T("%d steps to %d binSteps "), m_nProgSteps, nBinProgSteps);
|
|
1037 |
DbgLog(s1);
|
|
1038 |
|
|
1039 |
return 0;
|
|
1040 |
}
|
|
1041 |
|
|
1042 |
int CMTerm2Doc::TransBinToProg()
|
|
1043 |
{
|
|
1044 |
|
|
1045 |
return 0;
|
|
1046 |
}
|
|
1047 |
|
|
1048 |
void CMTerm2Doc::OnUploadFromPlc()
|
|
1049 |
{
|
|
1050 |
// TODO: 在此添加命令处理程序代码
|
|
1051 |
int r;
|
|
1052 |
CString s1;
|
|
1053 |
if (!m_bOnline) {
|
|
1054 |
r = Connect();
|
|
1055 |
MyKLink1.Open();
|
|
1056 |
}
|
|
1057 |
if (!m_bOnline) return;
|
|
1058 |
r = MyKLink1.ReadRunStat(1,0,0,32,(unsigned short *)&MyKLink1.KMRunStat);
|
|
1059 |
|
|
1060 |
|
|
1061 |
// AfxMessageBox(_T("UploadFrom PLC From Doc"));
|
|
1062 |
CString s2;
|
|
1063 |
s2.Format(_T("Cur Programs %d \r\n"), nBinProgSteps);
|
|
1064 |
unsigned short * pBinBuf2 = (unsigned short *)BinProgs;
|
|
1065 |
for (int i = 0; i < nBinProgSteps * 2; i += 8) {
|
|
1066 |
s1.Format(_T("%03X: "), i);
|
|
1067 |
for (int j = 0; j < 8 && i+j < nBinProgSteps * 2; j++) {
|
|
1068 |
s1.AppendFormat(_T("%04X "), pBinBuf2[i + j]);
|
|
1069 |
}
|
|
1070 |
s2 += s1 + _T("\r\n");
|
|
1071 |
}
|
|
1072 |
DbgLog(s2);
|
|
1073 |
|
|
1074 |
int nBinSteps = MyKLink1.KMRunStat.nBinProgSize;
|
|
1075 |
s1.Format(_T("program to upload Size %d "), nBinSteps);
|
|
1076 |
DbgLog(s1);
|
|
1077 |
|
|
1078 |
USHORT Buf3[2048];
|
|
1079 |
s2.Empty();
|
|
1080 |
int nUploadSize = nBinSteps *2;
|
|
1081 |
int nSteps = 64;
|
|
1082 |
for (int i = 0; i < nUploadSize; i += nSteps) {
|
|
1083 |
if (i + nSteps > nUploadSize) { nSteps = nUploadSize - i; }
|
|
1084 |
s1.Format(_T("2 Uploading %d to %d "), i, i + nSteps);
|
|
1085 |
DbgLog(s1);
|
|
1086 |
int r = MyKLink1.ReadProgram(1, 2, i, nSteps*2 , Buf3+i);
|
|
1087 |
s1.Format(_T("Download r = %d "), r);
|
|
1088 |
DbgLog(s1);
|
|
1089 |
//Update Progress Bar
|
|
1090 |
}
|
|
1091 |
s2.Format(_T(" Uploaded from bank 2 \r\n"));
|
|
1092 |
for (int i = 0; i < nBinSteps * 2; i += 8) {
|
|
1093 |
s1.Format(_T("%03X: "), i);
|
|
1094 |
for (int j = 0; j < 8 && i + j < nBinSteps * 2; j++) {
|
|
1095 |
s1.AppendFormat(_T("%04X "), Buf3[i + j]);
|
|
1096 |
}
|
|
1097 |
s2 += s1 + _T("\r\n");
|
|
1098 |
}
|
|
1099 |
DbgLog(s2);
|
|
1100 |
|
|
1101 |
for (int i = 0; i < nBinSteps * 2; i++)
|
|
1102 |
{
|
|
1103 |
((USHORT *)BinProgs)[i] = Buf3[i];
|
|
1104 |
}
|
|
1105 |
nBinProgSteps = nBinSteps;
|
|
1106 |
TransBinToProg();
|
|
1107 |
UpdateAllViews(NULL);
|
|
1108 |
}
|
|
1109 |
|
|
1110 |
int CMTerm2Doc::DownloadToPLC()
|
|
1111 |
{
|
|
1112 |
// TODO: 在此处添加实现代码.
|
|
1113 |
int r;
|
|
1114 |
CString s1;
|
|
1115 |
if (!m_bOnline) {
|
|
1116 |
r=Connect();
|
|
1117 |
MyKLink1.Open();
|
|
1118 |
}
|
|
1119 |
if (!m_bOnline) return 0;
|
|
1120 |
|
|
1121 |
if (m_bPlcRunning) {
|
|
1122 |
r = AfxMessageBox(_T("PLC Running, Stop it?"), MB_YESNO);
|
|
1123 |
if (r == IDYES) { StopPLC();}
|
|
1124 |
else { return 0; }
|
|
1125 |
}
|
|
1126 |
|
|
1127 |
// 下载程序
|
|
1128 |
s1.Format(_T("Start Download Program ..."));
|
|
1129 |
DbgLog(s1);
|
|
1130 |
r = MyKLink1.StartProgram(1,2);
|
|
1131 |
s1.Format(_T("Result = %d"),r);
|
|
1132 |
DbgLog(s1);
|
|
1133 |
int DownloadSize = nBinProgSteps;
|
|
1134 |
|
|
1135 |
int Steps = 16;
|
|
1136 |
for (int i = 0; i < DownloadSize; i += Steps) {
|
|
1137 |
//int Steps = 16;
|
|
1138 |
if (i + Steps > DownloadSize) { Steps = DownloadSize - i; }
|
|
1139 |
s1.Format(_T("Downloading %d to %d "), i, i + Steps);
|
|
1140 |
DbgLog(s1);
|
|
1141 |
r = MyKLink1.WriteProgram(1, 2, (i)*4, Steps * 4, (USHORT *)&BinProgs[i]);
|
|
1142 |
s1.Format(_T("Download r = %d "), r);
|
|
1143 |
DbgLog(s1);
|
|
1144 |
//Update Progress Bar
|
|
1145 |
}
|
|
1146 |
|
|
1147 |
s1.Format(_T("Finish Downloading "));
|
|
1148 |
DbgLog(s1);
|
|
1149 |
r = MyKLink1.FinishProgram(1,2,nBinProgSteps);
|
|
1150 |
s1.Format(_T("Download Finished r = %d "), r);
|
|
1151 |
DbgLog(s1);
|
|
1152 |
// 下载注释
|
|
1153 |
|
|
1154 |
|
|
1155 |
// 下载系统寄存器配置
|
|
1156 |
|
|
1157 |
|
|
1158 |
|
|
1159 |
return 0;
|
|
1160 |
}
|
|
1161 |
|
|
1162 |
void CMTerm2Doc::OnDownloadToPlc()
|
|
1163 |
{
|
|
1164 |
// TODO: 在此添加命令处理程序代码
|
|
1165 |
DownloadToPLC();
|
|
1166 |
}
|
|
1167 |
|
|
1168 |
void CMTerm2Doc::OnUpdateDownloadToPlc(CCmdUI *pCmdUI)
|
|
1169 |
{
|
|
1170 |
// TODO: 在此添加命令更新用户界面处理程序代码
|
|
1171 |
}
|
|
1172 |
|
|
1173 |
void CMTerm2Doc::OnOnline()
|
|
1174 |
{
|
|
1175 |
// TODO: 在此添加命令处理程序代码
|
|
1176 |
int r;
|
|
1177 |
if (!m_bOnline)
|
|
1178 |
{
|
|
1179 |
r = Connect();
|
|
1180 |
MyKLink1.Open();
|
|
1181 |
}
|
|
1182 |
if (!m_bOnline) return;
|
|
1183 |
// m_bOnline = true;
|
|
1184 |
UpdateAllViews(NULL, UpdataHint::UpdateStat);
|
|
1185 |
}
|
|
1186 |
|
|
1187 |
void CMTerm2Doc::OnUpdateOnline(CCmdUI *pCmdUI)
|
|
1188 |
{
|
|
1189 |
// TODO: 在此添加命令更新用户界面处理程序代码
|
|
1190 |
pCmdUI->SetCheck(m_bOnline == true);
|
|
1191 |
}
|
|
1192 |
|
|
1193 |
void CMTerm2Doc::OnOffline()
|
|
1194 |
{
|
|
1195 |
// TODO: 在此添加命令处理程序代码
|
|
1196 |
int r;
|
|
1197 |
if (m_bOnline)
|
|
1198 |
{
|
|
1199 |
r = DisConnect();
|
|
1200 |
MyKLink1.Close();
|
|
1201 |
}
|
|
1202 |
m_bOnline = false;
|
|
1203 |
UpdateAllViews(NULL, UpdataHint::UpdateStat);
|
|
1204 |
}
|
|
1205 |
|
|
1206 |
void CMTerm2Doc::OnUpdateOffline(CCmdUI *pCmdUI)
|
|
1207 |
{
|
|
1208 |
// TODO: 在此添加命令更新用户界面处理程序代码
|
|
1209 |
pCmdUI->SetCheck(m_bOnline == false);
|
|
1210 |
}
|
|
1211 |
|
|
1212 |
void CMTerm2Doc::OnSimulate()
|
|
1213 |
{
|
|
1214 |
// TODO: 在此添加命令处理程序代码
|
|
1215 |
if (!m_bSimulate) {
|
|
1216 |
myKMachine1.Download(BinProgs, nBinProgSteps);
|
|
1217 |
myKMachine1.StartPLC();
|
|
1218 |
m_bSimulate = true;
|
|
1219 |
m_bOnline = true;
|
|
1220 |
StartPLC();
|
|
1221 |
}
|
|
1222 |
else {
|
|
1223 |
m_bSimulate = false;
|
|
1224 |
m_bOnline = false;
|
|
1225 |
StopPLC();
|
|
1226 |
}
|
|
1227 |
UpdateAllViews(NULL, UpdataHint::UpdateStat);
|
|
1228 |
}
|
|
1229 |
|
|
1230 |
void CMTerm2Doc::OnUpdateSimulate(CCmdUI *pCmdUI)
|
|
1231 |
{
|
|
1232 |
// TODO: 在此添加命令更新用户界面处理程序代码
|
|
1233 |
pCmdUI->SetCheck(m_bSimulate == true);
|
|
1234 |
}
|
|
1235 |
|
|
1236 |
int CMTerm2Doc::StartPLC()
|
|
1237 |
{
|
|
1238 |
// TODO: 在此处添加实现代码.
|
|
1239 |
for (int i = 0; i < KLDataWXCount; i++) {
|
|
1240 |
KMem.WX[i] = 0;
|
|
1241 |
}
|
|
1242 |
for (int i = 0; i < KLDataWYCount; i++) {
|
|
1243 |
KMem.WY[i] = 0;
|
|
1244 |
}
|
|
1245 |
for (int i = 0; i < KLDataWRCount; i++) {
|
|
1246 |
KMem.WR[i] = 0;
|
|
1247 |
}
|
|
1248 |
for (int i = 0; i < KLDataDTCount; i++) {
|
|
1249 |
KMem.DT[i] = 0;
|
|
1250 |
}
|
|
1251 |
for (int i = 0; i < TOTALTIMERS; i++) {
|
|
1252 |
KMem.Timers[i] = { 0 };
|
|
1253 |
}
|
|
1254 |
nScanCount = 0;
|
|
1255 |
m_bPlcRunning = 1;
|
|
1256 |
return 0;
|
|
1257 |
}
|
|
1258 |
|
|
1259 |
|
|
1260 |
int CMTerm2Doc::StopPLC()
|
|
1261 |
{
|
|
1262 |
// TODO: 在此处添加实现代码.
|
|
1263 |
|
|
1264 |
m_bPlcRunning = false;
|
|
1265 |
|
|
1266 |
return 0;
|
|
1267 |
}
|
|
1268 |
|
|
1269 |
void CMTerm2Doc::OnPlcRun()
|
|
1270 |
{
|
|
1271 |
// TODO: 在此添加命令处理程序代码
|
|
1272 |
if (m_bPlcRunning) { StopPLC(); }
|
|
1273 |
else
|
|
1274 |
{
|
|
1275 |
StartPLC();
|
|
1276 |
}
|
|
1277 |
UpdateAllViews(NULL, UpdataHint::UpdateStat);
|
|
1278 |
}
|
|
1279 |
|
|
1280 |
void CMTerm2Doc::OnUpdatePlcRun(CCmdUI *pCmdUI)
|
|
1281 |
{
|
|
1282 |
// TODO: 在此添加命令更新用户界面处理程序代码
|
|
1283 |
pCmdUI->SetCheck(m_bPlcRunning == true);
|
|
1284 |
if (!m_bPlcRunning) pCmdUI->SetText(_T("PLC模式[PROG]"));
|
|
1285 |
else pCmdUI->SetText(_T("PLC模式[RUN]"));
|
|
1286 |
}
|
|
1287 |
|
|
1288 |
|
|
1289 |
int CMTerm2Doc::SetCommParam()
|
|
1290 |
{
|
|
1291 |
// TODO: 在此处添加实现代码.
|
|
1292 |
CString s1;
|
|
1293 |
s1.Format(_T("Doc SetupComm"));
|
|
1294 |
SysLog(s1);
|
|
1295 |
CDialogCommSet1 dialog1;
|
|
1296 |
INT_PTR r = dialog1.DoModal();
|
|
1297 |
if (r == IDOK )
|
|
1298 |
{
|
|
1299 |
nComPort=dialog1.m_nComNum;
|
|
1300 |
nBaud=dialog1.m_nBaudRate;
|
|
1301 |
ComSettings=dialog1.m_Settings;
|
|
1302 |
s1.Format(_T("dialog return port %d baud %d setting %S"),
|
|
1303 |
nComPort, nBaud, ComSettings);
|
|
1304 |
SysLog(s1);
|
|
1305 |
m_bCommParamSet = true;
|
|
1306 |
}
|
|
1307 |
else
|
|
1308 |
{
|
|
1309 |
return -1;
|
|
1310 |
}
|
|
1311 |
return 0;
|
|
1312 |
}
|
|
1313 |
|
|
1314 |
int CMTerm2Doc::Connect()
|
|
1315 |
{
|
|
1316 |
// TODO: 在此处添加实现代码.
|
|
1317 |
CString s1;
|
|
1318 |
if (!m_bCommParamSet)
|
|
1319 |
{
|
|
1320 |
if (SetCommParam()) return -1;
|
|
1321 |
}
|
|
1322 |
if (m_bOnline) return 0;
|
|
1323 |
|
|
1324 |
myHvSerialPort1.m_nPort = nComPort;
|
|
1325 |
myHvSerialPort1.m_nBaudRate = nBaud;
|
|
1326 |
myHvSerialPort1.m_Settings = "8,N,1";
|
|
1327 |
int r = myHvSerialPort1.Open();
|
|
1328 |
s1.Format(_T("Open %s = %d"), myHvSerialPort1.m_strResult, r);
|
|
1329 |
SysLog(s1);
|
|
1330 |
if (r == myHvSerialPort1.R_OK)
|
|
1331 |
{
|
|
1332 |
m_bOnline = true;
|
|
1333 |
// MyKLink1.Open();
|
|
1334 |
// m_static_connect.SetCtlColor(RGB(0, 255, 0));
|
|
1335 |
return 0;
|
|
1336 |
}
|
|
1337 |
// m_bOnline = true;
|
|
1338 |
return 0;
|
|
1339 |
}
|
|
1340 |
|
|
1341 |
int CMTerm2Doc::DisConnect()
|
|
1342 |
{
|
|
1343 |
// TODO: 在此处添加实现代码.
|
|
1344 |
if (!m_bOnline) return -1;
|
|
1345 |
myHvSerialPort1.Close();
|
|
1346 |
// MyKLink1.Close();
|
|
1347 |
m_bOnline = false;
|
|
1348 |
return 0;
|
|
1349 |
}
|
|
1350 |
|
|
1351 |
void CMTerm2Doc::OnComunicationSet()
|
|
1352 |
{
|
|
1353 |
// TODO: 在此添加命令处理程序代码
|
|
1354 |
SetCommParam();
|
|
1355 |
|
|
1356 |
}
|
|
1357 |
|
|
1358 |
void CMTerm2Doc::OnPlcSysregSet()
|
|
1359 |
{
|
|
1360 |
// TODO: 在此添加命令处理程序代码
|
|
1361 |
}
|
|
1362 |
|
|
1363 |
|
|
1364 |
CView * CMTerm2Doc::FindView(CRuntimeClass * pClass)
|
|
1365 |
{
|
|
1366 |
CView* pView=NULL;
|
|
1367 |
POSITION pos = GetFirstViewPosition();
|
|
1368 |
while (pos != NULL)
|
|
1369 |
{
|
|
1370 |
pView = GetNextView(pos);
|
|
1371 |
if (pView->IsKindOf(pClass))
|
|
1372 |
break;
|
|
1373 |
}
|
|
1374 |
if (!pView->IsKindOf(pClass))
|
|
1375 |
{
|
|
1376 |
//AfxMessageBox("Connt Locate the View.");
|
|
1377 |
return NULL;
|
|
1378 |
}
|
|
1379 |
return pView;
|
|
1380 |
}
|
|
1381 |
///*
|
|
1382 |
void CMTerm2Doc::OnMenuViewLds()
|
|
1383 |
{
|
|
1384 |
// TODO: 在此添加命令处理程序代码
|
|
1385 |
CString s1;
|
|
1386 |
CView * pView;
|
|
1387 |
pView = FindView(RUNTIME_CLASS(CMTerm2View));
|
|
1388 |
if (pView != NULL) {
|
|
1389 |
((CMDIFrameWndEx *)AfxGetMainWnd())->MDIActivate(pView->GetParent());
|
|
1390 |
// pView->SetActiveWindow();
|
|
1391 |
}
|
|
1392 |
else {
|
|
1393 |
s1 = GetTitle();
|
|
1394 |
//AfxMessageBox(s1);
|
|
1395 |
ASSERT_VALID(theApp.pDocTemplate);
|
|
1396 |
CFrameWnd * pFrame = theApp.pDocTemplate->CreateNewFrame(this, NULL);
|
|
1397 |
ASSERT_KINDOF(CFrameWnd, pFrame);
|
|
1398 |
theApp.pDocTemplate->InitialUpdateFrame(pFrame, this);
|
|
1399 |
}
|
|
1400 |
}
|
|
1401 |
|
|
1402 |
|
|
1403 |
void CMTerm2Doc::OnMenuViewBld()
|
|
1404 |
{
|
|
1405 |
// TODO: 在此添加命令处理程序代码
|
|
1406 |
CString s1;
|
|
1407 |
CView * pView;
|
|
1408 |
pView = FindView(RUNTIME_CLASS(CMTerm2BldView));
|
|
1409 |
if (pView != NULL) {
|
|
1410 |
((CMDIFrameWndEx *)AfxGetMainWnd())->MDIActivate(pView->GetParent());
|
|
1411 |
// pView->SetActiveWindow();
|
|
1412 |
}
|
|
1413 |
else {
|
|
1414 |
s1 = GetTitle();
|
|
1415 |
//AfxMessageBox(s1);
|
|
1416 |
ASSERT_VALID(theApp.m_pBldViewTemplate);
|
|
1417 |
CFrameWnd * pFrame = theApp.m_pBldViewTemplate->CreateNewFrame(this, NULL);
|
|
1418 |
ASSERT_KINDOF(CFrameWnd, pFrame);
|
|
1419 |
theApp.m_pBldViewTemplate->InitialUpdateFrame(pFrame, this);
|
|
1420 |
}
|
|
1421 |
}
|
|
1422 |
|
|
1423 |
|
|
1424 |
void CMTerm2Doc::OnMenuViewBnl()
|
|
1425 |
{
|
|
1426 |
// TODO: 在此添加命令处理程序代码
|
|
1427 |
CString s1;
|
|
1428 |
CView * pView;
|
|
1429 |
pView = FindView(RUNTIME_CLASS(CMTerm2BnlView));
|
|
1430 |
if (pView != NULL) {
|
|
1431 |
((CMDIFrameWndEx *)AfxGetMainWnd())->MDIActivate(pView->GetParent());
|
|
1432 |
// pView->SetActiveWindow();
|
|
1433 |
}
|
|
1434 |
else {
|
|
1435 |
s1 = GetTitle();
|
|
1436 |
//AfxMessageBox(s1);
|
|
1437 |
ASSERT_VALID(theApp.m_pBnlViewTemplate);
|
|
1438 |
CFrameWnd * pFrame = theApp.m_pBnlViewTemplate->CreateNewFrame(this, NULL);
|
|
1439 |
ASSERT_KINDOF(CFrameWnd, pFrame);
|
|
1440 |
theApp.m_pBnlViewTemplate->InitialUpdateFrame(pFrame, this);
|
|
1441 |
}
|
|
1442 |
}
|
|
1443 |
//*/
|
|
1444 |
|
|
1445 |
void CMTerm2Doc::OnMenuShowConsole()
|
|
1446 |
{
|
|
1447 |
// TODO: 在此添加命令处理程序代码
|
|
1448 |
CString s1;
|
|
1449 |
CView * pView;
|
|
1450 |
pView = FindView(RUNTIME_CLASS(CMTerm2CtrlView));
|
|
1451 |
if (pView != NULL) {
|
|
1452 |
((CMDIFrameWndEx *)AfxGetMainWnd())->MDIActivate(pView->GetParent());
|
|
1453 |
// pView->SetActiveWindow();
|
|
1454 |
}
|
|
1455 |
else {
|
|
1456 |
s1 = GetTitle();
|
|
1457 |
//AfxMessageBox(s1);
|
|
1458 |
ASSERT_VALID(theApp.m_pCtrlViewTemplate);
|
|
1459 |
CFrameWnd * pFrame = theApp.m_pCtrlViewTemplate->CreateNewFrame(this, NULL);
|
|
1460 |
ASSERT_KINDOF(CFrameWnd, pFrame);
|
|
1461 |
theApp.m_pCtrlViewTemplate->InitialUpdateFrame(pFrame, this);
|
|
1462 |
}
|
|
1463 |
}
|
|
1464 |
|
|
1465 |
|
|
1466 |
void CMTerm2Doc::OnMenuCommTest()
|
|
1467 |
{
|
|
1468 |
// TODO: 在此添加命令处理程序代码
|
|
1469 |
CString s1;
|
|
1470 |
CView * pView;
|
|
1471 |
pView = FindView(RUNTIME_CLASS(CMTerm2CommDevView));
|
|
1472 |
if (pView != NULL) {
|
|
1473 |
((CMDIFrameWndEx *)AfxGetMainWnd())->MDIActivate(pView->GetParent());
|
|
1474 |
// pView->SetActiveWindow();
|
|
1475 |
}
|
|
1476 |
else {
|
|
1477 |
s1 = GetTitle();
|
|
1478 |
//AfxMessageBox(s1);
|
|
1479 |
ASSERT_VALID(theApp.m_pCommDevViewTemplate);
|
|
1480 |
CFrameWnd * pFrame = theApp.m_pCommDevViewTemplate->CreateNewFrame(this, NULL);
|
|
1481 |
ASSERT_KINDOF(CFrameWnd, pFrame);
|
|
1482 |
theApp.m_pCommDevViewTemplate->InitialUpdateFrame(pFrame, this);
|
|
1483 |
}
|
|
1484 |
|
|
1485 |
}
|
|
1486 |
|
|
1487 |
const unsigned short bitMasks[16] =
|
|
1488 |
{
|
|
1489 |
0x1 << 0, 0x1 << 1, 0x1 << 2, 0x1 << 3, 0x1 << 4, 0x1 << 5, 0x1 << 6, 0x1 << 7,
|
|
1490 |
0x1 << 8, 0x1 << 9, 0x1 << 10, 0x1 << 11, 0x1 << 12, 0x1 << 13, 0x1 << 14, 0x1 << 15,
|
|
1491 |
};
|
|
1492 |
|
|
1493 |
inline void SetAddrBit(unsigned short * pW, unsigned char bitAddr)
|
|
1494 |
{
|
|
1495 |
(*pW) |= bitMasks[bitAddr & 0xf];
|
|
1496 |
}
|
|
1497 |
|
|
1498 |
inline void ResetBit(unsigned short * pW, unsigned char bitAddr)
|
|
1499 |
{
|
|
1500 |
(*pW) &= ~bitMasks[bitAddr & 0xf];
|
|
1501 |
}
|
|
1502 |
|
|
1503 |
static inline void SetBitValue(unsigned short * pW, unsigned char bitAddr, unsigned char Value)
|
|
1504 |
{
|
|
1505 |
if (Value) { SetAddrBit(pW, bitAddr); }
|
|
1506 |
else { ResetBit(pW, bitAddr); }
|
|
1507 |
}
|
|
1508 |
|
|
1509 |
static inline unsigned char GetBitValue(unsigned short W, unsigned char bitAddr)
|
|
1510 |
{
|
|
1511 |
if (W&bitMasks[bitAddr & 0xf]) return 1;
|
|
1512 |
else return 0;
|
|
1513 |
}
|
|
1514 |
|
|
1515 |
int CMTerm2Doc::GetCoilValue(int nCoilType, int nCoilAddr)
|
|
1516 |
{
|
|
1517 |
// TODO: 在此处添加实现代码.
|
|
1518 |
|
|
1519 |
if (m_bOnline && 0)
|
|
1520 |
{
|
|
1521 |
unsigned char value = 0;
|
|
1522 |
MyKLink1.ReadBit(1, nCoilType, nCoilAddr, &value);
|
|
1523 |
return value;
|
|
1524 |
}
|
|
1525 |
int nWordAddr = nCoilAddr >> 4;
|
|
1526 |
int nBitAddr = nCoilAddr & 0x0F;
|
|
1527 |
|
|
1528 |
switch (nCoilType)
|
|
1529 |
{
|
|
1530 |
case KLCoilTypeX:
|
|
1531 |
if (nCoilAddr >= KLCoilXCount) return 0;
|
|
1532 |
return GetBitValue(KMem.WX[nWordAddr], nBitAddr);
|
|
1533 |
break;
|
|
1534 |
case KLCoilTypeY:
|
|
1535 |
if (nCoilAddr >= KLCoilYCount) return 0;
|
|
1536 |
return GetBitValue(KMem.WY[nWordAddr], nBitAddr);
|
|
1537 |
break;
|
|
1538 |
case KLCoilTypeR:
|
|
1539 |
if (nCoilAddr >= KLCoilRCount) return 0;
|
|
1540 |
return GetBitValue(KMem.WR[nWordAddr], nBitAddr);
|
|
1541 |
break;
|
|
1542 |
case KLCoilTypeLX:
|
|
1543 |
if (nCoilAddr >= KLCoilLXCount) return 0;
|
|
1544 |
return GetBitValue(KMem.WLX[nWordAddr], nBitAddr);
|
|
1545 |
break;
|
|
1546 |
case KLCoilTypeLY:
|
|
1547 |
if (nCoilAddr >= KLCoilLYCount) return 0;
|
|
1548 |
return GetBitValue(KMem.WLY[nWordAddr], nBitAddr);
|
|
1549 |
break;
|
|
1550 |
case KLCoilTypeT:
|
|
1551 |
if (nCoilAddr >= KLCoilTCount) return 0;
|
|
1552 |
return GetBitValue(KMem.WT[nWordAddr], nBitAddr);
|
|
1553 |
break;
|
|
1554 |
case KLCoilTypeC:
|
|
1555 |
if (nCoilAddr >= KLCoilCCount) return 0;
|
|
1556 |
return GetBitValue(KMem.WC[nWordAddr], nBitAddr);
|
|
1557 |
break;
|
|
1558 |
case KLCoilTypeLR:
|
|
1559 |
if (nCoilAddr >= KLCoilLRCount) return 0;
|
|
1560 |
return GetBitValue(KMem.WLR[nWordAddr], nBitAddr);
|
|
1561 |
break;
|
|
1562 |
case KLCoilTypeSR:
|
|
1563 |
if (nCoilAddr >= KLCoilSRCount) return 0;
|
|
1564 |
return GetBitValue(KMem.WSR[nWordAddr], nBitAddr);
|
|
1565 |
break;
|
|
1566 |
}
|
|
1567 |
return 0;
|
|
1568 |
}
|
|
1569 |
|
|
1570 |
|
|
1571 |
int CMTerm2Doc::SetCoilValue(int nCoilType, int nCoilAddr, int nCoilValue)
|
|
1572 |
{
|
|
1573 |
// TODO: 在此处添加实现代码.
|
|
1574 |
if (m_bSimulate) {
|
|
1575 |
return myKMachine1.SetCoilValue(nCoilType, nCoilAddr, nCoilValue);
|
|
1576 |
}else
|
|
1577 |
if (m_bOnline)
|
|
1578 |
{
|
|
1579 |
unsigned char value =nCoilValue;
|
|
1580 |
int res = 0;
|
|
1581 |
res = MyKLink1.WriteBit(1, nCoilType, nCoilAddr, value);
|
|
1582 |
return res;
|
|
1583 |
}
|
|
1584 |
|
|
1585 |
int nWordAddr = nCoilAddr >> 4;
|
|
1586 |
int nBitAddr = nCoilAddr & 0x0F;
|
|
1587 |
|
|
1588 |
switch (nCoilType)
|
|
1589 |
{
|
|
1590 |
case KLCoilTypeX:
|
|
1591 |
if (nCoilAddr >= KLCoilXCount) return 0;
|
|
1592 |
SetBitValue(&KMem.WX[nWordAddr], nBitAddr, nCoilValue);
|
|
1593 |
break;
|
|
1594 |
case KLCoilTypeY:
|
|
1595 |
if (nCoilAddr >= KLCoilYCount) return 0;
|
|
1596 |
SetBitValue(&KMem.WY[nWordAddr], nBitAddr, nCoilValue);
|
|
1597 |
break;
|
|
1598 |
case KLCoilTypeR:
|
|
1599 |
if (nCoilAddr >= KLCoilRCount) return 0;
|
|
1600 |
SetBitValue(&KMem.WR[nWordAddr], nBitAddr, nCoilValue);
|
|
1601 |
break;
|
|
1602 |
case KLCoilTypeLX:
|
|
1603 |
if (nCoilAddr >= KLCoilLXCount) return 0;
|
|
1604 |
SetBitValue(&KMem.WLX[nWordAddr], nBitAddr, nCoilValue);
|
|
1605 |
break;
|
|
1606 |
case KLCoilTypeLY:
|
|
1607 |
if (nCoilAddr >= KLCoilLYCount) return 0;
|
|
1608 |
SetBitValue(&KMem.WLY[nWordAddr], nBitAddr, nCoilValue);
|
|
1609 |
break;
|
|
1610 |
case KLCoilTypeT:
|
|
1611 |
if (nCoilAddr >= KLCoilTCount) return 0;
|
|
1612 |
SetBitValue(&KMem.WT[nWordAddr], nBitAddr, nCoilValue);
|
|
1613 |
break;
|
|
1614 |
case KLCoilTypeC:
|
|
1615 |
if (nCoilAddr >= KLCoilCCount) return 0;
|
|
1616 |
SetBitValue(&KMem.WC[nWordAddr], nBitAddr, nCoilValue);
|
|
1617 |
break;
|
|
1618 |
case KLCoilTypeLR:
|
|
1619 |
if (nCoilAddr >= KLCoilLRCount) return 0;
|
|
1620 |
SetBitValue(&KMem.WLR[nWordAddr], nBitAddr, nCoilValue);
|
|
1621 |
break;
|
|
1622 |
case KLCoilTypeSR:
|
|
1623 |
if (nCoilAddr >= KLCoilSRCount) return 0;
|
|
1624 |
SetBitValue(&KMem.WSR[nWordAddr], nBitAddr, nCoilValue);
|
|
1625 |
|
|
1626 |
break;
|
|
1627 |
}
|
|
1628 |
if (m_bOnline)
|
|
1629 |
{
|
|
1630 |
// MyKLink1.WriteBit(1, nCoilType, nCoilAddr, nCoilValue);
|
|
1631 |
}
|
|
1632 |
return 0;
|
|
1633 |
}
|
|
1634 |
|
|
1635 |
int CMTerm2Doc::GetVarData(int nDataType, int nDataAddr)
|
|
1636 |
{
|
|
1637 |
// TODO: 在此处添加实现代码.
|
|
1638 |
if (m_bOnline && 0)
|
|
1639 |
{
|
|
1640 |
unsigned short value[20];
|
|
1641 |
unsigned short svalue = 0;
|
|
1642 |
if (nDataType == KLDataTypeDEC || nDataType == KLDataTypeHEX){
|
|
1643 |
return nDataAddr;
|
|
1644 |
}
|
|
1645 |
|
|
1646 |
MyKLink1.ReadDataWord(1, 2, nDataType, nDataAddr, value);// (unsigned char *)&KMem.DT[nDataAddr]);
|
|
1647 |
svalue = value[0];
|
|
1648 |
return svalue;
|
|
1649 |
}
|
|
1650 |
|
|
1651 |
switch (nDataType)
|
|
1652 |
{
|
|
1653 |
case KLDataTypeDEC:
|
|
1654 |
case KLDataTypeHEX:
|
|
1655 |
return nDataAddr;
|
|
1656 |
break;
|
|
1657 |
case KLDataTypeWX:
|
|
1658 |
if (nDataAddr >= KLDataWXCount) return 0;
|
|
1659 |
return KMem.WX[nDataAddr];
|
|
1660 |
break;
|
|
1661 |
case KLDataTypeWY:
|
|
1662 |
if (nDataAddr >= KLDataWYCount) return 0;
|
|
1663 |
return KMem.WY[nDataAddr];
|
|
1664 |
break;
|
|
1665 |
case KLDataTypeWR:
|
|
1666 |
if (nDataAddr >= KLDataWRCount) return 0;
|
|
1667 |
return KMem.WR[nDataAddr];
|
|
1668 |
break;
|
|
1669 |
case KLDataTypeWLX:
|
|
1670 |
if (nDataAddr >= KLDataWLCount) return 0;
|
|
1671 |
return KMem.WLX[nDataAddr];
|
|
1672 |
break;
|
|
1673 |
case KLDataTypeWLY:
|
|
1674 |
if (nDataAddr >= KLDataWLCount) return 0;
|
|
1675 |
return KMem.WLY[nDataAddr];
|
|
1676 |
break;
|
|
1677 |
case KLDataTypeDT:
|
|
1678 |
if (nDataAddr >= KLDataDTCount) return 0;
|
|
1679 |
return (signed short)KMem.DT[nDataAddr];
|
|
1680 |
break;
|
|
1681 |
case KLDataTypeSDT:
|
|
1682 |
if (nDataAddr >= KLDataSDTCount) return 0;
|
|
1683 |
return KMem.SDT[nDataAddr];
|
|
1684 |
break;
|
|
1685 |
case KLDataTypeWSR:
|
|
1686 |
if (nDataAddr >= KLCoilLRCount) return 0;
|
|
1687 |
return KMem.WSR[nDataAddr];
|
|
1688 |
break;
|
|
1689 |
case KLDataTypeSV:
|
|
1690 |
if (nDataAddr >= KLDataSVCount) return 0;
|
|
1691 |
return KMem.SV[nDataAddr];
|
|
1692 |
break;
|
|
1693 |
case KLDataTypeEV:
|
|
1694 |
if (nDataAddr >= KLDataEVCount) return 0;
|
|
1695 |
return KMem.EV[nDataAddr];
|
|
1696 |
break;
|
|
1697 |
case KLDataTypeLD:
|
|
1698 |
if (nDataAddr >= KLDataLDCount) return 0;
|
|
1699 |
return KMem.DT[nDataAddr];
|
|
1700 |
break;
|
|
1701 |
case KLDataSysCfg:
|
|
1702 |
if (nDataAddr >= KLCoilSRCount) return 0;
|
|
1703 |
return KMem.SDT[nDataAddr];
|
|
1704 |
break;
|
|
1705 |
case KLDataTypeFlash:
|
|
1706 |
if (nDataAddr >= KLCoilSRCount) return 0;
|
|
1707 |
return KMem.SDT[nDataAddr];
|
|
1708 |
break;
|
|
1709 |
case KLDataTypeTest:
|
|
1710 |
if (nDataAddr >= KLCoilSRCount) return 0;
|
|
1711 |
return KMem.SDT[nDataAddr];
|
|
1712 |
break;
|
|
1713 |
}
|
|
1714 |
return 0;
|
|
1715 |
}
|
|
1716 |
|
|
1717 |
|
|
1718 |
int CMTerm2Doc::SetVarData(int nDataType, int nDataAddr, int nDataValue)
|
|
1719 |
{
|
|
1720 |
// TODO: 在此处添加实现代码.
|
|
1721 |
|
|
1722 |
if (m_bSimulate) {
|
|
1723 |
return myKMachine1.SetVarData(nDataType, nDataAddr, nDataValue);
|
|
1724 |
}else
|
|
1725 |
if (m_bOnline)
|
|
1726 |
{
|
|
1727 |
// unsigned char value[20];
|
|
1728 |
unsigned short svalue[10];
|
|
1729 |
svalue[0]=nDataValue;
|
|
1730 |
int res = 0;
|
|
1731 |
res = MyKLink1.WriteDataWord(1, 2, nDataType, nDataAddr, svalue);
|
|
1732 |
return res;
|
|
1733 |
}
|
|
1734 |
|
|
1735 |
switch (nDataType)
|
|
1736 |
{
|
|
1737 |
// case KLDataTypeDEC:
|
|
1738 |
// case KLDataTypeHEX:
|
|
1739 |
// break;
|
|
1740 |
case KLDataTypeWX:
|
|
1741 |
if (nDataAddr >= KLDataWXCount) return 0;
|
|
1742 |
KMem.WX[nDataAddr] = nDataValue;
|
|
1743 |
break;
|
|
1744 |
case KLDataTypeWY:
|
|
1745 |
if (nDataAddr >= KLDataWYCount) return 0;
|
|
1746 |
KMem.WY[nDataAddr] = nDataValue;
|
|
1747 |
break;
|
|
1748 |
case KLDataTypeWR:
|
|
1749 |
if (nDataAddr >= KLDataWRCount) return 0;
|
|
1750 |
KMem.WR[nDataAddr] = nDataValue;
|
|
1751 |
break;
|
|
1752 |
case KLDataTypeWLX:
|
|
1753 |
if (nDataAddr >= KLDataWLCount) return 0;
|
|
1754 |
KMem.WLX[nDataAddr] = nDataValue;
|
|
1755 |
break;
|
|
1756 |
case KLDataTypeWLY:
|
|
1757 |
if (nDataAddr >= KLDataWLCount) return 0;
|
|
1758 |
KMem.WLY[nDataAddr] = nDataValue;
|
|
1759 |
break;
|
|
1760 |
case KLDataTypeDT:
|
|
1761 |
if (nDataAddr >= KLDataDTCount) return 0;
|
|
1762 |
KMem.DT[nDataAddr] = nDataValue;
|
|
1763 |
break;
|
|
1764 |
case KLDataTypeSDT:
|
|
1765 |
if (nDataAddr >= KLDataSDTCount) return 0;
|
|
1766 |
KMem.SDT[nDataAddr] = nDataValue;
|
|
1767 |
break;
|
|
1768 |
case KLDataTypeWSR:
|
|
1769 |
if (nDataAddr >= KLCoilLRCount) return 0;
|
|
1770 |
KMem.WSR[nDataAddr] = nDataValue;
|
|
1771 |
break;
|
|
1772 |
case KLDataTypeSV:
|
|
1773 |
if (nDataAddr >= KLDataSVCount) return 0;
|
|
1774 |
KMem.SV[nDataAddr] = nDataValue;
|
|
1775 |
break;
|
|
1776 |
case KLDataTypeEV:
|
|
1777 |
if (nDataAddr >= KLDataEVCount) return 0;
|
|
1778 |
KMem.EV[nDataAddr] = nDataValue;
|
|
1779 |
break;
|
|
1780 |
case KLDataTypeLD:
|
|
1781 |
if (nDataAddr >= KLDataLDCount) return 0;
|
|
1782 |
KMem.DT[nDataAddr] = nDataValue;
|
|
1783 |
break;
|
|
1784 |
case KLDataSysCfg:
|
|
1785 |
if (nDataAddr >= KLCoilSRCount) return 0;
|
|
1786 |
KMem.SDT[nDataAddr] = nDataValue;
|
|
1787 |
break;
|
|
1788 |
case KLDataTypeFlash:
|
|
1789 |
if (nDataAddr >= KLCoilSRCount) return 0;
|
|
1790 |
KMem.SDT[nDataAddr] = nDataValue;
|
|
1791 |
break;
|
|
1792 |
case KLDataTypeTest:
|
|
1793 |
if (nDataAddr >= KLCoilSRCount) return 0;
|
|
1794 |
KMem.SDT[nDataAddr] = nDataValue;
|
|
1795 |
break;
|
|
1796 |
}
|
|
1797 |
|
|
1798 |
return 0;
|
|
1799 |
}
|
|
1800 |
|
|
1801 |
|
|
1802 |
|
|
1803 |
int CMTerm2Doc::AddMonitorCoil(int nCoilType, int nCoilAddr, int nCount)
|
|
1804 |
{
|
|
1805 |
// TODO: 在此处添加实现代码.
|
|
1806 |
return 0;
|
|
1807 |
}
|
|
1808 |
|
|
1809 |
|
|
1810 |
int CMTerm2Doc::AddMonitorData(int nDataType, int nDataAddr, int nDataCount)
|
|
1811 |
{
|
|
1812 |
// TODO: 在此处添加实现代码.
|
|
1813 |
return 0;
|
|
1814 |
}
|
|
1815 |
|
|
1816 |
|
|
1817 |
int CMTerm2Doc::ClearMonitor()
|
|
1818 |
{
|
|
1819 |
// TODO: 在此处添加实现代码.
|
|
1820 |
return 0;
|
|
1821 |
}
|
|
1822 |
|
|
1823 |
|
|
1824 |
int CMTerm2Doc::DoPLCMonitor()
|
|
1825 |
{
|
|
1826 |
// TODO: 在此处添加实现代码.
|
|
1827 |
if (m_bSimulate) {
|
|
1828 |
int nDataType = MyKLink1.KLDataTypeWX;
|
|
1829 |
int nDataAddr = 0;
|
|
1830 |
int nDataCount = 4;
|
|
1831 |
int res;
|
|
1832 |
for (int i = 0; i < nDataCount; i++) {
|
|
1833 |
KMem.WX[i] = myKMachine1.KMem.WX[i];
|
|
1834 |
}
|
|
1835 |
|
|
1836 |
nDataType = MyKLink1.KLDataTypeWY;
|
|
1837 |
nDataAddr = 0;
|
|
1838 |
nDataCount = 4;
|
|
1839 |
for (int i = 0; i < nDataCount; i++) {
|
|
1840 |
KMem.WY[i] = myKMachine1.KMem.WY[i];
|
|
1841 |
}
|
|
1842 |
|
|
1843 |
nDataType = MyKLink1.KLDataTypeWR;
|
|
1844 |
nDataAddr = 0;
|
|
1845 |
nDataCount = 10;
|
|
1846 |
for (int i = 0; i < nDataCount; i++) {
|
|
1847 |
KMem.WR[i] = myKMachine1.KMem.WR[i];
|
|
1848 |
}
|
|
1849 |
|
|
1850 |
nDataType = MyKLink1.KLDataTypeDT;
|
|
1851 |
nDataAddr = 0;
|
|
1852 |
nDataCount = 80;
|
|
1853 |
for (int i = 0; i < nDataCount; i++) {
|
|
1854 |
KMem.DT[i] = myKMachine1.KMem.DT[i];
|
|
1855 |
}
|
|
1856 |
|
|
1857 |
nDataType = MyKLink1.KLDataTypeSV;
|
|
1858 |
nDataAddr = 0;
|
|
1859 |
nDataCount = 40;
|
|
1860 |
for (int i = 0; i < nDataCount; i++) {
|
|
1861 |
KMem.SV[i] = myKMachine1.KMem.SV[i];
|
|
1862 |
}
|
|
1863 |
|
|
1864 |
//res = MyKLink1.ReadDataWord(1, nDataCount, nDataType, nDataAddr, KMem.SV);// (unsigned char *)&KMem.DT[nDataAddr]);
|
|
1865 |
|
|
1866 |
nDataType = MyKLink1.KLDataTypeEV;
|
|
1867 |
nDataAddr = 0;
|
|
1868 |
nDataCount = 40;
|
|
1869 |
for (int i = 0; i < nDataCount; i++) {
|
|
1870 |
KMem.EV[i] = myKMachine1.KMem.EV[i];
|
|
1871 |
}
|
|
1872 |
|
|
1873 |
// res = MyKLink1.ReadDataWord(1, nDataCount, nDataType, nDataAddr, KMem.EV);// (unsigned char *)&KMem.DT[nDataAddr]);
|
|
1874 |
|
|
1875 |
}else if (m_bOnline)
|
|
1876 |
{
|
|
1877 |
int nDataType = MyKLink1.KLDataTypeWX;
|
|
1878 |
int nDataAddr = 0;
|
|
1879 |
int nDataCount = 4;
|
|
1880 |
int res;
|
|
1881 |
res = MyKLink1.ReadDataWord(1, nDataCount, nDataType, nDataAddr, KMem.WX);// (unsigned char *)&KMem.DT[nDataAddr]);
|
|
1882 |
|
|
1883 |
nDataType = MyKLink1.KLDataTypeWY;
|
|
1884 |
nDataAddr = 0;
|
|
1885 |
nDataCount = 4;
|
|
1886 |
res = MyKLink1.ReadDataWord(1, nDataCount, nDataType, nDataAddr, KMem.WY);// (unsigned char *)&KMem.DT[nDataAddr]);
|
|
1887 |
|
|
1888 |
nDataType = MyKLink1.KLDataTypeWR;
|
|
1889 |
nDataAddr = 0;
|
|
1890 |
nDataCount = 10;
|
|
1891 |
res = MyKLink1.ReadDataWord(1, nDataCount, nDataType, nDataAddr, KMem.WR);// (unsigned char *)&KMem.DT[nDataAddr]);
|
|
1892 |
|
|
1893 |
nDataType = MyKLink1.KLDataTypeDT;
|
|
1894 |
nDataAddr = 0;
|
|
1895 |
nDataCount = 80;
|
|
1896 |
res = MyKLink1.ReadDataWord(1, nDataCount, nDataType, nDataAddr, KMem.DT);// (unsigned char *)&KMem.DT[nDataAddr]);
|
|
1897 |
|
|
1898 |
nDataType = MyKLink1.KLDataTypeSV;
|
|
1899 |
nDataAddr = 0;
|
|
1900 |
nDataCount = 40;
|
|
1901 |
res = MyKLink1.ReadDataWord(1, nDataCount, nDataType, nDataAddr, KMem.SV);// (unsigned char *)&KMem.DT[nDataAddr]);
|
|
1902 |
|
|
1903 |
nDataType = MyKLink1.KLDataTypeEV;
|
|
1904 |
nDataAddr = 0;
|
|
1905 |
nDataCount = 40;
|
|
1906 |
res = MyKLink1.ReadDataWord(1, nDataCount, nDataType, nDataAddr, KMem.EV);// (unsigned char *)&KMem.DT[nDataAddr]);
|
|
1907 |
|
|
1908 |
}
|
|
1909 |
|
|
1910 |
return 0;
|
|
1911 |
}
|
|
1912 |
|
|
1913 |
void CMTerm2Doc::OnTimer(UINT_PTR nIDEvent)
|
|
1914 |
{
|
|
1915 |
if (m_bSimulate && m_bPlcRunning)
|
|
1916 |
{
|
|
1917 |
//ProcessPLCProg(Progs, m_nProgSteps);
|
|
1918 |
myKMachine1.ProcPLC();
|
|
1919 |
|
|
1920 |
// update PLC Stat
|
|
1921 |
|
|
1922 |
}
|
|
1923 |
}
|