提交 | 用户 | age
|
418cb3
|
1 |
// DialogFactCfg.cpp: 实现文件
|
Q |
2 |
//
|
|
3 |
|
|
4 |
#include "pch.h"
|
|
5 |
#include "MTerm1.h"
|
|
6 |
#include "DialogFactCfg.h"
|
|
7 |
#include "afxdialogex.h"
|
|
8 |
|
|
9 |
#include "MTerm1Doc.h"
|
|
10 |
|
|
11 |
// CDialogFactCfg 对话框
|
|
12 |
|
|
13 |
IMPLEMENT_DYNAMIC(CDialogFactCfg, CDialogEx)
|
|
14 |
|
|
15 |
CDialogFactCfg::CDialogFactCfg(CWnd* pParent /*=nullptr*/)
|
|
16 |
: CDialogEx(IDD_DIALOG_FACT_CFG, pParent)
|
|
17 |
{
|
|
18 |
InitDataItems();
|
|
19 |
}
|
|
20 |
|
|
21 |
CDialogFactCfg::~CDialogFactCfg()
|
|
22 |
{
|
|
23 |
}
|
|
24 |
|
|
25 |
void CDialogFactCfg::DoDataExchange(CDataExchange* pDX)
|
|
26 |
{
|
|
27 |
CDialogEx::DoDataExchange(pDX);
|
|
28 |
}
|
|
29 |
|
|
30 |
|
|
31 |
BEGIN_MESSAGE_MAP(CDialogFactCfg, CDialogEx)
|
|
32 |
ON_BN_CLICKED(IDC_BUTTON_CONN, &CDialogFactCfg::OnBnClickedButtonConn)
|
|
33 |
ON_BN_CLICKED(IDC_BUTTON_DISCONN, &CDialogFactCfg::OnBnClickedButtonDisconn)
|
|
34 |
ON_BN_CLICKED(IDC_BUTTON_READDATA, &CDialogFactCfg::OnBnClickedButtonReaddata)
|
|
35 |
ON_BN_CLICKED(IDC_BUTTON_WRITEDATA, &CDialogFactCfg::OnBnClickedButtonWritedata)
|
|
36 |
|
|
37 |
END_MESSAGE_MAP()
|
|
38 |
|
|
39 |
// CDialogFactCfg 消息处理程序
|
|
40 |
int CDialogFactCfg::AddDataItem(int nOffset, int nSize, int nType, CString sName)
|
|
41 |
{
|
|
42 |
FactoryDataItems[nFactoryDataItemsCount] = { nOffset,nSize,nType,sName };
|
|
43 |
nFactoryDataItemsCount++;
|
|
44 |
return 0;
|
|
45 |
}
|
|
46 |
|
|
47 |
int CDialogFactCfg::InitDataItems()
|
|
48 |
{
|
|
49 |
AddDataItem(0, 2, typeBIN, _T("开始标志"));
|
|
50 |
AddDataItem(2, 2, typeINT, _T("序号"));
|
|
51 |
AddDataItem(4, 2, typeHEX, _T("ModelNo"));
|
|
52 |
AddDataItem(6, 2, typeHEX, _T("ModelVer"));
|
|
53 |
AddDataItem(8, 4, typeUINT, _T("nLotNo"));
|
|
54 |
AddDataItem(12, 4, typeDATETIME, _T("nProductDate"));
|
|
55 |
AddDataItem(16, 4, typeUINT, _T("nSN1"));
|
|
56 |
AddDataItem(20, 4, typeHEX, _T("nProtocalVer"));
|
|
57 |
AddDataItem(24, 4, typeHEX, _T("nDefaultFuncr"));
|
|
58 |
AddDataItem(28, 16, typeString, _T("sModelStr"));
|
|
59 |
AddDataItem(44, 16, typeString, _T("sLot_No"));
|
|
60 |
AddDataItem(60, 16, typeString, _T("sSNStr"));
|
|
61 |
AddDataItem(76, 2, typeHEX, _T("CRC1"));
|
|
62 |
AddDataItem(78, 2, typeHEX, _T("EndSign"));
|
|
63 |
return 0;
|
|
64 |
}
|
|
65 |
|
|
66 |
int CDialogFactCfg::FindIdByName(CString sName)
|
|
67 |
{
|
|
68 |
for (int i = 0; i < nFactoryDataItemsCount; i++) {
|
|
69 |
if (FactoryDataItems[i].sName == sName) {
|
|
70 |
return i;
|
|
71 |
}
|
|
72 |
}
|
|
73 |
return -1;
|
|
74 |
}
|
|
75 |
|
|
76 |
int CDialogFactCfg::GetDataByOffset(void * pDataBlock, int nOffset)
|
|
77 |
{
|
|
78 |
return 0;
|
|
79 |
}
|
|
80 |
int CDialogFactCfg::GetDataByName(void * pDataBlock, CString sName)
|
|
81 |
{
|
|
82 |
return 0;
|
|
83 |
}
|
|
84 |
CString CDialogFactCfg::GetDataStrByName(void * pDataBlock, CString sName)
|
|
85 |
{
|
|
86 |
UCHAR * pBuf2 = (UCHAR *)pDataBlock;
|
|
87 |
CString s1;
|
|
88 |
UCHAR buf3[256];
|
|
89 |
CString s3;
|
|
90 |
int nIdx = FindIdByName(sName);
|
|
91 |
if (nIdx >= 0)
|
|
92 |
{
|
|
93 |
CTime ctime1;
|
|
94 |
int nType = FactoryDataItems[nIdx].nType;
|
|
95 |
int nSize = FactoryDataItems[nIdx].nSize;
|
|
96 |
int nOffset = FactoryDataItems[nIdx].nOffset;
|
|
97 |
int nValue;
|
|
98 |
UINT uValue;
|
|
99 |
switch (nType)
|
|
100 |
{
|
|
101 |
case typeINT:
|
|
102 |
if (nSize == 1) {
|
|
103 |
nValue = *((char *)(pBuf2 + nOffset));
|
|
104 |
}
|
|
105 |
else if (nSize == 2) {
|
|
106 |
nValue = *(short *)(pBuf2 + nOffset);
|
|
107 |
}
|
|
108 |
else if (nSize == 3) {
|
|
109 |
|
|
110 |
}
|
|
111 |
else if (nSize == 4) {
|
|
112 |
nValue = *(int *)(pBuf2 + nOffset);
|
|
113 |
}
|
|
114 |
s1.Format(_T("%d"), nValue);
|
|
115 |
break;
|
|
116 |
case typeUINT:
|
|
117 |
if (nSize == 1) {
|
|
118 |
uValue = *((UCHAR *)(pBuf2 + nOffset));
|
|
119 |
}
|
|
120 |
else if (nSize == 2) {
|
|
121 |
uValue = *(USHORT *)(pBuf2 + nOffset);
|
|
122 |
}
|
|
123 |
else if (nSize == 3) {
|
|
124 |
|
|
125 |
}
|
|
126 |
else if (nSize == 4) {
|
|
127 |
uValue = *(UINT *)(pBuf2 + nOffset);
|
|
128 |
}
|
|
129 |
s1.Format(_T("%u"), uValue);
|
|
130 |
break;
|
|
131 |
case typeHEX:
|
|
132 |
if (nSize == 1) {
|
|
133 |
uValue = *((UCHAR *)(pBuf2 + nOffset));
|
|
134 |
s1.Format(_T("%02X"), uValue);
|
|
135 |
}
|
|
136 |
else if (nSize == 2) {
|
|
137 |
uValue = *(USHORT *)(pBuf2 + nOffset);
|
|
138 |
s1.Format(_T("%04X"), uValue);
|
|
139 |
}
|
|
140 |
else if (nSize == 3) {
|
|
141 |
|
|
142 |
}
|
|
143 |
else if (nSize == 4) {
|
|
144 |
uValue = *(UINT *)(pBuf2 + nOffset);
|
|
145 |
s1.Format(_T("%08X"), uValue);
|
|
146 |
}
|
|
147 |
|
|
148 |
break;
|
|
149 |
case typeBIN:
|
|
150 |
if (nSize == 1) {
|
|
151 |
uValue = *((UCHAR *)(pBuf2 + nOffset));
|
|
152 |
s1.Format(_T("%02X"), uValue);
|
|
153 |
}
|
|
154 |
else if (nSize == 2) {
|
|
155 |
uValue = *(USHORT *)(pBuf2 + nOffset);
|
|
156 |
s1.Format(_T("%04X"), uValue);
|
|
157 |
}
|
|
158 |
else if (nSize == 3) {
|
|
159 |
|
|
160 |
}
|
|
161 |
else if (nSize == 4) {
|
|
162 |
uValue = *(UINT *)(pBuf2 + nOffset);
|
|
163 |
s1.Format(_T("%08X"), uValue);
|
|
164 |
}
|
|
165 |
|
|
166 |
break;
|
|
167 |
case typeFLOAT:
|
|
168 |
break;
|
|
169 |
case typeFIX:
|
|
170 |
break;
|
|
171 |
case typeBIT:
|
|
172 |
break;
|
|
173 |
case typeString:
|
|
174 |
for (int j = 0; j < nSize; j++)
|
|
175 |
{
|
|
176 |
buf3[j] = pBuf2[nOffset + j];
|
|
177 |
}
|
|
178 |
buf3[nSize] = 0;
|
|
179 |
s3 = buf3;
|
|
180 |
s1.Format(_T("%s"), s3);
|
|
181 |
break;
|
|
182 |
case typeDATETIME:
|
|
183 |
nValue = *(UINT *)(pBuf2 + nOffset);
|
|
184 |
ctime1 = nValue;
|
|
185 |
ctime1 = CStringToCTime(_T("2000-01-01 08:00:00"));
|
|
186 |
ctime1 += nValue;
|
|
187 |
s3 = ctime1.Format(_T("%Y-%m-%d %H:%M:%S"));
|
|
188 |
s1.Format(_T("%s"), s3);
|
|
189 |
break;
|
|
190 |
default:
|
|
191 |
break;
|
|
192 |
}
|
|
193 |
}
|
|
194 |
return s1;
|
|
195 |
}
|
|
196 |
int CDialogFactCfg::SetDataByName(void * pDataBlock, CString sName, UINT uValue)
|
|
197 |
{
|
|
198 |
UCHAR * pBuf2 = (UCHAR *)pDataBlock;
|
|
199 |
// UCHAR buf3[256];
|
|
200 |
int nIdx = FindIdByName(sName);
|
|
201 |
if (nIdx >= 0)
|
|
202 |
{
|
|
203 |
CTime ctime1;
|
|
204 |
CTime ctime2;
|
|
205 |
CTimeSpan ctime3;
|
|
206 |
int nType = FactoryDataItems[nIdx].nType;
|
|
207 |
int nSize = FactoryDataItems[nIdx].nSize;
|
|
208 |
int nOffset = FactoryDataItems[nIdx].nOffset;
|
|
209 |
int nValue;
|
|
210 |
switch (nType)
|
|
211 |
{
|
|
212 |
case typeINT:
|
|
213 |
if (nSize == 1) {
|
|
214 |
*((char *)(pBuf2 + nOffset)) = uValue;
|
|
215 |
}
|
|
216 |
else if (nSize == 2) {
|
|
217 |
*(short *)(pBuf2 + nOffset) = uValue;
|
|
218 |
}
|
|
219 |
else if (nSize == 3) {
|
|
220 |
|
|
221 |
}
|
|
222 |
else if (nSize == 4) {
|
|
223 |
*(int *)(pBuf2 + nOffset) = uValue;
|
|
224 |
}
|
|
225 |
break;
|
|
226 |
case typeUINT:
|
|
227 |
case typeHEX:
|
|
228 |
if (nSize == 1) {
|
|
229 |
*((UCHAR *)(pBuf2 + nOffset)) = uValue;
|
|
230 |
}
|
|
231 |
else if (nSize == 2) {
|
|
232 |
*(USHORT *)(pBuf2 + nOffset) = uValue;
|
|
233 |
}
|
|
234 |
else if (nSize == 3) {
|
|
235 |
|
|
236 |
}
|
|
237 |
else if (nSize == 4) {
|
|
238 |
*(UINT *)(pBuf2 + nOffset) = uValue;
|
|
239 |
}
|
|
240 |
break;
|
|
241 |
case typeBIN:
|
|
242 |
if (nSize == 1) {
|
|
243 |
*((UCHAR *)(pBuf2 + nOffset)) = uValue;
|
|
244 |
}
|
|
245 |
else if (nSize == 2) {
|
|
246 |
*(USHORT *)(pBuf2 + nOffset) = uValue;
|
|
247 |
}
|
|
248 |
else if (nSize == 3) {
|
|
249 |
|
|
250 |
}
|
|
251 |
else if (nSize == 4) {
|
|
252 |
*(UINT *)(pBuf2 + nOffset) = uValue;
|
|
253 |
}
|
|
254 |
|
|
255 |
break;
|
|
256 |
case typeFLOAT:
|
|
257 |
break;
|
|
258 |
case typeFIX:
|
|
259 |
break;
|
|
260 |
case typeBIT:
|
|
261 |
break;
|
|
262 |
case typeString:
|
|
263 |
break;
|
|
264 |
case typeDATETIME:
|
|
265 |
ctime1 = CStringToCTime(_T("2000-01-01 08:00:00"));
|
|
266 |
ctime2 = uValue;
|
|
267 |
ctime3 = ctime2 - ctime1;
|
|
268 |
nValue = (long)(ctime3.GetTotalSeconds());
|
|
269 |
*(UINT *)(pBuf2 + nOffset) = uValue;
|
|
270 |
|
|
271 |
break;
|
|
272 |
default:
|
|
273 |
break;
|
|
274 |
}
|
|
275 |
}
|
|
276 |
return 0;
|
|
277 |
}
|
|
278 |
int CDialogFactCfg::SetDataByName(void * pDataBlock, CString sName, CString sValue)
|
|
279 |
{
|
|
280 |
UCHAR * pBuf2 = (UCHAR *)pDataBlock;
|
|
281 |
// UCHAR buf3[256];
|
|
282 |
CStringA s3;
|
|
283 |
int nIdx = FindIdByName(sName);
|
|
284 |
if (nIdx >= 0)
|
|
285 |
{
|
|
286 |
CTime ctime1;
|
|
287 |
CTime ctime2;
|
|
288 |
CTimeSpan ctime3;
|
|
289 |
int nType = FactoryDataItems[nIdx].nType;
|
|
290 |
int nSize = FactoryDataItems[nIdx].nSize;
|
|
291 |
int nOffset = FactoryDataItems[nIdx].nOffset;
|
|
292 |
int nValue;
|
|
293 |
int len;
|
|
294 |
switch (nType)
|
|
295 |
{
|
|
296 |
case typeINT:
|
|
297 |
if (nSize == 1) {
|
|
298 |
*((char *)(pBuf2 + nOffset)) = _tstoi(sValue);
|
|
299 |
}
|
|
300 |
else if (nSize == 2) {
|
|
301 |
*(short *)(pBuf2 + nOffset) = _tstoi(sValue);
|
|
302 |
}
|
|
303 |
else if (nSize == 3) {
|
|
304 |
|
|
305 |
}
|
|
306 |
else if (nSize == 4) {
|
|
307 |
*(int *)(pBuf2 + nOffset) = _tstoi(sValue);
|
|
308 |
}
|
|
309 |
break;
|
|
310 |
case typeUINT:
|
|
311 |
if (nSize == 1) {
|
|
312 |
*((UCHAR *)(pBuf2 + nOffset)) = _tstoi(sValue);
|
|
313 |
}
|
|
314 |
else if (nSize == 2) {
|
|
315 |
*(USHORT *)(pBuf2 + nOffset) = _tstoi(sValue);
|
|
316 |
}
|
|
317 |
else if (nSize == 3) {
|
|
318 |
|
|
319 |
}
|
|
320 |
else if (nSize == 4) {
|
|
321 |
*(UINT *)(pBuf2 + nOffset) = _tstoi(sValue);
|
|
322 |
}
|
|
323 |
break;
|
|
324 |
case typeHEX:
|
|
325 |
if (nSize == 1) {
|
|
326 |
*((UCHAR *)(pBuf2 + nOffset)) = _tstoi(sValue);
|
|
327 |
|
|
328 |
}
|
|
329 |
else if (nSize == 2) {
|
|
330 |
*(USHORT *)(pBuf2 + nOffset) = _tstoi(sValue);
|
|
331 |
}
|
|
332 |
else if (nSize == 3) {
|
|
333 |
|
|
334 |
}
|
|
335 |
else if (nSize == 4) {
|
|
336 |
*(UINT *)(pBuf2 + nOffset) = _tstoi(sValue);
|
|
337 |
}
|
|
338 |
break;
|
|
339 |
case typeBIN:
|
|
340 |
if (nSize == 1) {
|
|
341 |
*((UCHAR *)(pBuf2 + nOffset)) = _tstoi(sValue);
|
|
342 |
}
|
|
343 |
else if (nSize == 2) {
|
|
344 |
*(USHORT *)(pBuf2 + nOffset) = _tstoi(sValue);
|
|
345 |
}
|
|
346 |
else if (nSize == 3) {
|
|
347 |
|
|
348 |
}
|
|
349 |
else if (nSize == 4) {
|
|
350 |
*(UINT *)(pBuf2 + nOffset) = _tstoi(sValue);
|
|
351 |
}
|
|
352 |
|
|
353 |
break;
|
|
354 |
case typeFLOAT:
|
|
355 |
break;
|
|
356 |
case typeFIX:
|
|
357 |
break;
|
|
358 |
case typeBIT:
|
|
359 |
break;
|
|
360 |
case typeString:
|
|
361 |
s3 = sValue;
|
|
362 |
len = s3.GetLength();
|
|
363 |
for (int j = 0; j < nSize; j++) {
|
|
364 |
if (j < len) {
|
|
365 |
pBuf2[nOffset + j] = s3[j];
|
|
366 |
}else {
|
|
367 |
pBuf2[nOffset + j] = ' ';
|
|
368 |
}
|
|
369 |
}
|
|
370 |
break;
|
|
371 |
case typeDATETIME:
|
|
372 |
ctime1 = CStringToCTime(_T("2000-01-01 08:00:00"));
|
|
373 |
ctime2 = CStringToCTime(sValue);;
|
|
374 |
ctime3 = ctime2 - ctime1;
|
|
375 |
nValue = (long)(ctime3.GetTotalSeconds());
|
|
376 |
*(UINT *)(pBuf2 + nOffset) = nValue;
|
|
377 |
|
|
378 |
break;
|
|
379 |
default:
|
|
380 |
break;
|
|
381 |
}
|
|
382 |
}
|
|
383 |
return 0;
|
|
384 |
}
|
|
385 |
|
|
386 |
|
|
387 |
|
|
388 |
CMTerm1Doc * CDialogFactCfg::GetDocument()
|
|
389 |
{
|
|
390 |
// TODO: 在此处添加实现代码.
|
|
391 |
CMDIFrameWnd *pFrame = (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd;
|
|
392 |
CMDIChildWnd *pChild = (CMDIChildWnd *)pFrame->GetActiveFrame();
|
|
393 |
CView *pV = (CView*)pChild->GetActiveView();
|
|
394 |
CMTerm1Doc* pDoc = (CMTerm1Doc *)(pV->GetDocument());
|
|
395 |
return pDoc;
|
|
396 |
}
|
|
397 |
|
|
398 |
int CDialogFactCfg::Connect()
|
|
399 |
{
|
|
400 |
// TODO: 在此处添加实现代码.
|
|
401 |
CString s1;
|
|
402 |
CMTerm1Doc* pDoc = (CMTerm1Doc *)GetDocument();
|
|
403 |
|
|
404 |
|
61deef
|
405 |
//int r = pDoc->Connect();
|
Q |
406 |
int r = theApp.MyKLink1.Connect();
|
|
407 |
|
|
408 |
s1.Format(_T("Open %s = %d"), theApp.MyKLink1.MySerPort1.m_strResult, r);
|
418cb3
|
409 |
SysLog(s1);
|
61deef
|
410 |
if (r == theApp.MyKLink1.MySerPort1.R_OK)
|
418cb3
|
411 |
{
|
61deef
|
412 |
theApp.MyKLink1.Open();
|
418cb3
|
413 |
return false;
|
Q |
414 |
}
|
|
415 |
return true;
|
|
416 |
return 0;
|
|
417 |
}
|
|
418 |
|
|
419 |
|
|
420 |
int CDialogFactCfg::Disconnect()
|
|
421 |
{
|
|
422 |
// TODO: 在此处添加实现代码.
|
|
423 |
CMTerm1Doc* pDoc = (CMTerm1Doc *)GetDocument();
|
|
424 |
|
|
425 |
pDoc->DisConnect();
|
61deef
|
426 |
theApp.MyKLink1.Close();
|
418cb3
|
427 |
return 0;
|
Q |
428 |
}
|
|
429 |
|
|
430 |
int CDialogFactCfg::ReadData()
|
|
431 |
{
|
|
432 |
CMTerm1Doc* pDoc = (CMTerm1Doc *)GetDocument();
|
|
433 |
|
|
434 |
unsigned short buf1[1024];
|
|
435 |
unsigned short len1;
|
61deef
|
436 |
int res = theApp.MyKLink1.GetInfo(1 ,&len1, buf1);
|
Q |
437 |
SysLog(theApp.MyKLink1.m_resultStr);
|
418cb3
|
438 |
CString s1;
|
Q |
439 |
s1.Format(_T("GetInfo = %d %d bytes"), res,len1);
|
61deef
|
440 |
if (res == theApp.MyKLink1.KL_OK)
|
418cb3
|
441 |
{
|
Q |
442 |
s1.Append(_T("\r\n"));
|
|
443 |
for (int i = 0; i < len1 / 2; i++)
|
|
444 |
{
|
|
445 |
s1.AppendFormat(_T("%04X "), buf1[i]);
|
|
446 |
}
|
|
447 |
}
|
|
448 |
SysLog(s1);
|
|
449 |
pKMInfoBlock pinfob = (pKMInfoBlock)buf1;
|
|
450 |
|
|
451 |
s1.Format(_T("%04X"), pinfob->nDeviceTypeVer);
|
|
452 |
SetDlgItemText(IDC_EDIT_DEVICE_TYPE, s1);
|
|
453 |
s1.Format(_T("%04X"), pinfob->nProgVer);
|
|
454 |
SetDlgItemText(IDC_EDIT_FIRM_VER, s1);
|
|
455 |
s1.Format(_T("%04X"), pinfob->nKLinkVer);
|
|
456 |
SetDlgItemText(IDC_EDIT_KLINK_VER, s1);
|
|
457 |
s1.Format(_T("%04X"), pinfob->nKBusVer);
|
|
458 |
SetDlgItemText(IDC_EDIT_KBUS_VER, s1);
|
|
459 |
s1.Format(_T("%04X"), 0);
|
|
460 |
s1.Empty();
|
|
461 |
SetDlgItemText(IDC_EDIT_KNET_VER, s1);
|
|
462 |
//s1.Format(_T("%04X"), 0);
|
|
463 |
SetDlgItemText(IDC_EDIT_KWL_VER, s1);
|
|
464 |
s1.Format(_T("%04X"), pinfob->nAbility);
|
|
465 |
SetDlgItemText(IDC_EDIT_FUNCTIONS, s1);
|
|
466 |
|
|
467 |
s1.Format(_T("%d"), pinfob->nCapacity1);
|
|
468 |
SetDlgItemText(IDC_EDIT_CAP_PROG, s1);
|
|
469 |
s1.Format(_T("%d"), pinfob->nCapacity2);
|
|
470 |
SetDlgItemText(IDC_EDIT_CAP_DT, s1);
|
|
471 |
|
|
472 |
SetDlgItemText(IDC_EDIT_CAP_WR, s1);
|
|
473 |
SetDlgItemText(IDC_EDIT_CAP_TM, s1);
|
|
474 |
s1.Format(_T("%d"), pinfob->nSwitchBits);
|
|
475 |
SetDlgItemText(IDC_EDIT_CAP_SW, s1);
|
|
476 |
s1.Format(_T("%d"), pinfob->nPorts);
|
|
477 |
SetDlgItemText(IDC_EDIT_CAP_COM, s1);
|
|
478 |
s1.Format(_T("%d"), pinfob->nManSize);
|
|
479 |
SetDlgItemText(IDC_EDIT_CAP_CFG, s1);
|
|
480 |
s1.Format(_T("%d"), pinfob->nLogSize);
|
|
481 |
SetDlgItemText(IDC_EDIT_CAP_EVENT, s1);
|
|
482 |
|
|
483 |
s1.Format(_T("%d"), pinfob->nDInput);
|
|
484 |
SetDlgItemText(IDC_EDIT_CAP_DIN, s1);
|
|
485 |
s1.Format(_T("%d"), pinfob->nDInput);
|
|
486 |
SetDlgItemText(IDC_EDIT_CAP_DOUT, s1);
|
|
487 |
s1.Format(_T("%d"), pinfob->nAInput);
|
|
488 |
SetDlgItemText(IDC_EDIT_CAP_AIN_I, s1);
|
|
489 |
s1.Format(_T("%d"), pinfob->nAOutput);
|
|
490 |
SetDlgItemText(IDC_EDIT_CAP_AOUT_I, s1);
|
|
491 |
s1.Format(_T("%d"), pinfob->nAInput);
|
|
492 |
SetDlgItemText(IDC_EDIT_CAP_AIN_E, s1);
|
|
493 |
s1.Format(_T("%d"), pinfob->nAOutput);
|
|
494 |
SetDlgItemText(IDC_EDIT_CAP_AOUT_E, s1);
|
|
495 |
s1.Format(_T("%d"), pinfob->nHInput);
|
|
496 |
SetDlgItemText(IDC_EDIT_CAP_HIN, s1);
|
|
497 |
s1.Format(_T("%d"), pinfob->nHOutput);
|
|
498 |
SetDlgItemText(IDC_EDIT_CAP_HOUT, s1);
|
|
499 |
s1.Empty();
|
|
500 |
SetDlgItemText(IDC_EDIT_CAP_IRQ_I, s1);
|
|
501 |
SetDlgItemText(IDC_EDIT_CAP_IRQ_O, s1);
|
|
502 |
SetDlgItemText(IDC_EDIT_CAP_EXT_I, s1);
|
|
503 |
SetDlgItemText(IDC_EDIT_CAP_EXT_O, s1);
|
|
504 |
|
|
505 |
CString s2;
|
|
506 |
CString s3;
|
|
507 |
unsigned char buf2[1024];
|
61deef
|
508 |
res = theApp.MyKLink1.GetUID(1, &len1, (unsigned short *)buf2);
|
Q |
509 |
SysLog(theApp.MyKLink1.m_resultStr);
|
418cb3
|
510 |
s1.Format(_T("GetUID = %d %d bytes"), res,len1);
|
Q |
511 |
|
61deef
|
512 |
if (res == theApp.MyKLink1.KL_OK)
|
418cb3
|
513 |
{
|
Q |
514 |
s1.Append(_T("\r\n"));
|
|
515 |
for (int i = 0; i < 12; i++)
|
|
516 |
{
|
|
517 |
s1.AppendFormat(_T("%02X "), buf2[i]);
|
|
518 |
s2.AppendFormat(_T("%02X"), buf2[12-i-1]);
|
|
519 |
// s3.AppendFormat(_T("%c"), buf2[12 - i - 1]);
|
|
520 |
}
|
|
521 |
}
|
|
522 |
SysLog(s1);
|
|
523 |
SetDlgItemText(IDC_EDIT_DEVICE_UID, s2);
|
|
524 |
|
|
525 |
|
61deef
|
526 |
res = theApp.MyKLink1.GetSN(1, &len1, (unsigned short *)buf2);
|
Q |
527 |
SysLog(theApp.MyKLink1.m_resultStr);
|
418cb3
|
528 |
s1.Format(_T("GetSN = %d %d bytes"), res,len1);
|
Q |
529 |
s2.Empty();
|
61deef
|
530 |
if (res == theApp.MyKLink1.KL_OK)
|
418cb3
|
531 |
{
|
Q |
532 |
s1.Append(_T("\r\n"));
|
|
533 |
for (int i = 0; i < 4; i++)
|
|
534 |
{
|
|
535 |
s1.AppendFormat(_T("%02X "), buf2[i]);
|
|
536 |
s2.AppendFormat(_T("%02X"), buf2[4-i-1]);
|
|
537 |
// s3.AppendFormat(_T("%c"), buf2[12 - i - 1]);
|
|
538 |
}
|
|
539 |
}
|
|
540 |
SysLog(s1);
|
|
541 |
|
61deef
|
542 |
res = theApp.MyKLink1.ReadFactoryData(1, 0, 120, &len1, (unsigned short *)buf2);
|
Q |
543 |
SysLog(theApp.MyKLink1.m_resultStr);
|
418cb3
|
544 |
s1.Format(_T("GetFactoryData = %d %d bytes"), res, len1);
|
Q |
545 |
s2.Empty();
|
61deef
|
546 |
if (res == theApp.MyKLink1.KL_OK)
|
418cb3
|
547 |
{
|
Q |
548 |
s1.Append(_T("\r\n"));
|
|
549 |
for (int i = 0; i < 256 && i< len1; i++)
|
|
550 |
{
|
|
551 |
s1.AppendFormat(_T("%02X "), buf2[i]);
|
|
552 |
// s2.AppendFormat(_T("%02X"), buf2[4 - i - 1]);
|
|
553 |
// s3.AppendFormat(_T("%c"), buf2[12 - i - 1]);
|
|
554 |
}
|
|
555 |
}
|
|
556 |
SysLog(s1);
|
|
557 |
s2 = GetDataStrByName(buf2, _T("nSN1"));
|
|
558 |
SetDlgItemText(IDC_EDIT_ORG_FACT_SN, s2);
|
|
559 |
|
|
560 |
// unsigned char buf3[1024];
|
|
561 |
CTime ctime1;
|
|
562 |
for (int i = 0; i < nFactoryDataItemsCount; i++)
|
|
563 |
{
|
|
564 |
// int nType = FactoryDataItems[i].nType;
|
|
565 |
// int nSize = FactoryDataItems[i].nSize;
|
|
566 |
// int nOffset = FactoryDataItems[i].nOffset;
|
|
567 |
CString sName = FactoryDataItems[i].sName;
|
|
568 |
s3 = GetDataStrByName(buf2,sName);
|
|
569 |
s1.Format(_T("%d %s %s"), i, sName, s3);
|
|
570 |
SysLog(s1);
|
|
571 |
}
|
|
572 |
|
|
573 |
s3=GetDataStrByName(buf2, _T("sLot_No"));
|
|
574 |
SetDlgItemText(IDC_EDIT_ORG_LOT_NO, s3);
|
|
575 |
|
|
576 |
s3 = GetDataStrByName(buf2, _T("nProductDate"));
|
|
577 |
SetDlgItemText(IDC_EDIT_ORG_FAC_DATE, s3);
|
|
578 |
|
|
579 |
|
|
580 |
return 0;
|
|
581 |
}
|
|
582 |
|
|
583 |
|
|
584 |
|
|
585 |
int CDialogFactCfg::WriteData()
|
|
586 |
{
|
|
587 |
// TODO: 在此处添加实现代码.
|
|
588 |
|
|
589 |
CString s1;
|
|
590 |
CMTerm1Doc* pDoc = (CMTerm1Doc *)GetDocument();
|
|
591 |
unsigned short buf1[1024];
|
|
592 |
// unsigned char buf2[1024];
|
|
593 |
// unsigned char buf3[1024];
|
|
594 |
/*
|
|
595 |
AddDataItem(0, 2, typeBIN, _T("开始标志"));
|
|
596 |
AddDataItem(2, 2, typeINT, _T("序号"));
|
|
597 |
AddDataItem(4, 2, typeBIN, _T("ModelNo"));
|
|
598 |
AddDataItem(6, 2, typeBIN, _T("ModelVer"));
|
|
599 |
AddDataItem(8, 4, typeUINT, _T("nLotNo"));
|
|
600 |
AddDataItem(12, 4, typeDATETIME, _T("nProductDate"));
|
|
601 |
AddDataItem(16, 4, typeBIN, _T("nSN1"));
|
|
602 |
AddDataItem(20, 4, typeBIN, _T("nProtocalVer"));
|
|
603 |
AddDataItem(24, 4, typeBIN, _T("nDefaultFuncr"));
|
|
604 |
AddDataItem(28, 16, typeString, _T("sModelStr"));
|
|
605 |
AddDataItem(44, 16, typeString, _T("sLot_No"));
|
|
606 |
AddDataItem(60, 16, typeString, _T("sSNStr"));
|
|
607 |
AddDataItem(76, 2, typeBIN, _T("CRC1"));
|
|
608 |
AddDataItem(78, 2, typeBIN, _T("EndSign"));
|
|
609 |
*/
|
|
610 |
int res = 0;
|
|
611 |
unsigned short len1;
|
61deef
|
612 |
res = theApp.MyKLink1.ReadFactoryData(1, 0, 120, &len1, (unsigned short *)buf1);
|
Q |
613 |
SysLog(theApp.MyKLink1.m_resultStr);
|
418cb3
|
614 |
s1.Format(_T("GetFactoryData = %d %d bytes"), res,len1);
|
Q |
615 |
|
|
616 |
GetDlgItemText(IDC_DATETIMEPICKER1, s1);
|
|
617 |
SysLog(s1);
|
|
618 |
CTime date;
|
|
619 |
((CDateTimeCtrl *)(GetDlgItem(IDC_DATETIMEPICKER1)))->GetTime(date);
|
|
620 |
|
|
621 |
UINT uValue;
|
|
622 |
|
|
623 |
SetDataByName(buf1, _T("开始标志"), 0x55AA);
|
|
624 |
SetDataByName(buf1, _T("序号"), 0x0002);
|
|
625 |
SetDataByName(buf1, _T("ModelNo"), 0x0008);
|
|
626 |
SetDataByName(buf1, _T("ModelVer"), 0x0100);
|
|
627 |
GetDlgItemText(IDC_EDIT_LOT_NO, s1); uValue = _tstoi(s1);
|
|
628 |
SetDataByName(buf1, _T("nLotNo"), uValue);
|
|
629 |
|
|
630 |
GetDlgItemText(IDC_DATETIMEPICKER1, s1);
|
|
631 |
s1 = date.Format(_T("%Y-%m-%d %H:%M:%S"));
|
|
632 |
SetDataByName(buf1, _T("nProductDate"), s1);
|
|
633 |
|
|
634 |
GetDlgItemText(IDC_EDIT_FACT_SN, s1); uValue = _tstoi(s1);
|
|
635 |
SetDataByName(buf1, _T("nSN1"), uValue);
|
|
636 |
SetDataByName(buf1, _T("nProtocalVer"), 0x01000100);
|
|
637 |
SetDataByName(buf1, _T("nDefaultFuncr"), 0x00000001);
|
|
638 |
SetDataByName(buf1, _T("sModelStr"), _T("12122121"));
|
|
639 |
GetDlgItemText(IDC_EDIT_LOT_NO, s1);
|
|
640 |
SetDataByName(buf1, _T("sLot_No"), s1);
|
|
641 |
SetDataByName(buf1, _T("sSNStr"), _T("56566565"));
|
|
642 |
SetDataByName(buf1, _T("CRC1"), 0xEFEF);
|
|
643 |
SetDataByName(buf1, _T("EndSign"), 0x55AA);
|
|
644 |
|
|
645 |
CString s3;
|
|
646 |
|
|
647 |
for (int i = 0; i < nFactoryDataItemsCount; i++)
|
|
648 |
{
|
|
649 |
// int nType = FactoryDataItems[i].nType;
|
|
650 |
// int nSize = FactoryDataItems[i].nSize;
|
|
651 |
// int nOffset = FactoryDataItems[i].nOffset;
|
|
652 |
CString sName = FactoryDataItems[i].sName;
|
|
653 |
s3 = GetDataStrByName(buf1, sName);
|
|
654 |
s1.Format(_T("%d %s %s"), i, sName, s3);
|
|
655 |
SysLog(s1);
|
|
656 |
}
|
|
657 |
|
61deef
|
658 |
res = theApp.MyKLink1.WriteFactoryData(1, 0, 80, buf1);
|
Q |
659 |
SysLog(theApp.MyKLink1.m_resultStr);
|
418cb3
|
660 |
s1.Format(_T("WriteFactoryData = %d "), res);
|
Q |
661 |
SysLog(s1);
|
|
662 |
return 0;
|
|
663 |
}
|
|
664 |
|
|
665 |
void CDialogFactCfg::OnBnClickedButtonReaddata()
|
|
666 |
{
|
|
667 |
// TODO: 在此添加控件通知处理程序代码
|
|
668 |
ReadData();
|
|
669 |
}
|
|
670 |
|
|
671 |
void CDialogFactCfg::OnBnClickedButtonConn()
|
|
672 |
{
|
|
673 |
// TODO: 在此添加控件通知处理程序代码
|
|
674 |
Connect();
|
|
675 |
|
|
676 |
}
|
|
677 |
|
|
678 |
|
|
679 |
void CDialogFactCfg::OnBnClickedButtonDisconn()
|
|
680 |
{
|
|
681 |
// TODO: 在此添加控件通知处理程序代码
|
|
682 |
Disconnect();
|
|
683 |
|
|
684 |
}
|
|
685 |
|
|
686 |
|
|
687 |
|
|
688 |
|
|
689 |
void CDialogFactCfg::OnBnClickedButtonWritedata()
|
|
690 |
{
|
|
691 |
// TODO: 在此添加控件通知处理程序代码
|
|
692 |
WriteData();
|
|
693 |
|
|
694 |
}
|
|
695 |
|
|
696 |
CString saveInputStr=_T(""), saveInput1Str= _T("");
|
|
697 |
CString sDisplayStr;
|
|
698 |
CString sStoreStr;
|
|
699 |
bool bEditEndFlg = false;
|
|
700 |
|
|
701 |
/*
|
|
702 |
int CDialogFactCfg::CharKeyClick(CString sKey)
|
|
703 |
{
|
|
704 |
// TODO: 在此处添加实现代码.
|
|
705 |
if (bEditEndFlg)
|
|
706 |
{
|
|
707 |
sDisplayStr.Empty();
|
|
708 |
bEditEndFlg = false;
|
|
709 |
}
|
|
710 |
sDisplayStr.Append(sKey);
|
|
711 |
int len1 = sDisplayStr.GetLength();
|
|
712 |
if (len1 > 1 && sDisplayStr[0] == _T('0')) sDisplayStr = sDisplayStr.Right(sDisplayStr.GetLength() - 1);
|
|
713 |
|
|
714 |
SetDlgItemText(IDC_EDIT_VIEW, sDisplayStr);
|
|
715 |
return 0;
|
|
716 |
}
|
|
717 |
void CDialogFactCfg::OnBnClickedBtn1()
|
|
718 |
{
|
|
719 |
CharKeyClick(_T("1"));
|
|
720 |
}
|
|
721 |
void CDialogFactCfg::OnBnClickedBtn3()
|
|
722 |
{
|
|
723 |
CharKeyClick(_T("3"));
|
|
724 |
}
|
|
725 |
void CDialogFactCfg::OnBnClickedBtn4()
|
|
726 |
{
|
|
727 |
CharKeyClick(_T("4"));
|
|
728 |
}
|
|
729 |
void CDialogFactCfg::OnBnClickedBtn5()
|
|
730 |
{
|
|
731 |
CharKeyClick(_T("5"));
|
|
732 |
}
|
|
733 |
void CDialogFactCfg::OnBnClickedBtnClear()
|
|
734 |
{
|
|
735 |
sDisplayStr.Empty();
|
|
736 |
bEditEndFlg = false;
|
|
737 |
SetDlgItemText(IDC_EDIT_VIEW, _T("0"));
|
|
738 |
}
|
|
739 |
void CDialogFactCfg::OnBnClickedBtnAdd()
|
|
740 |
{
|
|
741 |
bEditEndFlg = true;
|
|
742 |
sStoreStr = sDisplayStr;
|
|
743 |
|
|
744 |
//saveInput1Str = saveInputStr;
|
|
745 |
//saveInputStr = "";
|
|
746 |
}
|
|
747 |
void CDialogFactCfg::OnBnClickedBtnBackSpace()
|
|
748 |
{
|
|
749 |
int len1 = sDisplayStr.GetLength();
|
|
750 |
if (len1 > 1)
|
|
751 |
{
|
|
752 |
sDisplayStr = sDisplayStr.Left(sDisplayStr.GetLength() - 1);
|
|
753 |
}
|
|
754 |
else if (len1 == 1)
|
|
755 |
{
|
|
756 |
sDisplayStr = "0";
|
|
757 |
}
|
|
758 |
// bEditEndFlg = false;
|
|
759 |
SetDlgItemText(IDC_EDIT_VIEW, sDisplayStr);
|
|
760 |
}
|
|
761 |
|
|
762 |
|
|
763 |
|
|
764 |
void CDialogFactCfg::OnBnClickedButton0()
|
|
765 |
{
|
|
766 |
// TODO: 在此添加控件通知处理程序代码
|
|
767 |
CharKeyClick(_T("0"));
|
|
768 |
}
|
|
769 |
|
|
770 |
|
|
771 |
void CDialogFactCfg::OnBnClickedButton1Dot()
|
|
772 |
{
|
|
773 |
// TODO: 在此添加控件通知处理程序代码
|
|
774 |
CharKeyClick(_T("."));
|
|
775 |
}
|
|
776 |
|
|
777 |
|
|
778 |
void CDialogFactCfg::OnBnClickedButtonEq()
|
|
779 |
{
|
|
780 |
// TODO: 在此添加控件通知处理程序代码
|
|
781 |
bEditEndFlg = true;
|
|
782 |
|
|
783 |
float a = (float)_tstof(sStoreStr);
|
|
784 |
float b = (float)_tstof(sDisplayStr);
|
|
785 |
|
|
786 |
float c = a + b;
|
|
787 |
|
|
788 |
sDisplayStr.Format(_T("%g"),c);
|
|
789 |
SetDlgItemText(IDC_EDIT_VIEW, sDisplayStr);
|
|
790 |
|
|
791 |
}
|
|
792 |
*/ |