|
// ConfigToolView.cpp: CConfigToolView 类的实现
|
//
|
|
#include "pch.h"
|
#include "framework.h"
|
// SHARED_HANDLERS 可以在实现预览、缩略图和搜索筛选器句柄的
|
// ATL 项目中进行定义,并允许与该项目共享文档代码。
|
#ifndef SHARED_HANDLERS
|
#include "ConfigTool.h"
|
#endif
|
|
#include "ConfigToolDoc.h"
|
#include "ConfigToolView.h"
|
#include "../MyLib/Functions.hpp"
|
|
#ifdef _DEBUG
|
#define new DEBUG_NEW
|
#endif
|
|
CConfigToolDoc::stCtrls myCtrls[] =
|
{
|
25001,CConfigToolDoc::typeText,_T("文本输入框1"),_T("默认文本1"),_T("DT200"),
|
25002,CConfigToolDoc::typeText,_T("文本输入框2"),_T("默认文本2"),_T("DT202"),
|
25003,CConfigToolDoc::typeInt,_T("整数输入框1"),_T("123"),_T("默认地址"),
|
25004,CConfigToolDoc::typeInt,_T("整数输入框2"),_T("4562"),_T("默认地址"),
|
25005,CConfigToolDoc::typeFloat,_T("浮点输入框1"),_T("123.6"),_T("默认地址"),
|
25006,CConfigToolDoc::typeFloat,_T("浮点输入框2"),_T("234.5"),_T("默认地址"),
|
25007,CConfigToolDoc::typeSelect,_T("选择框1"),_T("选择1|选项2|选项3|选项4|选项5"),_T("默认地址"),
|
25008,CConfigToolDoc::typeSelect,_T("选择甜点"),_T("苹果|西瓜|香蕉|沙拉|火龙果"),_T("默认地址"),
|
25009,CConfigToolDoc::typeCheck,_T("复选框1"),_T("默认选择1"),_T("默认地址"),
|
25010,CConfigToolDoc::typeCheck,_T("复选框2"),_T("默认选择2"),_T("默认地址"),
|
25011,CConfigToolDoc::typeButton,_T("按钮1"),_T("默认1"),_T("默认地址"),
|
25012,CConfigToolDoc::typeButton,_T("按钮2"),_T("默认2"),_T("默认地址"),
|
25013,CConfigToolDoc::typeButton,_T("按钮3"),_T("默认3"),_T("默认地址"),
|
25014,CConfigToolDoc::typeButton,_T("按钮4"),_T("默认4"),_T("默认地址"),
|
25015,CConfigToolDoc::typeButton,_T("按钮5"),_T("默认5"),_T("默认地址"),
|
25016,CConfigToolDoc::typeButton,_T("按钮6"),_T("默认6"),_T("默认地址"),
|
25017,CConfigToolDoc::typeButton,_T("按钮7"),_T("默认7"),_T("默认地址"),
|
|
};
|
CStatic * pCStatics[100] = { 0 };
|
CWnd * pCWnds[100] = { 0 };
|
|
int nCtrls = sizeof(myCtrls) / sizeof(CConfigToolDoc::stCtrls);
|
|
// CConfigToolView
|
|
IMPLEMENT_DYNCREATE(CConfigToolView, CFormView)
|
|
BEGIN_MESSAGE_MAP(CConfigToolView, CFormView)
|
// 标准打印命令
|
ON_COMMAND(ID_FILE_PRINT, &CFormView::OnFilePrint)
|
ON_COMMAND(ID_FILE_PRINT_DIRECT, &CFormView::OnFilePrint)
|
ON_COMMAND(ID_FILE_PRINT_PREVIEW, &CFormView::OnFilePrintPreview)
|
ON_WM_CLOSE()
|
ON_WM_DESTROY()
|
ON_BN_CLICKED(IDC_BUTTON_COMM_SET, &CConfigToolView::OnBnClickedButtonCommSet)
|
ON_BN_CLICKED(IDC_BUTTON_CONNECT, &CConfigToolView::OnBnClickedButtonConnect)
|
ON_BN_CLICKED(IDC_BUTTON_DISCONNECT, &CConfigToolView::OnBnClickedButtonDisconnect)
|
ON_BN_CLICKED(IDC_BUTTON_UPLOAD, &CConfigToolView::OnBnClickedButtonUpload)
|
ON_BN_CLICKED(IDC_BUTTON_DOWNLOAD, &CConfigToolView::OnBnClickedButtonDownload)
|
ON_BN_CLICKED(IDC_BUTTON_EVENTLOG, &CConfigToolView::OnBnClickedButtonEventlog)
|
ON_WM_MOUSEWHEEL()
|
ON_WM_TIMER()
|
ON_BN_CLICKED(IDC_BUTTON_WRITEDATA, &CConfigToolView::OnBnClickedButtonWritedata)
|
ON_BN_CLICKED(IDC_BUTTON_TIME_NOW, &CConfigToolView::OnBnClickedButtonTimeNow)
|
ON_BN_CLICKED(IDC_BUTTON_LOAD_SYSCFG_FILE, &CConfigToolView::OnBnClickedButtonLoadSyscfgFile)
|
ON_BN_CLICKED(IDC_BUTTON_SAVE_SYSCFG_FILE, &CConfigToolView::OnBnClickedButtonSaveSyscfgFile)
|
END_MESSAGE_MAP()
|
|
// CConfigToolView 构造/析构
|
|
CConfigToolView::CConfigToolView() noexcept
|
: CFormView(IDD_CONFIGTOOL_FORM)
|
{
|
// TODO: 在此处添加构造代码
|
psyscfg = (pstKMSysCfg)m_cfgdatabuf;
|
|
}
|
|
CConfigToolView::~CConfigToolView()
|
{
|
}
|
|
void CConfigToolView::DoDataExchange(CDataExchange* pDX)
|
{
|
CFormView::DoDataExchange(pDX);
|
DDX_Control(pDX, IDC_EDIT_LOG1, m_edit_log1);
|
}
|
|
BOOL CConfigToolView::PreCreateWindow(CREATESTRUCT& cs)
|
{
|
// TODO: 在此处通过修改
|
// CREATESTRUCT cs 来修改窗口类或样式
|
|
return CFormView::PreCreateWindow(cs);
|
}
|
|
int CConfigToolView::AddDlgItems()
|
{
|
for (int i = 0; i < nCtrls; i++)
|
{
|
if (pCStatics[i] != NULL) { delete pCStatics[i]; pCStatics[i] = NULL; }
|
if (pCWnds[i] != NULL) { delete pCWnds[i]; pCWnds[i] = NULL; }
|
|
}
|
|
int x0 = 20;
|
int y0 = 48;
|
|
int x1 = 220, x2 = 240, x3 = 480;
|
|
int height = 16;
|
int SpaceY = 24;
|
CString s1;
|
CRect rect1, rect2;
|
for (int i = 0; i < nCtrls; i++)
|
{
|
CString strs[100];
|
CStatic * p1;
|
CEdit * p2;
|
CComboBox * p3;
|
CButton * p5;
|
int n = 0;
|
rect1.left = x0, rect1.right = x1;
|
rect1.top = y0 + i * SpaceY;
|
rect1.bottom = rect1.top + height;
|
|
rect2.left = x2, rect2.right = x3;
|
rect2.top = y0 + i * SpaceY;
|
rect2.bottom = rect1.top + height;
|
|
int k = myCtrls[i].nType;
|
int j;
|
float f;
|
switch (k)
|
{
|
case CConfigToolDoc::typeNone:
|
break;
|
case CConfigToolDoc::typeText:
|
p1 = new CStatic();
|
// p1->SetWindowText(myCtrls[i].sName);
|
p1->Create(myCtrls[i].sName, SS_LEFT, rect1, this);
|
p1->ShowWindow(SW_SHOW);
|
pCStatics[i] = p1;
|
|
p2 = new CEdit;
|
p2->Create(ES_LEFT, rect2, this, myCtrls[i].nUID);
|
p2->ShowWindow(SW_SHOW);
|
p2->SetWindowText(myCtrls[i].Value);
|
|
pCWnds[i] = p2;
|
|
break;
|
case CConfigToolDoc::typeInt:
|
p1 = new CStatic();
|
// p1->SetWindowText(myCtrls[i].sName);
|
p1->Create(myCtrls[i].sName, SS_LEFT, rect1, this);
|
p1->ShowWindow(SW_SHOW);
|
pCStatics[i] = p1;
|
|
p2 = new CEdit;
|
p2->Create(ES_LEFT, rect2, this, myCtrls[i].nUID);
|
p2->ShowWindow(SW_SHOW);
|
j = _tstoi(myCtrls[i].Value);
|
s1.Format(_T("%d"), j);
|
p2->SetWindowText(s1);
|
|
pCWnds[i] = p2;
|
break;
|
case CConfigToolDoc::typeFloat:
|
p1 = new CStatic();
|
// p1->SetWindowText(myCtrls[i].sName);
|
p1->Create(myCtrls[i].sName, SS_LEFT, rect1, this);
|
p1->ShowWindow(SW_SHOW);
|
pCStatics[i] = p1;
|
|
p2 = new CEdit;
|
p2->Create(ES_LEFT, rect2, this, myCtrls[i].nUID);
|
p2->ShowWindow(SW_SHOW);
|
f = float(_tstof(myCtrls[i].Value));
|
s1.Format(_T("%.3f"), f);
|
p2->SetWindowText(s1);
|
pCWnds[i] = p2;
|
break;
|
case CConfigToolDoc::typeSelect:
|
p1 = new CStatic();
|
// p1->SetWindowText(myCtrls[i].sName);
|
p1->Create(myCtrls[i].sName, SS_LEFT, rect1, this);
|
p1->ShowWindow(SW_SHOW);
|
pCStatics[i] = p1;
|
|
p3 = new CComboBox;
|
p3->Create(CBS_DROPDOWN, rect2, this, myCtrls[i].nUID);
|
p3->ShowWindow(SW_SHOW);
|
s1 = myCtrls[i].Value;
|
n = Split(s1, _T("|"), strs);
|
for (int m = 0; m < n; m++)
|
{
|
p3->AddString(strs[m]);
|
}
|
p3->SetCurSel(0);
|
// p3->SetWindowText(myCtrls[i].Value);
|
pCWnds[i] = p3;
|
break;
|
case CConfigToolDoc::typeCheck:
|
p1 = new CStatic();
|
// p1->SetWindowText(myCtrls[i].sName);
|
p1->Create(myCtrls[i].sName, SS_LEFT, rect1, this);
|
p1->ShowWindow(SW_SHOW);
|
pCStatics[i] = p1;
|
|
p5 = new CButton;
|
p5->Create(myCtrls[i].sName, BS_CHECKBOX | BS_AUTOCHECKBOX, rect2, this, myCtrls[i].nUID);
|
p5->ShowWindow(SW_SHOW);
|
pCWnds[i] = p5;
|
break;
|
case CConfigToolDoc::typeButton:
|
p1 = new CStatic();
|
// p1->SetWindowText(myCtrls[i].sName);
|
p1->Create(myCtrls[i].sName, SS_LEFT, rect1, this);
|
p1->ShowWindow(SW_SHOW);
|
pCStatics[i] = p1;
|
|
p5 = new CButton;
|
p5->Create(myCtrls[i].sName, BS_PUSHBUTTON, rect2, this, myCtrls[i].nUID);
|
p5->ShowWindow(SW_SHOW);
|
pCWnds[i] = p5;
|
break;
|
|
default:
|
break;
|
}
|
}
|
return 0;
|
}
|
|
void CConfigToolView::OnInitialUpdate()
|
{
|
CFormView::OnInitialUpdate();
|
GetParentFrame()->RecalcLayout();
|
ResizeParentToFit();
|
|
CString VersionStr = _T("V1.02");
|
CString BuildStr = _T("20210728");
|
|
// TODO: 在此添加专用代码和/或调用基类
|
myLogger1.SetLogPathName(_T("D:\\Logs\\ConfigTool"), _T("ConfigTool"));
|
myLogger1.AttachWnd(m_edit_log1.m_hWnd);
|
myLogger1.bShowLog[0] = 1;
|
myLogger1.bShowThreadId = 0;
|
myLogger1.bShowChannel = 0;
|
myLogger1.bSaveLog[0] = 1;
|
myLogger1.bShowDate = 1;
|
SysLog(_T(" Start ") + VersionStr + _T(" ") + BuildStr + _T("\r\n"));
|
myLogger1.bShowDate = 0;
|
// myLogger1.bShowLineCount=0;
|
// myLogger1.bShowTime=0;
|
myLogger1.UpdateLogDisplay();
|
|
|
|
// AddDlgItems();
|
|
GetDlgItem(IDC_STATIC_PROP)->GetClientRect(&rect1);
|
m_nFrameheight = rect1.bottom - rect1.top;
|
GetDlgItem(IDC_STATIC_PROP)->ClientToScreen(&rect1);
|
this->ScreenToClient(&rect1);
|
|
|
m_propsyscfg1.Create(IDD_PROP_SYSREG1, this);
|
m_propsyscfg1.EnableWindow(true);
|
m_propsyscfg1.GetClientRect(&rect0);
|
m_nPropHeight = rect0.bottom - rect0.top;
|
m_propsyscfg1.ShowWindow(SW_SHOW);
|
m_propsyscfg1.MoveWindow(&rect1, true);
|
|
int nNewPos = m_nScrollPos;
|
int Scrolldel = nNewPos - m_nScrollPos;
|
m_propsyscfg1.ScrollWindow(0, Scrolldel);
|
m_nScrollPos += Scrolldel;
|
|
m_propsyscfg1.psyscfg = (pstKMSysCfg)m_cfgdatabuf;
|
|
m_propsyscfg1.m_nFrameheight = m_nFrameheight;
|
m_propsyscfg1.UpdateScrollInfo();
|
|
SCROLLINFO si;
|
si.cbSize = sizeof(SCROLLINFO);
|
si.fMask = SIF_ALL;
|
si.nMin = 0;
|
si.nMax = m_nPropHeight;//你滑动画面的高度
|
si.nPage = m_nFrameheight; //这个是你显示画面的高度
|
si.nPos = 0;//这个是滑块的位置 初始化的时候是0 以后会根据你的操作变动
|
// GetDlgItem(IDC_STATIC_PROP)->SetScrollInfo(SB_VERT, &si);
|
// m_propsyscfg1.SetScrollInfo(SB_VERT, &si);
|
|
// m_prop_scrollbar1.SetScrollInfo(&si, true);
|
|
SetTimer(0, 10, NULL);
|
SetTimer(1, 100, NULL);
|
SetTimer(2, 500, NULL);
|
|
}
|
|
|
// CConfigToolView 打印
|
|
BOOL CConfigToolView::OnPreparePrinting(CPrintInfo* pInfo)
|
{
|
// 默认准备
|
return DoPreparePrinting(pInfo);
|
}
|
|
void CConfigToolView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
|
{
|
// TODO: 添加额外的打印前进行的初始化过程
|
}
|
|
void CConfigToolView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
|
{
|
// TODO: 添加打印后进行的清理过程
|
}
|
|
void CConfigToolView::OnPrint(CDC* pDC, CPrintInfo* /*pInfo*/)
|
{
|
// TODO: 在此处添加自定义打印代码
|
}
|
|
|
// CConfigToolView 诊断
|
|
#ifdef _DEBUG
|
void CConfigToolView::AssertValid() const
|
{
|
CFormView::AssertValid();
|
}
|
|
void CConfigToolView::Dump(CDumpContext& dc) const
|
{
|
CFormView::Dump(dc);
|
}
|
|
CConfigToolDoc* CConfigToolView::GetDocument() const // 非调试版本是内联的
|
{
|
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CConfigToolDoc)));
|
return (CConfigToolDoc*)m_pDocument;
|
}
|
#endif //_DEBUG
|
|
|
// CConfigToolView 消息处理程序
|
|
void CConfigToolView::OnClose()
|
{
|
// TODO: 在此添加消息处理程序代码和/或调用默认值
|
CFormView::OnClose();
|
}
|
|
void CConfigToolView::OnDestroy()
|
{
|
CFormView::OnDestroy();
|
for (int i = 0; i < nCtrls; i++)
|
{
|
if (pCStatics[i] != NULL) { delete pCStatics[i]; pCStatics[i] = NULL; }
|
if (pCWnds[i] != NULL) { delete pCWnds[i]; pCWnds[i] = NULL; }
|
|
}
|
// TODO: 在此处添加消息处理程序代码
|
}
|
|
BOOL CConfigToolView::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
|
{
|
// TODO: 在此添加消息处理程序代码和/或调用默认值
|
CPoint pt1 = pt;
|
ScreenToClient(&pt1);
|
if (PtInRect(rect1, pt1))
|
{
|
int nNewPos = m_nScrollPos;
|
m_propsyscfg1.VScrollBy(-zDelta);
|
if (zDelta < 0)
|
{
|
if (-m_nScrollPos < m_nPropHeight - m_nFrameheight - 30)
|
nNewPos = m_nScrollPos - 30;
|
else
|
nNewPos = -(m_nPropHeight - m_nFrameheight);
|
}
|
else if (zDelta > 0)
|
{
|
if (-m_nScrollPos > 30)
|
nNewPos = m_nScrollPos + 30;
|
else
|
nNewPos = 0;
|
}
|
else
|
{
|
}
|
int Scrolldel = nNewPos - m_nScrollPos;
|
//m_propsyscfg1.ScrollWindow(0, Scrolldel);
|
m_nScrollPos += Scrolldel;
|
return true;
|
}
|
// m_prop_scrollbar1.SetScrollPos(-m_nScrollPos);
|
return CFormView::OnMouseWheel(nFlags, zDelta, pt);
|
}
|
|
void CConfigToolView::OnTimer(UINT_PTR nIDEvent)
|
{
|
// TODO: 在此添加消息处理程序代码和/或调用默认值
|
if (nIDEvent == 0)
|
{
|
KillTimer(0);
|
DelayInit();
|
}
|
else if (nIDEvent == 1)
|
{
|
myLogger1.UpdateLogDisplay();
|
}
|
else if (nIDEvent == 2)
|
{
|
TestAutoConnect();
|
}
|
|
CFormView::OnTimer(nIDEvent);
|
}
|
|
int CConfigToolView::DelayInit()
|
{
|
// TODO: 在此处添加实现代码.
|
return 0;
|
}
|
|
int CConfigToolView::TestAutoConnect()
|
{
|
// TODO: 在此处添加实现代码.
|
int res;
|
unsigned short nCount;
|
bool bNewConnected = false;
|
if (m_bOpened)
|
{
|
res = GetDocument()->MyKlink.GetInfo(1, &nCount, m_InfoBlockbuf);
|
if (res == KLink1::KL_OK)
|
{
|
bNewConnected = true;
|
if (m_bConnected == false)
|
{
|
// new connected one.
|
ShowInfoBlockParams();
|
m_bConnected = true;
|
}
|
}
|
else
|
{
|
m_bConnected = false;
|
ClearInfoBlockParams();
|
}
|
}
|
return 0;
|
}
|
|
|
int CConfigToolView::ClearInfoBlockParams()
|
{
|
// TODO: 在此处添加实现代码.
|
CString s1;
|
s1.Empty();
|
SetDlgItemText(IDC_EDIT_DEVICE_TYPE, s1);
|
SetDlgItemText(IDC_EDIT_DEVICE_NAME, s1);
|
SetDlgItemText(IDC_EDIT_FIRM_VER, s1);
|
SetDlgItemText(IDC_EDIT_KLINK_VER, s1);
|
SetDlgItemText(IDC_EDIT_KBUS_VER, s1);
|
SetDlgItemText(IDC_EDIT_KNET_VER, s1);
|
SetDlgItemText(IDC_EDIT_KWL_VER, s1);
|
SetDlgItemText(IDC_EDIT_FUNCTIONS, s1);
|
|
SetDlgItemText(IDC_EDIT_CAP_PROG, s1);
|
SetDlgItemText(IDC_EDIT_CAP_DT, s1);
|
|
SetDlgItemText(IDC_EDIT_CAP_WR, s1);
|
SetDlgItemText(IDC_EDIT_CAP_TM, s1);
|
SetDlgItemText(IDC_EDIT_CAP_SW, s1);
|
SetDlgItemText(IDC_EDIT_CAP_COM, s1);
|
SetDlgItemText(IDC_EDIT_CAP_CFG, s1);
|
SetDlgItemText(IDC_EDIT_CAP_EVENT, s1);
|
|
SetDlgItemText(IDC_EDIT_CAP_DIN, s1);
|
SetDlgItemText(IDC_EDIT_CAP_DOUT, s1);
|
SetDlgItemText(IDC_EDIT_CAP_AIN_I, s1);
|
SetDlgItemText(IDC_EDIT_CAP_AOUT_I, s1);
|
SetDlgItemText(IDC_EDIT_CAP_AIN_E, s1);
|
SetDlgItemText(IDC_EDIT_CAP_AOUT_E, s1);
|
SetDlgItemText(IDC_EDIT_CAP_HIN, s1);
|
SetDlgItemText(IDC_EDIT_CAP_HOUT, s1);
|
SetDlgItemText(IDC_EDIT_CAP_IRQ_I, s1);
|
SetDlgItemText(IDC_EDIT_CAP_IRQ_O, s1);
|
SetDlgItemText(IDC_EDIT_CAP_EXT_I, s1);
|
SetDlgItemText(IDC_EDIT_CAP_EXT_O, s1);
|
|
SetDlgItemText(IDC_EDIT_DEVICE_UID, s1);
|
|
return 0;
|
}
|
|
|
CString CConfigToolView::GetDeviceNameStr(int DeviceTypeVer)
|
{
|
// TODO: 在此处添加实现代码.
|
static CString DeviceName;
|
DeviceName.Empty();
|
CString s1,s2;
|
UCHAR DeviceType, DeviceVer;
|
DeviceType = (DeviceTypeVer>>8)&0xff;
|
DeviceVer = DeviceTypeVer & 0xff;
|
s1.Format(_T("%02X"), DeviceType);
|
|
if (DeviceList["FAMILY"].Exist(s1))
|
{
|
DeviceName = DeviceList["FAMiLY"][s1];
|
s2.Format(_T("%02X"), DeviceVer);
|
Hash h1 = DeviceList[s1];
|
if (DeviceList[s1].Exist(s2))
|
{
|
DeviceName.Append(_T(", "));
|
DeviceName.Append (DeviceList[s1][s2]);
|
}
|
else
|
{
|
DeviceName.Append(_T(", "));
|
DeviceName.AppendFormat(_T("Version %02X"),DeviceVer);
|
}
|
}
|
else { DeviceName.Format(_T("Device %02X, Version %02X"),DeviceType,DeviceVer); }
|
|
return DeviceName;
|
}
|
|
int CConfigToolView::ShowInfoBlockParams()
|
{
|
// TODO: 在此处添加实现代码.
|
CString s1;
|
|
pInfoBlock = (pKMInfoBlock)m_InfoBlockbuf;
|
s1.Format(_T("%04X"), pInfoBlock->nDeviceTypeVer);
|
SetDlgItemText(IDC_EDIT_DEVICE_TYPE, s1);
|
|
s1 = GetDeviceNameStr(pInfoBlock->nDeviceTypeVer);
|
SetDlgItemText(IDC_EDIT_DEVICE_NAME, s1);
|
|
s1.Format(_T("%04X"), pInfoBlock->nProgVer);
|
SetDlgItemText(IDC_EDIT_FIRM_VER, s1);
|
s1.Format(_T("%04X"), pInfoBlock->nKLinkVer);
|
SetDlgItemText(IDC_EDIT_KLINK_VER, s1);
|
s1.Format(_T("%04X"), pInfoBlock->nKBusVer);
|
SetDlgItemText(IDC_EDIT_KBUS_VER, s1);
|
s1.Format(_T("%04X"), 0);
|
s1.Empty();
|
SetDlgItemText(IDC_EDIT_KNET_VER, s1);
|
//s1.Format(_T("%04X"), 0);
|
SetDlgItemText(IDC_EDIT_KWL_VER, s1);
|
s1.Format(_T("%04X"), pInfoBlock->nAbility);
|
SetDlgItemText(IDC_EDIT_FUNCTIONS, s1);
|
|
s1.Format(_T("%d"), pInfoBlock->nCapacity1);
|
SetDlgItemText(IDC_EDIT_CAP_PROG, s1);
|
s1.Format(_T("%d"), pInfoBlock->nCapacity2);
|
SetDlgItemText(IDC_EDIT_CAP_DT, s1);
|
|
SetDlgItemText(IDC_EDIT_CAP_WR, s1);
|
SetDlgItemText(IDC_EDIT_CAP_TM, s1);
|
s1.Format(_T("%d"), pInfoBlock->nSwitchBits);
|
SetDlgItemText(IDC_EDIT_CAP_SW, s1);
|
s1.Format(_T("%d"), pInfoBlock->nPorts);
|
SetDlgItemText(IDC_EDIT_CAP_COM, s1);
|
s1.Format(_T("%d"), pInfoBlock->nManSize);
|
SetDlgItemText(IDC_EDIT_CAP_CFG, s1);
|
s1.Format(_T("%d"), pInfoBlock->nLogSize);
|
SetDlgItemText(IDC_EDIT_CAP_EVENT, s1);
|
|
s1.Format(_T("%d"), pInfoBlock->nDInput);
|
SetDlgItemText(IDC_EDIT_CAP_DIN, s1);
|
s1.Format(_T("%d"), pInfoBlock->nDInput);
|
SetDlgItemText(IDC_EDIT_CAP_DOUT, s1);
|
s1.Format(_T("%d"), pInfoBlock->nAInput);
|
SetDlgItemText(IDC_EDIT_CAP_AIN_I, s1);
|
s1.Format(_T("%d"), pInfoBlock->nAOutput);
|
SetDlgItemText(IDC_EDIT_CAP_AOUT_I, s1);
|
s1.Format(_T("%d"), pInfoBlock->nAInput);
|
SetDlgItemText(IDC_EDIT_CAP_AIN_E, s1);
|
s1.Format(_T("%d"), pInfoBlock->nAOutput);
|
SetDlgItemText(IDC_EDIT_CAP_AOUT_E, s1);
|
s1.Format(_T("%d"), pInfoBlock->nHInput);
|
SetDlgItemText(IDC_EDIT_CAP_HIN, s1);
|
s1.Format(_T("%d"), pInfoBlock->nHOutput);
|
SetDlgItemText(IDC_EDIT_CAP_HOUT, s1);
|
s1.Empty();
|
SetDlgItemText(IDC_EDIT_CAP_IRQ_I, s1);
|
SetDlgItemText(IDC_EDIT_CAP_IRQ_O, s1);
|
SetDlgItemText(IDC_EDIT_CAP_EXT_I, s1);
|
SetDlgItemText(IDC_EDIT_CAP_EXT_O, s1);
|
|
unsigned short len1;
|
int res = GetDocument()->MyKlink.GetUID(1, &len1, (unsigned short *)uuidbuf);
|
// SysLog(GetDocument()->MyKlink.m_resultStr);
|
s1.Format(_T("GetUID = %d %d bytes"), res, len1);
|
// SysLog(s1);
|
CString s2;
|
if (res == KLink1::KL_OK)
|
{
|
s1.Append(_T("\r\n"));
|
for (int i = 0; i < 12; i++)
|
{
|
s1.AppendFormat(_T("%02X "), uuidbuf[i]);
|
s2.AppendFormat(_T("%02X"), uuidbuf[12 - i - 1]);
|
// s3.AppendFormat(_T("%c"), buf2[12 - i - 1]);
|
}
|
}
|
// SysLog(s1);
|
struuid = s2;
|
SetDlgItemText(IDC_EDIT_DEVICE_UID, struuid);
|
|
return 0;
|
}
|
|
|
int CConfigToolView::ShowFactoryDataParams()
|
{
|
// TODO: 在此处添加实现代码.
|
pfactorydata = (stFactoryData *)m_factorydataBuf;
|
|
return 0;
|
}
|
|
|
int CConfigToolView::ShowParams()
|
{
|
// TODO: 在此处添加实现代码.
|
ShowInfoBlockParams();
|
ShowFactoryDataParams();
|
m_propsyscfg1.ShowParams();
|
return 0;
|
}
|
|
int CConfigToolView::GetFactoryDataParams()
|
{
|
// TODO: 在此处添加实现代码.
|
m_propsyscfg1.GetParams();
|
|
return 0;
|
}
|
|
int CConfigToolView::GetParams()
|
{
|
// TODO: 在此处添加实现代码.
|
|
return 0;
|
}
|
|
void CConfigToolView::OnBnClickedButtonCommSet()
|
{
|
// TODO: 在此添加控件通知处理程序代码
|
CString s1;
|
|
int res = GetDocument()->MyKlink.SetCommParam();
|
s1.Format(_T("Com Set = %d COM%d %d %s"),res, GetDocument()->MyKlink.m_nPort, GetDocument()->MyKlink.m_nBaudRate, GetDocument()->MyKlink.m_Settings);
|
SysLog(s1);
|
}
|
|
void CConfigToolView::OnBnClickedButtonConnect()
|
{
|
// TODO: 在此添加控件通知处理程序代码
|
int res = ((CConfigToolDoc *)m_pDocument)->MyKlink.Connect();
|
CString s1;
|
s1.Format(_T("connect = %d %s"), res,GetDocument()->MyKlink.m_resultStr);
|
SysLog(s1);
|
if (res == KLink1::KL_OK) m_bOpened = true;
|
else { return; }
|
|
unsigned short nCount;
|
res = ((CConfigToolDoc *)m_pDocument)->MyKlink.GetInfo(1, &nCount, m_InfoBlockbuf);
|
pInfoBlock = (pKMInfoBlock)m_InfoBlockbuf;
|
s1.Format(_T("read InfoBlock = %d %d bytes \r\n"), res, nCount);
|
// s1 += FormatHex(m_InfoBlockbuf, nCount);
|
SysLog(s1);
|
if (res == KLink1::KL_OK)
|
{
|
ShowInfoBlockParams();
|
}
|
unsigned char DCount = 120;
|
res = ((CConfigToolDoc *)m_pDocument)->MyKlink.ReadFactoryData(1, 0, DCount, &nCount, m_factorydataBuf);
|
pfactorydata = (stFactoryData *)m_factorydataBuf;
|
s1.Format(_T("read FactoryData = %d %d bytes \r\n"), res, nCount);
|
// s1 += FormatHex(m_factorydataBuf, nCount);
|
SysLog(s1);
|
|
res = ((CConfigToolDoc *)m_pDocument)->MyKlink.ReadSysCfgData(1, 0, 0, DCount, &nCount, m_cfgdatabuf);
|
psyscfg = (pstKMSysCfg)m_cfgdatabuf;
|
s1.Format(_T("read SysCfgData = %d %d bytes \r\n"), res, nCount);
|
// s1 += FormatHex(m_cfgdatabuf, nCount);
|
SysLog(s1);
|
|
}
|
|
void CConfigToolView::OnBnClickedButtonDisconnect()
|
{
|
// TODO: 在此添加控件通知处理程序代码
|
CString s1;
|
int res = ((CConfigToolDoc *)m_pDocument)->MyKlink.Close();
|
m_bOpened = false;
|
s1.Format(_T("Close = %d "), res);
|
SysLog(s1);
|
}
|
|
void CConfigToolView::OnBnClickedButtonUpload()
|
{
|
// TODO: 在此添加控件通知处理程序代码
|
// unsigned short values[100];
|
int res;
|
CString s1;
|
unsigned short nCount;
|
|
res = ((CConfigToolDoc *)m_pDocument)->MyKlink.GetInfo(1, &nCount, m_InfoBlockbuf);
|
pInfoBlock = (pKMInfoBlock)m_InfoBlockbuf;
|
s1.Format(_T("read InfoBlock = %d %d bytes \r\n"), res, nCount);
|
s1 += FormatHex(m_InfoBlockbuf, nCount);
|
SysLog(s1);
|
unsigned char DCount = 120;
|
res = ((CConfigToolDoc *)m_pDocument)->MyKlink.ReadFactoryData(1, 0, DCount, &nCount, m_factorydataBuf);
|
pfactorydata = (stFactoryData *)m_factorydataBuf;
|
s1.Format(_T("read FactoryData = %d %d bytes \r\n"), res, nCount);
|
s1 += FormatHex(m_factorydataBuf, nCount);
|
SysLog(s1);
|
|
res = ((CConfigToolDoc *)m_pDocument)->MyKlink.ReadSysCfgData(1, 0,0, DCount, &nCount, m_cfgdatabuf);
|
psyscfg = (pstKMSysCfg)m_cfgdatabuf;
|
s1.Format(_T("read SysCfgData = %d %d bytes \r\n"), res, nCount);
|
s1 += FormatHex(m_cfgdatabuf, nCount);
|
SysLog(s1);
|
|
if (res == KLink1::KL_OK)
|
{
|
ShowParams();
|
}
|
|
// m_propsyscfg1.ShowParams();
|
}
|
|
void CConfigToolView::OnBnClickedButtonDownload()
|
{
|
int res;
|
CString s1;
|
unsigned char DCount = 120;
|
unsigned short nCount=0;
|
m_propsyscfg1.GetParams();
|
|
res = ((CConfigToolDoc *)m_pDocument)->MyKlink.WriteSysCfgData(1, 0, 0, DCount, m_cfgdatabuf);
|
// m_propsyscfg1.psyscfg = (pKMSysCfg)m_cfgdatabuf;
|
s1.Format(_T("Download = %d %d bytes"), res, DCount);
|
SysLog(s1);
|
if (res != KLink1::KL_OK)
|
{
|
s1.Format(_T("下载失败 "));
|
s1 += ((CConfigToolDoc *)m_pDocument)->MyKlink.m_resultStr;
|
s1 += ((CConfigToolDoc *)m_pDocument)->MyKlink.GetErrDescStr(res);
|
SysLog(s1);
|
}
|
|
// TODO: 在此添加控件通知处理程序代码
|
}
|
|
void CConfigToolView::OnBnClickedButtonEventlog()
|
{
|
// TODO: 在此添加控件通知处理程序代码
|
}
|
|
|
void CConfigToolView::OnBnClickedButtonWritedata()
|
{
|
// TODO: 在此添加控件通知处理程序代码
|
}
|
|
|
|
|
void CConfigToolView::OnBnClickedButtonTimeNow()
|
{
|
// TODO: 在此添加控件通知处理程序代码
|
}
|
|
|
void CConfigToolView::OnBnClickedButtonLoadSyscfgFile()
|
{
|
// TODO: 在此添加控件通知处理程序代码
|
CString s1;
|
CString strFilePath1;
|
MHash syscfg1;
|
CFileDialog dlg1(true,_T("*.cfg"),NULL,NULL,_T("配置文件(*.cfg)|*.cfg|所有文件 (*.*)|*.*||"),this);
|
INT_PTR r= dlg1.DoModal();
|
if (r == IDOK)
|
{
|
strFilePath1 = dlg1.GetPathName();
|
int res = syscfg1.LoadFromFile(strFilePath1);
|
s1.Format(_T("Load from file %s = %d "), strFilePath1, res);
|
SysLog(s1);
|
psyscfg->Version = int(syscfg1["SYSTEM"]["Version"]);
|
psyscfg->workmode = int(syscfg1["SYSTEM"]["WorkMode"]);
|
psyscfg->SwitchFunc = _tstoi(syscfg1["SYSTEM"]["SwitchFunc"]);
|
psyscfg->nCfgBlockCount = 0;
|
|
psyscfg->PortParams[0].WorkMode = int(syscfg1["Port_1"]["WorkMode"]);
|
psyscfg->PortParams[0].Station = int(syscfg1["Port_1"]["Station"]);
|
psyscfg->PortParams[0].BaudRate = int(syscfg1["Port_1"]["BaudRate"]);
|
psyscfg->PortParams[0].ByteSize = int(syscfg1["Port_1"]["ByteSize"]);
|
psyscfg->PortParams[0].Parity = int(syscfg1["Port_1"]["Parity"]);
|
psyscfg->PortParams[0].StopBits = int(syscfg1["Port_1"]["StopBits"]);
|
psyscfg->PortParams[0].EndType = int(syscfg1["Port_1"]["EndType"]);
|
psyscfg->PortParams[0].EofChar = int(syscfg1["Port_1"]["EofChar"]);
|
psyscfg->PortParams[0].SofChar = int(syscfg1["Port_1"]["SofChar"]);
|
psyscfg->PortParams[0].EndTime = int(syscfg1["Port_1"]["EndTime"]);
|
psyscfg->PortParams[0].RecvAddr = int(syscfg1["Port_1"]["RecvAddr"]);
|
psyscfg->PortParams[0].RecvSize = int(syscfg1["Port_1"]["RecvSize"]);
|
|
psyscfg->PortParams[1].WorkMode = int(syscfg1["Port_2"]["WorkMode"]);
|
psyscfg->PortParams[1].Station = int(syscfg1["Port_2"]["Station"]);
|
psyscfg->PortParams[1].BaudRate = int(syscfg1["Port_2"]["BaudRate"]);
|
psyscfg->PortParams[1].ByteSize = int(syscfg1["Port_2"]["ByteSize"]);
|
psyscfg->PortParams[1].Parity = int(syscfg1["Port_2"]["Parity"]);
|
psyscfg->PortParams[1].StopBits = int(syscfg1["Port_2"]["StopBits"]);
|
psyscfg->PortParams[1].EndType = int(syscfg1["Port_2"]["EndType"]);
|
psyscfg->PortParams[1].EofChar = int(syscfg1["Port_2"]["EofChar"]);
|
psyscfg->PortParams[1].SofChar = int(syscfg1["Port_2"]["SofChar"]);
|
psyscfg->PortParams[1].EndTime = int(syscfg1["Port_2"]["EndTime"]);
|
psyscfg->PortParams[1].RecvAddr = int(syscfg1["Port_2"]["RecvAddr"]);
|
psyscfg->PortParams[1].RecvSize = int(syscfg1["Port_2"]["RecvSize"]);
|
|
psyscfg->OutMappings[0].value = int(syscfg1["OutMapping"]["Output_0"]);
|
psyscfg->OutMappings[1].value = int(syscfg1["OutMapping"]["Output_1"]);
|
psyscfg->OutMappings[2].value = int(syscfg1["OutMapping"]["Output_2"]);
|
psyscfg->OutMappings[3].value = int(syscfg1["OutMapping"]["Output_3"]);
|
psyscfg->OutMappings[4].value = int(syscfg1["OutMapping"]["Output_4"]);
|
psyscfg->OutMappings[5].value = int(syscfg1["OutMapping"]["Output_5"]);
|
|
m_propsyscfg1.ShowParams();
|
|
}
|
|
|
}
|
|
|
void CConfigToolView::OnBnClickedButtonSaveSyscfgFile()
|
{
|
// TODO: 在此添加控件通知处理程序代码
|
CString s1;
|
CString sFilePathName1;
|
MHash syscfg1;
|
|
m_propsyscfg1.GetParams();
|
|
syscfg1["SYSTEM"]["Version"] = psyscfg->Version;
|
syscfg1["SYSTEM"]["WorkMode"] = psyscfg->workmode;
|
syscfg1["SYSTEM"]["SwitchFunc"] = psyscfg->SwitchFunc;
|
|
syscfg1["Port_1"]["WorkMode"] = psyscfg->PortParams[0].WorkMode;
|
syscfg1["Port_1"]["Station"] = psyscfg->PortParams[0].Station;
|
syscfg1["Port_1"]["BaudRate"] = psyscfg->PortParams[0].BaudRate;
|
syscfg1["Port_1"]["ByteSize"] = psyscfg->PortParams[0].ByteSize;
|
syscfg1["Port_1"]["Parity"] = psyscfg->PortParams[0].Parity;
|
syscfg1["Port_1"]["StopBits"] = psyscfg->PortParams[0].StopBits;
|
syscfg1["Port_1"]["EndType"] = psyscfg->PortParams[0].EndType;
|
syscfg1["Port_1"]["EofChar"] = psyscfg->PortParams[0].EofChar;
|
syscfg1["Port_1"]["SofChar"] = psyscfg->PortParams[0].SofChar;
|
syscfg1["Port_1"]["EndTime"] = psyscfg->PortParams[0].EndTime;
|
syscfg1["Port_1"]["RecvAddr"] = psyscfg->PortParams[0].RecvAddr;
|
syscfg1["Port_1"]["RecvSize"] = psyscfg->PortParams[0].RecvSize;
|
|
syscfg1["Port_2"]["WorkMode"] = psyscfg->PortParams[1].WorkMode;
|
syscfg1["Port_2"]["Station"] = psyscfg->PortParams[1].Station;
|
syscfg1["Port_2"]["BaudRate"] = psyscfg->PortParams[1].BaudRate;
|
syscfg1["Port_2"]["ByteSize"] = psyscfg->PortParams[1].ByteSize;
|
syscfg1["Port_2"]["Parity"] = psyscfg->PortParams[1].Parity;
|
syscfg1["Port_2"]["StopBits"] = psyscfg->PortParams[1].StopBits;
|
syscfg1["Port_2"]["EndType"] = psyscfg->PortParams[1].EndType;
|
syscfg1["Port_2"]["EofChar"] = psyscfg->PortParams[1].EofChar;
|
syscfg1["Port_2"]["SofChar"] = psyscfg->PortParams[1].SofChar;
|
syscfg1["Port_2"]["EndTime"] = psyscfg->PortParams[1].EndTime;
|
syscfg1["Port_2"]["RecvAddr"] = psyscfg->PortParams[1].RecvAddr;
|
syscfg1["Port_2"]["RecvSize"] = psyscfg->PortParams[1].RecvSize;
|
|
syscfg1["SYSTEM"]["Version"] = psyscfg->Version;
|
|
syscfg1["OutMapping"]["Output_0"] = psyscfg->OutMappings[0].value;
|
syscfg1["OutMapping"]["Output_1"] = psyscfg->OutMappings[1].value;
|
syscfg1["OutMapping"]["Output_2"] = psyscfg->OutMappings[2].value;
|
syscfg1["OutMapping"]["Output_3"] = psyscfg->OutMappings[3].value;
|
syscfg1["OutMapping"]["Output_4"] = psyscfg->OutMappings[4].value;
|
syscfg1["OutMapping"]["Output_5"] = psyscfg->OutMappings[5].value;
|
|
CFileDialog dlg1(false, _T("*.cfg"),NULL, OFN_OVERWRITEPROMPT, _T("配置文件(*.cfg)|*.cfg|所有文件 (*.*)|*.*||"),this);
|
INT_PTR r = dlg1.DoModal();
|
if (r == IDOK)
|
{
|
int res = 0;
|
sFilePathName1 = dlg1.GetPathName();
|
s1.Format(_T("Save to File %s = %d "), sFilePathName1, res);
|
SysLog(s1);
|
syscfg1.SaveToFile(sFilePathName1);
|
}
|
|
}
|
|