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