提交 | 用户 | age
|
418cb3
|
1 |
// MTerm1CtrlView.cpp: 实现文件
|
Q |
2 |
//
|
|
3 |
|
|
4 |
|
|
5 |
// MultiTerminal1Dlg.cpp: 实现文件
|
|
6 |
//
|
|
7 |
|
|
8 |
#include "pch.h"
|
|
9 |
#include "framework.h"
|
|
10 |
#include "MTerm1.h"
|
|
11 |
#include "MTerm1Doc.h"
|
|
12 |
#include "ChildFrm.h"
|
|
13 |
|
|
14 |
#include "MTerm1CommDevView.h"
|
|
15 |
|
|
16 |
#include <devguid.h>
|
|
17 |
#include <SetupAPI.h>
|
|
18 |
#include "../MyLib/Functions.hpp"
|
|
19 |
#include "../MyLib/UI_Func/UI_Func.hpp"
|
|
20 |
#include "AnsiParser.h"
|
|
21 |
#include "DataParser1.h"
|
|
22 |
//#include "KLink.h"
|
|
23 |
//#include "../MyLib/SerialCom/SerialCom.hpp"
|
|
24 |
#include <Dbt.h>
|
|
25 |
#include "DialogCommSet1.h"
|
|
26 |
#include "DialogSysRegSet.h"
|
|
27 |
#include "DialogStatusShow.h"
|
|
28 |
#include "DialogInfoDisplay.h"
|
|
29 |
|
|
30 |
#include "DialogCoilMon.h"
|
|
31 |
#include "DialogDataMon.h"
|
|
32 |
|
|
33 |
#include "DialogProgress.h"
|
|
34 |
#include "DialogEventLog.h"
|
|
35 |
#include "DialogDateTime.h"
|
|
36 |
#include "DialogForceIO.h"
|
|
37 |
//#include "HvSerialPort.h"
|
|
38 |
|
|
39 |
#ifdef _DEBUG
|
|
40 |
#define new DEBUG_NEW
|
|
41 |
#endif
|
|
42 |
|
|
43 |
//#pragma comment(lib,"setupapi.lib")
|
|
44 |
bool bAutoStart;
|
|
45 |
//int nComPort;
|
|
46 |
//int nBaud;
|
|
47 |
|
|
48 |
stCfgValCtrl myCfgValCtrls[] = {
|
|
49 |
"AutoStart", vtbool, &bAutoStart, IDC_CHECK_AUTO_START, ctCheckBox,
|
|
50 |
// "LastComPort", vtInt, &nComPort, IDC_COMBO_COMPORT, ctComboBoxIndex,
|
|
51 |
// "Baud", vtInt, &nBaud, IDC_COMBO_COM_BAUD, ctComboBoxString,
|
|
52 |
"Ref1", NULL, nullptr, IDC_EDIT_REF1, ctEdit,
|
|
53 |
};
|
|
54 |
|
|
55 |
|
|
56 |
int nMarkConfigs = sizeof(myCfgValCtrls) / sizeof(stCfgValCtrl);
|
|
57 |
|
|
58 |
int nTest1 = 1;
|
|
59 |
float nTest2 = 2;
|
|
60 |
double nTest3 = 3;
|
|
61 |
|
|
62 |
int MonitorTotalCount = 0;
|
|
63 |
int MonitorSuccessCount = 0;
|
|
64 |
int MonitorFailCount = 0;
|
|
65 |
int MonitorSpeed = 0;
|
|
66 |
int LastMonitorTotalCount = 0;
|
|
67 |
|
|
68 |
stCfgValCtrl myCfgTest1[] = {
|
|
69 |
"Test1", vtInt, &nTest1, 0,0,
|
|
70 |
"Test2", vtFloat, &nTest2, 0,0,
|
|
71 |
"Test3", vtDouble, &nTest3, 0,0,
|
|
72 |
};
|
|
73 |
int nCfgTestCount = sizeof(myCfgTest1) / sizeof(stCfgValCtrl);
|
|
74 |
|
|
75 |
unsigned char send1[40000];
|
|
76 |
unsigned char recv1[40000];
|
|
77 |
|
|
78 |
volatile int nDataToSend = 0;
|
|
79 |
|
|
80 |
volatile int BulkSendTest = 0;
|
|
81 |
|
|
82 |
unsigned char SDTbuf[512];
|
|
83 |
unsigned char WYbuf[256];
|
|
84 |
|
|
85 |
unsigned char WDTbuf[512];
|
|
86 |
|
|
87 |
// CMTerm1CommDevView
|
|
88 |
|
|
89 |
IMPLEMENT_DYNCREATE(CMTerm1CommDevView, CFormView)
|
|
90 |
|
|
91 |
CMTerm1CommDevView::CMTerm1CommDevView()
|
|
92 |
: CFormView(IDD_MTerm1CommDevView2)
|
|
93 |
{
|
|
94 |
|
|
95 |
}
|
|
96 |
|
|
97 |
CMTerm1CommDevView::~CMTerm1CommDevView()
|
|
98 |
{
|
|
99 |
}
|
|
100 |
|
|
101 |
void CMTerm1CommDevView::DoDataExchange(CDataExchange* pDX)
|
|
102 |
{
|
|
103 |
CFormView::DoDataExchange(pDX);
|
|
104 |
DDX_Control(pDX, IDC_COMBO_COMPORT, m_combo_comport);
|
|
105 |
DDX_Control(pDX, IDC_COMBO_COM_BAUD, m_combo_com_baud);
|
|
106 |
DDX_Control(pDX, IDC_EDIT_DISPLAY, m_edit_display);
|
|
107 |
DDX_Control(pDX, IDC_COMBO_INPUT, m_combo_input);
|
|
108 |
// DDX_Control(pDX, IDC_TREE1, m_treectrl1);
|
|
109 |
DDX_Control(pDX, IDC_EDIT_MON, m_edit_mon1);
|
|
110 |
DDX_Control(pDX, IDC_EDIT_MON2, m_edit_mon2);
|
|
111 |
DDX_Control(pDX, IDC_STATIC_CONNECT, m_static_connect);
|
|
112 |
|
|
113 |
}
|
|
114 |
|
|
115 |
BEGIN_MESSAGE_MAP(CMTerm1CommDevView, CFormView)
|
|
116 |
|
|
117 |
// ON_WM_SYSCOMMAND()
|
|
118 |
// ON_WM_PAINT()
|
|
119 |
// ON_WM_CLOSE()
|
|
120 |
// ON_WM_SIZE()
|
|
121 |
ON_WM_TIMER()
|
|
122 |
ON_BN_CLICKED(IDC_BUTTON_CONNECT, &CMTerm1CommDevView::OnBnClickedButtonConnect)
|
|
123 |
ON_BN_CLICKED(IDC_BUTTON_DISCONNECT, &CMTerm1CommDevView::OnBnClickedButtonDisconnect)
|
|
124 |
ON_BN_CLICKED(IDC_BUTTON_START, &CMTerm1CommDevView::OnBnClickedButtonStart)
|
|
125 |
ON_BN_CLICKED(IDC_BUTTON_STOP, &CMTerm1CommDevView::OnBnClickedButtonStop)
|
|
126 |
|
|
127 |
ON_BN_CLICKED(IDC_BUTTON_CLRSCR, &CMTerm1CommDevView::OnBnClickedButtonClrscr)
|
|
128 |
ON_BN_CLICKED(IDC_BUTTON_SEND, &CMTerm1CommDevView::OnBnClickedButtonSend)
|
|
129 |
// ON_CBN_EDITCHANGE(IDC_COMBO_INPUT, &CMTerm1CommDevView::OnCbnEditchangeComboInput)
|
|
130 |
// ON_CBN_SELCHANGE(IDC_COMBO_RES, &CMTerm1CommDevView::OnCbnSelchangeComboRes)
|
|
131 |
ON_BN_CLICKED(IDC_BUTTON_DO, &CMTerm1CommDevView::OnBnClickedButtonDo)
|
|
132 |
// ON_CBN_SELCHANGE(IDC_COMBO_CMD_TYPE, &CMTerm1CommDevView::OnCbnSelchangeComboCmdType)
|
|
133 |
// ON_CBN_SELCHANGE(IDC_COMBO_DCOUNT, &CMTerm1CommDevView::OnCbnSelchangeComboDcount)
|
|
134 |
// ON_BN_CLICKED(IDC_BUTTON_START_BULK_TEST, &CMTerm1CommDevView::OnBnClickedButtonStartBulkTest)
|
|
135 |
// ON_BN_CLICKED(IDC_BUTTON_STOP_BULK_TEST, &CMTerm1CommDevView::OnBnClickedButtonStopBulkTest)
|
|
136 |
// ON_WM_DEVICECHANGE()
|
|
137 |
// ON_WM_INITMENUPOPUP()
|
|
138 |
// ON_WM_MOUSEWHEEL()
|
|
139 |
// ON_BN_CLICKED(IDC_BUTTON_CLEAR_STAT, &CMTerm1CommDevView::OnBnClickedButtonClearStat)
|
|
140 |
// ON_BN_CLICKED(IDC_BUTTON_READ, &CMTerm1CommDevView::OnBnClickedButtonRead)
|
|
141 |
// ON_BN_CLICKED(IDC_BUTTON11, &CMTerm1CommDevView::OnBnClickedButton11)
|
|
142 |
ON_BN_CLICKED(IDC_BUTTON12, &CMTerm1CommDevView::OnBnClickedButton12)
|
|
143 |
ON_BN_CLICKED(IDC_BUTTON13, &CMTerm1CommDevView::OnBnClickedButton13)
|
|
144 |
ON_BN_CLICKED(IDC_BUTTON31, &CMTerm1CommDevView::OnBnClickedButton31)
|
|
145 |
ON_BN_CLICKED(IDC_BUTTON2, &CMTerm1CommDevView::OnBnClickedButton2)
|
|
146 |
ON_BN_CLICKED(IDC_BUTTON3, &CMTerm1CommDevView::OnBnClickedButton3)
|
|
147 |
END_MESSAGE_MAP()
|
|
148 |
|
|
149 |
|
|
150 |
// CMTerm1CommDevView 诊断
|
|
151 |
|
|
152 |
#ifdef _DEBUG
|
|
153 |
void CMTerm1CommDevView::AssertValid() const
|
|
154 |
{
|
|
155 |
CFormView::AssertValid();
|
|
156 |
}
|
|
157 |
|
|
158 |
#ifndef _WIN32_WCE
|
|
159 |
void CMTerm1CommDevView::Dump(CDumpContext& dc) const
|
|
160 |
{
|
|
161 |
CFormView::Dump(dc);
|
|
162 |
}
|
|
163 |
#endif
|
|
164 |
#endif //_DEBUG
|
|
165 |
|
|
166 |
|
|
167 |
// CMTerm1CommDevView 消息处理程序
|
|
168 |
|
|
169 |
void CMTerm1CommDevView::OnInitialUpdate()
|
|
170 |
{
|
|
171 |
CFormView::OnInitialUpdate();
|
|
172 |
// TODO: 在此添加专用代码和/或调用基类
|
|
173 |
// ResizeParentToFit();
|
|
174 |
// ((CChildFrame *)GetParentFrame())->RecalcLayout();
|
|
175 |
m_pStatusBar = ((CChildFrame *)GetParentFrame())->GetStatusBar();
|
|
176 |
|
|
177 |
m_bResourceOpened = 0;
|
|
178 |
|
|
179 |
LoadResourceList();
|
|
180 |
DisplayParams();
|
|
181 |
|
|
182 |
LoadModel();
|
|
183 |
/*
|
|
184 |
// m_treectrl1.SetExtendedStyle(TVS_EX_DRAWIMAGEASYNC,TVS_EX_DRAWIMAGEASYNC);
|
|
185 |
m_ColorTreeImages.Create(IDB_FILE_VIEW, 16, 0, RGB(255, 0, 255));
|
|
186 |
// m_ColorTreeImages.Create(IDB_PNG1,220,0,RGB(255,0,255));
|
|
187 |
|
|
188 |
m_treectrl1.SetImageList(&m_ColorTreeImages, TVSIL_NORMAL);
|
|
189 |
|
|
190 |
HTREEITEM hItem, hGroupItem, hSubItem;
|
|
191 |
hItem = m_treectrl1.InsertItem(_T("Parent1"), 0, 0, TVI_ROOT); // 在根结点上添加Parent1
|
|
192 |
hGroupItem = m_treectrl1.InsertItem(_T("Group1_1"), 1, 1, hItem);//在Parent1上添加一个子结点
|
|
193 |
|
|
194 |
hSubItem = m_treectrl1.InsertItem(_T("Child1_1"), 2, 2, hGroupItem);//在Parent1上添加一个子结点
|
|
195 |
hSubItem = m_treectrl1.InsertItem(_T("Child1_2"), 2, 2, hGroupItem, hSubItem);//在Parent1上添加一个子结点,排在Child1_1后面
|
|
196 |
hSubItem = m_treectrl1.InsertItem(_T("Child1_3"), 2, 2, hGroupItem, hSubItem);
|
|
197 |
|
|
198 |
hGroupItem = m_treectrl1.InsertItem(_T("Group1_2"), 1, 1, hItem, hGroupItem);//在Parent1上添加一个子结点
|
|
199 |
hSubItem = m_treectrl1.InsertItem(_T("Child1_4"), 2, 2, hGroupItem);//在Parent1上添加一个子结点
|
|
200 |
hSubItem = m_treectrl1.InsertItem(_T("Child1_5"), 2, 2, hGroupItem, hSubItem);//在Parent1上添加一个子结点,排在Child1_1后面
|
|
201 |
hSubItem = m_treectrl1.InsertItem(_T("Child1_6"), 2, 2, hGroupItem, hSubItem);
|
|
202 |
|
|
203 |
hItem = m_treectrl1.InsertItem(_T("Parent2"), TVI_ROOT, hItem);
|
|
204 |
hGroupItem = m_treectrl1.InsertItem(_T("Group2_1"), 1, 1, hItem);//在Parent1上添加一个子结点
|
|
205 |
|
|
206 |
hSubItem = m_treectrl1.InsertItem(_T("Child2_1"), 2, 2, hGroupItem);//在Parent1上添加一个子结点
|
|
207 |
hSubItem = m_treectrl1.InsertItem(_T("Child2_2"), 2, 2, hGroupItem, hSubItem);//在Parent1上添加一个子结点,排在Child1_1后面
|
|
208 |
hSubItem = m_treectrl1.InsertItem(_T("Child2_3"), 2, 2, hGroupItem, hSubItem);
|
|
209 |
|
|
210 |
hGroupItem = m_treectrl1.InsertItem(_T("Group2_2"), 1, 1, hItem, hGroupItem);//在Parent1上添加一个子结点
|
|
211 |
hSubItem = m_treectrl1.InsertItem(_T("Child2_4"), 2, 2, hGroupItem);//在Parent1上添加一个子结点
|
|
212 |
hSubItem = m_treectrl1.InsertItem(_T("Child2_5"), 2, 2, hGroupItem, hSubItem);//在Parent1上添加一个子结点,排在Child1_1后面
|
|
213 |
hSubItem = m_treectrl1.InsertItem(_T("Child2_6"), 2, 2, hGroupItem, hSubItem);
|
|
214 |
|
|
215 |
hItem = m_treectrl1.InsertItem(_T("Parent3"), TVI_ROOT, hItem);
|
|
216 |
hGroupItem = m_treectrl1.InsertItem(_T("Group3_1"), 1, 1, hItem);//在Parent1上添加一个子结点
|
|
217 |
|
|
218 |
hSubItem = m_treectrl1.InsertItem(_T("Child3_1"), 2, 2, hGroupItem);//在Parent1上添加一个子结点
|
|
219 |
hSubItem = m_treectrl1.InsertItem(_T("Child3_2"), 2, 2, hGroupItem, hSubItem);//在Parent1上添加一个子结点,排在Child1_1后面
|
|
220 |
hSubItem = m_treectrl1.InsertItem(_T("Child3_3"), 2, 2, hGroupItem, hSubItem);
|
|
221 |
|
|
222 |
hGroupItem = m_treectrl1.InsertItem(_T("Group3_2"), 1, 1, hItem, hGroupItem);//在Parent1上添加一个子结点
|
|
223 |
hSubItem = m_treectrl1.InsertItem(_T("Child3_4"), 2, 2, hGroupItem);//在Parent1上添加一个子结点
|
|
224 |
hSubItem = m_treectrl1.InsertItem(_T("Child3_5"), 2, 2, hGroupItem, hSubItem);//在Parent1上添加一个子结点,排在Child1_1后面
|
|
225 |
hSubItem = m_treectrl1.InsertItem(_T("Child3_6"), 2, 2, hGroupItem, hSubItem);
|
|
226 |
*/
|
|
227 |
// TVINSERTSTRUCT TVI_ROOT
|
|
228 |
// m_treectrl1.SetItemData(htree15,15);
|
|
229 |
|
|
230 |
// m_status_Cusp_Size.SetCtlColor(RGB(0xff, 0x40, 0x40));
|
|
231 |
// m_status_Hz.SetCtlColor(RGB(0xff, 0x40, 0x40));
|
|
232 |
// m_status_db.SetCtlColor(RGB(0xff, 0x40, 0x40));
|
|
233 |
|
|
234 |
SetTimer(0, 50, NULL);//delayinit
|
|
235 |
SetTimer(2, 100, NULL);//display
|
|
236 |
|
|
237 |
m_static_connect.SetCtlColor(RGB(0, 255, 0));
|
|
238 |
|
|
239 |
}
|
|
240 |
|
|
241 |
|
|
242 |
|
|
243 |
int CMTerm1CommDevView::DelayInit()
|
|
244 |
{
|
|
245 |
// InitCamera();
|
|
246 |
// InitPlcComm();
|
|
247 |
// InitAnalyzer();
|
|
248 |
SetTimer(1, 20, NULL); //plc
|
|
249 |
SetTimer(3, 300, NULL); //Analyzer
|
|
250 |
SetTimer(4, 1000, NULL); //Speed;
|
|
251 |
m_static_connect.SetCtlColor(RGB(255, 0, 0));
|
|
252 |
// m_static_connect.RedrawWindow();
|
|
253 |
return 0;
|
|
254 |
}
|
|
255 |
|
|
256 |
int CMTerm1CommDevView::Clear_COM_Stats()
|
|
257 |
{
|
|
258 |
// TODO: 在此处添加实现代码.
|
|
259 |
CMTerm1Doc *pDoc = (CMTerm1Doc *)GetDocument();
|
|
260 |
pDoc->MyKLink1.MySerPort1.TotalSendBytes = 0;
|
|
261 |
pDoc->MyKLink1.MySerPort1.TotalRecvBytes = 0;
|
|
262 |
|
|
263 |
MonitorTotalCount = 0;
|
|
264 |
MonitorSuccessCount = 0;
|
|
265 |
MonitorFailCount = 0;
|
|
266 |
return 0;
|
|
267 |
}
|
|
268 |
|
|
269 |
int CMTerm1CommDevView::UpdateDataDisplay()
|
|
270 |
{
|
|
271 |
CMTerm1Doc *pDoc = (CMTerm1Doc *)GetDocument();
|
|
272 |
if (!m_bOnline) return 0;
|
|
273 |
static int stepCount = 0;
|
|
274 |
CString s1, s2;
|
|
275 |
pDoc->MyKLink1.MySerPort1.CalSpeed();
|
|
276 |
s1.Format(_T("Send %8d %5d Bps \r\nRecv %8d %5d Bps\r\n"), pDoc->MyKLink1.MySerPort1.TotalSendBytes, pDoc->MyKLink1.MySerPort1.SendSpeed, pDoc->MyKLink1.MySerPort1.TotalRecvBytes, pDoc->MyKLink1.MySerPort1.RecvSpeed);
|
|
277 |
|
|
278 |
// s1.AppendFormat(_T("Total S %8d \r\nTotal R %8d \r\n"), MySerialCom1.TotalSendBytes, MySerialCom1.TotalRecvBytes);
|
|
279 |
s1 += intToString(pDoc->MyKLink1.MySerPort1.TotalRecvBytes) + _T("\r\n");
|
|
280 |
// stepCount++;
|
|
281 |
|
|
282 |
// static double LastCalTime = 0;
|
|
283 |
// double thisTime = GetTimemS();
|
|
284 |
pDoc->MyKLink1.CalSpeed();
|
|
285 |
/*
|
|
286 |
if (thisTime - LastCalTime > 500)
|
|
287 |
{
|
|
288 |
MonitorSpeed = int ((MonitorTotalCount - LastMonitorTotalCount) * 1000 / (thisTime - LastCalTime));
|
|
289 |
LastMonitorTotalCount = MonitorTotalCount;
|
|
290 |
LastCalTime = thisTime;
|
|
291 |
// stepCount = 0;
|
|
292 |
}
|
|
293 |
*/
|
|
294 |
s1.AppendFormat(_T("MT %6d Seq %d/%d %d/S \r\nOK %6d NG %d "),
|
|
295 |
pDoc->MyKLink1.m_nTotalSendCount, pDoc->MyKLink1.m_nSeq, pDoc->MyKLink1.m_nRSeq, pDoc->MyKLink1.m_SendSpeed,
|
|
296 |
pDoc->MyKLink1.m_nTotalRecvCount, pDoc->MyKLink1.m_nTotalSendCount-pDoc->MyKLink1.m_nTotalRecvCount);
|
|
297 |
SetDlgItemText(IDC_STATIC_SPEED, s1);
|
|
298 |
|
|
299 |
|
|
300 |
int nCount = 32;
|
|
301 |
s2.Empty();// s2.AppendFormat(_T("%d "), MonitorSuccessCount);
|
|
302 |
nCount = 16;
|
|
303 |
s2.Append(_T("WX "));
|
|
304 |
for (int i = 0; i < (nCount + 15) / 16; i++)
|
|
305 |
{
|
|
306 |
//s2.AppendFormat(_T("%02X: "), i * 16);
|
|
307 |
for (int j = 0; j < 8; j++)
|
|
308 |
{
|
|
309 |
s2.AppendFormat(_T("%04X"), pDoc->MyKLink1.MEM.WX[i * 8 + j]);
|
|
310 |
if (j == 3) { s2.Append(_T(" ")); }
|
|
311 |
else { s2.Append(_T(" ")); }
|
|
312 |
}
|
|
313 |
s2.Append(_T("\r\n"));
|
|
314 |
}
|
|
315 |
nCount = 16;
|
|
316 |
s2.Append(_T("WY "));
|
|
317 |
for (int i = 0; i < (nCount + 15) / 16; i++)
|
|
318 |
{
|
|
319 |
// s2.AppendFormat(_T("%02X: "), i * 16);
|
|
320 |
for (int j = 0; j < 8; j++)
|
|
321 |
{
|
|
322 |
s2.AppendFormat(_T("%04X"), pDoc->MyKLink1.MEM.WY[i * 8 + j]);
|
|
323 |
if (j == 3) { s2.Append(_T(" ")); }
|
|
324 |
else { s2.Append(_T(" ")); }
|
|
325 |
}
|
|
326 |
s2.Append(_T("\r\n"));
|
|
327 |
}
|
|
328 |
nCount = 32;
|
|
329 |
s2.Append(_T(" WR\r\n"));
|
|
330 |
for (int i = 0; i < (nCount + 15) / 16; i++)
|
|
331 |
{
|
|
332 |
s2.AppendFormat(_T("%02X: "), i * 16);
|
|
333 |
for (int j = 0; j < 8; j++)
|
|
334 |
{
|
|
335 |
s2.AppendFormat(_T("%04X"), pDoc->MyKLink1.MEM.WR[i * 8 + j]);
|
|
336 |
if (j == 3) { s2.Append(_T(" ")); }
|
|
337 |
else { s2.Append(_T(" ")); }
|
|
338 |
}
|
|
339 |
s2.Append(_T("\r\n"));
|
|
340 |
}
|
|
341 |
nCount = 96;
|
|
342 |
s2.Append(_T(" DT\r\n"));
|
|
343 |
for (int i = 0; i < (nCount + 15) / 16; i++)
|
|
344 |
{
|
|
345 |
s2.AppendFormat(_T("%02X: "), i * 16);
|
|
346 |
for (int j = 0; j < 8; j++)
|
|
347 |
{
|
|
348 |
s2.AppendFormat(_T("%04X"), pDoc->MyKLink1.MEM.DT[i * 8 + j]);
|
|
349 |
if (j == 3) { s2.Append(_T(" ")); }
|
|
350 |
else { s2.Append(_T(" ")); }
|
|
351 |
}
|
|
352 |
s2.Append(_T("\r\n"));
|
|
353 |
}
|
|
354 |
nCount = 256;
|
|
355 |
s2.Append(_T(" SDT\r\n"));
|
|
356 |
for (int i = 0; i < (nCount + 15) / 16; i++)
|
|
357 |
{
|
|
358 |
s2.AppendFormat(_T("%3X: "), i * 16);
|
|
359 |
for (int j = 0; j < 8; j++)
|
|
360 |
{
|
|
361 |
s2.AppendFormat(_T("%04X"), pDoc->MyKLink1.MEM.SDT[i * 8 + j]);
|
|
362 |
if (j == 3) { s2.Append(_T(" ")); }
|
|
363 |
else { s2.Append(_T(" ")); }
|
|
364 |
}
|
|
365 |
s2.Append(_T("\r\n"));
|
|
366 |
}
|
|
367 |
if (m_bMonitoring) {
|
|
368 |
SetDlgItemText(IDC_EDIT_MON, s2);
|
|
369 |
}
|
|
370 |
|
|
371 |
s2.Empty();
|
|
372 |
nCount = 256;
|
|
373 |
for (int i = 0; i < (nCount + 15) / 16; i++)
|
|
374 |
{
|
|
375 |
s2.AppendFormat(_T("%3X: "), i * 16);
|
|
376 |
for (int j = 0; j < 16; j++)
|
|
377 |
{
|
|
378 |
s2.AppendFormat(_T("%02X"), pDoc->MyKLink1.MEM.WDB[i * 16 + j]);
|
|
379 |
if (j == 7) { s2.Append(_T(" ")); }
|
|
380 |
else { s2.Append(_T(" ")); }
|
|
381 |
}
|
|
382 |
s2.Append(_T("\r\n"));
|
|
383 |
}
|
|
384 |
if (m_bMonitoring) {
|
|
385 |
SetDlgItemText(IDC_EDIT_MON3, s2);
|
|
386 |
}
|
|
387 |
|
|
388 |
// s2.AppendFormat(_T("%d\r\n"), pDoc->MyKLink1.MEM.SDD[5]);
|
|
389 |
|
|
390 |
nCount = 32;
|
|
391 |
//SetRedraw(FALSE);
|
|
392 |
|
|
393 |
s2.Empty();
|
|
394 |
if (m_bMonitoring) {
|
|
395 |
s1.Empty();
|
|
396 |
s1.Format(_T("主机\r\n"));
|
|
397 |
|
|
398 |
s1.AppendFormat(_T("00 跳线 %02X %s 当前 %02X\r\n"), pDoc->MyKLink1.MEM.SDD[0], intToBinString(pDoc->MyKLink1.MEM.SDD[0]), pDoc->MyKLink1.MEM.SDD[1]);
|
|
399 |
// s1.AppendFormat(_T("当前跳线 %02X %s\r\n"), pDoc->MyKLink1.MEM.SDD[1], intToBinString(pDoc->MyKLink1.MEM.SDD[1]));
|
|
400 |
s1.AppendFormat(_T("02 Tick计数 %u \r\n"), pDoc->MyKLink1.MEM.SDD[2]);
|
|
401 |
s1.AppendFormat(_T("03 nRunCount %u \r\n"), pDoc->MyKLink1.MEM.SDD[3]);
|
|
402 |
s1.AppendFormat(_T("04 RunStat %d \r\n"), pDoc->MyKLink1.MEM.SDD[4]);
|
|
403 |
s1.AppendFormat(_T("05 ErrStat %d \r\n"), pDoc->MyKLink1.MEM.SDD[5]);
|
|
404 |
s1.AppendFormat(_T("06 PwrOnCount %d \r\n"), pDoc->MyKLink1.MEM.SDD[6]);
|
|
405 |
s1.AppendFormat(_T("07 ThisRunTime %d \r\n"), pDoc->MyKLink1.MEM.SDD[7]);
|
|
406 |
|
|
407 |
int nTime1 = pDoc->MyKLink1.MEM.SDD[7];
|
|
408 |
s1.AppendFormat(_T("%dd %02d:%02d:%02d \r\n"), nTime1 / 86400, nTime1 / 3600 % 24, nTime1 / 60 % 60, nTime1 % 60);
|
|
409 |
s1.AppendFormat(_T("08 TotalTime %d \r\n"), pDoc->MyKLink1.MEM.SDD[8]);
|
|
410 |
nTime1 = pDoc->MyKLink1.MEM.SDD[8];
|
|
411 |
s1.AppendFormat(_T("%dd %02d:%02d:%02d \r\n"), nTime1 / 86400, nTime1 / 3600 % 24, nTime1 / 60 % 60, nTime1 % 60);
|
|
412 |
s1.AppendFormat(_T("09 CurTime %d \r\n"), pDoc->MyKLink1.MEM.SDD[9]);
|
|
413 |
|
|
414 |
nTime1 = pDoc->MyKLink1.MEM.SDD[9];
|
|
415 |
__time32_t time1 = nTime1;
|
|
416 |
CString s3;
|
|
417 |
//_tctime32_s(s3.GetBuffer(1024),1024, &time1);
|
|
418 |
//s3.ReleaseBuffer();
|
|
419 |
|
|
420 |
CTime ctime1 = time1;
|
|
421 |
if (nTime1 >= 0) s3 = ctime1.Format(_T("%Y-%m-%d %H:%M:%S"));
|
|
422 |
s1.Append(s3 + _T("\r\n"));
|
|
423 |
// s1.AppendFormat(_T("%04d-%02d-%02d %02d:%02d:%02d \r\n"), nTime1 / 86400, nTime1 / 3600 % 24, nTime1 / 60 % 60, nTime1 % 60);
|
|
424 |
s1.AppendFormat(_T("10 PwrFailCount %d \r\n"), pDoc->MyKLink1.MEM.SDD[10]);
|
|
425 |
s1.AppendFormat(_T("11 LastPwrFailTime %d \r\n"), pDoc->MyKLink1.MEM.SDD[11]);
|
|
426 |
nTime1 = pDoc->MyKLink1.MEM.SDD[11];
|
|
427 |
time1 = nTime1;
|
|
428 |
_tctime32_s(s3.GetBuffer(1024), 1024, &time1);
|
|
429 |
s3.ReleaseBuffer();
|
|
430 |
ctime1 = time1;
|
|
431 |
ctime1 += (30 * 365 + 7) * 24 * 3600;
|
|
432 |
ctime1 = CStringToCTime(_T("2000-01-01 08:00:00"));
|
|
433 |
ctime1 += nTime1;
|
|
434 |
s3 = ctime1.Format(_T("%Y-%m-%d %H:%M:%S"));
|
|
435 |
s1.Append(s3 + _T("\r\n"));
|
|
436 |
|
|
437 |
s1.AppendFormat(_T("12 LastScanTime uS %u \r\n"), pDoc->MyKLink1.MEM.SDD[12]);
|
|
438 |
s1.AppendFormat(_T("13 ScanTime uS %d \r\n"), pDoc->MyKLink1.MEM.SDD[13]);
|
|
439 |
s1.AppendFormat(_T("14 MinScanTime uS %d \r\n"), pDoc->MyKLink1.MEM.SDD[14]);
|
|
440 |
s1.AppendFormat(_T("15 %d \r\n"), pDoc->MyKLink1.MEM.SDD[15]);
|
|
441 |
s1.AppendFormat(_T("16 %d \r\n"), pDoc->MyKLink1.MEM.SDD[16]);
|
|
442 |
s1.AppendFormat(_T("17 %d \r\n"), pDoc->MyKLink1.MEM.SDD[17]);
|
|
443 |
s1.AppendFormat(_T("18 %d \r\n"), pDoc->MyKLink1.MEM.SDD[18]);
|
|
444 |
s1.AppendFormat(_T("19 %d \r\n"), pDoc->MyKLink1.MEM.SDD[19]);
|
|
445 |
s1.AppendFormat(_T("20 %d \r\n"), pDoc->MyKLink1.MEM.SDD[20]);
|
|
446 |
s1.AppendFormat(_T("21 %d \r\n"), pDoc->MyKLink1.MEM.SDD[21]);
|
|
447 |
s1.AppendFormat(_T("22 %d \r\n"), pDoc->MyKLink1.MEM.SDD[22]);
|
|
448 |
s1.AppendFormat(_T("23 %d \r\n"), pDoc->MyKLink1.MEM.SDD[23]);
|
|
449 |
|
|
450 |
float Vref = 1.2f;
|
|
451 |
float Vcor = (float)pDoc->MyKLink1.MEM.SDT[53] / pDoc->MyKLink1.MEM.SDT[55];
|
|
452 |
float V33 = 3.3f * Vcor;
|
|
453 |
|
|
454 |
s1.AppendFormat(_T("24 24V电压 %d %.2f V \r\n"), pDoc->MyKLink1.MEM.SDT[48], pDoc->MyKLink1.MEM.SDT[48] * V33 / 4096 * 11);
|
|
455 |
s1.AppendFormat(_T("25 %d \r\n"), pDoc->MyKLink1.MEM.SDT[49]);
|
|
456 |
s1.AppendFormat(_T("26 5V 电压 %d %.3f V \r\n"), pDoc->MyKLink1.MEM.SDT[50], pDoc->MyKLink1.MEM.SDT[50] * V33 / 4096 * 2);
|
|
457 |
s1.AppendFormat(_T("27 %d \r\n"), pDoc->MyKLink1.MEM.SDT[51]);
|
|
458 |
s1.AppendFormat(_T("28 %d \r\n"), pDoc->MyKLink1.MEM.SDT[52]);
|
|
459 |
s1.AppendFormat(_T("29 %d \r\n"), pDoc->MyKLink1.MEM.SDT[53]);
|
|
460 |
float temp = (1430 - pDoc->MyKLink1.MEM.SDT[54]* 0.806f ) / 4.3f + 25;
|
|
461 |
s1.AppendFormat(_T("30 芯片温度 %d %.1f ℃ \r\n"), pDoc->MyKLink1.MEM.SDT[54],temp);
|
|
462 |
s1.AppendFormat(_T("31 1.2V参考 %d 3.3V电压 %.3f V \r\n"), pDoc->MyKLink1.MEM.SDT[55], V33);
|
|
463 |
|
|
464 |
|
|
465 |
|
|
466 |
//型号
|
|
467 |
//版本
|
|
468 |
//协议版本
|
|
469 |
//生产日期
|
|
470 |
//生产批号
|
|
471 |
//序列号
|
|
472 |
|
|
473 |
//开机次数
|
|
474 |
//总开机时间
|
|
475 |
//最大连续开机时间
|
|
476 |
//本次开机时间
|
|
477 |
//电源闪断次数
|
|
478 |
//总看门狗动作次数
|
|
479 |
//本次看门狗动作次数
|
|
480 |
//电源电压
|
|
481 |
//核心温度
|
|
482 |
|
|
483 |
//输入输出
|
|
484 |
//IO状态,开路,短路,熔断.....
|
|
485 |
|
|
486 |
//包顺序错误
|
|
487 |
//令牌 广播形式, 环路形式
|
|
488 |
//
|
|
489 |
|
|
490 |
s2 += s1;
|
|
491 |
s2.AppendFormat(_T("\r\n"));
|
|
492 |
int nOffset = 32;
|
|
493 |
s1.Empty();
|
|
494 |
s1.Format(_T("子机1\r\n"));
|
|
495 |
KLink1::pChnStat pchnstat1 = (KLink1::pChnStat)&(pDoc->MyKLink1.MEM.SDD[nOffset + 0]);
|
|
496 |
unsigned int nSendPackets = pchnstat1->SendPackets;
|
|
497 |
s1.AppendFormat(_T("当前状态: %04X\r\n"), pchnstat1->Stat);
|
|
498 |
s1.AppendFormat(_T("发收包数:%6d/%6d(%.2f%%)\r\n发送时间 %10u (uS)\r\n"),
|
|
499 |
pchnstat1->SendPackets,
|
|
500 |
pchnstat1->RecvPackets, pchnstat1->RecvPackets *100.0 / nSendPackets,
|
|
501 |
pchnstat1->LastSentTimeuS);
|
|
502 |
|
|
503 |
s1.AppendFormat(_T("丢包计数:%d(%.2f%%) 连续 %d(Max:%d)\r\n"),
|
|
504 |
pchnstat1->LostPackets, pchnstat1->LostPackets *100.0 / nSendPackets,
|
|
505 |
pchnstat1->CtnLstPkts,
|
|
506 |
pchnstat1->MaxCtnLstPkts);
|
|
507 |
|
|
508 |
s1.AppendFormat(_T("返回延迟 %d(max:%d) uS\r\n"),
|
|
509 |
pchnstat1->Delay, pchnstat1->MaxDelay);
|
|
510 |
s1.AppendFormat(_T("循环时间 %d uS\r\n"),
|
|
511 |
pchnstat1->SendTimeInterval);
|
|
512 |
|
|
513 |
s1.AppendFormat(_T("子机收发 %6d/%6d \r\n"),
|
|
514 |
pchnstat1->ClientRecvPkts,
|
|
515 |
pchnstat1->ClientSendPkts);
|
|
516 |
|
|
517 |
s2 += s1;
|
|
518 |
s2.AppendFormat(_T("\r\n"));
|
|
519 |
|
|
520 |
nOffset = 32 + 24;
|
|
521 |
s1.Format(_T("子机2\r\n"));
|
|
522 |
pchnstat1 = (KLink1::pChnStat)&(pDoc->MyKLink1.MEM.SDD[nOffset + 0]);
|
|
523 |
nSendPackets = pchnstat1->SendPackets;
|
|
524 |
s1.AppendFormat(_T("当前状态: %04X\r\n"), pchnstat1->Stat);
|
|
525 |
s1.AppendFormat(_T("发收包数:%6d/%6d(%.2f%%)\r\n发送时间 %10u (uS)\r\n"),
|
|
526 |
pchnstat1->SendPackets,
|
|
527 |
pchnstat1->RecvPackets, pchnstat1->RecvPackets *100.0 / nSendPackets,
|
|
528 |
pchnstat1->LastSentTimeuS);
|
|
529 |
|
|
530 |
s1.AppendFormat(_T("丢包计数:%d(%.2f%%) 连续 %d(Max:%d)\r\n"),
|
|
531 |
pchnstat1->LostPackets, pchnstat1->LostPackets *100.0 / nSendPackets,
|
|
532 |
pchnstat1->CtnLstPkts,
|
|
533 |
pchnstat1->MaxCtnLstPkts);
|
|
534 |
|
|
535 |
s1.AppendFormat(_T("返回延迟 %d(max:%d) uS\r\n"),
|
|
536 |
pchnstat1->Delay, pchnstat1->MaxDelay);
|
|
537 |
s1.AppendFormat(_T("循环时间 %d uS\r\n"),
|
|
538 |
pchnstat1->SendTimeInterval);
|
|
539 |
|
|
540 |
s1.AppendFormat(_T("子机收发 %6d/%6d \r\n"),
|
|
541 |
pchnstat1->ClientRecvPkts,
|
|
542 |
pchnstat1->ClientSendPkts);
|
|
543 |
|
|
544 |
s2 += s1;
|
|
545 |
//m_edit_mon2.SetSel(0, -1);
|
|
546 |
//m_edit_mon2.ReplaceSel(s2);
|
|
547 |
SetDlgItemText(IDC_EDIT_MON2, s2);
|
|
548 |
}
|
|
549 |
|
|
550 |
s1.Empty();
|
|
551 |
pstWLRunStat pWLRunStat = (pstWLRunStat)(&pDoc->KWLB);
|
|
552 |
s1 += _T("发送数量: ") + intToString(pWLRunStat->sentCount) + _T("\r\n");
|
|
553 |
s1 += _T("接收数量: ") + intToString(pWLRunStat->recvCount) + _T("\r\n");
|
|
554 |
|
|
555 |
s1 += _T("发送时间: ") + intToString(pWLRunStat->lastSendtime) + _T(" uS\r\n");
|
|
556 |
s1 += _T("接收时间: ") + intToString(pWLRunStat->lastRecvtime) + _T(" uS\r\n");
|
|
557 |
s1 += _T("动作时间: ") + intToString(pWLRunStat->lastActTime) + _T(" uS\r\n");
|
|
558 |
s1 += _T("相应时间: ") + intToString(pWLRunStat->lastAckTime) + _T(" uS\r\n");
|
|
559 |
s1 += _T("循环时间: ") + intToString(pWLRunStat->cycleTime,9) + _T(" uS\r\n");
|
|
560 |
s1 += _T("延迟: ") + intToString(pWLRunStat->latancy,9) + _T(" uS\r\n");
|
|
561 |
s1.AppendFormat(_T("丢包数量: %d\r\n"), pWLRunStat->LostPackets);
|
|
562 |
s1.AppendFormat(_T("连续丢包: %d\r\n"), pWLRunStat->CtnLstPkts);
|
|
563 |
s1.AppendFormat(_T("最大连续: %d\r\n"), pWLRunStat->MaxCtnLstPkts);
|
|
564 |
s1.AppendFormat(_T("发送错误: %d\r\n"), pWLRunStat->TXErr);
|
|
565 |
s1.AppendFormat(_T("接收错误: %d\r\n"), pWLRunStat->RXErr);
|
|
566 |
s1.AppendFormat(_T("CRC错误: %d\r\n"), pWLRunStat->CRCErr);
|
|
567 |
s1.AppendFormat(_T("本机信号强度: %d dBm %d dBm\r\n"), pWLRunStat->RSSI, pWLRunStat->SNR);
|
|
568 |
s1.AppendFormat(_T("对方信号强度: %d dBm %d dBm\r\n"), pWLRunStat->tRSSI, pWLRunStat->tSNR);
|
|
569 |
|
|
570 |
SetDlgItemText(IDC_EDIT_MON4, s1);
|
|
571 |
//SetRedraw(TRUE);
|
|
572 |
//s1.Append(s2);
|
|
573 |
//s1.Append(_T("\r\n"));
|
|
574 |
UpdateStatusBar(-1);
|
|
575 |
return 0;
|
|
576 |
}
|
|
577 |
|
|
578 |
int CMTerm1CommDevView::UpdateStatusBar(int nIndex)
|
|
579 |
{
|
|
580 |
// TODO: 在此处添加实现代码.
|
|
581 |
CString s1;
|
|
582 |
CMTerm1Doc * pDoc = (CMTerm1Doc*)GetDocument();
|
|
583 |
|
|
584 |
if (nIndex == idxMachineType || nIndex == -1) { //机型代码
|
|
585 |
s1 = pDoc->m_sMachineType;
|
|
586 |
m_pStatusBar->SetPaneText(idxMachineType, s1);
|
|
587 |
}
|
|
588 |
if (nIndex == idxProgPos || nIndex == -1) { //程序位置/步数
|
|
589 |
// s1.Format(_T("%5d/%5d"), m_nCurProgStep, pDoc->m_nProgSteps);
|
|
590 |
// m_pStatusBar->SetPaneText(idxProgPos, s1);
|
|
591 |
}
|
|
592 |
if (nIndex == idxOnline || nIndex == -1) { //在线 /离线
|
|
593 |
if (!pDoc->m_bOnline) {
|
|
594 |
s1 = _T("离线");
|
|
595 |
m_pStatusBar->SetPaneText(idxOnline, s1);
|
|
596 |
m_pStatusBar->SetPaneBackgroundColor(idxOnline);
|
|
597 |
}
|
|
598 |
else if (pDoc->m_bOnline) {
|
|
599 |
if (pDoc->m_bSimulate) {
|
|
600 |
s1 = _T("在线(仿真)");
|
|
601 |
m_pStatusBar->SetPaneText(2, s1);
|
|
602 |
m_pStatusBar->SetPaneBackgroundColor(idxOnline, OnlineColor);
|
|
603 |
}
|
|
604 |
else {
|
|
605 |
s1 = _T("在线");
|
|
606 |
m_pStatusBar->SetPaneText(2, s1);
|
|
607 |
m_pStatusBar->SetPaneBackgroundColor(idxOnline, OnlineColor);
|
|
608 |
}
|
|
609 |
}
|
|
610 |
}
|
|
611 |
if (nIndex == idxRunning || nIndex == -1) { // 运行 / 停止
|
|
612 |
if (!pDoc->m_bOnline) {
|
|
613 |
s1 = _T("");
|
|
614 |
m_pStatusBar->SetPaneText(idxRunning, s1);
|
|
615 |
m_pStatusBar->SetPaneBackgroundColor(idxRunning);
|
|
616 |
m_pStatusBar->SetPaneWidth(idxRunning, 0);
|
|
617 |
m_pStatusBar->SetPaneStyle(idxRunning, SBPS_DISABLED);
|
|
618 |
|
|
619 |
}
|
|
620 |
else if (!pDoc->m_bPlcRunning) {
|
|
621 |
s1 = _T("PROG");
|
|
622 |
m_pStatusBar->SetPaneText(idxRunning, s1);
|
|
623 |
m_pStatusBar->SetPaneWidth(idxRunning, s1.GetLength() * 8);
|
|
624 |
m_pStatusBar->SetPaneBackgroundColor(idxRunning, ProgColor);
|
|
625 |
}
|
|
626 |
else {
|
|
627 |
s1 = _T("RUN");
|
|
628 |
m_pStatusBar->SetPaneText(idxRunning, s1);
|
|
629 |
m_pStatusBar->SetPaneWidth(idxRunning, s1.GetLength() * 8);
|
|
630 |
m_pStatusBar->SetPaneBackgroundColor(idxRunning, RunningColor);
|
|
631 |
}
|
|
632 |
}
|
|
633 |
if (nIndex == idxMonitor || nIndex == -1) { // 监控 //
|
|
634 |
// s1 = pDoc->m_sMachineType;
|
|
635 |
if (!m_bMonitoring) {
|
|
636 |
s1 = _T("[监控停止]");
|
|
637 |
m_pStatusBar->SetPaneText(idxMonitor, s1);
|
|
638 |
m_pStatusBar->SetPaneBackgroundColor(idxMonitor);
|
|
639 |
}
|
|
640 |
else {
|
|
641 |
s1 = _T("[正在监控]");
|
|
642 |
m_pStatusBar->SetPaneText(idxMonitor, s1);
|
|
643 |
m_pStatusBar->SetPaneBackgroundColor(idxMonitor, MonitorColor);
|
|
644 |
}
|
|
645 |
}
|
|
646 |
if (nIndex == idxAddress || nIndex == -1) { // 地址,本站
|
|
647 |
// s1 = pDoc->m_sMachineType;
|
|
648 |
if (!pDoc->m_bOnline) {
|
|
649 |
s1 = _T("本站");
|
|
650 |
m_pStatusBar->SetPaneText(idxAddress, s1);
|
|
651 |
m_pStatusBar->SetPaneBackgroundColor(idxMonitor);
|
|
652 |
}
|
|
653 |
else {
|
|
654 |
s1 = _T("本站");
|
|
655 |
m_pStatusBar->SetPaneText(idxAddress, s1);
|
|
656 |
m_pStatusBar->SetPaneBackgroundColor(idxMonitor, AddressColor);
|
|
657 |
}
|
|
658 |
|
|
659 |
}
|
|
660 |
if (nIndex == idxInfoDisp || nIndex == -1) { // INFO DISPLAY
|
|
661 |
// s1 = pDoc->m_sMachineType;
|
|
662 |
m_pStatusBar->SetPaneText(idxInfoDisp, s1);
|
|
663 |
}
|
|
664 |
return 0;
|
|
665 |
}
|
|
666 |
|
|
667 |
void CMTerm1CommDevView::OnTimer(UINT_PTR nIDEvent)
|
|
668 |
{
|
|
669 |
// TODO: 在此添加消息处理程序代码和/或调用默认值
|
|
670 |
CString s1, s2;
|
|
671 |
|
|
672 |
if (nIDEvent == 0)
|
|
673 |
{
|
|
674 |
KillTimer(0);
|
|
675 |
DelayInit();
|
|
676 |
}
|
|
677 |
else if (nIDEvent == 1)
|
|
678 |
{
|
|
679 |
//ProcessPLC();
|
|
680 |
MonitorPLC();
|
|
681 |
}
|
|
682 |
else if (nIDEvent == 2)
|
|
683 |
{
|
|
684 |
// ProcessInput();
|
|
685 |
//DrawPic1();
|
|
686 |
// MyLogger1.UpdateLogDisplay(0);
|
|
687 |
UpdateDataDisplay();
|
|
688 |
UpdateLEDDisplay();
|
|
689 |
}
|
|
690 |
else if (nIDEvent == 3)
|
|
691 |
{
|
|
692 |
if (m_bResourceOpened && !m_bPause)
|
|
693 |
{
|
|
694 |
// int n=AcqureDatas(m_nChannel);
|
|
695 |
int n = 0;
|
|
696 |
if (n > 0)
|
|
697 |
{
|
|
698 |
}
|
|
699 |
}
|
|
700 |
}
|
|
701 |
else if (nIDEvent == 4) {}
|
|
702 |
else {}
|
|
703 |
CFormView::OnTimer(nIDEvent);
|
|
704 |
}
|
|
705 |
|
|
706 |
|
|
707 |
// 如果向对话框添加最小化按钮,则需要下面的代码
|
|
708 |
// 来绘制该图标。 对于使用文档/视图模型的 MFC 应用程序,
|
|
709 |
// 这将由框架自动完成。
|
|
710 |
|
|
711 |
/*
|
|
712 |
BOOL CMTerm1CommDevView::PreTranslateMessage(MSG* pMsg)
|
|
713 |
{
|
|
714 |
// TODO: 在此添加专用代码和/或调用基类
|
|
715 |
CString s1;
|
|
716 |
if (pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_RETURN)
|
|
717 |
{
|
|
718 |
if (GetDlgItem(IDC_COMBO_INPUT) == GetFocus())
|
|
719 |
{
|
|
720 |
OnBnClickedButtonSend();
|
|
721 |
}
|
|
722 |
return FALSE;
|
|
723 |
}
|
|
724 |
if (pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_BACK)
|
|
725 |
{
|
|
726 |
return FALSE;
|
|
727 |
}
|
|
728 |
if (pMsg->message == WM_KEYDOWN)
|
|
729 |
{
|
|
730 |
|
|
731 |
BOOL bCtrl = ::GetKeyState(VK_CONTROL) & 0x80;
|
|
732 |
switch (pMsg->wParam)
|
|
733 |
{
|
|
734 |
case 'a':
|
|
735 |
case 'A':
|
|
736 |
if (bCtrl)
|
|
737 |
{
|
|
738 |
CEdit* edit = (CEdit*)(GetDlgItem(IDC_EDIT_LOG1));
|
|
739 |
//edit->SetFocus();
|
|
740 |
edit->SetSel(0, -1);
|
|
741 |
return FALSE;
|
|
742 |
}
|
|
743 |
}
|
|
744 |
}
|
|
745 |
try
|
|
746 |
{
|
|
747 |
return CFormView::PreTranslateMessage(pMsg);
|
|
748 |
}
|
|
749 |
catch (CMemoryException* e)
|
|
750 |
{
|
|
751 |
CString Serror;
|
|
752 |
e->GetErrorMessage(Serror.GetBuffer(256), 256);
|
|
753 |
Serror.ReleaseBuffer();
|
|
754 |
s1.Format(_T("程序 发生 内存 错误 %s \r\n"), Serror);
|
|
755 |
PopupMessage(s1);
|
|
756 |
}
|
|
757 |
catch (CFileException* e)
|
|
758 |
{
|
|
759 |
CString Serror;
|
|
760 |
e->GetErrorMessage(Serror.GetBuffer(256), 256);
|
|
761 |
Serror.ReleaseBuffer();
|
|
762 |
s1.Format(_T("程序 发生 文件 错误 %s \r\n"), Serror);
|
|
763 |
PopupMessage(s1);
|
|
764 |
}
|
|
765 |
catch (SE_Exception & e)
|
|
766 |
{
|
|
767 |
s1.Format(_T("程序 发生 SE 错误 Code %08X Addr %08X \r\n%s\r\n"), e.getSeNumber(), e.getAddress(), e.getInfoStr());
|
|
768 |
PopupMessage(s1);
|
|
769 |
}
|
|
770 |
catch (CException* e)
|
|
771 |
{
|
|
772 |
CString Serror;
|
|
773 |
e->GetErrorMessage(Serror.GetBuffer(256), 256);
|
|
774 |
Serror.ReleaseBuffer();
|
|
775 |
s1.Format(_T("程序 发生 C++ 错误 %s \r\n"), Serror);
|
|
776 |
PopupMessage(s1);
|
|
777 |
}
|
|
778 |
catch (...)
|
|
779 |
{
|
|
780 |
s1.Format(_T("程序 发生未知错误 \r\n"));
|
|
781 |
PopupMessage(s1);
|
|
782 |
}
|
|
783 |
return TRUE;
|
|
784 |
|
|
785 |
return CFormView::PreTranslateMessage(pMsg);
|
|
786 |
}
|
|
787 |
*/
|
|
788 |
void CMTerm1CommDevView::FindComPort()
|
|
789 |
{
|
|
790 |
CString s1, s2;
|
|
791 |
m_combo_comport.ResetContent();
|
|
792 |
for (int i = 1; i <= 16; i++)
|
|
793 |
{
|
|
794 |
s1.Format(_T("COM%d"), i);
|
|
795 |
if (get_com_name(s1, s2)) s1 = s2;
|
|
796 |
m_combo_comport.AddString(s1);
|
|
797 |
}
|
|
798 |
sComSelStr = _T("COM3");
|
|
799 |
m_combo_comport.SelectString(0, sComSelStr);
|
|
800 |
m_combo_comport.SetCurSel(2);
|
|
801 |
return;
|
|
802 |
HKEY hKey;
|
|
803 |
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("Hardware\\DeviceMap\\SerialComm"), NULL, KEY_READ, &hKey) == ERROR_SUCCESS)
|
|
804 |
{
|
|
805 |
TCHAR szPortName[256], szComName[256];
|
|
806 |
DWORD dwLong, dwSize;
|
|
807 |
int nCount = 0;
|
|
808 |
|
|
809 |
m_combo_comport.ResetContent();
|
|
810 |
while (true)
|
|
811 |
{
|
|
812 |
dwLong = dwSize = 256;
|
|
813 |
if (RegEnumValue(hKey, nCount, szPortName, &dwLong, NULL, NULL, (PUCHAR)szComName, &dwSize) == ERROR_NO_MORE_ITEMS)
|
|
814 |
break;
|
|
815 |
|
|
816 |
m_combo_comport.InsertString(nCount, szComName);
|
|
817 |
nCount++;
|
|
818 |
}
|
|
819 |
RegCloseKey(hKey);
|
|
820 |
m_combo_comport.SetCurSel(0);
|
|
821 |
}
|
|
822 |
}
|
|
823 |
BOOL CMTerm1CommDevView::OnDeviceChange(UINT nEventType, DWORD_PTR dwData)
|
|
824 |
{
|
|
825 |
if (nEventType == DBT_DEVNODES_CHANGED)
|
|
826 |
{
|
|
827 |
FindComPort();
|
|
828 |
}
|
|
829 |
|
|
830 |
return TRUE;
|
|
831 |
}
|
|
832 |
|
|
833 |
int CMTerm1CommDevView::LoadResourceList()
|
|
834 |
{
|
|
835 |
Hash & ResourceCfg = MyCfg1["Resources"];
|
|
836 |
int nCount;
|
|
837 |
nCount = _tstoi(ResourceCfg["Count"]);
|
|
838 |
CString s1, s2;
|
|
839 |
for (int i = 0; i < nCount; i++)
|
|
840 |
{
|
|
841 |
s1.Format(_T("Addr%d"), i);
|
|
842 |
s2 = ResourceCfg[s1];
|
|
843 |
((CComboBox *)GetDlgItem(IDC_COMBO_RES))->AddString(s2);
|
|
844 |
}
|
|
845 |
s1 = ResourceCfg["LastAddr"];
|
|
846 |
((CComboBox *)GetDlgItem(IDC_COMBO_RES))->SetWindowText(s1);
|
|
847 |
return nCount;
|
|
848 |
}
|
|
849 |
|
|
850 |
int CMTerm1CommDevView::SaveResourceList()
|
|
851 |
{
|
|
852 |
Hash & ResourceCfg = MyCfg1["Resources"];
|
|
853 |
int nCount1 = _tstoi(ResourceCfg["Count"]);
|
|
854 |
CString s1, s2, s3;
|
|
855 |
((CComboBox *)GetDlgItem(IDC_COMBO_RES))->GetWindowText(s3);
|
|
856 |
|
|
857 |
int bFound = 0;
|
|
858 |
int nCount2 = ((CComboBox *)GetDlgItem(IDC_COMBO_RES))->GetCount();
|
|
859 |
for (int i = 0; i < nCount2; i++)
|
|
860 |
{
|
|
861 |
((CComboBox *)GetDlgItem(IDC_COMBO_RES))->GetLBText(i, s2);
|
|
862 |
if (s2 == s3) { bFound = 1; break; }
|
|
863 |
}
|
|
864 |
if (!bFound)
|
|
865 |
{
|
|
866 |
((CComboBox *)GetDlgItem(IDC_COMBO_RES))->AddString(s3);
|
|
867 |
s1.Format(_T("Addr%d"), nCount1);
|
|
868 |
ResourceCfg[s1] = s3;
|
|
869 |
nCount1 = nCount1 + 1;
|
|
870 |
s1.Format(_T("%d"), nCount1);
|
|
871 |
ResourceCfg["Count"] = s1;
|
|
872 |
}
|
|
873 |
ResourceCfg["LastAddr"] = s3;
|
|
874 |
|
|
875 |
return nCount1;
|
|
876 |
}
|
|
877 |
|
|
878 |
int CMTerm1CommDevView::DisplayParams()
|
|
879 |
{
|
|
880 |
CMTerm1Doc *pDoc = (CMTerm1Doc *)GetDocument();
|
|
881 |
CString s1, s2;
|
|
882 |
Hash & ModelConfg = MyCfg1["Model"];
|
|
883 |
ModelConfg.SetCtrlList(this, myCfgValCtrls, nMarkConfigs);
|
|
884 |
|
|
885 |
for (int i = 1; i <= 16; i++)
|
|
886 |
{
|
|
887 |
s1.Format(_T("COM%d"), i);
|
|
888 |
if (get_com_name(s1, s2)) (s1 = s2);
|
|
889 |
m_combo_comport.AddString(s1);
|
|
890 |
|
|
891 |
}
|
|
892 |
sComSelStr = _T("COM3");
|
|
893 |
m_combo_comport.SelectString(0, sComSelStr);
|
|
894 |
m_combo_comport.SetCurSel(2);
|
|
895 |
|
|
896 |
m_combo_com_baud.AddString(_T("1200"));
|
|
897 |
m_combo_com_baud.AddString(_T("2400"));
|
|
898 |
m_combo_com_baud.AddString(_T("4800"));
|
|
899 |
m_combo_com_baud.AddString(_T("9600"));
|
|
900 |
m_combo_com_baud.AddString(_T("19200"));
|
|
901 |
m_combo_com_baud.AddString(_T("38400"));
|
|
902 |
m_combo_com_baud.AddString(_T("57600"));
|
|
903 |
m_combo_com_baud.AddString(_T("115200"));
|
|
904 |
m_combo_com_baud.AddString(_T("128000"));
|
|
905 |
m_combo_com_baud.AddString(_T("187500"));
|
|
906 |
m_combo_com_baud.AddString(_T("230400"));
|
|
907 |
m_combo_com_baud.AddString(_T("460800"));
|
|
908 |
m_combo_com_baud.AddString(_T("921600"));
|
|
909 |
m_combo_com_baud.AddString(_T("1000000"));
|
|
910 |
m_combo_com_baud.AddString(_T("2000000"));
|
|
911 |
m_combo_com_baud.AddString(_T("3000000"));
|
|
912 |
sBaudSelStr = _T("230400");
|
|
913 |
m_combo_com_baud.SelectString(0, sBaudSelStr);
|
|
914 |
|
|
915 |
MyThreadProc1ToRun = 0;
|
|
916 |
MyThreadProc1Running = 0;
|
|
917 |
|
|
918 |
((CComboBox *)GetDlgItem(IDC_COMBO_MADDR))->SetCurSel(0);
|
|
919 |
((CComboBox *)GetDlgItem(IDC_COMBO_CMD))->SetCurSel(2);
|
|
920 |
((CComboBox *)GetDlgItem(IDC_COMBO_CMD_TYPE))->SetCurSel(0);
|
|
921 |
((CComboBox *)GetDlgItem(IDC_COMBO_DADDR))->SetCurSel(0);
|
|
922 |
((CComboBox *)GetDlgItem(IDC_COMBO_DCOUNT))->SetCurSel(6);
|
|
923 |
|
|
924 |
return 0;
|
|
925 |
}
|
|
926 |
|
|
927 |
int CMTerm1CommDevView::GetParams()
|
|
928 |
{
|
|
929 |
CString s1, s2;
|
|
930 |
Hash & ModelConfg = MyCfg1["Model"];
|
|
931 |
ModelConfg.GetCtrlList(this, myCfgValCtrls, nMarkConfigs);
|
|
932 |
|
|
933 |
return 0;
|
|
934 |
}
|
|
935 |
|
|
936 |
int CMTerm1CommDevView::LoadModel()
|
|
937 |
{
|
|
938 |
CString s1;
|
|
939 |
|
|
940 |
Hash & ModelConfg = MyCfg1["Model"];
|
|
941 |
return 0;
|
|
942 |
}
|
|
943 |
|
|
944 |
int CMTerm1CommDevView::SaveModel()
|
|
945 |
{
|
|
946 |
CString s1, s2;
|
|
947 |
Hash & ModelConfg = MyCfg1["Model"];
|
|
948 |
return 0;
|
|
949 |
}
|
|
950 |
|
|
951 |
|
|
952 |
int CMTerm1CommDevView::OpenResource(CStringA ResourceStr)
|
|
953 |
{
|
|
954 |
CString s1;
|
|
955 |
CMTerm1Doc *pDoc = (CMTerm1Doc *) GetDocument();
|
|
956 |
|
|
957 |
int r = pDoc->Connect();
|
|
958 |
s1.Format(_T("Open %s = %d"), pDoc->MyKLink1.m_resultStr, r);
|
|
959 |
SysLog(s1);
|
|
960 |
if (r == pDoc->MyKLink1.MySerPort1.R_OK)
|
|
961 |
{
|
|
962 |
m_bResourceOpened = true;
|
|
963 |
// pDoc->MyKLink1.Open();
|
|
964 |
m_static_connect.SetCtlColor(RGB(0, 255, 0));
|
|
965 |
return true;
|
|
966 |
}
|
|
967 |
return false;
|
|
968 |
}
|
|
969 |
|
|
970 |
int CMTerm1CommDevView::CloseResource()
|
|
971 |
{
|
|
972 |
CMTerm1Doc *pDoc = (CMTerm1Doc *)GetDocument();
|
|
973 |
|
|
974 |
m_static_connect.SetCtlColor(RGB(80, 80, 80));
|
|
975 |
if (m_bResourceOpened)
|
|
976 |
{
|
|
977 |
pDoc->DisConnect();
|
|
978 |
pDoc->MyKLink1.Close();
|
|
979 |
m_bResourceOpened = false;
|
|
980 |
}
|
|
981 |
return 0;
|
|
982 |
}
|
|
983 |
|
|
984 |
int CMTerm1CommDevView::LoadData(CString sFilePathName)
|
|
985 |
{
|
|
986 |
CFile file1;
|
|
987 |
CFileException e1;
|
|
988 |
CStringA s1a;
|
|
989 |
int nDataCount = 0;
|
|
990 |
int r = file1.Open(sFilePathName, CFile::modeRead, &e1);
|
|
991 |
if (r)
|
|
992 |
{
|
|
993 |
int len1 = (int)file1.GetLength();
|
|
994 |
file1.Read(s1a.GetBufferSetLength(len1 + 100), len1);
|
|
995 |
s1a.ReleaseBuffer(len1);
|
|
996 |
int k = s1a.Find("\n", 0);
|
|
997 |
int n = atoi(s1a.Left(k));
|
|
998 |
CStringA s2A;
|
|
999 |
CStringA resultstr[100];
|
|
1000 |
for (int i = 0; i < n; i++)
|
|
1001 |
{
|
|
1002 |
int j = s1a.Find("\n", k + 1);
|
|
1003 |
s2A = s1a.Mid(k + 1, j - k - 1);
|
|
1004 |
Split(s2A, ",", resultstr);
|
|
1005 |
float a = (float)atof(resultstr[0]);
|
|
1006 |
float b = (float)atof(resultstr[1]);
|
|
1007 |
float c = (float)atof(resultstr[2]);
|
|
1008 |
k = j;
|
|
1009 |
}
|
|
1010 |
nDataCount = n;
|
|
1011 |
}
|
|
1012 |
return nDataCount;
|
|
1013 |
}
|
|
1014 |
|
|
1015 |
int CMTerm1CommDevView::SaveData(CString sFilePathName)
|
|
1016 |
{
|
|
1017 |
CFile file1;
|
|
1018 |
CFileException e1;
|
|
1019 |
CStringA s1a;
|
|
1020 |
int nDataCount = 0;
|
|
1021 |
int r = file1.Open(sFilePathName, CFile::modeCreate | CFile::modeWrite, &e1);
|
|
1022 |
if (r)
|
|
1023 |
{
|
|
1024 |
s1a.Format("%d\r\n", nDataCount);
|
|
1025 |
for (int i = 0; i < nDataCount; i++)
|
|
1026 |
{
|
|
1027 |
s1a.AppendFormat("%f,%f,%f\r\n", 0, 0, 0);
|
|
1028 |
}
|
|
1029 |
file1.Write(s1a.GetBuffer(), s1a.GetLength());
|
|
1030 |
file1.Close();
|
|
1031 |
}
|
|
1032 |
return 0;
|
|
1033 |
}
|
|
1034 |
|
|
1035 |
void CMTerm1CommDevView::OnSize(UINT nType, int cx, int cy)
|
|
1036 |
{
|
|
1037 |
CFormView::OnSize(nType, cx, cy);
|
|
1038 |
if (!this->IsWindowVisible() && !BInited) { return; }
|
|
1039 |
CString s1;
|
|
1040 |
s1.Format(_T("Dialog OnSize Type %d cx %d cy %d \r\n"), nType, cx, cy);
|
|
1041 |
// SysLog(s1);
|
|
1042 |
switch (nType)
|
|
1043 |
{
|
|
1044 |
case SIZE_MAXHIDE:
|
|
1045 |
case SIZE_MAXSHOW:
|
|
1046 |
case SIZE_MINIMIZED:
|
|
1047 |
return;
|
|
1048 |
}
|
|
1049 |
if (nType == SIZE_MAXIMIZED || nType == SIZE_RESTORED)
|
|
1050 |
{
|
|
1051 |
// calLayerOuts();
|
|
1052 |
// CalButtonsLayerOut();
|
|
1053 |
}
|
|
1054 |
// TODO: 在此处添加消息处理程序代码
|
|
1055 |
}
|
|
1056 |
|
|
1057 |
int CMTerm1CommDevView::calLayerOuts()
|
|
1058 |
{
|
|
1059 |
GetClientRect(&MainClientRect);
|
|
1060 |
MainClientRect.bottom -= 20;
|
|
1061 |
int w = MainClientRect.Width();
|
|
1062 |
int h = MainClientRect.Height();
|
|
1063 |
DivRectX(MainClientRect, LeftRect, RightRect, 600, 0.7f);
|
|
1064 |
|
|
1065 |
DivRectY3(LeftRect, ItemRect, ButtonRect, LogRect, 0.7f, 0.1f, 0.2f);
|
|
1066 |
|
|
1067 |
CRect ItemRect1, ItemRect2;
|
|
1068 |
DivRectX(ItemRect, ItemRect1, ItemRect2, 0.5f, 0.5f);
|
|
1069 |
|
|
1070 |
PicRect = RightRect;
|
|
1071 |
|
|
1072 |
DivRectY(PicRect, PicRectUp, PicRectDown, 24, 0.95f);
|
|
1073 |
|
|
1074 |
// dialogitemshow1.MoveWindow(&ItemRect1);
|
|
1075 |
// dialogitemshow2.MoveWindow(&ItemRect2);
|
|
1076 |
|
|
1077 |
GetDlgItem(IDC_EDIT_DISPLAY)->MoveWindow(&PicRectUp);
|
|
1078 |
GetDlgItem(IDC_COMBO_INPUT)->MoveWindow(&PicRectDown);
|
|
1079 |
GetDlgItem(IDC_EDIT_LOG1)->MoveWindow(&LogRect);
|
|
1080 |
|
|
1081 |
//CalButtonsLayerOut();
|
|
1082 |
RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0);
|
|
1083 |
|
|
1084 |
|
|
1085 |
return 0;
|
|
1086 |
}
|
|
1087 |
|
|
1088 |
int CMTerm1CommDevView::MonitorPLC()
|
|
1089 |
{
|
|
1090 |
CMTerm1Doc *pDoc = (CMTerm1Doc *)GetDocument();
|
|
1091 |
|
|
1092 |
if (m_bMonitoring && pDoc->MyKLink1.MySerPort1.m_bOpened)
|
|
1093 |
{
|
|
1094 |
unsigned char DstAddr = 1;
|
|
1095 |
unsigned char DataType = pDoc->MyKLink1.KLDataTypeSDT;
|
|
1096 |
unsigned short DAddr = 0;
|
|
1097 |
unsigned char DCount = 32;
|
|
1098 |
// unsigned char Data1[256];
|
|
1099 |
unsigned char ExtFrameLen = 0;
|
|
1100 |
|
|
1101 |
unsigned short nCount;
|
|
1102 |
CString s1, s2;
|
|
1103 |
MonitorTotalCount++;
|
|
1104 |
int nThisSuccessCount = 0;
|
|
1105 |
int nThisFailCount = 0;
|
|
1106 |
int res;
|
|
1107 |
static int nStep = 0;
|
|
1108 |
// WX
|
|
1109 |
///*
|
|
1110 |
if (nStep == 0)
|
|
1111 |
{
|
|
1112 |
DataType = pDoc->MyKLink1.KLDataTypeWX;
|
|
1113 |
DCount = 16;
|
|
1114 |
res = pDoc->MyKLink1.ReadDataByte(DstAddr, DataType, DAddr, DCount, &nCount, &pDoc->MyKLink1.MEM.WXB[DAddr]);
|
|
1115 |
nCount = DCount;
|
|
1116 |
if (res == pDoc->MyKLink1.KL_OK)
|
|
1117 |
{
|
|
1118 |
nThisSuccessCount++;
|
|
1119 |
}
|
|
1120 |
else
|
|
1121 |
{
|
|
1122 |
nThisFailCount++;
|
|
1123 |
s1.Format(_T("R:= %d %s \r\n"), res, pDoc->MyKLink1.m_resultStr);
|
|
1124 |
SysLog(s1);
|
|
1125 |
}
|
|
1126 |
|
|
1127 |
}
|
|
1128 |
//*/
|
|
1129 |
|
|
1130 |
///*
|
|
1131 |
//WY
|
|
1132 |
if (nStep == 0)
|
|
1133 |
{
|
|
1134 |
DataType = pDoc->MyKLink1.KLDataTypeWY;
|
|
1135 |
DCount = 16;
|
|
1136 |
res = pDoc->MyKLink1.ReadDataByte(DstAddr, DataType, DAddr, DCount, &nCount, &pDoc->MyKLink1.MEM.WYB[DAddr]);
|
|
1137 |
nCount = DCount;
|
|
1138 |
if (res == pDoc->MyKLink1.KL_OK)
|
|
1139 |
{
|
|
1140 |
nThisSuccessCount++;
|
|
1141 |
}
|
|
1142 |
else
|
|
1143 |
{
|
|
1144 |
nThisFailCount++;
|
|
1145 |
s1.Format(_T("R:= %d %s \r\n"), res, pDoc->MyKLink1.m_resultStr);
|
|
1146 |
SysLog(s1);
|
|
1147 |
}
|
|
1148 |
//*/
|
|
1149 |
}
|
|
1150 |
///*
|
|
1151 |
//WR
|
|
1152 |
if (nStep==0)
|
|
1153 |
{
|
|
1154 |
DataType = pDoc->MyKLink1.KLDataTypeWR;
|
|
1155 |
DCount = 32;
|
|
1156 |
res = pDoc->MyKLink1.ReadDataByte(DstAddr, DataType, DAddr, DCount, &nCount, &pDoc->MyKLink1.MEM.WRB[DAddr]);
|
|
1157 |
nCount = DCount;
|
|
1158 |
if (res == pDoc->MyKLink1.KL_OK)
|
|
1159 |
{
|
|
1160 |
nThisSuccessCount++;
|
|
1161 |
}
|
|
1162 |
else
|
|
1163 |
{
|
|
1164 |
nThisFailCount++;
|
|
1165 |
s1.Format(_T("R:= %d %s \r\n"), res, pDoc->MyKLink1.m_resultStr);
|
|
1166 |
SysLog(s1);
|
|
1167 |
}
|
|
1168 |
}
|
|
1169 |
//*/
|
|
1170 |
//DT
|
|
1171 |
if (nStep == 1)
|
|
1172 |
{
|
|
1173 |
DataType = pDoc->MyKLink1.KLDataTypeDT;
|
|
1174 |
DCount = 96;
|
|
1175 |
res = pDoc->MyKLink1.ReadDataByte(DstAddr, DataType, DAddr, DCount, &nCount, &pDoc->MyKLink1.MEM.DTB[DAddr]);
|
|
1176 |
nCount = DCount;
|
|
1177 |
if (res == pDoc->MyKLink1.KL_OK)
|
|
1178 |
{
|
|
1179 |
nThisSuccessCount++;
|
|
1180 |
}
|
|
1181 |
else
|
|
1182 |
{
|
|
1183 |
nThisFailCount++;
|
|
1184 |
s1.Format(_T("R:= %d %s \r\n"), res, pDoc->MyKLink1.m_resultStr);
|
|
1185 |
SysLog(s1);
|
|
1186 |
}
|
|
1187 |
|
|
1188 |
}
|
|
1189 |
int ByteAddr = 0;
|
|
1190 |
//SDT
|
|
1191 |
if (nStep >= 2 && nStep <= 4)
|
|
1192 |
{
|
|
1193 |
int nBlock = nStep - 2;
|
|
1194 |
DataType = pDoc->MyKLink1.KLDataTypeSDT;
|
|
1195 |
ByteAddr = nBlock * 128;
|
|
1196 |
DCount = 128;
|
|
1197 |
res = pDoc->MyKLink1.ReadDataByte(DstAddr, DataType, ByteAddr, DCount, &nCount, &pDoc->MyKLink1.MEM.SDB[ByteAddr]);
|
|
1198 |
nCount = DCount;
|
|
1199 |
if (res == pDoc->MyKLink1.KL_OK)
|
|
1200 |
{
|
|
1201 |
for (int i = 0; i < DCount; i++) { SDTbuf[ByteAddr + i] = pDoc->MyKLink1.MEM.SDB[ByteAddr + i]; }
|
|
1202 |
nThisSuccessCount++;
|
|
1203 |
}
|
|
1204 |
else
|
|
1205 |
{
|
|
1206 |
nThisFailCount++;
|
|
1207 |
s1.Format(_T("R:= %d %s \r\n"), res, pDoc->MyKLink1.m_resultStr);
|
|
1208 |
SysLog(s1);
|
|
1209 |
}
|
|
1210 |
}
|
|
1211 |
if (nStep >= 5 && nStep <= 7)
|
|
1212 |
{
|
|
1213 |
int nBlock = nStep - 5;
|
|
1214 |
DataType = pDoc->MyKLink1.KLDataTypeWDT;
|
|
1215 |
ByteAddr = nBlock * 128;
|
|
1216 |
DCount = 128;
|
|
1217 |
res = pDoc->MyKLink1.ReadDataByte(DstAddr, DataType, ByteAddr, DCount, &nCount, &pDoc->MyKLink1.MEM.WDB[ByteAddr]);
|
|
1218 |
nCount = DCount;
|
|
1219 |
if (res == pDoc->MyKLink1.KL_OK)
|
|
1220 |
{
|
|
1221 |
for (int i = 0; i < DCount; i++) { WDTbuf[ByteAddr + i] = pDoc->MyKLink1.MEM.WDB[ByteAddr + i]; }
|
|
1222 |
nThisSuccessCount++;
|
|
1223 |
}
|
|
1224 |
else
|
|
1225 |
{
|
|
1226 |
nThisFailCount++;
|
|
1227 |
s1.Format(_T("R:= %d %s \r\n"), res, pDoc->MyKLink1.m_resultStr);
|
|
1228 |
SysLog(s1);
|
|
1229 |
}
|
|
1230 |
}
|
|
1231 |
|
|
1232 |
if (nStep >= 8 && nStep <= 13)
|
|
1233 |
{
|
|
1234 |
int nBlock = nStep - 8;
|
|
1235 |
DataType = pDoc->MyKLink1.KLDataTypeKBD;
|
|
1236 |
ByteAddr = nBlock * 128;
|
|
1237 |
DCount = 128;
|
|
1238 |
res = pDoc->MyKLink1.ReadDataByte(DstAddr, DataType, ByteAddr, DCount, &nCount, &pDoc->KBDB[ByteAddr]);
|
|
1239 |
nCount = DCount;
|
|
1240 |
if (res == pDoc->MyKLink1.KL_OK)
|
|
1241 |
{
|
|
1242 |
//for (int i = 0; i < DCount; i++) { WDTbuf[ByteAddr + i] = pDoc->MyKLink1.MEM.WDB[ByteAddr + i]; }
|
|
1243 |
nThisSuccessCount++;
|
|
1244 |
}
|
|
1245 |
else
|
|
1246 |
{
|
|
1247 |
nThisFailCount++;
|
|
1248 |
s1.Format(_T("R:= %d %s \r\n"), res, pDoc->MyKLink1.m_resultStr);
|
|
1249 |
SysLog(s1);
|
|
1250 |
}
|
|
1251 |
}
|
|
1252 |
if (nStep >= 14 && nStep <= 14)
|
|
1253 |
{
|
|
1254 |
int nBlock = nStep - 14;
|
|
1255 |
DataType = pDoc->MyKLink1.KLDataTypeKWLD;
|
|
1256 |
ByteAddr = nBlock * 128;
|
|
1257 |
DCount = 128;
|
|
1258 |
res = pDoc->MyKLink1.ReadDataByte(DstAddr, DataType, ByteAddr, DCount, &nCount, &pDoc->KWLB[ByteAddr]);
|
|
1259 |
nCount = DCount;
|
|
1260 |
if (res == pDoc->MyKLink1.KL_OK)
|
|
1261 |
{
|
|
1262 |
//for (int i = 0; i < DCount; i++) { WDTbuf[ByteAddr + i] = pDoc->MyKLink1.MEM.WDB[ByteAddr + i]; }
|
|
1263 |
nThisSuccessCount++;
|
|
1264 |
}
|
|
1265 |
else
|
|
1266 |
{
|
|
1267 |
nThisFailCount++;
|
|
1268 |
s1.Format(_T("R:= %d %s \r\n"), res, pDoc->MyKLink1.m_resultStr);
|
|
1269 |
SysLog(s1);
|
|
1270 |
}
|
|
1271 |
}
|
|
1272 |
|
|
1273 |
nStep++;
|
|
1274 |
// if (nStep == 2) { nStep = 3; }
|
|
1275 |
if (nStep > 14) { nStep = 0; }
|
|
1276 |
MonitorSuccessCount += nThisSuccessCount;
|
|
1277 |
MonitorFailCount += nThisFailCount;
|
|
1278 |
if (nThisFailCount == 0)
|
|
1279 |
{
|
|
1280 |
|
|
1281 |
|
|
1282 |
}
|
|
1283 |
else
|
|
1284 |
{
|
|
1285 |
|
|
1286 |
}
|
|
1287 |
}
|
|
1288 |
return 0;
|
|
1289 |
}
|
|
1290 |
void CMTerm1CommDevView::OnClose()
|
|
1291 |
{
|
|
1292 |
// TODO: 在此添加消息处理程序代码和/或调用默认值
|
|
1293 |
// if (pHvCamera1 != nullptr) { delete pHvCamera1; pHvCamera1 = nullptr; }
|
|
1294 |
MyThreadProc1ToRun = 0;
|
|
1295 |
CloseResource();
|
|
1296 |
GetParams();
|
|
1297 |
SaveMyConfig();
|
|
1298 |
Sleep(100);
|
|
1299 |
|
|
1300 |
CFormView::OnClose();
|
|
1301 |
}
|
|
1302 |
|
|
1303 |
int DrawCross(HWND hWnd1, int handx, int handy)
|
|
1304 |
{
|
|
1305 |
///*
|
|
1306 |
using namespace Gdiplus;
|
|
1307 |
CRect rect1;
|
|
1308 |
GetClientRect(hWnd1, &rect1);
|
|
1309 |
|
|
1310 |
int ClientWidth = rect1.Width();
|
|
1311 |
int ClientHeight = rect1.Height();
|
|
1312 |
int CenterX = ClientWidth / 2;
|
|
1313 |
int CenterY = ClientHeight / 2;
|
|
1314 |
|
|
1315 |
|
|
1316 |
int ZeroRage = 14;
|
|
1317 |
int rZeroRage = ZeroRage * ClientWidth / 256;
|
|
1318 |
Bitmap bmp1(ClientWidth, ClientHeight);
|
|
1319 |
Graphics gr1(&bmp1);
|
|
1320 |
|
|
1321 |
gr1.Clear(Gdiplus::Color::White);
|
|
1322 |
|
|
1323 |
Pen pen1(Color::Gray, 1);
|
|
1324 |
Pen pen2(Color::Black, 2);
|
|
1325 |
//画大十字线
|
|
1326 |
gr1.DrawLine(&pen1, 0, CenterY, ClientWidth, CenterY);
|
|
1327 |
gr1.DrawLine(&pen1, CenterX, 0, CenterX, ClientHeight);
|
|
1328 |
|
|
1329 |
//画中心零点的范围
|
|
1330 |
gr1.DrawRectangle(&pen1, CenterX - rZeroRage, CenterY - rZeroRage, rZeroRage * 2, rZeroRage * 2);
|
|
1331 |
|
|
1332 |
//画允许框的范围
|
|
1333 |
gr1.DrawRectangle(&pen1, ClientWidth * 10 / 100, ClientHeight * 10 / 100, ClientWidth * 80 / 100, ClientHeight * 80 / 100);
|
|
1334 |
|
|
1335 |
//画小十字线
|
|
1336 |
int curx = handx * ClientWidth / 256;
|
|
1337 |
int cury = (255 - handy) *ClientHeight / 256;
|
|
1338 |
|
|
1339 |
if (curx < 0) { curx = 0; }
|
|
1340 |
if (curx > ClientWidth) { curx = ClientWidth; }
|
|
1341 |
if (cury < 0) { cury = 0; }
|
|
1342 |
if (cury > ClientHeight) { cury = ClientHeight; }
|
|
1343 |
|
|
1344 |
gr1.DrawLine(&pen2, curx - 8, cury, curx + 8, cury);
|
|
1345 |
gr1.DrawLine(&pen2, curx, cury - 8, curx, cury + 8);
|
|
1346 |
|
|
1347 |
HDC hdc1 = GetDC(hWnd1);
|
|
1348 |
SetTextColor(hdc1, 0x00c0c0c0);
|
|
1349 |
SetBkColor(hdc1, 0x00000000);
|
|
1350 |
|
|
1351 |
Graphics gr2(hdc1);
|
|
1352 |
gr2.DrawImage(&bmp1, 0, 0);
|
|
1353 |
ReleaseDC(hWnd1, hdc1);
|
|
1354 |
|
|
1355 |
return 0;
|
|
1356 |
}
|
|
1357 |
|
|
1358 |
DWORD WINAPI CMTerm1CommDevView::MyThreadProc1(LPVOID pParam)
|
|
1359 |
{
|
|
1360 |
CString s1, s2;
|
|
1361 |
SysLog(_T("线程开始运行\r\n"));
|
|
1362 |
MyThreadProc1Running = 1;
|
|
1363 |
CMTerm1Doc *pDoc = (CMTerm1Doc *)GetDocument();
|
|
1364 |
|
|
1365 |
|
|
1366 |
/*
|
|
1367 |
static OVERLAPPED ovlap1, ovlap2;
|
|
1368 |
COMMTIMEOUTS ctimeout1;
|
|
1369 |
|
|
1370 |
|
|
1371 |
ovlap1.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
|
|
1372 |
ovlap2.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
|
|
1373 |
memset(&ctimeout1, 0, sizeof(ctimeout1));
|
|
1374 |
ctimeout1.ReadIntervalTimeout = 1;
|
|
1375 |
ctimeout1.ReadTotalTimeoutMultiplier = 0;
|
|
1376 |
ctimeout1.ReadTotalTimeoutConstant = 1;
|
|
1377 |
ctimeout1.WriteTotalTimeoutConstant = 0;
|
|
1378 |
ctimeout1.WriteTotalTimeoutMultiplier = 0;
|
|
1379 |
*/
|
|
1380 |
|
|
1381 |
//s2.GetLength();
|
|
1382 |
// memcpy(send1,s2,bytetosend1);
|
|
1383 |
|
|
1384 |
pDoc->MyAnsiParser1.AttachWnd(m_edit_display.GetSafeHwnd());
|
|
1385 |
pDoc->MyAnsiParser1.SetScreenWH(150, 40);
|
|
1386 |
|
|
1387 |
// CClientDC hcurDC(this);
|
|
1388 |
HWND hDrawXY = GetDlgItem(IDC_STATIC_DRAW_XY)->m_hWnd;
|
|
1389 |
|
|
1390 |
int handx = 0, handy = 0;
|
|
1391 |
int oldhandx = 0, oldhandy = 0;
|
|
1392 |
|
|
1393 |
|
|
1394 |
SysLog(_T("准备接收\r\n"));
|
|
1395 |
DWORD dNumtoRead = 1000;
|
|
1396 |
dNumtoRead = 64;
|
|
1397 |
nDataToSend = 0;
|
|
1398 |
DWORD wCount2 = 0;
|
|
1399 |
DWORD dwSent = 0;
|
|
1400 |
int nRunCount = 0;
|
|
1401 |
int nTotalRecv = 0;
|
|
1402 |
//计算接收速度;
|
|
1403 |
|
|
1404 |
int LastSpeedTime = (int)GetTickCountmS();
|
|
1405 |
int nThisRecv = 0;
|
|
1406 |
double AvgSpeed = 0;
|
|
1407 |
double CurSpeed = 0;
|
|
1408 |
long nCount1 = 0;
|
|
1409 |
int LastSendLength = 0;
|
|
1410 |
unsigned char databuf1[256];
|
|
1411 |
for (; MyThreadProc1ToRun == 1;)
|
|
1412 |
{
|
|
1413 |
// AppendText("H");
|
|
1414 |
nCount1++;
|
|
1415 |
if (BulkSendTest == 1)
|
|
1416 |
{
|
|
1417 |
//nDataToSend += 400;
|
|
1418 |
nDataToSend = LastSendLength;
|
|
1419 |
// s1.Format(_T("BulkToSend %d Bytes"), nDataToSend);
|
|
1420 |
// SysLog(s1);
|
|
1421 |
dwSent = pDoc->MyKLink1.SendPacket((char *)send1, nDataToSend);
|
|
1422 |
s1.Format(_T("S %d ->"), nDataToSend);
|
|
1423 |
for (int i = 0; i < nDataToSend; i++)
|
|
1424 |
{
|
|
1425 |
s1.AppendFormat(_T("%02X "), send1[i]);
|
|
1426 |
}
|
|
1427 |
// SysLog(s1);
|
|
1428 |
//WriteFile(hCom, send1, nDataToSend, &dwSent, NULL);
|
|
1429 |
nDataToSend = 0;
|
|
1430 |
//continue;
|
|
1431 |
}
|
|
1432 |
int SendAndRead = 0;
|
|
1433 |
if (nDataToSend > 0)
|
|
1434 |
{
|
|
1435 |
s1.Format(_T("ToSend %d Bytes"), nDataToSend);
|
|
1436 |
SysLog(s1);
|
|
1437 |
dwSent = pDoc->MyKLink1.SendPacket((char *)send1, nDataToSend);
|
|
1438 |
s1.Format(_T("S %d ->"), nDataToSend);
|
|
1439 |
for (int i = 0; i < nDataToSend; i++)
|
|
1440 |
{
|
|
1441 |
s1.AppendFormat(_T("%02X "), send1[i]);
|
|
1442 |
}
|
|
1443 |
SysLog(s1);
|
|
1444 |
SendAndRead = 1;
|
|
1445 |
//WriteFile(hCom, send1, nDataToSend, &dwSent, NULL);
|
|
1446 |
LastSendLength = nDataToSend;
|
|
1447 |
nDataToSend = 0;
|
|
1448 |
}
|
|
1449 |
// ResetEvent(ovlap2.hEvent);
|
|
1450 |
if (SendAndRead == 1)
|
|
1451 |
{
|
|
1452 |
s1.Format(_T("Start to Read %d "), dNumtoRead);
|
|
1453 |
SysLog(s1);
|
|
1454 |
}
|
|
1455 |
//ReadFile(hCom, recv1, dNumtoRead, &wCount2, &ovlap2);
|
|
1456 |
wCount2 = pDoc->MyKLink1.RecvPacket((char *)recv1, dNumtoRead);
|
|
1457 |
// WaitForSingleObject(ovlap2.hEvent,800);
|
|
1458 |
// GetOverlappedResult(hCom,&ovlap2,&wCount2,TRUE);
|
|
1459 |
if (wCount2 == 0) continue;
|
|
1460 |
// continue;
|
|
1461 |
int ThisTime = static_cast <int> (GetTickCountmS());
|
|
1462 |
// s3.Format("%d %d ",recv2length,wCount2);AppendText(s3);
|
|
1463 |
nTotalRecv += wCount2;
|
|
1464 |
nThisRecv += wCount2;
|
|
1465 |
s1.Format(_T("R %d ->"), wCount2);
|
|
1466 |
for (DWORD i = 0; i < wCount2; i++)
|
|
1467 |
{
|
|
1468 |
s1.AppendFormat(_T("%02X "), recv1[i]);
|
|
1469 |
}
|
|
1470 |
unsigned char nCmd, nStatus;
|
|
1471 |
unsigned short nCount;
|
|
1472 |
|
|
1473 |
s1.Append(_T("\r\n"));
|
|
1474 |
// SysLog(s1);
|
|
1475 |
//continue;
|
|
1476 |
pDoc->MyKLink1.ParseRplyPacket(recv1, wCount2, &nCmd, &nStatus, &nCount, databuf1);
|
|
1477 |
|
|
1478 |
s1.Format(_T("R-> Cmd:%02X Status:%04X Count:%02d \r\nData: "), nCmd, nStatus, nCount);
|
|
1479 |
s2.Empty();
|
|
1480 |
for (int i = 0; i < nCount; i++)
|
|
1481 |
{
|
|
1482 |
s2.AppendFormat(_T("%02X "), databuf1[i]);
|
|
1483 |
}
|
|
1484 |
// SetDlgItemText(IDC_EDIT_DATA2, s2);
|
|
1485 |
s1.Append(s2);
|
|
1486 |
s1.Append(_T("\r\n"));
|
|
1487 |
SysLog(s1);
|
|
1488 |
int HasData = pDoc->MyDataParser1.PutIn(recv1, wCount2);
|
|
1489 |
CStringA sA1;
|
|
1490 |
TToAnsi(s1, sA1);
|
|
1491 |
// MyAnsiParser1.PutIn((unsigned char *)sA1.GetBuffer(), sA1.GetLength()); sA1.ReleaseBuffer();
|
|
1492 |
// MyAnsiParser1.PutIn(recv1, wCount2);
|
|
1493 |
if (HasData)
|
|
1494 |
{
|
|
1495 |
pDoc->MyDataParser1.GetOutput(&handx, &handy);
|
|
1496 |
if (oldhandx != handx || oldhandy != handy)
|
|
1497 |
{
|
|
1498 |
DrawCross(hDrawXY, handx, handy);
|
|
1499 |
oldhandx = handx;
|
|
1500 |
oldhandy = handy;
|
|
1501 |
}
|
|
1502 |
|
|
1503 |
// m_edit2.SetSel(currenty*82+currentx,currenty*82+currentx+1,FALSE);
|
|
1504 |
s1.Format(_T("X=%3d(%2d%%) Y=%3d(%2d%%)"), handx, handx * 100 / 256, handy, handy * 100 / 256);
|
|
1505 |
SetDlgItemText(IDC_STATIC_STAT_XY, s1);
|
|
1506 |
// GetWindowDlg(IDC_STATIC5)->SetWindowText("X: Y:");
|
|
1507 |
}
|
|
1508 |
nRunCount++;
|
|
1509 |
|
|
1510 |
if (ThisTime - LastSpeedTime > 500)
|
|
1511 |
{
|
|
1512 |
CurSpeed = (double)nThisRecv / (ThisTime - LastSpeedTime);
|
|
1513 |
nThisRecv = 0;
|
|
1514 |
LastSpeedTime = ThisTime;
|
|
1515 |
}
|
|
1516 |
s1.Format(_T("Runing %d \r %.3fkBps"), nRunCount, CurSpeed);
|
|
1517 |
SetDlgItemText(IDC_STATIC_STATUS_CON, s1);
|
|
1518 |
//SysLog(_T("."));
|
|
1519 |
|
|
1520 |
}
|
|
1521 |
SysLog(_T("跳出接收循环\r\n"));
|
|
1522 |
// hcurDC.SelectObject(def_font);
|
|
1523 |
// CloseHandle(hCom);
|
|
1524 |
SysLog(_T("线程结束运行\r\n\r\n"));
|
|
1525 |
MyThreadProc1Running = 0;
|
|
1526 |
return 0;
|
|
1527 |
}
|
|
1528 |
|
|
1529 |
UINT CMTerm1CommDevView::MyJumper1(LPVOID pParam) //线程跳板
|
|
1530 |
{
|
|
1531 |
CMTerm1CommDevView *pInput = (CMTerm1CommDevView *)pParam; //反跳到真正的执行程序
|
|
1532 |
return pInput->MyThreadProc1(0);
|
|
1533 |
}
|
|
1534 |
|
|
1535 |
void CMTerm1CommDevView::OnBnClickedButtonConnect()
|
|
1536 |
{
|
|
1537 |
OnMenuOnline();
|
|
1538 |
if (!m_bResourceOpened)
|
|
1539 |
{
|
|
1540 |
return;
|
|
1541 |
}
|
|
1542 |
m_bMonitoring = false;
|
|
1543 |
// TODO: 在此添加控件通知处理程序代码
|
|
1544 |
}
|
|
1545 |
|
|
1546 |
void CMTerm1CommDevView::OnBnClickedButtonDisconnect()
|
|
1547 |
{
|
|
1548 |
OnMenuOffline();
|
|
1549 |
m_bMonitoring = false;
|
|
1550 |
if (!m_bResourceOpened)
|
|
1551 |
{
|
|
1552 |
return;
|
|
1553 |
}
|
|
1554 |
// TODO: 在此添加控件通知处理程序代码
|
|
1555 |
}
|
|
1556 |
|
|
1557 |
void CMTerm1CommDevView::OnBnClickedButtonStart()
|
|
1558 |
{
|
|
1559 |
// TODO: 在此添加控件通知处理程序代码
|
|
1560 |
OnMenuOnline();
|
|
1561 |
if (!m_bResourceOpened)
|
|
1562 |
{
|
|
1563 |
return;
|
|
1564 |
}
|
|
1565 |
m_bMonitoring = false;
|
|
1566 |
OnMenuMonitor();
|
|
1567 |
return;
|
|
1568 |
if (MyThreadProc1ToRun == 1 || MyThreadProc1Running == 1)
|
|
1569 |
{
|
|
1570 |
SysLog(_T("线程在运行中,不能再次运行\r\n"));
|
|
1571 |
}
|
|
1572 |
else
|
|
1573 |
{
|
|
1574 |
MyThreadProc1ToRun = 1;
|
|
1575 |
AfxBeginThread(MyJumper1, (LPVOID)this);
|
|
1576 |
}
|
|
1577 |
|
|
1578 |
}
|
|
1579 |
|
|
1580 |
void CMTerm1CommDevView::OnBnClickedButtonStop()
|
|
1581 |
{
|
|
1582 |
// TODO: 在此添加控件通知处理程序代码
|
|
1583 |
CMTerm1Doc *pDoc = (CMTerm1Doc *)GetDocument();
|
|
1584 |
|
|
1585 |
m_bMonitoring = true;
|
|
1586 |
OnMenuMonitor();
|
|
1587 |
// OnMenuOffline();
|
|
1588 |
|
|
1589 |
return;
|
|
1590 |
if (MyThreadProc1Running)
|
|
1591 |
{
|
|
1592 |
if (MyThreadProc1ToRun)
|
|
1593 |
{
|
|
1594 |
SysLog(_T("停止线程运行\r\n"));
|
|
1595 |
MyThreadProc1ToRun = 0;
|
|
1596 |
}
|
|
1597 |
else
|
|
1598 |
{
|
|
1599 |
SysLog(_T("线程停止中\r\n"));
|
|
1600 |
}
|
|
1601 |
}
|
|
1602 |
else
|
|
1603 |
{
|
|
1604 |
SysLog(_T("线程未运行\r\n"));
|
|
1605 |
}
|
|
1606 |
pDoc->MyKLink1.Close();
|
|
1607 |
}
|
|
1608 |
|
|
1609 |
|
|
1610 |
void CMTerm1CommDevView::OnBnClickedButtonClrscr()
|
|
1611 |
{
|
|
1612 |
// TODO: 在此添加控件通知处理程序代码
|
|
1613 |
CMTerm1Doc *pDoc = (CMTerm1Doc *)GetDocument();
|
|
1614 |
CString s1;
|
|
1615 |
s1.Format(_T("Clear Screen \r\n"));
|
|
1616 |
SysLog(s1);
|
|
1617 |
pDoc->MyAnsiParser1.ClrScreen();
|
|
1618 |
}
|
|
1619 |
|
|
1620 |
|
|
1621 |
void CMTerm1CommDevView::OnBnClickedButtonSend()
|
|
1622 |
{
|
|
1623 |
// TODO: 在此添加控件通知处理程序代码
|
|
1624 |
|
|
1625 |
CString s1, sInput;
|
|
1626 |
//get text
|
|
1627 |
m_combo_input.GetWindowText(sInput);
|
|
1628 |
int j = m_combo_input.SelectString(0, sInput);
|
|
1629 |
if (j == -1)
|
|
1630 |
{
|
|
1631 |
m_combo_input.InsertString(-1, sInput);
|
|
1632 |
int k = m_combo_input.GetCount();
|
|
1633 |
m_combo_input.SetCurSel(k - 1);
|
|
1634 |
}
|
|
1635 |
else
|
|
1636 |
{
|
|
1637 |
m_combo_input.GetWindowText(s1);
|
|
1638 |
if (s1 != sInput)
|
|
1639 |
{
|
|
1640 |
m_combo_input.InsertString(-1, sInput);
|
|
1641 |
int k = m_combo_input.GetCount();
|
|
1642 |
m_combo_input.SetCurSel(k - 1);
|
|
1643 |
}
|
|
1644 |
}
|
|
1645 |
int res = 0;
|
|
1646 |
|
|
1647 |
// send text;
|
|
1648 |
|
|
1649 |
if (nDataToSend == 0)
|
|
1650 |
{
|
|
1651 |
CStringA sA1;
|
|
1652 |
TToAnsi(sInput, sA1);
|
|
1653 |
int k = sA1.GetLength();
|
|
1654 |
memcpy(send1, sA1.GetBuffer(), k);
|
|
1655 |
sA1.ReleaseBuffer();
|
|
1656 |
nDataToSend = k;
|
|
1657 |
res = 1;
|
|
1658 |
}
|
|
1659 |
else
|
|
1660 |
{
|
|
1661 |
|
|
1662 |
}
|
|
1663 |
s1.Format(_T("Send Cmd %s %d %d\r\n"), sInput, sInput.GetLength(), res);
|
|
1664 |
SysLog(s1);
|
|
1665 |
|
|
1666 |
}
|
|
1667 |
|
|
1668 |
void CMTerm1CommDevView::OnCbnSelchangeComboRes()
|
|
1669 |
{
|
|
1670 |
// TODO: 在此添加控件通知处理程序代码
|
|
1671 |
}
|
|
1672 |
|
|
1673 |
void CMTerm1CommDevView::OnCbnEditchangeComboInput()
|
|
1674 |
{
|
|
1675 |
// TODO: 在此添加控件通知处理程序代码
|
|
1676 |
CString s1;
|
|
1677 |
// s1.Format(_T("Combo_Input Edit Changed \r\n"));
|
|
1678 |
// SysLog(s1);
|
|
1679 |
}
|
|
1680 |
|
|
1681 |
void CMTerm1CommDevView::OnBnClickedButtonDo()
|
|
1682 |
{
|
|
1683 |
// TODO: 在此添加控件通知处理程序代码
|
|
1684 |
CMTerm1Doc *pDoc = (CMTerm1Doc *)GetDocument();
|
|
1685 |
|
|
1686 |
unsigned char buf1[256];
|
|
1687 |
unsigned char buf2[256];
|
|
1688 |
unsigned char Data1[256];
|
|
1689 |
unsigned char Data2[256];
|
|
1690 |
CString s1, sInput;
|
|
1691 |
CString MAddrStr;
|
|
1692 |
CString CMDstr;
|
|
1693 |
CString TypeStr;
|
|
1694 |
CString DAddrStr;
|
|
1695 |
CString DCountStr;
|
|
1696 |
CString Data1Str;
|
|
1697 |
|
|
1698 |
GetDlgItemText(IDC_COMBO_MADDR, MAddrStr);
|
|
1699 |
GetDlgItemText(IDC_COMBO_CMD, CMDstr);
|
|
1700 |
GetDlgItemText(IDC_COMBO_CMD_TYPE, TypeStr);
|
|
1701 |
GetDlgItemText(IDC_COMBO_DADDR, DAddrStr);
|
|
1702 |
GetDlgItemText(IDC_COMBO_DCOUNT, DCountStr);
|
|
1703 |
GetDlgItemText(IDC_EDIT_DATA1, Data1Str);
|
|
1704 |
|
|
1705 |
int DstAddr = _tstoi(MAddrStr);
|
|
1706 |
int Cmd = _tstoi(CMDstr);
|
|
1707 |
int DataType = _tstoi(TypeStr);
|
|
1708 |
int DAddr = _tstoi(DAddrStr);
|
|
1709 |
int DCount = _tstoi(DCountStr);
|
|
1710 |
|
|
1711 |
CString Resultstrs[100];
|
|
1712 |
int j = Split(Data1Str, _T(" "), Resultstrs);
|
|
1713 |
for (int i = 0; i < j; i++)
|
|
1714 |
{
|
|
1715 |
Data1[i] = Xtoi(Resultstrs[i]);
|
|
1716 |
}
|
|
1717 |
|
|
1718 |
|
|
1719 |
int bExtData = ((CButton *)GetDlgItem(IDC_CHECK_EXT_DATA))->GetCheck();
|
|
1720 |
CString ExtDataDstStr;
|
|
1721 |
CString ExtDataTypeStr;
|
|
1722 |
CString ExtDataLenStr;
|
|
1723 |
CString ExtDataStr;
|
|
1724 |
GetDlgItemText(IDC_COMBO_EXT_DST, ExtDataDstStr);
|
|
1725 |
GetDlgItemText(IDC_COMBO_EXT_TYPE, ExtDataTypeStr);
|
|
1726 |
GetDlgItemText(IDC_COMBO_EXT_DATA_LEN, ExtDataLenStr);
|
|
1727 |
GetDlgItemText(IDC_EDIT_EXT_DATA1, ExtDataStr);
|
|
1728 |
|
|
1729 |
int ExtDataDst = _tstoi(ExtDataDstStr);
|
|
1730 |
int ExtDataType = _tstoi(ExtDataTypeStr);
|
|
1731 |
int ExtDataLen = _tstoi(ExtDataLenStr);
|
|
1732 |
|
|
1733 |
j = Split(ExtDataStr, _T(" "), Resultstrs);
|
|
1734 |
for (int i = 0; i < j; i++)
|
|
1735 |
{
|
|
1736 |
Data2[i] = Xtoi(Resultstrs[i]);
|
|
1737 |
}
|
|
1738 |
|
|
1739 |
int ExtFrameLen = pDoc->MyKLink1.MakeExtDataFrame(buf2, ExtDataDst, ExtDataType, ExtDataLen, Data2);
|
|
1740 |
|
|
1741 |
KLink1::unKLStat nStat1 = { 0 };
|
|
1742 |
nStat1.HasExt = bExtData;
|
|
1743 |
nStat1.nSEQ = pDoc->MyKLink1.GetNextSeq();
|
|
1744 |
// Cmd += 0x30; //KLink::cmdRead
|
|
1745 |
int len1 = pDoc->MyKLink1.MakeReqPacketEx(buf1, DstAddr, nStat1.StatByte, Cmd, DataType, DAddr, DCount, Data1, ExtFrameLen, buf2);
|
|
1746 |
s1.Format(_T("S %d ->"), len1);
|
|
1747 |
int res = 0;
|
|
1748 |
int SendType = 1;
|
|
1749 |
if (SendType == 1)
|
|
1750 |
{
|
|
1751 |
res = pDoc->MyKLink1.SendPacket((char *)buf1, len1);
|
|
1752 |
for (int i = 0; i < len1; i++)
|
|
1753 |
{
|
|
1754 |
s1.AppendFormat(_T("%02X "), buf1[i]);
|
|
1755 |
}
|
|
1756 |
|
|
1757 |
}
|
|
1758 |
else if (SendType == 2)
|
|
1759 |
{
|
|
1760 |
if (nDataToSend == 0)
|
|
1761 |
{
|
|
1762 |
int k = len1;
|
|
1763 |
memcpy(send1, buf1, k);
|
|
1764 |
nDataToSend = k;
|
|
1765 |
res = 1;
|
|
1766 |
}
|
|
1767 |
}
|
|
1768 |
s1.AppendFormat(_T(" = %d\r\n"), res);
|
|
1769 |
SysLog(s1);
|
|
1770 |
|
|
1771 |
DWORD wCount2;
|
|
1772 |
DWORD dNumtoRead = DCount + 6;;
|
|
1773 |
int numToRead = dNumtoRead;
|
|
1774 |
int len2 = 0;
|
|
1775 |
int nTryCount = 0;
|
|
1776 |
int nTryCount2 = 0;
|
|
1777 |
// 在没有收到数据的情况向,连续重试10次,在收到数据后,又没有数据,再重试3次。
|
|
1778 |
for (int i = 0; i < 10; i++)
|
|
1779 |
{
|
|
1780 |
nTryCount++;
|
|
1781 |
int len = pDoc->MyKLink1.RecvPacket((char *)recv1 + len2, numToRead - len2);
|
|
1782 |
if (len >0) len2 += len;
|
|
1783 |
if (len2 >= numToRead) break;
|
|
1784 |
if (len2 > 0) {
|
|
1785 |
nTryCount2++;
|
|
1786 |
if (len > 0) { nTryCount2 = 0; }
|
|
1787 |
if (nTryCount2 >= 1) break;
|
|
1788 |
}
|
|
1789 |
}
|
|
1790 |
|
|
1791 |
//wCount2 = MySerialCom1.Read((char *)recv1, dNumtoRead);
|
|
1792 |
wCount2 = len2;
|
|
1793 |
// WaitForSingleObject(ovlap2.hEvent,800);
|
|
1794 |
// GetOverlappedResult(hCom,&ovlap2,&wCount2,TRUE);
|
|
1795 |
//if (wCount2 == 0) continue;
|
|
1796 |
// continue;
|
|
1797 |
int ThisTime = static_cast <int> (GetTickCountmS());
|
|
1798 |
// s3.Format("%d %d ",recv2length,wCount2);AppendText(s3);
|
|
1799 |
|
|
1800 |
s1.Format(_T("R %d(Try %d %d)=%d->"), dNumtoRead, nTryCount, nTryCount2, wCount2);
|
|
1801 |
for (DWORD i = 0; i < 32 && i < wCount2; i++)
|
|
1802 |
{
|
|
1803 |
s1.AppendFormat(_T("%02X "), recv1[i]);
|
|
1804 |
}
|
|
1805 |
s1.Append(_T("... \r\n"));
|
|
1806 |
SysLog(s1);
|
|
1807 |
unsigned char nCmd = 0, nStatus = 0;
|
|
1808 |
unsigned short nCount = 0;
|
|
1809 |
|
|
1810 |
|
|
1811 |
//continue;
|
|
1812 |
unsigned short databuf1[256];
|
|
1813 |
pDoc->MyKLink1.ParseRplyPacket(recv1, wCount2, &nCmd, &nStatus, &nCount, databuf1);
|
|
1814 |
|
|
1815 |
s1.Format(_T("R: Cmd:%02X St:%02X N:%02d D:\r\n"), nCmd, nStatus, nCount);
|
|
1816 |
CString s2;
|
|
1817 |
s2.Empty();
|
|
1818 |
|
|
1819 |
for (int i = 0; i < (nCount + 15) / 16; i++)
|
|
1820 |
{
|
|
1821 |
s2.AppendFormat(_T("%02X: "), i * 16);
|
|
1822 |
for (int j = 0; j < 8 && i * 8 + j < nCount / 2; j++)
|
|
1823 |
{
|
|
1824 |
s2.AppendFormat(_T("%04X"), databuf1[i * 8 + j]);
|
|
1825 |
if (j == 3) { s2.Append(_T(" ")); }
|
|
1826 |
else { s2.Append(_T(" ")); }
|
|
1827 |
}
|
|
1828 |
s2.Append(_T("\r\n"));
|
|
1829 |
}
|
|
1830 |
|
|
1831 |
// for (int i = 0; i < nCount; i++)
|
|
1832 |
// {
|
|
1833 |
// s2.AppendFormat(_T("%02X "), databuf1[i]);
|
|
1834 |
// }
|
|
1835 |
// SetDlgItemText(IDC_EDIT_DATA2, s2);
|
|
1836 |
s1.Append(s2);
|
|
1837 |
// s1.Append(_T("\r\n"));
|
|
1838 |
SysLog(s1);
|
|
1839 |
|
|
1840 |
}
|
|
1841 |
|
|
1842 |
void CMTerm1CommDevView::OnCbnSelchangeComboCmdType()
|
|
1843 |
{
|
|
1844 |
// TODO: 在此添加控件通知处理程序代码
|
|
1845 |
}
|
|
1846 |
|
|
1847 |
|
|
1848 |
void CMTerm1CommDevView::OnCbnSelchangeComboDcount()
|
|
1849 |
{
|
|
1850 |
// TODO: 在此添加控件通知处理程序代码
|
|
1851 |
}
|
|
1852 |
|
|
1853 |
|
|
1854 |
void CMTerm1CommDevView::OnBnClickedButtonStartBulkTest()
|
|
1855 |
{
|
|
1856 |
// TODO: 在此添加控件通知处理程序代码
|
|
1857 |
BulkSendTest = 1;
|
|
1858 |
|
|
1859 |
}
|
|
1860 |
|
|
1861 |
|
|
1862 |
void CMTerm1CommDevView::OnBnClickedButtonStopBulkTest()
|
|
1863 |
{
|
|
1864 |
// TODO: 在此添加控件通知处理程序代码
|
|
1865 |
BulkSendTest = 0;
|
|
1866 |
}
|
|
1867 |
|
|
1868 |
void CMTerm1CommDevView::OnMenuCommset()
|
|
1869 |
{
|
|
1870 |
// TODO: 在此添加命令处理程序代码
|
|
1871 |
CDialogCommSet1 dialog1;
|
|
1872 |
dialog1.DoModal();
|
|
1873 |
|
|
1874 |
}
|
|
1875 |
|
|
1876 |
void CMTerm1CommDevView::OnMenuDownload()
|
|
1877 |
{
|
|
1878 |
// TODO: 在此添加命令处理程序代码
|
|
1879 |
}
|
|
1880 |
|
|
1881 |
|
|
1882 |
void CMTerm1CommDevView::OnMenuUpload()
|
|
1883 |
{
|
|
1884 |
// TODO: 在此添加命令处理程序代码
|
|
1885 |
}
|
|
1886 |
|
|
1887 |
|
|
1888 |
void CMTerm1CommDevView::OnMenuOnline()
|
|
1889 |
{
|
|
1890 |
// TODO: 在此添加命令处理程序代码
|
|
1891 |
CString s1;
|
|
1892 |
s1.Format(_T("切换在线"));
|
|
1893 |
SysLog(s1);
|
|
1894 |
if (m_bOnline)
|
|
1895 |
{
|
|
1896 |
SysLog(_T("已经在线"));
|
|
1897 |
return;
|
|
1898 |
}
|
|
1899 |
int r = OpenResource("");
|
|
1900 |
if (r) {
|
|
1901 |
m_bOnline = true;
|
|
1902 |
// m_wndToolBar.GetToolBarCtrl().CheckDlgButton(ID_MENU_ONLINE, m_bOnline);
|
|
1903 |
// ((CButton *)m_wndToolBar.GetDlgItem(ID_MENU_ONLINE))->SetCheck(m_bOnline);
|
|
1904 |
|
|
1905 |
if (m_bOnline) {
|
|
1906 |
// m_wndToolBar.SetButtonStyle(17, TBBS_CHECKBOX);
|
|
1907 |
// m_wndToolBar.SetButtonStyle(18, TBBS_CHECKED);
|
|
1908 |
}
|
|
1909 |
|
|
1910 |
}
|
|
1911 |
else {
|
|
1912 |
// m_wndToolBar.SetButtonStyle(17, TBBS_CHECKED);
|
|
1913 |
// m_wndToolBar.SetButtonStyle(18, TBBS_CHECKBOX);
|
|
1914 |
}
|
|
1915 |
|
|
1916 |
return;
|
|
1917 |
}
|
|
1918 |
|
|
1919 |
void CMTerm1CommDevView::OnUpdateMenuOnline(CCmdUI *pCmdUI)
|
|
1920 |
{
|
|
1921 |
// TODO: 在此添加命令更新用户界面处理程序代码
|
|
1922 |
pCmdUI->SetCheck(m_bOnline);
|
|
1923 |
// m_wndToolBar.GetToolBarCtrl().CheckDlgButton(ID_MENU_ONLINE, m_bOnline);
|
|
1924 |
|
|
1925 |
}
|
|
1926 |
|
|
1927 |
|
|
1928 |
void CMTerm1CommDevView::OnMenuOffline()
|
|
1929 |
{
|
|
1930 |
// TODO: 在此添加命令处理程序代码
|
|
1931 |
CMTerm1Doc *pDoc = (CMTerm1Doc *)GetDocument();
|
|
1932 |
|
|
1933 |
CString s1;
|
|
1934 |
m_bOnline = false;
|
|
1935 |
// m_wndToolBar.CheckDlgButton(ID_MENU_ONLINE, m_bOnline);
|
|
1936 |
s1.Format(_T("切换离线"));
|
|
1937 |
SysLog(s1);
|
|
1938 |
CloseResource();
|
|
1939 |
return;
|
|
1940 |
|
|
1941 |
if (MyThreadProc1Running)
|
|
1942 |
{
|
|
1943 |
if (MyThreadProc1ToRun)
|
|
1944 |
{
|
|
1945 |
SysLog(_T("停止线程运行\r\n"));
|
|
1946 |
MyThreadProc1ToRun = 0;
|
|
1947 |
}
|
|
1948 |
else
|
|
1949 |
{
|
|
1950 |
SysLog(_T("线程停止中\r\n"));
|
|
1951 |
}
|
|
1952 |
}
|
|
1953 |
else
|
|
1954 |
{
|
|
1955 |
SysLog(_T("线程未运行\r\n"));
|
|
1956 |
}
|
|
1957 |
pDoc->MyKLink1.Close();
|
|
1958 |
}
|
|
1959 |
|
|
1960 |
void CMTerm1CommDevView::OnUpdateMenuOffline(CCmdUI *pCmdUI)
|
|
1961 |
{
|
|
1962 |
// TODO: 在此添加命令更新用户界面处理程序代码
|
|
1963 |
pCmdUI->SetCheck(!m_bOnline);
|
|
1964 |
}
|
|
1965 |
|
|
1966 |
void CMTerm1CommDevView::OnMenuMonitor()
|
|
1967 |
{
|
|
1968 |
// TODO: 在此添加命令处理程序代码
|
|
1969 |
CString s1;
|
|
1970 |
m_bMonitoring = !m_bMonitoring;
|
|
1971 |
s1.Format(_T("切换监控 -> %d"), m_bMonitoring);
|
|
1972 |
SysLog(s1);
|
|
1973 |
}
|
|
1974 |
|
|
1975 |
void CMTerm1CommDevView::OnUpdateMenuMonitor(CCmdUI *pCmdUI)
|
|
1976 |
{
|
|
1977 |
// TODO: 在此添加命令更新用户界面处理程序代码
|
|
1978 |
CString s1;
|
|
1979 |
pCmdUI->SetCheck(m_bMonitoring);
|
|
1980 |
}
|
|
1981 |
|
|
1982 |
void CMTerm1CommDevView::OnMenuRun()
|
|
1983 |
{
|
|
1984 |
// TODO: 在此添加命令处理程序代码
|
|
1985 |
CString s1;
|
|
1986 |
m_bRunning = !m_bRunning;
|
|
1987 |
s1.Format(_T("切换运行 -> %d "), m_bRunning);
|
|
1988 |
SysLog(s1);
|
|
1989 |
}
|
|
1990 |
|
|
1991 |
|
|
1992 |
void CMTerm1CommDevView::OnUpdateMenuRun(CCmdUI *pCmdUI)
|
|
1993 |
{
|
|
1994 |
// TODO: 在此添加命令更新用户界面处理程序代码
|
|
1995 |
pCmdUI->SetCheck(m_bRunning);
|
|
1996 |
}
|
|
1997 |
|
|
1998 |
|
|
1999 |
|
|
2000 |
void CMTerm1CommDevView::OnMenuSysregSet()
|
|
2001 |
{
|
|
2002 |
// TODO: 在此添加命令处理程序代码
|
|
2003 |
CDialogSysRegSet dialog1;
|
|
2004 |
|
|
2005 |
INT_PTR r = dialog1.DoModal();
|
|
2006 |
|
|
2007 |
|
|
2008 |
}
|
|
2009 |
|
|
2010 |
|
|
2011 |
void CMTerm1CommDevView::OnMenuStatusShow()
|
|
2012 |
{
|
|
2013 |
// TODO: 在此添加命令处理程序代码
|
|
2014 |
CDialogStatusShow dialog1;
|
|
2015 |
INT_PTR r = dialog1.DoModal();
|
|
2016 |
|
|
2017 |
|
|
2018 |
}
|
|
2019 |
|
|
2020 |
|
|
2021 |
void CMTerm1CommDevView::OnMenuInfoDisplay()
|
|
2022 |
{
|
|
2023 |
// TODO: 在此添加命令处理程序代码
|
|
2024 |
CDialogInfoDisplay dialog1;
|
|
2025 |
INT_PTR r = dialog1.DoModal();
|
|
2026 |
}
|
|
2027 |
|
|
2028 |
|
|
2029 |
void CMTerm1CommDevView::OnMenuCoilMon()
|
|
2030 |
{
|
|
2031 |
// TODO: 在此添加命令处理程序代码
|
|
2032 |
CDialogCoilMon dialog1;
|
|
2033 |
INT_PTR r = dialog1.DoModal();
|
|
2034 |
}
|
|
2035 |
|
|
2036 |
|
|
2037 |
void CMTerm1CommDevView::OnMenuDataMon()
|
|
2038 |
{
|
|
2039 |
// TODO: 在此添加命令处理程序代码
|
|
2040 |
CDialogDataMon dialog1;
|
|
2041 |
INT_PTR r = dialog1.DoModal();
|
|
2042 |
|
|
2043 |
}
|
|
2044 |
|
|
2045 |
|
|
2046 |
void CMTerm1CommDevView::OnMenuCommTool()
|
|
2047 |
{
|
|
2048 |
// TODO: 在此添加命令处理程序代码
|
|
2049 |
// CDialogCommTest dialog1;
|
|
2050 |
// INT_PTR r = dialog1.DoModal();
|
|
2051 |
|
|
2052 |
}
|
|
2053 |
|
|
2054 |
|
|
2055 |
BOOL CMTerm1CommDevView::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
|
|
2056 |
{
|
|
2057 |
// TODO: 在此添加消息处理程序代码和/或调用默认值
|
|
2058 |
|
|
2059 |
return CFormView::OnMouseWheel(nFlags, zDelta, pt);
|
|
2060 |
}
|
|
2061 |
|
|
2062 |
|
|
2063 |
void CMTerm1CommDevView::OnBnClickedButtonClearStat()
|
|
2064 |
{
|
|
2065 |
// TODO: 在此添加控件通知处理程序代码
|
|
2066 |
Clear_COM_Stats();
|
|
2067 |
}
|
|
2068 |
|
|
2069 |
void CMTerm1CommDevView::OnBnClickedButtonRead()
|
|
2070 |
{
|
|
2071 |
//CDialogProgress dialog1;
|
|
2072 |
//INT_PTR r = dialog1.DoModal();
|
|
2073 |
|
|
2074 |
CDialogProgress * pdialog1 = new CDialogProgress();
|
|
2075 |
pdialog1->Create(IDD_DIALOG_PROGRESS, this);
|
|
2076 |
pdialog1->ShowWindow(SW_SHOW);
|
|
2077 |
pdialog1->UpdateWindow();
|
|
2078 |
for (int i = 0; i <= 200; i++)
|
|
2079 |
{
|
|
2080 |
pdialog1->SetPos(i / 2);
|
|
2081 |
// pdialog1->UpdateWindow();
|
|
2082 |
// DoEvents();
|
|
2083 |
Sleep(50);
|
|
2084 |
|
|
2085 |
}
|
|
2086 |
// pdialog1->SetPos(99);
|
|
2087 |
// pdialog1->UpdateWindow();
|
|
2088 |
for (int i = 0; i < 10; i++)
|
|
2089 |
{
|
|
2090 |
DoEvents();
|
|
2091 |
Sleep(10);
|
|
2092 |
}
|
|
2093 |
|
|
2094 |
pdialog1->DestroyWindow();
|
|
2095 |
delete pdialog1; pdialog1 = NULL;
|
|
2096 |
|
|
2097 |
|
|
2098 |
// TODO: 在此添加控件通知处理程序代码
|
|
2099 |
}
|
|
2100 |
|
|
2101 |
|
|
2102 |
|
|
2103 |
|
|
2104 |
void CMTerm1CommDevView::OnMenuEventLog()
|
|
2105 |
{
|
|
2106 |
// TODO: 在此添加命令处理程序代码
|
|
2107 |
CDialogEventLog dialog1;
|
|
2108 |
INT_PTR r = dialog1.DoModal();
|
|
2109 |
|
|
2110 |
}
|
|
2111 |
|
|
2112 |
|
|
2113 |
void CMTerm1CommDevView::OnMenuCommTest()
|
|
2114 |
{
|
|
2115 |
// TODO: 在此添加命令处理程序代码
|
|
2116 |
// CDialogCommTest dialog1;
|
|
2117 |
// INT_PTR r = dialog1.DoModal();
|
|
2118 |
}
|
|
2119 |
|
|
2120 |
|
|
2121 |
void CMTerm1CommDevView::OnMenuForceIo()
|
|
2122 |
{
|
|
2123 |
// TODO: 在此添加命令处理程序代码
|
|
2124 |
CDialogForceIO dialog1;
|
|
2125 |
INT_PTR r = dialog1.DoModal();
|
|
2126 |
}
|
|
2127 |
|
|
2128 |
|
|
2129 |
void CMTerm1CommDevView::OnMenuDatetime()
|
|
2130 |
{
|
|
2131 |
// TODO: 在此添加命令处理程序代码
|
|
2132 |
CDialogDateTime dialog1;
|
|
2133 |
INT_PTR r = dialog1.DoModal();
|
|
2134 |
}
|
|
2135 |
|
|
2136 |
typedef unsigned char uint8_t;
|
|
2137 |
typedef unsigned short uint16_t;
|
|
2138 |
typedef unsigned int uint32_t;
|
|
2139 |
typedef int int32_t;
|
|
2140 |
|
|
2141 |
const uint16_t polynom = 0xA001;
|
|
2142 |
|
|
2143 |
uint16_t crc16bitbybit(uint8_t *ptr, uint16_t len)
|
|
2144 |
{
|
|
2145 |
uint8_t i;
|
|
2146 |
uint16_t crc = 0xffff;
|
|
2147 |
|
|
2148 |
if (len == 0) {
|
|
2149 |
len = 1;
|
|
2150 |
}
|
|
2151 |
while (len--) {
|
|
2152 |
crc ^= *ptr;
|
|
2153 |
for (i = 0; i < 8; i++)
|
|
2154 |
{
|
|
2155 |
if (crc & 1) {
|
|
2156 |
crc >>= 1;
|
|
2157 |
crc ^= polynom;
|
|
2158 |
}
|
|
2159 |
else {
|
|
2160 |
crc >>= 1;
|
|
2161 |
}
|
|
2162 |
}
|
|
2163 |
ptr++;
|
|
2164 |
}
|
|
2165 |
return(crc);
|
|
2166 |
}
|
|
2167 |
|
|
2168 |
/* Table of CRC values for high–order byte */
|
|
2169 |
const uint8_t crctablehi[] = {
|
|
2170 |
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81,
|
|
2171 |
0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0,
|
|
2172 |
0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01,
|
|
2173 |
0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41,
|
|
2174 |
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81,
|
|
2175 |
0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0,
|
|
2176 |
0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01,
|
|
2177 |
0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
|
|
2178 |
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81,
|
|
2179 |
0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0,
|
|
2180 |
0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01,
|
|
2181 |
0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
|
|
2182 |
0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81,
|
|
2183 |
0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0,
|
|
2184 |
0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01,
|
|
2185 |
0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
|
|
2186 |
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81,
|
|
2187 |
0x40
|
|
2188 |
};
|
|
2189 |
/* Table of CRC values for low–order byte */
|
|
2190 |
const uint8_t crctablelo[] = {
|
|
2191 |
0x00, 0xC0, 0xC1, 0x01, 0xC3, 0x03, 0x02, 0xC2, 0xC6, 0x06, 0x07, 0xC7, 0x05, 0xC5, 0xC4,
|
|
2192 |
0x04, 0xCC, 0x0C, 0x0D, 0xCD, 0x0F, 0xCF, 0xCE, 0x0E, 0x0A, 0xCA, 0xCB, 0x0B, 0xC9, 0x09,
|
|
2193 |
0x08, 0xC8, 0xD8, 0x18, 0x19, 0xD9, 0x1B, 0xDB, 0xDA, 0x1A, 0x1E, 0xDE, 0xDF, 0x1F, 0xDD,
|
|
2194 |
0x1D, 0x1C, 0xDC, 0x14, 0xD4, 0xD5, 0x15, 0xD7, 0x17, 0x16, 0xD6, 0xD2, 0x12, 0x13, 0xD3,
|
|
2195 |
0x11, 0xD1, 0xD0, 0x10, 0xF0, 0x30, 0x31, 0xF1, 0x33, 0xF3, 0xF2, 0x32, 0x36, 0xF6, 0xF7,
|
|
2196 |
0x37, 0xF5, 0x35, 0x34, 0xF4, 0x3C, 0xFC, 0xFD, 0x3D, 0xFF, 0x3F, 0x3E, 0xFE, 0xFA, 0x3A,
|
|
2197 |
0x3B, 0xFB, 0x39, 0xF9, 0xF8, 0x38, 0x28, 0xE8, 0xE9, 0x29, 0xEB, 0x2B, 0x2A, 0xEA, 0xEE,
|
|
2198 |
0x2E, 0x2F, 0xEF, 0x2D, 0xED, 0xEC, 0x2C, 0xE4, 0x24, 0x25, 0xE5, 0x27, 0xE7, 0xE6, 0x26,
|
|
2199 |
0x22, 0xE2, 0xE3, 0x23, 0xE1, 0x21, 0x20, 0xE0, 0xA0, 0x60, 0x61, 0xA1, 0x63, 0xA3, 0xA2,
|
|
2200 |
0x62, 0x66, 0xA6, 0xA7, 0x67, 0xA5, 0x65, 0x64, 0xA4, 0x6C, 0xAC, 0xAD, 0x6D, 0xAF, 0x6F,
|
|
2201 |
0x6E, 0xAE, 0xAA, 0x6A, 0x6B, 0xAB, 0x69, 0xA9, 0xA8, 0x68, 0x78, 0xB8, 0xB9, 0x79, 0xBB,
|
|
2202 |
0x7B, 0x7A, 0xBA, 0xBE, 0x7E, 0x7F, 0xBF, 0x7D, 0xBD, 0xBC, 0x7C, 0xB4, 0x74, 0x75, 0xB5,
|
|
2203 |
0x77, 0xB7, 0xB6, 0x76, 0x72, 0xB2, 0xB3, 0x73, 0xB1, 0x71, 0x70, 0xB0, 0x50, 0x90, 0x91,
|
|
2204 |
0x51, 0x93, 0x53, 0x52, 0x92, 0x96, 0x56, 0x57, 0x97, 0x55, 0x95, 0x94, 0x54, 0x9C, 0x5C,
|
|
2205 |
0x5D, 0x9D, 0x5F, 0x9F, 0x9E, 0x5E, 0x5A, 0x9A, 0x9B, 0x5B, 0x99, 0x59, 0x58, 0x98, 0x88,
|
|
2206 |
0x48, 0x49, 0x89, 0x4B, 0x8B, 0x8A, 0x4A, 0x4E, 0x8E, 0x8F, 0x4F, 0x8D, 0x4D, 0x4C, 0x8C,
|
|
2207 |
0x44, 0x84, 0x85, 0x45, 0x87, 0x47, 0x46, 0x86, 0x82, 0x42, 0x43, 0x83, 0x41, 0x81, 0x80,
|
|
2208 |
0x40
|
|
2209 |
};
|
|
2210 |
|
|
2211 |
uint16_t crc16table(uint8_t *ptr, uint16_t len)
|
|
2212 |
{
|
|
2213 |
uint8_t crchi = 0xff;
|
|
2214 |
uint8_t crclo = 0xff;
|
|
2215 |
uint16_t index;
|
|
2216 |
while (len--)
|
|
2217 |
{
|
|
2218 |
index = crclo ^ *ptr++;
|
|
2219 |
crclo = crchi ^ crctablehi[index];
|
|
2220 |
crchi = crctablelo[index];
|
|
2221 |
}
|
|
2222 |
return (crchi << 8 | crclo);
|
|
2223 |
}
|
|
2224 |
|
|
2225 |
const uint16_t crctalbeabs[] = {
|
|
2226 |
0x0000, 0xCC01, 0xD801, 0x1400, 0xF001, 0x3C00, 0x2800, 0xE401,
|
|
2227 |
0xA001, 0x6C00, 0x7800, 0xB401, 0x5000, 0x9C01, 0x8801, 0x4400
|
|
2228 |
};
|
|
2229 |
|
|
2230 |
uint16_t crc16tablefast(uint8_t *ptr, uint16_t len)
|
|
2231 |
{
|
|
2232 |
uint16_t crc = 0xffff;
|
|
2233 |
uint16_t i;
|
|
2234 |
uint8_t ch;
|
|
2235 |
|
|
2236 |
for (i = 0; i < len; i++) {
|
|
2237 |
ch = *ptr++;
|
|
2238 |
crc = crctalbeabs[(ch ^ crc) & 15] ^ (crc >> 4);
|
|
2239 |
crc = crctalbeabs[((ch >> 4) ^ crc) & 15] ^ (crc >> 4);
|
|
2240 |
}
|
|
2241 |
|
|
2242 |
return crc;
|
|
2243 |
}
|
|
2244 |
|
|
2245 |
void modbuscrc16test()
|
|
2246 |
{
|
|
2247 |
printf("\n");
|
|
2248 |
printf(" Modbus CRC16 tester\n");
|
|
2249 |
printf("-----------------------------------------------------------------------\n");
|
|
2250 |
uint8_t crc16_data[] = { 0x01, 0x04, 0x04, 0x43, 0x6b, 0x58, 0x0e }; // expected crc value 0xD825.
|
|
2251 |
printf(" modbus crc16table test, expected value : 0xd825, calculate value : 0x%x\n", crc16table(crc16_data, sizeof(crc16_data)));
|
|
2252 |
printf(" modbus crc16tablefast test, expected value : 0xd825, calculate value : 0x%x\n", crc16tablefast(crc16_data, sizeof(crc16_data)));
|
|
2253 |
printf(" modbus crc16bitbybit test, expected value : 0xd825, calculate value : 0x%x\n", crc16bitbybit(crc16_data, sizeof(crc16_data)));
|
|
2254 |
}
|
|
2255 |
|
|
2256 |
|
|
2257 |
void CMTerm1CommDevView::OnBnClickedButton11()
|
|
2258 |
{
|
|
2259 |
// TODO: 在此添加控件通知处理程序代码
|
|
2260 |
uint8_t crc16_data[] = { 0x01, 0x04, 0x04, 0x43, 0x6b, 0x58, 0x0e }; // expected crc value 0xD825.
|
|
2261 |
|
|
2262 |
uint16_t crc1, crc2, crc3;
|
|
2263 |
double time1 = GetTimemS();
|
|
2264 |
for (int i = 0; i < 10000; i++)
|
|
2265 |
crc1 = crc16table(crc16_data, sizeof(crc16_data));
|
|
2266 |
double time2 = GetTimemS();
|
|
2267 |
for (int i = 0; i < 10000; i++)
|
|
2268 |
crc2 = crc16tablefast(crc16_data, sizeof(crc16_data));
|
|
2269 |
double time3 = GetTimemS();
|
|
2270 |
for (int i = 0; i < 10000; i++)
|
|
2271 |
crc3 = crc16bitbybit(crc16_data, sizeof(crc16_data));
|
|
2272 |
double time4 = GetTimemS();
|
|
2273 |
CString s1;
|
|
2274 |
s1.Format(_T("crc results \r\n"));
|
|
2275 |
s1.AppendFormat(_T("crc result1 %x time %f \r\n"), crc1, time2 - time1);
|
|
2276 |
s1.AppendFormat(_T("crc result2 %x time %f \r\n"), crc2, time3 - time2);
|
|
2277 |
s1.AppendFormat(_T("crc result3 %x time %f \r\n"), crc3, time4 - time3);
|
|
2278 |
SysLog(s1);
|
|
2279 |
}
|
|
2280 |
|
|
2281 |
|
|
2282 |
void CMTerm1CommDevView::OnBnClickedButton12()
|
|
2283 |
{
|
|
2284 |
// TODO: 在此添加控件通知处理程序代码
|
|
2285 |
CMTerm1Doc *pDoc = (CMTerm1Doc *)GetDocument();
|
|
2286 |
/*
|
|
2287 |
CString s1;
|
|
2288 |
pDoc->MyKLink1.MySerPort1.SetParams(1, 115200, _T("8-N-1"));
|
|
2289 |
int r = pDoc->MyKLink1.MySerPort1.Open();
|
|
2290 |
s1.Format(_T("%d %s"), r, pDoc->MyKLink1.MySerPort1.m_strResult);
|
|
2291 |
SysLog(s1);
|
|
2292 |
*/
|
|
2293 |
}
|
|
2294 |
|
|
2295 |
|
|
2296 |
void CMTerm1CommDevView::OnBnClickedButton13()
|
|
2297 |
{
|
|
2298 |
// TODO: 在此添加控件通知处理程序代码
|
|
2299 |
CMTerm1Doc *pDoc = (CMTerm1Doc *)GetDocument();
|
|
2300 |
/*
|
|
2301 |
CString s1;
|
|
2302 |
int r = pDoc->MyKLink1.MySerPort1.Close();
|
|
2303 |
s1.Format(_T("%d %s"), r, pDoc->MyKLink1.MySerPort1.m_strResult);
|
|
2304 |
SysLog(s1);
|
|
2305 |
|
|
2306 |
double REPO_RATE(0.0);
|
|
2307 |
REPO_RATE = _tstof(_T(""));
|
|
2308 |
s1.Format(_T("RAPO_RATE = %f \n"), REPO_RATE);
|
|
2309 |
SysLog(s1);
|
|
2310 |
*/
|
|
2311 |
|
|
2312 |
}
|
|
2313 |
enum enStat
|
|
2314 |
{
|
|
2315 |
normal=0,
|
|
2316 |
setchn=1,
|
|
2317 |
setvalue=2,
|
|
2318 |
setonoff=3,
|
|
2319 |
|
|
2320 |
};
|
|
2321 |
int nStat = 0;
|
|
2322 |
int ntimecount = 0;
|
|
2323 |
#define MaxTimeOut 50
|
|
2324 |
|
|
2325 |
int nCurChn = 0;
|
|
2326 |
int nValue[4] = { 100,200,300,400 };
|
|
2327 |
int LedOn[4] = { 0 };
|
|
2328 |
int flickTimer = 0;
|
|
2329 |
int CMTerm1CommDevView::UpdateLEDDisplay()
|
|
2330 |
{
|
|
2331 |
// TODO: 在此处添加实现代码.
|
|
2332 |
flickTimer++;
|
|
2333 |
int bHide = 0;
|
|
2334 |
if ((flickTimer & 0x7) > 3) { bHide = 1; }
|
|
2335 |
|
|
2336 |
CString s1;
|
|
2337 |
s1 = _T("0000");
|
|
2338 |
|
|
2339 |
s1.Format(_T("%d%03d"), nCurChn, nValue[nCurChn]);
|
|
2340 |
if (nStat == setchn && bHide)
|
|
2341 |
{
|
|
2342 |
s1.Format(_T(" %03d"), nValue[nCurChn]);
|
|
2343 |
}
|
|
2344 |
if (nStat == setvalue && bHide)
|
|
2345 |
{
|
|
2346 |
s1.Format(_T("%d "),nCurChn);
|
|
2347 |
}
|
|
2348 |
if (nStat == setonoff && bHide)
|
|
2349 |
{
|
|
2350 |
s1.Format(_T(" "), nCurChn);
|
|
2351 |
}
|
|
2352 |
|
|
2353 |
SetDlgItemText(IDC_EDIT31, s1);
|
|
2354 |
|
|
2355 |
s1.Format(_T("%d %d %d %d"), LedOn[0], LedOn[1], LedOn[2], LedOn[3]);
|
|
2356 |
SetDlgItemText(IDC_EDIT32, s1);
|
|
2357 |
|
|
2358 |
ntimecount++;
|
|
2359 |
if (ntimecount >= MaxTimeOut) { nStat = normal; }
|
|
2360 |
return 0;
|
|
2361 |
}
|
|
2362 |
|
|
2363 |
void CMTerm1CommDevView::OnBnClickedButton31()
|
|
2364 |
{
|
|
2365 |
// TODO: 在此添加控件通知处理程序代码
|
|
2366 |
ntimecount = 0;
|
|
2367 |
if (nStat == setchn)
|
|
2368 |
{
|
|
2369 |
nCurChn++;
|
|
2370 |
if (nCurChn >= 4) { nCurChn = 0; }
|
|
2371 |
}
|
|
2372 |
if (nStat == setvalue)
|
|
2373 |
{
|
|
2374 |
nValue[nCurChn] ++;
|
|
2375 |
if (nValue[nCurChn] > 999) { nValue[nCurChn] = 999; }
|
|
2376 |
}
|
|
2377 |
if (nStat == setonoff)
|
|
2378 |
{
|
|
2379 |
LedOn[nCurChn] =1;
|
|
2380 |
}
|
|
2381 |
}
|
|
2382 |
|
|
2383 |
|
|
2384 |
void CMTerm1CommDevView::OnBnClickedButton2()
|
|
2385 |
{
|
|
2386 |
// TODO: 在此添加控件通知处理程序代码
|
|
2387 |
ntimecount = 0;
|
|
2388 |
if (nStat == setchn)
|
|
2389 |
{
|
|
2390 |
nCurChn--;
|
|
2391 |
if (nCurChn <0) { nCurChn = 3; }
|
|
2392 |
}
|
|
2393 |
if (nStat == setvalue)
|
|
2394 |
{
|
|
2395 |
nValue[nCurChn] --;
|
|
2396 |
if (nValue[nCurChn] <= 0) { nValue[nCurChn] = 0; }
|
|
2397 |
}
|
|
2398 |
if (nStat == setonoff)
|
|
2399 |
{
|
|
2400 |
LedOn[nCurChn] = 0;
|
|
2401 |
}
|
|
2402 |
}
|
|
2403 |
|
|
2404 |
|
|
2405 |
void CMTerm1CommDevView::OnBnClickedButton3()
|
|
2406 |
{
|
|
2407 |
// TODO: 在此添加控件通知处理程序代码
|
|
2408 |
ntimecount = 0;
|
|
2409 |
if (nStat == normal)
|
|
2410 |
{
|
|
2411 |
nStat = setchn;
|
|
2412 |
} else if (nStat == setchn)
|
|
2413 |
{
|
|
2414 |
nStat = setvalue;
|
|
2415 |
} else if (nStat == setvalue)
|
|
2416 |
{
|
|
2417 |
nStat = setonoff;
|
|
2418 |
}
|
|
2419 |
else if (nStat == setonoff)
|
|
2420 |
{
|
|
2421 |
nStat = setchn;
|
|
2422 |
}
|
|
2423 |
|
|
2424 |
}
|
|
2425 |
|