QuakeGod
2024-12-24 61deef5cdf96cbfdd6ad45be49e80d597c00ca65
2024-12-24
49个文件已修改
86个文件已添加
12088 ■■■■■ 已修改文件
ConfigTool/CChidSysCfg1.cpp 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ConfigTool/CChidSysCfg1.h 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
ConfigTool/ConfigTool.vcxproj 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
ConfigTool/ConfigToolView.cpp 40 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ConfigTool/ConfigToolView.h 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
FirmwareTool/DeviceList.ini 55 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
FirmwareTool/FirmwareTool.cpp 191 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
FirmwareTool/FirmwareTool.h 66 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
FirmwareTool/FirmwareTool.rc 补丁 | 查看 | 原始文档 | blame | 历史
FirmwareTool/FirmwareTool.vcxproj 215 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
FirmwareTool/FirmwareTool.vcxproj.filters 63 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
FirmwareTool/FirmwareToolDlg.cpp 705 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
FirmwareTool/FirmwareToolDlg.h 125 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
FirmwareTool/RCa14640 补丁 | 查看 | 原始文档 | blame | 历史
FirmwareTool/framework.h 49 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
FirmwareTool/pch.cpp 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
FirmwareTool/pch.h 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
FirmwareTool/res/FirmwareTool.ico 补丁 | 查看 | 原始文档 | blame | 历史
FirmwareTool/res/FirmwareTool.rc2 补丁 | 查看 | 原始文档 | blame | 历史
FirmwareTool/resource.h 31 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
FirmwareTool/targetver.h 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
KLink1/CDialogCommSet1.cpp 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
KLink1/HvSerialPort.cpp 18 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
KLink1/HvSerialPort.h 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
KLink1/KLink.cpp 475 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
KLink1/KLink.h 163 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
KwLoRaTool/KwLoRaTool.cpp 155 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
KwLoRaTool/KwLoRaTool.h 41 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
KwLoRaTool/KwLoRaTool.rc 补丁 | 查看 | 原始文档 | blame | 历史
KwLoRaTool/KwLoRaTool.vcxproj 219 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
KwLoRaTool/KwLoRaTool.vcxproj.filters 69 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
KwLoRaTool/KwLoRaToolDlg.cpp 601 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
KwLoRaTool/KwLoRaToolDlg.h 134 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
KwLoRaTool/MyButton.cpp 29 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
KwLoRaTool/MyButton.h 17 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
KwLoRaTool/framework.h 49 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
KwLoRaTool/pch.cpp 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
KwLoRaTool/pch.h 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
KwLoRaTool/res/KwLoRaTool.ico 补丁 | 查看 | 原始文档 | blame | 历史
KwLoRaTool/res/KwLoRaTool.rc2 补丁 | 查看 | 原始文档 | blame | 历史
KwLoRaTool/resource.h 64 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
KwLoRaTool/targetver.h 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
LCDDisplay/RCa14640 补丁 | 查看 | 原始文档 | blame | 历史
MFCApplication1/ChildFrm.cpp 101 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MFCApplication1/ChildFrm.h 43 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MFCApplication1/ChildView.cpp 55 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MFCApplication1/ChildView.h 36 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MFCApplication1/MFCApplication1.cpp 186 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MFCApplication1/MFCApplication1.h 39 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MFCApplication1/MFCApplication1.rc 补丁 | 查看 | 原始文档 | blame | 历史
MFCApplication1/MFCApplication1.vcxproj 220 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MFCApplication1/MFCApplication1.vcxproj.filters 78 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MFCApplication1/MainFrm.cpp 96 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MFCApplication1/MainFrm.h 42 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MFCApplication1/Resource.h 20 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MFCApplication1/framework.h 49 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MFCApplication1/pch.cpp 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MFCApplication1/pch.h 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MFCApplication1/res/MFCApplication1.ico 补丁 | 查看 | 原始文档 | blame | 历史
MFCApplication1/res/MFCApplication1.rc2 补丁 | 查看 | 原始文档 | blame | 历史
MFCApplication1/res/Toolbar.bmp 补丁 | 查看 | 原始文档 | blame | 历史
MFCApplication1/targetver.h 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MFCMView/ChildFrm.cpp 104 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MFCMView/ChildFrm.h 43 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MFCMView/ChildView.cpp 55 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MFCMView/ChildView.h 36 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MFCMView/MFCMView.cpp 188 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MFCMView/MFCMView.h 39 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MFCMView/MFCMView.rc 补丁 | 查看 | 原始文档 | blame | 历史
MFCMView/MFCMView.vcxproj 220 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MFCMView/MFCMView.vcxproj.filters 78 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MFCMView/MainFrm.cpp 108 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MFCMView/MainFrm.h 42 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MFCMView/Resource.h 20 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MFCMView/framework.h 49 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MFCMView/pch.cpp 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MFCMView/pch.h 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MFCMView/res/MFCMView.ico 补丁 | 查看 | 原始文档 | blame | 历史
MFCMView/res/MFCMView.rc2 补丁 | 查看 | 原始文档 | blame | 历史
MFCMView/res/Toolbar.bmp 补丁 | 查看 | 原始文档 | blame | 历史
MFCMView/targetver.h 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MTerm1.sln 30 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MTerm1/0prog2.kpg 49 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MTerm1/CChidSysCfg1.cpp 428 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MTerm1/CChidSysCfg1.h 44 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MTerm1/ConfigToolView.cpp 934 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MTerm1/ConfigToolView.h 109 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MTerm1/DeviceList.ini 55 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MTerm1/DialogDateTime.cpp 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
MTerm1/DialogEventLog.cpp 10 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MTerm1/DialogFactCfg.cpp 44 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MTerm1/DialogStatusShow.cpp 41 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MTerm1/DialogSysRegSet.cpp 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MTerm1/DialogSysRegSet.h 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
MTerm1/KDefine.h 314 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MTerm1/KMachine.cpp 7 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MTerm1/KMachine.h 39 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MTerm1/MTerm1.cpp 60 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MTerm1/MTerm1.h 36 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MTerm1/MTerm1.rc 补丁 | 查看 | 原始文档 | blame | 历史
MTerm1/MTerm1.vcxproj 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MTerm1/MTerm1.vcxproj.filters 30 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MTerm1/MTerm1BnlView.cpp 200 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MTerm1/MTerm1BnlView.h 19 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MTerm1/MTerm1CommDevView.cpp 890 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MTerm1/MTerm1CommDevView.h 177 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MTerm1/MTerm1CtrlView.cpp 28 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MTerm1/MTerm1CtrlView.h 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MTerm1/MTerm1Doc.cpp 374 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MTerm1/MTerm1Doc.h 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MTerm1/MTerm1View.cpp 166 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MTerm1/MTerm1View.h 32 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MTerm1/MainFrm.cpp 111 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MTerm1/MainFrm.h 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MTerm1/MyChildFrm.cpp 164 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MTerm1/MyChildFrm.h 50 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MTerm1/MyChildFrmConfig.cpp 164 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MTerm1/MyChildFrmConfig.h 50 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MTerm1/MyFormLog.cpp 16 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MTerm1/MyPaneLog.cpp 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MTerm1/NavView.cpp 1430 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MTerm1/NavView.h 121 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MTerm1/RCa14640 补丁 | 查看 | 原始文档 | blame | 历史
MTerm1/RCb14640 补丁 | 查看 | 原始文档 | blame | 历史
MTerm1/RCc14640 补丁 | 查看 | 原始文档 | blame | 历史
MTerm1/RCd14640 补丁 | 查看 | 原始文档 | blame | 历史
MTerm1/Resource.h 133 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MTerm1/res/sort.bmp 补丁 | 查看 | 原始文档 | blame | 历史
MTerm1/res/sort1.bmp 补丁 | 查看 | 原始文档 | blame | 历史
MTerm1/res/sort_25.bmp 补丁 | 查看 | 原始文档 | blame | 历史
MTerm2/NavView.cpp 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MTerm2/NavView.h 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
MultiTerminal1/MultiTerminal1.vcxproj 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MyLib/LOGGER/Logger.hpp 5 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MyLib/MHashINI/MHash.hpp 18 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ConfigTool/CChidSysCfg1.cpp
@@ -344,7 +344,7 @@
// ---  输出端口映射  ----------------------------
    for (int i = 0; i < 6; i++) {
        unsigned short bytebitaddr = psyscfg->OutMappings[i];
        unsigned short bytebitaddr = psyscfg->OutMappings[i].value;
        s1.Format(_T("mappig %d %04x"), i, bytebitaddr);
        SysLog(s1);
        unsigned char ntype = (bytebitaddr & 0xf000) >> 12;
@@ -374,7 +374,7 @@
        unsigned char byteaddr = ((CComboBox *)GetDlgItem(addr_ctrl_ids[i]))->GetCurSel();
        unsigned char bitoff = ((CComboBox *)GetDlgItem(bit_ctrl_ids[i]))->GetCurSel();
        unsigned short bytebitaddr = (ntype << 12) + (byteaddr << 4) + (bitoff);
            psyscfg->OutMappings[i] = bytebitaddr;
            psyscfg->OutMappings[i].value = bytebitaddr;
            s1.Format(_T("mappig %d %04x"), i, bytebitaddr);
            SysLog(s1);
    }
ConfigTool/CChidSysCfg1.h
@@ -26,7 +26,7 @@
    int m_nFrameheight;
    int m_nScrollPos = 0;
    pKMSysCfg psyscfg;
    pstKMSysCfg psyscfg;
    int DelayInit();
    int ShowParams();
ConfigTool/ConfigTool.vcxproj
@@ -51,7 +51,7 @@
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
    <ConfigurationType>Application</ConfigurationType>
    <UseDebugLibraries>false</UseDebugLibraries>
    <PlatformToolset>v143</PlatformToolset>
    <PlatformToolset>v142</PlatformToolset>
    <WholeProgramOptimization>true</WholeProgramOptimization>
    <CharacterSet>Unicode</CharacterSet>
    <UseOfMfc>Dynamic</UseOfMfc>
ConfigTool/ConfigToolView.cpp
@@ -75,7 +75,7 @@
    : CFormView(IDD_CONFIGTOOL_FORM)
{
    // TODO: 在此处添加构造代码
    psyscfg = (pKMSysCfg)m_cfgdatabuf;
    psyscfg = (pstKMSysCfg)m_cfgdatabuf;
}
@@ -281,7 +281,7 @@
    m_propsyscfg1.ScrollWindow(0, Scrolldel);
    m_nScrollPos += Scrolldel;
    m_propsyscfg1.psyscfg = (pKMSysCfg)m_cfgdatabuf;
    m_propsyscfg1.psyscfg = (pstKMSysCfg)m_cfgdatabuf;
    m_propsyscfg1.m_nFrameheight = m_nFrameheight;
    m_propsyscfg1.UpdateScrollInfo();
@@ -693,8 +693,8 @@
//    s1 += FormatHex(m_factorydataBuf, nCount);
    SysLog(s1);
    res = ((CConfigToolDoc *)m_pDocument)->MyKlink.ReadSysCfgData(1, 0, DCount, &nCount, m_cfgdatabuf);
    psyscfg = (pKMSysCfg)m_cfgdatabuf;
    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);
@@ -731,8 +731,8 @@
    s1 += FormatHex(m_factorydataBuf, nCount);
    SysLog(s1);
    res = ((CConfigToolDoc *)m_pDocument)->MyKlink.ReadSysCfgData(1, 0, DCount, &nCount, m_cfgdatabuf);
    psyscfg = (pKMSysCfg)m_cfgdatabuf;
    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);
@@ -753,7 +753,7 @@
    unsigned short nCount=0;
    m_propsyscfg1.GetParams();
    res = ((CConfigToolDoc *)m_pDocument)->MyKlink.WriteSysCfgData(1, 0, DCount, m_cfgdatabuf);
    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);
@@ -805,7 +805,7 @@
        psyscfg->Version = int(syscfg1["SYSTEM"]["Version"]);
        psyscfg->workmode = int(syscfg1["SYSTEM"]["WorkMode"]);
        psyscfg->SwitchFunc = _tstoi(syscfg1["SYSTEM"]["SwitchFunc"]);
        psyscfg->Space1 = 0;
        psyscfg->nCfgBlockCount = 0;
        psyscfg->PortParams[0].WorkMode = int(syscfg1["Port_1"]["WorkMode"]);
        psyscfg->PortParams[0].Station = int(syscfg1["Port_1"]["Station"]);
@@ -833,12 +833,12 @@
        psyscfg->PortParams[1].RecvAddr = int(syscfg1["Port_2"]["RecvAddr"]);
        psyscfg->PortParams[1].RecvSize = int(syscfg1["Port_2"]["RecvSize"]);
        psyscfg->OutMappings[0] = int(syscfg1["OutMapping"]["Output_0"]);
        psyscfg->OutMappings[1] = int(syscfg1["OutMapping"]["Output_1"]);
        psyscfg->OutMappings[2] = int(syscfg1["OutMapping"]["Output_2"]);
        psyscfg->OutMappings[3] = int(syscfg1["OutMapping"]["Output_3"]);
        psyscfg->OutMappings[4] = int(syscfg1["OutMapping"]["Output_4"]);
        psyscfg->OutMappings[5] = int(syscfg1["OutMapping"]["Output_5"]);
        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();
@@ -889,12 +889,12 @@
    syscfg1["SYSTEM"]["Version"] = psyscfg->Version;
    syscfg1["OutMapping"]["Output_0"] = psyscfg->OutMappings[0];
    syscfg1["OutMapping"]["Output_1"] = psyscfg->OutMappings[1];
    syscfg1["OutMapping"]["Output_2"] = psyscfg->OutMappings[2];
    syscfg1["OutMapping"]["Output_3"] = psyscfg->OutMappings[3];
    syscfg1["OutMapping"]["Output_4"] = psyscfg->OutMappings[4];
    syscfg1["OutMapping"]["Output_5"] = psyscfg->OutMappings[5];
    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();
ConfigTool/ConfigToolView.h
@@ -70,7 +70,7 @@
    stFactoryData * pfactorydata;
    unsigned short m_cfgdatabuf[256];
    pKMSysCfg psyscfg;
    pstKMSysCfg psyscfg;
    bool m_bOpened = false;
    bool m_bConnected = false;
FirmwareTool/DeviceList.ini
New file
@@ -0,0 +1,55 @@
[FAMILY]
00=未知设备
01=4入4出 试验模块
02=8入8出 试验模块
03=16入16出,旧排线
04=8入8出,旧排线
05=16路 旧黑端子1
06=8路 旧黑端子1
07=16路 旧黑端子2
08=8路 旧黑端子2
09=16路 新绿端子
0A=8路 新绿端子
0B=8入8从 Mini
0C=
0D=V45_NET,网络模块
0E=KL10-Ext-FPx, 松下扩展
0F=KL12 16路无线
10=KL12 8路无线
11=
12=
13=KL10-CON 协议转换板
[01]
;4入4出试验模块
01=VER1
02=Ver2
[02]
01=
02=
[03]
[04]
[05]
[06]
[07]
[08]
[09]
[0A]
[0B]
[0C]
[0D]
[0E]
;KL10-EXT-FPX, 松下扩展
00=版本00,
01=版本01   ;
02=版本02   ;现在使用的模块
[0F]
[10]
[11]
[12]
[13]
00=版本00
01=版本01
02=版本02
FirmwareTool/FirmwareTool.cpp
New file
@@ -0,0 +1,191 @@

// FirmwareTool.cpp: 定义应用程序的类行为。
//
#include "pch.h"
#include "framework.h"
#include "FirmwareTool.h"
#include "FirmwareToolDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CFirmwareToolApp
BEGIN_MESSAGE_MAP(CFirmwareToolApp, CWinApp)
    ON_COMMAND(ID_HELP, &CWinApp::OnHelp)
END_MESSAGE_MAP()
MHash myCfg1;
Logger myLogger1;
MHash DeviceList;
// CFirmwareToolApp 构造
CFirmwareToolApp::CFirmwareToolApp()
{
    // 支持重新启动管理器
    m_dwRestartManagerSupportFlags = AFX_RESTART_MANAGER_SUPPORT_RESTART;
    // TODO: 在此处添加构造代码,
    // 将所有重要的初始化放置在 InitInstance 中
}
// 唯一的 CFirmwareToolApp 对象
CFirmwareToolApp theApp;
// CFirmwareToolApp 初始化
BOOL CFirmwareToolApp::InitInstance()
{
    // 如果一个运行在 Windows XP 上的应用程序清单指定要
    // 使用 ComCtl32.dll 版本 6 或更高版本来启用可视化方式,
    //则需要 InitCommonControlsEx()。  否则,将无法创建窗口。
    INITCOMMONCONTROLSEX InitCtrls;
    InitCtrls.dwSize = sizeof(InitCtrls);
    // 将它设置为包括所有要在应用程序中使用的
    // 公共控件类。
    InitCtrls.dwICC = ICC_WIN95_CLASSES;
    InitCommonControlsEx(&InitCtrls);
    CWinApp::InitInstance();
    AfxEnableControlContainer();
    // 创建 shell 管理器,以防对话框包含
    // 任何 shell 树视图控件或 shell 列表视图控件。
    CShellManager *pShellManager = new CShellManager;
    // 激活“Windows Native”视觉管理器,以便在 MFC 控件中启用主题
    CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows));
    // 标准初始化
    // 如果未使用这些功能并希望减小
    // 最终可执行文件的大小,则应移除下列
    // 不需要的特定初始化例程
    // 更改用于存储设置的注册表项
    // TODO: 应适当修改该字符串,
    // 例如修改为公司或组织名
    SetRegistryKey(_T("应用程序向导生成的本地应用程序"));
    DeviceList.LoadFromFile(_T("./DeviceList.Ini"));
    CFirmwareToolDlg dlg;
    m_pMainWnd = &dlg;
    INT_PTR nResponse = dlg.DoModal();
    if (nResponse == IDOK)
    {
        // TODO: 在此放置处理何时用
        //  “确定”来关闭对话框的代码
    }
    else if (nResponse == IDCANCEL)
    {
        // TODO: 在此放置处理何时用
        //  “取消”来关闭对话框的代码
    }
    else if (nResponse == -1)
    {
        TRACE(traceAppMsg, 0, "警告: 对话框创建失败,应用程序将意外终止。\n");
        TRACE(traceAppMsg, 0, "警告: 如果您在对话框上使用 MFC 控件,则无法 #define _AFX_NO_MFC_CONTROLS_IN_DIALOGS。\n");
    }
    // 删除上面创建的 shell 管理器。
    if (pShellManager != nullptr)
    {
        delete pShellManager;
    }
#if !defined(_AFXDLL) && !defined(_AFX_NO_MFC_CONTROLS_IN_DIALOGS)
    ControlBarCleanUp();
#endif
    // 由于对话框已关闭,所以将返回 FALSE 以便退出应用程序,
    //  而不是启动应用程序的消息泵。
    return FALSE;
}
int SysLog(CString s, int channel)
{
    myLogger1.LogTxt(s, channel);
    return 1;
}
int DbgLog(CString s, int channel)
{
    myLogger1.LogTxt(s, channel);
    return 1;
}
int PopupMessage(CString Msg, int channel)
{
    Msg.Trim(_T("\r\n"));
    SysLog(_T("报警信息: ") + Msg + _T("\r\n"), channel);
    return 0;
}
void DoEvents()
{
    MSG msg;
    while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
    {
        DispatchMessage(&msg);
        TranslateMessage(&msg);
    }
}
int LoadMyConfig()
{
    CString ConfigFilePathName;
    ConfigFilePathName = _T("./Settings.ini");
    int j = myCfg1.LoadFromFile(ConfigFilePathName);
    return j;
}
int SaveMyConfig()
{
    CString ConfigFilePathName;
    ConfigFilePathName = _T("./Settings.ini");
    int j = myCfg1.SaveToFile(ConfigFilePathName);
    return j;
}
CString DeviceTypeToStr(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("(%02X)"), DeviceVer);
        }
    }
    else { DeviceName.Format(_T("Device %02X(%02X)"), DeviceType, DeviceVer); }
    return DeviceName;
}
FirmwareTool/FirmwareTool.h
New file
@@ -0,0 +1,66 @@

// FirmwareTool.h: PROJECT_NAME 应用程序的主头文件
//
#pragma once
#ifndef __AFXWIN_H__
    #error "在包含此文件之前包含 'pch.h' 以生成 PCH"
#endif
#include "resource.h"        // 主符号
#include "../MyLib/LOGGER/Logger.hpp"
#include "../MyLib/MHashINI/MHash.hpp"
void Trans_Tunc(unsigned int, EXCEPTION_POINTERS*);
#define CHECKE(func) try {func;} catch(SE_Exception &e) {DisplayException(_T(__FILE__),__LINE__,_T(__FUNCTION__),_T(#func),e);} catch (CException * e) {DisplayException(_T(__FILE__),__LINE__,_T(__FUNCTION__),_T(#func),e);} catch (...){DisplayException(_T(__FILE__),__LINE__,_T(__FUNCTION__),_T(#func));}
class SE_Exception
{
private:
    SE_Exception() {}
    unsigned int nSE;
    PVOID Addr;
    CString InfoStr;
public:
    SE_Exception(SE_Exception& e) : nSE(e.nSE) {}
    SE_Exception(unsigned int n) :nSE(n) {}
    SE_Exception(unsigned int n, PVOID a) :nSE(n), Addr(a) {}
    SE_Exception(unsigned int n, PVOID a, CString& str1) :nSE(n), Addr(a), InfoStr(str1) {}
    ~SE_Exception() {}
    unsigned int getSeNumber() { return nSE; }
    PVOID getAddress() { return Addr; }
    CString& getInfoStr() { return InfoStr; }
};
int DisplayException(CString File, int Line, CString Func, CString Sentence, SE_Exception& e);
int DisplayException(CString File, int Line, CString Func, CString Sentence, CException* e);
int DisplayException(CString File, int Line, CString Func, CString Sentence);
// CFirmwareToolApp:
// 有关此类的实现,请参阅 FirmwareTool.cpp
//
class CFirmwareToolApp : public CWinApp
{
public:
    CFirmwareToolApp();
// 重写
public:
    virtual BOOL InitInstance();
// 实现
    DECLARE_MESSAGE_MAP()
};
extern CFirmwareToolApp theApp;
extern MHash myCfg1;
extern Logger myLogger1;
int SysLog(CString s, int channel = 0);
int DbgLog(CString s, int channel = 0);
int PopupMessage(CString Msg, int channel = 0);
void DoEvents();
CString DeviceTypeToStr(int DeviceTypeVer);
FirmwareTool/FirmwareTool.rc
Binary files differ
FirmwareTool/FirmwareTool.vcxproj
New file
@@ -0,0 +1,215 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup Label="ProjectConfigurations">
    <ProjectConfiguration Include="Debug|Win32">
      <Configuration>Debug</Configuration>
      <Platform>Win32</Platform>
    </ProjectConfiguration>
    <ProjectConfiguration Include="Release|Win32">
      <Configuration>Release</Configuration>
      <Platform>Win32</Platform>
    </ProjectConfiguration>
    <ProjectConfiguration Include="Debug|x64">
      <Configuration>Debug</Configuration>
      <Platform>x64</Platform>
    </ProjectConfiguration>
    <ProjectConfiguration Include="Release|x64">
      <Configuration>Release</Configuration>
      <Platform>x64</Platform>
    </ProjectConfiguration>
  </ItemGroup>
  <PropertyGroup Label="Globals">
    <VCProjectVersion>16.0</VCProjectVersion>
    <ProjectGuid>{BE51EFF7-87E7-4287-A627-60EE573068BB}</ProjectGuid>
    <Keyword>MFCProj</Keyword>
    <RootNamespace>FirmwareTool</RootNamespace>
    <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
  </PropertyGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
    <ConfigurationType>Application</ConfigurationType>
    <UseDebugLibraries>true</UseDebugLibraries>
    <PlatformToolset>v142</PlatformToolset>
    <CharacterSet>Unicode</CharacterSet>
    <UseOfMfc>Dynamic</UseOfMfc>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
    <ConfigurationType>Application</ConfigurationType>
    <UseDebugLibraries>false</UseDebugLibraries>
    <PlatformToolset>v142</PlatformToolset>
    <WholeProgramOptimization>true</WholeProgramOptimization>
    <CharacterSet>Unicode</CharacterSet>
    <UseOfMfc>Dynamic</UseOfMfc>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
    <ConfigurationType>Application</ConfigurationType>
    <UseDebugLibraries>true</UseDebugLibraries>
    <PlatformToolset>v142</PlatformToolset>
    <CharacterSet>Unicode</CharacterSet>
    <UseOfMfc>Dynamic</UseOfMfc>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
    <ConfigurationType>Application</ConfigurationType>
    <UseDebugLibraries>false</UseDebugLibraries>
    <PlatformToolset>v142</PlatformToolset>
    <WholeProgramOptimization>true</WholeProgramOptimization>
    <CharacterSet>Unicode</CharacterSet>
    <UseOfMfc>Dynamic</UseOfMfc>
  </PropertyGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
  <ImportGroup Label="ExtensionSettings">
  </ImportGroup>
  <ImportGroup Label="Shared">
  </ImportGroup>
  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  </ImportGroup>
  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  </ImportGroup>
  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  </ImportGroup>
  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  </ImportGroup>
  <PropertyGroup Label="UserMacros" />
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    <LinkIncremental>true</LinkIncremental>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    <LinkIncremental>true</LinkIncremental>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    <LinkIncremental>false</LinkIncremental>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
    <LinkIncremental>false</LinkIncremental>
  </PropertyGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    <ClCompile>
      <PrecompiledHeader>Use</PrecompiledHeader>
      <WarningLevel>Level3</WarningLevel>
      <SDLCheck>true</SDLCheck>
      <PreprocessorDefinitions>_WINDOWS;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
    </ClCompile>
    <Link>
      <SubSystem>Windows</SubSystem>
    </Link>
    <Midl>
      <MkTypLibCompatible>false</MkTypLibCompatible>
      <ValidateAllParameters>true</ValidateAllParameters>
      <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
    </Midl>
    <ResourceCompile>
      <Culture>0x0804</Culture>
      <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
    </ResourceCompile>
  </ItemDefinitionGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    <ClCompile>
      <PrecompiledHeader>Use</PrecompiledHeader>
      <WarningLevel>Level3</WarningLevel>
      <SDLCheck>true</SDLCheck>
      <PreprocessorDefinitions>WIN32;_WINDOWS;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
    </ClCompile>
    <Link>
      <SubSystem>Windows</SubSystem>
    </Link>
    <Midl>
      <MkTypLibCompatible>false</MkTypLibCompatible>
      <ValidateAllParameters>true</ValidateAllParameters>
      <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
    </Midl>
    <ResourceCompile>
      <Culture>0x0804</Culture>
      <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
    </ResourceCompile>
  </ItemDefinitionGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    <ClCompile>
      <PrecompiledHeader>Use</PrecompiledHeader>
      <WarningLevel>Level3</WarningLevel>
      <FunctionLevelLinking>true</FunctionLevelLinking>
      <IntrinsicFunctions>true</IntrinsicFunctions>
      <SDLCheck>true</SDLCheck>
      <PreprocessorDefinitions>WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
    </ClCompile>
    <Link>
      <SubSystem>Windows</SubSystem>
      <EnableCOMDATFolding>true</EnableCOMDATFolding>
      <OptimizeReferences>true</OptimizeReferences>
    </Link>
    <Midl>
      <MkTypLibCompatible>false</MkTypLibCompatible>
      <ValidateAllParameters>true</ValidateAllParameters>
      <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
    </Midl>
    <ResourceCompile>
      <Culture>0x0804</Culture>
      <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
    </ResourceCompile>
  </ItemDefinitionGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
    <ClCompile>
      <PrecompiledHeader>Use</PrecompiledHeader>
      <WarningLevel>Level3</WarningLevel>
      <FunctionLevelLinking>true</FunctionLevelLinking>
      <IntrinsicFunctions>true</IntrinsicFunctions>
      <SDLCheck>true</SDLCheck>
      <PreprocessorDefinitions>_WINDOWS;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
    </ClCompile>
    <Link>
      <SubSystem>Windows</SubSystem>
      <EnableCOMDATFolding>true</EnableCOMDATFolding>
      <OptimizeReferences>true</OptimizeReferences>
    </Link>
    <Midl>
      <MkTypLibCompatible>false</MkTypLibCompatible>
      <ValidateAllParameters>true</ValidateAllParameters>
      <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
    </Midl>
    <ResourceCompile>
      <Culture>0x0804</Culture>
      <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
    </ResourceCompile>
  </ItemDefinitionGroup>
  <ItemGroup>
    <ClInclude Include="FirmwareTool.h" />
    <ClInclude Include="FirmwareToolDlg.h" />
    <ClInclude Include="framework.h" />
    <ClInclude Include="pch.h" />
    <ClInclude Include="Resource.h" />
    <ClInclude Include="targetver.h" />
  </ItemGroup>
  <ItemGroup>
    <ClCompile Include="FirmwareTool.cpp" />
    <ClCompile Include="FirmwareToolDlg.cpp" />
    <ClCompile Include="pch.cpp">
      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
    </ClCompile>
  </ItemGroup>
  <ItemGroup>
    <ResourceCompile Include="FirmwareTool.rc" />
  </ItemGroup>
  <ItemGroup>
    <None Include="res\FirmwareTool.rc2" />
  </ItemGroup>
  <ItemGroup>
    <Image Include="res\FirmwareTool.ico" />
  </ItemGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
  <ImportGroup Label="ExtensionTargets">
  </ImportGroup>
</Project>
FirmwareTool/FirmwareTool.vcxproj.filters
New file
@@ -0,0 +1,63 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup>
    <Filter Include="源文件">
      <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
      <Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
    </Filter>
    <Filter Include="头文件">
      <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
      <Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
    </Filter>
    <Filter Include="资源文件">
      <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
      <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
    </Filter>
  </ItemGroup>
  <ItemGroup>
    <ClInclude Include="FirmwareTool.h">
      <Filter>头文件</Filter>
    </ClInclude>
    <ClInclude Include="FirmwareToolDlg.h">
      <Filter>头文件</Filter>
    </ClInclude>
    <ClInclude Include="framework.h">
      <Filter>头文件</Filter>
    </ClInclude>
    <ClInclude Include="targetver.h">
      <Filter>头文件</Filter>
    </ClInclude>
    <ClInclude Include="Resource.h">
      <Filter>头文件</Filter>
    </ClInclude>
    <ClInclude Include="pch.h">
      <Filter>头文件</Filter>
    </ClInclude>
  </ItemGroup>
  <ItemGroup>
    <ClCompile Include="FirmwareTool.cpp">
      <Filter>源文件</Filter>
    </ClCompile>
    <ClCompile Include="FirmwareToolDlg.cpp">
      <Filter>源文件</Filter>
    </ClCompile>
    <ClCompile Include="pch.cpp">
      <Filter>源文件</Filter>
    </ClCompile>
  </ItemGroup>
  <ItemGroup>
    <ResourceCompile Include="FirmwareTool.rc">
      <Filter>资源文件</Filter>
    </ResourceCompile>
  </ItemGroup>
  <ItemGroup>
    <None Include="res\FirmwareTool.rc2">
      <Filter>资源文件</Filter>
    </None>
  </ItemGroup>
  <ItemGroup>
    <Image Include="res\FirmwareTool.ico">
      <Filter>资源文件</Filter>
    </Image>
  </ItemGroup>
</Project>
FirmwareTool/FirmwareToolDlg.cpp
New file
@@ -0,0 +1,705 @@

// FirmwareToolDlg.cpp: 实现文件
//
#include "pch.h"
#include "framework.h"
#include "FirmwareTool.h"
#include "FirmwareToolDlg.h"
#include "afxdialogex.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
CString sBtldrFileName;
CString sAppFileName;
CString sAppFileTitle;
unsigned char btldrbuf[131072];
unsigned char Appfilebuf[131072];
unsigned char firmwarebuf[262144];
int nBtldrInfoOffset = 256;
int AppOffset = 4096;
int nAppInfoOffset = 256;
int btldrLength = 0;
int AppFileLength = 0;
int FirmwareSize = 0;
unsigned char AppVerMajor = 0;
unsigned char AppVerMinor = 0;
bool btldrfileLoaded = false;
bool appfileLoaded = false;
bool combinefileSaved = false;
// 用于应用程序“关于”菜单项的 CAboutDlg 对话框
class CAboutDlg : public CDialogEx
{
public:
    CAboutDlg();
// 对话框数据
#ifdef AFX_DESIGN_TIME
    enum { IDD = IDD_ABOUTBOX };
#endif
    protected:
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV 支持
// 实现
protected:
    DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialogEx(IDD_ABOUTBOX)
{
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
    CDialogEx::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx)
END_MESSAGE_MAP()
// CFirmwareToolDlg 对话框
CFirmwareToolDlg::CFirmwareToolDlg(CWnd* pParent /*=nullptr*/)
    : CDialogEx(IDD_FIRMWARETOOL_DIALOG, pParent)
{
    m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CFirmwareToolDlg::DoDataExchange(CDataExchange* pDX)
{
    CDialogEx::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CFirmwareToolDlg, CDialogEx)
    ON_WM_SYSCOMMAND()
    ON_WM_PAINT()
    ON_WM_QUERYDRAGICON()
    ON_BN_CLICKED(IDC_BUTTON_OPEN_BTLDR, &CFirmwareToolDlg::OnBnClickedButtonOpenBtldr)
    ON_BN_CLICKED(IDC_BUTTON_OPEN_APP, &CFirmwareToolDlg::OnBnClickedButtonOpenApp)
    ON_BN_CLICKED(IDC_BUTTON_MAKE, &CFirmwareToolDlg::OnBnClickedButtonMake)
    ON_WM_TIMER()
    ON_WM_CLOSE()
END_MESSAGE_MAP()
// CFirmwareToolDlg 消息处理程序
BOOL CFirmwareToolDlg::OnInitDialog()
{
    CDialogEx::OnInitDialog();
    // 将“关于...”菜单项添加到系统菜单中。
    // IDM_ABOUTBOX 必须在系统命令范围内。
    ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
    ASSERT(IDM_ABOUTBOX < 0xF000);
    CMenu* pSysMenu = GetSystemMenu(FALSE);
    if (pSysMenu != nullptr)
    {
        BOOL bNameValid;
        CString strAboutMenu;
        bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
        ASSERT(bNameValid);
        if (!strAboutMenu.IsEmpty())
        {
            pSysMenu->AppendMenu(MF_SEPARATOR);
            pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
        }
    }
    // 设置此对话框的图标。  当应用程序主窗口不是对话框时,框架将自动
    //  执行此操作
    SetIcon(m_hIcon, TRUE);            // 设置大图标
    SetIcon(m_hIcon, FALSE);        // 设置小图标
    // TODO: 在此添加额外的初始化代码
    myLogger1.AttachWnd(GetDlgItem(IDC_EDIT_LOG)->m_hWnd);
    myLogger1.bShowLog[0] = 1;
    myLogger1.bSaveLog[0] = 1;
    myLogger1.SetLogPathName(_T("D:/logs/FirmWareTool"), _T("RunLog"));
    myLogger1.bShowThreadId = 0;
    myLogger1.bShowChannel = 0;
    SysLog(_T("Program Start \r\n"));
    SetTimer(0, 100, NULL);//delayinit
    SetTimer(2, 100, NULL);//display
    LoadConfig();
    ShowParams();
    return TRUE;  // 除非将焦点设置到控件,否则返回 TRUE
}
void CFirmwareToolDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
    if ((nID & 0xFFF0) == IDM_ABOUTBOX)
    {
        CAboutDlg dlgAbout;
        dlgAbout.DoModal();
    }
    else
    {
        CDialogEx::OnSysCommand(nID, lParam);
    }
}
// 如果向对话框添加最小化按钮,则需要下面的代码
//  来绘制该图标。  对于使用文档/视图模型的 MFC 应用程序,
//  这将由框架自动完成。
void CFirmwareToolDlg::OnPaint()
{
    if (IsIconic())
    {
        CPaintDC dc(this); // 用于绘制的设备上下文
        SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
        // 使图标在工作区矩形中居中
        int cxIcon = GetSystemMetrics(SM_CXICON);
        int cyIcon = GetSystemMetrics(SM_CYICON);
        CRect rect;
        GetClientRect(&rect);
        int x = (rect.Width() - cxIcon + 1) / 2;
        int y = (rect.Height() - cyIcon + 1) / 2;
        // 绘制图标
        dc.DrawIcon(x, y, m_hIcon);
    }
    else
    {
        CDialogEx::OnPaint();
    }
}
//当用户拖动最小化窗口时系统调用此函数取得光标
//显示。
HCURSOR CFirmwareToolDlg::OnQueryDragIcon()
{
    return static_cast<HCURSOR>(m_hIcon);
}
BOOL CFirmwareToolDlg::PreTranslateMessage(MSG* pMsg)
{
    // TODO: 在此添加专用代码和/或调用基类
    CString s1;
    if (pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_ESCAPE)
    {
        return   TRUE;
    }
    if (pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_RETURN)
    {
        return   FALSE;
    }
    if (pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_BACK)
    {
        return   FALSE;
    }
    try
    {
        //        if (m_tooltip1.GetSafeHwnd() != NULL) m_tooltip1.RelayEvent(pMsg);
        return CDialogEx::PreTranslateMessage(pMsg);
    }
    catch (CMemoryException* e)
    {
        CString Serror;
        e->GetErrorMessage(Serror.GetBuffer(256), 256);
        Serror.ReleaseBuffer();
        s1.Format(_T("程序 发生 内存 错误 %s \r\n"), Serror);
        PopupMessage(s1);
    }
    catch (CFileException* e)
    {
        CString Serror;
        e->GetErrorMessage(Serror.GetBuffer(256), 256);
        Serror.ReleaseBuffer();
        s1.Format(_T("程序 发生 文件 错误 %s \r\n"), Serror);
        PopupMessage(s1);
    }
    /*
        catch (SE_Exception& e)
        {
            s1.Format(_T("程序 发生 SE 错误 Code %08X Addr %08X \r\n%s\r\n"), e.getSeNumber(), e.getAddress(), e.getInfoStr());
            PopupMessage(s1);
        }
    */
    catch (CException* e)
    {
        CString Serror;
        e->GetErrorMessage(Serror.GetBuffer(256), 256);
        Serror.ReleaseBuffer();
        s1.Format(_T("程序 发生 C++ 错误 %s \r\n"), Serror);
        PopupMessage(s1);
    }
    catch (...)
    {
        s1.Format(_T("程序 发生未知错误 \r\n"));
        PopupMessage(s1);
    }
    return TRUE;
    return CDialogEx::PreTranslateMessage(pMsg);
}
int CFirmwareToolDlg::DelayInit()
{
    // TODO: 在此处添加实现代码.
//    InitCamera();
//    InitPlcCon();
//    InitNetCon();
    SetTimer(1, 50, NULL);//plc
//    SetTimer(3, 100, NULL);
    return 0;
}
int CFirmwareToolDlg::ShowParams()
{
    // TODO: 在此处添加实现代码.
    CString s1;
    s1.Format(_T("%d"), AppOffset);
    SetDlgItemText(IDC_EDIT_OFFSET, s1);
    return 0;
}
int CFirmwareToolDlg::GetParams()
{
    // TODO: 在此处添加实现代码.
    CString s1;
    GetDlgItemText(IDC_EDIT_OFFSET, s1);
    AppOffset = _tstoi(s1);
//    s1.Format(_T("%d"), AppOffset);
    return 0;
}
int CFirmwareToolDlg::LoadConfig()
{
    // TODO: 在此处添加实现代码.
    return 0;
}
int CFirmwareToolDlg::SaveConfig()
{
    // TODO: 在此处添加实现代码.
    return 0;
}
void CFirmwareToolDlg::OnClose()
{
    // TODO: 在此添加消息处理程序代码和/或调用默认值
    CDialogEx::OnClose();
}
void CFirmwareToolDlg::OnTimer(UINT_PTR nIDEvent)
{
    // TODO: 在此添加消息处理程序代码和/或调用默认值
    if (nIDEvent == 0)
    {
        KillTimer(0);
        DelayInit();
    }
    else if (nIDEvent == 1)
    {
        //ProcessPLC();
    }
    else if (nIDEvent == 2)
    {
        //        ProcessInput();
        //DrawPic1();
        myLogger1.UpdateLogDisplay(0);
    }
    else if (nIDEvent == 3)
    {
    }
    else
    {
    }
    CDialogEx::OnTimer(nIDEvent);
}
const uint16_t crctalbeabs[] = {
    0x0000, 0xCC01, 0xD801, 0x1400, 0xF001, 0x3C00, 0x2800, 0xE401,
    0xA001, 0x6C00, 0x7800, 0xB401, 0x5000, 0x9C01, 0x8801, 0x4400
};
uint16_t crc16tablefast(uint8_t* ptr, uint16_t len)
{
    uint16_t crc = 0xffff;
    uint16_t i;
    uint8_t ch;
    for (i = 0; i < len; i++) {
        ch = *ptr++;
        crc = crctalbeabs[(ch ^ crc) & 15] ^ (crc >> 4);
        crc = crctalbeabs[((ch >> 4) ^ crc) & 15] ^ (crc >> 4);
    }
    return crc;
}
// 载入BootLoader文件
int CFirmwareToolDlg::LoadBtldrFile(CString sFilePathName)
{
    // TODO: 在此处添加实现代码.
    CString s1;
    CFile file1;
    CFileException e;
    bool r = file1.Open(sFilePathName, CFile::modeRead | CFile::typeBinary, &e);
    if (r) { s1.Format(_T("打开 File %s = 成功"), sFilePathName); }
    else { s1.Format(_T("打开 File %s = 失败"), sFilePathName); }
    DbgLog(s1);
    if (r)
    {
        int len1 = (int)file1.GetLength();
        if (len1 < 65536) {
            file1.Read(btldrbuf, len1);
        }
        else {
            file1.Read(btldrbuf, 65536);
        }
        file1.Close();
        unsigned short crc2 = crc16tablefast(btldrbuf, len1);
        unsigned char* buf2 = btldrbuf + nBtldrInfoOffset; ;
        //s1.Format(_T("GetInfo From File  = %d %d \r\n"), j, len1);
        unsigned int nBlkType = 0;
        unsigned int nBlkVer = 0;
        s1.Empty();
        s1.Format(_T("文件信息\r\n"));
        SetDlgItemText(IDC_STATIC_BTLDR_INFO, s1);
        pBtLdrInfoBlock pinfob = (pBtLdrInfoBlock)buf2;
        if (pinfob->Hdr.nBlkSign == 0xaa55 ) {
            s1.Empty();
            s1.Format(_T("文件信息  "));
            // s1.AppendFormat(_T("启动文件 %s \r\n"), sFilePathName);
            s1.AppendFormat(_T("文件大小: %d \r\n"), len1);
            s1.AppendFormat(_T("信息块位置: 0x%04X  信息块大小: %d  \r\n"), nBtldrInfoOffset, pinfob->Hdr.nBlkSize);
            s1.AppendFormat(_T("信息块类型: 0x%04X  "), pinfob->Hdr.nBlkTypeVer);
            nBlkType = (pinfob->Hdr.nBlkTypeVer) >> 8;
            nBlkVer = pinfob->Hdr.nBlkTypeVer & 0xff;
            if (nBlkType == 0x01) {    s1.AppendFormat(_T(" (BootLoader 类型1 版本 %d) "),nBlkVer);    }
            else if (nBlkType == 0x02) {    s1.AppendFormat(_T(" (BootLoader 类型2 版本 %d) "), nBlkVer);    }
            else if (nBlkType == 0x03) {    s1.AppendFormat(_T(" (App类型1 版本 %d) "), nBlkVer);    }
            else if (nBlkType == 0x04) {    s1.AppendFormat(_T(" (App类型2 版本 %d) "), nBlkVer);    }
            else {        s1.AppendFormat(_T(" (未知类型)  "));    }
            s1.AppendFormat(_T("\r\n"));
            s1.AppendFormat(_T("启动区版本: 0x%04X  启动器对应芯片: 0x%04X\r\n"), pinfob->nBtldrVer, pinfob->nBtldrDevice);
            s1.AppendFormat(_T("启动器大小: 0x%04X  实际代码大小: 0x%04X \r\n"), pinfob->nBtldrSize, pinfob->nBtldrDataSize);
            s1.AppendFormat(_T("应用区地址: 0x%08X (偏移 %d )\r\n"), pinfob->nBtldr_AppAddr, pinfob->nBtldr_AppAddr -0x08000000);
            s1.AppendFormat(_T("信息暂存区: 0x%08X \r\n应用暂存区: 0x%08X \r\n"), pinfob->nBtldr_NewAppInfoAddr, pinfob->nBtldr_NewAppAddr);
            SetDlgItemText(IDC_STATIC_BTLDR_INFO, s1);
            if (nBlkType == 0x01 || nBlkType == 0x02) {
                btldrLength = len1;
                btldrfileLoaded = true;
                pAppInfoBlock pAppinfo2 = (pAppInfoBlock)(btldrbuf + AppOffset + nAppInfoOffset);
                s1.Append(_T("\r\n"));
                s1.AppendFormat(_T("信息块2位置: 0x%04X  信息块2大小: %d  \r\n"), AppOffset + nAppInfoOffset, pAppinfo2->Hdr.nBlkSize);
                s1.AppendFormat(_T("信息块2类型: 0x%04X  "), pAppinfo2->Hdr.nBlkTypeVer);
                nBlkType = (pAppinfo2->Hdr.nBlkTypeVer) >> 8;
                nBlkVer = pAppinfo2->Hdr.nBlkTypeVer & 0xff;
                if (nBlkType == 0x01) { s1.AppendFormat(_T(" (BootLoader 类型1 版本 %d) "), nBlkVer); }
                else if (nBlkType == 0x02) { s1.AppendFormat(_T(" (BootLoader 类型2 版本 %d) "), nBlkVer); }
                else if (nBlkType == 0x03) { s1.AppendFormat(_T(" (App类型1 版本 %d) "), nBlkVer); }
                else if (nBlkType == 0x04) { s1.AppendFormat(_T(" (App类型2 版本 %d) "), nBlkVer); }
                else { s1.AppendFormat(_T(" (未知类型)  ")); }
                s1.AppendFormat(_T("\r\n"));
                s1.AppendFormat(_T("对应模块类型: %04X %s\r\n"), pAppinfo2->nAppDevice, DeviceTypeToStr(pAppinfo2->nAppDevice));
                s1.AppendFormat(_T("应用区版本:   %d.%02d\r\n"), pAppinfo2->nAppVerMajor,pAppinfo2->nAppVerMinor);
                s1.AppendFormat(_T("应用区大小: 0x%04X  实际代码大小: 0x%04X \r\n"), pAppinfo2->nAppSize, pAppinfo2->nAppDataSize);
                s1.AppendFormat(_T("应用区地址: 0x%08X (偏移 %d )\r\n"), pAppinfo2->nAppStartAddr, pAppinfo2->nAppStartAddr - 0x08000000);
                s1.AppendFormat(_T("信息暂存区: 0x%08X \r\n应用暂存区: 0x%08X \r\n"), pAppinfo2->nAppStartOffset, pAppinfo2->nApp);
                //s2 += s1;
                if ((pAppinfo2->Hdr.nBlkSign == 0xaa55)) {
                    SetDlgItemText(IDC_STATIC_BTLDR_INFO, s1);
                }
            } else {
                s1.Format(_T("文件信息块中不包含 BootLoader 内容, 是否继续 "));
                int r3 = AfxMessageBox(s1, MB_YESNO);
                if (r3 == IDYES) {
                    btldrLength = len1;
                    btldrfileLoaded = true;
                }
            }
//            s1.Format(_T("  BootLoader启动文件  版本 %04X 硬件类型 %04X 占用空间 %04X,  %d Bytes\r\n 是否继续"), pinfob->nBtldrVer, pinfob->nBtldrDevice, pinfob->nBtldrSize, len1);
        }
        else {
            s1.Format(_T("BootLoader启动文件中未找到信息块, 文件  %d Bytes\r\n 是否继续"), len1);
            int r3 = AfxMessageBox(s1, MB_YESNO);
            if (r3 == IDYES) {
                btldrLength = len1;
                btldrfileLoaded = true;
            }
        }
    }
    return 0;
}
// 载入APP应用程序文件
int CFirmwareToolDlg::LoadAppFile(CString sFilePathName)
{
    // TODO: 在此处添加实现代码.
    CString s1;
    CString s2;
    CFile file1;
    CFileException e;
    bool r = file1.Open(sFilePathName, CFile::modeRead | CFile::typeBinary, &e);
    if (r) { s1.Format(_T("打开 File %s = 成功"), sFilePathName); }
    else { s1.Format(_T("打开 File %s = 失败"), sFilePathName); }
    DbgLog(s1);
    if (r)
    {
        int len1 = (int)file1.GetLength();
        if (len1 < 262144) {
            file1.Read(Appfilebuf, len1);
        }
        else {
            file1.Read(Appfilebuf, len1);
        }
        file1.Close();
        unsigned short crc2 = crc16tablefast(Appfilebuf, len1);
        unsigned int nBlkType = 0;
        unsigned int nBlkVer = 0;
        // 查找 Appinfo 和 KMInfo Block
        pAppInfoBlock pAppinfo = (pAppInfoBlock)(Appfilebuf + nAppInfoOffset);
        s1.Empty();
        s1.Format(_T("文件信息  \r\n"));
        SetDlgItemText(IDC_STATIC_APP_INFO, s1);
        if (pAppinfo->Hdr.nBlkSign == 0xaa55) {
            s1.Empty();
            s1.Format(_T("文件信息  "));
            // s1.AppendFormat(_T("启动文件 %s \r\n"), sFilePathName);
            s1.AppendFormat(_T("文件大小: %d \r\n"), len1);
            s1.AppendFormat(_T("信息块1位置: 0x%04X  信息块大小: %d  \r\n"), nAppInfoOffset, pAppinfo->Hdr.nBlkSize);
            s1.AppendFormat(_T("信息块类型: 0x%04X  "), pAppinfo->Hdr.nBlkTypeVer);
            nBlkType = (pAppinfo->Hdr.nBlkTypeVer) >> 8;
            nBlkVer = pAppinfo->Hdr.nBlkTypeVer & 0xff;
            if (nBlkType == 0x01) { s1.AppendFormat(_T(" (BootLoader 类型1 版本 %d) "), nBlkVer); }
            else if (nBlkType == 0x02) { s1.AppendFormat(_T(" (BootLoader 类型2 版本 %d) "), nBlkVer); }
            else if (nBlkType == 0x03) { s1.AppendFormat(_T(" (App类型1 版本 %d) "), nBlkVer); }
            else if (nBlkType == 0x04) { s1.AppendFormat(_T(" (App类型2 版本 %d) "), nBlkVer); }
            else { s1.AppendFormat(_T(" (未知类型)  ")); }
            s1.AppendFormat(_T("\r\n"));
            if (nBlkType == 0x01 || nBlkType == 0x02) {
                pBtLdrInfoBlock pinfob = (pBtLdrInfoBlock)pAppinfo;
                s1.AppendFormat(_T("启动区版本: 0x%04X  启动器对应芯片: 0x%04X\r\n"), pinfob->nBtldrVer, pinfob->nBtldrDevice);
                s1.AppendFormat(_T("启动器大小: 0x%04X  实际代码大小: 0x%04X \r\n"), pinfob->nBtldrSize, pinfob->nBtldrDataSize);
                s1.AppendFormat(_T("应用区地址: 0x%08X (偏移 %d )\r\n"), pinfob->nBtldr_AppAddr, pinfob->nBtldr_AppAddr - 0x08000000);
                s1.AppendFormat(_T("信息暂存区: 0x%08X \r\n应用暂存区: 0x%08X \r\n"), pinfob->nBtldr_NewAppInfoAddr, pinfob->nBtldr_NewAppAddr);
            }
            else if (nBlkType == 0x03 || nBlkType == 0x04) {
                s1.AppendFormat(_T("对应模块类型: %04X %s\r\n"),  pAppinfo->nAppDevice, DeviceTypeToStr(pAppinfo->nAppDevice));
                s1.AppendFormat(_T("应用区版本:   %d.%02d \r\n"), pAppinfo->nAppVerMajor, pAppinfo->nAppVerMinor);
                s1.AppendFormat(_T("应用区大小: 0x%04X  实际代码大小: 0x%04X \r\n"), pAppinfo->nAppSize, pAppinfo->nAppDataSize);
                s1.AppendFormat(_T("应用区地址: 0x%08X (偏移 %d )\r\n"), pAppinfo->nAppStartAddr, pAppinfo->nAppStartAddr - 0x08000000);
                s1.AppendFormat(_T("信息暂存区: 0x%08X \r\n应用暂存区: 0x%08X \r\n"), pAppinfo->nAppStartOffset, pAppinfo->nApp);
            }
            s2 = s1;
            SetDlgItemText(IDC_STATIC_APP_INFO, s1);
            if (nBlkType == 0x03 || nBlkType == 0x04) {
                appfileLoaded = true;
                AppFileLength = len1;
                AppVerMajor = pAppinfo->nAppVerMajor;
                AppVerMinor = pAppinfo->nAppVerMinor;
            }
            else {
                if ((nBlkType == 0x01 || nBlkType == 0x02) && len1 >= AppOffset + nAppInfoOffset  + sizeof(stAppInfoBlock) )
                {
                    pAppInfoBlock pAppinfo2 = (pAppInfoBlock)(Appfilebuf + AppOffset + nAppInfoOffset);
                    s1.Append(_T("\r\n"));
                    s1.AppendFormat(_T("信息块2位置: 0x%04X  信息块2大小: %d  \r\n"), AppOffset + nAppInfoOffset, pAppinfo2->Hdr.nBlkSize);
                    s1.AppendFormat(_T("信息块2类型: 0x%04X  "), pAppinfo2->Hdr.nBlkTypeVer);
                    nBlkType = (pAppinfo2->Hdr.nBlkTypeVer) >> 8;
                    nBlkVer = pAppinfo2->Hdr.nBlkTypeVer & 0xff;
                    if (nBlkType == 0x01) { s1.AppendFormat(_T(" (BootLoader 类型1 版本 %d) "), nBlkVer); }
                    else if (nBlkType == 0x02) { s1.AppendFormat(_T(" (BootLoader 类型2 版本 %d) "), nBlkVer); }
                    else if (nBlkType == 0x03) { s1.AppendFormat(_T(" (App类型1 版本 %d) "), nBlkVer); }
                    else if (nBlkType == 0x04) { s1.AppendFormat(_T(" (App类型2 版本 %d) "), nBlkVer); }
                    else { s1.AppendFormat(_T(" (未知类型)  ")); }
                    s1.AppendFormat(_T("\r\n"));
                    s1.AppendFormat(_T("对应模块类型: %04X %s\r\n"), pAppinfo2->nAppDevice, DeviceTypeToStr(pAppinfo2->nAppDevice));
                    s1.AppendFormat(_T("应用区版本:   %d.%02d\r\n"), pAppinfo2->nAppVerMajor,pAppinfo2->nAppVerMinor);
                    s1.AppendFormat(_T("应用区大小: 0x%04X  实际代码大小: 0x%04X \r\n"), pAppinfo2->nAppSize, pAppinfo2->nAppDataSize);
                    s1.AppendFormat(_T("应用区地址: 0x%08X (偏移 %d )\r\n"), pAppinfo2->nAppStartAddr, pAppinfo2->nAppStartAddr - 0x08000000);
                    s1.AppendFormat(_T("信息暂存区: 0x%08X \r\n应用暂存区: 0x%08X \r\n"), pAppinfo2->nAppStartOffset, pAppinfo2->nApp);
                    //s2 += s1;
                    if ((pAppinfo2->Hdr.nBlkSign == 0xaa55) && pAppinfo2->Hdr.nBlkTypeVer == 0x0301) {
                        SetDlgItemText(IDC_STATIC_APP_INFO, s1);
                        s1.Format(_T("文件已经是bootloader和App合成的文件 , 是否使用文件中App?"));
                        int r3 = AfxMessageBox(s1, MB_YESNO);
                        if (r3 == IDYES) {
                            memmove(Appfilebuf, Appfilebuf + AppOffset, len1 - AppOffset);
                            appfileLoaded = true;
                            AppFileLength = len1-AppOffset;
                            AppVerMajor = pAppinfo2->nAppVerMajor;
                            AppVerMinor = pAppinfo2->nAppVerMinor;
                        }
                    }
                    else {
                        s1.Format(_T("文件 不是App文件 , 是否继续 "));
                        int r3 = AfxMessageBox(s1, MB_YESNO);
                        if (r3 == IDYES) {
                            appfileLoaded = true;
                            AppFileLength = len1;
                            AppVerMajor = 0;
                            AppVerMinor = 0;
                        }
                    }
                }
                else {
                    s1.Format(_T("文件 不是App文件 , 是否继续 "));
                    int r3 = AfxMessageBox(s1, MB_YESNO);
                    if (r3 == IDYES) {
                        appfileLoaded = true;
                        AppFileLength = len1;
                        AppVerMajor = 0;
                        AppVerMinor = 0;
                    }
                }
            }
            //            s1.Format(_T("  BootLoader启动文件  版本 %04X 硬件类型 %04X 占用空间 %04X,  %d Bytes\r\n 是否继续"), pinfob->nBtldrVer, pinfob->nBtldrDevice, pinfob->nBtldrSize, len1);
        }
        else {
            s1.Format(_T("文件中未找到信息块, 文件大小  %d Bytes\r\n 是否继续"), len1);
            int r3 = AfxMessageBox(s1, MB_YESNO);
            if (r3 == IDYES) {
                appfileLoaded = true;
                AppFileLength = len1;
                AppVerMajor = 0;
                AppVerMinor = 0;
            }
        }
    }
    return 0;
}
int CFirmwareToolDlg::MakeFirmware()
{
    // TODO: 在此处添加实现代码.
    CString s1;
    s1.Format(_T("Btldr File Size %d \r\n"), btldrLength);
    s1.AppendFormat(_T("App File Size %d \r\n"), AppFileLength);
    DbgLog(s1);
    if (btldrfileLoaded && appfileLoaded) {
        memcpy(firmwarebuf, btldrbuf, AppOffset);
        memcpy(firmwarebuf + AppOffset, Appfilebuf, AppFileLength);
        FirmwareSize = AppOffset + AppFileLength;
        s1.Format(_T("Firmware File Size %d \r\n"), FirmwareSize);
        DbgLog(s1);
    }
    return 0;
}
void CFirmwareToolDlg::OnBnClickedButtonOpenBtldr()
{
    // TODO: 在此添加控件通知处理程序代码
    CString s1;
    CFileDialog dialog1(true);
    INT_PTR r = dialog1.DoModal();
    if (r == IDOK)
    {
        CString sFilePathName = dialog1.GetPathName();
        SetDlgItemText(IDC_EDIT_BTLDR_NAME, sFilePathName);
        //OpenFile
        LoadBtldrFile(sFilePathName);
    }
}
void CFirmwareToolDlg::OnBnClickedButtonOpenApp()
{
    // TODO: 在此添加控件通知处理程序代码
    CString s1;
    CFileDialog dialog1(true);
    INT_PTR r = dialog1.DoModal();
    if (r == IDOK)
    {
        CString sFilePathName = dialog1.GetPathName();
        sAppFileName = dialog1.GetFileName();
        sAppFileTitle = dialog1.GetFileTitle();
        SetDlgItemText(IDC_EDIT_APP_NAME, sFilePathName);
        //OpenFile
        LoadAppFile(sFilePathName);
    }
}
void CFirmwareToolDlg::OnBnClickedButtonMake()
{
    // TODO: 在此添加控件通知处理程序代码
    CString s1;
    int r = MakeFirmware();
    CString sFileName;
    if (AppVerMajor > 0) {
        s1.Format(_T("%d.%02d"), AppVerMajor, AppVerMinor);
        sFileName = sAppFileTitle + _T("_") + s1;
    }
    else {
        sFileName = sAppFileTitle + _T("_all");
    }
    CFileDialog dialog1(false,_T("bin"),sFileName);
    INT_PTR r2 = dialog1.DoModal();
    if (r2 == IDOK)
    {
        CString sFilePathName = dialog1.GetPathName();
        SetDlgItemText(IDC_EDIT_FIRMWARE_NAME, sFilePathName);
        //OpenFile
        SaveFirmwareAsFile(sFilePathName);
    }
}
int CFirmwareToolDlg::SaveFirmwareAsFile(CString sFilePathName)
{
    // TODO: 在此处添加实现代码.
    CString s1;
    CFile file1;
    CFileException e;
    bool r = file1.Open(sFilePathName, CFile::modeCreate | CFile::modeWrite | CFile::typeBinary, &e);
    if (r) { s1.Format(_T("创建 File %s = 成功"), sFilePathName); }
    else { s1.Format(_T("创建 File %s = 失败"), sFilePathName); }
    DbgLog(s1);
    if (r)
    {
        int len1 = FirmwareSize;
        file1.Write(firmwarebuf, len1);
        file1.Close();
        s1.Format(_T("保存 File %s = 完成"), sFilePathName);
        DbgLog(s1);
    }
    return 0;
}
FirmwareTool/FirmwareToolDlg.h
New file
@@ -0,0 +1,125 @@

// FirmwareToolDlg.h: 头文件
//
#pragma once
typedef struct tagInfoBlock // 20 bytes
{
    //    USHORT nBlockLenth;
    USHORT nDeviceTypeVer;            //device type        x.y
//    UCHAR nDevierVer;
    USHORT nProgVer;                    //prog version    x.y
    USHORT nKLinkVer;                //x.y
    USHORT nKBusVer;                //x.y
//    USHORT nKNetVer;                //x.y
//    USHORT nKWLVer;                    //x.y
    UCHAR nCapacity1;                //    ? K
    UCHAR nCapacity2;                //    ? k
    UCHAR nDInput;
    UCHAR nDOutput;
    UCHAR nAInput;
    UCHAR nAOutput;
    UCHAR nHInput;
    UCHAR nHOutput;
    UCHAR nExt1;
    UCHAR nExt2;
    UCHAR nLogSize;
    UCHAR nPorts;
    UCHAR nManSize;
    UCHAR nAbility;
    UCHAR nSwitchBits;
}stKMInfoBlock, * pKMInfoBlock;
typedef struct tagInfoBlockHdr {
    unsigned short nBlkSign;                    // 开始标志
    unsigned short nBlkTypeVer;                // 类型和版本
    unsigned short nBlkSize;                    // Block 大小, 包括开始和结束标志
    unsigned short Pad1;
}stInfoBlockHdr;
typedef struct tagInfoBlockTail {
    unsigned short CRC16;
    unsigned short EndSign;
}stInfoBlockTail;
typedef struct tagBtLdrInfoBlock {
    stInfoBlockHdr Hdr;
    unsigned short nBtldrVer;
    unsigned short nBtldrDevice;
    unsigned short nBtldrSize;        // 设计大小
    unsigned short nBtldrDataSize;        //代码大小
    unsigned int nBtldr_AppAddr;
    unsigned int nBtldr_NewAppInfoAddr;
    unsigned int nBtldr_NewAppAddr;
    stInfoBlockTail tail;
}stBtLdrInfoBlock, *pBtLdrInfoBlock;
typedef struct tagAppInfoBlock {
    stInfoBlockHdr Hdr;
    union {
        unsigned short nAppVer;
        struct {
            unsigned char nAppVerMinor;
            unsigned char nAppVerMajor;
        };
    };
    unsigned short nAppDevice;
    unsigned short nAppSize;        // 设计大小
    unsigned short nAppDataSize;        //代码大小
    unsigned int nAppStartAddr;
    unsigned int nAppStartOffset;
    unsigned int nApp;
    stInfoBlockTail tail;
}stAppInfoBlock, * pAppInfoBlock;
// CFirmwareToolDlg 对话框
class CFirmwareToolDlg : public CDialogEx
{
// 构造
public:
    CFirmwareToolDlg(CWnd* pParent = nullptr);    // 标准构造函数
// 对话框数据
#ifdef AFX_DESIGN_TIME
    enum { IDD = IDD_FIRMWARETOOL_DIALOG };
#endif
    protected:
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV 支持
// 实现
protected:
    HICON m_hIcon;
    // 生成的消息映射函数
    virtual BOOL OnInitDialog();
    afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
    afx_msg void OnPaint();
    afx_msg HCURSOR OnQueryDragIcon();
    DECLARE_MESSAGE_MAP()
public:
    afx_msg void OnBnClickedButtonOpenBtldr();
    afx_msg void OnBnClickedButtonOpenApp();
    afx_msg void OnBnClickedButtonMake();
    virtual BOOL PreTranslateMessage(MSG* pMsg);
    afx_msg void OnTimer(UINT_PTR nIDEvent);
    int DelayInit();
    int ShowParams();
    int GetParams();
    int LoadConfig();
    int SaveConfig();
    afx_msg void OnClose();
    // 载入BootLoader文件
    int LoadBtldrFile(CString sFilePathName);
    // 载入APP应用程序文件
    int LoadAppFile(CString sFilePathName);
    int MakeFirmware();
    int SaveFirmwareAsFile(CString sFilePathName);
};
FirmwareTool/RCa14640
Binary files differ
FirmwareTool/framework.h
New file
@@ -0,0 +1,49 @@
#pragma once
#ifndef VC_EXTRALEAN
#define VC_EXTRALEAN            // 从 Windows 头中排除极少使用的资料
#endif
#include "targetver.h"
#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS      // 某些 CString 构造函数将是显式的
// 关闭 MFC 的一些常见且经常可放心忽略的隐藏警告消息
#define _AFX_ALL_WARNINGS
#include <afxwin.h>         // MFC 核心组件和标准组件
#include <afxext.h>         // MFC 扩展
#include <afxdisp.h>        // MFC 自动化类
#ifndef _AFX_NO_OLE_SUPPORT
#include <afxdtctl.h>           // MFC 对 Internet Explorer 4 公共控件的支持
#endif
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h>             // MFC 对 Windows 公共控件的支持
#endif // _AFX_NO_AFXCMN_SUPPORT
#include <afxcontrolbars.h>     // MFC 支持功能区和控制条
#ifdef _UNICODE
#if defined _M_IX86
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")
#elif defined _M_X64
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"")
#else
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
#endif
#endif
FirmwareTool/pch.cpp
New file
@@ -0,0 +1,5 @@
// pch.cpp: 与预编译标头对应的源文件
#include "pch.h"
// 当使用预编译的头时,需要使用此源文件,编译才能成功。
FirmwareTool/pch.h
New file
@@ -0,0 +1,13 @@
// pch.h: 这是预编译标头文件。
// 下方列出的文件仅编译一次,提高了将来生成的生成性能。
// 这还将影响 IntelliSense 性能,包括代码完成和许多代码浏览功能。
// 但是,如果此处列出的文件中的任何一个在生成之间有更新,它们全部都将被重新编译。
// 请勿在此处添加要频繁更新的文件,这将使得性能优势无效。
#ifndef PCH_H
#define PCH_H
// 添加要在此处预编译的标头
#include "framework.h"
#endif //PCH_H
FirmwareTool/res/FirmwareTool.ico
FirmwareTool/res/FirmwareTool.rc2
Binary files differ
FirmwareTool/resource.h
New file
@@ -0,0 +1,31 @@
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ 生成的包含文件。
// 供 FirmwareTool.rc 使用
//
#define IDM_ABOUTBOX                    0x0010
#define IDD_ABOUTBOX                    100
#define IDS_ABOUTBOX                    101
#define IDD_FIRMWARETOOL_DIALOG         102
#define IDR_MAINFRAME                   128
#define IDC_EDIT_BTLDR_NAME             1000
#define IDC_BUTTON_OPEN_BTLDR           1001
#define IDC_BUTTON_OPEN_APP             1003
#define IDC_EDIT_APP_NAME               1004
#define IDC_BUTTON_MAKE                 1005
#define IDC_EDIT_FIRMWARE_NAME          1006
#define IDC_EDIT_LOG                    1007
#define IDC_STATIC_BTLDR_INFO           1008
#define IDC_STATIC_APP_INFO             1009
#define IDC_EDIT5                       1010
#define IDC_EDIT_OFFSET                 1010
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE        130
#define _APS_NEXT_COMMAND_VALUE         32771
#define _APS_NEXT_CONTROL_VALUE         1011
#define _APS_NEXT_SYMED_VALUE           101
#endif
#endif
FirmwareTool/targetver.h
New file
@@ -0,0 +1,8 @@
#pragma once
// 包括 SDKDDKVer.h 将定义可用的最高版本的 Windows 平台。
//如果要为以前的 Windows 平台生成应用程序,请包括 WinSDKVer.h,并
// 将 _WIN32_WINNT 宏设置为要支持的平台,然后再包括 SDKDDKVer.h。
#include <SDKDDKVer.h>
KLink1/CDialogCommSet1.cpp
@@ -155,9 +155,13 @@
int CDialogCommSet1::ShowParams()
{
    // TODO: 在此处添加实现代码.
    CString s1;
    ((CComboBox *)GetDlgItem(IDC_COMBO_NETWORK_TYPE))->SetCurSel(0);
    ((CComboBox *)GetDlgItem(IDC_COMBO_PORT))->SetCurSel(0);
    ((CComboBox *)GetDlgItem(IDC_COMBO_PORT))->SetCurSel(m_nComNum-1);
    ((CComboBox *)GetDlgItem(IDC_COMBO_BAUD))->SetCurSel(7);
    s1.Format(_T("%d"), m_nBaudRate);
    ((CComboBox*)GetDlgItem(IDC_COMBO_BAUD))->SelectString(0, s1);
    ((CButton *)GetDlgItem(IDC_RADIO_DATA_LENGTH_8B))->SetCheck(1);
@@ -172,7 +176,6 @@
    UpdateComPortList();
    CString s1;
    if (m_bOpened) s1 = _T("已连接"); else s1 = _T("未连接");
    ((CStatic*)GetDlgItem(IDC_STATIC_STATE))->SetWindowText(s1);
    return 0;
@@ -187,6 +190,7 @@
    CString baudstr;
    GetDlgItemText(IDC_COMBO_BAUD, baudstr);
    m_nBaudRate = _tstoi(baudstr);
    m_Settings = "8,N,1";
    ((CButton *)GetDlgItem(IDC_RADIO_DATA_LENGTH_8B))->GetCheck();
KLink1/HvSerialPort.cpp
@@ -136,9 +136,11 @@
    m_bOpened = true;
    //Start Read Thread
    if (m_bUseWorkThread) {
        MyThreadProc1ToRun = 1;
        AfxBeginThread(MyJumper1, (LPVOID)this);
    }
//    MyThreadProc1ToRun = 1;
//    AfxBeginThread(MyJumper1, (LPVOID)this);
    return R_OK;
}
@@ -272,7 +274,7 @@
//            }
//            if (dwEvtMask & EV_RXCHAR)
            if (1) { Sleep(1); } else
            //if (1) { Sleep(1); } else
            {
                ClearCommError(hCom1, &m_dwError, &cs);
                int bytes = cs.cbInQue;
@@ -280,7 +282,7 @@
                if (bytes > 0)
                {
                    int j = ReadFile(hCom1, RecvBuf2, bytes, &dwReaded, NULL);
                    if (j > 0)
                    if (j > 0 && dwReaded>0)
                    {
                        //m_CS1.Lock();
                        EnterCriticalSection(&g_cs);
@@ -361,7 +363,13 @@
}
int HvSerialPort1::Recv(void * pBuf, int len1)
{
    return RecvFromCom(pBuf, len1);
    if (m_bUseWorkThread) {
        return RecvFromBuf(pBuf, len1);
    }
    else {
        return RecvFromCom(pBuf, len1);
    }
}
int HvSerialPort1::RecvFromBuf(void * pBuf, int len1)
KLink1/HvSerialPort.h
@@ -33,6 +33,8 @@
    int m_nBaudRate;
    CString m_Settings;
    CRITICAL_SECTION g_cs;
    bool m_bAutoReConnect = 1;
    bool m_bUseWorkThread = 0;
//    CCriticalSection m_CS1;
//    CCriticalSection m_CS2;
@@ -41,13 +43,13 @@
    volatile bool MyThreadProc1Running;
    volatile int RecvBufDataLen = 0;
    unsigned char * RecvBuf[4096];
    unsigned char RecvBuf[4096];
    volatile int RecvBufPos = 0;
    unsigned char * RecvBuf2[4096];
    unsigned char RecvBuf2[4096];
    DWORD m_dwError;
    CString m_strResult;
    int m_nCountToTry = 5;
    int m_nCountToTry = 3;
    int m_nCountToWait = 1;
    volatile    DWORD TotalSendBytes, TotalRecvBytes;
KLink1/KLink.cpp
@@ -136,7 +136,7 @@
        //    dlg.DoModal();
    */
    CDialogCommSet1 dialog1;
    if (m_bCommParamSet)
//    if (m_bCommParamSet)
    {
        dialog1.m_nComNum = m_nPort;
        dialog1.m_nBaudRate = m_nBaudRate;
@@ -197,6 +197,7 @@
    if (r == MySerPort1.R_OK)
    {
        m_bOpened = true;
        // GotoCmdMode();
        //        MyKLink1.Open();
        //        m_static_connect.SetCtlColor(RGB(0, 255, 0));
        return KL_OK;
@@ -213,10 +214,12 @@
    }
    */
    m_bOpened = true;
//
    return KL_OK;
};
int KLink1::Close(int CloseParam)
{
    ExitCmdMode();
    if (m_bCloseCallBackSet)
    {
        m_CallBackFuncs.CloseFunc();
@@ -224,6 +227,33 @@
    m_bOpened = false;
    return KL_OK;
};
int KLink1::GotoCmdMode(int Param)
{
    int res = KL_OK;
    int len1 = 3;
    m_Packetbuf[0] = '+';
    m_Packetbuf[1] = '+';
    m_Packetbuf[2] = '+';
    SendPacket(m_Packetbuf, len1);
    return res;
}
int KLink1::ExitCmdMode(int Param)
{
    int res = KL_OK;
    int len1 = 3;
    m_Packetbuf[0] = '-';
    m_Packetbuf[1] = '-';
    m_Packetbuf[2] = '-';
    SendPacket(m_Packetbuf, len1);
    return res;
}
int KLink1::Connect(int ConnectParam)
{
    int OpenParam = ConnectParam;
@@ -231,9 +261,11 @@
    unsigned short len1;
    unsigned short buf1[256];
    //m_resultStr = MySerPort1.m_strResult;
    GotoCmdMode();
    return res;
    if (res == KL_OK)
    {
        GotoCmdMode();
        int res2 = GetInfo(m_Dst, &len1, buf1);
        if (m_bOnConnectCallBackSet) { m_CallBackFuncs.OnConnect(); }
@@ -243,6 +275,7 @@
}
int KLink1::DisConnect(int DisConnectParam)
{
    ExitCmdMode();
    if (m_bOnDisConnectCallBackSet) { m_CallBackFuncs.OnDisConnect(DisConnectParam); }
    return Close();
}
@@ -279,6 +312,7 @@
{
    if (m_bOpened && m_bSendCallBackSet)
    {
        m_nTotalSendCount++;
        if (m_bClearBufCallBackSet) m_CallBackFuncs.ClearBufFunc();
        return m_CallBackFuncs.SendPkgFunc(pBuf, Len);
    }
@@ -303,6 +337,7 @@
        }
        if (len2 >= LenToRead) {
            m_nContinueErrCount = 0;
            m_nTotalRecvCount++;
            return len2;
        }
        else if (len2 <= 0) {
@@ -315,6 +350,7 @@
            return KL_ERR;
        }
        else {
            m_nTotalRecvCount++;
            return len2;
        }
    }
@@ -349,7 +385,7 @@
    pPacket->Cmd = nCMD;
    pPacket->Type1 = Type;
    int Datalen = 0;
    int nWordAddr;
    int nByteAddr;
    int nWordCount;
    switch (nCMD)
@@ -507,6 +543,23 @@
        Datalen = 0;
        PkgLen1 = sizeof(stKLReqPacket) + 4 + Datalen;
        break;
    case KLCmdReadPLCAnno:
        Datalen = 0;
        PkgLen1 = sizeof(stKLReqPacket) + 4 + Datalen;
        break;
    case KLCmdStartPLCAnno:
        Datalen = 0;
        PkgLen1 = sizeof(stKLReqPacket) + 4 + Datalen;
        break;
    case KLCmdWritePLCAnno:
        Datalen = nCount;
        memcpy(pPacket->Params + 4, pData, Datalen);
        PkgLen1 = sizeof(stKLReqPacket) + 4 + Datalen;
        break;
    case KLCmdFinishPLCAnno:
        Datalen = 0;
        PkgLen1 = sizeof(stKLReqPacket) + 4 + Datalen;
        break;
    case KLCmdReadRunStat:
        Datalen = 0;
@@ -565,11 +618,7 @@
        break;
    default:
        pPacket->Params[0] = nAddr % 256;
        pPacket->Params[1] = nAddr / 256;
        pPacket->Params[2] = nCount % 256;
        pPacket->Params[3] = nCount / 256;
        Datalen = 0;
        Datalen = nCount;
        memcpy(pPacket->Params + 4, pData, Datalen);
        PkgLen1 = sizeof(stKLReqPacket) + 4 + Datalen;
        break;
@@ -590,6 +639,45 @@
    return PkgLen1;
}
int KLink1::MakeRemoteReqPacketEx(void* pBuf, UCHAR nDst, UCHAR Stat, UCHAR nPort, UCHAR nChildId, UCHAR nReqId, UCHAR Param1, USHORT nAddr , USHORT nCount , void* pData , int ExtFrameLen , void* pExtDataFrame)
{
    int PkgLen1 = 0;
    pKLReqPacket pPacket = (pKLReqPacket)pBuf;
    pPacket->StartSign = KLSignStart;
    pPacket->DstAddr = nDst;
    pPacket->Stat = Stat;
    pPacket->Cmd = KLCmdPortRemoteReq;
    pPacket->Type1 = nReqId;
    pKLStat pStat = (pKLStat) & (pPacket->Stat);
    int Datalen = nCount;
    int nWordAddr = nAddr;
    int nWordCount = nCount;
    pPacket->Params[0] = nPort;
    pPacket->Params[1] = nChildId;
    pPacket->Params[2] = Param1;
    pPacket->Params[3] = nAddr % 256;
    pPacket->Params[4] = nAddr / 256;
    pPacket->Params[5] = nCount % 256;
//    pPacket->Params[6] = nCount / 256;
    memcpy(&pPacket->Params[6], pData, Datalen);
    PkgLen1 = sizeof(stKLReqPacket) + 6 + Datalen;
    if (PkgLen1 >= sizeof(stKLReqPacket))
    {
        UCHAR BCC = KLBCC(pBuf, PkgLen1 - 1);
        pPacket->Params[PkgLen1 - sizeof(stKLReqPacket)] = BCC;
    }
/*
    if (pStat->HasExt && ExtFrameLen > 0 && pExtDataFrame != NULL)
    {
        memcpy(pPacket->Params + PkgLen1 - sizeof(stKLReqPacket) + 1, pExtDataFrame, ExtFrameLen);
        PkgLen1 += ExtFrameLen;
    };
*/
    return PkgLen1;
}
int KLink1::CheckPackage(void * pBuf, int nSize)
{
@@ -647,6 +735,7 @@
    m_nRSeq = ((pKLStat)&nStatus)->nSEQ;
    int Datalen = pPacket->nSize1;
    *nCount = Datalen;
    USHORT ErrCode;
    switch (*nCmd)
    {
    case KLCmdNone:
@@ -701,7 +790,10 @@
    case KLCmdSaveToFlash:
        break;
    case KLCmdGetMode:
        *nCount = Datalen;
        memcpy(pData, pPacket->Datas, Datalen);
        break;
    case KLCmdReadProgram:
        *nCount = Datalen;
        memcpy(pData, pPacket->Datas, Datalen);
@@ -713,6 +805,19 @@
        *nCount = Datalen;
        break;
    case KLCmdFinishProgram:
        *nCount = Datalen;
        break;
    case KLCmdReadPLCAnno:
        *nCount = Datalen;
        memcpy(pData, pPacket->Datas, Datalen);
        break;
    case KLCmdStartPLCAnno:
        *nCount = Datalen;
        break;
    case KLCmdWritePLCAnno:
        *nCount = Datalen;
        break;
    case KLCmdFinishPLCAnno:
        *nCount = Datalen;
        break;
@@ -735,10 +840,23 @@
        *nCount = Datalen;
        memcpy(pData, pPacket->Datas, Datalen);
        break;
    case KLCmdErrRply:
    case KLCmdGetPortInfo:
        *nCount = Datalen;
        memcpy(pData, pPacket->Datas, Datalen);
        break;
    case KLCmdGetPortChildInfo:
        *nCount = Datalen;
        memcpy(pData, pPacket->Datas, Datalen);
        break;
    case KLCmdGetPortChnInfo:
        *nCount = Datalen;
        memcpy(pData, pPacket->Datas, Datalen);
        break;
    case KLCmdErrRply:
        ErrCode = Datalen + 1000;
        *nCount = 0;
        return ErrCode;
        //memcpy(pData, pPacket->Datas, Datalen);
        break;
    default:
        *nCount = Datalen;
@@ -1093,12 +1211,12 @@
}
int KLink1::ReadSysCfgData(UCHAR nDst, USHORT nStartAddr, UCHAR nByteCount, USHORT * nReadBytes, USHORT * Values)
int KLink1::ReadSysCfgData(UCHAR nDst, UCHAR nType, USHORT nStartAddr, UCHAR nByteCount, USHORT * nReadBytes, USHORT * Values)
{
    m_Dst = nDst;
    m_resultStr.Empty();
    UCHAR nExpSeq = GetNextSeq();
    int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdReadSysCfg, 0, nStartAddr, nByteCount, Values);
    int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdReadSysCfg, nType, nStartAddr, nByteCount, Values);
    CString s1;
    for (int i = 0; i < len1; i++) {
        s1.AppendFormat(_T("%02X "), m_Packetbuf[i]);
@@ -1117,13 +1235,12 @@
    return res;
    return KL_OK;
}
int KLink1::WriteSysCfgData(UCHAR nDst, USHORT nStartAddr, UCHAR nByteCount, USHORT * Values)
int KLink1::WriteSysCfgData(UCHAR nDst, UCHAR nType, USHORT nStartAddr, UCHAR nByteCount, USHORT * Values)
{
    m_Dst = nDst;
    m_resultStr.Empty();
    UCHAR nExpSeq = GetNextSeq();
    int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdWriteSysCfg, 0, nStartAddr, nByteCount, Values);
    int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdWriteSysCfg, nType, nStartAddr, nByteCount, Values);
    SendPacket(m_Packetbuf, len1);
    int nReadBytes = 0;
    int numToRead = sizeof(stKLRplyPktHdr) + nReadBytes;
@@ -1253,7 +1370,7 @@
}
int KLink1::ReadProgram(UCHAR nDst, UCHAR nType, USHORT nWordAddr, UCHAR nWordCount, USHORT * Values)
int KLink1::ReadPLCProgram(UCHAR nDst, UCHAR nType, USHORT nWordAddr, UCHAR nWordCount, USHORT * Values)
{
    int res = KL_OK;
    m_Dst = nDst;
@@ -1268,18 +1385,20 @@
    unsigned char nCmd;
    unsigned short nnCount = 0;
    res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, m_DataBuf);
    unsigned char * values2 = (unsigned char *)Values;
    for (int i = 0; i < nnCount; i++)    values2[i] = m_DataBuf[i];
    if (res == KL_OK) {
        unsigned char* values2 = (unsigned char*)Values;
        for (int i = 0; i < nnCount; i++)    values2[i] = m_DataBuf[i];
    }
    return res;
}
int KLink1::StartProgram(UCHAR nDst, UCHAR nType)
int KLink1::StartDownloadPLCProgram(UCHAR nDst, UCHAR nType, USHORT nProgBytes, USHORT nCRC)
{
    int res = KL_OK;
    m_Dst = nDst;
    UCHAR nExpSeq = GetNextSeq();
    int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdStartProgram, nType);
    int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdStartProgram, nType, nProgBytes,nCRC);
    SendPacket(m_Packetbuf, len1);
    int len2 = RecvPacket(m_RecvBuf, 6);
    if (len2 <= 0) { len2 = RecvPacket(m_RecvBuf, 6); }
@@ -1291,12 +1410,88 @@
}
int KLink1::WriteProgram(UCHAR nDst, UCHAR nType, USHORT nWordAddr, UCHAR nWordCount, USHORT * Values)
int KLink1::DownloadPLCProgram(UCHAR nDst, UCHAR nType, USHORT nByteAddr, UCHAR nByteCount, USHORT * Values)
{
    int res = KL_OK;
    m_Dst = nDst;
    UCHAR nExpSeq = GetNextSeq();
    int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdWriteProgram, nType, nWordAddr, nWordCount, Values);
    int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdWriteProgram, nType, nByteAddr, nByteCount, Values);
    SendPacket(m_Packetbuf, len1);
    int len2 = RecvPacket(m_RecvBuf, 6, 10);
    if (len2 <= 0) { len2 = RecvPacket(m_RecvBuf, 6, 30); }
    if (len2 <= 0) return KL_ERR;
    unsigned char nCmd;
    unsigned short nnCount = 0;
    res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, m_DataBuf);
    //    Values[0] = m_DataBuf[0];
    return res;
}
int KLink1::FinishDownloadPLCProgram(UCHAR nDst, UCHAR nType, USHORT nProgSteps, USHORT nCRC)
{
    int res = KL_OK;
    m_Dst = nDst;
    UCHAR nExpSeq = GetNextSeq();
    int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdFinishProgram, nType, nProgSteps,nCRC);
    SendPacket(m_Packetbuf, len1);
    int len2 = RecvPacket(m_RecvBuf, 6,10);
    if (len2 <= 0) { len2 = RecvPacket(m_RecvBuf, 6, 30); }
    if (len2 <= 0) return KL_ERR;
    unsigned char nCmd;
    unsigned short nnCount = 0;
    res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, m_DataBuf);
    return res;
}
int KLink1::ReadPLCAnno(UCHAR nDst, UCHAR nType, USHORT nByteAddr, UCHAR nByteCount, UCHAR* Values)
{
    int res = KL_OK;
    m_Dst = nDst;
    UCHAR nExpSeq = GetNextSeq();
    int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdReadPLCAnno, nType, nByteAddr, nByteCount);
    SendPacket(m_Packetbuf, len1);
//    int nByteCount = nByteCount;
    int numToRead = sizeof(stKLRplyPktHdr) + nByteCount;
    int len2 = RecvPacket(m_RecvBuf, numToRead);
    if (len2 <= 0) { len2 = RecvPacket(m_RecvBuf, numToRead); }
    if (len2 <= 0) return KL_ERR;
    unsigned char nCmd;
    unsigned short nnCount = 0;
    res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, m_DataBuf);
    if (res == KL_OK) {
        unsigned char* values2 = (unsigned char*)Values;
        for (int i = 0; i < nnCount; i++)    values2[i] = m_DataBuf[i];
    }
    return res;
}
int KLink1::StartDownloadPLCAnno(UCHAR nDst, UCHAR nType, USHORT nBytes, USHORT nCRC)
{
    int res = KL_OK;
    m_Dst = nDst;
    UCHAR nExpSeq = GetNextSeq();
    int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdStartPLCAnno, nType, nBytes, nCRC);
    SendPacket(m_Packetbuf, len1);
    int len2 = RecvPacket(m_RecvBuf, 6);
    if (len2 <= 0) { len2 = RecvPacket(m_RecvBuf, 6); }
    if (len2 <= 0) return KL_ERR;
    unsigned char nCmd;
    unsigned short nnCount = 0;
    res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, m_DataBuf);
    return res;
}
int KLink1::DownloadPLCAnno(UCHAR nDst, UCHAR nType, USHORT nByteAddr, UCHAR nByteCount, UCHAR* Values)
{
    int res = KL_OK;
    m_Dst = nDst;
    UCHAR nExpSeq = GetNextSeq();
    int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdWritePLCAnno, nType, nByteAddr, nByteCount, Values);
    SendPacket(m_Packetbuf, len1);
    int len2 = RecvPacket(m_RecvBuf, 6);
@@ -1310,13 +1505,13 @@
}
int KLink1::FinishProgram(UCHAR nDst, UCHAR nType, USHORT nStepSize)
int KLink1::FinishDownloadPLCAnno(UCHAR nDst, UCHAR nType, USHORT nByteSize, USHORT nCRC)
{
    int res = KL_OK;
    m_Dst = nDst;
    UCHAR nExpSeq = GetNextSeq();
    int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdFinishProgram, nType, nStepSize);
    int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdFinishPLCAnno, nType, nByteSize, nCRC);
    SendPacket(m_Packetbuf, len1);
    int len2 = RecvPacket(m_RecvBuf, 6);
    if (len2 <= 0) { len2 = RecvPacket(m_RecvBuf, 6, 30); }
@@ -1326,7 +1521,6 @@
    res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, m_DataBuf);
    return res;
}
int KLink1::ReadRunStat(UCHAR nDst, UCHAR nType, USHORT nWordAddr, UCHAR nWordCount, USHORT * Values)
{
@@ -1367,3 +1561,234 @@
    return res;
}
int KLink1::ResetDevice(UCHAR nDst, UCHAR nType)
{
    m_Dst = nDst;
    m_resultStr.Empty();
    UCHAR nExpSeq = GetNextSeq();
    int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdResetMachine, nType, 0, 0, 0);
    SendPacket(m_Packetbuf, len1);
    int nByteCount = 0;
    int numToRead = sizeof(stKLRplyPktHdr) + nByteCount;
    int len2 = RecvPacket(m_RecvBuf, numToRead);
    //    if (len2 <= 0) { len2 = RecvPacket(m_RecvBuf, numToRead); }
    if (len2 <= 0) return KL_TIMEOUT;
    unsigned char nCmd;
    unsigned short nnCount = 0;
    int res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, m_DataBuf);
    return res;
}
int KLink1::WriteFirmware(UCHAR nDst, UCHAR nType, USHORT nByteAddr, UCHAR nByteCount, UCHAR* Values)
{
    m_Dst = nDst;
    m_resultStr.Empty();
    UCHAR nExpSeq = GetNextSeq();
    int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdWriteFirmware, nType, nByteAddr , nByteCount, Values);
    SendPacket(m_Packetbuf, len1);
    nByteCount = 0;
    int numToRead = sizeof(stKLRplyPktHdr) + nByteCount;
    int len2 = RecvPacket(m_RecvBuf, numToRead);
    //    if (len2 <= 0) { len2 = RecvPacket(m_RecvBuf, numToRead); }
    m_resultStr.Format(_T("S %d, R %d "), len1, len2);
    if (len2 <= 0) return KL_TIMEOUT;
    m_resultStr.Append(_T("\r\n"));
    for (int j = 0; j < len2; j++) {
        m_resultStr.AppendFormat(_T("%02X "), m_RecvBuf[j]);
    }
    unsigned char nCmd;
    unsigned short nnCount = 0;
    int res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, m_DataBuf);
    return res;
}
int KLink1::WriteFirmInfo(UCHAR nDst, UCHAR nType, USHORT nByteAddr, UCHAR nByteCount, UCHAR* Values)
{
    m_Dst = nDst;
    m_resultStr.Empty();
    UCHAR nExpSeq = GetNextSeq();
    int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdWriteFirmInfo, nType, nByteAddr , nByteCount, Values);
    SendPacket(m_Packetbuf, len1);
    nByteCount = 0;
    int numToRead = sizeof(stKLRplyPktHdr) + nByteCount;
    int len2 = RecvPacket(m_RecvBuf, numToRead);
    //    if (len2 <= 0) { len2 = RecvPacket(m_RecvBuf, numToRead); }
    if (len2 <= 0) return KL_TIMEOUT;
    unsigned char nCmd;
    unsigned short nnCount = 0;
    int res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, m_DataBuf);
    return res;
}
int KLink1::GetPortInfo(UCHAR nDst, UCHAR nType, UCHAR nByteCount, USHORT* nByteRead, USHORT* Values)
{
    m_Dst = nDst;
    m_resultStr.Empty();
    UCHAR nExpSeq = GetNextSeq();
    int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdGetPortInfo, nType, 0, 0);
    SendPacket(m_Packetbuf, len1);
    int numToRead = sizeof(stKLRplyPktHdr) + nByteCount;
    int len2 = 0;
    len2 = RecvPacket(m_RecvBuf, numToRead);
    if (len2 <= 0) { m_resultStr.Format(_T("Recv Failed len %d To=%d"), len2, numToRead); return KL_ERR; }
    if (len2 < numToRead)
    {
        CString s1;
        for (int i = 0; i < len2; i++)
        {
            s1.AppendFormat(_T("%02X "), m_RecvBuf[i]);
        }
        s1.Append(_T("\r\n"));
        m_resultStr.Format(_T("ToRead %d R= %d \r\n"), numToRead, len2);
        m_resultStr += s1;
    }
    unsigned char nCmd;
    unsigned short nnCount = 0;
    int res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, m_DataBuf);
    if (res == KL_OK)
    {
        memcpy(Values, m_DataBuf, nnCount);
    }
    else
    {
        m_resultStr.AppendFormat(_T("Res=%d ToRead %d Count %d "), res, numToRead, len2);
        CString s1;
        s1 = GetErrDescStr(res);
        m_resultStr += s1;
        return res;
    }
    *nByteRead = nnCount;
    return KL_OK;
}
int KLink1::GetPortChildInfo(UCHAR nDst, UCHAR nType, UCHAR nChildId, UCHAR nByteCount, USHORT* nByteRead, USHORT* Values)
{
    m_Dst = nDst;
    m_resultStr.Empty();
    UCHAR nExpSeq = GetNextSeq();
    int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdGetPortChildInfo, nType, nChildId, 0);
    SendPacket(m_Packetbuf, len1);
    int numToRead = sizeof(stKLRplyPktHdr) + nByteCount;
    int len2 = 0;
    len2 = RecvPacket(m_RecvBuf, numToRead);
    if (len2 <= 0) { m_resultStr.Format(_T("Recv Failed len %d To=%d"), len2, numToRead); return KL_ERR; }
    if (len2 < numToRead)
    {
        CString s1;
        for (int i = 0; i < len2; i++)
        {
            s1.AppendFormat(_T("%02X "), m_RecvBuf[i]);
        }
        s1.Append(_T("\r\n"));
        m_resultStr.Format(_T("ToRead %d R= %d \r\n"), numToRead, len2);
        m_resultStr += s1;
    }
    unsigned char nCmd;
    unsigned short nnCount = 0;
    int res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, m_DataBuf);
    if (res == KL_OK)
    {
        memcpy(Values, m_DataBuf, nnCount);
    }
    else
    {
        m_resultStr.AppendFormat(_T("Res=%d ToRead %d Count %d "), res, numToRead, len2);
        CString s1;
        s1 = GetErrDescStr(res);
        m_resultStr += s1;
        return res;
    }
    *nByteRead = nnCount;
    return KL_OK;
}
int KLink1::GetPortChnInfo(UCHAR nDst, UCHAR nType, UCHAR nChnId, UCHAR nByteCount, USHORT* nByteRead, USHORT* Values)
{
    m_Dst = nDst;
    m_resultStr.Empty();
    UCHAR nExpSeq = GetNextSeq();
    int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdGetPortChnInfo, nType, nChnId, 0);
    SendPacket(m_Packetbuf, len1);
    int numToRead = sizeof(stKLRplyPktHdr) + nByteCount;
    int len2 = 0;
    len2 = RecvPacket(m_RecvBuf, numToRead);
    if (len2 <= 0) { m_resultStr.Format(_T("Recv Failed len %d To=%d"), len2, numToRead); return KL_ERR; }
    if (len2 < numToRead)
    {
        CString s1;
        for (int i = 0; i < len2; i++)
        {
            s1.AppendFormat(_T("%02X "), m_RecvBuf[i]);
        }
        s1.Append(_T("\r\n"));
        m_resultStr.Format(_T("ToRead %d R= %d \r\n"), numToRead, len2);
        m_resultStr += s1;
    }
    unsigned char nCmd;
    unsigned short nnCount = 0;
    int res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, m_DataBuf);
    if (res == KL_OK)
    {
        memcpy(Values, m_DataBuf, nnCount);
    }
    else
    {
        m_resultStr.AppendFormat(_T("Res=%d ToRead %d Count %d "), res, numToRead, len2);
        CString s1;
        s1 = GetErrDescStr(res);
        m_resultStr += s1;
        return res;
    }
    *nByteRead = nnCount;
    return KL_OK;
}
int KLink1::RunRemoteReq(UCHAR nDst, UCHAR nPort, UCHAR nChnId, UCHAR nReqId, UCHAR nParam,USHORT nByteAddr, UCHAR nByteCount, void * pData)
{
    m_Dst = nDst;
    m_resultStr.Empty();
    UCHAR nExpSeq = GetNextSeq();
    int len1 = MakeRemoteReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, nPort, nChnId, nReqId,nParam,nByteAddr,nByteCount,pData);
    SendPacket(m_Packetbuf, len1);
    int numToRead = sizeof(stKLRplyPktHdr) + 0;
    int len2 = 0;
    len2 = RecvPacket(m_RecvBuf, numToRead);
    if (len2 <= 0) { m_resultStr.Format(_T("Recv Failed len %d To=%d"), len2, numToRead); return KL_ERR; }
    if (len2 < numToRead)
    {
        CString s1;
        for (int i = 0; i < len2; i++)
        {
            s1.AppendFormat(_T("%02X "), m_RecvBuf[i]);
        }
        s1.Append(_T("\r\n"));
        m_resultStr.Format(_T("ToRead %d R= %d \r\n"), numToRead, len2);
        m_resultStr += s1;
    }
    unsigned char nCmd;
    unsigned short nnCount = 0;
    int res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, m_DataBuf);
    if (res == KL_OK)
    {
    }
    else
    {
        m_resultStr.AppendFormat(_T("Res=%d ToRead %d Count %d "), res, numToRead, len2);
        CString s1;
        s1 = GetErrDescStr(res);
        m_resultStr += s1;
        return res;
    }
    return KL_OK;
}
int KLink1::RmoteBlinkLED(UCHAR nDst, UCHAR nPort, UCHAR nChnId, UCHAR nSecond)
{
    return RunRemoteReq(nDst, nPort, nChnId, ReqBlinkLED, nSecond,0,0,0);
}
KLink1/KLink.h
@@ -23,6 +23,37 @@
// 此类是从KLink1.dll 导出的
class KLINK1_API KLink1 {
    enum enServiceReqs
    {
        ReqNone,
        ReqInit,
        ReqReset,
        ReqStop,
        ReqRun,
        ReqBlinkLED,
        ReqStartDiag,
        ReqStopDiag,
        ReqPortChildInfo,
        ReqPortChnInfo,
        ReqUpdateFirm,
        ReqUpdateFirmInfo,
        ReqTransFirmware,
        ReqTransCfg,
        ReqTransProg,
        ReqTransData,
        ReqTransBlink,
        ReqTransChild,
        ReqTransInfo,
        ReqTransOutBandData,
        ReqRead1Bit,
        ReqWrite1Bit,
        ReqReadBits,
        ReqWriteBits,
        ReqReadData,
        ReqWriteData,
        ReqRemoteTran,
    };
    typedef unsigned char UCHAR;
    typedef unsigned short USHORT;
@@ -34,9 +65,14 @@
    HvSerialPort1 MySerPort1;
    int m_bCommParamSet = 0;
    int m_nPort;
    int m_nBaudRate;
    CString m_Settings;
    int m_nPort=1;
    int m_nBaudRate=115200;
    CString m_Settings=_T("8,N,1");
/*
    int m_nDefaultPort=1;
    int m_nDefaultBaudRate=115200;
    CString m_DefaultSettings=_T("8,N,1");
*/
#define TYPECOIL 0x00
#define TYPEDATA 0x80
@@ -103,7 +139,7 @@
        KL_NOT_SUPPORT,
    };
    const char * GetErrDescStr(int nErrNo);
    static const char * GetErrDescStr(int nErrNo);
    enum
    {
@@ -157,6 +193,10 @@
        KLCmdStartProgram,
        KLCmdWriteProgram,
        KLCmdFinishProgram,
        KLCmdReadPLCAnno,
        KLCmdStartPLCAnno,
        KLCmdWritePLCAnno,
        KLCmdFinishPLCAnno,
        KLCmdRead1Bit = 0x21,                //ReadSingleBit
        KLCmdWrite1Bit = 0x22,                //WriteSingleBit
@@ -208,7 +248,13 @@
        KLCmdMC = 0x70,
        KLCmdMD,
        KLCmdMG,
        KLCmdWriteFirmware,
        KLCmdWriteFirmInfo,
        KLCmdGetPortInfo,
        KLCmdGetPortChnInfo,
        KLCmdGetPortChildInfo,
        KLCmdPortRemoteReq,
        KLCmdThrough,
        KLCmdErrRply = 0xEE,                //ERRORReply
@@ -400,34 +446,36 @@
    typedef struct tagChnStat
    {
        unsigned int Stat;
        unsigned int SendPackets;
        unsigned int RecvPackets;
        unsigned int LastSentTimeuS;
        unsigned int LostPackets;
        unsigned int CtnLstPkts;
        unsigned int MaxCtnLstPkts;
        unsigned int NotPkgErr;
        unsigned int PkgLenErr;
        unsigned int BCCErr;
        unsigned int TimeOutErr;
        unsigned int Delay;
        unsigned int MaxDelay;
        unsigned int SendTimeInterval;
        unsigned short Stat;
        unsigned short SendPackets;
        unsigned short RecvPackets;
        unsigned short LastSentTimeuS;
        unsigned short LostPackets;
        unsigned short CtnLstPkts;
        unsigned short MaxCtnLstPkts;
        unsigned short NotPkgErr;
        unsigned short PkgLenErr;
        unsigned short BCCErr;
        unsigned short TimeOutErr;
        unsigned short Delay;
        unsigned short MaxDelay;
        unsigned short SendTimeInterval;
        union
        {
            unsigned int ClientDatas[10];
            unsigned short ClientDatas[10];
            struct {
                unsigned int ClientRecvPkts;    //
                unsigned int ClientSendPkts;    //
                unsigned int ClientNotPktErr;    //
                unsigned int ClientMisIdPkts;    //
                unsigned int ClientPkgLenErr;    //
                unsigned int ClientBccErr;        //
                unsigned int ClientTimeOutErr;    //
                unsigned short ClientRecvPkts;    //
                unsigned short ClientSendPkts;    //
                unsigned short ClientNotPktErr;    //
                unsigned short ClientMisIdPkts;    //
        //        unsigned int ClientNoEndErr;    //
                unsigned short ClientPkgLenErr;    //
                unsigned short ClientBccErr;        //
                unsigned short ClientTimeOutErr;    //
            };
        };
    } stChnStat, *pChnStat;
    enum enKLDataCounts
    {
        KLDataWXCount = 16,
@@ -467,6 +515,18 @@
            USHORT WY[64];
            UCHAR WYB[128];
            UINT WYD[32];
        };
        union //tagWLX
        {
            USHORT WLX[64];
            UCHAR WLXB[128];
            UINT WLXD[32];
        };
        union //tagWLY
        {
            USHORT WLY[64];
            UCHAR WLYB[128];
            UINT WLYD[32];
        };
        union //tagDT
        {
@@ -508,8 +568,21 @@
            unsigned short WDT[KLDataWDTCount];
            unsigned char WDB[KLDataWDTCount * 2];
        };
        union
        {
            UCHAR KBDB[2048];
            USHORT KBDT[1024];
            UINT KBDD[512];
        };
        union {
            UCHAR KWLB[256];
            USHORT KWLT[128];
            UINT KWLD[64];
        };
    }MEM;
    CString m_resultStr;
    static int xtoi(const char * hexstr, int len = 0);
@@ -596,6 +669,9 @@
    int Connect(int ConnectParam = 0);
    int DisConnect(int DisConnectParam = 0);
    
    int GotoCmdMode(int Param = 0);
    int ExitCmdMode(int Param = 0);
    int DoHeartBeat(int nParam = 0);
    void OnTimer();
@@ -610,6 +686,7 @@
    //int MakeReqPacket(void * pBuf, UCHAR nDst, UCHAR Stat, UCHAR nCMD, UCHAR Type, USHORT nAddr = 0, USHORT nCount = 0, void * pData = NULL);
    int MakeReqPacketEx(void * pBuf, UCHAR nDst, UCHAR Stat, UCHAR nCMD, UCHAR Type, USHORT nAddr = 0, USHORT nCount = 0, void * pData = NULL, int ExtFrameLen = 0, void * pExtDataFrame = NULL);
    int MakeRemoteReqPacketEx(void* pBuf, UCHAR nDst, UCHAR Stat, UCHAR nPort, UCHAR nChildId, UCHAR nCMD, UCHAR Param1, USHORT nAddr = 0, USHORT nCount = 0, void* pData = NULL, int ExtFrameLen = 0, void* pExtDataFrame = NULL);
    int CheckPackage(void * pBuf, int nSize);
    int ProcessPacket(void *pBuf, int nLen);
@@ -621,8 +698,8 @@
    int ReadFactoryData(UCHAR nDst, USHORT nStartAddr, UCHAR nByteCount, USHORT * nReadBytes, USHORT * Values);
    int WriteFactoryData(UCHAR nDst, USHORT nStartAddr, UCHAR nByteCount, USHORT * Values);
    int ReadSysCfgData(UCHAR nDst, USHORT nStartAddr, UCHAR nByteCount, USHORT * nReadBytes, USHORT * Values);
    int WriteSysCfgData(UCHAR nDst, USHORT nStartAddr, UCHAR nByteCount, USHORT * Values);
    int ReadSysCfgData(UCHAR nDst, UCHAR nType, USHORT nStartAddr, UCHAR nByteCount, USHORT * nReadBytes, USHORT * Values);
    int WriteSysCfgData(UCHAR nDst, UCHAR nType, USHORT nStartAddr, UCHAR nByteCount, USHORT * Values);
    //int GetTime32(UCHAR nDst, int * nCount);
@@ -656,15 +733,35 @@
    int BlinkLED(UCHAR nDst, UCHAR nSecond);
    int ReadProgram(UCHAR nDst, UCHAR nType, USHORT nWordAddr, UCHAR nWordCount, USHORT * Values);
    int ReadPLCProgram(UCHAR nDst, UCHAR nType, USHORT nWordAddr, UCHAR nWordCount, USHORT * Values);
    int StartDownloadPLCProgram(UCHAR nDst, UCHAR nType, USHORT nProgBytes,USHORT nCRC = 0);
    int DownloadPLCProgram(UCHAR nDst, UCHAR nType, USHORT nByteAddr, UCHAR nByteCount, USHORT * Values);
    int FinishDownloadPLCProgram(UCHAR nDst, UCHAR nType, USHORT nProgSteps, USHORT nCRC = 0);
    int StartProgram(UCHAR nDst, UCHAR nType);
    int WriteProgram(UCHAR nDst, UCHAR nType, USHORT nWordAddr, UCHAR nWordCount, USHORT * Values);
    int FinishProgram(UCHAR nDst, UCHAR nType, USHORT nStepSize);
    int ReadPLCAnno(UCHAR nDst, UCHAR nType, USHORT nByteAddr, UCHAR nByteCount, UCHAR* Values);
    int StartDownloadPLCAnno(UCHAR nDst, UCHAR nType, USHORT nBytes, USHORT nCRC = 0);
    int DownloadPLCAnno(UCHAR nDst, UCHAR nType, USHORT nByteAddr, UCHAR nByteCount, UCHAR* Values);
    int FinishDownloadPLCAnno(UCHAR nDst, UCHAR nType, USHORT nByteSize, USHORT nCRC = 0);
    int ReadRunStat(UCHAR nDst, UCHAR nType, USHORT nWordAddr, UCHAR nWordCount, USHORT * Values);
    int ClearStatistics(UCHAR nDst, UCHAR nType);
    int ResetDevice(UCHAR nDst, UCHAR nType);
    int WriteFirmware(UCHAR nDst, UCHAR nType, USHORT nByteAddr, UCHAR nByteCount, UCHAR* Values);
    int WriteFirmInfo(UCHAR nDst, UCHAR nType, USHORT nByteAddr, UCHAR nByteCount, UCHAR* Values);
    int GetPortInfo(UCHAR nDst, UCHAR nType, UCHAR nByteCount, USHORT* nByteRead, USHORT* Values);
    int GetPortChildInfo(UCHAR nDst, UCHAR nType, UCHAR nChildId, UCHAR nByteCount, USHORT* nByteRead, USHORT* Values);
    int GetPortChnInfo(UCHAR nDst, UCHAR nType, UCHAR nChnId, UCHAR nByteCount, USHORT* nByteRead, USHORT* Values);
    int RunRemoteReq(UCHAR nDst, UCHAR nPort, UCHAR nChnId, UCHAR nReqId, UCHAR nParam, USHORT nByteAddr = 0, UCHAR nByteCount =0 ,void * pData = 0);
    int RmoteBlinkLED(UCHAR nDst, UCHAR nPort, UCHAR nChnId, UCHAR nSecond);
};
KwLoRaTool/KwLoRaTool.cpp
New file
@@ -0,0 +1,155 @@

// KwLoRaTool.cpp: 定义应用程序的类行为。
//
#include "pch.h"
#include "framework.h"
#include "KwLoRaTool.h"
#include "KwLoRaToolDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CKwLoRaToolApp
BEGIN_MESSAGE_MAP(CKwLoRaToolApp, CWinApp)
    ON_COMMAND(ID_HELP, &CWinApp::OnHelp)
END_MESSAGE_MAP()
Logger myLogger1;
MHash myCfg1;
// CKwLoRaToolApp 构造
CKwLoRaToolApp::CKwLoRaToolApp()
{
    // 支持重新启动管理器
    m_dwRestartManagerSupportFlags = AFX_RESTART_MANAGER_SUPPORT_RESTART;
    // TODO: 在此处添加构造代码,
    // 将所有重要的初始化放置在 InitInstance 中
}
// 唯一的 CKwLoRaToolApp 对象
CKwLoRaToolApp theApp;
// CKwLoRaToolApp 初始化
BOOL CKwLoRaToolApp::InitInstance()
{
    // 如果一个运行在 Windows XP 上的应用程序清单指定要
    // 使用 ComCtl32.dll 版本 6 或更高版本来启用可视化方式,
    //则需要 InitCommonControlsEx()。  否则,将无法创建窗口。
    INITCOMMONCONTROLSEX InitCtrls;
    InitCtrls.dwSize = sizeof(InitCtrls);
    // 将它设置为包括所有要在应用程序中使用的
    // 公共控件类。
    InitCtrls.dwICC = ICC_WIN95_CLASSES;
    InitCommonControlsEx(&InitCtrls);
    CWinApp::InitInstance();
    AfxEnableControlContainer();
    // 创建 shell 管理器,以防对话框包含
    // 任何 shell 树视图控件或 shell 列表视图控件。
    CShellManager *pShellManager = new CShellManager;
    // 激活“Windows Native”视觉管理器,以便在 MFC 控件中启用主题
    CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows));
    // 标准初始化
    // 如果未使用这些功能并希望减小
    // 最终可执行文件的大小,则应移除下列
    // 不需要的特定初始化例程
    // 更改用于存储设置的注册表项
    // TODO: 应适当修改该字符串,
    // 例如修改为公司或组织名
    SetRegistryKey(_T("应用程序向导生成的本地应用程序"));
    CKwLoRaToolDlg dlg;
    m_pMainWnd = &dlg;
    INT_PTR nResponse = dlg.DoModal();
    if (nResponse == IDOK)
    {
        // TODO: 在此放置处理何时用
        //  “确定”来关闭对话框的代码
    }
    else if (nResponse == IDCANCEL)
    {
        // TODO: 在此放置处理何时用
        //  “取消”来关闭对话框的代码
    }
    else if (nResponse == -1)
    {
        TRACE(traceAppMsg, 0, "警告: 对话框创建失败,应用程序将意外终止。\n");
        TRACE(traceAppMsg, 0, "警告: 如果您在对话框上使用 MFC 控件,则无法 #define _AFX_NO_MFC_CONTROLS_IN_DIALOGS。\n");
    }
    // 删除上面创建的 shell 管理器。
    if (pShellManager != nullptr)
    {
        delete pShellManager;
    }
#if !defined(_AFXDLL) && !defined(_AFX_NO_MFC_CONTROLS_IN_DIALOGS)
    ControlBarCleanUp();
#endif
    // 由于对话框已关闭,所以将返回 FALSE 以便退出应用程序,
    //  而不是启动应用程序的消息泵。
    return FALSE;
}
int SysLog(CString s, int channel)
{
    myLogger1.LogTxt(s, channel);
    return 1;
}
int DbgLog(CString s, int channel)
{
    myLogger1.LogTxt(s, channel);
    return 1;
}
int PopupMessage(CString Msg, int channel)
{
    Msg.Trim(_T("\r\n"));
    SysLog(_T("报警信息: ") + Msg + _T("\r\n"), channel);
    return 0;
}
void DoEvents()
{
    MSG msg;
    while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
    {
        DispatchMessage(&msg);
        TranslateMessage(&msg);
    }
}
int LoadMyConfig()
{
    CString ConfigFilePathName;
    ConfigFilePathName = _T("./Settings.ini");
    int j = myCfg1.LoadFromFile(ConfigFilePathName);
    return j;
}
int SaveMyConfig()
{
    CString ConfigFilePathName;
    ConfigFilePathName = _T("./Settings.ini");
    int j = myCfg1.SaveToFile(ConfigFilePathName);
    return j;
}
KwLoRaTool/KwLoRaTool.h
New file
@@ -0,0 +1,41 @@

// KwLoRaTool.h: PROJECT_NAME 应用程序的主头文件
//
#pragma once
#ifndef __AFXWIN_H__
    #error "在包含此文件之前包含 'pch.h' 以生成 PCH"
#endif
#include "resource.h"        // 主符号
#include "../MyLib/LOGGER/Logger.hpp"
#include "../MyLib/MHashINI/MHash.hpp"
//#include "SerialPort.h"
// CKwLoRaToolApp:
// 有关此类的实现,请参阅 KwLoRaTool.cpp
//
class CKwLoRaToolApp : public CWinApp
{
public:
    CKwLoRaToolApp();
// 重写
public:
    virtual BOOL InitInstance();
// 实现
    DECLARE_MESSAGE_MAP()
};
extern CKwLoRaToolApp theApp;
extern Logger myLogger1;
extern MHash myCfg1;
int SysLog(CString s, int channel = 0);
int DbgLog(CString s, int channel = 0);
int PopupMessage(CString Msg, int channel = 0);
void DoEvents();
KwLoRaTool/KwLoRaTool.rc
Binary files differ
KwLoRaTool/KwLoRaTool.vcxproj
New file
@@ -0,0 +1,219 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup Label="ProjectConfigurations">
    <ProjectConfiguration Include="Debug|Win32">
      <Configuration>Debug</Configuration>
      <Platform>Win32</Platform>
    </ProjectConfiguration>
    <ProjectConfiguration Include="Release|Win32">
      <Configuration>Release</Configuration>
      <Platform>Win32</Platform>
    </ProjectConfiguration>
    <ProjectConfiguration Include="Debug|x64">
      <Configuration>Debug</Configuration>
      <Platform>x64</Platform>
    </ProjectConfiguration>
    <ProjectConfiguration Include="Release|x64">
      <Configuration>Release</Configuration>
      <Platform>x64</Platform>
    </ProjectConfiguration>
  </ItemGroup>
  <PropertyGroup Label="Globals">
    <VCProjectVersion>16.0</VCProjectVersion>
    <ProjectGuid>{B10AEE8B-ECA1-4758-A8AD-05FED4DE6A32}</ProjectGuid>
    <Keyword>MFCProj</Keyword>
    <RootNamespace>KwLoRaTool</RootNamespace>
    <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
  </PropertyGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
    <ConfigurationType>Application</ConfigurationType>
    <UseDebugLibraries>true</UseDebugLibraries>
    <PlatformToolset>v142</PlatformToolset>
    <CharacterSet>Unicode</CharacterSet>
    <UseOfMfc>Dynamic</UseOfMfc>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
    <ConfigurationType>Application</ConfigurationType>
    <UseDebugLibraries>false</UseDebugLibraries>
    <PlatformToolset>v142</PlatformToolset>
    <WholeProgramOptimization>true</WholeProgramOptimization>
    <CharacterSet>Unicode</CharacterSet>
    <UseOfMfc>Dynamic</UseOfMfc>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
    <ConfigurationType>Application</ConfigurationType>
    <UseDebugLibraries>true</UseDebugLibraries>
    <PlatformToolset>v142</PlatformToolset>
    <CharacterSet>Unicode</CharacterSet>
    <UseOfMfc>Dynamic</UseOfMfc>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
    <ConfigurationType>Application</ConfigurationType>
    <UseDebugLibraries>false</UseDebugLibraries>
    <PlatformToolset>v142</PlatformToolset>
    <WholeProgramOptimization>true</WholeProgramOptimization>
    <CharacterSet>Unicode</CharacterSet>
    <UseOfMfc>Dynamic</UseOfMfc>
  </PropertyGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
  <ImportGroup Label="ExtensionSettings">
  </ImportGroup>
  <ImportGroup Label="Shared">
  </ImportGroup>
  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  </ImportGroup>
  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  </ImportGroup>
  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  </ImportGroup>
  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  </ImportGroup>
  <PropertyGroup Label="UserMacros" />
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
    <LinkIncremental>false</LinkIncremental>
    <LibraryPath>../x64/Release;x64/Release;$(LibraryPath)</LibraryPath>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    <LinkIncremental>true</LinkIncremental>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    <LinkIncremental>true</LinkIncremental>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    <LinkIncremental>false</LinkIncremental>
  </PropertyGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
    <ClCompile>
      <PrecompiledHeader>Use</PrecompiledHeader>
      <WarningLevel>Level3</WarningLevel>
      <FunctionLevelLinking>true</FunctionLevelLinking>
      <IntrinsicFunctions>true</IntrinsicFunctions>
      <SDLCheck>true</SDLCheck>
      <PreprocessorDefinitions>_WINDOWS;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
      <LanguageStandard>stdcpp20</LanguageStandard>
    </ClCompile>
    <Link>
      <SubSystem>Windows</SubSystem>
      <EnableCOMDATFolding>true</EnableCOMDATFolding>
      <OptimizeReferences>true</OptimizeReferences>
    </Link>
    <Midl>
      <MkTypLibCompatible>false</MkTypLibCompatible>
      <ValidateAllParameters>true</ValidateAllParameters>
      <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
    </Midl>
    <ResourceCompile>
      <Culture>0x0804</Culture>
      <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
    </ResourceCompile>
  </ItemDefinitionGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    <ClCompile>
      <PrecompiledHeader>Use</PrecompiledHeader>
      <WarningLevel>Level3</WarningLevel>
      <SDLCheck>true</SDLCheck>
      <PreprocessorDefinitions>WIN32;_WINDOWS;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
    </ClCompile>
    <Link>
      <SubSystem>Windows</SubSystem>
    </Link>
    <Midl>
      <MkTypLibCompatible>false</MkTypLibCompatible>
      <ValidateAllParameters>true</ValidateAllParameters>
      <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
    </Midl>
    <ResourceCompile>
      <Culture>0x0804</Culture>
      <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
    </ResourceCompile>
  </ItemDefinitionGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    <ClCompile>
      <PrecompiledHeader>Use</PrecompiledHeader>
      <WarningLevel>Level3</WarningLevel>
      <SDLCheck>true</SDLCheck>
      <PreprocessorDefinitions>_WINDOWS;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
    </ClCompile>
    <Link>
      <SubSystem>Windows</SubSystem>
    </Link>
    <Midl>
      <MkTypLibCompatible>false</MkTypLibCompatible>
      <ValidateAllParameters>true</ValidateAllParameters>
      <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
    </Midl>
    <ResourceCompile>
      <Culture>0x0804</Culture>
      <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
    </ResourceCompile>
  </ItemDefinitionGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    <ClCompile>
      <PrecompiledHeader>Use</PrecompiledHeader>
      <WarningLevel>Level3</WarningLevel>
      <FunctionLevelLinking>true</FunctionLevelLinking>
      <IntrinsicFunctions>true</IntrinsicFunctions>
      <SDLCheck>true</SDLCheck>
      <PreprocessorDefinitions>WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
    </ClCompile>
    <Link>
      <SubSystem>Windows</SubSystem>
      <EnableCOMDATFolding>true</EnableCOMDATFolding>
      <OptimizeReferences>true</OptimizeReferences>
    </Link>
    <Midl>
      <MkTypLibCompatible>false</MkTypLibCompatible>
      <ValidateAllParameters>true</ValidateAllParameters>
      <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
    </Midl>
    <ResourceCompile>
      <Culture>0x0804</Culture>
      <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
    </ResourceCompile>
  </ItemDefinitionGroup>
  <ItemGroup>
    <ClInclude Include="framework.h" />
    <ClInclude Include="KwLoRaTool.h" />
    <ClInclude Include="KwLoRaToolDlg.h" />
    <ClInclude Include="MyButton.h" />
    <ClInclude Include="pch.h" />
    <ClInclude Include="Resource.h" />
    <ClInclude Include="targetver.h" />
  </ItemGroup>
  <ItemGroup>
    <ClCompile Include="KwLoRaTool.cpp" />
    <ClCompile Include="KwLoRaToolDlg.cpp" />
    <ClCompile Include="MyButton.cpp" />
    <ClCompile Include="pch.cpp">
      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
    </ClCompile>
  </ItemGroup>
  <ItemGroup>
    <ResourceCompile Include="KwLoRaTool.rc" />
  </ItemGroup>
  <ItemGroup>
    <None Include="res\KwLoRaTool.rc2" />
  </ItemGroup>
  <ItemGroup>
    <Image Include="res\KwLoRaTool.ico" />
  </ItemGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
  <ImportGroup Label="ExtensionTargets">
  </ImportGroup>
</Project>
KwLoRaTool/KwLoRaTool.vcxproj.filters
New file
@@ -0,0 +1,69 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup>
    <Filter Include="源文件">
      <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
      <Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
    </Filter>
    <Filter Include="头文件">
      <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
      <Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
    </Filter>
    <Filter Include="资源文件">
      <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
      <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
    </Filter>
  </ItemGroup>
  <ItemGroup>
    <ClInclude Include="KwLoRaTool.h">
      <Filter>头文件</Filter>
    </ClInclude>
    <ClInclude Include="KwLoRaToolDlg.h">
      <Filter>头文件</Filter>
    </ClInclude>
    <ClInclude Include="framework.h">
      <Filter>头文件</Filter>
    </ClInclude>
    <ClInclude Include="targetver.h">
      <Filter>头文件</Filter>
    </ClInclude>
    <ClInclude Include="Resource.h">
      <Filter>头文件</Filter>
    </ClInclude>
    <ClInclude Include="pch.h">
      <Filter>头文件</Filter>
    </ClInclude>
    <ClInclude Include="MyButton.h">
      <Filter>头文件</Filter>
    </ClInclude>
  </ItemGroup>
  <ItemGroup>
    <ClCompile Include="KwLoRaTool.cpp">
      <Filter>源文件</Filter>
    </ClCompile>
    <ClCompile Include="KwLoRaToolDlg.cpp">
      <Filter>源文件</Filter>
    </ClCompile>
    <ClCompile Include="pch.cpp">
      <Filter>源文件</Filter>
    </ClCompile>
    <ClCompile Include="MyButton.cpp">
      <Filter>源文件</Filter>
    </ClCompile>
  </ItemGroup>
  <ItemGroup>
    <ResourceCompile Include="KwLoRaTool.rc">
      <Filter>资源文件</Filter>
    </ResourceCompile>
  </ItemGroup>
  <ItemGroup>
    <None Include="res\KwLoRaTool.rc2">
      <Filter>资源文件</Filter>
    </None>
  </ItemGroup>
  <ItemGroup>
    <Image Include="res\KwLoRaTool.ico">
      <Filter>资源文件</Filter>
    </Image>
  </ItemGroup>
</Project>
KwLoRaTool/KwLoRaToolDlg.cpp
New file
@@ -0,0 +1,601 @@

// KwLoRaToolDlg.cpp: 实现文件
//
#include "pch.h"
#include "framework.h"
#include "KwLoRaTool.h"
#include "KwLoRaToolDlg.h"
#include "afxdialogex.h"
#include <devguid.h>
#include <SetupAPI.h>
#include <Dbt.h>
#pragma comment(lib,"SetupAPI.lib")
#include "../KLink1/KLink.h"
#pragma comment(lib,"KLink1.lib")
KLink1 myKlink1;
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
const CKwLoRaToolDlg::stWLConfig defaultWLConfig =
{
    .RF_T_Freq = 430620000,            // uint32_t     Hz
    .RF_R_Freq = 430620000,            // uint32_t         //Hz
    .nChnSpacing = 530,            //          uint16_t ChannelSpacing;        //kHz
    .nCycleTime = 80,        // CycleTime
//    .ModemType = 1, //        //0: FSK,    1: LoRa
    .workMode = 3,                //    0, None 1, Uni, 2 Thr, 3 Multi1, 4 Multi2,  5 MulMa
    .nChannel = 0,
    .bMaster = 0,
    .nRadioAddr = 1 ,
    .bEnableMulti = 0,
    .Tx_Power = 20,                //      uchar Tx_Power;
    .LoraBandWidth = 1,                //             uchar LoraBandWidth;        //        [0: 125 kHz, 1: 250 kHz, 2: 500 kHz, 3: Reserved ]
    .LoRaFactor = 5,                //             uchar LoRaFactor;                //        [SF5 .. SF 12]
    .LoRaCodingRate = 1,                //            uchar LoRaCodingRate;        //        [1 : 4/5,  2: 4/6,  3:  4/7,    4:  4/8
    .NetWorkAddr = 0x00,            //            uint8_t NetWorkAddr;
    .DeviceAddr = 0x0102,        //            uint16_t DeviceAddr;
    .bEnableAddr = 0,                //            uchar bEnableAddr;
    .bEnableEncrypt = 0,                //            uchar bEnableEncrypt;
    .bEnableRelay = 0,                //            uchar bEnableRelay;
    .LoRaPreambleLen = 4,                //            uchar LoRaPreamble_Len;            // 2 - 12
    .bAutoPower = 1,
    .bAutoReSend = 1,                        // 自动重发
};
// 用于应用程序“关于”菜单项的 CAboutDlg 对话框
class CAboutDlg : public CDialogEx
{
public:
    CAboutDlg();
// 对话框数据
#ifdef AFX_DESIGN_TIME
    enum { IDD = IDD_ABOUTBOX };
#endif
    protected:
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV 支持
// 实现
protected:
    DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialogEx(IDD_ABOUTBOX)
{
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
    CDialogEx::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx)
END_MESSAGE_MAP()
// CKwLoRaToolDlg 对话框
CKwLoRaToolDlg::CKwLoRaToolDlg(CWnd* pParent /*=nullptr*/)
    : CDialogEx(IDD_KWLORATOOL_DIALOG, pParent)
{
    m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CKwLoRaToolDlg::DoDataExchange(CDataExchange* pDX)
{
    CDialogEx::DoDataExchange(pDX);
    DDX_Control(pDX, IDC_MFCBUTTON1, m_button1);
    DDX_Control(pDX, IDC_BUTTON_CONN, m_Button_Conn);
    DDX_Control(pDX, IDC_BUTTON_EN_CMD, m_MFCButton_EN_CMD);
    DDX_Control(pDX, IDC_BUTTON_SCAN_COM, m_MFCButton_SCAN_COM);
    DDX_Control(pDX, IDC_BUTTON_EXPORT_CONFIG, m_MFCButton_EXPORT_CONFIG);
    DDX_Control(pDX, IDC_BUTTON_CLEAR_LOG, m_MFCButton_CLEAR_LOG);
    DDX_Control(pDX, IDC_BUTTON_SEND_NID, m_MFCButton_SEND_NID);
    DDX_Control(pDX, IDC_BUTTON_SEND_ADDR, m_MFCButton_SEND_ADDR);
    DDX_Control(pDX, IDC_BUTTON_SEND_EN_ADDR, m_MFCButton_SEND_EN_ADDR);
    DDX_Control(pDX, IDC_BUTTON_SEND_ENCYPT, m_MFCButton_SEND_ENCYPT);
    DDX_Control(pDX, IDC_BUTTON_SEND_RELAY, m_MFCButton_SEND_RELAY);
    DDX_Control(pDX, IDC_BUTTON_SEND_T_FREQ, m_MFCButton_SEND_T_FREQ);
    DDX_Control(pDX, IDC_BUTTON_SEND_R_FREQ, m_MFCButton_SEND_R_FREQ);
    DDX_Control(pDX, IDC_BUTTON_SEND_RFPOWER, m_MFCButton_SEND_RF_POWER);
    DDX_Control(pDX, IDC_BUTTON_SEND_RFBW, m_MFCButton_SEND_RF_BW);
    DDX_Control(pDX, IDC_BUTTON_SEND_FACTOR, m_MFCButton_SEND_LORA_FACTOR);
    DDX_Control(pDX, IDC_BUTTON_SEND_FEC_RATE, m_MFCButton_SEND_LORA_FEC_RATE);
    DDX_Control(pDX, IDC_BUTTON_SEND_COM_BAUDRATE, m_MFCButton_SEND_COM_BAUDRATE);
    DDX_Control(pDX, IDC_BUTTON_SEND_COM_FORMAT, m_MFCButton_SEND_COM_FORMAT);
    DDX_Control(pDX, IDC_BUTTON_SEND_DEFAULT, m_MFCButton_SEND_DEFAULT);
    DDX_Control(pDX, IDC_BUTTON_SEND_RESET, m_MFCButton_SEND_RESET);
    DDX_Control(pDX, IDC_BUTTON_READ, m_MFCButton_RAED);
    DDX_Control(pDX, IDC_BUTTON_WRITE, m_MFCButton_WRITE);
    DDX_Control(pDX, IDC_COMBO_COM_SEL, m_combo_com_sel);
}
BEGIN_MESSAGE_MAP(CKwLoRaToolDlg, CDialogEx)
    ON_WM_SYSCOMMAND()
    ON_WM_PAINT()
    ON_WM_QUERYDRAGICON()
    ON_WM_DEVICECHANGE()
    ON_BN_CLICKED(IDC_BUTTON_CONN, &CKwLoRaToolDlg::OnBnClickedButtonConn)
    ON_BN_CLICKED(IDC_BUTTON_EN_CMD, &CKwLoRaToolDlg::OnBnClickedButtonEnCmd)
    ON_BN_CLICKED(IDC_BUTTON_SCAN_COM, &CKwLoRaToolDlg::OnBnClickedButtonScanCom)
    ON_BN_CLICKED(IDC_BUTTON_EXPORT_CONFIG, &CKwLoRaToolDlg::OnBnClickedButtonExportConfig)
    ON_BN_CLICKED(IDC_BUTTON_CLEAR_LOG, &CKwLoRaToolDlg::OnBnClickedButtonClearLog)
    ON_BN_CLICKED(IDC_BUTTON_SEND_NID, &CKwLoRaToolDlg::OnBnClickedButtonSendNid)
    ON_BN_CLICKED(IDC_BUTTON_SEND_ADDR, &CKwLoRaToolDlg::OnBnClickedButtonSendAddr)
    ON_BN_CLICKED(IDC_BUTTON_SEND_EN_ADDR, &CKwLoRaToolDlg::OnBnClickedButtonSendEnAddr)
    ON_BN_CLICKED(IDC_BUTTON_SEND_ENCYPT, &CKwLoRaToolDlg::OnBnClickedButtonSendEncypt)
    ON_BN_CLICKED(IDC_BUTTON_SEND_RELAY, &CKwLoRaToolDlg::OnBnClickedButtonSendRelay)
    ON_BN_CLICKED(IDC_BUTTON_SEND_T_FREQ, &CKwLoRaToolDlg::OnBnClickedButtonSendTFreq)
    ON_BN_CLICKED(IDC_BUTTON_SEND_R_FREQ, &CKwLoRaToolDlg::OnBnClickedButtonSendRFreq)
    ON_BN_CLICKED(IDC_BUTTON_SEND_RFPOWER, &CKwLoRaToolDlg::OnBnClickedButtonSendRfpower)
    ON_BN_CLICKED(IDC_BUTTON_SEND_RFBW, &CKwLoRaToolDlg::OnBnClickedButtonSendRfbw)
    ON_BN_CLICKED(IDC_BUTTON_SEND_FACTOR, &CKwLoRaToolDlg::OnBnClickedButtonSendFactor)
    ON_BN_CLICKED(IDC_BUTTON_SEND_FEC_RATE, &CKwLoRaToolDlg::OnBnClickedButtonSendFecRate)
    ON_BN_CLICKED(IDC_BUTTON_SEND_COM_BAUDRATE, &CKwLoRaToolDlg::OnBnClickedButtonSendComBaudrate)
    ON_BN_CLICKED(IDC_BUTTON_SEND_COM_FORMAT, &CKwLoRaToolDlg::OnBnClickedButtonSendComFormat)
    ON_BN_CLICKED(IDC_BUTTON_SEND_DEFAULT, &CKwLoRaToolDlg::OnBnClickedButtonSendDefault)
    ON_BN_CLICKED(IDC_BUTTON_SEND_RESET, &CKwLoRaToolDlg::OnBnClickedButtonSendReset)
    ON_BN_CLICKED(IDC_BUTTON_READ, &CKwLoRaToolDlg::OnBnClickedButtonRead)
    ON_BN_CLICKED(IDC_BUTTON_WRITE, &CKwLoRaToolDlg::OnBnClickedButtonWrite)
    ON_WM_TIMER()
END_MESSAGE_MAP()
// 串口接收数据, 响应方式
// 1, 阻塞等待
// 2, 非阻塞,轮询
// 3, 回调函数
// 4, windows消息
//
// CKwLoRaToolDlg 消息处理程序
unsigned int BtnIdList[] =
{
    IDC_BUTTON_CONN,IDC_BUTTON_EN_CMD,IDC_BUTTON_SCAN_COM,IDC_BUTTON_EXPORT_CONFIG,
    IDC_BUTTON_CLEAR_LOG,
    IDC_BUTTON_SEND_NID,IDC_BUTTON_SEND_ADDR,IDC_BUTTON_SEND_EN_ADDR,IDC_BUTTON_SEND_ENCYPT,IDC_BUTTON_SEND_RELAY,
    IDC_BUTTON_SEND_T_FREQ,IDC_BUTTON_SEND_R_FREQ,IDC_BUTTON_SEND_RFPOWER,IDC_BUTTON_SEND_RFBW,IDC_BUTTON_SEND_FACTOR,IDC_BUTTON_SEND_FEC_RATE,
    IDC_BUTTON_SEND_COM_BAUDRATE,IDC_BUTTON_SEND_COM_FORMAT,
    IDC_BUTTON_SEND_DEFAULT,IDC_BUTTON_SEND_RESET,IDC_BUTTON_READ,IDC_BUTTON_WRITE
};
BOOL CKwLoRaToolDlg::OnInitDialog()
{
    CDialogEx::OnInitDialog();
    // 将“关于...”菜单项添加到系统菜单中。
    // IDM_ABOUTBOX 必须在系统命令范围内。
    ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
    ASSERT(IDM_ABOUTBOX < 0xF000);
    CMenu* pSysMenu = GetSystemMenu(FALSE);
    if (pSysMenu != nullptr)
    {
        BOOL bNameValid;
        CString strAboutMenu;
        bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
        ASSERT(bNameValid);
        if (!strAboutMenu.IsEmpty())
        {
            pSysMenu->AppendMenu(MF_SEPARATOR);
            pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
        }
    }
    // 设置此对话框的图标。  当应用程序主窗口不是对话框时,框架将自动
    //  执行此操作
    SetIcon(m_hIcon, TRUE);            // 设置大图标
    SetIcon(m_hIcon, FALSE);        // 设置小图标
    // TODO: 在此添加额外的初始化代码
    m_button1.m_bTransparent = FALSE;
    m_button1.m_bDontUseWinXPTheme = TRUE;
    m_button1.SetFaceColor(RGB(128, 128, 255));
    for (int i = 0; i < sizeof(BtnIdList) / sizeof(unsigned int); i++){
        ((CMFCButton*)GetDlgItem(BtnIdList[i]))->m_bTransparent = FALSE;
        ((CMFCButton*)GetDlgItem(BtnIdList[i]))->m_bDontUseWinXPTheme = TRUE;
        ((CMFCButton*)GetDlgItem(BtnIdList[i]))->SetFaceColor(RGB(40, 40, 255));
        ((CMFCButton*)GetDlgItem(BtnIdList[i]))->SetTextColor(RGB(255, 255, 255));
    }
    myLogger1.AttachWnd(GetDlgItem(IDC_EDIT_LOG)->m_hWnd);
    myLogger1.bShowLog[0] = 1;
    myLogger1.bSaveLog[0] = 1;
    myLogger1.SetLogPathName(_T("D:/logs/FirmWareTool"), _T("RunLog"));
    myLogger1.bShowThreadId = 0;
    myLogger1.bShowChannel = 0;
    SysLog(_T("Program Start \r\n"));
    SetTimer(0, 100, NULL);//delayinit
    SetTimer(2, 100, NULL);//display
//    LoadConfig();
    myWLConfig = defaultWLConfig;
    ShowParams();
    return TRUE;  // 除非将焦点设置到控件,否则返回 TRUE
}
void CKwLoRaToolDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
    if ((nID & 0xFFF0) == IDM_ABOUTBOX)
    {
        CAboutDlg dlgAbout;
        dlgAbout.DoModal();
    }
    else
    {
        CDialogEx::OnSysCommand(nID, lParam);
    }
}
// 如果向对话框添加最小化按钮,则需要下面的代码
//  来绘制该图标。  对于使用文档/视图模型的 MFC 应用程序,
//  这将由框架自动完成。
void CKwLoRaToolDlg::OnPaint()
{
    if (IsIconic())
    {
        CPaintDC dc(this); // 用于绘制的设备上下文
        SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
        // 使图标在工作区矩形中居中
        int cxIcon = GetSystemMetrics(SM_CXICON);
        int cyIcon = GetSystemMetrics(SM_CYICON);
        CRect rect;
        GetClientRect(&rect);
        int x = (rect.Width() - cxIcon + 1) / 2;
        int y = (rect.Height() - cyIcon + 1) / 2;
        // 绘制图标
        dc.DrawIcon(x, y, m_hIcon);
    }
    else
    {
        CDialogEx::OnPaint();
    }
}
//当用户拖动最小化窗口时系统调用此函数取得光标
//显示。
HCURSOR CKwLoRaToolDlg::OnQueryDragIcon()
{
    return static_cast<HCURSOR>(m_hIcon);
}
int CKwLoRaToolDlg::DelayInit()
{
    // TODO: 在此处添加实现代码.
    return 0;
}
//得到COMx的名字
//namebuf:用于存放名字的缓冲区
//bufsize:缓冲区大小
//comx:要查找的COM编号.例如:COM1,COM2,COM3....
//返回值:0,成功找到了.
//       1,失败.
int get_com_name(CString comx, CString& namebuf)
{
    HDEVINFO hdinfo;
    int res = 0;
    SP_DEVINFO_DATA   hddevinfo = { sizeof(SP_DEVINFO_DATA) };
    hdinfo = SetupDiGetClassDevs(&GUID_DEVCLASS_PORTS, 0, 0, DIGCF_PRESENT);//获取PORTS类别的已安装设备信息
    if (hdinfo != INVALID_HANDLE_VALUE)//获取成功
    {
        for (int i = 0; SetupDiEnumDeviceInfo(hdinfo, i, &hddevinfo); i++)//轮询所有已安装设备
        {
            SetupDiGetDeviceRegistryProperty(hdinfo, &hddevinfo, SPDRP_FRIENDLYNAME, 0, (PBYTE)(namebuf.GetBuffer(2048)), 2048, 0);//获得单个装置的详细资料
            namebuf.ReleaseBuffer();
            if (namebuf.Find(comx) != -1) {
                res = 1; break;
            }
            //char *t;
            //t = strstr(namebuf, comx);
            //if (t)
            //{
            //    t--;
            //    *t = '\0';//添加结束符,作用就是把"(COMX)"这段字符去掉
            //    res = 0;
            //    break;//成功找到了COMx的名字
            //}
        }
    }
    return res;
}
int CKwLoRaToolDlg::ShowParams()
{
    // TODO: 在此处添加实现代码.
    UpdateComList();
    CString s1;
    s1.Format(_T("%02X"), myWLConfig.NetWorkAddr);
    SetDlgItemText(IDC_EDIT_NET_ID, s1);
    s1.Format(_T("%02X"), myWLConfig.nRadioAddr);
    SetDlgItemText(IDC_EDIT_NET_ID, s1);
    s1.Format(_T("%02X"), myWLConfig.nChannel);
    SetDlgItemText(IDC_EDIT_NET_ID, s1);
    s1.Format(_T("%02X"), myWLConfig.DeviceAddr);
    SetDlgItemText(IDC_EDIT_NET_ID, s1);
    s1.Format(_T("%02X"), myWLConfig.bEnableAddr);
    SetDlgItemText(IDC_EDIT_NET_ID, s1);
    s1.Format(_T("%02X"), myWLConfig.bEnableEncrypt);
    SetDlgItemText(IDC_EDIT_NET_ID, s1);
    s1.Format(_T("%02X"), myWLConfig.bEnableRelay);
    SetDlgItemText(IDC_EDIT_NET_ID, s1);
    s1.Format(_T("%02X"), myWLConfig.NetWorkAddr);
    SetDlgItemText(IDC_EDIT_NET_ID, s1);
    s1.Format(_T("%02X"), myWLConfig.NetWorkAddr);
    SetDlgItemText(IDC_EDIT_NET_ID, s1);
    s1.Format(_T("%02X"), myWLConfig.Tx_Power);
    SetDlgItemText(IDC_EDIT_NET_ID, s1);
    s1.Format(_T("%02X"), myWLConfig.LoraBandWidth);
    SetDlgItemText(IDC_EDIT_NET_ID, s1);
    s1.Format(_T("%02X"), myWLConfig.LoRaFactor);
    SetDlgItemText(IDC_EDIT_NET_ID, s1);
    s1.Format(_T("%02X"), myWLConfig.LoRaCodingRate);
    SetDlgItemText(IDC_EDIT_NET_ID, s1);
    s1.Format(_T("%02X"), myWLConfig.LoRaPreambleLen);
    SetDlgItemText(IDC_EDIT_NET_ID, s1);
    s1.Format(_T("%02X"), myWLConfig.bAutoPower);
    SetDlgItemText(IDC_EDIT_NET_ID, s1);
    s1.Format(_T("%02X"), myWLConfig.bAutoReSend);
    SetDlgItemText(IDC_EDIT_NET_ID, s1);
    s1.Format(_T("%02X"), myWLConfig.NetWorkAddr);
    return 0;
}
int CKwLoRaToolDlg::UpdateComList()
{
    // TODO: 在此处添加实现代码.
    CString s1, s2;
    m_combo_com_sel.Clear();
    m_combo_com_sel.ResetContent();
    for (int i = 1; i <= 16; i++) {
        s1.Format(_T("COM%d"), i);
        if (get_com_name(s1 + _T(")"), s2)) { s1 = s2; }
        m_combo_com_sel.AddString(s1);
    }
    m_combo_com_sel.SetCurSel(0);
    ((CComboBox*)GetDlgItem(IDC_COMBO_CONN_BAUDRATE))->SetCurSel(3);
    ((CComboBox*)GetDlgItem(IDC_COMBO_CONN_PARITY))->SetCurSel(0);
    ((CComboBox*)GetDlgItem(IDC_COMBO_CONN_DATABIT))->SetCurSel(1);
    ((CComboBox*)GetDlgItem(IDC_COMBO_CONN_STOPBIT))->SetCurSel(0);
    return 0;
    HKEY   hKey;
    if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("Hardware\\DeviceMap\\SerialComm"), NULL, KEY_READ, &hKey) == ERROR_SUCCESS)
    {
        TCHAR       szPortName[256], szComName[256];
        DWORD       dwLong, dwSize;
        int         nCount = 0;
        m_combo_com_sel.ResetContent();
        while (true)
        {
            dwLong = dwSize = 256;
            if (RegEnumValue(hKey, nCount, szPortName, &dwLong, NULL, NULL, (PUCHAR)szComName, &dwSize) == ERROR_NO_MORE_ITEMS)
                break;
            m_combo_com_sel.InsertString(nCount, szComName);
            nCount++;
        }
        RegCloseKey(hKey);
        m_combo_com_sel.SetCurSel(0);
    }
    return 0;
}
///*
BOOL CKwLoRaToolDlg::OnDeviceChange(UINT nEventType, DWORD_PTR dwData)
{
    if (nEventType == DBT_DEVNODES_CHANGED)
        UpdateComList();
    return  TRUE;
}
// */
int CKwLoRaToolDlg::GetParams()
{
    // TODO: 在此处添加实现代码.
    return 0;
}
void CKwLoRaToolDlg::OnTimer(UINT_PTR nIDEvent)
{
    // TODO: 在此添加消息处理程序代码和/或调用默认值
    if (nIDEvent == 0)
    {
        KillTimer(0);
        DelayInit();
    }
    else if (nIDEvent == 1)
    {
        //ProcessPLC();
    }
    else if (nIDEvent == 2)
    {
        //        ProcessInput();
        //DrawPic1();
        myLogger1.UpdateLogDisplay(0);
    }
    else if (nIDEvent == 3)
    {
    }
    else
    {
    }
    CDialogEx::OnTimer(nIDEvent);
}
void CKwLoRaToolDlg::OnBnClickedButtonConn()
{
    // TODO: 在此添加控件通知处理程序代码
    myKlink1.Connect();
}
void CKwLoRaToolDlg::OnBnClickedButtonEnCmd()
{
    // TODO: 在此添加控件通知处理程序代码
}
void CKwLoRaToolDlg::OnBnClickedButtonScanCom()
{
    // TODO: 在此添加控件通知处理程序代码
}
void CKwLoRaToolDlg::OnBnClickedButtonExportConfig()
{
    // TODO: 在此添加控件通知处理程序代码
}
void CKwLoRaToolDlg::OnBnClickedButtonSendNid()
{
    // TODO: 在此添加控件通知处理程序代码
}
void CKwLoRaToolDlg::OnBnClickedButtonSendAddr()
{
    // TODO: 在此添加控件通知处理程序代码
}
void CKwLoRaToolDlg::OnBnClickedButtonSendEnAddr()
{
    // TODO: 在此添加控件通知处理程序代码
}
void CKwLoRaToolDlg::OnBnClickedButtonSendEncypt()
{
    // TODO: 在此添加控件通知处理程序代码
}
void CKwLoRaToolDlg::OnBnClickedButtonSendRelay()
{
    // TODO: 在此添加控件通知处理程序代码
}
void CKwLoRaToolDlg::OnBnClickedButtonSendTFreq()
{
    // TODO: 在此添加控件通知处理程序代码
}
void CKwLoRaToolDlg::OnBnClickedButtonSendRFreq()
{
    // TODO: 在此添加控件通知处理程序代码
}
void CKwLoRaToolDlg::OnBnClickedButtonSendRfpower()
{
    // TODO: 在此添加控件通知处理程序代码
}
void CKwLoRaToolDlg::OnBnClickedButtonSendRfbw()
{
    // TODO: 在此添加控件通知处理程序代码
}
void CKwLoRaToolDlg::OnBnClickedButtonSendFactor()
{
    // TODO: 在此添加控件通知处理程序代码
}
void CKwLoRaToolDlg::OnBnClickedButtonSendFecRate()
{
    // TODO: 在此添加控件通知处理程序代码
}
void CKwLoRaToolDlg::OnBnClickedButtonSendComBaudrate()
{
    // TODO: 在此添加控件通知处理程序代码
}
void CKwLoRaToolDlg::OnBnClickedButtonSendComFormat()
{
    // TODO: 在此添加控件通知处理程序代码
}
void CKwLoRaToolDlg::OnBnClickedButtonSendDefault()
{
    // TODO: 在此添加控件通知处理程序代码
}
void CKwLoRaToolDlg::OnBnClickedButtonSendReset()
{
    // TODO: 在此添加控件通知处理程序代码
}
void CKwLoRaToolDlg::OnBnClickedButtonRead()
{
    // TODO: 在此添加控件通知处理程序代码
}
void CKwLoRaToolDlg::OnBnClickedButtonWrite()
{
    // TODO: 在此添加控件通知处理程序代码
}
void CKwLoRaToolDlg::OnBnClickedButtonClearLog()
{
    // TODO: 在此添加控件通知处理程序代码
}
KwLoRaTool/KwLoRaToolDlg.h
New file
@@ -0,0 +1,134 @@

// KwLoRaToolDlg.h: 头文件
//
#pragma once
#include "MyButton.h"
// CKwLoRaToolDlg 对话框
class CKwLoRaToolDlg : public CDialogEx
{
// 构造
public:
    CKwLoRaToolDlg(CWnd* pParent = nullptr);    // 标准构造函数
// 对话框数据
#ifdef AFX_DESIGN_TIME
    enum { IDD = IDD_KWLORATOOL_DIALOG };
#endif
    protected:
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV 支持
// 实现
protected:
    HICON m_hIcon;
    // 生成的消息映射函数
    virtual BOOL OnInitDialog();
    afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
    afx_msg void OnPaint();
    afx_msg HCURSOR OnQueryDragIcon();
    DECLARE_MESSAGE_MAP()
public:
    int ShowParams();
    int GetParams();
    afx_msg void OnTimer(UINT_PTR nIDEvent);
    int DelayInit();
    CMFCButton m_button1;
    CMFCButton m_Button_Conn;
    CMFCButton m_MFCButton_EN_CMD;
    CMFCButton m_MFCButton_SCAN_COM;
    CMFCButton m_MFCButton_EXPORT_CONFIG;
    CMFCButton m_MFCButton_CLEAR_LOG;
    CMFCButton m_MFCButton_SEND_NID;
    CMFCButton m_MFCButton_SEND_ADDR;
    CMFCButton m_MFCButton_SEND_EN_ADDR;
    CMFCButton m_MFCButton_SEND_ENCYPT;
    CMFCButton m_MFCButton_SEND_RELAY;
    CMFCButton m_MFCButton_SEND_T_FREQ;
    CMFCButton m_MFCButton_SEND_R_FREQ;
    CMFCButton m_MFCButton_SEND_RF_POWER;
    CMFCButton m_MFCButton_SEND_RF_BW;
    CMFCButton m_MFCButton_SEND_LORA_FACTOR;
    CMFCButton m_MFCButton_SEND_LORA_FEC_RATE;
    CMFCButton m_MFCButton_SEND_COM_BAUDRATE;
    CMFCButton m_MFCButton_SEND_COM_FORMAT;
    CMFCButton m_MFCButton_SEND_DEFAULT;
    CMFCButton m_MFCButton_SEND_RESET;
    CMFCButton m_MFCButton_RAED;
    CMFCButton m_MFCButton_WRITE;
    afx_msg void OnBnClickedButtonConn();
    afx_msg void OnBnClickedButtonEnCmd();
    afx_msg void OnBnClickedButtonScanCom();
    afx_msg void OnBnClickedButtonExportConfig();
    afx_msg void OnBnClickedButtonSendNid();
    afx_msg void OnBnClickedButtonSendAddr();
    afx_msg void OnBnClickedButtonSendEnAddr();
    afx_msg void OnBnClickedButtonSendEncypt();
    afx_msg void OnBnClickedButtonSendRelay();
    afx_msg void OnBnClickedButtonSendTFreq();
    afx_msg void OnBnClickedButtonSendRFreq();
    afx_msg void OnBnClickedButtonSendRfpower();
    afx_msg void OnBnClickedButtonSendRfbw();
    afx_msg void OnBnClickedButtonSendFactor();
    afx_msg void OnBnClickedButtonSendFecRate();
    afx_msg void OnBnClickedButtonSendComBaudrate();
    afx_msg void OnBnClickedButtonSendComFormat();
    afx_msg void OnBnClickedButtonSendDefault();
    afx_msg void OnBnClickedButtonSendReset();
    afx_msg void OnBnClickedButtonRead();
    afx_msg void OnBnClickedButtonWrite();
    afx_msg void OnBnClickedButtonClearLog();
    afx_msg BOOL OnDeviceChange(UINT nEventType, DWORD_PTR dwData);
    CComboBox m_combo_com_sel;
    int UpdateComList();
    typedef unsigned char uchar;
    typedef struct tagWLConfig
    {
        uint32_t RF_T_Freq;                    //Hz
        uint32_t RF_R_Freq;                    //Hz
        uint16_t nChnSpacing;        //kHz
        uint16_t nCycleTime;            //
    //    uchar ModemType;            //    0: FSK,    1: LoRa
        uchar workMode;            //    0, None 1, Uni, 2 Thr, 3 Multi1, 4 Multi2,  5 MulMa
        uchar nChannel;
        uchar bMaster;
        uchar nRadioAddr;
        uchar bEnableMulti;
        uchar Tx_Power;            // dBm        5 - 22 dBm
        uchar LoraBandWidth;        //        [0: 125 kHz, 1: 250 kHz, 2: 500 kHz, 3: Reserved ]
        uchar LoRaFactor;                //        [SF5 .. SF 12]
        uchar LoRaCodingRate;        //        [1 : 4/5,  2: 4/6,  3:  4/7,    4:  4/8 ]
        uint8_t NetWorkAddr;
        uint16_t DeviceAddr;
        uchar bEnableAddr;
        uchar bEnableEncrypt;
        uchar bEnableRelay;
        uchar LoRaPreambleLen;            // 2 - 12
        uchar bAutoPower;                //自动功率
        uchar bAutoReSend;        //自动重发
    //    uchar ;        //
    //    uchar
    }stWLConfig, * pstWLConfig;
    stWLConfig myWLConfig;
};
KwLoRaTool/MyButton.cpp
New file
@@ -0,0 +1,29 @@
#include "pch.h"
#include "MyButton.h"
BEGIN_MESSAGE_MAP(MyButton, CButton)
    ON_WM_CTLCOLOR_REFLECT()
END_MESSAGE_MAP()
MyButton::MyButton()
{
    m_color = RGB(0, 0, 255); // 默认蓝色
}
void MyButton::SetButtonColor(COLORREF color)
{
    m_color = color;
    RedrawWindow();
}
HBRUSH MyButton::CtlColor(CDC* pDC, UINT /*nCtlColor*/)
{
    // TODO:  在此更改 DC 的任何特性
    if (this->IsWindowEnabled()) {
        pDC->SetBkColor(m_color);
    }
    // TODO:  如果不应调用父级的处理程序,则返回非 null 画笔
    return NULL;
}
KwLoRaTool/MyButton.h
New file
@@ -0,0 +1,17 @@
#pragma once
#include <afxwin.h>
class MyButton :   public CButton
{
public:
    MyButton();
    void SetButtonColor(COLORREF color);
public:
    DECLARE_MESSAGE_MAP()
    afx_msg HBRUSH CtlColor(CDC* /*pDC*/, UINT /*nCtlColor*/);
private:
    COLORREF m_color;
public:
};
KwLoRaTool/framework.h
New file
@@ -0,0 +1,49 @@
#pragma once
#ifndef VC_EXTRALEAN
#define VC_EXTRALEAN            // 从 Windows 头中排除极少使用的资料
#endif
#include "targetver.h"
#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS      // 某些 CString 构造函数将是显式的
// 关闭 MFC 的一些常见且经常可放心忽略的隐藏警告消息
#define _AFX_ALL_WARNINGS
#include <afxwin.h>         // MFC 核心组件和标准组件
#include <afxext.h>         // MFC 扩展
#include <afxdisp.h>        // MFC 自动化类
#ifndef _AFX_NO_OLE_SUPPORT
#include <afxdtctl.h>           // MFC 对 Internet Explorer 4 公共控件的支持
#endif
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h>             // MFC 对 Windows 公共控件的支持
#endif // _AFX_NO_AFXCMN_SUPPORT
#include <afxcontrolbars.h>     // MFC 支持功能区和控制条
#ifdef _UNICODE
#if defined _M_IX86
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")
#elif defined _M_X64
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"")
#else
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
#endif
#endif
KwLoRaTool/pch.cpp
New file
@@ -0,0 +1,5 @@
// pch.cpp: 与预编译标头对应的源文件
#include "pch.h"
// 当使用预编译的头时,需要使用此源文件,编译才能成功。
KwLoRaTool/pch.h
New file
@@ -0,0 +1,13 @@
// pch.h: 这是预编译标头文件。
// 下方列出的文件仅编译一次,提高了将来生成的生成性能。
// 这还将影响 IntelliSense 性能,包括代码完成和许多代码浏览功能。
// 但是,如果此处列出的文件中的任何一个在生成之间有更新,它们全部都将被重新编译。
// 请勿在此处添加要频繁更新的文件,这将使得性能优势无效。
#ifndef PCH_H
#define PCH_H
// 添加要在此处预编译的标头
#include "framework.h"
#endif //PCH_H
KwLoRaTool/res/KwLoRaTool.ico
KwLoRaTool/res/KwLoRaTool.rc2
Binary files differ
KwLoRaTool/resource.h
New file
@@ -0,0 +1,64 @@
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ 生成的包含文件。
// 供 KwLoRaTool.rc 使用
//
#define IDM_ABOUTBOX                    0x0010
#define IDD_ABOUTBOX                    100
#define IDS_ABOUTBOX                    101
#define IDD_KWLORATOOL_DIALOG           102
#define IDR_MAINFRAME                   128
#define IDC_COMBO_COM_SEL               1000
#define IDC_COMBO_CONN_BAUDRATE         1001
#define IDC_COMBO_CONN_PARITY           1002
#define IDC_COMBO_CONN_DATABIT          1003
#define IDC_COMBO_CONN_STOPBIT          1004
#define IDC_BUTTON_CONN                 1005
#define IDC_BUTTON_EN_CMD               1006
#define IDC_BUTTON_SCAN_COM             1007
#define IDC_BUTTON_EXPORT_CONFIG        1008
#define IDC_CHECK_AUTO_READ_CFG         1009
#define IDC_EDIT_LOG                    1010
#define IDC_BUTTON_CLEAR_LOG            1011
#define IDC_COMBO_EN_ADDR               1012
#define IDC_COMBO_ENCRYPT               1013
#define IDC_COMBO_RELAY                 1014
#define IDC_COMBO_RF_POWER              1015
#define IDC_COMBO_RF_BW                 1016
#define IDC_COMBO_RF_FACTOR             1017
#define IDC_COMBO_FEC_RATE              1018
#define IDC_COMBO_COM_BAUDRATE          1019
#define IDC_COMBO_COM_FORMAT            1020
#define IDC_EDIT_NET_ID                 1021
#define IDC_EDIT_DEV_ADDR               1022
#define IDC_EDIT_T_FREQ                 1023
#define IDC_EDIT_R_FREQ                 1024
#define IDC_EDIT_SENSITIVE              1025
#define IDC_BUTTON_SEND_NID             1026
#define IDC_BUTTON_SEND_ADDR            1027
#define IDC_BUTTON_SEND_EN_ADDR         1028
#define IDC_BUTTON_SEND_ENCYPT          1029
#define IDC_BUTTON_SEND_RELAY           1030
#define IDC_BUTTON_SEND_T_FREQ          1031
#define IDC_BUTTON_SEND_R_FREQ          1032
#define IDC_BUTTON_SEND_RFPOWER         1033
#define IDC_BUTTON_SEND_RFBW            1034
#define IDC_BUTTON_SEND_FACTOR          1035
#define IDC_BUTTON_SEND_FEC_RATE        1036
#define IDC_BUTTON_SEND_COM_BAUDRATE    1037
#define IDC_BUTTON_SEND_COM_FORMAT      1038
#define IDC_BUTTON_SEND_DEFAULT         1039
#define IDC_BUTTON_SEND_RESET           1040
#define IDC_BUTTON_READ                 1041
#define IDC_BUTTON_WRITE                1042
#define IDC_MFCBUTTON1                  1043
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE        131
#define _APS_NEXT_COMMAND_VALUE         32771
#define _APS_NEXT_CONTROL_VALUE         1044
#define _APS_NEXT_SYMED_VALUE           101
#endif
#endif
KwLoRaTool/targetver.h
New file
@@ -0,0 +1,8 @@
#pragma once
// 包括 SDKDDKVer.h 将定义可用的最高版本的 Windows 平台。
//如果要为以前的 Windows 平台生成应用程序,请包括 WinSDKVer.h,并
// 将 _WIN32_WINNT 宏设置为要支持的平台,然后再包括 SDKDDKVer.h。
#include <SDKDDKVer.h>
LCDDisplay/RCa14640
Binary files differ
MFCApplication1/ChildFrm.cpp
New file
@@ -0,0 +1,101 @@

// ChildFrm.cpp: CChildFrame 类的实现
//
#include "pch.h"
#include "framework.h"
#include "MFCApplication1.h"
#include "ChildFrm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CChildFrame
IMPLEMENT_DYNCREATE(CChildFrame, CMDIChildWnd)
BEGIN_MESSAGE_MAP(CChildFrame, CMDIChildWnd)
    ON_COMMAND(ID_FILE_CLOSE, &CChildFrame::OnFileClose)
    ON_WM_SETFOCUS()
    ON_WM_CREATE()
END_MESSAGE_MAP()
// CChildFrame 构造/析构
CChildFrame::CChildFrame() noexcept
{
    // TODO: 在此添加成员初始化代码
}
CChildFrame::~CChildFrame()
{
}
BOOL CChildFrame::PreCreateWindow(CREATESTRUCT& cs)
{
    // TODO: 在此处通过修改 CREATESTRUCT cs 来修改窗口类或样式
    if( !CMDIChildWnd::PreCreateWindow(cs) )
        return FALSE;
    cs.dwExStyle &= ~WS_EX_CLIENTEDGE;
    cs.lpszClass = AfxRegisterWndClass(0);
    return TRUE;
}
// CChildFrame 诊断
#ifdef _DEBUG
void CChildFrame::AssertValid() const
{
    CMDIChildWnd::AssertValid();
}
void CChildFrame::Dump(CDumpContext& dc) const
{
    CMDIChildWnd::Dump(dc);
}
#endif //_DEBUG
// CChildFrame 消息处理程序
void CChildFrame::OnFileClose()
{
    // 若要关闭框架,只需发送 WM_CLOSE,
    // 这相当于从系统菜单中选择关闭。
    SendMessage(WM_CLOSE);
}
int CChildFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    if (CMDIChildWnd::OnCreate(lpCreateStruct) == -1)
        return -1;
    // 创建一个视图以占用框架的工作区
    if (!m_wndView.Create(nullptr, nullptr, AFX_WS_DEFAULT_VIEW,
        CRect(0, 0, 0, 0), this, AFX_IDW_PANE_FIRST, nullptr))
    {
        TRACE0("未能创建视图窗口\n");
        return -1;
    }
    return 0;
}
void CChildFrame::OnSetFocus(CWnd* pOldWnd)
{
    CMDIChildWnd::OnSetFocus(pOldWnd);
    m_wndView.SetFocus();
}
BOOL CChildFrame::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo)
{
    // 让视图第一次尝试该命令
    if (m_wndView.OnCmdMsg(nID, nCode, pExtra, pHandlerInfo))
        return TRUE;
    // 否则,执行默认处理
    return CMDIChildWnd::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
}
MFCApplication1/ChildFrm.h
New file
@@ -0,0 +1,43 @@

// ChildFrm.h: CChildFrame 类的接口
//
#pragma once
#include "ChildView.h"
class CChildFrame : public CMDIChildWnd
{
    DECLARE_DYNCREATE(CChildFrame)
public:
    CChildFrame() noexcept;
// 特性
protected:
    CSplitterWnd m_wndSplitter;
public:
// 操作
public:
// 重写
    public:
    virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
    virtual BOOL OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo);
// 实现
public:
    // 框架工作区的视图。
    CChildView m_wndView;
    virtual ~CChildFrame();
#ifdef _DEBUG
    virtual void AssertValid() const;
    virtual void Dump(CDumpContext& dc) const;
#endif
// 生成的消息映射函数
protected:
    afx_msg void OnFileClose();
    afx_msg void OnSetFocus(CWnd* pOldWnd);
    afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
    DECLARE_MESSAGE_MAP()
};
MFCApplication1/ChildView.cpp
New file
@@ -0,0 +1,55 @@

// ChildView.cpp: CChildView 类的实现
//
#include "pch.h"
#include "framework.h"
#include "MFCApplication1.h"
#include "ChildView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CChildView
CChildView::CChildView()
{
}
CChildView::~CChildView()
{
}
BEGIN_MESSAGE_MAP(CChildView, CWnd)
    ON_WM_PAINT()
END_MESSAGE_MAP()
// CChildView 消息处理程序
BOOL CChildView::PreCreateWindow(CREATESTRUCT& cs)
{
    if (!CWnd::PreCreateWindow(cs))
        return FALSE;
    cs.dwExStyle |= WS_EX_CLIENTEDGE;
    cs.style &= ~WS_BORDER;
    cs.lpszClass = AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW|CS_DBLCLKS,
        ::LoadCursor(nullptr, IDC_ARROW), reinterpret_cast<HBRUSH>(COLOR_WINDOW+1), nullptr);
    return TRUE;
}
void CChildView::OnPaint()
{
    CPaintDC dc(this); // 用于绘制的设备上下文
    // TODO: 在此处添加消息处理程序代码
    // 不要为绘制消息而调用 CWnd::OnPaint()
}
MFCApplication1/ChildView.h
New file
@@ -0,0 +1,36 @@

// ChildView.h: CChildView 类的接口
//
#pragma once
// CChildView 窗口
class CChildView : public CWnd
{
// 构造
public:
    CChildView();
// 特性
public:
// 操作
public:
// 重写
    protected:
    virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
// 实现
public:
    virtual ~CChildView();
    // 生成的消息映射函数
protected:
    afx_msg void OnPaint();
    DECLARE_MESSAGE_MAP()
};
MFCApplication1/MFCApplication1.cpp
New file
@@ -0,0 +1,186 @@

// MFCApplication1.cpp: 定义应用程序的类行为。
//
#include "pch.h"
#include "framework.h"
#include "afxwinappex.h"
#include "afxdialogex.h"
#include "MFCApplication1.h"
#include "MainFrm.h"
#include "ChildFrm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CMFCApplication1App
BEGIN_MESSAGE_MAP(CMFCApplication1App, CWinApp)
    ON_COMMAND(ID_APP_ABOUT, &CMFCApplication1App::OnAppAbout)
    ON_COMMAND(ID_FILE_NEW, &CMFCApplication1App::OnFileNew)
END_MESSAGE_MAP()
// CMFCApplication1App 构造
CMFCApplication1App::CMFCApplication1App() noexcept
{
    // 支持重新启动管理器
    m_dwRestartManagerSupportFlags = AFX_RESTART_MANAGER_SUPPORT_RESTART;
#ifdef _MANAGED
    // 如果应用程序是利用公共语言运行时支持(/clr)构建的,则:
    //     1) 必须有此附加设置,“重新启动管理器”支持才能正常工作。
    //     2) 在您的项目中,您必须按照生成顺序向 System.Windows.Forms 添加引用。
    System::Windows::Forms::Application::SetUnhandledExceptionMode(System::Windows::Forms::UnhandledExceptionMode::ThrowException);
#endif
    // TODO: 将以下应用程序 ID 字符串替换为唯一的 ID 字符串;建议的字符串格式
    //为 CompanyName.ProductName.SubProduct.VersionInformation
    SetAppID(_T("MFCApplication1.AppID.NoVersion"));
    // TODO:  在此处添加构造代码,
    // 将所有重要的初始化放置在 InitInstance 中
}
// 唯一的 CMFCApplication1App 对象
CMFCApplication1App theApp;
// CMFCApplication1App 初始化
BOOL CMFCApplication1App::InitInstance()
{
    // 如果一个运行在 Windows XP 上的应用程序清单指定要
    // 使用 ComCtl32.dll 版本 6 或更高版本来启用可视化方式,
    //则需要 InitCommonControlsEx()。  否则,将无法创建窗口。
    INITCOMMONCONTROLSEX InitCtrls;
    InitCtrls.dwSize = sizeof(InitCtrls);
    // 将它设置为包括所有要在应用程序中使用的
    // 公共控件类。
    InitCtrls.dwICC = ICC_WIN95_CLASSES;
    InitCommonControlsEx(&InitCtrls);
    CWinApp::InitInstance();
    // 初始化 OLE 库
    if (!AfxOleInit())
    {
        AfxMessageBox(IDP_OLE_INIT_FAILED);
        return FALSE;
    }
    AfxEnableControlContainer();
    EnableTaskbarInteraction(FALSE);
    // 使用 RichEdit 控件需要 AfxInitRichEdit2()
    // AfxInitRichEdit2();
    // 标准初始化
    // 如果未使用这些功能并希望减小
    // 最终可执行文件的大小,则应移除下列
    // 不需要的特定初始化例程
    // 更改用于存储设置的注册表项
    // TODO: 应适当修改该字符串,
    // 例如修改为公司或组织名
    SetRegistryKey(_T("应用程序向导生成的本地应用程序"));
    // 若要创建主窗口,此代码将创建新的框架窗口
    // 对象,然后将其设置为应用程序的主窗口对象
    CMDIFrameWnd* pFrame = new CMainFrame;
    if (!pFrame)
        return FALSE;
    m_pMainWnd = pFrame;
    // 创建主 MDI 框架窗口
    if (!pFrame->LoadFrame(IDR_MAINFRAME))
        return FALSE;
    // 试图加载共享 MDI 菜单和快捷键表
    //TODO: 添加附加成员变量,并加载对
    //    应用程序可能需要的附加菜单类型的调用
    HINSTANCE hInst = AfxGetResourceHandle();
    m_hMDIMenu  = ::LoadMenu(hInst, MAKEINTRESOURCE(IDR_MFCApplication1TYPE));
    m_hMDIAccel = ::LoadAccelerators(hInst, MAKEINTRESOURCE(IDR_MFCApplication1TYPE));
    // 主窗口已初始化,因此显示它并对其进行更新
    pFrame->ShowWindow(m_nCmdShow);
    pFrame->UpdateWindow();
    return TRUE;
}
int CMFCApplication1App::ExitInstance()
{
    //TODO: 处理可能已添加的附加资源
    if (m_hMDIMenu != nullptr)
        FreeResource(m_hMDIMenu);
    if (m_hMDIAccel != nullptr)
        FreeResource(m_hMDIAccel);
    AfxOleTerm(FALSE);
    return CWinApp::ExitInstance();
}
// CMFCApplication1App 消息处理程序
void CMFCApplication1App::OnFileNew()
{
    CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
    // 创建新的 MDI 子窗口
    pFrame->CreateNewChild(
        RUNTIME_CLASS(CChildFrame), IDR_MFCApplication1TYPE, m_hMDIMenu, m_hMDIAccel);
}
// 用于应用程序“关于”菜单项的 CAboutDlg 对话框
class CAboutDlg : public CDialogEx
{
public:
    CAboutDlg() noexcept;
// 对话框数据
#ifdef AFX_DESIGN_TIME
    enum { IDD = IDD_ABOUTBOX };
#endif
protected:
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV 支持
// 实现
protected:
    DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() noexcept : CDialogEx(IDD_ABOUTBOX)
{
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
    CDialogEx::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx)
END_MESSAGE_MAP()
// 用于运行对话框的应用程序命令
void CMFCApplication1App::OnAppAbout()
{
    CAboutDlg aboutDlg;
    aboutDlg.DoModal();
}
// CMFCApplication1App 消息处理程序
MFCApplication1/MFCApplication1.h
New file
@@ -0,0 +1,39 @@

// MFCApplication1.h: MFCApplication1 应用程序的主头文件
//
#pragma once
#ifndef __AFXWIN_H__
    #error "在包含此文件之前包含 'pch.h' 以生成 PCH"
#endif
#include "resource.h"       // 主符号
// CMFCApplication1App:
// 有关此类的实现,请参阅 MFCApplication1.cpp
//
class CMFCApplication1App : public CWinApp
{
public:
    CMFCApplication1App() noexcept;
// 重写
public:
    virtual BOOL InitInstance();
    virtual int ExitInstance();
// 实现
protected:
    HMENU  m_hMDIMenu;
    HACCEL m_hMDIAccel;
public:
    afx_msg void OnAppAbout();
    afx_msg void OnFileNew();
    DECLARE_MESSAGE_MAP()
};
extern CMFCApplication1App theApp;
MFCApplication1/MFCApplication1.rc
Binary files differ
MFCApplication1/MFCApplication1.vcxproj
New file
@@ -0,0 +1,220 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup Label="ProjectConfigurations">
    <ProjectConfiguration Include="Debug|Win32">
      <Configuration>Debug</Configuration>
      <Platform>Win32</Platform>
    </ProjectConfiguration>
    <ProjectConfiguration Include="Release|Win32">
      <Configuration>Release</Configuration>
      <Platform>Win32</Platform>
    </ProjectConfiguration>
    <ProjectConfiguration Include="Debug|x64">
      <Configuration>Debug</Configuration>
      <Platform>x64</Platform>
    </ProjectConfiguration>
    <ProjectConfiguration Include="Release|x64">
      <Configuration>Release</Configuration>
      <Platform>x64</Platform>
    </ProjectConfiguration>
  </ItemGroup>
  <PropertyGroup Label="Globals">
    <VCProjectVersion>16.0</VCProjectVersion>
    <ProjectGuid>{08DF2942-97FC-4EA6-B79C-3E1D4DC969AB}</ProjectGuid>
    <Keyword>MFCProj</Keyword>
    <RootNamespace>MFCApplication1</RootNamespace>
    <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
  </PropertyGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
    <ConfigurationType>Application</ConfigurationType>
    <UseDebugLibraries>true</UseDebugLibraries>
    <PlatformToolset>v142</PlatformToolset>
    <CharacterSet>Unicode</CharacterSet>
    <UseOfMfc>Dynamic</UseOfMfc>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
    <ConfigurationType>Application</ConfigurationType>
    <UseDebugLibraries>false</UseDebugLibraries>
    <PlatformToolset>v142</PlatformToolset>
    <WholeProgramOptimization>true</WholeProgramOptimization>
    <CharacterSet>Unicode</CharacterSet>
    <UseOfMfc>Dynamic</UseOfMfc>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
    <ConfigurationType>Application</ConfigurationType>
    <UseDebugLibraries>true</UseDebugLibraries>
    <PlatformToolset>v142</PlatformToolset>
    <CharacterSet>Unicode</CharacterSet>
    <UseOfMfc>Dynamic</UseOfMfc>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
    <ConfigurationType>Application</ConfigurationType>
    <UseDebugLibraries>false</UseDebugLibraries>
    <PlatformToolset>v142</PlatformToolset>
    <WholeProgramOptimization>true</WholeProgramOptimization>
    <CharacterSet>Unicode</CharacterSet>
    <UseOfMfc>Dynamic</UseOfMfc>
  </PropertyGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
  <ImportGroup Label="ExtensionSettings">
  </ImportGroup>
  <ImportGroup Label="Shared">
  </ImportGroup>
  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  </ImportGroup>
  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  </ImportGroup>
  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  </ImportGroup>
  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  </ImportGroup>
  <PropertyGroup Label="UserMacros" />
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    <LinkIncremental>true</LinkIncremental>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    <LinkIncremental>true</LinkIncremental>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    <LinkIncremental>false</LinkIncremental>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
    <LinkIncremental>false</LinkIncremental>
  </PropertyGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    <ClCompile>
      <PrecompiledHeader>Use</PrecompiledHeader>
      <WarningLevel>Level3</WarningLevel>
      <SDLCheck>true</SDLCheck>
      <PreprocessorDefinitions>_WINDOWS;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
    </ClCompile>
    <Link>
      <SubSystem>Windows</SubSystem>
    </Link>
    <Midl>
      <MkTypLibCompatible>false</MkTypLibCompatible>
      <ValidateAllParameters>true</ValidateAllParameters>
      <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
    </Midl>
    <ResourceCompile>
      <Culture>0x0804</Culture>
      <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
    </ResourceCompile>
  </ItemDefinitionGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    <ClCompile>
      <PrecompiledHeader>Use</PrecompiledHeader>
      <WarningLevel>Level3</WarningLevel>
      <SDLCheck>true</SDLCheck>
      <PreprocessorDefinitions>WIN32;_WINDOWS;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
    </ClCompile>
    <Link>
      <SubSystem>Windows</SubSystem>
    </Link>
    <Midl>
      <MkTypLibCompatible>false</MkTypLibCompatible>
      <ValidateAllParameters>true</ValidateAllParameters>
      <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
    </Midl>
    <ResourceCompile>
      <Culture>0x0804</Culture>
      <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
    </ResourceCompile>
  </ItemDefinitionGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    <ClCompile>
      <PrecompiledHeader>Use</PrecompiledHeader>
      <WarningLevel>Level3</WarningLevel>
      <FunctionLevelLinking>true</FunctionLevelLinking>
      <IntrinsicFunctions>true</IntrinsicFunctions>
      <SDLCheck>true</SDLCheck>
      <PreprocessorDefinitions>WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
    </ClCompile>
    <Link>
      <SubSystem>Windows</SubSystem>
      <EnableCOMDATFolding>true</EnableCOMDATFolding>
      <OptimizeReferences>true</OptimizeReferences>
    </Link>
    <Midl>
      <MkTypLibCompatible>false</MkTypLibCompatible>
      <ValidateAllParameters>true</ValidateAllParameters>
      <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
    </Midl>
    <ResourceCompile>
      <Culture>0x0804</Culture>
      <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
    </ResourceCompile>
  </ItemDefinitionGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
    <ClCompile>
      <PrecompiledHeader>Use</PrecompiledHeader>
      <WarningLevel>Level3</WarningLevel>
      <FunctionLevelLinking>true</FunctionLevelLinking>
      <IntrinsicFunctions>true</IntrinsicFunctions>
      <SDLCheck>true</SDLCheck>
      <PreprocessorDefinitions>_WINDOWS;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
    </ClCompile>
    <Link>
      <SubSystem>Windows</SubSystem>
      <EnableCOMDATFolding>true</EnableCOMDATFolding>
      <OptimizeReferences>true</OptimizeReferences>
    </Link>
    <Midl>
      <MkTypLibCompatible>false</MkTypLibCompatible>
      <ValidateAllParameters>true</ValidateAllParameters>
      <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
    </Midl>
    <ResourceCompile>
      <Culture>0x0804</Culture>
      <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
    </ResourceCompile>
  </ItemDefinitionGroup>
  <ItemGroup>
    <ClInclude Include="ChildFrm.h" />
    <ClInclude Include="ChildView.h" />
    <ClInclude Include="framework.h" />
    <ClInclude Include="MainFrm.h" />
    <ClInclude Include="MFCApplication1.h" />
    <ClInclude Include="pch.h" />
    <ClInclude Include="Resource.h" />
    <ClInclude Include="targetver.h" />
  </ItemGroup>
  <ItemGroup>
    <ClCompile Include="ChildFrm.cpp" />
    <ClCompile Include="ChildView.cpp" />
    <ClCompile Include="MainFrm.cpp" />
    <ClCompile Include="MFCApplication1.cpp" />
    <ClCompile Include="pch.cpp">
      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
    </ClCompile>
  </ItemGroup>
  <ItemGroup>
    <ResourceCompile Include="MFCApplication1.rc" />
  </ItemGroup>
  <ItemGroup>
    <None Include="res\MFCApplication1.rc2" />
  </ItemGroup>
  <ItemGroup>
    <Image Include="res\MFCApplication1.ico" />
    <Image Include="res\Toolbar.bmp" />
  </ItemGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
  <ImportGroup Label="ExtensionTargets">
  </ImportGroup>
</Project>
MFCApplication1/MFCApplication1.vcxproj.filters
New file
@@ -0,0 +1,78 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup>
    <Filter Include="源文件">
      <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
      <Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
    </Filter>
    <Filter Include="头文件">
      <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
      <Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
    </Filter>
    <Filter Include="资源文件">
      <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
      <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
    </Filter>
  </ItemGroup>
  <ItemGroup>
    <ClInclude Include="MFCApplication1.h">
      <Filter>头文件</Filter>
    </ClInclude>
    <ClInclude Include="framework.h">
      <Filter>头文件</Filter>
    </ClInclude>
    <ClInclude Include="targetver.h">
      <Filter>头文件</Filter>
    </ClInclude>
    <ClInclude Include="MainFrm.h">
      <Filter>头文件</Filter>
    </ClInclude>
    <ClInclude Include="ChildFrm.h">
      <Filter>头文件</Filter>
    </ClInclude>
    <ClInclude Include="ChildView.h">
      <Filter>头文件</Filter>
    </ClInclude>
    <ClInclude Include="Resource.h">
      <Filter>头文件</Filter>
    </ClInclude>
    <ClInclude Include="pch.h">
      <Filter>头文件</Filter>
    </ClInclude>
  </ItemGroup>
  <ItemGroup>
    <ClCompile Include="MFCApplication1.cpp">
      <Filter>源文件</Filter>
    </ClCompile>
    <ClCompile Include="MainFrm.cpp">
      <Filter>源文件</Filter>
    </ClCompile>
    <ClCompile Include="ChildFrm.cpp">
      <Filter>源文件</Filter>
    </ClCompile>
    <ClCompile Include="ChildView.cpp">
      <Filter>源文件</Filter>
    </ClCompile>
    <ClCompile Include="pch.cpp">
      <Filter>源文件</Filter>
    </ClCompile>
  </ItemGroup>
  <ItemGroup>
    <ResourceCompile Include="MFCApplication1.rc">
      <Filter>资源文件</Filter>
    </ResourceCompile>
  </ItemGroup>
  <ItemGroup>
    <None Include="res\MFCApplication1.rc2">
      <Filter>资源文件</Filter>
    </None>
  </ItemGroup>
  <ItemGroup>
    <Image Include="res\MFCApplication1.ico">
      <Filter>资源文件</Filter>
    </Image>
    <Image Include="res\Toolbar.bmp">
      <Filter>资源文件</Filter>
    </Image>
  </ItemGroup>
</Project>
MFCApplication1/MainFrm.cpp
New file
@@ -0,0 +1,96 @@

// MainFrm.cpp: CMainFrame 类的实现
//
#include "pch.h"
#include "framework.h"
#include "MFCApplication1.h"
#include "MainFrm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CMainFrame
IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd)
BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
    ON_WM_CREATE()
END_MESSAGE_MAP()
static UINT indicators[] =
{
    ID_SEPARATOR,           // 状态行指示器
    ID_INDICATOR_CAPS,
    ID_INDICATOR_NUM,
    ID_INDICATOR_SCRL,
};
// CMainFrame 构造/析构
CMainFrame::CMainFrame() noexcept
{
    // TODO: 在此添加成员初始化代码
}
CMainFrame::~CMainFrame()
{
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
        return -1;
    if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
        !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
    {
        TRACE0("未能创建工具栏\n");
        return -1;      // 未能创建
    }
    if (!m_wndStatusBar.Create(this))
    {
        TRACE0("未能创建状态栏\n");
        return -1;      // 未能创建
    }
    m_wndStatusBar.SetIndicators(indicators, sizeof(indicators)/sizeof(UINT));
    // TODO: 如果不需要可停靠工具栏,则删除这三行
    m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
    EnableDocking(CBRS_ALIGN_ANY);
    DockControlBar(&m_wndToolBar);
    return 0;
}
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
    if( !CMDIFrameWnd::PreCreateWindow(cs) )
        return FALSE;
    // TODO: 在此处通过修改
    //  CREATESTRUCT cs 来修改窗口类或样式
    return TRUE;
}
// CMainFrame 诊断
#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
    CMDIFrameWnd::AssertValid();
}
void CMainFrame::Dump(CDumpContext& dc) const
{
    CMDIFrameWnd::Dump(dc);
}
#endif //_DEBUG
// CMainFrame 消息处理程序
MFCApplication1/MainFrm.h
New file
@@ -0,0 +1,42 @@

// MainFrm.h: CMainFrame 类的接口
//
#pragma once
class CMainFrame : public CMDIFrameWnd
{
    DECLARE_DYNAMIC(CMainFrame)
public:
    CMainFrame() noexcept;
// 特性
public:
// 操作
public:
// 重写
public:
    virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
// 实现
public:
    virtual ~CMainFrame();
#ifdef _DEBUG
    virtual void AssertValid() const;
    virtual void Dump(CDumpContext& dc) const;
#endif
protected:  // 控件条嵌入成员
    CToolBar          m_wndToolBar;
    CStatusBar        m_wndStatusBar;
// 生成的消息映射函数
protected:
    afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
    DECLARE_MESSAGE_MAP()
};
MFCApplication1/Resource.h
New file
@@ -0,0 +1,20 @@
//{{NO_DEPENDENCIES}}
// 生成的 Microsoft Visual C++ 包含文件。
// 由 MFCApplication1.rc 使用
//
#define IDD_ABOUTBOX                100
#define IDP_OLE_INIT_FAILED            100
#define IDR_MAINFRAME                128
#define IDR_MFCApplication1TYPE                130
#define ID_WINDOW_MANAGER            131
// 新对象的下一组默认值
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE    310
#define _APS_NEXT_CONTROL_VALUE        1000
#define _APS_NEXT_SYMED_VALUE        310
#define _APS_NEXT_COMMAND_VALUE        32771
#endif
#endif
MFCApplication1/framework.h
New file
@@ -0,0 +1,49 @@
#pragma once
#ifndef VC_EXTRALEAN
#define VC_EXTRALEAN            // 从 Windows 头中排除极少使用的资料
#endif
#include "targetver.h"
#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS      // 某些 CString 构造函数将是显式的
// 关闭 MFC 的一些常见且经常可放心忽略的隐藏警告消息
#define _AFX_ALL_WARNINGS
#include <afxwin.h>         // MFC 核心组件和标准组件
#include <afxext.h>         // MFC 扩展
#include <afxdisp.h>        // MFC 自动化类
#ifndef _AFX_NO_OLE_SUPPORT
#include <afxdtctl.h>           // MFC 对 Internet Explorer 4 公共控件的支持
#endif
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h>             // MFC 对 Windows 公共控件的支持
#endif // _AFX_NO_AFXCMN_SUPPORT
#include <afxcontrolbars.h>     // MFC 支持功能区和控制条
#ifdef _UNICODE
#if defined _M_IX86
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")
#elif defined _M_X64
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"")
#else
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
#endif
#endif
MFCApplication1/pch.cpp
New file
@@ -0,0 +1,5 @@
// pch.cpp: 与预编译标头对应的源文件
#include "pch.h"
// 当使用预编译的头时,需要使用此源文件,编译才能成功。
MFCApplication1/pch.h
New file
@@ -0,0 +1,13 @@
// pch.h: 这是预编译标头文件。
// 下方列出的文件仅编译一次,提高了将来生成的生成性能。
// 这还将影响 IntelliSense 性能,包括代码完成和许多代码浏览功能。
// 但是,如果此处列出的文件中的任何一个在生成之间有更新,它们全部都将被重新编译。
// 请勿在此处添加要频繁更新的文件,这将使得性能优势无效。
#ifndef PCH_H
#define PCH_H
// 添加要在此处预编译的标头
#include "framework.h"
#endif //PCH_H
MFCApplication1/res/MFCApplication1.ico
MFCApplication1/res/MFCApplication1.rc2
Binary files differ
MFCApplication1/res/Toolbar.bmp
MFCApplication1/targetver.h
New file
@@ -0,0 +1,8 @@
#pragma once
// 包括 SDKDDKVer.h 将定义可用的最高版本的 Windows 平台。
//如果要为以前的 Windows 平台生成应用程序,请包括 WinSDKVer.h,并
// 将 _WIN32_WINNT 宏设置为要支持的平台,然后再包括 SDKDDKVer.h。
#include <SDKDDKVer.h>
MFCMView/ChildFrm.cpp
New file
@@ -0,0 +1,104 @@

// ChildFrm.cpp: CChildFrame 类的实现
//
#include "pch.h"
#include "framework.h"
#include "MFCMView.h"
#include "ChildFrm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CChildFrame
IMPLEMENT_DYNCREATE(CChildFrame, CMDIChildWndEx)
BEGIN_MESSAGE_MAP(CChildFrame, CMDIChildWndEx)
    ON_COMMAND(ID_FILE_CLOSE, &CChildFrame::OnFileClose)
    ON_WM_SETFOCUS()
    ON_WM_CREATE()
END_MESSAGE_MAP()
// CChildFrame 构造/析构
CChildFrame::CChildFrame() noexcept
{
    // TODO: 在此添加成员初始化代码
}
CChildFrame::~CChildFrame()
{
}
BOOL CChildFrame::PreCreateWindow(CREATESTRUCT& cs)
{
    // TODO: 在此处通过修改 CREATESTRUCT cs 来修改窗口类或样式
    if( !CMDIChildWndEx::PreCreateWindow(cs) )
        return FALSE;
    cs.style = WS_CHILD | WS_VISIBLE | WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU
        | FWS_ADDTOTITLE | WS_THICKFRAME;
    cs.dwExStyle &= ~WS_EX_CLIENTEDGE;
    cs.lpszClass = AfxRegisterWndClass(0);
    return TRUE;
}
// CChildFrame 诊断
#ifdef _DEBUG
void CChildFrame::AssertValid() const
{
    CMDIChildWndEx::AssertValid();
}
void CChildFrame::Dump(CDumpContext& dc) const
{
    CMDIChildWndEx::Dump(dc);
}
#endif //_DEBUG
// CChildFrame 消息处理程序
void CChildFrame::OnFileClose()
{
    // 若要关闭框架,只需发送 WM_CLOSE,
    // 这相当于从系统菜单中选择关闭。
    SendMessage(WM_CLOSE);
}
int CChildFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    if (CMDIChildWndEx::OnCreate(lpCreateStruct) == -1)
        return -1;
    // 创建一个视图以占用框架的工作区
    if (!m_wndView.Create(nullptr, nullptr, AFX_WS_DEFAULT_VIEW,
        CRect(0, 0, 0, 0), this, AFX_IDW_PANE_FIRST, nullptr))
    {
        TRACE0("未能创建视图窗口\n");
        return -1;
    }
    return 0;
}
void CChildFrame::OnSetFocus(CWnd* pOldWnd)
{
    CMDIChildWndEx::OnSetFocus(pOldWnd);
    m_wndView.SetFocus();
}
BOOL CChildFrame::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo)
{
    // 让视图第一次尝试该命令
    if (m_wndView.OnCmdMsg(nID, nCode, pExtra, pHandlerInfo))
        return TRUE;
    // 否则,执行默认处理
    return CMDIChildWndEx::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
}
MFCMView/ChildFrm.h
New file
@@ -0,0 +1,43 @@

// ChildFrm.h: CChildFrame 类的接口
//
#pragma once
#include "ChildView.h"
class CChildFrame : public CMDIChildWndEx
{
    DECLARE_DYNCREATE(CChildFrame)
public:
    CChildFrame() noexcept;
// 特性
protected:
    CSplitterWndEx m_wndSplitter;
public:
// 操作
public:
// 重写
    public:
    virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
    virtual BOOL OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo);
// 实现
public:
    // 框架工作区的视图。
    CChildView m_wndView;
    virtual ~CChildFrame();
#ifdef _DEBUG
    virtual void AssertValid() const;
    virtual void Dump(CDumpContext& dc) const;
#endif
// 生成的消息映射函数
protected:
    afx_msg void OnFileClose();
    afx_msg void OnSetFocus(CWnd* pOldWnd);
    afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
    DECLARE_MESSAGE_MAP()
};
MFCMView/ChildView.cpp
New file
@@ -0,0 +1,55 @@

// ChildView.cpp: CChildView 类的实现
//
#include "pch.h"
#include "framework.h"
#include "MFCMView.h"
#include "ChildView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CChildView
CChildView::CChildView()
{
}
CChildView::~CChildView()
{
}
BEGIN_MESSAGE_MAP(CChildView, CWnd)
    ON_WM_PAINT()
END_MESSAGE_MAP()
// CChildView 消息处理程序
BOOL CChildView::PreCreateWindow(CREATESTRUCT& cs)
{
    if (!CWnd::PreCreateWindow(cs))
        return FALSE;
    cs.dwExStyle |= WS_EX_CLIENTEDGE;
    cs.style &= ~WS_BORDER;
    cs.lpszClass = AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW|CS_DBLCLKS,
        ::LoadCursor(nullptr, IDC_ARROW), reinterpret_cast<HBRUSH>(COLOR_WINDOW+1), nullptr);
    return TRUE;
}
void CChildView::OnPaint()
{
    CPaintDC dc(this); // 用于绘制的设备上下文
    // TODO: 在此处添加消息处理程序代码
    // 不要为绘制消息而调用 CWnd::OnPaint()
}
MFCMView/ChildView.h
New file
@@ -0,0 +1,36 @@

// ChildView.h: CChildView 类的接口
//
#pragma once
// CChildView 窗口
class CChildView : public CWnd
{
// 构造
public:
    CChildView();
// 特性
public:
// 操作
public:
// 重写
    protected:
    virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
// 实现
public:
    virtual ~CChildView();
    // 生成的消息映射函数
protected:
    afx_msg void OnPaint();
    DECLARE_MESSAGE_MAP()
};
MFCMView/MFCMView.cpp
New file
@@ -0,0 +1,188 @@

// MFCMView.cpp: 定义应用程序的类行为。
//
#include "pch.h"
#include "framework.h"
#include "afxwinappex.h"
#include "afxdialogex.h"
#include "MFCMView.h"
#include "MainFrm.h"
#include "ChildFrm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CMFCMViewApp
BEGIN_MESSAGE_MAP(CMFCMViewApp, CWinAppEx)
    ON_COMMAND(ID_APP_ABOUT, &CMFCMViewApp::OnAppAbout)
    ON_COMMAND(ID_FILE_NEW, &CMFCMViewApp::OnFileNew)
END_MESSAGE_MAP()
// CMFCMViewApp 构造
CMFCMViewApp::CMFCMViewApp() noexcept
{
    // 支持重新启动管理器
    m_dwRestartManagerSupportFlags = AFX_RESTART_MANAGER_SUPPORT_ALL_ASPECTS;
#ifdef _MANAGED
    // 如果应用程序是利用公共语言运行时支持(/clr)构建的,则:
    //     1) 必须有此附加设置,“重新启动管理器”支持才能正常工作。
    //     2) 在您的项目中,您必须按照生成顺序向 System.Windows.Forms 添加引用。
    System::Windows::Forms::Application::SetUnhandledExceptionMode(System::Windows::Forms::UnhandledExceptionMode::ThrowException);
#endif
    // TODO: 将以下应用程序 ID 字符串替换为唯一的 ID 字符串;建议的字符串格式
    //为 CompanyName.ProductName.SubProduct.VersionInformation
    SetAppID(_T("MFCMView.AppID.NoVersion"));
    // TODO:  在此处添加构造代码,
    // 将所有重要的初始化放置在 InitInstance 中
}
// 唯一的 CMFCMViewApp 对象
CMFCMViewApp theApp;
// CMFCMViewApp 初始化
BOOL CMFCMViewApp::InitInstance()
{
    // 如果一个运行在 Windows XP 上的应用程序清单指定要
    // 使用 ComCtl32.dll 版本 6 或更高版本来启用可视化方式,
    //则需要 InitCommonControlsEx()。  否则,将无法创建窗口。
    INITCOMMONCONTROLSEX InitCtrls;
    InitCtrls.dwSize = sizeof(InitCtrls);
    // 将它设置为包括所有要在应用程序中使用的
    // 公共控件类。
    InitCtrls.dwICC = ICC_WIN95_CLASSES;
    InitCommonControlsEx(&InitCtrls);
    CWinAppEx::InitInstance();
    // 初始化 OLE 库
    if (!AfxOleInit())
    {
        AfxMessageBox(IDP_OLE_INIT_FAILED);
        return FALSE;
    }
    AfxEnableControlContainer();
    EnableTaskbarInteraction();
    // 使用 RichEdit 控件需要 AfxInitRichEdit2()
    // AfxInitRichEdit2();
    // 标准初始化
    // 如果未使用这些功能并希望减小
    // 最终可执行文件的大小,则应移除下列
    // 不需要的特定初始化例程
    // 更改用于存储设置的注册表项
    // TODO: 应适当修改该字符串,
    // 例如修改为公司或组织名
    SetRegistryKey(_T("应用程序向导生成的本地应用程序"));
    // 若要创建主窗口,此代码将创建新的框架窗口
    // 对象,然后将其设置为应用程序的主窗口对象
    CMDIFrameWnd* pFrame = new CMainFrame;
    if (!pFrame)
        return FALSE;
    m_pMainWnd = pFrame;
    // 创建主 MDI 框架窗口
    if (!pFrame->LoadFrame(IDR_MAINFRAME))
        return FALSE;
    // 试图加载共享 MDI 菜单和快捷键表
    //TODO: 添加附加成员变量,并加载对
    //    应用程序可能需要的附加菜单类型的调用
    HINSTANCE hInst = AfxGetResourceHandle();
    m_hMDIMenu  = ::LoadMenu(hInst, MAKEINTRESOURCE(IDR_MFCMViewTYPE));
    m_hMDIAccel = ::LoadAccelerators(hInst, MAKEINTRESOURCE(IDR_MFCMViewTYPE));
    // 主窗口已初始化,因此显示它并对其进行更新
    pFrame->ShowWindow(m_nCmdShow);
    pFrame->UpdateWindow();
    return TRUE;
}
int CMFCMViewApp::ExitInstance()
{
    //TODO: 处理可能已添加的附加资源
    if (m_hMDIMenu != nullptr)
        FreeResource(m_hMDIMenu);
    if (m_hMDIAccel != nullptr)
        FreeResource(m_hMDIAccel);
    AfxOleTerm(FALSE);
    return CWinAppEx::ExitInstance();
}
// CMFCMViewApp 消息处理程序
void CMFCMViewApp::OnFileNew()
{
    CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
    pFrame->LockWindowUpdate();
    // 创建新的 MDI 子窗口
    pFrame->CreateNewChild(
        RUNTIME_CLASS(CChildFrame), IDR_MFCMViewTYPE, m_hMDIMenu, m_hMDIAccel);
    pFrame->UnlockWindowUpdate();
}
// 用于应用程序“关于”菜单项的 CAboutDlg 对话框
class CAboutDlg : public CDialogEx
{
public:
    CAboutDlg() noexcept;
// 对话框数据
#ifdef AFX_DESIGN_TIME
    enum { IDD = IDD_ABOUTBOX };
#endif
protected:
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV 支持
// 实现
protected:
    DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() noexcept : CDialogEx(IDD_ABOUTBOX)
{
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
    CDialogEx::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx)
END_MESSAGE_MAP()
// 用于运行对话框的应用程序命令
void CMFCMViewApp::OnAppAbout()
{
    CAboutDlg aboutDlg;
    aboutDlg.DoModal();
}
// CMFCMViewApp 消息处理程序
MFCMView/MFCMView.h
New file
@@ -0,0 +1,39 @@

// MFCMView.h: MFCMView 应用程序的主头文件
//
#pragma once
#ifndef __AFXWIN_H__
    #error "在包含此文件之前包含 'pch.h' 以生成 PCH"
#endif
#include "resource.h"       // 主符号
// CMFCMViewApp:
// 有关此类的实现,请参阅 MFCMView.cpp
//
class CMFCMViewApp : public CWinAppEx
{
public:
    CMFCMViewApp() noexcept;
// 重写
public:
    virtual BOOL InitInstance();
    virtual int ExitInstance();
// 实现
protected:
    HMENU  m_hMDIMenu;
    HACCEL m_hMDIAccel;
public:
    afx_msg void OnAppAbout();
    afx_msg void OnFileNew();
    DECLARE_MESSAGE_MAP()
};
extern CMFCMViewApp theApp;
MFCMView/MFCMView.rc
Binary files differ
MFCMView/MFCMView.vcxproj
New file
@@ -0,0 +1,220 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup Label="ProjectConfigurations">
    <ProjectConfiguration Include="Debug|Win32">
      <Configuration>Debug</Configuration>
      <Platform>Win32</Platform>
    </ProjectConfiguration>
    <ProjectConfiguration Include="Release|Win32">
      <Configuration>Release</Configuration>
      <Platform>Win32</Platform>
    </ProjectConfiguration>
    <ProjectConfiguration Include="Debug|x64">
      <Configuration>Debug</Configuration>
      <Platform>x64</Platform>
    </ProjectConfiguration>
    <ProjectConfiguration Include="Release|x64">
      <Configuration>Release</Configuration>
      <Platform>x64</Platform>
    </ProjectConfiguration>
  </ItemGroup>
  <PropertyGroup Label="Globals">
    <VCProjectVersion>16.0</VCProjectVersion>
    <ProjectGuid>{75E31345-9F86-46BE-B0A8-DAEF59D7841B}</ProjectGuid>
    <Keyword>MFCProj</Keyword>
    <RootNamespace>MFCMView</RootNamespace>
    <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
  </PropertyGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
    <ConfigurationType>Application</ConfigurationType>
    <UseDebugLibraries>true</UseDebugLibraries>
    <PlatformToolset>v142</PlatformToolset>
    <CharacterSet>Unicode</CharacterSet>
    <UseOfMfc>Dynamic</UseOfMfc>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
    <ConfigurationType>Application</ConfigurationType>
    <UseDebugLibraries>false</UseDebugLibraries>
    <PlatformToolset>v142</PlatformToolset>
    <WholeProgramOptimization>true</WholeProgramOptimization>
    <CharacterSet>Unicode</CharacterSet>
    <UseOfMfc>Dynamic</UseOfMfc>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
    <ConfigurationType>Application</ConfigurationType>
    <UseDebugLibraries>true</UseDebugLibraries>
    <PlatformToolset>v142</PlatformToolset>
    <CharacterSet>Unicode</CharacterSet>
    <UseOfMfc>Dynamic</UseOfMfc>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
    <ConfigurationType>Application</ConfigurationType>
    <UseDebugLibraries>false</UseDebugLibraries>
    <PlatformToolset>v142</PlatformToolset>
    <WholeProgramOptimization>true</WholeProgramOptimization>
    <CharacterSet>Unicode</CharacterSet>
    <UseOfMfc>Dynamic</UseOfMfc>
  </PropertyGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
  <ImportGroup Label="ExtensionSettings">
  </ImportGroup>
  <ImportGroup Label="Shared">
  </ImportGroup>
  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  </ImportGroup>
  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  </ImportGroup>
  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  </ImportGroup>
  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  </ImportGroup>
  <PropertyGroup Label="UserMacros" />
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    <LinkIncremental>true</LinkIncremental>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    <LinkIncremental>true</LinkIncremental>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    <LinkIncremental>false</LinkIncremental>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
    <LinkIncremental>false</LinkIncremental>
  </PropertyGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    <ClCompile>
      <PrecompiledHeader>Use</PrecompiledHeader>
      <WarningLevel>Level3</WarningLevel>
      <SDLCheck>true</SDLCheck>
      <PreprocessorDefinitions>_WINDOWS;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
    </ClCompile>
    <Link>
      <SubSystem>Windows</SubSystem>
    </Link>
    <Midl>
      <MkTypLibCompatible>false</MkTypLibCompatible>
      <ValidateAllParameters>true</ValidateAllParameters>
      <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
    </Midl>
    <ResourceCompile>
      <Culture>0x0804</Culture>
      <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
    </ResourceCompile>
  </ItemDefinitionGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    <ClCompile>
      <PrecompiledHeader>Use</PrecompiledHeader>
      <WarningLevel>Level3</WarningLevel>
      <SDLCheck>true</SDLCheck>
      <PreprocessorDefinitions>WIN32;_WINDOWS;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
    </ClCompile>
    <Link>
      <SubSystem>Windows</SubSystem>
    </Link>
    <Midl>
      <MkTypLibCompatible>false</MkTypLibCompatible>
      <ValidateAllParameters>true</ValidateAllParameters>
      <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
    </Midl>
    <ResourceCompile>
      <Culture>0x0804</Culture>
      <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
    </ResourceCompile>
  </ItemDefinitionGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    <ClCompile>
      <PrecompiledHeader>Use</PrecompiledHeader>
      <WarningLevel>Level3</WarningLevel>
      <FunctionLevelLinking>true</FunctionLevelLinking>
      <IntrinsicFunctions>true</IntrinsicFunctions>
      <SDLCheck>true</SDLCheck>
      <PreprocessorDefinitions>WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
    </ClCompile>
    <Link>
      <SubSystem>Windows</SubSystem>
      <EnableCOMDATFolding>true</EnableCOMDATFolding>
      <OptimizeReferences>true</OptimizeReferences>
    </Link>
    <Midl>
      <MkTypLibCompatible>false</MkTypLibCompatible>
      <ValidateAllParameters>true</ValidateAllParameters>
      <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
    </Midl>
    <ResourceCompile>
      <Culture>0x0804</Culture>
      <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
    </ResourceCompile>
  </ItemDefinitionGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
    <ClCompile>
      <PrecompiledHeader>Use</PrecompiledHeader>
      <WarningLevel>Level3</WarningLevel>
      <FunctionLevelLinking>true</FunctionLevelLinking>
      <IntrinsicFunctions>true</IntrinsicFunctions>
      <SDLCheck>true</SDLCheck>
      <PreprocessorDefinitions>_WINDOWS;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
    </ClCompile>
    <Link>
      <SubSystem>Windows</SubSystem>
      <EnableCOMDATFolding>true</EnableCOMDATFolding>
      <OptimizeReferences>true</OptimizeReferences>
    </Link>
    <Midl>
      <MkTypLibCompatible>false</MkTypLibCompatible>
      <ValidateAllParameters>true</ValidateAllParameters>
      <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
    </Midl>
    <ResourceCompile>
      <Culture>0x0804</Culture>
      <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
    </ResourceCompile>
  </ItemDefinitionGroup>
  <ItemGroup>
    <ClInclude Include="ChildFrm.h" />
    <ClInclude Include="ChildView.h" />
    <ClInclude Include="framework.h" />
    <ClInclude Include="MainFrm.h" />
    <ClInclude Include="MFCMView.h" />
    <ClInclude Include="pch.h" />
    <ClInclude Include="Resource.h" />
    <ClInclude Include="targetver.h" />
  </ItemGroup>
  <ItemGroup>
    <ClCompile Include="ChildFrm.cpp" />
    <ClCompile Include="ChildView.cpp" />
    <ClCompile Include="MainFrm.cpp" />
    <ClCompile Include="MFCMView.cpp" />
    <ClCompile Include="pch.cpp">
      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
    </ClCompile>
  </ItemGroup>
  <ItemGroup>
    <ResourceCompile Include="MFCMView.rc" />
  </ItemGroup>
  <ItemGroup>
    <None Include="res\MFCMView.rc2" />
  </ItemGroup>
  <ItemGroup>
    <Image Include="res\MFCMView.ico" />
    <Image Include="res\Toolbar.bmp" />
  </ItemGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
  <ImportGroup Label="ExtensionTargets">
  </ImportGroup>
</Project>
MFCMView/MFCMView.vcxproj.filters
New file
@@ -0,0 +1,78 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup>
    <Filter Include="源文件">
      <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
      <Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
    </Filter>
    <Filter Include="头文件">
      <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
      <Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
    </Filter>
    <Filter Include="资源文件">
      <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
      <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
    </Filter>
  </ItemGroup>
  <ItemGroup>
    <ClInclude Include="MFCMView.h">
      <Filter>头文件</Filter>
    </ClInclude>
    <ClInclude Include="framework.h">
      <Filter>头文件</Filter>
    </ClInclude>
    <ClInclude Include="targetver.h">
      <Filter>头文件</Filter>
    </ClInclude>
    <ClInclude Include="MainFrm.h">
      <Filter>头文件</Filter>
    </ClInclude>
    <ClInclude Include="ChildFrm.h">
      <Filter>头文件</Filter>
    </ClInclude>
    <ClInclude Include="ChildView.h">
      <Filter>头文件</Filter>
    </ClInclude>
    <ClInclude Include="Resource.h">
      <Filter>头文件</Filter>
    </ClInclude>
    <ClInclude Include="pch.h">
      <Filter>头文件</Filter>
    </ClInclude>
  </ItemGroup>
  <ItemGroup>
    <ClCompile Include="MFCMView.cpp">
      <Filter>源文件</Filter>
    </ClCompile>
    <ClCompile Include="MainFrm.cpp">
      <Filter>源文件</Filter>
    </ClCompile>
    <ClCompile Include="ChildFrm.cpp">
      <Filter>源文件</Filter>
    </ClCompile>
    <ClCompile Include="ChildView.cpp">
      <Filter>源文件</Filter>
    </ClCompile>
    <ClCompile Include="pch.cpp">
      <Filter>源文件</Filter>
    </ClCompile>
  </ItemGroup>
  <ItemGroup>
    <ResourceCompile Include="MFCMView.rc">
      <Filter>资源文件</Filter>
    </ResourceCompile>
  </ItemGroup>
  <ItemGroup>
    <None Include="res\MFCMView.rc2">
      <Filter>资源文件</Filter>
    </None>
  </ItemGroup>
  <ItemGroup>
    <Image Include="res\MFCMView.ico">
      <Filter>资源文件</Filter>
    </Image>
    <Image Include="res\Toolbar.bmp">
      <Filter>资源文件</Filter>
    </Image>
  </ItemGroup>
</Project>
MFCMView/MainFrm.cpp
New file
@@ -0,0 +1,108 @@

// MainFrm.cpp: CMainFrame 类的实现
//
#include "pch.h"
#include "framework.h"
#include "MFCMView.h"
#include "MainFrm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CMainFrame
IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWndEx)
BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWndEx)
    ON_WM_CREATE()
END_MESSAGE_MAP()
static UINT indicators[] =
{
    ID_SEPARATOR,           // 状态行指示器
    ID_INDICATOR_CAPS,
    ID_INDICATOR_NUM,
    ID_INDICATOR_SCRL,
};
// CMainFrame 构造/析构
CMainFrame::CMainFrame() noexcept
{
    // TODO: 在此添加成员初始化代码
}
CMainFrame::~CMainFrame()
{
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    if (CMDIFrameWndEx::OnCreate(lpCreateStruct) == -1)
        return -1;
    CMDITabInfo mdiTabParams;
    mdiTabParams.m_style = CMFCTabCtrl::STYLE_3D_ONENOTE; // 其他可用样式...
    mdiTabParams.m_bActiveTabCloseButton = TRUE;      // 设置为 FALSE 会将关闭按钮放置在选项卡区域的右侧
    mdiTabParams.m_bTabIcons = FALSE;    // 设置为 TRUE 将在 MDI 选项卡上启用文档图标
    mdiTabParams.m_bAutoColor = TRUE;    // 设置为 FALSE 将禁用 MDI 选项卡的自动着色
    mdiTabParams.m_bDocumentMenu = TRUE; // 在选项卡区域的右边缘启用文档菜单
    EnableMDITabbedGroups(TRUE, mdiTabParams);
    if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
        !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
    {
        TRACE0("未能创建工具栏\n");
        return -1;      // 未能创建
    }
    if (!m_wndStatusBar.Create(this))
    {
        TRACE0("未能创建状态栏\n");
        return -1;      // 未能创建
    }
    m_wndStatusBar.SetIndicators(indicators, sizeof(indicators)/sizeof(UINT));
    // TODO: 如果不需要可停靠工具栏,则删除这三行
    m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
    EnableDocking(CBRS_ALIGN_ANY);
    DockControlBar(&m_wndToolBar);
    // 将文档名和应用程序名称在窗口标题栏上的顺序进行交换。这
    // 将改进任务栏的可用性,因为显示的文档名带有缩略图。
    ModifyStyle(0, FWS_PREFIXTITLE);
    return 0;
}
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
    if( !CMDIFrameWndEx::PreCreateWindow(cs) )
        return FALSE;
    // TODO: 在此处通过修改
    //  CREATESTRUCT cs 来修改窗口类或样式
    return TRUE;
}
// CMainFrame 诊断
#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
    CMDIFrameWndEx::AssertValid();
}
void CMainFrame::Dump(CDumpContext& dc) const
{
    CMDIFrameWndEx::Dump(dc);
}
#endif //_DEBUG
// CMainFrame 消息处理程序
MFCMView/MainFrm.h
New file
@@ -0,0 +1,42 @@

// MainFrm.h: CMainFrame 类的接口
//
#pragma once
class CMainFrame : public CMDIFrameWndEx
{
    DECLARE_DYNAMIC(CMainFrame)
public:
    CMainFrame() noexcept;
// 特性
public:
// 操作
public:
// 重写
public:
    virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
// 实现
public:
    virtual ~CMainFrame();
#ifdef _DEBUG
    virtual void AssertValid() const;
    virtual void Dump(CDumpContext& dc) const;
#endif
protected:  // 控件条嵌入成员
    CToolBar          m_wndToolBar;
    CStatusBar        m_wndStatusBar;
// 生成的消息映射函数
protected:
    afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
    DECLARE_MESSAGE_MAP()
};
MFCMView/Resource.h
New file
@@ -0,0 +1,20 @@
//{{NO_DEPENDENCIES}}
// 生成的 Microsoft Visual C++ 包含文件。
// 由 MFCMView.rc 使用
//
#define IDD_ABOUTBOX                100
#define IDP_OLE_INIT_FAILED            100
#define IDR_MAINFRAME                128
#define IDR_MFCMViewTYPE                130
#define ID_WINDOW_MANAGER            131
// 新对象的下一组默认值
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE    310
#define _APS_NEXT_CONTROL_VALUE        1000
#define _APS_NEXT_SYMED_VALUE        310
#define _APS_NEXT_COMMAND_VALUE        32771
#endif
#endif
MFCMView/framework.h
New file
@@ -0,0 +1,49 @@
#pragma once
#ifndef VC_EXTRALEAN
#define VC_EXTRALEAN            // 从 Windows 头中排除极少使用的资料
#endif
#include "targetver.h"
#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS      // 某些 CString 构造函数将是显式的
// 关闭 MFC 的一些常见且经常可放心忽略的隐藏警告消息
#define _AFX_ALL_WARNINGS
#include <afxwin.h>         // MFC 核心组件和标准组件
#include <afxext.h>         // MFC 扩展
#include <afxdisp.h>        // MFC 自动化类
#ifndef _AFX_NO_OLE_SUPPORT
#include <afxdtctl.h>           // MFC 对 Internet Explorer 4 公共控件的支持
#endif
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h>             // MFC 对 Windows 公共控件的支持
#endif // _AFX_NO_AFXCMN_SUPPORT
#include <afxcontrolbars.h>     // MFC 支持功能区和控制条
#ifdef _UNICODE
#if defined _M_IX86
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")
#elif defined _M_X64
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"")
#else
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
#endif
#endif
MFCMView/pch.cpp
New file
@@ -0,0 +1,5 @@
// pch.cpp: 与预编译标头对应的源文件
#include "pch.h"
// 当使用预编译的头时,需要使用此源文件,编译才能成功。
MFCMView/pch.h
New file
@@ -0,0 +1,13 @@
// pch.h: 这是预编译标头文件。
// 下方列出的文件仅编译一次,提高了将来生成的生成性能。
// 这还将影响 IntelliSense 性能,包括代码完成和许多代码浏览功能。
// 但是,如果此处列出的文件中的任何一个在生成之间有更新,它们全部都将被重新编译。
// 请勿在此处添加要频繁更新的文件,这将使得性能优势无效。
#ifndef PCH_H
#define PCH_H
// 添加要在此处预编译的标头
#include "framework.h"
#endif //PCH_H
MFCMView/res/MFCMView.ico
MFCMView/res/MFCMView.rc2
Binary files differ
MFCMView/res/Toolbar.bmp
MFCMView/targetver.h
New file
@@ -0,0 +1,8 @@
#pragma once
// 包括 SDKDDKVer.h 将定义可用的最高版本的 Windows 平台。
//如果要为以前的 Windows 平台生成应用程序,请包括 WinSDKVer.h,并
// 将 _WIN32_WINNT 宏设置为要支持的平台,然后再包括 SDKDDKVer.h。
#include <SDKDDKVer.h>
MTerm1.sln
@@ -24,6 +24,12 @@
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ConsoleApplication1", "ConsoleApplication1\ConsoleApplication1.vcxproj", "{83C17606-596D-4072-83A2-0C634C20E742}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "FirmwareTool", "FirmwareTool\FirmwareTool.vcxproj", "{BE51EFF7-87E7-4287-A627-60EE573068BB}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "KwLoRaTool", "KwLoRaTool\KwLoRaTool.vcxproj", "{B10AEE8B-ECA1-4758-A8AD-05FED4DE6A32}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MFCApplication1", "MFCApplication1\MFCApplication1.vcxproj", "{08DF2942-97FC-4EA6-B79C-3E1D4DC969AB}"
EndProject
Global
    GlobalSection(SolutionConfigurationPlatforms) = preSolution
        Debug|x64 = Debug|x64
@@ -104,6 +110,30 @@
        {83C17606-596D-4072-83A2-0C634C20E742}.Release|x64.Build.0 = Release|x64
        {83C17606-596D-4072-83A2-0C634C20E742}.Release|x86.ActiveCfg = Release|Win32
        {83C17606-596D-4072-83A2-0C634C20E742}.Release|x86.Build.0 = Release|Win32
        {BE51EFF7-87E7-4287-A627-60EE573068BB}.Debug|x64.ActiveCfg = Debug|x64
        {BE51EFF7-87E7-4287-A627-60EE573068BB}.Debug|x64.Build.0 = Debug|x64
        {BE51EFF7-87E7-4287-A627-60EE573068BB}.Debug|x86.ActiveCfg = Debug|Win32
        {BE51EFF7-87E7-4287-A627-60EE573068BB}.Debug|x86.Build.0 = Debug|Win32
        {BE51EFF7-87E7-4287-A627-60EE573068BB}.Release|x64.ActiveCfg = Release|x64
        {BE51EFF7-87E7-4287-A627-60EE573068BB}.Release|x64.Build.0 = Release|x64
        {BE51EFF7-87E7-4287-A627-60EE573068BB}.Release|x86.ActiveCfg = Release|Win32
        {BE51EFF7-87E7-4287-A627-60EE573068BB}.Release|x86.Build.0 = Release|Win32
        {B10AEE8B-ECA1-4758-A8AD-05FED4DE6A32}.Debug|x64.ActiveCfg = Debug|x64
        {B10AEE8B-ECA1-4758-A8AD-05FED4DE6A32}.Debug|x64.Build.0 = Debug|x64
        {B10AEE8B-ECA1-4758-A8AD-05FED4DE6A32}.Debug|x86.ActiveCfg = Debug|Win32
        {B10AEE8B-ECA1-4758-A8AD-05FED4DE6A32}.Debug|x86.Build.0 = Debug|Win32
        {B10AEE8B-ECA1-4758-A8AD-05FED4DE6A32}.Release|x64.ActiveCfg = Release|x64
        {B10AEE8B-ECA1-4758-A8AD-05FED4DE6A32}.Release|x64.Build.0 = Release|x64
        {B10AEE8B-ECA1-4758-A8AD-05FED4DE6A32}.Release|x86.ActiveCfg = Release|Win32
        {B10AEE8B-ECA1-4758-A8AD-05FED4DE6A32}.Release|x86.Build.0 = Release|Win32
        {08DF2942-97FC-4EA6-B79C-3E1D4DC969AB}.Debug|x64.ActiveCfg = Debug|x64
        {08DF2942-97FC-4EA6-B79C-3E1D4DC969AB}.Debug|x64.Build.0 = Debug|x64
        {08DF2942-97FC-4EA6-B79C-3E1D4DC969AB}.Debug|x86.ActiveCfg = Debug|Win32
        {08DF2942-97FC-4EA6-B79C-3E1D4DC969AB}.Debug|x86.Build.0 = Debug|Win32
        {08DF2942-97FC-4EA6-B79C-3E1D4DC969AB}.Release|x64.ActiveCfg = Release|x64
        {08DF2942-97FC-4EA6-B79C-3E1D4DC969AB}.Release|x64.Build.0 = Release|x64
        {08DF2942-97FC-4EA6-B79C-3E1D4DC969AB}.Release|x86.ActiveCfg = Release|Win32
        {08DF2942-97FC-4EA6-B79C-3E1D4DC969AB}.Release|x86.Build.0 = Release|Win32
    EndGlobalSection
    GlobalSection(SolutionProperties) = preSolution
        HideSolutionNode = FALSE
MTerm1/0prog2.kpg
@@ -27,6 +27,22 @@
AN    X23
AN    X24
AN    X25
ST    LX0
AN    LX1
AN    LX2
AN    LX3
AN    LX4
AN    LX5
AN    LX6
AN    LX7
AN    LX8
AN    LX9
AN    LX10
AN    LX11
AN    LX12
AN    LX13
AN    LX14
AN    LX15
ST    Y0
AN    Y1
AN    Y2
@@ -59,8 +75,24 @@
AN    Y29
AN    Y30
AN    Y31
ST    LY0
AN    LY1
AN    LY2
AN    LY3
AN    LY4
AN    LY5
AN    LY6
AN    LY7
AN    LY8
AN    LY9
AN    LY10
AN    LY11
AN    LY12
AN    LY13
AN    LY14
AN    LY15
ST    R0
MV    WY0    WLY1
MV    WY0    WLY0
ST    SR13
PSHS
MV    WX0    WX1
@@ -331,19 +363,4 @@
DT36    绿灯2 秒余数
DT22    绿灯1剩余时间
[MONCOILLIST]
[MONDATALIST]
时间
DT13    黄灯1时间
DT14    绿灯2延迟时间
DT32    剩余秒数
DT33    余数
DT15    绿灯2时间
DT16    黄灯2时间
DT25    绿灯2剩余时间
DT35    绿灯2剩余秒数
DT36    绿灯2 秒余数
DT22    绿灯1剩余时间
[MONCOILLIST]
[MONDATALIST]
[MONDATALIST]
MTerm1/CChidSysCfg1.cpp
New file
@@ -0,0 +1,428 @@
// CChidSysCfg1.cpp: 实现文件
//
#include "pch.h"
//#include "ConfigTool.h"
#include "MTerm1.h"
#include "CChidSysCfg1.h"
#include "afxdialogex.h"
// CChidSysCfg1 对话框
IMPLEMENT_DYNAMIC(CChidSysCfg1, CDialogEx)
CChidSysCfg1::CChidSysCfg1(CWnd* pParent /*=nullptr*/)
    : CDialogEx(IDD_PROP_SYSREG2, pParent)
{
}
CChidSysCfg1::~CChidSysCfg1()
{
}
void CChidSysCfg1::DoDataExchange(CDataExchange* pDX)
{
    CDialogEx::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CChidSysCfg1, CDialogEx)
    ON_WM_VSCROLL()
    ON_WM_SIZE()
    ON_WM_MOUSEHWHEEL()
    ON_WM_TIMER()
END_MESSAGE_MAP()
// CChidSysCfg1 消息处理程序
BOOL CChidSysCfg1::OnInitDialog()
{
    CDialogEx::OnInitDialog();
    // TODO:  在此添加额外的初始化
    RECT rect0;
    GetClientRect(&rect0);
    m_nPropHeight = rect0.bottom - rect0.top;
    m_nFrameheight = 300;
    UpdateScrollInfo();
    CString s1;
    s1.Format(_T("CChildSysCfg1 OnInitDialog"));
    SysLog(s1);
    return TRUE;  // return TRUE unless you set the focus to a control
                  // 异常: OCX 属性页应返回 FALSE
}
void CChidSysCfg1::OnSize(UINT nType, int cx, int cy)
{
    CDialogEx::OnSize(nType, cx, cy);
    // TODO: 在此处添加消息处理程序代码
}
int CChidSysCfg1::UpdateScrollInfo()
{
    // TODO: 在此处添加实现代码.
    SCROLLINFO vinfo;
    vinfo.cbSize = sizeof(vinfo);
    vinfo.fMask = SIF_ALL;
    vinfo.nPage = m_nFrameheight;//滚动块自身的长短,通常有如下关系:其长度/滚动条长度(含两个箭头)=nPage/(nMax+2),
               //另外nPage取值-1时,滚动条会不见了。
    vinfo.nMax = m_nPropHeight;// -m_nFrameheight;//滚动条所能滚动的最大值
    vinfo.nMin = 0;//滚动条所能滚动的最小值
    vinfo.nTrackPos = 0;
    SetScrollInfo(SB_VERT, &vinfo);//即使上述步骤一不做,使用此条语句也可以显示滚动条
    CString s1;
    s1.Format(_T("CChildSysCfg1 UpdateScrollInfo"));
    SysLog(s1);
    return 0;
}
int CChidSysCfg1::VScrollBy(int nPos)
{
    // TODO: 在此处添加实现代码.
    CString s1;
    int nMin, nMax;
    int TempPos;
    this->GetScrollRange(SB_VERT, &nMin, &nMax);
    TempPos = this->GetScrollPos(SB_VERT);
    TempPos += nPos;
    if (TempPos < 0) TempPos = 0;
    if (TempPos > nMax - m_nFrameheight) TempPos = nMax - m_nFrameheight;
    SetScrollPos(SB_VERT, TempPos);
    int nNewPos = -TempPos;
    int Scrolldel = nNewPos - m_nScrollPos;
    s1.Format(_T("PropSysReg Scroll %d %d %d %d"), m_nScrollPos, TempPos, nNewPos, Scrolldel);
//    SysLog(s1);
    this->ScrollWindow(0, Scrolldel);
    m_nScrollPos += Scrolldel;
    return 0;
}
void CChidSysCfg1::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
    // TODO: 在此添加消息处理程序代码和/或调用默认值
///*
    CString s1;
    s1.Format(_T("PropSysReg OnVScroll %d %d"), nSBCode, nPos);
//    SysLog(s1);
    int nMin, nMax;
    int TempPos;
    if (pScrollBar == NULL) {
        this->GetScrollRange(SB_VERT, &nMin, &nMax);
        TempPos = this->GetScrollPos(SB_VERT);
    }
    else {
        pScrollBar->GetScrollRange(&nMin, &nMax);  //取得滚动条范围
        TempPos = pScrollBar->GetScrollPos();
    }
    switch (nSBCode)
    {
    case SB_THUMBPOSITION://拖动滑块
    case SB_THUMBTRACK:
        if (pScrollBar == NULL) {
            SetScrollPos(SB_VERT, nPos);
        }
        else {
            pScrollBar->SetScrollPos(nPos);
        }
        TempPos = nPos;
        break;
    case SB_LINEUP://点击上边/左边的箭头
        TempPos-=10;
        if (TempPos < 0)TempPos = 0;
        if (pScrollBar == NULL) { SetScrollPos(SB_VERT, TempPos); }
        else { pScrollBar->SetScrollPos(TempPos); }
        break;
    case SB_LINEDOWN://点击下边/右边的箭头
        TempPos+=10;
        if (TempPos > nMax) TempPos = nMax;
        if (pScrollBar == NULL) { SetScrollPos(SB_VERT, TempPos); }
        else { pScrollBar->SetScrollPos(TempPos); }
        break;
    case SB_PAGEUP:   // 如果向上/左滚动一页
        TempPos -= 100;
        if (TempPos < 0) TempPos = 0;
        if (pScrollBar == NULL) { SetScrollPos(SB_VERT, TempPos); }
        else { pScrollBar->SetScrollPos(TempPos); }
        break;
    case SB_PAGEDOWN:    // 如果向下/右滚动一页
        TempPos += 100;
        if (TempPos > nMax) TempPos = nMax;
        if (pScrollBar == NULL) { SetScrollPos(SB_VERT, TempPos); }
        else { pScrollBar->SetScrollPos(TempPos); }
        break;
    }
    int nNewPos = -TempPos;
    int Scrolldel = nNewPos - m_nScrollPos;
    s1.Format(_T("PropSysReg Scroll %d %d %d"), m_nScrollPos, nNewPos, Scrolldel);
//    SysLog(s1);
    this->ScrollWindow(0, Scrolldel);
    m_nScrollPos += Scrolldel;
    //*/
    CDialogEx::OnVScroll(nSBCode, nPos, pScrollBar);
}
void CChidSysCfg1::OnMouseHWheel(UINT nFlags, short zDelta, CPoint pt)
{
    // 此功能要求 Windows Vista 或更高版本。
    // _WIN32_WINNT 符号必须 >= 0x0600。
    // TODO: 在此添加消息处理程序代码和/或调用默认值
///*
    int nNewPos = m_nScrollPos;
    if (zDelta < 0)
    {
        this->ScrollWindow(0, 0);
//        if (-m_nScrollPos < m_nPropHeight - m_nFrameheight - 30)
//            nNewPos = m_nScrollPos - 30;
//        else
//            nNewPos = -(m_nPropHeight - m_nFrameheight);
    }
    else if (zDelta > 0)
    {
        this->ScrollWindow(0, 100);
//        if (-m_nScrollPos > 30)
//            nNewPos = m_nScrollPos + 30;
//        else
//            nNewPos = 0;
    }
    else
    {
    }
//    int Scrolldel = nNewPos - m_nScrollPos;
//    this->ScrollWindow(0, Scrolldel);
//    m_nScrollPos += Scrolldel;
//    GetDlgItem(IDC_SCROLLBAR1)->SetScrollPos(-m_nScrollPos);
//*/
    CDialogEx::OnMouseHWheel(nFlags, zDelta, pt);
}
void CChidSysCfg1::OnTimer(UINT_PTR nIDEvent)
{
    // TODO: 在此添加消息处理程序代码和/或调用默认值
    if (nIDEvent == 0)
    {
        KillTimer(0);
        DelayInit();
    }
    else if (nIDEvent == 1)
    {
    }
    CDialogEx::OnTimer(nIDEvent);
}
int CChidSysCfg1::DelayInit()
{
    return 0;
}
unsigned int type_ctrl_ids[6] = {
    IDC_COMBO_FROM_COIL_TYPE_00 ,IDC_COMBO_FROM_COIL_TYPE_01 ,IDC_COMBO_FROM_COIL_TYPE_02 ,
    IDC_COMBO_FROM_COIL_TYPE_03 ,IDC_COMBO_FROM_COIL_TYPE_04 ,IDC_COMBO_FROM_COIL_TYPE_05};
unsigned int addr_ctrl_ids[6] = {
    IDC_COMBO_FROM_COIL_ADDR_00 ,IDC_COMBO_FROM_COIL_ADDR_01 ,IDC_COMBO_FROM_COIL_ADDR_02 ,
    IDC_COMBO_FROM_COIL_ADDR_03 ,IDC_COMBO_FROM_COIL_ADDR_04 ,IDC_COMBO_FROM_COIL_ADDR_05 };
unsigned int bit_ctrl_ids[6] = {
    IDC_COMBO_FROM_COIL_BIT_00 ,IDC_COMBO_FROM_COIL_BIT_01 ,IDC_COMBO_FROM_COIL_BIT_02 ,
    IDC_COMBO_FROM_COIL_BIT_03 ,IDC_COMBO_FROM_COIL_BIT_04 ,IDC_COMBO_FROM_COIL_BIT_05 };
int CChidSysCfg1::ShowParams()
{
    CString s1;
    s1.Format(_T("ShowParams"));
    SysLog(s1);
// ---------  工作模式  ---------------------------------------
//工作模式,跳线功能等,good 指示灯
//
    ((CComboBox*)GetDlgItem(IDC_COMBO_WORKMODE3))->SetCurSel(psyscfg->workmode);
// -----------------------------------------------------------
//----------  通讯端口1,RS232  -----------------------------
/*
    s1.Format(_T("mode %d"), psyscfg->PortParams[0].WorkMode); SysLog(s1);
    s1.Format(_T("station %d"), psyscfg->PortParams[0].Station); SysLog(s1);
    s1.Format(_T("baudrate %d"), psyscfg->PortParams[0].BaudRate); SysLog(s1);
    s1.Format(_T("bytesize %d"), psyscfg->PortParams[0].ByteSize); SysLog(s1);
    s1.Format(_T("stopbits %d"), psyscfg->PortParams[0].StopBits); SysLog(s1);
    s1.Format(_T("parity %d"), psyscfg->PortParams[0].Parity); SysLog(s1);
    s1.Format(_T("eofchar %d"), psyscfg->PortParams[0].EofChar); SysLog(s1);
    s1.Format(_T("sofchar %d"), psyscfg->PortParams[0].SofChar); SysLog(s1);
    s1.Format(_T("endtype %d"), psyscfg->PortParams[0].EndType); SysLog(s1);
    s1.Format(_T("recvaddr %d"), psyscfg->PortParams[0].RecvAddr); SysLog(s1);
    s1.Format(_T("recvsize %d"), psyscfg->PortParams[0].RecvSize); SysLog(s1);
    s1.Format(_T("endtime %d"), psyscfg->PortParams[0].EndTime); SysLog(s1);
*/
    ((CComboBox *)GetDlgItem(IDC_COMBO_WORKMODE1))->SetCurSel(psyscfg->PortParams[0].WorkMode);
    ((CComboBox *)GetDlgItem(IDC_COMBO_STATION1))->SetCurSel(psyscfg->PortParams[0].Station);
    s1.Format(_T("%d"), psyscfg->PortParams[0].BaudRate * 100);
    ((CComboBox *)GetDlgItem(IDC_COMBO_BAUDRATE1))->SelectString(0, s1);
    ((CComboBox *)GetDlgItem(IDC_COMBO_BAUDRATE1))->SetWindowText(s1);
    ((CComboBox *)GetDlgItem(IDC_COMBO_BYTE_SIZE1))->SetCurSel(psyscfg->PortParams[0].ByteSize);
    ((CComboBox *)GetDlgItem(IDC_COMBO_STOP_BIT1))->SetCurSel(psyscfg->PortParams[0].StopBits);
    ((CComboBox *)GetDlgItem(IDC_COMBO_PARITY1))->SetCurSel(psyscfg->PortParams[0].Parity);
    ((CComboBox *)GetDlgItem(IDC_COMBO_EOF_CHAR1))->SetCurSel(psyscfg->PortParams[0].EofChar);
    ((CComboBox *)GetDlgItem(IDC_COMBO_SOF_CHAR1))->SetCurSel(psyscfg->PortParams[0].SofChar);
    ((CComboBox *)GetDlgItem(IDC_COMBO_END_TYPE1))->SetCurSel(psyscfg->PortParams[0].EndType);
    s1.Format(_T("%d"), psyscfg->PortParams[0].RecvAddr);
    ((CEdit *)GetDlgItem(IDC_EDIT_BUF_ADDR1))->SetWindowText(s1);
    s1.Format(_T("%d"), psyscfg->PortParams[0].RecvSize);
    ((CEdit *)GetDlgItem(IDC_EDIT_BUF_SIZE1))->SetWindowText(s1);;
    s1.Format(_T("%d"), psyscfg->PortParams[0].EndTime);
    ((CEdit *)GetDlgItem(IDC_EDIT_END_TIME1))->SetWindowText(s1);;
//------------------------------------------------------------------
// ---  通讯端口2 RS485  ----------------------------
    ((CComboBox *)GetDlgItem(IDC_COMBO_WORKMODE2))->SetCurSel(psyscfg->PortParams[1].WorkMode);
    ((CComboBox *)GetDlgItem(IDC_COMBO_STATION2))->SetCurSel(psyscfg->PortParams[1].Station);
    s1.Format(_T("%d"), psyscfg->PortParams[1].BaudRate * 100);
    ((CComboBox *)GetDlgItem(IDC_COMBO_BAUDRATE2))->SelectString(0, s1);
    ((CComboBox *)GetDlgItem(IDC_COMBO_BAUDRATE2))->SetWindowText(s1);
    ((CComboBox *)GetDlgItem(IDC_COMBO_BYTE_SIZE2))->SetCurSel(psyscfg->PortParams[1].ByteSize);
    ((CComboBox *)GetDlgItem(IDC_COMBO_STOP_BIT2))->SetCurSel(psyscfg->PortParams[1].StopBits);
    ((CComboBox *)GetDlgItem(IDC_COMBO_PARITY2))->SetCurSel(psyscfg->PortParams[1].Parity);
    ((CComboBox *)GetDlgItem(IDC_COMBO_EOF_CHAR2))->SetCurSel(psyscfg->PortParams[1].EofChar);
    ((CComboBox *)GetDlgItem(IDC_COMBO_SOF_CHAR2))->SetCurSel(psyscfg->PortParams[1].SofChar);
    ((CComboBox *)GetDlgItem(IDC_COMBO_END_TYPE2))->SetCurSel(psyscfg->PortParams[1].EndType);
    s1.Format(_T("%d"), psyscfg->PortParams[1].RecvAddr);
    ((CEdit *)GetDlgItem(IDC_EDIT_BUF_ADDR2))->SetWindowText(s1);
    s1.Format(_T("%d"), psyscfg->PortParams[1].RecvSize);
    ((CEdit *)GetDlgItem(IDC_EDIT_BUF_SIZE2))->SetWindowText(s1);;
    s1.Format(_T("%d"), psyscfg->PortParams[1].EndTime);
    ((CEdit *)GetDlgItem(IDC_EDIT_END_TIME2))->SetWindowText(s1);;
//------------------------------------------------------------------
// ---  输入滤波  ----------------------------
    int i = 0;
    i = psyscfg->InputParams[0].Filter0;
    ((CComboBox *)GetDlgItem(IDC_COMBO_INPUT_FILTER_1))->SetCurSel(i);
    i = psyscfg->InputParams[0].Filter1;
    ((CComboBox *)GetDlgItem(IDC_COMBO_INPUT_FILTER_2))->SetCurSel(i);
    i = psyscfg->InputParams[1].Filter0;
    ((CComboBox *)GetDlgItem(IDC_COMBO_INPUT_FILTER_3))->SetCurSel(i);
    i = psyscfg->InputParams[1].Filter1;
    ((CComboBox *)GetDlgItem(IDC_COMBO_INPUT_FILTER_4))->SetCurSel(i);
    i = psyscfg->InputParams[2].Filter0;
    ((CComboBox *)GetDlgItem(IDC_COMBO_INPUT_FILTER_5))->SetCurSel(i);
    i = psyscfg->InputParams[2].Filter1;
    ((CComboBox *)GetDlgItem(IDC_COMBO_INPUT_FILTER_6))->SetCurSel(i);
    i = psyscfg->InputParams[3].Filter0;
    ((CComboBox *)GetDlgItem(IDC_COMBO_INPUT_FILTER_7))->SetCurSel(i);
    i = psyscfg->InputParams[3].Filter1;
    ((CComboBox *)GetDlgItem(IDC_COMBO_INPUT_FILTER_8))->SetCurSel(i);
//------------------------------------------------------------------
// ---  输出保持  ----------------------------
    i = psyscfg->OutputParams[0].Hold1;
    ((CComboBox *)GetDlgItem(IDC_COMBO_OUTPUT_SET_1))->SetCurSel(i);
    i = psyscfg->OutputParams[0].Hold2;
    ((CComboBox *)GetDlgItem(IDC_COMBO_OUTPUT_SET_1))->SetCurSel(i);
//------------------------------------------------------------------
// ---  输出端口映射  ----------------------------
    for (int i = 0; i < 6; i++) {
        unsigned short bytebitaddr = psyscfg->OutMappings[i].value;
        s1.Format(_T("mappig %d %04x"), i, bytebitaddr);
        SysLog(s1);
        unsigned char ntype = (bytebitaddr & 0xf000) >> 12;
        unsigned char byteaddr = (bytebitaddr & 0x0ff0) >> 4;
        unsigned char bitoff = bytebitaddr & 0x000f;
        ((CComboBox *)GetDlgItem(type_ctrl_ids[i]))->SetCurSel(ntype);
        ((CComboBox *)GetDlgItem(addr_ctrl_ids[i]))->SetCurSel(byteaddr);
        ((CComboBox *)GetDlgItem(bit_ctrl_ids[i]))->SetCurSel(bitoff);
    }
//------------------------------------------------------------------
    return 0;
}
int CChidSysCfg1::GetParams()
{
    CString s1;
    s1.Format(_T("GetParams"));
    SysLog(s1);
    psyscfg->workmode = ((CComboBox*)GetDlgItem(IDC_COMBO_WORKMODE))->GetCurSel();
    for (int i = 0; i < 6; i++) {
        unsigned char ntype = ((CComboBox *)GetDlgItem(type_ctrl_ids[i]))->GetCurSel();
        unsigned char byteaddr = ((CComboBox *)GetDlgItem(addr_ctrl_ids[i]))->GetCurSel();
        unsigned char bitoff = ((CComboBox *)GetDlgItem(bit_ctrl_ids[i]))->GetCurSel();
        unsigned short bytebitaddr = (ntype << 12) + (byteaddr << 4) + (bitoff);
            psyscfg->OutMappings[i].value = bytebitaddr;
            s1.Format(_T("mappig %d %04x"), i, bytebitaddr);
            SysLog(s1);
    }
    return 0;
}
BOOL CChidSysCfg1::PreTranslateMessage(MSG* pMsg)
{
    // TODO: 在此添加专用代码和/或调用基类
    CString s1;
    if (pMsg->hwnd && pMsg->message == WM_MOUSEWHEEL)
    {
        if (pMsg->hwnd != this->m_hWnd)
        {
            pMsg->hwnd = this->m_hWnd;
            //return TRUE;
        }
/*
        GetClassName(pMsg->hwnd, s1.GetBuffer(256), 256);
        s1.ReleaseBuffer();
        if (s1.Find(_T("COMBOBOX")) == 0)
        {
            return TRUE;
        }
*/
    }
    return CDialogEx::PreTranslateMessage(pMsg);
}
BOOL CChidSysCfg1::OnChildNotify(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pLResult)
{
    // TODO: 在此添加专用代码和/或调用基类
    //if (message == WM_MOUSEWHEEL) return true;
    return CDialogEx::OnChildNotify(message, wParam, lParam, pLResult);
}
MTerm1/CChidSysCfg1.h
New file
@@ -0,0 +1,44 @@
#pragma once
// CChidSysCfg1 对话框
#include "../MTerm1/KDefine.h"
class CChidSysCfg1 : public CDialogEx
{
    DECLARE_DYNAMIC(CChidSysCfg1)
public:
    CChidSysCfg1(CWnd* pParent = nullptr);   // 标准构造函数
    virtual ~CChidSysCfg1();
// 对话框数据
#ifdef AFX_DESIGN_TIME
    enum { IDD = IDD_PROP_SYSREG1 };
#endif
protected:
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV 支持
    DECLARE_MESSAGE_MAP()
public:
    int m_nPropHeight;
    int m_nFrameheight;
    int m_nScrollPos = 0;
    pstKMSysCfg psyscfg;
    int DelayInit();
    int ShowParams();
    int GetParams();
    virtual BOOL OnInitDialog();
    afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
    afx_msg void OnSize(UINT nType, int cx, int cy);
    afx_msg void OnMouseHWheel(UINT nFlags, short zDelta, CPoint pt);
    afx_msg void OnTimer(UINT_PTR nIDEvent);
    virtual BOOL OnChildNotify(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pLResult);
    int UpdateScrollInfo();
    int VScrollBy(int nPos);
    virtual BOOL PreTranslateMessage(MSG* pMsg);
};
MTerm1/ConfigToolView.cpp
New file
@@ -0,0 +1,934 @@

// ConfigToolView.cpp: CConfigToolView 类的实现
//
#include "pch.h"
#include "framework.h"
// SHARED_HANDLERS 可以在实现预览、缩略图和搜索筛选器句柄的
// ATL 项目中进行定义,并允许与该项目共享文档代码。
#ifndef SHARED_HANDLERS
//#include "ConfigTool.h"
#include "MTerm1.h"
#endif
//#include "ConfigToolDoc.h"
#include "ConfigToolView.h"
#include "../MyLib/Functions.hpp"
extern MHash DeviceList;
#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);
*/
CString& FormatHex(void* databuf, int nSize)
{
    static CString str1;
    unsigned char* ptr1 = (unsigned char*)databuf;
    str1.Empty();
    for (int i = 0; i < nSize && i < 256; i++)
    {
        //        if ((i & 0xf) == 0) str1.AppendFormat(_T("%02X  "), i);
        str1.AppendFormat(_T("%02X "), ptr1[i]);
        if (((i + 1) & 0xf) == 0) str1.Append(_T("\r\n"));
    }
    return str1;
}
// 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_SYSREG2, 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 = theApp.MyKLink1.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 = theApp.MyKLink1.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 = theApp.MyKLink1.SetCommParam();
    s1.Format(_T("Com Set = %d  COM%d %d %s"),res, theApp.MyKLink1.m_nPort, theApp.MyKLink1.m_nBaudRate, theApp.MyKLink1.m_Settings);
    SysLog(s1);
}
void CConfigToolView::OnBnClickedButtonConnect()
{
    // TODO: 在此添加控件通知处理程序代码
    int res = theApp.MyKLink1.Connect();
    CString s1;
    s1.Format(_T("connect = %d %s"), res, theApp.MyKLink1.m_resultStr);
    SysLog(s1);
    if (res == KLink1::KL_OK) m_bOpened = true;
    else { return; }
    unsigned short nCount;
    res = theApp.MyKLink1.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 = theApp.MyKLink1.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 = theApp.MyKLink1.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 = theApp.MyKLink1.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 = theApp.MyKLink1.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 = theApp.MyKLink1.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 = theApp.MyKLink1.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 = theApp.MyKLink1.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 += theApp.MyKLink1.m_resultStr;
        s1 += theApp.MyKLink1.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);
    }
}
MTerm1/ConfigToolView.h
New file
@@ -0,0 +1,109 @@

// ConfigToolView.h: CConfigToolView 类的接口
//
#pragma once
#include "CChidSysCfg1.h"
#include "../MTerm1/KDefine.h"
class CConfigToolView : public CFormView
{
protected: // 仅从序列化创建
    CConfigToolView() noexcept;
    DECLARE_DYNCREATE(CConfigToolView)
public:
#ifdef AFX_DESIGN_TIME
    enum{ IDD = IDD_CONFIGTOOL_FORM };
#endif
/*
// 特性
public:
    CConfigToolDoc* GetDocument() const;
*/
// 操作
public:
// 重写
public:
    virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
protected:
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV 支持
    virtual void OnInitialUpdate(); // 构造后第一次调用
    virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);
    virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);
    virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);
    virtual void OnPrint(CDC* pDC, CPrintInfo* pInfo);
// 实现
public:
    virtual ~CConfigToolView();
#ifdef _DEBUG
    virtual void AssertValid() const;
    virtual void Dump(CDumpContext& dc) const;
#endif
protected:
// 生成的消息映射函数
protected:
    DECLARE_MESSAGE_MAP()
public:
    CRect rect0;
    CRect rect1;
    int m_nFrameheight;
    int m_nPropHeight;
    int m_nScrollPos = 0;
    CChidSysCfg1 m_propsyscfg1;
    unsigned short m_InfoBlockbuf[256];
    pKMInfoBlock pInfoBlock;
    unsigned char uuidbuf[256];
    CString struuid;
    unsigned short m_factorydataBuf[256];
    stFactoryData * pfactorydata;
    unsigned short m_cfgdatabuf[256];
    pstKMSysCfg psyscfg;
    bool m_bOpened = false;
    bool m_bConnected = false;
    afx_msg void OnClose();
    afx_msg void OnDestroy();
    int AddDlgItems();
    afx_msg void OnBnClickedButtonCommSet();
    afx_msg void OnBnClickedButtonConnect();
    afx_msg void OnBnClickedButtonDisconnect();
    afx_msg void OnBnClickedButtonUpload();
    afx_msg void OnBnClickedButtonDownload();
    afx_msg void OnBnClickedButtonEventlog();
    afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt);
    CEdit m_edit_log1;
    afx_msg void OnTimer(UINT_PTR nIDEvent);
    int DelayInit();
    afx_msg void OnBnClickedButtonWritedata();
    int ShowParams();
    int GetParams();
    afx_msg void OnBnClickedButtonTimeNow();
    afx_msg void OnBnClickedButtonLoadSyscfgFile();
    afx_msg void OnBnClickedButtonSaveSyscfgFile();
    int ShowInfoBlockParams();
    int ShowFactoryDataParams();
    int GetFactoryDataParams();
    int ClearInfoBlockParams();
    int TestAutoConnect();
    CString GetDeviceNameStr(int DeviceTypeVer);
};
/*
#ifndef _DEBUG  // ConfigToolView.cpp 中的调试版本
inline CConfigToolDoc* CConfigToolView::GetDocument() const
   { return reinterpret_cast<CConfigToolDoc*>(m_pDocument); }
#endif
*/
MTerm1/DeviceList.ini
New file
@@ -0,0 +1,55 @@
[FAMILY]
00=未知设备
01=4入4出 试验模块
02=8入8出 试验模块
03=16入16出,旧排线
04=8入8出,旧排线
05=16路 旧黑端子1
06=8路 旧黑端子1
07=16路 旧黑端子2
08=8路 旧黑端子2
09=16路 新绿端子
0A=8路 新绿端子
0B=8入8从 Mini
0C=
0D=V45_NET,网络模块
0E=KL10-Ext-FPx, 松下扩展
0F=KL12 16路无线
10=KL12 8路无线
11=
12=
13=KL10-CON 协议转换板
[01]
;4入4出试验模块
01=VER1
02=Ver2
[02]
01=
02=
[03]
[04]
[05]
[06]
[07]
[08]
[09]
[0A]
[0B]
[0C]
[0D]
[0E]
;KL10-EXT-FPX, 松下扩展
00=版本00,
01=版本01   ;
02=版本02   ;现在使用的模块
[0F]
[10]
[11]
[12]
[13]
00=版本00
01=版本01
02=版本02
MTerm1/DialogDateTime.cpp
@@ -132,7 +132,7 @@
    CTime time1(year,mon,day,hour,min,sec);
    __time32_t time2 = (__time32_t)time1.GetTime();
    pDoc->MyKLink1.SetDateTime32(1, time2);
    theApp.MyKLink1.SetDateTime32(1, time2);
//    MyKLink1.WriteDataByte(1, 4, MyKLink1.KLDataTypeSDT, 36, (unsigned char *)&time2);
}
MTerm1/DialogEventLog.cpp
@@ -60,12 +60,12 @@
    CMTerm1Doc* pDoc = (CMTerm1Doc *)(pV->GetDocument());
    int nCount;
    int res = pDoc->MyKLink1.GetEventLogCount(1, &nCount);
    int res = theApp.MyKLink1.GetEventLogCount(1, &nCount);
    CString s1;
    s1.Format(_T("Get EventLogCount Result r=%d  N=%d "), res, nCount);
    SysLog(s1);
    if (res == pDoc->MyKLink1.KL_OK)
    if (res == theApp.MyKLink1.KL_OK)
    {
        s1.Format(_T("%d"), nCount);
        GetDlgItem(IDC_EDIT_EVENT_COUNT)->SetWindowText(s1);
@@ -83,13 +83,13 @@
    CMTerm1Doc* pDoc = (CMTerm1Doc *)(pV->GetDocument());
    int nCount;
    int res = pDoc->MyKLink1.GetEventLogCount(1, &nCount);
    int res = theApp.MyKLink1.GetEventLogCount(1, &nCount);
    CString s1;
    s1.Format(_T("Get EventLogCount Result r=%d  N=%d "), res, nCount);
    SysLog(s1);
    if (res == pDoc->MyKLink1.KL_OK)
    if (res == theApp.MyKLink1.KL_OK)
    {
        s1.Format(_T("%d"), nCount);
        GetDlgItem(IDC_EDIT_EVENT_COUNT)->SetWindowText(s1);
@@ -153,7 +153,7 @@
    int res;
    CString s1;
    res = pDoc->MyKLink1.GetEventLog(1, nIndex, nReadCount, &KEventLogs[nIndex]);
    res = theApp.MyKLink1.GetEventLog(1, nIndex, nReadCount, &KEventLogs[nIndex]);
    s1.Format(_T(" Get EventLog %d Result r=%d "), nIndex, res);
    s1.AppendFormat(_T("%d %d %d %d %d %d"), KEventLogs[nIndex].Sign1, KEventLogs[nIndex].Seq1, KEventLogs[nIndex].nTime, KEventLogs[nIndex].nType, KEventLogs[nIndex].nParam1, KEventLogs[nIndex].nParam2);
    // SysLog(s1);
MTerm1/DialogFactCfg.cpp
@@ -402,12 +402,14 @@
    CMTerm1Doc* pDoc = (CMTerm1Doc *)GetDocument();
    int r = pDoc->Connect();
    s1.Format(_T("Open %s  = %d"), pDoc->MyKLink1.MySerPort1.m_strResult, r);
    //int r = pDoc->Connect();
    int r = theApp.MyKLink1.Connect();
    s1.Format(_T("Open %s  = %d"), theApp.MyKLink1.MySerPort1.m_strResult, r);
    SysLog(s1);
    if (r == pDoc->MyKLink1.MySerPort1.R_OK)
    if (r == theApp.MyKLink1.MySerPort1.R_OK)
    {
        pDoc->MyKLink1.Open();
        theApp.MyKLink1.Open();
        return false;
    }
    return true;
@@ -421,7 +423,7 @@
    CMTerm1Doc* pDoc = (CMTerm1Doc *)GetDocument();
    
    pDoc->DisConnect();
    pDoc->MyKLink1.Close();
    theApp.MyKLink1.Close();
    return 0;
}
@@ -431,11 +433,11 @@
    unsigned short buf1[1024];
    unsigned short len1;
    int res = pDoc->MyKLink1.GetInfo(1 ,&len1, buf1);
    SysLog(pDoc->MyKLink1.m_resultStr);
    int res = theApp.MyKLink1.GetInfo(1 ,&len1, buf1);
    SysLog(theApp.MyKLink1.m_resultStr);
    CString s1;
    s1.Format(_T("GetInfo = %d %d bytes"), res,len1);
    if (res == pDoc->MyKLink1.KL_OK)
    if (res == theApp.MyKLink1.KL_OK)
    {
        s1.Append(_T("\r\n"));
        for (int i = 0; i < len1 / 2; i++)
@@ -503,11 +505,11 @@
    CString s2;
    CString s3;
    unsigned char buf2[1024];
    res = pDoc->MyKLink1.GetUID(1, &len1, (unsigned short *)buf2);
    SysLog(pDoc->MyKLink1.m_resultStr);
    res = theApp.MyKLink1.GetUID(1, &len1, (unsigned short *)buf2);
    SysLog(theApp.MyKLink1.m_resultStr);
    s1.Format(_T("GetUID = %d %d bytes"), res,len1);
    
    if (res == pDoc->MyKLink1.KL_OK)
    if (res == theApp.MyKLink1.KL_OK)
    {
        s1.Append(_T("\r\n"));
        for (int i = 0; i < 12; i++)
@@ -521,11 +523,11 @@
    SetDlgItemText(IDC_EDIT_DEVICE_UID, s2);
    
    res = pDoc->MyKLink1.GetSN(1, &len1, (unsigned short *)buf2);
    SysLog(pDoc->MyKLink1.m_resultStr);
    res = theApp.MyKLink1.GetSN(1, &len1, (unsigned short *)buf2);
    SysLog(theApp.MyKLink1.m_resultStr);
    s1.Format(_T("GetSN = %d %d bytes"), res,len1);
    s2.Empty();
    if (res == pDoc->MyKLink1.KL_OK)
    if (res == theApp.MyKLink1.KL_OK)
    {
        s1.Append(_T("\r\n"));
        for (int i = 0; i < 4; i++)
@@ -537,11 +539,11 @@
    }
    SysLog(s1);
    res = pDoc->MyKLink1.ReadFactoryData(1, 0, 120, &len1, (unsigned short *)buf2);
    SysLog(pDoc->MyKLink1.m_resultStr);
    res = theApp.MyKLink1.ReadFactoryData(1, 0, 120, &len1, (unsigned short *)buf2);
    SysLog(theApp.MyKLink1.m_resultStr);
    s1.Format(_T("GetFactoryData = %d %d bytes"), res, len1);
    s2.Empty();
    if (res == pDoc->MyKLink1.KL_OK)
    if (res == theApp.MyKLink1.KL_OK)
    {
        s1.Append(_T("\r\n"));
        for (int i = 0; i < 256 && i< len1; i++)
@@ -607,8 +609,8 @@
*/
    int res = 0;
    unsigned short len1;
    res = pDoc->MyKLink1.ReadFactoryData(1, 0, 120, &len1, (unsigned short *)buf1);
    SysLog(pDoc->MyKLink1.m_resultStr);
    res = theApp.MyKLink1.ReadFactoryData(1, 0, 120, &len1, (unsigned short *)buf1);
    SysLog(theApp.MyKLink1.m_resultStr);
    s1.Format(_T("GetFactoryData = %d %d bytes"), res,len1);
    GetDlgItemText(IDC_DATETIMEPICKER1, s1);
@@ -653,8 +655,8 @@
        SysLog(s1);
    }
    res = pDoc->MyKLink1.WriteFactoryData(1, 0, 80, buf1);
    SysLog(pDoc->MyKLink1.m_resultStr);
    res = theApp.MyKLink1.WriteFactoryData(1, 0, 80, buf1);
    SysLog(theApp.MyKLink1.m_resultStr);
    s1.Format(_T("WriteFactoryData = %d "), res);
    SysLog(s1);
    return 0;
MTerm1/DialogStatusShow.cpp
@@ -54,7 +54,7 @@
int CDialogStatusShow::ShowParams()
{
    // TODO: 在此处添加实现代码.
    m_liststatus1.SetExtendedStyle(LVS_EX_DOUBLEBUFFER | LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_ONECLICKACTIVATE | LVS_EX_LABELTIP);
    m_liststatus1.SetExtendedStyle( LVS_EX_DOUBLEBUFFER | LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_ONECLICKACTIVATE | LVS_EX_LABELTIP);
    m_liststatus1.DeleteAllItems();
    while (m_liststatus1.DeleteColumn(0));
    m_liststatus1.InsertColumn(0, _T("NO"), LVCFMT_LEFT, 96, -1);//LVCFMT_LEFT, LVCFMT_RIGHT, or LVCFMT_CENTER
@@ -66,7 +66,13 @@
    m_liststatus1.InsertColumn(6, _T("子机5"), LVCFMT_LEFT, 128, -1);//LVCFMT_LEFT, LVCFMT_RIGHT, or LVCFMT_CENTER
    m_liststatus1.InsertColumn(7, _T("子机6"), LVCFMT_LEFT, 128, -1);//LVCFMT_LEFT, LVCFMT_RIGHT, or LVCFMT_CENTER
    m_liststatus1.InsertColumn(8, _T("子机7"), LVCFMT_LEFT, 128, -1);//LVCFMT_LEFT, LVCFMT_RIGHT, or LVCFMT_CENTER
    m_liststatus1.InsertColumn(10, _T("子机8"), LVCFMT_LEFT, 128, -1);//LVCFMT_LEFT, LVCFMT_RIGHT, or LVCFMT_CENTER
    m_liststatus1.InsertColumn(9, _T("子机8"), LVCFMT_LEFT, 128, -1);//LVCFMT_LEFT, LVCFMT_RIGHT, or LVCFMT_CENTER
    m_liststatus1.InsertColumn(10, _T("子机9"), LVCFMT_LEFT, 128, -1);//LVCFMT_LEFT, LVCFMT_RIGHT, or LVCFMT_CENTER
    m_liststatus1.InsertColumn(11, _T("子机10"), LVCFMT_LEFT, 128, -1);//LVCFMT_LEFT, LVCFMT_RIGHT, or LVCFMT_CENTER
    m_liststatus1.InsertColumn(12, _T("子机11"), LVCFMT_LEFT, 128, -1);//LVCFMT_LEFT, LVCFMT_RIGHT, or LVCFMT_CENTER
    m_liststatus1.InsertColumn(13, _T("子机12"), LVCFMT_LEFT, 128, -1);//LVCFMT_LEFT, LVCFMT_RIGHT, or LVCFMT_CENTER
    m_liststatus1.InsertColumn(14, _T("子机13"), LVCFMT_LEFT, 128, -1);//LVCFMT_LEFT, LVCFMT_RIGHT, or LVCFMT_CENTER
    m_liststatus1.InsertColumn(15, _T("子机14"), LVCFMT_LEFT, 128, -1);//LVCFMT_LEFT, LVCFMT_RIGHT, or LVCFMT_CENTER
    m_liststatus1.InsertItem(0, _T("状态"));
    m_liststatus1.InsertItem(1, _T("发送包计数"));
@@ -76,22 +82,26 @@
    m_liststatus1.InsertItem(5, _T("连续丢包"));
    m_liststatus1.InsertItem(6, _T("最大连续"));
    m_liststatus1.InsertItem(7, _T("非包计数"));
//    m_liststatus1.InsertItem(8, _T("无结尾包"));
    m_liststatus1.InsertItem(8, _T("包长错误"));
    m_liststatus1.InsertItem(9, _T("校验错误"));
    m_liststatus1.InsertItem(10, _T("超时错误"));
    m_liststatus1.InsertItem(11, _T("返回延迟(uS)"));
    m_liststatus1.InsertItem(12, _T("最大延迟(uS)"));
    m_liststatus1.InsertItem(13, _T("循环时间(uS)"));
    m_liststatus1.InsertItem(11, _T("返回延迟(mS)"));
    m_liststatus1.InsertItem(12, _T("最大延迟(mS)"));
    m_liststatus1.InsertItem(13, _T("循环时间(mS)"));
    m_liststatus1.InsertItem(14, _T("子机接收"));
    m_liststatus1.InsertItem(15, _T("子机发送"));
    m_liststatus1.InsertItem(16, _T("子机非包"));
    m_liststatus1.InsertItem(17, _T("子机非ID"));
//    m_liststatus1.InsertItem(18, _T("子机无尾"));
    m_liststatus1.InsertItem(18, _T("子机包长"));
    m_liststatus1.InsertItem(19, _T("子机校验"));
    m_liststatus1.InsertItem(20, _T("子机超时"));
    m_liststatus1.InsertItem(21, _T("子机超时"));
    m_liststatus1.InsertItem(22, _T("子机超时"));
    m_liststatus1.InsertItem(23, _T("子机超时"));
    m_liststatus1.InsertItem(24, _T("子机超时"));
    m_liststatus1.InsertItem(25, _T("子机超时"));
    m_liststatus1.InsertItem(26, _T("子机超时"));
    m_liststatus1.InsertItem(27, _T("子机超时"));
    return 0;
}
@@ -121,10 +131,10 @@
    int nOffset = 0;
    KLink1::pChnStat pchnstat1;
    unsigned int nSendPackets;
    int nChilds = 8;
    int nChilds = 14;
    //子机1  
    //子机2
    for (int i = 0; i < nChilds; i++)
    for (int i = 0; i <= nChilds; i++)
    {
        nOffset = 0 + sizeof(KLink1::stChnStat) * i;
        pchnstat1 = (KLink1::pChnStat)&(pDoc->KBDB[nOffset + 0]);
@@ -157,11 +167,11 @@
        m_liststatus1.SetItemText(9, 1 + i, s1);
        s1.Format(_T("%u (%.3f%%)"), pchnstat1->TimeOutErr, pchnstat1->TimeOutErr * 100.0 / nSendPackets);
        m_liststatus1.SetItemText(10, 1 + i, s1);
        s1.Format(_T("%u"), pchnstat1->Delay);
        s1.Format(_T("%.1f"), pchnstat1->Delay/10.0f);
        m_liststatus1.SetItemText(11, 1 + i, s1);
        s1.Format(_T("%u"), pchnstat1->MaxDelay);
        s1.Format(_T("%.1f"), pchnstat1->MaxDelay/10.0f);
        m_liststatus1.SetItemText(12, 1 + i, s1);
        s1.Format(_T("%u"), pchnstat1->SendTimeInterval);
        s1.Format(_T("%.1f"), pchnstat1->SendTimeInterval/10.0f);
        m_liststatus1.SetItemText(13, 1 + i, s1);
@@ -209,9 +219,6 @@
    CDialogEx::OnClose();
}
void CDialogStatusShow::OnBnClickedButtonClearStatistics()
{
    // TODO: 在此添加控件通知处理程序代码
@@ -220,6 +227,6 @@
    CView   *pV = (CView*)pChild->GetActiveView();
    CMTerm1Doc* pDoc = (CMTerm1Doc *)(pV->GetDocument());
    pDoc->MyKLink1.ClearStatistics(1, 0);
    theApp.MyKLink1.ClearStatistics(1, 0);
}
MTerm1/DialogSysRegSet.cpp
@@ -186,7 +186,7 @@
    CMTerm1Doc* pDoc = (CMTerm1Doc *)GetDocument();
    unsigned short DCount = 120;
    unsigned short nCount=0;
    int res = pDoc->MyKLink1.ReadDataWord(1, KLDataSysCfg, 0, DCount, &nCount, m_databuf1);
    int res = theApp.MyKLink1.ReadDataWord(1, KLDataSysCfg, 0, DCount, &nCount, m_databuf1);
    CString s1;
    s1.Format(_T("ReadDataWord = %d  %d   %p  %p"), res,nCount, m_databuf1, &pSysCfg->PortParams[0]);
    SysLog(s1);
@@ -200,7 +200,7 @@
    }
    SysLog(s1);
    pSysCfg = (pKMSysCfg)m_databuf1;
    pSysCfg = (pstKMSysCfg)m_databuf1;
    m_listSel1.GetCount();
    AddPropPage(_T("工作模式设置1"), &m_propmodecfg1, IDD_PROP_MODE_CFG1, &pSysCfg->workmode);
@@ -488,7 +488,8 @@
    
    s1.Format(_T("sizeof (syscfg)  %d"), sizeof(stKMSysCfg));
    SysLog(s1);
    int res = pDoc->MyKLink1.ReadSysCfgData(1, 0, DCount, &nCount, buf1);
    UCHAR nType = 0;
    int res = theApp.MyKLink1.ReadSysCfgData(1, nType, 0, DCount, &nCount, buf1);
    s1.Format(_T("ReadDataWord = %d  %d"), res, nCount);
    SysLog(s1);
    s1.Empty(); s1.Append(_T("\r\n"));
@@ -527,7 +528,8 @@
    s1.Format(_T("sizeof (syscfg)  %d"), sizeof(stKMSysCfg));
    SysLog(s1);
    int res = pDoc->MyKLink1.WriteSysCfgData(1, 0, DCount, m_databuf1);
    UCHAR nType = 0;
    int res = theApp.MyKLink1.WriteSysCfgData(1, nType, 0, DCount, m_databuf1);
    s1.Format(_T("Write syscfg = %d "), res);
    SysLog(s1);
}
@@ -544,7 +546,7 @@
    s1.Format(_T("sizeof (syscfg)  %d"), sizeof(stKMSysCfg));
    SysLog(s1);
    int res = pDoc->MyKLink1.ReadDataWord(1, KLDataSysCfg,0,DCount, &nCount, buf1);
    int res = theApp.MyKLink1.ReadDataWord(1, KLDataSysCfg,0,DCount, &nCount, buf1);
    s1.Format(_T("ReadDataWord = %d  %d"), res, nCount);
    SysLog(s1);
    s1.Empty(); s1.Append(_T("\r\n"));
MTerm1/DialogSysRegSet.h
@@ -52,7 +52,7 @@
    unsigned short DeviceType;  // 当前设备类型,按照设备类型生成 proppage
    unsigned short m_databuf1[256];
    pKMSysCfg pSysCfg;
    pstKMSysCfg pSysCfg;
    //先知道 syscfg 的大小。
    // 打开窗口后, 在  delayInit中读取 syscfg 内容到 buf1;
    // 按照buf1 中的顺序,对 proppage 窗口进行数值 的地址 设置 ,指针 。
MTerm1/KDefine.h
@@ -109,15 +109,178 @@
    Output_Set_1 = 2,
};
enum enPortType
enum enPortHardType
{
    PortType_Com = 0,    //¼ÆËã»úͨѶ
    PortType_Gen = 1,    //ͨÓÃͨѶ£¬×ÔÓÉ¿Ú
    PortType_KLink = 2, //KlinkͨѶ
    PortType_KBus = 3,     //KBusͨѶ
    PortType_KNet = 4,     // KNetͨѶ
    PortType_ModbusRTU = 5, //Modbus RTU Í¨Ñ¶
    PortHardType_None    =    0,    //    空接口,无类型
    PortHardType_SOFT    =    1,    //    软件虚拟接口,可能是隧道等.
    PortHardType_UART    =    2,    //    串行接口
    PortHardType_RS232    =    3,    //    232接口
    PortHardType_RS485    =    4,    //    485接口
    PortHardType_SLP    =    5,    //    单总线接口
    PortHardType_RF        =    6,    //    无线接口
    PortHardType_LORA    =    7,    //    LoRa无线接口
    PortHardType_OPTI    =    8,    //    光纤接口
    PortHardType_ETH    =    9,    //    以太网接口
    PortHardType_WIFI    =    10,    //    WiFi接口
    PortHardType_BT        =    11,    //    以太网接口
};
static CString PortHardTypeToStr(int nPortHardType)
{
    static CString s1;
    switch (nPortHardType)
    {
    case PortHardType_None:
        return _T("NULL");
    case PortHardType_SOFT:        // = 1,    //    软件虚拟接口,可能是隧道等.
        return _T("Soft");
    case PortHardType_UART:        // = 2,    //    串行接口
        return _T("UART");
    case PortHardType_RS232:    //= 3,    //    232接口
        return _T("RS232");
    case PortHardType_RS485:    //= 4,    //    485接口
        return _T("RS485");
    case PortHardType_SLP:        //= 5,    //    单总线接口
        return _T("SLP");
    case PortHardType_RF:        //= 6,    //    无线接口
        return _T("RF");
    case PortHardType_LORA:        //= 7,    //    LoRa无线接口
        return _T("LoRa");
    case PortHardType_OPTI:        //= 8,    //    光纤接口
        return _T("Opti");
    case PortHardType_ETH:        //= 9,    //    以太网接口
        return _T("ETH");
    case PortHardType_WIFI:        //= 10,    //    WiFi接口
        return _T("WiFi");
    case PortHardType_BT:        //= 11,    //    以太网接口
        return _T("BT");
    default:
        return _T("UNKNOWN");
        break;
    }
}
enum enPortUseType
{
    PortUse_Default = 0,    //默认
    PortUse_Console = 1,    //控制台接口
    PortUse_KLink = 2,        //KLink通讯
    PortUse_KBus = 3,         //KBus通讯
    PortUse_KNet = 4,         // KNet通讯
    PortUse_SLP = 5,        // SLP单总线
    PortUse_KRF = 6,         // 无线通讯
    PortUse_ModbusRTU = 7, //Modbus RTU 通讯
    PortUse_ModbusTCP = 8, //Modbus TCP 通讯
    PortUse_Com = 9,        //    计算机通讯
    PortUse_Gen = 10,        //通用通讯,自由口
};
static CString PortUseTypeToStr(int nPortHardType)
{
    static CString s1;
    switch (nPortHardType)
    {
    case PortUse_Default:        // = 0 默认
        return _T("NULL");
    case PortUse_Console:        // = 1,    //控制台接口
        return _T("终端");
    case PortUse_KLink:        // = 2,    //KLink通讯
        return _T("KLink");
    case PortUse_KBus:    //= 3,    //    KNet通讯
        return _T("KBus");
    case PortUse_KNet:    //= 4,    //    串行接口
        return _T("KNet");
    case PortHardType_SLP:        //= 5,    //    SLP单总线
        return _T("KSLP");
    case PortUse_KRF:        //= 6,    //    无线通讯
        return _T("KwRF");
    case PortUse_ModbusRTU:        //= 7,    //    Modbus RTU 通讯
        return _T("ModbusRTU");
    case PortUse_ModbusTCP:        //= 8,    //    Modbus TCP 通讯
        return _T("ModbusTCP");
    case PortUse_Com:        //= 9,    //    计算机通讯
        return _T("");
    case PortUse_Gen:        //= 10,    //    通用通讯,自由口
        return _T("WiFi");
    default:
        return _T("UNKNOWN");
        break;
    }
}
enum enServiceReqs
{
    ReqNone,
    ReqInit,
    ReqReset,
    ReqStop,
    ReqRun,
    ReqBlinkLED,
    ReqStartDiag,
    ReqStopDiag,
    ReqPortChildInfo,
    ReqPortChnInfo,
    ReqUpdateFirm,
    ReqUpdateFirmInfo,
    ReqTransFirmware,
    ReqTransCfg,
    ReqTransProg,
    ReqTransData,
    ReqTransBlink,
    ReqTransChild,
    ReqTransInfo,
    ReqTransOutBandData,
    ReqRead1Bit,
    ReqWrite1Bit,
    ReqReadBits,
    ReqWriteBits,
    ReqReadData,
    ReqWriteData,
    ReqRemoteTran,
};
typedef struct tagPortAbility
{
    USHORT ChildList : 1;
    USHORT AccessChild : 1;
    USHORT TranProg : 1;
    USHORT TranCfg : 1;
    USHORT Diag : 1;
    USHORT TranOutBandData : 1;
    USHORT Tunnel : 1;
    USHORT TranFirmware : 1;
    USHORT TranBlink : 1;
}stPortAbility;
// 各端口 互联 通信
typedef int (*CommFuncDef)(int ReqId, int nParam, void* pData, int len1);
typedef struct tagPortDef
{
    union {
        USHORT nPortType;
        struct {
            UCHAR nPortHardType;
            UCHAR nPortUseType;
        };
    };
    USHORT ability;        //能力, 获取子机信息等。
    UCHAR bEnable;
    UCHAR bRunning;
    UCHAR StationId;
    UCHAR bMaster;
    UCHAR nMaxStations;
    UCHAR nCurStations;
    UCHAR nHealth;
    short PortConfigType;
    short PortConfigSize;
    short PortRunStatType;
    short PortRunStatSize;
//    CommFuncDef ReqCommFunc;
    // func2 CommReq;
}stPortDef, * pstPortDef;
enum enKeventType
{
@@ -132,17 +295,75 @@
    EventTypeProg = 8,
    EventTypeForce = 9,
    EventTypeClearEvent = 10,
    EventType
};
typedef struct tagDevPortDef
{
    union {
        USHORT nPortType;
        struct {
            UCHAR nPortHardType;
            UCHAR nPortUseType;
        };
    };
    UCHAR bEnabled;
    UCHAR bRunning;
    UCHAR StationID;
    UCHAR bMaster;
    UCHAR MaxStations;
    UCHAR CurStations;
    UCHAR Health;
}stDevPortDef;
typedef struct tagDeviceDef
{
    USHORT nDeviceTypeVer;
    USHORT nProgVer;
    UCHAR InBitCount;
    UCHAR OutBitCount;
    unsigned short nPortCount;
    stDevPortDef Ports[8];        //最多8个通讯端口
}stDeviceDef;
typedef struct tagDeviceInfo        // KBus 子机基本信息
{
    unsigned short DeviceType;        // 子机类型
    union {
        unsigned short DeviceVer;            // 子机版本
        struct {
            unsigned char DeviceVerMinor;
            unsigned char DeviceVerMajor;
        };
    };
    unsigned char InBitCount;            // 输入开关量数量
    unsigned char OutBitCount;        // 输出开关量数量
    unsigned char ExInBitCount;        // 扩展的输入开关量数量
    unsigned char ExOutBitCount;    // 扩展的输出开关量数量
    unsigned char DWStartAddr;        // 输出数据字数
    unsigned char OutDWCount;            // 输出数据字数
    unsigned char AIWCount;                // 输入模拟量通道(字)数    // 16位为一个字(通道)
    unsigned char AQWCount;                // 输出模拟量通道(字)数    // 16位为一个字(通道)
//    unsigned char AIBits;                    //  每通道位数        // 16位以下
//    unsigned char AQbits;                    //    每通道位数        // 16位以下
}stDeviceInfo;
typedef struct tagInfoBlock // 20 bytes
{
    //    USHORT nBlockLenth;
    USHORT nDeviceTypeVer;            //device type        x.y
//    UCHAR nDevierVer;
    USHORT nProgVer;                    //prog version    x.y
    union {
        USHORT nProgVer;                    //prog version    x.y
        struct {
            UCHAR nProgVerMinor;
            UCHAR nProgVerMajor;
        };
    };
    USHORT nKLinkVer;                //x.y
    USHORT nKBusVer;                //x.y
//    USHORT nKNetVer;                //x.y
@@ -186,6 +407,14 @@
}stFactoryData, *pFactoryData;
typedef struct tagNewAppInfoBlock
{
    unsigned short Sign;
    unsigned short Version;
    unsigned int Length;
    unsigned int nCRC;
}stNewAppInfoBlock, * pNewAppInfoBlock;
typedef struct tagKMFuncParam
{
@@ -233,23 +462,68 @@
    BYTE Hold2 : 4;
}stOutputHoldParam;
// 硬件描述文件
typedef struct tagOutMapping
{
    USHORT bitPos : 4;
    USHORT byteAddr : 8;
    USHORT type : 4;
}stOutMapping;
typedef struct tagCfgBlockInfo
{
    UCHAR nBlockType;
    UCHAR nBlockSize;
}stCfgBlockInfo;
//#pragma pack(2)
typedef struct tagKMSysCfg        //120 Bytes total
{
    USHORT Version;                        // SC0    // 2 Bytes
    USHORT workmode;                    // SC1  // 2 Bytes 0=From jumper
    USHORT SwitchFunc;                    // SC2  // 2 Bytes
    USHORT Space1;                        // 2 bytes
    USHORT Version;                                        // SC0    // 2 Bytes
    USHORT workmode;                                    // SC1  // 2 Bytes 0=From jumper
    USHORT SwitchFunc;                                // SC2  // 2 Bytes
    USHORT nCfgBlockCount;                                            // 2 Bytes
    stComPortParam PortParams[2];                    // 28 Bytes
    stInputFilterParam InputParams[16];                //8 Bytes
    stComPortParam PortParams[2];                            // 8 Bytes
    stInputFilterParam InputParams[16];                //16 Bytes
    stOutputHoldParam OutputParams[16];                //16 Bytes
    USHORT OutMappings[6];                //12 Bytes //输出映射
    UINT Space2[12];                                //48 bytes
    union {
        USHORT value;                                        //12 Bytes //输出映射
        struct {
            USHORT bitPos : 4;
            USHORT byteAddr : 8;
            USHORT type : 4;
        };
    }OutMappings[8];
}stKMSysCfg, *pKMSysCfg;
    USHORT nProgBank;
    USHORT nProgSize;
    USHORT nAnnoSize;
    USHORT nCount;
    stCfgBlockInfo CfgBlockInfos[8];
    UINT cfgvar8;                                                            // 4 Bytes
    UINT cfgvar9;                                                            // 4 Bytes
    UINT cfgvar10;                                                        // 4 Bytes
//    UINT cfgvar11;                                                        // 4 Bytes
//    UINT cfgvar12;                                                        // 4 Bytes
//    UINT cfgvar13;                                                        // 4 Bytes
//    UINT cfgvar14;                                                        // 4 Bytes
//    UINT cfgvar15;                                                        // 4 Bytes
//    UINT cfgvar16;                                                        // 4 Bytes
//    UINT Space1[4];                                                        //16 Bytes
}stKMSysCfg, * pstKMSysCfg;
typedef struct tagStoredKMSysCfg
{
    unsigned short Sign1;
    unsigned short Seq1;
    stKMSysCfg theKMSysCfg;
    unsigned short CRC1;
    unsigned short EndSign1;
}stStoredKMSysCfg, * pStoredKMSysCfg;
typedef struct tagTimer
@@ -392,7 +666,7 @@
    OP_TMR = 0xDC,    //
    OP_TMX = 0xDD,    //
    OP_TMY = 0xFA,    //
    OP_END = 0xFF,
};
typedef struct stBinProg1
MTerm1/KMachine.cpp
@@ -496,7 +496,7 @@
}
int KMachine::ProcessPLCBinProg(const stBinProg1 * pBinprog, int nSize)
int KMachine::ProcessPLCBinProg(const stBinProg1 * pBinprog, int nProgSteps)
{
    if (nScanCount == 0) {
        SetCoilValue(KLCoilTypeSR, 13, 1);
@@ -528,7 +528,7 @@
    int lastScanInputVal = 1;//上个扫描周期,当前指令输入状态,为 微分 做参考
    while (CurPos < nSize)
    while (CurPos < nProgSteps)
    {
        unsigned int nNextPos = 1;
        unsigned int thisOP = pBinprog[CurPos].nOp;
@@ -544,6 +544,9 @@
            //        case OP_NOP:
            break;
            //无参数 指令
        case OP_END:
            nNextPos = nProgSteps;
            break;
        case OP_NOT:
        case OP_ANS:
        case OP_ORS:
MTerm1/KMachine.h
@@ -6,6 +6,43 @@
*/
#pragma once
#include "KDefine.h"
typedef struct tagInfoBlockHdr {
    unsigned short nBlkSign;                    // 开始标志
    unsigned short nBlkTypeVer;                // 类型和版本
    unsigned short nBlkSize;                    // Block 大小, 包括开始和结束标志
    unsigned short Pad1;
}stInfoBlockHdr;
typedef struct tagInfoBlockTail {
    unsigned short CRC16;
    unsigned short EndSign;
}stInfoBlockTail;
typedef struct tagBtLdrInfoBlock {
    stInfoBlockHdr Hdr;
    unsigned short nBtldrVer;
    unsigned short nBtldrDevice;
    unsigned short nBtldrSize;        // 设计大小
    unsigned short nBtldrDataSize;        //代码大小
    unsigned int nBtldr_AppAddr;
    unsigned int nBtldr_NewAppInfoAddr;
    unsigned int nBtldr_NewAppAddr;
    stInfoBlockTail tail;
}stBtLdrInfoBlock, * pBtLdrInfoBlock;
typedef struct tagAppInfoBlock {
    stInfoBlockHdr Hdr;
    unsigned short nAppVer;
    unsigned short nAppDevice;
    unsigned short nAppSize;        // 设计大小
    unsigned short nAppDataSize;        //代码大小
    unsigned int nAppStartAddr;
    unsigned int nAppStartOffset;
    unsigned int nApp;
    stInfoBlockTail tail;
}stAppInfoBlock, * pAppInfoBlock;
class KMachine
{
@@ -59,7 +96,7 @@
    int PopOutVal(void);
//    int ProcessPLCProg(const stProg * prog, int nSize);
    int ProcPLC();
    int ProcessPLCBinProg(const stBinProg1 * pBinprog, int nSize);
    int ProcessPLCBinProg(const stBinProg1 * pBinprog, int nProgSteps);
};
MTerm1/MTerm1.cpp
@@ -49,6 +49,7 @@
#pragma comment(lib,"KLink1.lib")
MHash MyCfg1;
Logger myLogger1;
MHash DeviceList;
// CMTerm1App
@@ -138,7 +139,7 @@
    SetRegistryKey(_T("应用程序向导生成的本地应用程序"));
    LoadStdProfileSettings(4);  // 加载标准 INI 文件选项(包括 MRU)
    DeviceList.LoadFromFile(_T("./DeviceList.Ini"));
    // 注册应用程序的文档模板。  文档模板
    // 将用作文档、框架窗口和视图之间的连接
//    CMultiDocTemplate* pDocTemplate;
@@ -175,7 +176,7 @@
    if (!m_pBnlViewTemplate)
        return FALSE;
    AddDocTemplate(m_pBnlViewTemplate);
/*
    m_pCommDevViewTemplate = new CMultiDocTemplate(IDR_MTerm1TYPE,
        RUNTIME_CLASS(CMTerm1Doc),
        RUNTIME_CLASS(CChildFrame), // 自定义 MDI 子框架
@@ -183,8 +184,8 @@
    if (!m_pCommDevViewTemplate)
        return FALSE;
    AddDocTemplate(m_pCommDevViewTemplate);
*/
/*
    m_pCtrlViewTemplate = new CMultiDocTemplate(IDR_MTerm1TYPE,
        RUNTIME_CLASS(CMTerm1Doc),
        RUNTIME_CLASS(CChildFrame), // 自定义 MDI 子框架
@@ -192,7 +193,8 @@
    if (!m_pCtrlViewTemplate)
        return FALSE;
    AddDocTemplate(m_pCtrlViewTemplate);
// */
/*
    m_pProgViewTemplate = new CMultiDocTemplate(IDR_MTerm1TYPE,
        RUNTIME_CLASS(CMTerm1Doc),
        RUNTIME_CLASS(CChildFrame), // 自定义 MDI 子框架
@@ -200,7 +202,7 @@
    if (!m_pProgViewTemplate)
        return FALSE;
    AddDocTemplate(m_pProgViewTemplate);
  */
    m_pCoilViewTemplate = new CMultiDocTemplate(IDR_MTerm1TYPE,
        RUNTIME_CLASS(CMTerm1Doc),
        RUNTIME_CLASS(CChildFrame), // 自定义 MDI 子框架
@@ -216,11 +218,7 @@
    if (!m_pDataViewTemplate)
        return FALSE;
    AddDocTemplate(m_pDataViewTemplate);
/*
    m_pNewDocTemplate = new CMultiDocTemplate(IDR_MTerm1TYPE,
        RUNTIME_CLASS(CMTerm1Doc),
        RUNTIME_CLASS(CChildFrame), // 自定义 MDI 子框架
@@ -228,7 +226,8 @@
    if (!m_pNewDocTemplate)
        return FALSE;
    AddDocTemplate(m_pNewDocTemplate);
//*/
 //*/
    // 创建主 MDI 框架窗口
    CMainFrame* pMainFrame = new CMainFrame;
    if (!pMainFrame || !pMainFrame->LoadFrame(IDR_MAINFRAME))
@@ -591,6 +590,7 @@
    int k = Str1.GetLength();
    int j = (k - 1) / 3;    //逗号个数
    int l = k - j * 3; //起始位置
    if (Str1[l-1] < '0' || Str1[l-1] > '9') { l += 3; j -= 1; }
    for (int i = l; i < k + j; i += 4)
    {
        Str1.Insert(i, _T(","));
@@ -634,4 +634,38 @@
        mask >>= 1;
    }
    return Str1;
}
}
CString DeviceTypeToStr(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("(%02X)"), DeviceVer);
        }
    }
    else { DeviceName.Format(_T("Device %02X(%02X)"), DeviceType, DeviceVer); }
    return DeviceName;
}
MTerm1/MTerm1.h
@@ -12,6 +12,13 @@
#include "../mylib/LOGGER/Logger.hpp"
#include "../MyLib/MHashINI/MHash.hpp"
#include "KDefine.h"
//#include "KLink.h"
#include "KMachine.h"
#include "../KLink1/KLink.h"
#pragma comment(lib,"KLink1.lib")
void Trans_Tunc(unsigned int, EXCEPTION_POINTERS*);
#define CHECKE(func) try {func;} catch(SE_Exception &e) {DisplayException(_T(__FILE__),__LINE__,_T(__FUNCTION__),_T(#func),e);} catch (CException * e) {DisplayException(_T(__FILE__),__LINE__,_T(__FUNCTION__),_T(#func),e);} catch (...){DisplayException(_T(__FILE__),__LINE__,_T(__FUNCTION__),_T(#func));}
class SE_Exception
@@ -82,6 +89,33 @@
// 实现
    bool m_bHiColorIcons;
    KMachine myKMachine1;
    KLink1 MyKLink1;
    union {
        unsigned char KBDD[2048];
        unsigned short KBDT[1024];
        unsigned char KBDB[2048];
    };
    union {
        unsigned char KWLD[2048];
        unsigned short KWLT[1024];
        unsigned char KWLB[2048];
    };
    bool m_bCommParamSet = false;
    int nComPort;
    int nBaud;
    CStringA ComSettings;
    bool m_bOnline = false;
    bool m_bSimulate = false;
    bool m_bPlcRunning = false;
    afx_msg void OnAppAbout();
    DECLARE_MESSAGE_MAP()
    afx_msg void OnFileNew();
@@ -110,3 +144,5 @@
int get_com_name(CString comx, CString &namebuf);
CString DeviceTypeToStr(int DeviceTypeVer);
MTerm1/MTerm1.rc
Binary files differ
MTerm1/MTerm1.vcxproj
@@ -191,9 +191,11 @@
  </ItemDefinitionGroup>
  <ItemGroup>
    <ClInclude Include="AnsiParser.h" />
    <ClInclude Include="CChidSysCfg1.h" />
    <ClInclude Include="CMyFuncKeyToolBar.h" />
    <ClInclude Include="CMyPaneInputShow.h" />
    <ClInclude Include="CMyPropPage.h" />
    <ClInclude Include="ConfigToolView.h" />
    <ClInclude Include="DataParser1.h" />
    <ClInclude Include="DialogCoilMon.h" />
    <ClInclude Include="DialogCommSet1.h" />
@@ -214,6 +216,8 @@
    <ClInclude Include="DialogStatusShow.h" />
    <ClInclude Include="DialogSysRegSet.h" />
    <ClInclude Include="ChildFrm.h" />
    <ClInclude Include="MyChildFrm.h" />
    <ClInclude Include="MyChildFrmConfig.h" />
    <ClInclude Include="MyDlgBarFuncKey.h" />
    <ClInclude Include="MyDlgBarInputShow.h" />
    <ClInclude Include="MyFormInputShow.h" />
@@ -249,9 +253,11 @@
  <ItemGroup>
    <ClCompile Include="..\MyLib\StaticEx.cpp" />
    <ClCompile Include="AnsiParser.cpp" />
    <ClCompile Include="CChidSysCfg1.cpp" />
    <ClCompile Include="CMyFuncKeyToolBar.cpp" />
    <ClCompile Include="CMyPaneInputShow.cpp" />
    <ClCompile Include="CMyPropPage.cpp" />
    <ClCompile Include="ConfigToolView.cpp" />
    <ClCompile Include="DataParser1.cpp" />
    <ClCompile Include="DialogCoilMon.cpp" />
    <ClCompile Include="DialogCommSet1.cpp" />
@@ -272,6 +278,8 @@
    <ClCompile Include="DialogStatusShow.cpp" />
    <ClCompile Include="DialogSysRegSet.cpp" />
    <ClCompile Include="ChildFrm.cpp" />
    <ClCompile Include="MyChildFrm.cpp" />
    <ClCompile Include="MyChildFrmConfig.cpp" />
    <ClCompile Include="MyDlgBarFuncKey.cpp" />
    <ClCompile Include="MyDlgBarInputShow.cpp" />
    <ClCompile Include="MyFormInputShow.cpp" />
@@ -330,6 +338,8 @@
    <Image Include="res\MTerm1.ico" />
    <Image Include="res\MTerm1Doc.ico" />
    <Image Include="res\sort.bmp" />
    <Image Include="res\sort1.bmp" />
    <Image Include="res\sort_25.bmp" />
    <Image Include="res\sort_hc.bmp" />
    <Image Include="res\Toolbar.bmp" />
    <Image Include="res\toolbar1.bmp" />
MTerm1/MTerm1.vcxproj.filters
@@ -180,6 +180,18 @@
    <ClInclude Include="MyFormInputShow.h">
      <Filter>头文件</Filter>
    </ClInclude>
    <ClInclude Include="MyChildFrm.h">
      <Filter>头文件</Filter>
    </ClInclude>
    <ClInclude Include="CChidSysCfg1.h">
      <Filter>头文件</Filter>
    </ClInclude>
    <ClInclude Include="ConfigToolView.h">
      <Filter>头文件</Filter>
    </ClInclude>
    <ClInclude Include="MyChildFrmConfig.h">
      <Filter>头文件</Filter>
    </ClInclude>
  </ItemGroup>
  <ItemGroup>
    <ClCompile Include="MainFrm.cpp">
@@ -338,6 +350,18 @@
    <ClCompile Include="IOPoint.cpp">
      <Filter>源文件</Filter>
    </ClCompile>
    <ClCompile Include="MyChildFrm.cpp">
      <Filter>源文件</Filter>
    </ClCompile>
    <ClCompile Include="CChidSysCfg1.cpp">
      <Filter>源文件</Filter>
    </ClCompile>
    <ClCompile Include="ConfigToolView.cpp">
      <Filter>源文件</Filter>
    </ClCompile>
    <ClCompile Include="MyChildFrmConfig.cpp">
      <Filter>源文件</Filter>
    </ClCompile>
  </ItemGroup>
  <ItemGroup>
    <ResourceCompile Include="MTerm1.rc">
@@ -420,6 +444,12 @@
    <Image Include="res\MTerm1Doc.ico">
      <Filter>资源文件</Filter>
    </Image>
    <Image Include="res\sort1.bmp">
      <Filter>资源文件</Filter>
    </Image>
    <Image Include="res\sort_25.bmp">
      <Filter>资源文件</Filter>
    </Image>
  </ItemGroup>
  <ItemGroup>
    <Text Include="design1.txt" />
MTerm1/MTerm1BnlView.cpp
@@ -5,12 +5,14 @@
#include "MTerm1.h"
#include "MTerm1BnlView.h"
#include "MTerm1Doc.h"
#include "ChildFrm.h"
// CMTerm1BnlView
IMPLEMENT_DYNCREATE(CMTerm1BnlView, CEditView)
IMPLEMENT_DYNCREATE(CMTerm1BnlView, CFormView)
CMTerm1BnlView::CMTerm1BnlView()
    : CFormView(IDD_MTerm1BnlView)
{
}
@@ -19,24 +21,41 @@
{
}
void CMTerm1BnlView::DoDataExchange(CDataExchange* pDX)
{
    CFormView::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CMTerm1BnlView, CEditView)
BEGIN_MESSAGE_MAP(CMTerm1BnlView, CFormView)
    ON_BN_CLICKED(IDC_BUTTON_LOAD, &CMTerm1BnlView::OnBnClickedButtonLoad)
    ON_BN_CLICKED(IDC_BUTTON_SAVE, &CMTerm1BnlView::OnBnClickedButtonSave)
    ON_BN_CLICKED(ID_PROG_CONVERT, &CMTerm1BnlView::OnBnClickedButtonConvert)
    ON_BN_CLICKED(IDC_BUTTON_CONVERT, &CMTerm1BnlView::OnBnClickedButtonConvert)
    ON_BN_CLICKED(IDC_BUTTON_TRNS_TOTXT, &CMTerm1BnlView::OnBnClickedButtonTrnsTotxt)
    ON_BN_CLICKED(IDC_BUTTON_TRNS_PRG, &CMTerm1BnlView::OnBnClickedButtonTrnsPrg)
    ON_BN_CLICKED(IDC_BUTTON4, &CMTerm1BnlView::OnBnClickedButton4)
    ON_WM_SIZE()
END_MESSAGE_MAP()
// CMTerm1BnlView 诊断
#ifdef _DEBUG
void CMTerm1BnlView::AssertValid() const
{
    CFormView::AssertValid();
}
#ifndef _WIN32_WCE
void CMTerm1BnlView::Dump(CDumpContext& dc) const
{
    CFormView::Dump(dc);
}
#endif
#endif //_DEBUG
// CMTerm1BnlView 绘图
void CMTerm1BnlView::OnInitialUpdate()
{
    CEditView::OnInitialUpdate();
    CMTerm1Doc * pDoc = (CMTerm1Doc *)GetDocument();
    pDoc->ProgTxt;
//    CSize sizeTotal;
//    // TODO:  计算此视图的合计大小
//    sizeTotal.cx = sizeTotal.cy = 100;
//    SetScrollSizes(MM_TEXT, sizeTotal);
}
void CMTerm1BnlView::OnDraw(CDC* pDC)
{
    CDocument* pDoc = GetDocument();
@@ -44,21 +63,140 @@
}
// CMTerm1BnlView 诊断
#ifdef _DEBUG
void CMTerm1BnlView::AssertValid() const
{
    CEditView::AssertValid();
}
#ifndef _WIN32_WCE
void CMTerm1BnlView::Dump(CDumpContext& dc) const
{
    CEditView::Dump(dc);
}
#endif
#endif //_DEBUG
// CMTerm1BnlView 消息处理程序
void CMTerm1BnlView::OnInitialUpdate()
{
    CFormView::OnInitialUpdate();
    // TODO: 在此添加专用代码和/或调用基类
    m_pStatusBar = ((CChildFrame*)GetParentFrame())->GetStatusBar();
    ResizeParentToFit();
    CMTerm1Doc* pDoc = (CMTerm1Doc*)GetDocument();
    this->GetParentFrame()->SetWindowText(pDoc->GetTitle());
    CString s1;
    CStringA s1A;
    pDoc->TransToTxt(s1A);
    s1 = s1A;
    SetDlgItemText(IDC_EDIT1, s1);
}
void CMTerm1BnlView::OnUpdate(CView* /*pSender*/, LPARAM lHint, CObject* /*pHint*/)
{
    // TODO: 在此添加专用代码和/或调用基类
    CMTerm1Doc* pDoc = (CMTerm1Doc*)GetDocument();
    CStringA s1A;
    pDoc->TransToTxt(s1A);
    CString s1;
    s1 = s1A;
    SetDlgItemText(IDC_EDIT1, s1);
    ((CEdit*)GetDlgItem(IDC_EDIT1))->SetSel((int)lHint, (int)lHint + 1);
}
void CMTerm1BnlView::OnBnClickedButtonLoad()
{
    // TODO: 在此添加控件通知处理程序代码
    CMTerm1Doc* pDoc = (CMTerm1Doc*)GetDocument();
    CFileDialog dialog1(true);
    INT_PTR r = dialog1.DoModal();
    if (r == IDOK)
    {
        CString sFilePathName = dialog1.GetFileName();
        pDoc->LoadFromFile(sFilePathName);
        //        pDoc->UpdateAllViews(NULL);
    }
}
void CMTerm1BnlView::OnBnClickedButtonSave()
{
    // TODO: 在此添加控件通知处理程序代码
    CString s1;
    CMTerm1Doc* pDoc = (CMTerm1Doc*)GetDocument();
    //    pDoc->DoFileSave();
}
void CMTerm1BnlView::OnBnClickedButtonConvert()
{
    // TODO: 在此添加控件通知处理程序代码
    CMTerm1Doc* pDoc = (CMTerm1Doc*)GetDocument();
    CString s1;
    CStringA s1A;
    GetDlgItemText(IDC_EDIT1, s1);
    s1A = s1;
    pDoc->TransTxtToProg(s1A);
    pDoc->TransToTxt(s1A);
    s1 = s1A;
    SetDlgItemText(IDC_EDIT1, s1);
    pDoc->UpdateAllViews(this);
}
void CMTerm1BnlView::OnBnClickedButtonTrnsTotxt()
{
    // TODO: 在此添加控件通知处理程序代码
    CMTerm1Doc* pDoc = (CMTerm1Doc*)GetDocument();
    CStringA s1A;
    pDoc->TransToTxt(s1A);
    CString s1;
    s1 = s1A;
    //    AnsiToT(s1A, s1);
    SetDlgItemText(IDC_EDIT1, s1);
}
void CMTerm1BnlView::OnBnClickedButtonTrnsPrg()
{
    // TODO: 在此添加控件通知处理程序代码
    CMTerm1Doc* pDoc = (CMTerm1Doc*)GetDocument();
    CString s1;
    CStringA s1A;
    GetDlgItemText(IDC_EDIT1, s1);
    s1A = s1;
    pDoc->TransFileToProg(s1A);
    pDoc->UpdateAllViews(this);
    //    AnsiToT(s1A, s1);
}
void CMTerm1BnlView::OnBnClickedButton4()
{
    // TODO: 在此添加控件通知处理程序代码
    CMTerm1Doc* pDoc = (CMTerm1Doc*)GetDocument();
    theApp.MyKLink1.fnTest1(2);
    CRect rect1;
    this->GetClientRect(&rect1);
    //    this->GetParentFrame()->SetWindowPos(NULL, rect1.left, rect1.top, 100, 200, SWP_NOZORDER);
}
void CMTerm1BnlView::OnSize(UINT nType, int cx, int cy)
{
    CFormView::OnSize(nType, cx, cy);
    CString s1;
    CWnd* pwnd;
    ///*
    pwnd = GetDlgItem(IDC_EDIT1);
    if (pwnd != NULL)
    {
        CRect    rect1;
        pwnd->GetWindowRect(rect1);
        ScreenToClient(rect1);
        pwnd->SetWindowPos(NULL, 0, 0, rect1.Width(), cy - 20, NULL);
        //        s1.Format(_T("OnSize %d  %d %d \r\n"), nType, cx, cy);
        //((CEdit*)GetDlgItem(IDC_EDIT1))->ReplaceSel(s1);
    }
    // */
    //
    // TODO: 在此处添加消息处理程序代码
}
MTerm1/MTerm1BnlView.h
@@ -4,7 +4,7 @@
// CMTerm1BnlView 视图
class CMTerm1BnlView : public CEditView
class CMTerm1BnlView : public CFormView
{
    DECLARE_DYNCREATE(CMTerm1BnlView)
@@ -13,6 +13,10 @@
    virtual ~CMTerm1BnlView();
public:
    CMFCStatusBar* m_pStatusBar;
#ifdef AFX_DESIGN_TIME
    enum { IDD = IDD_MTerm1BnlView };
#endif
#ifdef _DEBUG
    virtual void AssertValid() const;
#ifndef _WIN32_WCE
@@ -21,10 +25,21 @@
#endif
protected:
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV 支持
    virtual void OnDraw(CDC* pDC);      // 重写以绘制该视图
    virtual void OnInitialUpdate();     // 构造后的第一次
//    virtual void OnInitialUpdate();     // 构造后的第一次
    DECLARE_MESSAGE_MAP()
public:
    virtual void OnInitialUpdate();
    afx_msg void OnBnClickedButtonLoad();
    afx_msg void OnBnClickedButtonSave();
    afx_msg void OnBnClickedButtonConvert();
    afx_msg void OnBnClickedButtonTrnsTotxt();
    afx_msg void OnBnClickedButtonTrnsPrg();
    virtual void OnUpdate(CView* /*pSender*/, LPARAM /*lHint*/, CObject* /*pHint*/);
    afx_msg void OnBnClickedButton4();
    afx_msg void OnSize(UINT nType, int cx, int cy);
};
MTerm1/MTerm1CommDevView.cpp
@@ -138,17 +138,19 @@
//    ON_WM_MOUSEWHEEL()
//    ON_BN_CLICKED(IDC_BUTTON_CLEAR_STAT, &CMTerm1CommDevView::OnBnClickedButtonClearStat)
//    ON_BN_CLICKED(IDC_BUTTON_READ, &CMTerm1CommDevView::OnBnClickedButtonRead)
//    ON_BN_CLICKED(IDC_BUTTON11, &CMTerm1CommDevView::OnBnClickedButton11)
    ON_BN_CLICKED(IDC_BUTTON11, &CMTerm1CommDevView::OnBnClickedButton11)
    ON_BN_CLICKED(IDC_BUTTON12, &CMTerm1CommDevView::OnBnClickedButton12)
    ON_BN_CLICKED(IDC_BUTTON13, &CMTerm1CommDevView::OnBnClickedButton13)
    ON_BN_CLICKED(IDC_BUTTON31, &CMTerm1CommDevView::OnBnClickedButton31)
    ON_BN_CLICKED(IDC_BUTTON2, &CMTerm1CommDevView::OnBnClickedButton2)
    ON_BN_CLICKED(IDC_BUTTON3, &CMTerm1CommDevView::OnBnClickedButton3)
    ON_BN_CLICKED(IDC_BUTTON5, &CMTerm1CommDevView::OnBnClickedButton5)
    ON_BN_CLICKED(IDC_BUTTON9, &CMTerm1CommDevView::OnBnClickedButton9)
END_MESSAGE_MAP()
// CMTerm1CommDevView 诊断
/*
#ifdef _DEBUG
void CMTerm1CommDevView::AssertValid() const
{
@@ -162,7 +164,13 @@
}
#endif
#endif //_DEBUG
*/
BOOL CMTerm1CommDevView::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext)
{
    // TODO: 在此添加专用代码和/或调用基类
    return CFormView::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext);
}
// CMTerm1CommDevView 消息处理程序
@@ -256,9 +264,9 @@
int CMTerm1CommDevView::Clear_COM_Stats()
{
    // TODO: 在此处添加实现代码.
    CMTerm1Doc *pDoc = (CMTerm1Doc *)GetDocument();
    pDoc->MyKLink1.MySerPort1.TotalSendBytes = 0;
    pDoc->MyKLink1.MySerPort1.TotalRecvBytes = 0;
    // CMTerm1Doc *pDoc = (CMTerm1Doc *)GetDocument();
    theApp.MyKLink1.MySerPort1.TotalSendBytes = 0;
    theApp.MyKLink1.MySerPort1.TotalRecvBytes = 0;
    MonitorTotalCount = 0;
    MonitorSuccessCount = 0;
@@ -268,20 +276,20 @@
int CMTerm1CommDevView::UpdateDataDisplay()
{
    CMTerm1Doc *pDoc = (CMTerm1Doc *)GetDocument();
    // CMTerm1Doc *pDoc = (CMTerm1Doc *)GetDocument();
    if (!m_bOnline) return 0;
    static int stepCount = 0;
    CString s1, s2;
    pDoc->MyKLink1.MySerPort1.CalSpeed();
    s1.Format(_T("Send %8d %5d Bps \r\nRecv %8d %5d Bps\r\n"), pDoc->MyKLink1.MySerPort1.TotalSendBytes, pDoc->MyKLink1.MySerPort1.SendSpeed, pDoc->MyKLink1.MySerPort1.TotalRecvBytes, pDoc->MyKLink1.MySerPort1.RecvSpeed);
    theApp.MyKLink1.MySerPort1.CalSpeed();
    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);
    //    s1.AppendFormat(_T("Total S %8d \r\nTotal R %8d \r\n"), MySerialCom1.TotalSendBytes, MySerialCom1.TotalRecvBytes);
    s1 += intToString(pDoc->MyKLink1.MySerPort1.TotalRecvBytes) + _T("\r\n");
    s1 += intToString(theApp.MyKLink1.MySerPort1.TotalRecvBytes) + _T("\r\n");
    //    stepCount++;
//    static double LastCalTime = 0;
//    double thisTime = GetTimemS();
    pDoc->MyKLink1.CalSpeed();
    theApp.MyKLink1.CalSpeed();
/*
    if (thisTime - LastCalTime > 500)
    {
@@ -292,39 +300,93 @@
    }
*/
    s1.AppendFormat(_T("MT %6d Seq %d/%d %d/S \r\nOK %6d NG %d "),
        pDoc->MyKLink1.m_nTotalSendCount, pDoc->MyKLink1.m_nSeq, pDoc->MyKLink1.m_nRSeq, pDoc->MyKLink1.m_SendSpeed,
        pDoc->MyKLink1.m_nTotalRecvCount, pDoc->MyKLink1.m_nTotalSendCount-pDoc->MyKLink1.m_nTotalRecvCount);
        theApp.MyKLink1.m_nTotalSendCount, theApp.MyKLink1.m_nSeq, theApp.MyKLink1.m_nRSeq, theApp.MyKLink1.m_SendSpeed,
        theApp.MyKLink1.m_nTotalRecvCount, theApp.MyKLink1.m_nTotalSendCount-theApp.MyKLink1.m_nTotalRecvCount);
    SetDlgItemText(IDC_STATIC_SPEED, s1);
    if (!m_bMonitoring) return 0;
    int nCount = 32;
    s2.Empty();//    s2.AppendFormat(_T("%d    "), MonitorSuccessCount);
    nCount = 16;
    s2.Append(_T("WX  "));
    s2.Append(_T("WX   "));
    for (int i = 0; i < (nCount + 15) / 16; i++)
    {
        //s2.AppendFormat(_T("%02X: "), i * 16);
        for (int j = 0; j < 8; j++)
        for (int j = 0; j < 16; j++)
        {
            s2.AppendFormat(_T("%04X"), pDoc->MyKLink1.MEM.WX[i * 8 + j]);
            s2.AppendFormat(_T("%02X"), theApp.MyKLink1.MEM.WXB[i * 16 + j]);
            if (j == 7) { s2.Append(_T("  ")); }
            else { s2.Append(_T(" ")); }
        }
        s2.Append(_T("\r\n"));
    }
    nCount = 16;
    s2.Append(_T("WY   "));
    for (int i = 0; i < (nCount + 15) / 16; i++)
    {
        // s2.AppendFormat(_T("%02X: "), i * 16);
        for (int j = 0; j < 16; j++)
        {
            s2.AppendFormat(_T("%02X"), theApp.MyKLink1.MEM.WYB[i * 16 + j]);
            if (j == 7) { s2.Append(_T("  ")); }
            else { s2.Append(_T(" ")); }
        }
        s2.Append(_T("\r\n"));
    }
    nCount = 16;
    s2.Append(_T("WLX  "));
    for (int i = 0; i < (nCount + 15) / 16; i++)
    {
        //s2.AppendFormat(_T("%02X: "), i * 16);
        for (int j = 0; j < 16; j++)
        {
            s2.AppendFormat(_T("%02X"), theApp.MyKLink1.MEM.WLXB[i * 16 + j]);
            if (j == 7) { s2.Append(_T("  ")); }
            else { s2.Append(_T(" ")); }
        }
        s2.Append(_T("\r\n"));
    }
    nCount = 16;
    s2.Append(_T("WLY  "));
    for (int i = 0; i < (nCount + 15) / 16; i++)
    {
        // s2.AppendFormat(_T("%02X: "), i * 16);
        for (int j = 0; j < 16; j++)
        {
            s2.AppendFormat(_T("%02X"), theApp.MyKLink1.MEM.WLYB[i * 16 + j]);
            if (j == 7) { s2.Append(_T("  ")); }
            else { s2.Append(_T(" ")); }
        }
        s2.Append(_T("\r\n"));
    }
/*
    nCount = 16;
    s2.Append(_T("WFX  "));
    for (int i = 0; i < (nCount + 15) / 16; i++)
    {
        //s2.AppendFormat(_T("%02X: "), i * 16);
        for (int j = 0; j < 16; j++)
        {
            s2.AppendFormat(_T("%04X"), theApp.MyKLink1.MEM.WFXB[i * 16 + j]);
            if (j == 3) { s2.Append(_T("  ")); }
            else { s2.Append(_T(" ")); }
        }
        s2.Append(_T("\r\n"));
    }
    nCount = 16;
    s2.Append(_T("WY  "));
    s2.Append(_T("WFY  "));
    for (int i = 0; i < (nCount + 15) / 16; i++)
    {
        // s2.AppendFormat(_T("%02X: "), i * 16);
        for (int j = 0; j < 8; j++)
        for (int j = 0; j < 16; j++)
        {
            s2.AppendFormat(_T("%04X"), pDoc->MyKLink1.MEM.WY[i * 8 + j]);
            s2.AppendFormat(_T("%04X"), theApp.MyKLink1.MEM.WFYB[i * 16 + j]);
            if (j == 3) { s2.Append(_T("  ")); }
            else { s2.Append(_T(" ")); }
        }
        s2.Append(_T("\r\n"));
    }
*/
    nCount = 32;
    s2.Append(_T("  WR\r\n"));
    for (int i = 0; i < (nCount + 15) / 16; i++)
@@ -332,7 +394,7 @@
        s2.AppendFormat(_T("%02X: "), i * 16);
        for (int j = 0; j < 8; j++)
        {
            s2.AppendFormat(_T("%04X"), pDoc->MyKLink1.MEM.WR[i * 8 + j]);
            s2.AppendFormat(_T("%04X"), theApp.MyKLink1.MEM.WR[i * 8 + j]);
            if (j == 3) { s2.Append(_T("  ")); }
            else { s2.Append(_T(" ")); }
        }
@@ -345,7 +407,7 @@
        s2.AppendFormat(_T("%02X: "), i * 16);
        for (int j = 0; j < 8; j++)
        {
            s2.AppendFormat(_T("%04X"), pDoc->MyKLink1.MEM.DT[i * 8 + j]);
            s2.AppendFormat(_T("%04X"), theApp.MyKLink1.MEM.DT[i * 8 + j]);
            if (j == 3) { s2.Append(_T("  ")); }
            else { s2.Append(_T(" ")); }
        }
@@ -358,7 +420,7 @@
        s2.AppendFormat(_T("%3X: "), i * 16);
        for (int j = 0; j < 8; j++)
        {
            s2.AppendFormat(_T("%04X"), pDoc->MyKLink1.MEM.SDT[i * 8 + j]);
            s2.AppendFormat(_T("%04X"), theApp.MyKLink1.MEM.SDT[i * 8 + j]);
            if (j == 3) { s2.Append(_T("  ")); }
            else { s2.Append(_T(" ")); }
        }
@@ -375,7 +437,7 @@
        s2.AppendFormat(_T("%3X: "), i * 16);
        for (int j = 0; j < 16; j++)
        {
            s2.AppendFormat(_T("%02X"), pDoc->MyKLink1.MEM.WDB[i * 16 + j]);
            s2.AppendFormat(_T("%02X"), theApp.MyKLink1.MEM.WDB[i * 16 + j]);
            if (j == 7) { s2.Append(_T("  ")); }
            else { s2.Append(_T(" ")); }
        }
@@ -385,7 +447,7 @@
        SetDlgItemText(IDC_EDIT_MON3, s2);
    }
    //    s2.AppendFormat(_T("%d\r\n"), pDoc->MyKLink1.MEM.SDD[5]);
    //    s2.AppendFormat(_T("%d\r\n"), theApp.MyKLink1.MEM.SDD[5]);
    nCount = 32;
    //SetRedraw(FALSE);
@@ -395,23 +457,20 @@
        s1.Empty();
        s1.Format(_T("主机\r\n"));
        s1.AppendFormat(_T("00 跳线 %02X %s 当前 %02X\r\n"), pDoc->MyKLink1.MEM.SDD[0], intToBinString(pDoc->MyKLink1.MEM.SDD[0]), pDoc->MyKLink1.MEM.SDD[1]);
        //        s1.AppendFormat(_T("当前跳线 %02X %s\r\n"), pDoc->MyKLink1.MEM.SDD[1], intToBinString(pDoc->MyKLink1.MEM.SDD[1]));
        s1.AppendFormat(_T("02 Tick计数  %u \r\n"), pDoc->MyKLink1.MEM.SDD[2]);
        s1.AppendFormat(_T("03 nRunCount %u \r\n"), pDoc->MyKLink1.MEM.SDD[3]);
        s1.AppendFormat(_T("04 RunStat %d \r\n"), pDoc->MyKLink1.MEM.SDD[4]);
        s1.AppendFormat(_T("05 ErrStat %d \r\n"), pDoc->MyKLink1.MEM.SDD[5]);
        s1.AppendFormat(_T("06 PwrOnCount %d \r\n"), pDoc->MyKLink1.MEM.SDD[6]);
        s1.AppendFormat(_T("07 ThisRunTime %d \r\n"), pDoc->MyKLink1.MEM.SDD[7]);
        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]);
        //        s1.AppendFormat(_T("当前跳线 %02X %s\r\n"), theApp.MyKLink1.MEM.SDD[1], intToBinString(theApp.MyKLink1.MEM.SDD[1]));
        s1.AppendFormat(_T("02 Tick计数  %u \r\n"), theApp.MyKLink1.MEM.SDD[2]);
        s1.AppendFormat(_T("03 nRunCount %u \r\n"), theApp.MyKLink1.MEM.SDD[3]);
        s1.AppendFormat(_T("04 RunStat %d \r\n"), theApp.MyKLink1.MEM.SDD[4]);
        s1.AppendFormat(_T("05 ErrStat %d \r\n"), theApp.MyKLink1.MEM.SDD[5]);
        s1.AppendFormat(_T("06 PwrOnCount %d \r\n"), theApp.MyKLink1.MEM.SDD[6]);
        int nTime1 = theApp.MyKLink1.MEM.SDD[7];
        s1.AppendFormat(_T("07 ThisRunTime %d  %dd %02d:%02d:%02d\r\n"), nTime1, nTime1 / 86400, nTime1 / 3600 % 24, nTime1 / 60 % 60, nTime1 % 60);
        nTime1 = theApp.MyKLink1.MEM.SDD[8];
        s1.AppendFormat(_T("08 TotalTime   %d  %dd %02d:%02d:%02d\r\n"), nTime1, nTime1 / 86400, nTime1 / 3600 % 24, nTime1 / 60 % 60, nTime1 % 60);
        s1.AppendFormat(_T("09 CurTime %d "), theApp.MyKLink1.MEM.SDD[9]);
        int nTime1 = pDoc->MyKLink1.MEM.SDD[7];
        s1.AppendFormat(_T("%dd %02d:%02d:%02d \r\n"), nTime1 / 86400, nTime1 / 3600 % 24, nTime1 / 60 % 60, nTime1 % 60);
        s1.AppendFormat(_T("08 TotalTime %d \r\n"), pDoc->MyKLink1.MEM.SDD[8]);
        nTime1 = pDoc->MyKLink1.MEM.SDD[8];
        s1.AppendFormat(_T("%dd %02d:%02d:%02d \r\n"), nTime1 / 86400, nTime1 / 3600 % 24, nTime1 / 60 % 60, nTime1 % 60);
        s1.AppendFormat(_T("09 CurTime %d \r\n"), pDoc->MyKLink1.MEM.SDD[9]);
        nTime1 = pDoc->MyKLink1.MEM.SDD[9];
        nTime1 = theApp.MyKLink1.MEM.SDD[9];
        __time32_t time1 = nTime1;
        CString s3;
        //_tctime32_s(s3.GetBuffer(1024),1024, &time1);
@@ -421,9 +480,9 @@
        if (nTime1 >= 0) s3 = ctime1.Format(_T("%Y-%m-%d %H:%M:%S"));
        s1.Append(s3 + _T("\r\n"));
        //        s1.AppendFormat(_T("%04d-%02d-%02d %02d:%02d:%02d \r\n"), nTime1 / 86400, nTime1 / 3600 % 24, nTime1 / 60 % 60, nTime1 % 60);
        s1.AppendFormat(_T("10 PwrFailCount %d \r\n"), pDoc->MyKLink1.MEM.SDD[10]);
        s1.AppendFormat(_T("11 LastPwrFailTime %d \r\n"), pDoc->MyKLink1.MEM.SDD[11]);
        nTime1 = pDoc->MyKLink1.MEM.SDD[11];
        s1.AppendFormat(_T("10 PwrFailCount %d \r\n"), theApp.MyKLink1.MEM.SDD[10]);
        s1.AppendFormat(_T("11 LastPwrFailTime %d \r\n"), theApp.MyKLink1.MEM.SDD[11]);
        nTime1 = theApp.MyKLink1.MEM.SDD[11];
        time1 = nTime1;
        _tctime32_s(s3.GetBuffer(1024), 1024, &time1);
        s3.ReleaseBuffer();
@@ -434,33 +493,41 @@
        s3 = ctime1.Format(_T("%Y-%m-%d %H:%M:%S"));
        s1.Append(s3 + _T("\r\n"));
        s1.AppendFormat(_T("12 LastScanTime uS %u \r\n"), pDoc->MyKLink1.MEM.SDD[12]);
        s1.AppendFormat(_T("13 ScanTime uS %d  \r\n"), pDoc->MyKLink1.MEM.SDD[13]);
        s1.AppendFormat(_T("14 MinScanTime uS %d \r\n"), pDoc->MyKLink1.MEM.SDD[14]);
        s1.AppendFormat(_T("15 %d \r\n"), pDoc->MyKLink1.MEM.SDD[15]);
        s1.AppendFormat(_T("16 %d \r\n"), pDoc->MyKLink1.MEM.SDD[16]);
        s1.AppendFormat(_T("17 %d \r\n"), pDoc->MyKLink1.MEM.SDD[17]);
        s1.AppendFormat(_T("18 %d \r\n"), pDoc->MyKLink1.MEM.SDD[18]);
        s1.AppendFormat(_T("19 %d \r\n"), pDoc->MyKLink1.MEM.SDD[19]);
        s1.AppendFormat(_T("20 %d \r\n"), pDoc->MyKLink1.MEM.SDD[20]);
        s1.AppendFormat(_T("21 %d \r\n"), pDoc->MyKLink1.MEM.SDD[21]);
        s1.AppendFormat(_T("22 %d \r\n"), pDoc->MyKLink1.MEM.SDD[22]);
        s1.AppendFormat(_T("23 %d \r\n"), pDoc->MyKLink1.MEM.SDD[23]);
        s1.AppendFormat(_T("12 LastScanTime uS %u \r\n"), theApp.MyKLink1.MEM.SDD[12]);
        s1.AppendFormat(_T("13 ScanTime uS %d  \r\n"), theApp.MyKLink1.MEM.SDD[13]);
        s1.AppendFormat(_T("14 MinScanTime uS %d \r\n"), theApp.MyKLink1.MEM.SDD[14]);
        s1.AppendFormat(_T("15 %d \r\n"), theApp.MyKLink1.MEM.SDD[15]);
        s1.AppendFormat(_T("16 %d \r\n"), theApp.MyKLink1.MEM.SDD[16]);
        s1.AppendFormat(_T("17 %d \r\n"), theApp.MyKLink1.MEM.SDD[17]);
        s1.AppendFormat(_T("18 %d \r\n"), theApp.MyKLink1.MEM.SDD[18]);
        s1.AppendFormat(_T("19 %d \r\n"), theApp.MyKLink1.MEM.SDD[19]);
        s1.AppendFormat(_T("20 %d \r\n"), theApp.MyKLink1.MEM.SDD[20]);
//        s1.AppendFormat(_T("21 %d \r\n"), theApp.MyKLink1.MEM.SDD[21]);
//        s1.AppendFormat(_T("22 %d \r\n"), theApp.MyKLink1.MEM.SDD[22]);
//        s1.AppendFormat(_T("23 %d \r\n"), theApp.MyKLink1.MEM.SDD[23]);
        float Vref = 1.2f;
        float Vcor = (float)pDoc->MyKLink1.MEM.SDT[53] / pDoc->MyKLink1.MEM.SDT[55];
        //theApp.MyKLink1.MEM.SDT[56] = 1521;
        float Vcor = (float)theApp.MyKLink1.MEM.SDT[48 + 18] / theApp.MyKLink1.MEM.SDT[48 + 17];
        float V33 = 3.3f * Vcor;
        s1.AppendFormat(_T("24 24V电压 %d %.2f V \r\n"), pDoc->MyKLink1.MEM.SDT[48], pDoc->MyKLink1.MEM.SDT[48] * V33 / 4096 * 11);
        s1.AppendFormat(_T("25 %d \r\n"), pDoc->MyKLink1.MEM.SDT[49]);
        s1.AppendFormat(_T("26 5V 电压 %d %.3f V \r\n"), pDoc->MyKLink1.MEM.SDT[50], pDoc->MyKLink1.MEM.SDT[50] * V33 / 4096 * 2);
        s1.AppendFormat(_T("27 %d \r\n"), pDoc->MyKLink1.MEM.SDT[51]);
        s1.AppendFormat(_T("28 %d \r\n"), pDoc->MyKLink1.MEM.SDT[52]);
        s1.AppendFormat(_T("29 %d \r\n"), pDoc->MyKLink1.MEM.SDT[53]);
        float temp = (1430 - pDoc->MyKLink1.MEM.SDT[54]* 0.806f ) / 4.3f + 25;
        s1.AppendFormat(_T("30 芯片温度 %d %.1f ℃ \r\n"), pDoc->MyKLink1.MEM.SDT[54],temp);
        s1.AppendFormat(_T("31 1.2V参考 %d  3.3V电压 %.3f V \r\n"), pDoc->MyKLink1.MEM.SDT[55], V33);
        s1.AppendFormat(_T("24 ADC0 %d  \r\n"), theApp.MyKLink1.MEM.SDT[48 + 0]);
        s1.AppendFormat(_T("25 ADC1 %d \r\n"), theApp.MyKLink1.MEM.SDT[48 + 1]);
        s1.AppendFormat(_T("26 ADC2 %d  \r\n"), theApp.MyKLink1.MEM.SDT[48 + 2]);
        s1.AppendFormat(_T("27 ADC3 %d \r\n"), theApp.MyKLink1.MEM.SDT[48 + 3]);
        s1.AppendFormat(_T("28 ADC4 %d \r\n"), theApp.MyKLink1.MEM.SDT[48 + 4]);
        s1.AppendFormat(_T("29 ADC5 %d \r\n"), theApp.MyKLink1.MEM.SDT[48 + 5]);
        s1.AppendFormat(_T("30 ADC6 %d \r\n"), theApp.MyKLink1.MEM.SDT[48 + 6]);
        s1.AppendFormat(_T("30 ADC7 %d \r\n"), theApp.MyKLink1.MEM.SDT[48 + 7]);
        s1.AppendFormat(_T("30 ADC8 %d \r\n"), theApp.MyKLink1.MEM.SDT[48 + 8]);
        float temp = (1430 - theApp.MyKLink1.MEM.SDT[48 + 16]* 0.806f ) / 4.3f + 25;
        s1.AppendFormat(_T("31 芯片温度 %d %.1f ℃ \r\n"), theApp.MyKLink1.MEM.SDT[48 + 16],temp);
        s1.AppendFormat(_T("32 1.2V参考 %d  3.3V电压 %.3f V \r\n"), theApp.MyKLink1.MEM.SDT[48 + 17], V33);
        s1.AppendFormat(_T("33 1.2V校准电压 %d  \r\n"), theApp.MyKLink1.MEM.SDT[48 + 18]);
        s2 += s1;
        s2.AppendFormat(_T("\r\n"));
        //型号
@@ -487,12 +554,28 @@
        //令牌  广播形式, 环路形式
        //
        s1.Format(_T("PosX     %d \r\n"), (signed short)theApp.MyKLink1.MEM.WDT[24]);
        s1.AppendFormat(_T("PosY     %d \r\n"),(signed short) theApp.MyKLink1.MEM.WDT[25]);
        s1.AppendFormat(_T("PosZ     %d \r\n"), theApp.MyKLink1.MEM.WDT[26]);
        s1.AppendFormat(_T("PosZ1     %d \r\n"), theApp.MyKLink1.MEM.WDT[27]);
        s1.AppendFormat(_T("PosZ2     %d \r\n"), theApp.MyKLink1.MEM.WDT[28]);
        s1.AppendFormat(_T("PosZ3     %d \r\n"), theApp.MyKLink1.MEM.WDT[29]);
        s1.AppendFormat(_T("result0     %d \r\n"), (signed short)theApp.MyKLink1.MEM.WDT[32]);
        s1.AppendFormat(_T("result1     %d \r\n"), (signed short)theApp.MyKLink1.MEM.WDT[33]);
        s1.AppendFormat(_T("result2     %d \r\n"), (signed short)theApp.MyKLink1.MEM.WDT[34]);
        s1.AppendFormat(_T("result3     %d \r\n"), (signed short)theApp.MyKLink1.MEM.WDT[35]);
        s1.AppendFormat(_T("result4     %d \r\n"), (signed short)theApp.MyKLink1.MEM.WDT[36]);
        s1.AppendFormat(_T("result5     %d \r\n"), (signed short)theApp.MyKLink1.MEM.WDT[37]);
        s1.AppendFormat(_T("result6     %d \r\n"), (signed short)theApp.MyKLink1.MEM.WDT[38]);
        s1.AppendFormat(_T("result7     %d \r\n"), (signed short)theApp.MyKLink1.MEM.WDT[39]);
        s2 += s1;
        s2.AppendFormat(_T("\r\n"));
/*
        int nOffset = 32;
        s1.Empty();
        s1.Format(_T("子机1\r\n"));
        KLink1::pChnStat pchnstat1 = (KLink1::pChnStat)&(pDoc->MyKLink1.MEM.SDD[nOffset + 0]);
        KLink1::pChnStat pchnstat1 = (KLink1::pChnStat)&(theApp.MyKLink1.MEM.SDD[nOffset + 0]);
        unsigned int nSendPackets = pchnstat1->SendPackets;
        s1.AppendFormat(_T("当前状态: %04X\r\n"), pchnstat1->Stat);
        s1.AppendFormat(_T("发收包数:%6d/%6d(%.2f%%)\r\n发送时间 %10u (uS)\r\n"),
@@ -519,7 +602,7 @@
        nOffset = 32 + 24;
        s1.Format(_T("子机2\r\n"));
        pchnstat1 = (KLink1::pChnStat)&(pDoc->MyKLink1.MEM.SDD[nOffset + 0]);
        pchnstat1 = (KLink1::pChnStat)&(theApp.MyKLink1.MEM.SDD[nOffset + 0]);
        nSendPackets = pchnstat1->SendPackets;
        s1.AppendFormat(_T("当前状态: %04X\r\n"), pchnstat1->Stat);
        s1.AppendFormat(_T("发收包数:%6d/%6d(%.2f%%)\r\n发送时间 %10u (uS)\r\n"),
@@ -542,37 +625,16 @@
            pchnstat1->ClientSendPkts);
        s2 += s1;
// */
        //m_edit_mon2.SetSel(0, -1);
        //m_edit_mon2.ReplaceSel(s2);
        SetDlgItemText(IDC_EDIT_MON2, s2);
    }
    s1.Empty();
    pstWLRunStat  pWLRunStat = (pstWLRunStat)(&pDoc->KWLB);
    s1.Format(_T("状态   %04X %04X 步骤 %04X \r\n"), pWLRunStat->Stat, pWLRunStat->curStat, pWLRunStat->runStep);
    s1 += _T("发送数量: ") + intToString(pWLRunStat->sentCount) + _T("   对方收到: ") + intToString(pWLRunStat->targetRecvdCount) + _T("   差值: ") + intToString(pWLRunStat->sentCount - pWLRunStat->targetRecvdCount)  + _T("\r\n");
    s1 += _T("接收数量: ") + intToString(pWLRunStat->recvCount) + _T("   对方发出: ") + intToString(pWLRunStat->targetSentCount) + _T("   差值: ") + intToString(pWLRunStat->targetSentCount - pWLRunStat->recvCount) + _T("\r\n");
    s1 += _T("发送时间: ") + fixToString(pWLRunStat->lastSendtime,0,1) + _T(" mS\r\n");
    s1 += _T("发完时间: ") + fixToString(pWLRunStat->lastSenttime, 0, 1) + _T("   ") + fixToString(pWLRunStat->lastSenttime - pWLRunStat->lastSendtime, 0, 1) + _T(" mS\r\n");
    s1 += _T("接收时间: ") + fixToString(pWLRunStat->lastRecvtime,0,1) + _T(" mS\r\n");
    s1 += _T("收到时间: ") + fixToString(pWLRunStat->lastRecvdtime, 0, 1)  + _T("   ") + fixToString(pWLRunStat->lastRecvdtime - pWLRunStat->lastRecvtime, 0, 1) + +_T(" mS\r\n");
    s1 += _T("动作时间: ") + fixToString(pWLRunStat->lastActTime,0,1) + _T(" mS\r\n");
    s1 += _T("响应时间: ") +  fixToString(pWLRunStat->lastAckTime,0,1) + _T("   ") + fixToString(pWLRunStat->lastAckTime - pWLRunStat->lastActTime, 0, 1) + _T(" mS\r\n");
    s1 += _T("循环时间: ") + fixToString(pWLRunStat->cycleTime,0,1) + _T(" mS\r\n");
    s1 += _T("延迟:     ") + fixToString(pWLRunStat->latancy,0,1) + _T(" mS\r\n");
    s1.AppendFormat(_T("丢包数量: %d     连续丢包: %d    最大连续  %d\r\n"), pWLRunStat->LostPackets, pWLRunStat->CtnLstPkts, pWLRunStat->MaxCtnLstPkts);
    s1.AppendFormat(_T("发送错误: %d     接收错误: %d    时间 %s mS\r\n"), pWLRunStat->TXErr, pWLRunStat->RXErr, fixToString(pWLRunStat->lastErrTime,0,1));
    s1.AppendFormat(_T("CRC错误:  %d\r\n"), pWLRunStat->CRCErr);
    s1.AppendFormat(_T("CAD次数:  %d\r\n"), pWLRunStat->CADDoneCount);
    s1.AppendFormat(_T("小错误1: %d     中错误2: %d     大错误3: %d\r\n"), pWLRunStat->Err1Count, pWLRunStat->Err2Count, pWLRunStat->Err3Count);
    s1.AppendFormat(_T("步骤错误1: %d     步骤错误2: %d\r\n"), pWLRunStat->StepErr1, pWLRunStat->StepErr2);
    s1.AppendFormat(_T("本机信号强度: %d dBm  SNR %d dBm\r\n"), pWLRunStat->RSSI, pWLRunStat->SNR);
    s1.AppendFormat(_T("对方信号强度: %d dBm  SNR %d dBm\r\n"), pWLRunStat->tRSSI, pWLRunStat->tSNR);
//    pstWLRunStat  pWLRunStat = (pstWLRunStat)(theApp.MyKLink1.MEM.KWLB);
    s1 = KWRunStatToString((pstWLRunStat)(theApp.MyKLink1.MEM.KWLB));
    SetDlgItemText(IDC_EDIT_MON4, s1);
    //SetRedraw(TRUE);
    //s1.Append(s2);
@@ -580,11 +642,127 @@
    UpdateStatusBar(-1);
    return 0;
}
CString CMTerm1CommDevView::KWRunStatToString(pstWLRunStat pWLRunStat1)
{
    CString s1;
    //    pstWLRunStat  pWLRunStat1 = (pstWLRunStat)(theApp.MyKLink1.MEM.KWLB);
    s1.Format(_T("stsize %d 无线状态   %04X %04X 步骤 %04X \r\n"), sizeof(stWLRunStat), pWLRunStat1->Status, pWLRunStat1->curStat, pWLRunStat1->runStep);
    s1.AppendFormat(_T("频率 %.3f Bw %d TxP %ddBm Fctr %d CDR %d ToA %dmS\r\n"),
        float(pWLRunStat1->RF_Freq / 1000000.0f), pWLRunStat1->LoraBandWidth, pWLRunStat1->Tx_Power, pWLRunStat1->LoRaFactor, pWLRunStat1->LoRaCodingRate, pWLRunStat1->nTimeOnAir);
    s1 += _T("当前子机: ") + intToString(pWLRunStat1->nCurClient) + _T("\r\n");
//    s1 += _T("频率: ") + intToString(pWLRunStat1->RF_Freq) + _T("   空中时间: ") + intToString(pWLRunStat1->nTimeOnAir) + _T("\r\n");
//    s1 += _T("BW: ") + intToString(pWLRunStat1->LoraBandWidth) + _T("  Tx_Pwr: ") + intToString(pWLRunStat1->Tx_Power) +_T("  ");
//    s1 += _T("Factor: ") + intToString(pWLRunStat1->LoRaFactor) + _T("  CodingRate : ") + intToString(pWLRunStat1->LoRaCodingRate) + _T("\r\n");
    s1 += _T("发送数量: ") + intToString(pWLRunStat1->sentCount) + _T("   对方收到: ") + intToString(pWLRunStat1->targetRecvdCount) + _T("   差值: ") + intToString(pWLRunStat1->sentCount - pWLRunStat1->targetRecvdCount) + _T("\r\n");
    s1 += _T("接收数量: ") + intToString(pWLRunStat1->recvCount) + _T("   对方发出: ") + intToString(pWLRunStat1->targetSentCount) + _T("   差值: ") + intToString(pWLRunStat1->targetSentCount - pWLRunStat1->recvCount) + _T("\r\n");
    s1 += _T("发送时间: ") + fixToString(pWLRunStat1->lastSendtime, 0, 1) + _T(" mS\r\n");
    s1 += _T("发完时间: ") + fixToString(pWLRunStat1->lastSenttime, 0, 1) + _T("   ") + fixToString(pWLRunStat1->lastSenttime - pWLRunStat1->lastSendtime, 0, 1) + _T(" mS\r\n");
    s1 += _T("接收时间: ") + fixToString(pWLRunStat1->lastRecvtime, 0, 1) + _T(" mS\r\n");
    s1 += _T("收到时间: ") + fixToString(pWLRunStat1->lastRecvdtime, 0, 1) + _T("   ") + fixToString(pWLRunStat1->lastRecvdtime - pWLRunStat1->lastRecvtime, 0, 1) + +_T(" mS\r\n");
    s1 += _T("动作时间: ") + fixToString(pWLRunStat1->lastActTime, 0, 1) + _T(" mS\r\n");
    s1 += _T("响应时间: ") + fixToString(pWLRunStat1->lastAckTime, 0, 1) + _T("   ") + fixToString(pWLRunStat1->lastAckTime - pWLRunStat1->lastActTime, 0, 1) + _T(" mS\r\n");
    s1 += _T("循环时间: ") + fixToString(pWLRunStat1->cycleTime, 0, 1) + _T(" mS\r\n");
    s1 += _T("延迟:     ") + fixToString(pWLRunStat1->latancy, 0, 1) + _T(" mS\r\n");
    s1.AppendFormat(_T("丢包数量: %d     连续丢包: %d    最大连续  %d\r\n"), pWLRunStat1->LostPackets, pWLRunStat1->CtnLstPkts, pWLRunStat1->MaxCtnLstPkts);
    s1.AppendFormat(_T("发送错误: %d     接收错误: %d    时间 %s mS\r\n"), pWLRunStat1->TXErr, pWLRunStat1->RXErr, fixToString(pWLRunStat1->lastErrTime, 0, 1));
    s1.AppendFormat(_T("CRC错误:  %d   包格式错误  %d   地址错误  %d   %04X\r\n"), pWLRunStat1->CRCErr, pWLRunStat1->PktErr, pWLRunStat1->ChnErr, pWLRunStat1->nErrChn);
    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);
    s1.AppendFormat(_T("小错误1: %d     中错误2: %d     大错误3: %d\r\n"), pWLRunStat1->Err1Count, pWLRunStat1->Err2Count, pWLRunStat1->Err3Count);
    s1.AppendFormat(_T("步骤错误1: %d     步骤错误2: %d\r\n"), pWLRunStat1->StepErr1, pWLRunStat1->StepErr2);
    CString s2;
    if (pWLRunStat1->RSSI < -100) { s2.Format(_T("(0%%)")); }
    else if (pWLRunStat1->RSSI > 0) { s2.Format(_T("(100%%)")); }
    else { s2.Format(_T("(%d%%)"), pWLRunStat1->RSSI + 100); }
    s1.AppendFormat(_T("本机信号强度: %d dBm  SNR %d dB  ▁▃▅▇\r\n"), pWLRunStat1->RSSI, pWLRunStat1->SNR);
    if (pWLRunStat1->tRSSI < -100) { s2.Format(_T("(0%%)")); }
    else if (pWLRunStat1->tRSSI > 0) { s2.Format(_T("(100%%)")); }
    else { s2.Format(_T("(%d%%)"), pWLRunStat1->tRSSI + 100); }
    s1.AppendFormat(_T("对方信号强度: %d dBm  SNR %d dB  ▁▃▅▇\r\n"), pWLRunStat1->tRSSI, pWLRunStat1->tSNR);
    return s1;
}
CString CMTerm1CommDevView::KWRunStatToString(pstWLRunStatV12 pWLRunStat1)
{
    CString s1;
    //    pstWLRunStat  pWLRunStat1 = (pstWLRunStat)(theApp.MyKLink1.MEM.KWLB);
    s1.Format(_T("stsize %d 无线状态   %04X %04X 步骤 %04X \r\n"),sizeof(stWLRunStatV12), pWLRunStat1->Status, pWLRunStat1->curStat, pWLRunStat1->runStep);
    s1 += _T("频率: ") + intToString(pWLRunStat1->RF_Freq) + _T("   空中时间: ") + intToString(pWLRunStat1->nTimeOnAir) + _T("\r\n");
    s1 += _T("发送数量: ") + intToString(pWLRunStat1->sentCount) + _T("   对方收到: ") + intToString(pWLRunStat1->targetRecvdCount) + _T("   差值: ") + intToString(pWLRunStat1->sentCount - pWLRunStat1->targetRecvdCount) + _T("\r\n");
    s1 += _T("接收数量: ") + intToString(pWLRunStat1->recvCount) + _T("   对方发出: ") + intToString(pWLRunStat1->targetSentCount) + _T("   差值: ") + intToString(pWLRunStat1->targetSentCount - pWLRunStat1->recvCount) + _T("\r\n");
    s1 += _T("发送时间: ") + fixToString(pWLRunStat1->lastSendtime, 0, 1) + _T(" mS\r\n");
    s1 += _T("发完时间: ") + fixToString(pWLRunStat1->lastSenttime, 0, 1) + _T("   ") + fixToString(pWLRunStat1->lastSenttime - pWLRunStat1->lastSendtime, 0, 1) + _T(" mS\r\n");
    s1 += _T("接收时间: ") + fixToString(pWLRunStat1->lastRecvtime, 0, 1) + _T(" mS\r\n");
    s1 += _T("收到时间: ") + fixToString(pWLRunStat1->lastRecvdtime, 0, 1) + _T("   ") + fixToString(pWLRunStat1->lastRecvdtime - pWLRunStat1->lastRecvtime, 0, 1) + +_T(" mS\r\n");
    s1 += _T("动作时间: ") + fixToString(pWLRunStat1->lastActTime, 0, 1) + _T(" mS\r\n");
    s1 += _T("响应时间: ") + fixToString(pWLRunStat1->lastAckTime, 0, 1) + _T("   ") + fixToString(pWLRunStat1->lastAckTime - pWLRunStat1->lastActTime, 0, 1) + _T(" mS\r\n");
    s1 += _T("循环时间: ") + fixToString(pWLRunStat1->cycleTime, 0, 1) + _T(" mS\r\n");
    s1 += _T("延迟:     ") + fixToString(pWLRunStat1->latancy, 0, 1) + _T(" mS\r\n");
    s1.AppendFormat(_T("丢包数量: %d     连续丢包: %d    最大连续  %d\r\n"), pWLRunStat1->LostPackets, pWLRunStat1->CtnLstPkts, pWLRunStat1->MaxCtnLstPkts);
    s1.AppendFormat(_T("发送错误: %d     接收错误: %d    时间 %s mS\r\n"), pWLRunStat1->TXErr, pWLRunStat1->RXErr, fixToString(pWLRunStat1->lastErrTime, 0, 1));
    s1.AppendFormat(_T("CRC错误:  %d     频道错误  %d    包错误  %d\r\n"), pWLRunStat1->CRCErr, pWLRunStat1->ChnErr, pWLRunStat1->PktErr);
    s1.AppendFormat(_T("CAD次数:  %d\r\n"), pWLRunStat1->CADDoneCount);
    s1.AppendFormat(_T("小错误1: %d     中错误2: %d     大错误3: %d\r\n"), pWLRunStat1->Err1Count, pWLRunStat1->Err2Count, pWLRunStat1->Err3Count);
    s1.AppendFormat(_T("步骤错误1: %d     步骤错误2: %d\r\n"), pWLRunStat1->StepErr1, pWLRunStat1->StepErr2);
    CString s2;
    if (pWLRunStat1->RSSI < -100) { s2.Format(_T("(0%%)")); }
    else if (pWLRunStat1->RSSI > 0) { s2.Format(_T("(100%%)")); }
    else { s2.Format(_T("(%d%%)"), pWLRunStat1->RSSI + 100); }
    s1.AppendFormat(_T("本机信号强度: %d dBm ▁▃▅▇ SNR %d dB\r\n"), pWLRunStat1->RSSI, pWLRunStat1->SNR);
    if (pWLRunStat1->tRSSI < -100) { s2.Format(_T("(0%%)")); }
    else if (pWLRunStat1->tRSSI > 0) { s2.Format(_T("(100%%)")); }
    else { s2.Format(_T("(%d%%)"), pWLRunStat1->tRSSI + 100); }
    s1.AppendFormat(_T("对方信号强度: %d dBm ▁▃▅▇ SNR %d dB\r\n"), pWLRunStat1->tRSSI, pWLRunStat1->tSNR);
    return s1;
}
CString CMTerm1CommDevView::KWRunStatToString(pstWLRunStatV1 pWLRunStat1)
{
    CString s1;
    //    pstWLRunStat  pWLRunStat1 = (pstWLRunStat)(theApp.MyKLink1.MEM.KWLB);
    s1.Format(_T("stsize %d 无线状态   %04X %04X 步骤 %04X \r\n"), sizeof(stWLRunStatV1), pWLRunStat1->Status, pWLRunStat1->curStat, pWLRunStat1->runStep);
//    s1 += _T("频率: ") + intToString(pWLRunStat1->RF_Freq) + _T("   空中时间: ") + intToString(pWLRunStat1->nTimeOnAir) + _T("\r\n");
    s1 += _T("发送数量: ") + intToString(pWLRunStat1->sentCount) + _T("   对方收到: ") + intToString(pWLRunStat1->targetRecvdCount) + _T("   差值: ") + intToString(pWLRunStat1->sentCount - pWLRunStat1->targetRecvdCount) + _T("\r\n");
    s1 += _T("接收数量: ") + intToString(pWLRunStat1->recvCount) + _T("   对方发出: ") + intToString(pWLRunStat1->targetSentCount) + _T("   差值: ") + intToString(pWLRunStat1->targetSentCount - pWLRunStat1->recvCount) + _T("\r\n");
    s1 += _T("发送时间: ") + fixToString(pWLRunStat1->lastSendtime, 0, 1) + _T(" mS\r\n");
    s1 += _T("发完时间: ") + fixToString(pWLRunStat1->lastSenttime, 0, 1) + _T("   ") + fixToString(pWLRunStat1->lastSenttime - pWLRunStat1->lastSendtime, 0, 1) + _T(" mS\r\n");
    s1 += _T("接收时间: ") + fixToString(pWLRunStat1->lastRecvtime, 0, 1) + _T(" mS\r\n");
    s1 += _T("收到时间: ") + fixToString(pWLRunStat1->lastRecvdtime, 0, 1) + _T("   ") + fixToString(pWLRunStat1->lastRecvdtime - pWLRunStat1->lastRecvtime, 0, 1) + +_T(" mS\r\n");
    s1 += _T("动作时间: ") + fixToString(pWLRunStat1->lastActTime, 0, 1) + _T(" mS\r\n");
    s1 += _T("响应时间: ") + fixToString(pWLRunStat1->lastAckTime, 0, 1) + _T("   ") + fixToString(pWLRunStat1->lastAckTime - pWLRunStat1->lastActTime, 0, 1) + _T(" mS\r\n");
    s1 += _T("循环时间: ") + fixToString(pWLRunStat1->cycleTime, 0, 1) + _T(" mS\r\n");
    s1 += _T("延迟:     ") + fixToString(pWLRunStat1->latancy, 0, 1) + _T(" mS\r\n");
    s1.AppendFormat(_T("丢包数量: %d     连续丢包: %d    最大连续  %d\r\n"), pWLRunStat1->LostPackets, pWLRunStat1->CtnLstPkts, pWLRunStat1->MaxCtnLstPkts);
    s1.AppendFormat(_T("发送错误: %d     接收错误: %d    时间 %s mS\r\n"), pWLRunStat1->TXErr, pWLRunStat1->RXErr, fixToString(pWLRunStat1->lastErrTime, 0, 1));
    s1.AppendFormat(_T("CRC错误:  %d  \r\n"), pWLRunStat1->CRCErr);
    s1.AppendFormat(_T("CAD次数:  %d\r\n"), pWLRunStat1->CADDoneCount);
    s1.AppendFormat(_T("小错误1: %d     中错误2: %d     大错误3: %d\r\n"), pWLRunStat1->Err1Count, pWLRunStat1->Err2Count, pWLRunStat1->Err3Count);
    s1.AppendFormat(_T("步骤错误1: %d     步骤错误2: %d\r\n"), pWLRunStat1->StepErr1, pWLRunStat1->StepErr2);
    CString s2;
    if (pWLRunStat1->RSSI < -100) { s2.Format(_T("(0%%)")); }
    else if (pWLRunStat1->RSSI > 0) { s2.Format(_T("(100%%)")); }
    else { s2.Format(_T("(%d%%)"), pWLRunStat1->RSSI+100); }
    s1.AppendFormat(_T("本机信号强度: %ddBm %s ▁▃▅▇   信噪比 SNR %d dB\r\n"), pWLRunStat1->RSSI, s2, pWLRunStat1->SNR);
    if (pWLRunStat1->tRSSI < -100) { s2.Format(_T("(0%%)")); }
    else if (pWLRunStat1->tRSSI > 0) { s2.Format(_T("(100%%)")); }
    else { s2.Format(_T("(%d%%)"), pWLRunStat1->tRSSI + 100); }
    s1.AppendFormat(_T("对方信号强度: %ddBm %s ▁▃▅▇   信噪比 SNR %d dB\r\n"), pWLRunStat1->tRSSI,s2, pWLRunStat1->tSNR);
    return s1;
}
int CMTerm1CommDevView::UpdateStatusBar(int nIndex)
{
    // TODO: 在此处添加实现代码.
    CString s1;
    return 0;
    CMTerm1Doc * pDoc = (CMTerm1Doc*)GetDocument();
    if (nIndex == idxMachineType || nIndex == -1) {        //机型代码
@@ -690,6 +868,7 @@
        //        ProcessInput();
        //DrawPic1();
//        MyLogger1.UpdateLogDisplay(0);
        //MonitorPLC();
        UpdateDataDisplay();
        UpdateLEDDisplay();
    }
@@ -883,7 +1062,7 @@
int CMTerm1CommDevView::DisplayParams()
{
    CMTerm1Doc *pDoc = (CMTerm1Doc *)GetDocument();
    // // CMTerm1Doc *pDoc = (CMTerm1Doc *)GetDocument();
    CString s1, s2;
    Hash & ModelConfg = MyCfg1["Model"];
    ModelConfg.SetCtrlList(this, myCfgValCtrls, nMarkConfigs);
@@ -915,7 +1094,7 @@
    m_combo_com_baud.AddString(_T("1000000"));
    m_combo_com_baud.AddString(_T("2000000"));
    m_combo_com_baud.AddString(_T("3000000"));
    sBaudSelStr = _T("230400");
    sBaudSelStr = _T("115200");
    m_combo_com_baud.SelectString(0, sBaudSelStr);
    MyThreadProc1ToRun = 0;
@@ -958,15 +1137,16 @@
int CMTerm1CommDevView::OpenResource(CStringA ResourceStr)
{
    CString s1;
    CMTerm1Doc *pDoc = (CMTerm1Doc *) GetDocument();
    // CMTerm1Doc *pDoc = (CMTerm1Doc *) GetDocument();
    
    int r = pDoc->Connect();
    s1.Format(_T("Open %s  = %d"), pDoc->MyKLink1.m_resultStr, r);
    //int r = pDoc->Connect();
    int r = theApp.MyKLink1.Connect();
    s1.Format(_T("Open %s  = %d"), theApp.MyKLink1.m_resultStr, r);
    SysLog(s1);
    if (r == pDoc->MyKLink1.MySerPort1.R_OK)
    if (r == theApp.MyKLink1.MySerPort1.R_OK)
    {
        m_bResourceOpened = true;
    //    pDoc->MyKLink1.Open();
    //    theApp.MyKLink1.Open();
        m_static_connect.SetCtlColor(RGB(0, 255, 0));
        return true;
    }
@@ -975,13 +1155,13 @@
int CMTerm1CommDevView::CloseResource()
{
    CMTerm1Doc *pDoc = (CMTerm1Doc *)GetDocument();
    // CMTerm1Doc *pDoc = (CMTerm1Doc *)GetDocument();
    m_static_connect.SetCtlColor(RGB(80, 80, 80));
    if (m_bResourceOpened)
    {
        pDoc->DisConnect();
        pDoc->MyKLink1.Close();
        //pDoc->DisConnect();
        theApp.MyKLink1.Close();
        m_bResourceOpened = false;
    }
    return 0;
@@ -1093,12 +1273,12 @@
int CMTerm1CommDevView::MonitorPLC()
{
    CMTerm1Doc *pDoc = (CMTerm1Doc *)GetDocument();
    // CMTerm1Doc *pDoc = (CMTerm1Doc *)GetDocument();
    if (m_bMonitoring && pDoc->MyKLink1.MySerPort1.m_bOpened)
    if (m_bMonitoring && theApp.MyKLink1.MySerPort1.m_bOpened)
    {
        unsigned char DstAddr = 1;
        unsigned char DataType = pDoc->MyKLink1.KLDataTypeSDT;
        unsigned char DataType = theApp.MyKLink1.KLDataTypeSDT;
        unsigned short DAddr = 0;
        unsigned char DCount = 32;
        //        unsigned char Data1[256];
@@ -1115,18 +1295,19 @@
        ///*
        if (nStep == 0)
        {
            DataType = pDoc->MyKLink1.KLDataTypeWX;
            DataType = theApp.MyKLink1.KLDataTypeWX;
            DAddr = 0;
            DCount = 16;
            res = pDoc->MyKLink1.ReadDataByte(DstAddr,  DataType, DAddr, DCount, &nCount, &pDoc->MyKLink1.MEM.WXB[DAddr]);
            res = theApp.MyKLink1.ReadDataByte(DstAddr,  DataType, DAddr, DCount, &nCount, &theApp.MyKLink1.MEM.WXB[DAddr]);
            nCount = DCount;
            if (res == pDoc->MyKLink1.KL_OK)
            if (res == theApp.MyKLink1.KL_OK)
            {
                nThisSuccessCount++;
            }
            else
            {
                nThisFailCount++;
                s1.Format(_T("R:= %d %s  \r\n"), res, pDoc->MyKLink1.m_resultStr);
                s1.Format(_T("R:= %d %s  \r\n"), res, theApp.MyKLink1.m_resultStr);
                SysLog(s1);
            }
@@ -1137,38 +1318,84 @@
        //WY
        if (nStep == 0)
        {
            DataType = pDoc->MyKLink1.KLDataTypeWY;
            DataType = theApp.MyKLink1.KLDataTypeWY;
            DAddr = 0;
            DCount = 16;
            res = pDoc->MyKLink1.ReadDataByte(DstAddr, DataType, DAddr, DCount, &nCount, &pDoc->MyKLink1.MEM.WYB[DAddr]);
            res = theApp.MyKLink1.ReadDataByte(DstAddr, DataType, DAddr, DCount, &nCount, &theApp.MyKLink1.MEM.WYB[DAddr]);
            nCount = DCount;
            if (res == pDoc->MyKLink1.KL_OK)
            if (res == theApp.MyKLink1.KL_OK)
            {
                nThisSuccessCount++;
            }
            else
            {
                nThisFailCount++;
                s1.Format(_T("R:= %d %s  \r\n"), res, pDoc->MyKLink1.m_resultStr);
                s1.Format(_T("R:= %d %s  \r\n"), res, theApp.MyKLink1.m_resultStr);
                SysLog(s1);
            }
            //*/
        }
        //*/
        // WLX
        ///*
        if (nStep == 0)
        {
            DataType = theApp.MyKLink1.KLDataTypeWLX;
            DAddr = 0;
            DCount = 16;
            res = theApp.MyKLink1.ReadDataByte(DstAddr, DataType, DAddr, DCount, &nCount, &theApp.MyKLink1.MEM.WLXB[DAddr]);
            nCount = DCount;
            if (res == theApp.MyKLink1.KL_OK)
            {
                nThisSuccessCount++;
            }
            else
            {
                nThisFailCount++;
                s1.Format(_T("R:= %d %s  \r\n"), res, theApp.MyKLink1.m_resultStr);
                SysLog(s1);
            }
        }
        //*/
        ///*
        //WLY
        if (nStep == 0)
        {
            DataType = theApp.MyKLink1.KLDataTypeWLY;
            DAddr = 0;
            DCount = 16;
            res = theApp.MyKLink1.ReadDataByte(DstAddr, DataType, DAddr, DCount, &nCount, &theApp.MyKLink1.MEM.WLYB[DAddr]);
            nCount = DCount;
            if (res == theApp.MyKLink1.KL_OK)
            {
                nThisSuccessCount++;
            }
            else
            {
                nThisFailCount++;
                s1.Format(_T("R:= %d %s  \r\n"), res, theApp.MyKLink1.m_resultStr);
                SysLog(s1);
            }
        }
        //*/
        ///*
        //WR
        if (nStep==0)
        {
            DataType = pDoc->MyKLink1.KLDataTypeWR;
            DataType = theApp.MyKLink1.KLDataTypeWR;
            DAddr = 0;
            DCount = 32;
            res = pDoc->MyKLink1.ReadDataByte(DstAddr,  DataType, DAddr, DCount, &nCount, &pDoc->MyKLink1.MEM.WRB[DAddr]);
            res = theApp.MyKLink1.ReadDataByte(DstAddr,  DataType, DAddr, DCount, &nCount, &theApp.MyKLink1.MEM.WRB[DAddr]);
            nCount = DCount;
            if (res == pDoc->MyKLink1.KL_OK)
            if (res == theApp.MyKLink1.KL_OK)
            {
                nThisSuccessCount++;
            }
            else
            {
                nThisFailCount++;
                s1.Format(_T("R:= %d %s  \r\n"), res, pDoc->MyKLink1.m_resultStr);
                s1.Format(_T("R:= %d %s  \r\n"), res, theApp.MyKLink1.m_resultStr);
                SysLog(s1);
            }
        }
@@ -1176,18 +1403,19 @@
        //DT
        if (nStep == 1)
        {
            DataType = pDoc->MyKLink1.KLDataTypeDT;
            DataType = theApp.MyKLink1.KLDataTypeDT;
            DAddr = 0;
            DCount = 96;
            res = pDoc->MyKLink1.ReadDataByte(DstAddr,  DataType, DAddr, DCount, &nCount, &pDoc->MyKLink1.MEM.DTB[DAddr]);
            res = theApp.MyKLink1.ReadDataByte(DstAddr,  DataType, DAddr, DCount, &nCount, &theApp.MyKLink1.MEM.DTB[DAddr]);
            nCount = DCount;
            if (res == pDoc->MyKLink1.KL_OK)
            if (res == theApp.MyKLink1.KL_OK)
            {
                nThisSuccessCount++;
            }
            else
            {
                nThisFailCount++;
                s1.Format(_T("R:= %d %s  \r\n"), res, pDoc->MyKLink1.m_resultStr);
                s1.Format(_T("R:= %d %s  \r\n"), res, theApp.MyKLink1.m_resultStr);
                SysLog(s1);
            }
@@ -1197,40 +1425,40 @@
        if (nStep >= 2 && nStep <= 4)
        {
            int nBlock = nStep - 2;
            DataType = pDoc->MyKLink1.KLDataTypeSDT;
            DataType = theApp.MyKLink1.KLDataTypeSDT;
            ByteAddr = nBlock * 128;
            DCount = 128;
            res = pDoc->MyKLink1.ReadDataByte(DstAddr,  DataType, ByteAddr, DCount, &nCount, &pDoc->MyKLink1.MEM.SDB[ByteAddr]);
            res = theApp.MyKLink1.ReadDataByte(DstAddr,  DataType, ByteAddr, DCount, &nCount, &theApp.MyKLink1.MEM.SDB[ByteAddr]);
            nCount = DCount;
            if (res == pDoc->MyKLink1.KL_OK)
            if (res == theApp.MyKLink1.KL_OK)
            {
                for (int i = 0; i < DCount; i++) { SDTbuf[ByteAddr + i] = pDoc->MyKLink1.MEM.SDB[ByteAddr + i]; }
                for (int i = 0; i < DCount; i++) { SDTbuf[ByteAddr + i] = theApp.MyKLink1.MEM.SDB[ByteAddr + i]; }
                nThisSuccessCount++;
            }
            else
            {
                nThisFailCount++;
                s1.Format(_T("R:= %d %s  \r\n"), res, pDoc->MyKLink1.m_resultStr);
                s1.Format(_T("R:= %d %s  \r\n"), res, theApp.MyKLink1.m_resultStr);
                SysLog(s1);
            }
        }
        if (nStep >= 5 && nStep <= 7)
        {
            int nBlock = nStep - 5;
            DataType = pDoc->MyKLink1.KLDataTypeWDT;
            DataType = theApp.MyKLink1.KLDataTypeWDT;
            ByteAddr = nBlock * 128;
            DCount = 128;
            res = pDoc->MyKLink1.ReadDataByte(DstAddr, DataType, ByteAddr, DCount, &nCount, &pDoc->MyKLink1.MEM.WDB[ByteAddr]);
            res = theApp.MyKLink1.ReadDataByte(DstAddr, DataType, ByteAddr, DCount, &nCount, &theApp.MyKLink1.MEM.WDB[ByteAddr]);
            nCount = DCount;
            if (res == pDoc->MyKLink1.KL_OK)
            if (res == theApp.MyKLink1.KL_OK)
            {
                for (int i = 0; i < DCount; i++) { WDTbuf[ByteAddr + i] = pDoc->MyKLink1.MEM.WDB[ByteAddr + i]; }
                for (int i = 0; i < DCount; i++) { WDTbuf[ByteAddr + i] = theApp.MyKLink1.MEM.WDB[ByteAddr + i]; }
                nThisSuccessCount++;
            }
            else
            {
                nThisFailCount++;
                s1.Format(_T("R:= %d %s  \r\n"), res, pDoc->MyKLink1.m_resultStr);
                s1.Format(_T("R:= %d %s  \r\n"), res, theApp.MyKLink1.m_resultStr);
                SysLog(s1);
            }
        }
@@ -1238,40 +1466,40 @@
        if (nStep >= 8 && nStep <= 13)
        {
            int nBlock = nStep - 8;
            DataType = pDoc->MyKLink1.KLDataTypeKBD;
            DataType = theApp.MyKLink1.KLDataTypeKBD;
            ByteAddr = nBlock * 128;
            DCount = 128;
            res = pDoc->MyKLink1.ReadDataByte(DstAddr, DataType, ByteAddr, DCount, &nCount, &pDoc->KBDB[ByteAddr]);
            res = theApp.MyKLink1.ReadDataByte(DstAddr, DataType, ByteAddr, DCount, &nCount, &theApp.MyKLink1.MEM.KBDB[ByteAddr]);
            nCount = DCount;
            if (res == pDoc->MyKLink1.KL_OK)
            if (res == theApp.MyKLink1.KL_OK)
            {
                //for (int i = 0; i < DCount; i++) { WDTbuf[ByteAddr + i] = pDoc->MyKLink1.MEM.WDB[ByteAddr + i]; }
                //for (int i = 0; i < DCount; i++) { WDTbuf[ByteAddr + i] = theApp.MyKLink1.MEM.WDB[ByteAddr + i]; }
                nThisSuccessCount++;
            }
            else
            {
                nThisFailCount++;
                s1.Format(_T("R:= %d %s  \r\n"), res, pDoc->MyKLink1.m_resultStr);
                s1.Format(_T("R:= %d %s  \r\n"), res, theApp.MyKLink1.m_resultStr);
                SysLog(s1);
            }
        }
        if (nStep >= 14 && nStep <= 14)
        {
            int nBlock = nStep - 14;
            DataType = pDoc->MyKLink1.KLDataTypeKWLD;
            DataType = theApp.MyKLink1.KLDataTypeKWLD;
            ByteAddr = nBlock * 128;
            DCount = 128;
            res = pDoc->MyKLink1.ReadDataByte(DstAddr, DataType, ByteAddr, DCount, &nCount, &pDoc->KWLB[ByteAddr]);
            res = theApp.MyKLink1.ReadDataByte(DstAddr, DataType, ByteAddr, DCount, &nCount, &theApp.MyKLink1.MEM.KWLB[ByteAddr]);
            nCount = DCount;
            if (res == pDoc->MyKLink1.KL_OK)
            if (res == theApp.MyKLink1.KL_OK)
            {
                //for (int i = 0; i < DCount; i++) { WDTbuf[ByteAddr + i] = pDoc->MyKLink1.MEM.WDB[ByteAddr + i]; }
                //for (int i = 0; i < DCount; i++) { WDTbuf[ByteAddr + i] = theApp.MyKLink1.MEM.WDB[ByteAddr + i]; }
                nThisSuccessCount++;
            }
            else
            {
                nThisFailCount++;
                s1.Format(_T("R:= %d %s  \r\n"), res, pDoc->MyKLink1.m_resultStr);
                s1.Format(_T("R:= %d %s  \r\n"), res, theApp.MyKLink1.m_resultStr);
                SysLog(s1);
            }
        }
@@ -1366,7 +1594,7 @@
    CString s1, s2;
    SysLog(_T("线程开始运行\r\n"));
    MyThreadProc1Running = 1;
    CMTerm1Doc *pDoc = (CMTerm1Doc *)GetDocument();
    // CMTerm1Doc *pDoc = (CMTerm1Doc *)GetDocument();
    /*
@@ -1387,8 +1615,8 @@
    //s2.GetLength();
    //    memcpy(send1,s2,bytetosend1);
    pDoc->MyAnsiParser1.AttachWnd(m_edit_display.GetSafeHwnd());
    pDoc->MyAnsiParser1.SetScreenWH(150, 40);
//    pDoc->MyAnsiParser1.AttachWnd(m_edit_display.GetSafeHwnd());
//    pDoc->MyAnsiParser1.SetScreenWH(150, 40);
    //    CClientDC hcurDC(this);
    HWND hDrawXY = GetDlgItem(IDC_STATIC_DRAW_XY)->m_hWnd;
@@ -1424,7 +1652,7 @@
            nDataToSend = LastSendLength;
            //            s1.Format(_T("BulkToSend %d Bytes"), nDataToSend);
            //            SysLog(s1);
            dwSent = pDoc->MyKLink1.SendPacket((char *)send1, nDataToSend);
            dwSent = theApp.MyKLink1.SendPacket((char *)send1, nDataToSend);
            s1.Format(_T("S %d ->"), nDataToSend);
            for (int i = 0; i < nDataToSend; i++)
            {
@@ -1440,7 +1668,7 @@
        {
            s1.Format(_T("ToSend %d Bytes"), nDataToSend);
            SysLog(s1);
            dwSent = pDoc->MyKLink1.SendPacket((char *)send1, nDataToSend);
            dwSent = theApp.MyKLink1.SendPacket((char *)send1, nDataToSend);
            s1.Format(_T("S %d ->"), nDataToSend);
            for (int i = 0; i < nDataToSend; i++)
            {
@@ -1459,7 +1687,7 @@
            SysLog(s1);
        }
        //ReadFile(hCom, recv1, dNumtoRead, &wCount2, &ovlap2);
        wCount2 = pDoc->MyKLink1.RecvPacket((char *)recv1, dNumtoRead);
        wCount2 = theApp.MyKLink1.RecvPacket((char *)recv1, dNumtoRead);
        //        WaitForSingleObject(ovlap2.hEvent,800);
        //        GetOverlappedResult(hCom,&ovlap2,&wCount2,TRUE);
        if (wCount2 == 0) continue;
@@ -1479,7 +1707,7 @@
        s1.Append(_T("\r\n"));
        // SysLog(s1);
        //continue;
        pDoc->MyKLink1.ParseRplyPacket(recv1, wCount2, &nCmd, &nStatus, &nCount, databuf1);
        theApp.MyKLink1.ParseRplyPacket(recv1, wCount2, &nCmd, &nStatus, &nCount, databuf1);
        s1.Format(_T("R-> Cmd:%02X  Status:%04X  Count:%02d  \r\nData: "), nCmd, nStatus, nCount);
        s2.Empty();
@@ -1491,14 +1719,14 @@
        s1.Append(s2);
        s1.Append(_T("\r\n"));
        SysLog(s1);
        int HasData = pDoc->MyDataParser1.PutIn(recv1, wCount2);
        int HasData = 0; // pDoc->MyDataParser1.PutIn(recv1, wCount2);
        CStringA sA1;
        TToAnsi(s1, sA1);
        //        MyAnsiParser1.PutIn((unsigned char *)sA1.GetBuffer(), sA1.GetLength()); sA1.ReleaseBuffer();
        //        MyAnsiParser1.PutIn(recv1, wCount2);
        if (HasData)
        {
            pDoc->MyDataParser1.GetOutput(&handx, &handy);
            //pDoc->MyDataParser1.GetOutput(&handx, &handy);
            if (oldhandx != handx || oldhandy != handy)
            {
                DrawCross(hDrawXY, handx, handy);
@@ -1586,7 +1814,7 @@
void CMTerm1CommDevView::OnBnClickedButtonStop()
{
    // TODO: 在此添加控件通知处理程序代码
    CMTerm1Doc *pDoc = (CMTerm1Doc *)GetDocument();
    // CMTerm1Doc *pDoc = (CMTerm1Doc *)GetDocument();
    m_bMonitoring = true;
    OnMenuMonitor();
@@ -1609,18 +1837,18 @@
    {
        SysLog(_T("线程未运行\r\n"));
    }
    pDoc->MyKLink1.Close();
    theApp.MyKLink1.Close();
}
void CMTerm1CommDevView::OnBnClickedButtonClrscr()
{
    // TODO: 在此添加控件通知处理程序代码
    CMTerm1Doc *pDoc = (CMTerm1Doc *)GetDocument();
    // CMTerm1Doc *pDoc = (CMTerm1Doc *)GetDocument();
    CString s1;
    s1.Format(_T("Clear Screen \r\n"));
    SysLog(s1);
    pDoc->MyAnsiParser1.ClrScreen();
    //pDoc->MyAnsiParser1.ClrScreen();
}
@@ -1687,7 +1915,7 @@
void CMTerm1CommDevView::OnBnClickedButtonDo()
{
    // TODO: 在此添加控件通知处理程序代码
    CMTerm1Doc *pDoc = (CMTerm1Doc *)GetDocument();
    // CMTerm1Doc *pDoc = (CMTerm1Doc *)GetDocument();
    unsigned char buf1[256];
    unsigned char buf2[256];
@@ -1742,19 +1970,19 @@
        Data2[i] = Xtoi(Resultstrs[i]);
    }
    int ExtFrameLen = pDoc->MyKLink1.MakeExtDataFrame(buf2, ExtDataDst, ExtDataType, ExtDataLen, Data2);
    int ExtFrameLen = theApp.MyKLink1.MakeExtDataFrame(buf2, ExtDataDst, ExtDataType, ExtDataLen, Data2);
    KLink1::unKLStat nStat1 = { 0 };
    nStat1.HasExt = bExtData;
    nStat1.nSEQ = pDoc->MyKLink1.GetNextSeq();
    nStat1.nSEQ = theApp.MyKLink1.GetNextSeq();
    //    Cmd += 0x30;    //KLink::cmdRead
    int len1 = pDoc->MyKLink1.MakeReqPacketEx(buf1, DstAddr, nStat1.StatByte, Cmd, DataType, DAddr, DCount, Data1, ExtFrameLen, buf2);
    int len1 = theApp.MyKLink1.MakeReqPacketEx(buf1, DstAddr, nStat1.StatByte, Cmd, DataType, DAddr, DCount, Data1, ExtFrameLen, buf2);
    s1.Format(_T("S %d ->"), len1);
    int res = 0;
    int SendType = 1;
    if (SendType == 1)
    {
        res = pDoc->MyKLink1.SendPacket((char *)buf1, len1);
        res = theApp.MyKLink1.SendPacket((char *)buf1, len1);
        for (int i = 0; i < len1; i++)
        {
            s1.AppendFormat(_T("%02X "), buf1[i]);
@@ -1784,7 +2012,7 @@
    for (int i = 0; i < 10; i++)
    {
        nTryCount++;
        int len = pDoc->MyKLink1.RecvPacket((char *)recv1 + len2, numToRead - len2);
        int len = theApp.MyKLink1.RecvPacket((char *)recv1 + len2, numToRead - len2);
        if (len >0) len2 += len;
        if (len2 >= numToRead) break;
        if (len2 > 0) {
@@ -1816,7 +2044,7 @@
    //continue;
    unsigned short databuf1[256];
    pDoc->MyKLink1.ParseRplyPacket(recv1, wCount2, &nCmd, &nStatus, &nCount, databuf1);
    theApp.MyKLink1.ParseRplyPacket(recv1, wCount2, &nCmd, &nStatus, &nCount, databuf1);
    s1.Format(_T("R: Cmd:%02X  St:%02X  N:%02d  D:\r\n"), nCmd, nStatus, nCount);
    CString s2;
@@ -1934,7 +2162,7 @@
void CMTerm1CommDevView::OnMenuOffline()
{
    // TODO: 在此添加命令处理程序代码
    CMTerm1Doc *pDoc = (CMTerm1Doc *)GetDocument();
    // CMTerm1Doc *pDoc = (CMTerm1Doc *)GetDocument();
    CString s1;
    m_bOnline = false;
@@ -1960,7 +2188,7 @@
    {
        SysLog(_T("线程未运行\r\n"));
    }
    pDoc->MyKLink1.Close();
    theApp.MyKLink1.Close();
}
void CMTerm1CommDevView::OnUpdateMenuOffline(CCmdUI *pCmdUI)
@@ -2288,25 +2516,30 @@
void CMTerm1CommDevView::OnBnClickedButton12()
{
    // TODO: 在此添加控件通知处理程序代码
    CMTerm1Doc *pDoc = (CMTerm1Doc *)GetDocument();
    // CMTerm1Doc *pDoc = (CMTerm1Doc *)GetDocument();
    CString s1;
/*
    CString s1;
    pDoc->MyKLink1.MySerPort1.SetParams(1, 115200, _T("8-N-1"));
    int r = pDoc->MyKLink1.MySerPort1.Open();
    s1.Format(_T("%d %s"), r, pDoc->MyKLink1.MySerPort1.m_strResult);
    theApp.MyKLink1.MySerPort1.SetParams(1, 115200, _T("8-N-1"));
    int r = theApp.MyKLink1.MySerPort1.Open();
    s1.Format(_T("%d %s"), r, theApp.MyKLink1.MySerPort1.m_strResult);
    SysLog(s1);
*/
    int k = theApp.MyKLink1.ResetDevice(1, 0);
    s1.Format(_T("ResetDevice  = %d"), k);
    SysLog(s1);
}
void CMTerm1CommDevView::OnBnClickedButton13()
{
    // TODO: 在此添加控件通知处理程序代码
    CMTerm1Doc *pDoc = (CMTerm1Doc *)GetDocument();
    // CMTerm1Doc *pDoc = (CMTerm1Doc *)GetDocument();
/*
    CString s1;
    int r = pDoc->MyKLink1.MySerPort1.Close();
    s1.Format(_T("%d %s"), r, pDoc->MyKLink1.MySerPort1.m_strResult);
    int r = theApp.MyKLink1.MySerPort1.Close();
    s1.Format(_T("%d %s"), r, theApp.MyKLink1.MySerPort1.m_strResult);
    SysLog(s1);
    double REPO_RATE(0.0);
@@ -2429,3 +2662,316 @@
}
// 热电阻电压转温度 查表
const short tempTab[] =
{
    261,    -20,
    276,    -19,
    291,    -18,
    307,    -17,
    324,    -16,
    341,    -15,
    359,    -14,
    378,    -13,
    397,    -12,
    417,    -11,
    438,    -10,
    460,    -9,
    483,    -8,
    506,    -7,
    530,    -6,
    555,    -5,
    581,    -4,
    608,    -3,
    635,    -2,
    663,    -1,
    692,    0,
    722,    1,
    753,    2,
    784,    3,
    817,    4,
    850,    5,
    884,    6,
    918,    7,
    954,    8,
    990,    9,
    1026,    10,
    1064,    11,
    1102,    12,
    1140,    13,
    1179,    14,
    1219,    15,
    1259,    16,
    1300,    17,
    1341,    18,
    1383,    19,
    1425,    20,
    1467,    21,
    1509,    22,
    1552,    23,
    1595,    24,
    1638,    25,
    1682,    26,
    1725,    27,
    1768,    28,
    1812,    29,
    1855,    30,
    1899,    31,
    1942,    32,
    1985,    33,
    2028,    34,
    2070,    35,
    2113,    36,
    2155,    37,
    2196,    38,
    2238,    39,
    2279,    40,
    2319,    41,
    2359,    42,
    2399,    43,
    2438,    44,
    2477,    45,
    2515,    46,
    2552,    47,
    2589,    48,
    2626,    49,
    2661,    50,
    2697,    51,
    2731,    52,
    2765,    53,
    2798,    54,
    2831,    55,
    2863,    56,
    2895,    57,
    2926,    58,
    2956,    59,
    2985,    60,
    3014,    61,
    3042,    62,
    3070,    63,
    3097,    64,
    3123,    65,
    3149,    66,
    3174,    67,
    3199,    68,
    3222,    69,
    3246,    70,
    3268,    71,
    3290,    72,
    3312,    73,
    3333,    74,
    3354,    75,
    3374,    76,
    3393,    77,
    3412,    78,
    3430,    79,
    3448,    80,
    3466,    81,
    3483,    82,
    3499,    83,
    3515,    84,
    3531,    85,
    3546,    86,
    3561,    87,
    3575,    88,
    3589,    89,
    3603,    90,
    3616,    91,
    3629,    92,
    3641,    93,
    3653,    94,
    3665,    95,
    3676,    96,
    3687,    97,
    3698,    98,
    3708,    99,
    3719,    100,
    3729,    101,
    3738,    102,
    3747,    103,
    3757,    104,
    3765,    105,
    3774,    106,
    3782,    107,
    3790,    108,
    3798,    109,
    3806,    110,
};
int lookupTempTab(unsigned short value)
{
    int n = sizeof(tempTab) / (sizeof(short) * 2);
    int p, q, r;
    p = 0; q = n - 1;
    r = (p + q) / 2;
    while (p < q && p != r && q != r) {
        short tempValue = tempTab[r * 2];
        if (tempValue == value) { break; }
        else if (tempValue < value) { p = r; r = (p + q) / 2; }
        else if (tempValue > value) { q = r; r = (p + q) / 2; }
    }
    short value1 = tempTab[r * 2];
    short temp1 = tempTab[r * 2 + 1] * 10;
    if (r == n - 1) return temp1;
    short value2 = tempTab[(r + 1) * 2];
    short temp2 = tempTab[(r + 1) * 2 + 1] * 10;
    int temp3 = temp1 + (temp2 - temp1) * (value - value1) / (value2 - value1);    // 线性插值
    return temp3;
}
void CMTerm1CommDevView::OnBnClickedButton5()
{
    // TODO: 在此添加控件通知处理程序代码
    double a, b, c, d, e;
    double m = 0;
    int nCount = 360;
    int nMaxIndex=0;
    for (int i = 0; i < nCount; i++)
    {
        a = (double)i * 2 * 3.141592653589793238462643383279 / nCount;
        b = (double)(i+1) * 2 * 3.141592653589793238462643383279 / nCount ;
        c = (sin(a) + sin(b)) / 2;
        d = sin((a + b) / 2);
        e = abs(d - c);
        if (e > m) { m = e; nMaxIndex = i; }
    }
    CString s1;
    s1.Format(_T("检验查表插值法 计算正弦值 最大误差\r\n"));
    s1.AppendFormat(_T("0-180 正弦表分为 %d 点, 两点之间进行插值,找最大误差点\r\n"),nCount);
    s1.AppendFormat(_T("max diff %lf   index %d"), m, nMaxIndex);
    SysLog(s1);
    nCount = 10;
    int nDigit = 8;
    s1.Format(_T("随机输出 %d 个 %d 位数\r\n"),nCount,nDigit);
    for (int i = 0; i < nCount; i++) {
        CString s2;
        for (int j = 0; j < nDigit; j++) {
            int k = rand() % 10;
            s2.AppendFormat(_T("%d"), k);
        }
        s1 += s2 + _T("\r\n");
    }
    SysLog(s1);
    s1.Empty();
    CString s2;
    for (int i = 0; i < 4096; i++) {
        int j = lookupTempTab(i);
        s2.Format(_T("%d %d \r\n"), i, j);
        s1 += s2;
    }
    SysLog(s1);
}
void CMTerm1CommDevView::OnBnClickedButton9()
{
    // TODO: 在此添加控件通知处理程序代码
    // Select File
    CMTerm1Doc* pDoc = (CMTerm1Doc*)GetDocument();
    CString s1;
    USHORT len1;
    USHORT buf1[1024];
    int r2 = theApp.MyKLink1.GetInfo(1, &len1, buf1);
    pKMInfoBlock pinfob = (pKMInfoBlock)buf1;
    if (r2 == 0 && len1 > 0) {
        for (int i = 0; i < len1 / 2; i++) {
            s1.AppendFormat(_T("%04X "), buf1[i]);
        }
        s1 += _T("\r\n");
        s1.AppendFormat(_T(" DeviceType %04X \t "), pinfob->nDeviceTypeVer);
        s1.AppendFormat(_T(" nProgVer %04X \r\n"), pinfob->nProgVer);
    }
    SysLog(s1);
    myLogger1.UpdateLogDisplay();
    unsigned char filebuf[65536];
    unsigned int blocksize = 128;
    stNewAppInfoBlock NewAppInfo;
    CFileDialog dialog1(true);
    INT_PTR r = dialog1.DoModal();
    if (r == IDOK)
    {
        CString sFilePathName = dialog1.GetPathName();
        //OpenFile
        CFile file1;
        CFileException e;
        bool r = file1.Open(sFilePathName, CFile::modeRead | CFile::typeBinary, &e);
        s1.Format(_T("Open File %s = %d"), sFilePathName, r);
        DbgLog(s1);
        if (r)
        {
            int len1 = (int)file1.GetLength();
            file1.Read(filebuf, len1);
            file1.Close();
            unsigned short crc2 = crc16tablefast(filebuf, len1);
            unsigned char* buf2 = filebuf + 0x1000; ;
            //s1.Format(_T("GetInfo From File  = %d %d \r\n"), j, len1);
            pKMInfoBlock pinfof = (pKMInfoBlock)buf2;
            s1.Format(_T(" 目标模块 类型 %04X 版本 %x, \r\n 固件文件 类型 %04X 版本 %x,  %d Bytes\r\n 是否继续"), pinfob->nDeviceTypeVer, pinfob->nProgVer,pinfof->nDeviceTypeVer,pinfof->nProgVer,len1);
            int r3 = AfxMessageBox(s1, MB_YESNO);
            if (r3 == IDYES) {
                int bError = 0;
                for (int i = 0; i < len1; i += blocksize)
                {
                    int sendsize = len1 - i;
                    if (sendsize > blocksize) { sendsize = blocksize; }
                    int k = 999;
                    int j = 0;
                    double time1 = GetTimemS();
                    for (j = 0; j < 5 && k != 0; j++) {
                        k = theApp.MyKLink1.WriteFirmware(1, 0, i, sendsize, filebuf + i);
                        if (k) {
                            double time2 = GetTimemS();
                            s1.Format(_T("Wr@ %x %dB = %d  re %d %.2fmS %s "), i, sendsize, k, j, time2 - time1, theApp.MyKLink1.m_resultStr);
                            SysLog(s1);
                            myLogger1.UpdateLogDisplay();
                            Sleep(30);
                        }
                    }
                    double time2 = GetTimemS();
                    s1.Format(_T("Wr@ %x %dB = %d  re %d %.2fmS"), i, sendsize, k, j, time2 - time1);
                    SysLog(s1);
                    myLogger1.UpdateLogDisplay();
                    if (k) {   // 出现错误;
                        bError = 1;
                        CString sErr;
                        sErr = KLink1::GetErrDescStr(k);
                        s1.Format(_T("下载出错 %d, %s"), k,sErr);
                        int r3 = AfxMessageBox(s1);
                        break;  //跳出
                    }
                }
                if (bError == 0) {
                    NewAppInfo.Length = len1;
                    NewAppInfo.Sign = 0x55AA;
                    NewAppInfo.Version = 0x109;
                    NewAppInfo.nCRC = crc2;
                    int k = theApp.MyKLink1.WriteFirmInfo(1, 0, 0, sizeof(NewAppInfo), (UCHAR*)&NewAppInfo);
                    s1.Format(_T("Write InfoBlock %d bytes = %d"), sizeof(NewAppInfo), k);
                    SysLog(s1);
                    Sleep(100);
                    int r5 = theApp.MyKLink1.ResetDevice(1, 0);
                    s1.Format(_T("ResetDevice  = %d"), r5);
                    SysLog(s1);
                    myLogger1.UpdateLogDisplay();
                    Sleep(2000);
                }
                OnMenuOffline();
                OnMenuOnline();
            }
        }
    }
}
MTerm1/MTerm1CommDevView.h
@@ -15,7 +15,7 @@
#ifdef AFX_DESIGN_TIME
    enum { IDD = IDD_MTerm1CommDevView2    };
#endif
/*
#ifdef _DEBUG
    virtual void AssertValid() const;
    CMTerm1Doc* CMTerm1CommDevView::GetDocument() const
@@ -27,7 +27,7 @@
    virtual void Dump(CDumpContext& dc) const;
#endif
#endif
*/
    protected:
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV 支持
    DECLARE_MESSAGE_MAP()
@@ -54,11 +54,94 @@
//    CToolBar m_wndToolBar;
//    CImageList m_ColorTreeImages;
//    CTreeCtrl m_treectrl1;
    typedef struct tagWLStat
    {
        uint32_t Stat;                            //状态
        uint32_t curStat;                        //当前状态
        uint32_t runStep;                        //工作步骤
        union {
            uint32_t Status;                            //状态
            struct {
                uint32_t bMasterSent : 1;
                uint32_t bMasterRecved : 1;
            };
        };
        uint16_t curStat;                        //当前状态
        uint16_t runStep;                        //工作步骤
        uint16_t RunStat;                        //运行状态
        uint16_t ErrStat;                        //错误状态
        uint32_t RF_Freq;                        //运行频率
        uint16_t nTimeOnAir;
        uint16_t DeviceAddr;
        uint8_t NetWorkAddr;
        uint8_t Tx_Power;            // dBm        5 - 22 dBm
        uint8_t LoraBandWidth;        //        [0: 125 kHz, 1: 250 kHz, 2: 500 kHz, 3: Reserved ]
        uint8_t LoRaFactor;                //        [SF5 .. SF 12]
        uint8_t LoRaCodingRate;        //        [1 : 4/5,  2: 4/6,  3:  4/7,    4:  4/8 ]
        uint8_t LoRaPreambleLen;            // 2 - 12
        uint8_t bEnableAddr;
        uint8_t bEnableEncrypt;
        uint8_t bEnableRelay;
        uint8_t bAutoReSend;        //自动重发
        uint8_t nCurClient;
        uint8_t nSeq;
        uint32_t sentCount;                    //发送计数
        uint32_t recvCount;                    //接收计数
        uint32_t lastSendtime;            //上次发送时间
        uint32_t lastSenttime;            //上次发送出时间
        uint32_t lastRecvtime;            //上次启动接收时间
        uint32_t lastRecvdtime;            //上次接收时间
        uint32_t lastActTime;            //上次动作时间
        uint32_t lastAckTime;            //上次应答时间
        uint32_t lastErrTime;                //上次错误时间
        uint32_t latancy;                        //延迟
        uint32_t cycleTime;                    //循环时间
        uint16_t LostPackets;                //丢包计数
        uint16_t CtnLstPkts;                //连续丢包计数
        uint16_t MaxCtnLstPkts;            //最大连续丢包计数
        uint16_t TXErr;                    //发送错误计数
        uint16_t RXErr;                    //接收错误计数
        uint16_t CRCErr;                 //CRC错误计数
        uint16_t PktErr;                //包错误    ;
        uint16_t ChnErr;                //频道错误;
        uint16_t nErrChn;                //错误的频道号;
        uint16_t CADDoneCount;            //CAD 完成次数
        uint16_t CADOkCount;                //CAD 是次数
        uint16_t CADNgCount;                //CAD 否次数
        uint16_t CADTimeOut;                //CAD 超时次数
        uint16_t StepErr1;                    //步骤错误1
        uint16_t StepErr2;                    //步骤错误2
        uint16_t Err1Count;                    //微闪报警次数
        uint16_t Err2Count;                    //大闪报警次数
        uint16_t Err3Count;                    //严重丢失信号次数
        int8_t RSSI;                                //信号强度
        int8_t SNR;                                //信噪比
        int8_t tRSSI;                            //对方信号强度
        int8_t tSNR;                            //对方信噪比
        uint32_t targetSentCount;            //对方发送数量
        uint32_t targetRecvdCount;        //对方接受数量
    }stWLRunStat, * pstWLRunStat;
    typedef struct tagWLStatV12
    {
        union {
            uint32_t Status;                            //状态
            struct {
                uint32_t bMasterSent : 1;
                uint32_t bMasterRecved : 1;
            };
        };
        uint16_t curStat;                        //当前状态
        uint16_t runStep;                        //工作步骤
        uint16_t RunStat;                        //运行状态
        uint16_t ErrStat;                        //错误状态
        uint32_t RF_Freq;                        //运行频率
        uint32_t nTimeOnAir;
        uint32_t sentCount;                    //发送计数
        uint32_t recvCount;                    //接收计数
        uint32_t lastSendtime;            //上次发送时间
@@ -70,18 +153,20 @@
        uint32_t lastErrTime;                //上次错误时间
        uint32_t latancy;                        //延迟
        uint32_t cycleTime;                    //循环时间
        uint32_t LostPackets;                //丢包计数
        uint32_t CtnLstPkts;                //连续丢包计数
        uint32_t MaxCtnLstPkts;            //最大连续丢包计数
        uint32_t TXErr;                            //发送错误计数
        uint32_t RXErr;                            //接收错误计数
        uint32_t CRCErr;                         //CRC错误计数
        uint32_t CADDoneCount;                //CAD 完成次数
        uint32_t StepErr1;                    //步骤错误1
        uint32_t StepErr2;                    //步骤错误2
        uint32_t Err1Count;                    //微闪报警次数
        uint32_t Err2Count;                    //大闪报警次数
        uint32_t Err3Count;                    //严重丢失信号次数
        uint16_t LostPackets;                //丢包计数
        uint16_t CtnLstPkts;                //连续丢包计数
        uint16_t MaxCtnLstPkts;            //最大连续丢包计数
        uint16_t TXErr;                            //发送错误计数
        uint16_t RXErr;                            //接收错误计数
        uint16_t CRCErr;                         //CRC错误计数
        uint16_t ChnErr;                        //频道错误
        uint16_t PktErr;                        //包错误
        uint16_t CADDoneCount;            //CAD 完成次数
        uint16_t StepErr1;                    //步骤错误1
        uint16_t StepErr2;                    //步骤错误2
        uint16_t Err1Count;                    //微闪报警次数
        uint16_t Err2Count;                    //大闪报警次数
        uint16_t Err3Count;                    //严重丢失信号次数
        int8_t RSSI;                                //信号强度
        int8_t SNR;                                //信噪比
        int8_t tRSSI;                            //对方信号强度
@@ -89,7 +174,60 @@
        uint32_t targetSentCount;            //对方发送数量
        uint32_t targetRecvdCount;        //对方接受数量
    }stWLRunStat, *pstWLRunStat;
    }stWLRunStatV12, *pstWLRunStatV12;
    typedef struct tagWLStatV1
    {
        union {
            uint32_t Status;                            //状态
            struct {
                uint32_t bMasterSent : 1;
                uint32_t bMasterRecved : 1;
            };
        };
        uint16_t curStat;                        //当前状态
        uint16_t runStep;                        //工作步骤
        uint16_t RunStat;                        //运行状态
        uint16_t ErrStat;                        //错误状态
//        uint32_t RF_Freq;                        //运行频率
//        uint32_t nTimeOnAir;
        uint32_t sentCount;                    //发送计数
        uint32_t recvCount;                    //接收计数
        uint32_t lastSendtime;            //上次发送时间
        uint32_t lastSenttime;            //上次发送出时间
        uint32_t lastRecvtime;            //上次启动接收时间
        uint32_t lastRecvdtime;            //上次接收时间
        uint32_t lastActTime;                //上次动作时间
        uint32_t lastAckTime;                //上次应答时间
        uint32_t lastErrTime;                //上次错误时间
        uint32_t latancy;                        //延迟
        uint32_t cycleTime;                    //循环时间
        uint16_t LostPackets;                //丢包计数
        uint16_t CtnLstPkts;                //连续丢包计数
        uint16_t MaxCtnLstPkts;            //最大连续丢包计数
        uint16_t TXErr;                            //发送错误计数
        uint16_t RXErr;                            //接收错误计数
        uint16_t CRCErr;                         //CRC错误计数
//        uint16_t ChnErr;                        //频道错误
//        uint16_t PktErr;                        //包错误
        uint16_t CADDoneCount;            //CAD 完成次数
        uint16_t StepErr1;                    //步骤错误1
        uint16_t StepErr2;                    //步骤错误2
        uint16_t Err1Count;                    //微闪报警次数
        uint16_t Err2Count;                    //大闪报警次数
        uint16_t Err3Count;                    //严重丢失信号次数
        int8_t RSSI;                                //信号强度
        int8_t SNR;                                //信噪比
        int8_t tRSSI;                            //对方信号强度
        int8_t tSNR;                            //对方信噪比
        uint32_t targetSentCount;            //对方发送数量
        uint32_t targetRecvdCount;        //对方接受数量
    }stWLRunStatV1, * pstWLRunStatV1;
    CString KWRunStatToString(pstWLRunStat pWLRunStat1);
    CString KWRunStatToString(pstWLRunStatV1 pWLRunStat1);
    CString KWRunStatToString(pstWLRunStatV12 pWLRunStat1);
    afx_msg void OnClose();
    afx_msg void OnSize(UINT nType, int cx, int cy);
@@ -210,4 +348,7 @@
    afx_msg void OnBnClickedButton3();
    int UpdateLEDDisplay();
    int UpdateStatusBar(int nIndex);
    afx_msg void OnBnClickedButton5();
    afx_msg void OnBnClickedButton9();
    virtual BOOL Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext = NULL);
};
MTerm1/MTerm1CtrlView.cpp
@@ -34,6 +34,7 @@
    ON_BN_CLICKED(IDC_BUTTON_TRNS_TOTXT, &CMTerm1CtrlView::OnBnClickedButtonTrnsTotxt)
    ON_BN_CLICKED(IDC_BUTTON_TRNS_PRG, &CMTerm1CtrlView::OnBnClickedButtonTrnsPrg)
    ON_BN_CLICKED(IDC_BUTTON4, &CMTerm1CtrlView::OnBnClickedButton4)
    ON_WM_SIZE()
END_MESSAGE_MAP()
@@ -161,10 +162,35 @@
{
    // TODO: 在此添加控件通知处理程序代码
    CMTerm1Doc * pDoc = (CMTerm1Doc *)GetDocument();
    pDoc->MyKLink1.fnTest1(2);
    theApp.MyKLink1.fnTest1(2);
    CRect rect1;
    this->GetClientRect(&rect1);
//    this->GetParentFrame()->SetWindowPos(NULL, rect1.left, rect1.top, 100, 200, SWP_NOZORDER);
}
void CMTerm1CtrlView::OnSize(UINT nType, int cx, int cy)
{
    CFormView::OnSize(nType, cx, cy);
    CString s1;
    CWnd* pwnd;
    ///*
    pwnd = GetDlgItem(IDC_EDIT1);
    if (pwnd != NULL)
    {
        CRect    rect1;
        pwnd->GetWindowRect(rect1);
        ScreenToClient(rect1);
        pwnd->SetWindowPos(NULL, 0, 0, rect1.Width(), cy - 20, NULL);
        //        s1.Format(_T("OnSize %d  %d %d \r\n"), nType, cx, cy);
        //((CEdit*)GetDlgItem(IDC_EDIT1))->ReplaceSel(s1);
    }
    // */
    //
    // TODO: 在此处添加消息处理程序代码
}
MTerm1/MTerm1CtrlView.h
@@ -38,6 +38,7 @@
    afx_msg void OnBnClickedButtonTrnsPrg();
    virtual void OnUpdate(CView* /*pSender*/, LPARAM /*lHint*/, CObject* /*pHint*/);
    afx_msg void OnBnClickedButton4();
    afx_msg void OnSize(UINT nType, int cx, int cy);
};
MTerm1/MTerm1Doc.cpp
@@ -77,6 +77,7 @@
CMTerm1Doc::stOpDef CMTerm1Doc::OpDef[] =
{
    {OP_NOP,"NOP",0},
    {OP_END,"ED",0},
    {OP_ST,"ST",1,KLParamCoil},
    {OP_ST_,"ST/",1,KLParamCoil},
    {OP_AN,"AN",1,KLParamCoil},
@@ -179,7 +180,7 @@
//    callbackfuncs.SendPkgFunc = std::bind(&HvSerialPort::Send, &myHvSerialPort1, std::placeholders::_1, std::placeholders::_2);
//    callbackfuncs.RecvPkgFunc = std::bind(&HvSerialPort::Recv, &myHvSerialPort1, std::placeholders::_1, std::placeholders::_2);
//    MyKLink1.SetCallBackFuncs(&callbackfuncs);
//    theApp.MyKLink1.SetCallBackFuncs(&callbackfuncs);
//    StartTime = myHvSerialPort1.GetTimemS();
}
@@ -410,7 +411,7 @@
    CFile file1;
    CFileException e;
    bool r = file1.Open(sFilePathName, CFile::modeReadWrite, &e);//读写模式打开文件
    bool r = file1.Open(sFilePathName, CFile::modeCreate|CFile::modeReadWrite, &e);//读写模式打开文件
    if (r)
    {
@@ -418,12 +419,12 @@
        CStringA sSectionNameA;
        //写入系统配置
        GetSectionTxt(SectionSysCfg, sSectionNameA); //获取系统配置的文本表示
        GetSectionName(SectionSysCfg, sSectionNameA); //获取系统配置的文本表示
        s1A = "[" + sSectionNameA + "]\r\n";
        file1.Write(s1A, s1A.GetLength());//将获取到的文本内容写入文件
        //写入程序
        GetSectionTxt(SectionProg, sSectionNameA); //获取程序的文本表示
        GetSectionName(SectionProg, sSectionNameA); //获取程序的文本表示
        s1A = "[" + sSectionNameA + "]\r\n";
        file1.Write(s1A, s1A.GetLength());//获取到的文本内容写入文件
@@ -431,7 +432,7 @@
        file1.Write(s1A, s1A.GetLength());//将转换后的文本内容写入文件
        //写入注释
        GetSectionTxt(SectionAnno, sSectionNameA); //获取注释的文本表示
        GetSectionName(SectionAnno, sSectionNameA); //获取注释的文本表示
        s1A = "[" + sSectionNameA + "]\r\n";
        file1.Write(s1A, s1A.GetLength());
        //循环遍历所有注释,并将其写入文件
@@ -443,12 +444,12 @@
            file1.Write(s1A, s1A.GetLength());
        }
        //写入触点监控列表
        GetSectionTxt(SectionCoilList, sSectionNameA); //获取触点监控列表的文本表示
        GetSectionName(SectionCoilList, sSectionNameA); //获取触点监控列表的文本表示
        s1A = "[" + sSectionNameA + "]\r\n";
        file1.Write(s1A, s1A.GetLength());
        //写入数据监控列表
        GetSectionTxt(SectionDataList, sSectionNameA); //获取数据监控列表的文本表示
        GetSectionName(SectionDataList, sSectionNameA); //获取数据监控列表的文本表示
        s1A = "[" + sSectionNameA + "]\r\n";
        file1.Write(s1A, s1A.GetLength());
@@ -466,7 +467,7 @@
/// </summary>
/// <param name="txt"></param>
/// <returns></returns>
int CMTerm1Doc::TxtToSection(CStringA txt)
int CMTerm1Doc::TxtToSectionType(CStringA txt)
{
    for (int i = 0; i < nSectionDefCount; i++) {
        if (SectionDef[i].SectionName == txt) {
@@ -482,7 +483,7 @@
/// <param name="nSectionType"></param>
/// <param name="txt"></param>
/// <returns></returns>
int CMTerm1Doc::GetSectionTxt(int nSectionType, CStringA & txt)
int CMTerm1Doc::GetSectionName(int nSectionType, CStringA & txt)
{
    for (int i = 0; i < nSectionDefCount; i++) {
        if (SectionDef[i].nSectionType == nSectionType) {
@@ -872,22 +873,23 @@
        StackDeeps[i] = nCurStackDeep;
    }
    s1.Format(_T("Remaining STs %d"), nSts);
    SysLog(s1);
    s1.Format(_T("Remaining STs %d \r\n"), nSts);
//    SysLog(s1);
    for (int i = 0; i < nSts; i++) {
        s1.Format(_T("[%d] %d "), i, stpos[i]);
        SysLog(s1);
        s1.AppendFormat(_T("[%d] %d\t"), i, stpos[i]);
    }
    s1.Format(_T("Pairs"));
    SysLog(s1);
    s1.Format(_T("Pairs \r\n"));
//    SysLog(s1);
    for (int i = 0; i < m_nProgSteps; i++) {
        int nPairTo = Progs[i].PairTo;
        if (nPairTo > 0) {
            s1.Format(_T("%d -- %d  type:%d"), i, nPairTo, Progs[nPairTo].nOpType1);
            SysLog(s1);
            s1.AppendFormat(_T("%d - %d  type:%d\t"), i, nPairTo, Progs[nPairTo].nOpType1);
        }
    }
    SysLog(s1);
    return 0;
}
int CMTerm1Doc::TransTxtToProg(CStringA ProgTxtA)
@@ -904,6 +906,24 @@
    TransLinesToProg(txtLines);
    return 0;
}
int CMTerm1Doc::AnnoToTxt(CStringA & AnnoTxtA)
{
    CString s1;
    CStringA s1A;
    CStringA sSectionNameA;
    GetSectionName(SectionAnno, sSectionNameA); //获取注释的文本表示
    s1A = "[" + sSectionNameA + "]\r\n";
    //循环遍历所有注释,并将其写入文件
    for (int i = 0; i < nCoilAnnoCount; i++)
    {
        if (mCoilAnnos[i].sAnno.IsEmpty()) { continue; }
        s1 = mCoilAnnos[i].sCoilName + _T("\t") + mCoilAnnos[i].sAnno + _T("\r\n");
        s1A += s1;
    }
    AnnoTxtA = s1A;
    return AnnoTxtA.GetLength();
}
int CMTerm1Doc::ReadAnnoFromTxt(CStringA AnnoTxtA)
@@ -923,11 +943,11 @@
    nCoilAnnoCount = 0;
    int nAnnoSectionLine = 0;
    int nAnnoStartLine = 0;
    int nAnnoLines = 0;
    int nAnnoStartLine = 1;
    int nAnnoLines = txtLineCount - 1;
    int bAnnoSection = GetSectionPos(SectionAnno, &nAnnoSectionLine, &nAnnoLines);
    if (bAnnoSection) { nAnnoStartLine = nAnnoSectionLine + 1; }
//    int bAnnoSection = GetSectionPos(SectionAnno, &nAnnoSectionLine, &nAnnoLines);
//    if (bAnnoSection) { nAnnoStartLine = nAnnoSectionLine + 1; }
    for (int i = nAnnoStartLine; i < nAnnoStartLine + nAnnoLines; i++)
    {
@@ -998,7 +1018,7 @@
            CStringA sSectionNameA;
            sSectionName = sLine.Mid(1, nRightBracket - 1);
            sSectionNameA = sSectionName;
            int theSection = TxtToSection(sSectionNameA);
            int theSection = TxtToSectionType(sSectionNameA);
            s1.Format(_T("+ Line %d  Section %d : [%s] type:%d  "), i + 1, nSectionCount, sSectionName, theSection);
            SysLog(s1);
@@ -1116,6 +1136,7 @@
        //case OP_NOP:
            break;
            //无参数 指令
        case OP_END:
        case OP_NOT:
        case OP_ANS:
        case OP_ORS:
@@ -1280,6 +1301,7 @@
            //case OP_NOP:
            break;
            //无参数 指令
        case OP_END:
        case OP_NOT:
        case OP_ANS:
        case OP_ORS:
@@ -1504,17 +1526,25 @@
    CString s1;
    if (!m_bOnline) {
        r = Connect();
    //    MyKLink1.Open();
    //    theApp.MyKLink1.Open();
    }
    if (!m_bOnline) return;
    r = MyKLink1.ReadRunStat(1,0,0,32,(unsigned short *)&MyKLink1.KMRunStat);
    r = theApp.MyKLink1.ReadRunStat(1,0,0,32,(unsigned short *)&theApp.MyKLink1.KMRunStat);
    USHORT read;
    unsigned short buf1[4096];
    r = theApp.MyKLink1.ReadSysCfgData(1, 0, 0, sizeof(stKMSysCfg), &read, buf1);
    pstKMSysCfg pKMSysCfg = (pstKMSysCfg)buf1;
    pKMSysCfg->nProgBank;
    if (r != 0) {
        AfxMessageBox(_T("UploadFrom PLC Failed"));
        AfxMessageBox(_T("读取 PLC 信息失败"));
        return;
    }
//    AfxMessageBox(_T("UploadFrom PLC From Doc"));
    CString s2;
/*
    s2.Format(_T("Cur Programs %d \r\n"), nBinProgSteps);
    unsigned short * pBinBuf2 = (unsigned short *)BinProgs;
    for (int i = 0; i < nBinProgSteps * 2; i += 8) {
@@ -1525,9 +1555,9 @@
        s2 += s1 + _T("\r\n");
    }
    DbgLog(s2);
    int nBinSteps = MyKLink1.KMRunStat.nBinProgSize;
    s1.Format(_T("program to upload Size %d "), nBinSteps);
*/
    int nBinSteps = pKMSysCfg->nProgSize; //theApp.MyKLink1.KMRunStat.nBinProgSize;
    s1.Format(_T("开始上载程序 大小 %d 步 "), nBinSteps);
    DbgLog(s1);
    USHORT Buf3[2048];
@@ -1536,13 +1566,14 @@
    int nSteps = 64;
    for (int i = 0; i < nUploadSize; i += nSteps) {
        if (i + nSteps > nUploadSize) { nSteps = nUploadSize - i; }
        s1.Format(_T("2 Uploading %d to %d "), i, i + nSteps);
        DbgLog(s1);
        int r = MyKLink1.ReadProgram(1, 2, i, nSteps*2 , Buf3+i);
        s1.Format(_T("Download r = %d "), r);
        s1.Format(_T("上载 %3d to %3d "), i, i + nSteps);
//        DbgLog(s1);
        int r = theApp.MyKLink1.ReadPLCProgram(1, 2, i, nSteps*2 , Buf3+i);
        s1.AppendFormat(_T(" r = %d "), r);
        DbgLog(s1);
        //Update Progress Bar
    }
/*
    s2.Format(_T(" Uploaded from bank 2 \r\n"));
    for (int i = 0; i < nBinSteps * 2; i += 8) {
        s1.Format(_T("%03X: "), i);
@@ -1552,13 +1583,43 @@
        s2 += s1 + _T("\r\n");
    }
    DbgLog(s2);
*/
    for (int i = 0; i < nBinSteps * 2; i++)
    {
        ((USHORT *)BinProgs)[i] = Buf3[i];
    }
    nBinProgSteps = nBinSteps;
    TransBinToProg();
    FindProgPair();
    int AnnoSize = pKMSysCfg->nAnnoSize;
    if (AnnoSize > 4088) { AnnoSize = 4088; }
    s1.Format(_T("开始上载注释 大小 %d 字节"), AnnoSize);
    DbgLog(s1);
    int nBlockSize = 64;
    UCHAR buf5[4096];
    for (int i = 0; i < AnnoSize; i += nBlockSize)
    {
        if (i + nBlockSize > AnnoSize) { nBlockSize = AnnoSize - i; }
        s1.Format(_T("上载注释 %3d to %3d "), i, i + nBlockSize);
        int r = theApp.MyKLink1.ReadPLCAnno(1, 2, i, nBlockSize, buf5 + i);
        s1.AppendFormat(_T(" r = %d \r\n"), r);
//        for (int j = 0; j < nBlockSize; j++) {
//            s1.AppendFormat(_T("%02X "), buf5[i+ j]);
//        }
        DbgLog(s1);
    }
    CStringA s1A;
    char * p1 = s1A.GetBufferSetLength(4096);
    memcpy(p1, buf5, AnnoSize);
    p1[AnnoSize] = 0;
    s1A.ReleaseBuffer();
    s1 = s1A;
//    DbgLog(s1);
    ReadAnnoFromTxt(s1A);
    UpdateAllViews(NULL);
}
@@ -1569,7 +1630,7 @@
    CString s1;
    if (!m_bOnline) {
        r=Connect();
    //    MyKLink1.Open();
    //    theApp.MyKLink1.Open();
    }
    if (!m_bOnline) return 0;
@@ -1582,7 +1643,7 @@
    // 下载程序
    s1.Format(_T("Start Download Program ..."));
    DbgLog(s1);
    r = MyKLink1.StartProgram(1,2);
    r = theApp.MyKLink1.StartDownloadPLCProgram(1,2,nBinProgSteps * 4);
    s1.Format(_T("Result = %d"),r);
    DbgLog(s1);
    int DownloadSize = nBinProgSteps;
@@ -1595,7 +1656,7 @@
        do {
            s1.Format(_T("Downloading %d to %d "), i, i + Steps);
            DbgLog(s1);
            r = MyKLink1.WriteProgram(1, 2, (i) * 4, Steps * 4, (USHORT*)&BinProgs[i]);
            r = theApp.MyKLink1.DownloadPLCProgram(1, 2, (i) * 4, Steps * 4, (USHORT*)&BinProgs[i]);
            s1.Format(_T("Download r = %d "), r);
            DbgLog(s1);
            n += 1;
@@ -1606,12 +1667,35 @@
    s1.Format(_T("Finish Downloading "));
    DbgLog(s1);
    r = MyKLink1.FinishProgram(1,2,nBinProgSteps);
    r = theApp.MyKLink1.FinishDownloadPLCProgram(1,2,nBinProgSteps);
    s1.Format(_T("Download Finished  r = %d "), r);
    DbgLog(s1);
    // 下载注释
    CStringA AnnoTxtA;
    int len3 = AnnoToTxt(AnnoTxtA);
    unsigned char buf1[4096];
    if (len3 > 4088) { len3 = 4088; }
    memcpy(buf1, AnnoTxtA.GetBuffer(), len3);
    AnnoTxtA.ReleaseBuffer();
    s1.Format(_T("开始下载注释 ... %d bytes "),len3);
    DbgLog(s1);
    s1 = AnnoTxtA;
    DbgLog(s1);
    r = theApp.MyKLink1.StartDownloadPLCAnno(1, 1, len3);
    int nBlockSize = 64;
    for (int i = 0; i < len3; i += nBlockSize) {
        if (i + nBlockSize > len3) { nBlockSize = len3 - i; }
        s1.Format(_T("Downloading %d to %d "), i, i + nBlockSize);
        DbgLog(s1);
        r = theApp.MyKLink1.DownloadPLCAnno(1, 1,i,nBlockSize,buf1+i);
        s1.Format(_T("Download r = %d "), r);
        DbgLog(s1);
    }
    s1.Format(_T("Finish Downloading 注释"));
    DbgLog(s1);
    r = theApp.MyKLink1.FinishDownloadPLCAnno(1, 1, len3);
    s1.Format(_T("Download Finished  r = %d "), r);
    DbgLog(s1);
    // 下载系统寄存器配置
    //启动运行
@@ -1640,7 +1724,7 @@
    if (!m_bOnline)
    {
        r = Connect();
        //MyKLink1.Open();
        //theApp.MyKLink1.Open();
    }
    if (!m_bOnline) return;
//    m_bOnline = true;
@@ -1660,9 +1744,11 @@
    if (m_bOnline)
    {
        r = DisConnect();
        MyKLink1.Close();
        theApp.MyKLink1.Close();
    }
    m_bPlcRunning = false;
    m_bOnline = false;
    UpdateAllViews(NULL, UpdataHint::UpdateStat);
}
@@ -1670,6 +1756,19 @@
{
    // TODO: 在此添加命令更新用户界面处理程序代码
    pCmdUI->SetCheck(m_bOnline == false);
//    pCmdUI->SetCheck(false);
}
void CMTerm1Doc::OnUpdateSimulate(CCmdUI* pCmdUI)
{
    // TODO: 在此添加命令更新用户界面处理程序代码
    pCmdUI->SetCheck(m_bSimulate == true);
}
void CMTerm1Doc::OnUpdatePlcRun(CCmdUI* pCmdUI)
{
    // TODO: 在此添加命令更新用户界面处理程序代码
    pCmdUI->SetCheck(m_bPlcRunning == true);
    if (!m_bPlcRunning)     pCmdUI->SetText(_T("PLC模式[PROG]"));
    else     pCmdUI->SetText(_T("PLC模式[RUN]"));
}
void CMTerm1Doc::OnSimulate()
@@ -1705,12 +1804,6 @@
    UpdateAllViews(NULL, UpdataHint::UpdateStat);
}
void CMTerm1Doc::OnUpdateSimulate(CCmdUI *pCmdUI)
{
    // TODO: 在此添加命令更新用户界面处理程序代码
    pCmdUI->SetCheck(m_bSimulate == true);
}
int CMTerm1Doc::StartPLC()
{
    // TODO: 在此处添加实现代码.
@@ -1730,10 +1823,11 @@
        for (int i = 0; i < TOTALTIMERS; i++) {
            KMem.Timers[i] = { 0 };
        }
        myKMachine1.nScanCount = 0;
        nScanCount = 0;
        m_bPlcRunning = 1;
    }else {
        MyKLink1.ChangeMode(1, 1);
        theApp.MyKLink1.ChangeMode(1, 1);
        m_bPlcRunning = 1;
    }
    return 0;
@@ -1747,7 +1841,7 @@
        m_bPlcRunning = false;
    }
    else {
        MyKLink1.ChangeMode(1, 0);
        theApp.MyKLink1.ChangeMode(1, 0);
        m_bPlcRunning = false;
    }
@@ -1765,22 +1859,13 @@
    UpdateAllViews(NULL, UpdataHint::UpdateStat);
}
void CMTerm1Doc::OnUpdatePlcRun(CCmdUI *pCmdUI)
{
    // TODO: 在此添加命令更新用户界面处理程序代码
    pCmdUI->SetCheck(m_bPlcRunning == true);
    if (!m_bPlcRunning)     pCmdUI->SetText(_T("PLC模式[PROG]"));
    else     pCmdUI->SetText(_T("PLC模式[RUN]"));
}
int CMTerm1Doc::SetCommParam()
{
    // TODO: 在此处添加实现代码.
    CString s1;
    s1.Format(_T("Doc SetupComm"));
    SysLog(s1);
    MyKLink1.SetCommParam();
    theApp.MyKLink1.SetCommParam();
    return 0;
/*
    CDialogCommSet1 dialog1;
@@ -1808,9 +1893,9 @@
    // TODO: 在此处添加实现代码.
    CString s1;
    unsigned short buf1[32];
    int res = MyKLink1.Connect();
    int res = theApp.MyKLink1.Connect();
    unsigned short len1;
    int j=MyKLink1.GetInfo(1, &len1, buf1);
    int j=theApp.MyKLink1.GetInfo(1, &len1, buf1);
    s1.Format(_T("GetInfo = %d %d \r\n"), j,len1);
    if (j==0 && len1 > 0) {
        for (int i = 0; i < len1/2; i++) {
@@ -1819,19 +1904,19 @@
        s1 += _T("\r\n");
        pKMInfoBlock pinfob = (pKMInfoBlock)buf1;
        s1.AppendFormat(_T(" DeviceType %04X \r\n"),pinfob->nDeviceTypeVer);
        s1.AppendFormat(_T(" DeviceType %04X \t "),pinfob->nDeviceTypeVer);
        s1.AppendFormat(_T(" nProgVer %04X \r\n"), pinfob->nProgVer);
        s1.AppendFormat(_T(" nKLinkVer %04X \r\n"), pinfob->nKLinkVer);
        s1.AppendFormat(_T(" nKLinkVer %04X \t"), pinfob->nKLinkVer);
        s1.AppendFormat(_T(" nKBusVer %04X \r\n"), pinfob->nKBusVer);
        s1.AppendFormat(_T(" nCapacity1 %d k\r\n"), pinfob->nCapacity1);
        s1.AppendFormat(_T(" nCapacity1 %d k \t"), pinfob->nCapacity1);
        s1.AppendFormat(_T(" nCapacity2 %d k\r\n"), pinfob->nCapacity2);
        s1.AppendFormat(_T(" nDInput %d \r\n"), pinfob->nDInput);
        s1.AppendFormat(_T(" nDInput %d \t"), pinfob->nDInput);
        s1.AppendFormat(_T(" nDOutput %d \r\n"), pinfob->nDOutput);
        s1.AppendFormat(_T(" nAInput %d \r\n"), pinfob->nAInput);
        s1.AppendFormat(_T(" nAInput %d \t"), pinfob->nAInput);
        s1.AppendFormat(_T(" nAOutput %d \r\n"), pinfob->nAOutput);
        s1.AppendFormat(_T(" nHInput %d \r\n"), pinfob->nHInput);
        s1.AppendFormat(_T(" nHInput %d   \t"), pinfob->nHInput);
        s1.AppendFormat(_T(" nHOutput %d \r\n"), pinfob->nHOutput);
        s1.AppendFormat(_T(" nExt1 %d \r\n"), pinfob->nExt1);
        s1.AppendFormat(_T(" nExt1 %d \t"), pinfob->nExt1);
        s1.AppendFormat(_T(" nExt2 %d \r\n"), pinfob->nExt2);
        s1.AppendFormat(_T(" nLogSize %d \r\n"), pinfob->nLogSize);
        s1.AppendFormat(_T(" nPorts %d \r\n"), pinfob->nPorts);
@@ -1841,31 +1926,32 @@
    }
    SysLog(s1);
    int r = MyKLink1.ReadRunStat(1, 0, 0, 32, (unsigned short*)&MyKLink1.KMRunStat);
    int r = theApp.MyKLink1.ReadRunStat(1, 0, 0, 32, (unsigned short*)&theApp.MyKLink1.KMRunStat);
    s1.Format(_T("GetRunStat = %d %d \r\n"), r, 32);
    KLink1::stRunStat RunStat1 = MyKLink1.KMRunStat;
    KLink1::stRunStat RunStat1 = theApp.MyKLink1.KMRunStat;
    s1.AppendFormat(_T(" Sign1 %04X \r\n"), RunStat1.Sign1);
    s1.AppendFormat(_T(" Sign1 %04X \t"), RunStat1.Sign1);
    s1.AppendFormat(_T(" Seq1 %d \r\n"), RunStat1.Seq1);
    s1.AppendFormat(_T(" PowerCount %d \r\n"), RunStat1.PowerCount);
    s1.AppendFormat(_T(" Reserved1 %d \r\n"), RunStat1.Reserved1);
    s1.AppendFormat(_T(" UpTime %d \r\n"), RunStat1.UpTime);
    s1.AppendFormat(_T(" UserData1 %d \r\n"), RunStat1.UserData1);
    s1.AppendFormat(_T(" WorkMode %d \r\n"), RunStat1.WorkMode);
    s1.AppendFormat(_T(" WorkMode %d \t"), RunStat1.WorkMode);
    s1.AppendFormat(_T(" WorkMode2 %d \r\n"), RunStat1.WorkMode2);
    s1.AppendFormat(_T(" nBinProgBank %d \r\n"), RunStat1.nBinProgBank);
    s1.AppendFormat(_T(" nBinProgBank %d \t"), RunStat1.nBinProgBank);
    s1.AppendFormat(_T(" nBinProgSize %d \r\n"), RunStat1.nBinProgSize);
    s1.AppendFormat(_T(" bLEDFlick %d \r\n"), RunStat1.bLEDFlick);
    s1.AppendFormat(_T(" Reserved2 %d \r\n"), RunStat1.Reserved2);
    s1.AppendFormat(_T(" CRC1 %04X \r\n"), RunStat1.CRC1);
    s1.AppendFormat(_T(" EndSign1 %04X \r\n"), RunStat1.EndSign1);
    SysLog(s1);
    unsigned char value;
    r = MyKLink1.GetMode(1, 0, &value);
    r = theApp.MyKLink1.GetMode(1, 0, &value);
    if (r == KLink1::KL_OK) { m_bPlcRunning = value; }
    s1.Format(_T("PLC Mode = %d"), value);
    SysLog(s1);
//    m_static_connect.SetCtlColor(RGB(0, 255, 0));
/*
    if (!m_bCommParamSet)
@@ -1883,7 +1969,7 @@
    if (r == myHvSerialPort1.R_OK)
    {
        m_bOnline = true;
//        MyKLink1.Open();
//        theApp.MyKLink1.Open();
//        m_static_connect.SetCtlColor(RGB(0, 255, 0));
        return 0;
    }
@@ -1897,8 +1983,9 @@
    // TODO: 在此处添加实现代码.
    if (!m_bOnline) return -1;
//    myHvSerialPort1.Close();
    MyKLink1.Close();
    theApp.MyKLink1.Close();
    m_bOnline = false;
    m_bPlcRunning = false;
    return 0;
}
@@ -2037,6 +2124,7 @@
void CMTerm1Doc::OnMenuCommTest()
{
    // TODO: 在此添加命令处理程序代码
/*
    CString s1;
    CView * pView;
    pView = FindView(RUNTIME_CLASS(CMTerm1CommDevView));
@@ -2052,6 +2140,7 @@
        ASSERT_KINDOF(CFrameWnd, pFrame);
        theApp.m_pCommDevViewTemplate->InitialUpdateFrame(pFrame, this);
    }
*/
}
@@ -2090,7 +2179,7 @@
    if (m_bOnline && 0)
    {
        unsigned char value = 0;
        MyKLink1.ReadBit(1, nCoilType, nCoilAddr, &value);
        theApp.MyKLink1.ReadBit(1, nCoilType, nCoilAddr, &value);
        return value;
    }
    int nWordAddr = nCoilAddr >> 4;
@@ -2149,7 +2238,7 @@
    {
        unsigned char value =nCoilValue;
        int res = 0;
        res = MyKLink1.WriteBit(1, nCoilType, nCoilAddr, value);
        res = theApp.MyKLink1.WriteBit(1, nCoilType, nCoilAddr, value);
        return res;
    }
@@ -2198,7 +2287,7 @@
    }
    if (m_bOnline)
    {
//        MyKLink1.WriteBit(1, nCoilType, nCoilAddr, nCoilValue);
//        theApp.MyKLink1.WriteBit(1, nCoilType, nCoilAddr, nCoilValue);
    }
    return 0;
}
@@ -2215,7 +2304,7 @@
            return nDataAddr;
        }
        MyKLink1.ReadDataWord(1,  nDataType, nDataAddr, 2, &nCount, value);// (unsigned char *)&KMem.DT[nDataAddr]);
        theApp.MyKLink1.ReadDataWord(1,  nDataType, nDataAddr, 2, &nCount, value);// (unsigned char *)&KMem.DT[nDataAddr]);
        svalue = value[0];
        return svalue;
    }
@@ -2300,7 +2389,7 @@
        unsigned short svalue[10];
        svalue[0]=nDataValue;
        int res = 0;
        res = MyKLink1.WriteDataWord(1, nDataType, nDataAddr, 2, svalue);
        res = theApp.MyKLink1.WriteDataWord(1, nDataType, nDataAddr, 2, svalue);
        return res;
    }
@@ -2398,7 +2487,7 @@
    // TODO: 在此处添加实现代码.
    CString s1;
    if (m_bSimulate) {
        int nDataType = MyKLink1.KLDataTypeWX;
        int nDataType = theApp.MyKLink1.KLDataTypeWX;
        int nDataAddr = 0;
        int nDataCount = 4;
//        int res;
@@ -2406,129 +2495,148 @@
            KMem.WX[i] = myKMachine1.KMem.WX[i];
        }
        nDataType = MyKLink1.KLDataTypeWY;
        nDataType = theApp.MyKLink1.KLDataTypeWY;
        nDataAddr = 0;
        nDataCount = 4;
        for (int i = 0; i < nDataCount; i++) {
            KMem.WY[i] = myKMachine1.KMem.WY[i];
        }
        nDataType = MyKLink1.KLDataTypeWLX;
        nDataType = theApp.MyKLink1.KLDataTypeWLX;
        nDataAddr = 0;
        nDataCount = 4;
        for (int i = 0; i < nDataCount; i++) {
            KMem.WLX[i] = myKMachine1.KMem.WLX[i];
        }
        nDataType = MyKLink1.KLDataTypeWLY;
        nDataType = theApp.MyKLink1.KLDataTypeWLY;
        nDataAddr = 0;
        nDataCount = 4;
        for (int i = 0; i < nDataCount; i++) {
            KMem.WLY[i] = myKMachine1.KMem.WLY[i];
        }
        nDataType = MyKLink1.KLDataTypeWR;
        nDataType = theApp.MyKLink1.KLDataTypeWR;
        nDataAddr = 0;
        nDataCount = 10;
        for (int i = 0; i < nDataCount; i++) {
            KMem.WR[i] = myKMachine1.KMem.WR[i];
        }
        nDataType = MyKLink1.KLDataTypeDT;
        nDataType = theApp.MyKLink1.KLDataTypeDT;
        nDataAddr = 0;
        nDataCount = 80;
        nDataCount = 128;
        for (int i = 0; i < nDataCount; i++) {
            KMem.DT[i] = myKMachine1.KMem.DT[i];
        }
        nDataType = MyKLink1.KLDataTypeSV;
        nDataType = theApp.MyKLink1.KLDataTypeSV;
        nDataAddr = 0;
        nDataCount = 40;
        for (int i = 0; i < nDataCount; i++) {
            KMem.SV[i] = myKMachine1.KMem.SV[i];
        }
        //res = MyKLink1.ReadDataWord(1, nDataCount, nDataType, nDataAddr, KMem.SV);// (unsigned char *)&KMem.DT[nDataAddr]);
        //res = theApp.MyKLink1.ReadDataWord(1, nDataCount, nDataType, nDataAddr, KMem.SV);// (unsigned char *)&KMem.DT[nDataAddr]);
        nDataType = MyKLink1.KLDataTypeEV;
        nDataType = theApp.MyKLink1.KLDataTypeEV;
        nDataAddr = 0;
        nDataCount = 40;
        for (int i = 0; i < nDataCount; i++) {
            KMem.EV[i] = myKMachine1.KMem.EV[i];
        }
//        res = MyKLink1.ReadDataWord(1, nDataCount, nDataType, nDataAddr, KMem.EV);// (unsigned char *)&KMem.DT[nDataAddr]);
//        res = theApp.MyKLink1.ReadDataWord(1, nDataCount, nDataType, nDataAddr, KMem.EV);// (unsigned char *)&KMem.DT[nDataAddr]);
    }else if (m_bOnline)
    {
        int nDataType = MyKLink1.KLDataTypeWX;
        if (theApp.MyKLink1.m_nContinueErrCount > 10) {
            DisConnect();
        }
        int nDataType = theApp.MyKLink1.KLDataTypeWX;
        int nDataAddr = 0;
        int nDataCount = 4;
        int nDataCount = 16;
        unsigned short nCount;
        int res;
        res = MyKLink1.ReadDataWord(1, nDataType, nDataAddr, nDataCount, &nCount, KMem.WX);// (unsigned char *)&KMem.DT[nDataAddr]);
        if (res != MyKLink1.KL_OK) {
            s1.Format(_T("R:= %d %s  \r\n"), res, MyKLink1.m_resultStr);
        res = theApp.MyKLink1.ReadDataWord(1, nDataType, nDataAddr, nDataCount, &nCount, KMem.WX);// (unsigned char *)&KMem.DT[nDataAddr]);
        if (res != theApp.MyKLink1.KL_OK) {
            s1.Format(_T("R:= %d %s  \r\n"), res, theApp.MyKLink1.m_resultStr);
            SysLog(s1);
        }
        nDataType = MyKLink1.KLDataTypeWY;
        nDataType = theApp.MyKLink1.KLDataTypeWY;
        nDataAddr = 0;
        nDataCount = 4;
        res = MyKLink1.ReadDataWord(1, nDataType, nDataAddr, nDataCount, &nCount, KMem.WY);// (unsigned char *)&KMem.DT[nDataAddr]);
        if (res != MyKLink1.KL_OK) {
            s1.Format(_T("R:= %d %s  \r\n"), res, MyKLink1.m_resultStr);
        nDataCount = 16;
        res = theApp.MyKLink1.ReadDataWord(1, nDataType, nDataAddr, nDataCount, &nCount, KMem.WY);// (unsigned char *)&KMem.DT[nDataAddr]);
        if (res != theApp.MyKLink1.KL_OK) {
            s1.Format(_T("R:= %d %s  \r\n"), res, theApp.MyKLink1.m_resultStr);
            SysLog(s1);
        }
        nDataType = MyKLink1.KLDataTypeWLX;
        nDataType = theApp.MyKLink1.KLDataTypeWLX;
        nDataAddr = 0;
        nDataCount = 4;
        res = MyKLink1.ReadDataWord(1, nDataType, nDataAddr, nDataCount, &nCount, KMem.WLX);// (unsigned char *)&KMem.DT[nDataAddr]);
        if (res != MyKLink1.KL_OK) {
            s1.Format(_T("R:= %d %s  \r\n"), res, MyKLink1.m_resultStr);
        nDataCount = 8;
        res = theApp.MyKLink1.ReadDataWord(1, nDataType, nDataAddr, nDataCount, &nCount, KMem.WLX);// (unsigned char *)&KMem.DT[nDataAddr]);
        if (res != theApp.MyKLink1.KL_OK) {
            s1.Format(_T("R:= %d %s  \r\n"), res, theApp.MyKLink1.m_resultStr);
            SysLog(s1);
        }
        nDataType = MyKLink1.KLDataTypeWLY;
        nDataType = theApp.MyKLink1.KLDataTypeWLY;
        nDataAddr = 0;
        nDataCount = 4;
        res = MyKLink1.ReadDataWord(1, nDataType, nDataAddr, nDataCount, &nCount, KMem.WLY);// (unsigned char *)&KMem.DT[nDataAddr]);
        if (res != MyKLink1.KL_OK) {
            s1.Format(_T("R:= %d %s  \r\n"), res, MyKLink1.m_resultStr);
        nDataCount = 8;
        res = theApp.MyKLink1.ReadDataWord(1, nDataType, nDataAddr, nDataCount, &nCount, KMem.WLY);// (unsigned char *)&KMem.DT[nDataAddr]);
        if (res != theApp.MyKLink1.KL_OK) {
            s1.Format(_T("R:= %d %s  \r\n"), res, theApp.MyKLink1.m_resultStr);
            SysLog(s1);
        }
        nDataType = MyKLink1.KLDataTypeWR;
        nDataType = theApp.MyKLink1.KLDataTypeWR;
        nDataAddr = 0;
        nDataCount = 16;
        res = theApp.MyKLink1.ReadDataWord(1, nDataType, nDataAddr, nDataCount, &nCount, KMem.WR);// (unsigned char *)&KMem.DT[nDataAddr]);
        if (res != theApp.MyKLink1.KL_OK) {
            s1.Format(_T("R:= %d %s  \r\n"), res, theApp.MyKLink1.m_resultStr);
            SysLog(s1);
        }
        nDataType = theApp.MyKLink1.KLDataTypeWSR;
        nDataAddr = 0;
        nDataCount = 10;
        res = MyKLink1.ReadDataWord(1, nDataType, nDataAddr, nDataCount, &nCount, KMem.WR);// (unsigned char *)&KMem.DT[nDataAddr]);
        if (res != MyKLink1.KL_OK) {
            s1.Format(_T("R:= %d %s  \r\n"), res, MyKLink1.m_resultStr);
        res = theApp.MyKLink1.ReadDataWord(1, nDataType, nDataAddr, nDataCount, &nCount, KMem.WSR);// (unsigned char *)&KMem.DT[nDataAddr]);
        if (res != theApp.MyKLink1.KL_OK) {
            s1.Format(_T("R:= %d %s  \r\n"), res, theApp.MyKLink1.m_resultStr);
            SysLog(s1);
        }
        nDataType = MyKLink1.KLDataTypeDT;
        nDataType = theApp.MyKLink1.KLDataTypeDT;
        nDataAddr = 0;
        nDataCount = 80;
        res = MyKLink1.ReadDataWord(1, nDataType, nDataAddr, nDataCount, &nCount, KMem.DT);// (unsigned char *)&KMem.DT[nDataAddr]);
        if (res != MyKLink1.KL_OK) {
            s1.Format(_T("R:= %d %s  \r\n"), res, MyKLink1.m_resultStr);
        nDataCount = 64;
        res = theApp.MyKLink1.ReadDataWord(1, nDataType, nDataAddr, nDataCount, &nCount, KMem.DT);// (unsigned char *)&KMem.DT[nDataAddr]);
        if (res != theApp.MyKLink1.KL_OK) {
            s1.Format(_T("R:= %d %s  \r\n"), res, theApp.MyKLink1.m_resultStr);
            SysLog(s1);
        }
        nDataType = MyKLink1.KLDataTypeSV;
        nDataAddr = 0;
        nDataCount = 40;
        res = MyKLink1.ReadDataWord(1, nDataType, nDataAddr, nDataCount, &nCount, KMem.SV);// (unsigned char *)&KMem.DT[nDataAddr]);
        if (res != MyKLink1.KL_OK) {
            s1.Format(_T("R:= %d %s  \r\n"), res, MyKLink1.m_resultStr);
        nDataAddr = 64;
        nDataCount = 64;
        res = theApp.MyKLink1.ReadDataWord(1, nDataType, nDataAddr, nDataCount, &nCount, &KMem.DT[64]);// (unsigned char *)&KMem.DT[nDataAddr]);
        if (res != theApp.MyKLink1.KL_OK) {
            s1.Format(_T("R:= %d %s  \r\n"), res, theApp.MyKLink1.m_resultStr);
            SysLog(s1);
        }
        nDataType = MyKLink1.KLDataTypeEV;
        nDataType = theApp.MyKLink1.KLDataTypeSV;
        nDataAddr = 0;
        nDataCount = 40;
        res = MyKLink1.ReadDataWord(1, nDataType, nDataAddr, nDataCount, &nCount, KMem.EV);// (unsigned char *)&KMem.DT[nDataAddr]);
        if (res != MyKLink1.KL_OK) {
            s1.Format(_T("R:= %d %s  \r\n"), res, MyKLink1.m_resultStr);
        nDataCount = 64;
        res = theApp.MyKLink1.ReadDataWord(1, nDataType, nDataAddr, nDataCount, &nCount, KMem.SV);// (unsigned char *)&KMem.DT[nDataAddr]);
        if (res != theApp.MyKLink1.KL_OK) {
            s1.Format(_T("R:= %d %s  \r\n"), res, theApp.MyKLink1.m_resultStr);
            SysLog(s1);
        }
        nDataType = theApp.MyKLink1.KLDataTypeEV;
        nDataAddr = 0;
        nDataCount = 64;
        res = theApp.MyKLink1.ReadDataWord(1, nDataType, nDataAddr, nDataCount, &nCount, KMem.EV);// (unsigned char *)&KMem.DT[nDataAddr]);
        if (res != theApp.MyKLink1.KL_OK) {
            s1.Format(_T("R:= %d %s  \r\n"), res, theApp.MyKLink1.m_resultStr);
            SysLog(s1);
        }
    }
MTerm1/MTerm1Doc.h
@@ -30,7 +30,7 @@
    // CSerialCom MySerialCom1;
//    HvSerialPort myHvSerialPort1;
    KMachine myKMachine1;
    KLink1 MyKLink1;
//    KLink1 MyKLink1;
    union {
        unsigned char KBDD[2048];
@@ -108,7 +108,7 @@
        int nBinStep;            //指令步
        int nParamCount;        //参数数量
        stParam Params[3];        //参数们
        int PairTo;                //对应指令
        int PairTo=0;                //对应指令
        stProg() {};
        stProg(CStringA sOpStr) {};
        stProg(int nOpType):nOpType1(nOpType) { nParamCount = 0; }
@@ -174,8 +174,8 @@
    };
    int nSectionDefCount = sizeof(SectionDef) / sizeof(stSectionDef);
    int TxtToSection(CStringA txt);
    int GetSectionTxt(int nSectionType, CStringA& txt);
    int TxtToSectionType(CStringA txt);
    int GetSectionName(int nSectionType, CStringA& txt);
    int ScanSections();
    struct stSection {
@@ -207,6 +207,8 @@
    int TransTxtToProg(CStringA ProgTxtA);
    int ReadAnnoFromTxt(CStringA AnnoTxtA);
    int AnnoToTxt(CStringA& AnnoTxtA);
    int TransProgToBin();
    int TransBinToProg();
MTerm1/MTerm1View.cpp
@@ -82,7 +82,7 @@
//    ON_COMMAND(ID_INDICATOR_MONITOR_STATUS, &CMTerm1View::OnIndicatorMonitorStatus)
//    ON_UPDATE_COMMAND_UI(ID_INDICATOR_MONITOR_STATUS, &CMTerm1View::OnUpdateIndicatorMonitorStatus)
ON_WM_KEYDOWN()
    ON_WM_KEYDOWN()
END_MESSAGE_MAP()
@@ -754,6 +754,15 @@
    {
    }
    else if (nType == typeEND)    {
        if (needReDraw) {
            //画左侧横线
            //DrawLeftRightLine(pDC, x0, y0, 14, 18);
            DrawAngleBracket(pDC, x0, y0, 8, 32);
            DrawCellText1(pDC, _T("ED"), x0 + 16, y0 + m_LinePosY - 8, 24, 14);
        }
    }
    else if (nType == typeLine1)
    {    //Draw Line
        //画直横线
@@ -1311,8 +1320,10 @@
        m_nCurProgStep = Cells[nRow][nCol].nProgStep;
    }
    if (!pDoc->m_bOnline) return;
    //if (!m_bMonitoring) return;
    if (!m_bMonitoring || !pDoc->m_bOnline) {
    };
    CString sParam;
    sParam = Cells[nRow][nCol].sParam;
    int nDataType, nDataAddr, nStat;
@@ -1448,13 +1459,14 @@
    // TODO: 在此添加消息处理程序代码和/或调用默认值
    CString s1;
    CMTerm1Doc * pDoc = (CMTerm1Doc*)GetDocument();
    static int nCount = 0;
    if (nIDEvent == 0) {
    }
    else if (nIDEvent == 1)
    {
        if (m_bMonitoring) {
        nCount++;
        if (m_bMonitoring && (nCount &1)) {
            //this->RedrawWindow();
            DoReDraw();
        }
@@ -2000,6 +2012,34 @@
            {
            case OP_NOP:
                break;
            case OP_END:
                nCellType =  typeEND;
                nCurLine = cy;
                cx = 0;
                if (cx <= m_CellPerLine) {
                    int hasData = 1;
                    while (hasData) {
                        hasData = 0;
                        for (int j = 0; j < m_CellPerLine; j++) {
                            if (Cells[nCurLine][j].nType != 0) {
                                nCurLine++; hasData = 1; break;
                            }
                        }
                    }
                    cy = nCurLine;
                    for (int j = 0; j < m_CellPerLine; j++)
                    {
                        Cells[cy][j].nType = typeLine1;
                    }
                    Cells[cy][m_CellPerLine - 1].nType = nCellType;
                    Cells[cy][cx].nOpType = nOp;
                    Cells[cy][m_CellPerLine - 1].nProgStep = i;
                }
                if (cy > maxy) { maxy = cy; }
                //cy++;
                break;
                break;
            case OP_ST:
            case OP_ST_:
                if (i == 0) 
@@ -2417,7 +2457,7 @@
                nSts--;
                nEndPts--;
                cy = EndPt[nEndPts].y;
                cx = EndPt[nEndPts].x;
            //    cx = EndPt[nEndPts].x;
                break;
            case OP_PSHS:
                EndPt[nEndPts] = POINT{ cx,cy };
@@ -2513,6 +2553,24 @@
            case OP_TMR:
            case OP_TMX:
            case OP_TMY:
                nCurLine = cy;
                {
                    int hasData = 1;
                    while (hasData) {
                        hasData = 0;
                        for (int j = cx; j < m_CellPerLine; j++) {
                            if (Cells[nCurLine][j].nType != 0) {
                                nCurLine++; hasData = 1; break;
                            }
                        }
                    }
                    //if (nCurLine > maxy)    maxy = nCurLine;
                    for (int j = cy; j < nCurLine; j++) {
                        Cells[j][cx].bLeftLineDn = 1;
                        Cells[j + 1][cx].bLeftLineUp = 1;
                    }
                }
                cy = nCurLine;
                Cells[cy][cx].nType = typeTM;
                Cells[cy][cx].nOpType = nOp;
                Cells[cy][cx].nProgStep = i;
@@ -2635,11 +2693,12 @@
    if (nType == typeNO)
     {
        CMTerm1Doc::stProg prog0;
        if (nOp >= 1 && nOp <= 255) {
            prog0.nOpType1 = nOp; // OP_AN;
        }
        else if (CellX==0) {
        if (CellX == 0) {
            prog0.nOpType1 = OP_ST; // OP_AN;
        }else
        if (nOp >= 1 && nOp <= 255) {
            //prog0.nOpType1 = nOp; // OP_AN;
            prog0.nOpType1 = OP_AN; // OP_AN;
        }
        else {
            prog0.nOpType1 = OP_AN; // OP_AN;
@@ -2656,13 +2715,14 @@
    }
    else if (nType == typeNC) {
        CMTerm1Doc::stProg prog0;
        if (nOp >= 1 && nOp <= 255) {
            prog0.nOpType1 = nOp; // OP_AN;
        }
        else if (CellX == 0) {
        if (CellX == 0) {
            prog0.nOpType1 = OP_ST_; // OP_AN;
        }
        else {
        else if (nOp >= 1 && nOp <= 255) {
            //prog0.nOpType1 = nOp; // OP_AN;
            prog0.nOpType1 = OP_AN_; // OP_AN;
        }
        else  {
            prog0.nOpType1 = OP_AN_; // OP_AN;
        }
        prog0.nParamCount = 1;
@@ -2674,6 +2734,9 @@
        prog0.Params[0].nParamType = nCoilType;
        prog0.Params[0].nParamAddr = nCoilAddr;
        theNode.prog1.Append(prog0);
    }
    else if (nType == typeEND) {
        theNode.prog1.Append(CMTerm1Doc::stProg(OP_END));
    }
    else if (nType == typePP) {
        CMTerm1Doc::stProg prog0;
@@ -2939,6 +3002,15 @@
        node* pThisNode1 = ptheArc1->headvex;    // 第一个实节点
        stProgSection prog1 = pThisNode1->prog1;
        if (prog1.Progs[0].nOpType1 == OP_AN) { prog1.Progs[0].nOpType1 = OP_ST; }
        else if (prog1.Progs[0].nOpType1 == OP_AN_) { prog1.Progs[0].nOpType1 = OP_ST_; }
        else if (prog1.Progs[0].nOpType1 == OP_ST || prog1.Progs[0].nOpType1 == OP_ST_ ){
            prog1.Prefix += 1;
            s1.Format(_T(" <+1  %s"),prog1.ToText());    DbgLog(s1);
        }
        else {
            prog1.Prefix += 0;
            s1.Format(_T(" < +0 %s"),prog1.ToText());    DbgLog(s1);
        }
        prog2 = prog1;                // 取得第一个实节点的程序
        ptheArc1 = ptheArc1->tlink;                //下一个弧
        while (ptheArc1)
@@ -2947,6 +3019,17 @@
            node* pThisNode2 = ptheArc1->headvex;
            stProgSection prog1 = pThisNode2->prog1;
            if (prog1.Progs[0].nOpType1 == OP_AN) { prog1.Progs[0].nOpType1 = OP_ST; }
            else if (prog1.Progs[0].nOpType1 == OP_AN_) { prog1.Progs[0].nOpType1 = OP_ST_; }
            else if (prog1.Progs[0].nOpType1 == OP_ST || prog1.Progs[0].nOpType1 == OP_ST_) {
                prog1.Prefix += 1;
                s1.Format(_T(" < 2 +1 %s"), prog1.ToText());    DbgLog(s1);
                if (theNode1.nType == -1) { prog1.reduce(); }
            }
            else {
                prog1.Prefix += 0;
                s1.Format(_T(" < 2 +0 %s"),prog1.ToText());    DbgLog(s1);
            }
            if (prog1.Progs.size() > 1) {
                prog1.Append(CMTerm1Doc::stProg(OP_ORS));
            }
@@ -2968,6 +3051,7 @@
        }
        if (theNode1.nType == -1 && theNode2.nType == -1) { prog2.Append(CMTerm1Doc::stProg(OP_ANS)); }
        pThisNode1->prog1 = prog2;                //将所有程序汇总到第一个实节点
    //    pThisNode1->prog1.reduce();
    //    s1 = prog2.ToText(GetDocument());
    //    DbgLog(_T("------ ") + s1);
    }
@@ -2999,9 +3083,19 @@
        node* pThisNode1 = ptheArc1->tailvex;    // 第一个实节点
        stProgSection prog1 = pThisNode1->prog1;
        if (prog1.Progs[0].nOpType1 == OP_AN) { prog1.Progs[0].nOpType1 = OP_ST; }
        else if (prog1.Progs[0].nOpType1 == OP_AN_) { prog1.Progs[0].nOpType1 = OP_ST_; }
        else if (prog1.Progs[0].nOpType1 == OP_ST || prog1.Progs[0].nOpType1 == OP_ST_) {
            prog1.Prefix += 1;
            s1.Format(_T(" > +1 %s"),prog1.ToText());    DbgLog(s1);
        }
        else {
            prog1.Prefix += 0;
            s1.Format(_T(" > +0 %s"), prog1.ToText());    DbgLog(s1);
        }
        prog2 = prog1;                // 取得第一个实节点的程序
        ptheArc1 = ptheArc1->hlink;
        bool NeedANS = 0;
        while (ptheArc1)
        {
            //取得相连的虚节点地址
@@ -3009,13 +3103,24 @@
            stProgSection prog1 = pThisNode2->prog1;
            if (prog1.Progs[0].nOpType1 == OP_AN) { prog1.Progs[0].nOpType1 = OP_ST; }
            else if (prog1.Progs[0].nOpType1 == OP_AN_) { prog1.Progs[0].nOpType1 = OP_ST_; }
            else if (prog1.Progs[0].nOpType1 == OP_ST || prog1.Progs[0].nOpType1 == OP_ST_) {
                prog1.Prefix += 1;
                s1.Format(_T(" > 2 +1 %s"),prog1.ToText());    DbgLog(s1);
            }
            else {
                prog1.Prefix += 0;
                s1.Format(_T(" >2 +0 %s"),prog1.ToText());    DbgLog(s1);
            }
            if (prog1.Progs.size() > 1) {
                prog1.Append(CMTerm1Doc::stProg(OP_ORS));
                NeedANS = 1;
            }
            else {
                if (pThisNode2->nType == typeNC) prog1.Progs[0].nOpType1 = OP_OR_;
                else if (pThisNode2->nType == typeNO) prog1.Progs[0].nOpType1 = OP_OR;
                else prog1.Progs[0].nOpType1 = OP_OR;
                NeedANS = 1;
            }
            prog2 += prog1;
@@ -3026,8 +3131,9 @@
            pThisNode2->bEnable = 0;                //删除实节点
            ptheArc1 = pTheNextArc;
        }
        if (theNode1.nType == -1 && theNode2.nType == -1) { prog2.Append(CMTerm1Doc::stProg(OP_ANS)); }
        if (theNode1.nType == -1 && theNode2.nType == -1 && NeedANS) { prog2.Append(CMTerm1Doc::stProg(OP_ANS)); }
        pThisNode1->prog1 = prog2;                //将所有程序汇总到第一个实节点
    //    pThisNode1->prog1.reduce();
    //    s1 = prog2.ToText(GetDocument());
    //    DbgLog(_T("------ ") + s1);
    }
@@ -3234,11 +3340,17 @@
            s1.Format(_T("- %d type %d op %s coil %s  in %d   out %d"), thisNode->nId, thisNode->nType, thisNode->Op, thisNode->CoilName, thisNode->indegree, thisNode->outdegree);
            DbgLog(s1);
            s1 = thisNode->prog1.ToText();
            DbgLog(_T("------ ") + s1);
            DbgLog(_T("------ \r\n") + s1);
            arc* thisArc = thisNode->firstOut;
            if (thisNode->outdegree > 0) { allOutputMerged = 0; }
            if (thisNode->nType != typeOUT && thisNode->nType != typeSET && thisNode->nType != typeRESET) { allOutputSimple = 0; }
            if (thisNode->nType == typeOUT || thisNode->nType == typeSET || thisNode->nType == typeRESET) {
                thisNode->prog1.bModifyVal = 0;
            }
            else {
                allOutputSimple = 0;
                thisNode->prog1.bModifyVal = 1;
            }
            while (thisArc) {
                thisNode = thisArc->headvex;
                thisNode->InProcCount++;
@@ -3290,16 +3402,21 @@
                node* thisNode = thisArc->headvex;
                stProgSection prog2;
                prog2.Append(CMTerm1Doc::stProg(OP_PSHS));
                int bLastModify = 1;
                prog2 += thisNode->prog1;
                if (thisNode->prog1.bModifyVal == 0) { bLastModify = 0; s1.Format(_T(" ModifyVal = 0, %s"), thisNode->prog1.ToText()); }
                thisArc = thisArc->tlink;
                for (int i = 1; i < nOutput  && thisArc != 0; i++) {
                    node* thatNode = thisArc->headvex;
                    if (i == nOutput - 1) { // 最后一个
                        prog2.Append(CMTerm1Doc::stProg(OP_POPS));
                    }
                    else {
                        prog2.Append(CMTerm1Doc::stProg(OP_RDS));
                        if (bLastModify) { prog2.Append(CMTerm1Doc::stProg(OP_RDS)); }
                    }
                    if (thisNode->prog1.bModifyVal == 0) { bLastModify = 0;s1.Format(_T(" ModifyVal = 0, %s"), thisNode->prog1.ToText()); }
                    else { bLastModify = 1; }
                    prog2 += thatNode->prog1;
                    arc* tempArc = thisArc->tlink;
                    RemoveArc(thisArc->nId);
@@ -3450,6 +3567,9 @@
                    case typeLine1:
                        break;
                    case typeEND:
                        PrevNode = AddNode(nType, k, j, theCell.sCoilName, PrevNode);
                        break;
                    case typeNO:
                        PrevNode = AddNode(nType, k, j, theCell.sCoilName, PrevNode);
                        break;
@@ -3525,8 +3645,8 @@
        }
        //输出已经生成的 AOV 图 顶点信息
        for (int j = 1; j < nNodeCount; j++) {
            s1.Format(_T("%d    %d %s %s    in %d  out %d"), j, nodes[j].nType,nodes[j].Op, nodes[j].CoilName,nodes[j].indegree,nodes[j].outdegree);
//            DbgLog(s1);
            s1.Format(_T("%d    %d %s %s  in %d  out %d  %s "), j, nodes[j].nType,nodes[j].Op, nodes[j].CoilName,nodes[j].indegree,nodes[j].outdegree, nodes[j].prog1.ToText());
            DbgLog(s1);
        }
        //输出AOV图的 弧 数据 
        for (int j = 1; j < nArcCount; j++) {
@@ -3543,6 +3663,8 @@
            // 处理 AOV 图
            // 从 母线 开始 
            //串联归并 // 归并原则, 普通节点,非虚节点, 两个虚节点之间 多个连续的,归并, 非输出。
            s1.Format(_T("合并串联的节点 %d "), n);
            DbgLog(s1);
            MergeVPSubSerialNodes(1);
            // 处理虚节点
            // 虚节点的多输入处理, 单 OR 或者 多 ORS。
@@ -3553,6 +3675,8 @@
            // 对于后面还有改变的, PSHS, RDS, POPS
            // 另外,可以后期简化, ST 后紧跟 ORS 的, 简化为 OR。
            // PSHS RDS POPS 后跟不改变的。 简化
            s1.Format(_T("处理虚节点的输出 %d "), n);
            DbgLog(s1);
            ScanAOV1(1);
            if (nodes[2].outdegree == 0) break;
        }
MTerm1/MTerm1View.h
@@ -62,6 +62,7 @@
        typeFN4 = 70,        //3个参数的函数
        typeCoil=99,
        typeEND = 255,
    };
    struct stCell
@@ -95,6 +96,9 @@
    stCell Cells[2000][16] = { 0 };
    struct stProgSection
    {
        int Prefix = 0;
        int Suffix = 0;
        int bModifyVal = 1;
        std::vector <CMTerm1Doc::stProg> Progs;
        int Append(CMTerm1Doc::stProg prog) {
            Progs.push_back(prog);
@@ -109,6 +113,7 @@
        };
        int operator+=(const struct stProgSection progsec) {
            Append(progsec);
            bModifyVal = bModifyVal | progsec.bModifyVal;
            return 0;
        };
@@ -120,6 +125,7 @@
            CString s1;
            CStringA s2A;
            int n = (int)Progs.size();
            s2A.Format(" +%d ", Prefix);
            for (int k = 0; k < n; k++) {
                CMTerm1Doc::stProg& prog0 = Progs.at(k);
                s2A = prog0.ToText();
@@ -127,6 +133,32 @@
            }
            return s1;
        }
        int reduce()
        {
            if (Prefix > 0) {
                int level = 0;
                int j = Progs.size();
                for (int i = 0; i < j; i++) {
                    int nOp = Progs[i].nOpType1;
                    if (nOp == OP_ST || nOp == OP_ST_) {
                        level += 1;;
                    }
                    else if (nOp == OP_ORS) {
                        level -= 1;
                    }
                    if (nOp == OP_ANS) {
                        level -= 1;
                        if (level == 0) {
                            Progs.erase(Progs.begin() + i);
                            Prefix -= 1;
                            break;
                        }
                    }
                }
            }
            return Prefix;
        }
    };
    std::pair<int, int> popsPoint[100];
MTerm1/MainFrm.cpp
@@ -14,6 +14,8 @@
#include "MTerm1TestView.h"
#include "MTerm1ProgTxt.h"
#include <windows.h>
#include "MyChildFrm.h"
#include "MyChildFrmConfig.h"
#ifdef _DEBUG
#define new DEBUG_NEW
@@ -42,9 +44,12 @@
//    ON_COMMAND(ID_MENU_VIEW_BLD, &CMainFrame::OnMenuViewBld)
//    ON_COMMAND(ID_MENU_VIEW_BNL, &CMainFrame::OnMenuViewBnl)
ON_COMMAND(ID_MENU_SHOW_LOG, &CMainFrame::OnMenuShowLog)
ON_COMMAND(ID_MENU_SHOW_DEV, &CMainFrame::OnMenuShowDev)
ON_COMMAND(ID_MENU_SHOWNAV, &CMainFrame::OnMenuShownav)
    ON_COMMAND(ID_MENU_SHOW_LOG, &CMainFrame::OnMenuShowLog)
    ON_COMMAND(ID_MENU_SHOW_DEV, &CMainFrame::OnMenuShowDev)
    ON_COMMAND(ID_MENU_SHOWNAV, &CMainFrame::OnMenuShownav)
    ON_COMMAND(ID_COMMTEST, &CMainFrame::OnCommtest)
    ON_COMMAND(ID_DEVICE_CONFIG, &CMainFrame::OnDeviceConfig)
END_MESSAGE_MAP()
static UINT indicators[] =
@@ -83,7 +88,7 @@
//    m_dlgMyLog.ShowWindow(SW_SHOW);
//    BOOL bNameValid;
    CMainFrame::EnableLoadDockState(FALSE);
    // 创建类视图
    CString strNavView;
//    bNameValid = strNavView.LoadString(IDS_CLASS_VIEW);
@@ -237,9 +242,16 @@
//    DockControlBar(&m_wndToolBar);
//    EnableDocking(CBRS_ALIGN_ANY);
    m_wndNavView.SetMinSize(CSize(300, 300));
    DockPane(&m_wndNavView);
    CDockablePane* pTabbedBar = nullptr;
//    m_wndMyPaneLog.AttachToTabWnd(&m_wndNavView, DM_SHOW, TRUE,&pTabbedBar);
//    m_wndNavView.AttachToTabWnd(&m_wndMyPaneLog, DM_SHOW, TRUE, &pTabbedBar);
    m_wndMyPaneLog.SetMinSize(CSize(300, 300));
    m_wndMyPaneLog.DockToWindow(&m_wndNavView, CBRS_BOTTOM);
//    DockPane(&m_wndMyPaneLog);
//    CDockablePane* pTabbedBar = nullptr;
//    m_wndNavView.AttachToTabWnd(&m_wndFileView, DM_SHOW, TRUE, &pTabbedBar);
@@ -262,9 +274,9 @@
//    DockPane(&m_wndDlgBar_Func_Key);
//    DockControlBar(&m_wndDlgBar_Func_Key);
    DockPane(&m_wndMyPaneInputShow);
    DockPane(&m_wndNavView);
    DockPane(&m_wndMyPaneLog);
    m_wndNavView.SetMinSize(CSize(0, 0));
    m_wndMyPaneLog.SetMinSize(CSize(0, 0));
//    DockPane(pTabbedBar);
//    m_wndMyPaneInputShow.m_pMyFormInputShow->SetBtnDisplayESC(1);
//*/
@@ -477,3 +489,86 @@
    // TODO: 在此添加命令处理程序代码
    m_wndNavView.ShowWindow(SW_SHOW);
}
BOOL CMainFrame::PreTranslateMessage(MSG* pMsg)
{
    // TODO: 在此添加专用代码和/或调用基类
    UINT  nCode = pMsg->wParam;
    if (pMsg->message == WM_KEYDOWN)
    {
        if ((nCode == _T('A') || nCode == _T('C') || nCode == _T('X') || nCode == _T('V')|| nCode == _T('Z') || nCode == _T('Y'))
            && (::GetKeyState(VK_CONTROL) & 0x8000))
        {
            ::TranslateMessage(pMsg);
            ::DispatchMessage(pMsg);
            return TRUE;
        }
    }
    return CMDIFrameWndEx::PreTranslateMessage(pMsg);
}
void CMainFrame::OnCommtest()
{
    // TODO: 在此添加命令处理程序代码
//    this->LockWindowUpdate();
    if (m_pCommDevView == nullptr) {
/*
        CRect rectWndClient;
        GetClientRect(&rectWndClient);
        rectWndClient.left = 200;
        rectWndClient.right = 500;
        rectWndClient.top = 200;
        rectWndClient.bottom = 500;
        CFrameWnd* pFrameWnd = new CFrameWnd();
        pFrameWnd->Create(_T("333"), _T("444"), WS_VISIBLE, rectWndClient, this);
        CRuntimeClass* pViewRuntimeClass = RUNTIME_CLASS(CMTerm1CommDevView);
        m_pCommDevView = (CMTerm1CommDevView*)pViewRuntimeClass->CreateObject();
        m_pCommDevView->Create(_T("1111"), _T("2222"), WS_VISIBLE | WS_CHILD | WS_MAXIMIZE, rectWndClient, pFrameWnd, 123, NULL);
        m_pCommDevView->OnInitialUpdate();
// */
        CMDIChildWnd * pChildWnd = this->CreateNewChild(RUNTIME_CLASS(CMyChildFrame), IDR_MTerm1TYPE);
/*
        CCreateContext cx;
        cx.m_pCurrentFrame = this;
        cx.m_pNewViewClass = RUNTIME_CLASS(CMTerm1CommDevView);
        cx.m_pCurrentDoc = NULL;
        cx.m_pLastView = NULL;
        cx.m_pNewDocTemplate = NULL;
        m_pCommDevView = DYNAMIC_DOWNCAST(CMTerm1CommDevView, pChildWnd->CreateView(&cx, 23456));
        if (!m_pCommDevView) {
        }
        else {
            RecalcLayout();
            m_pCommDevView->ShowWindow(SW_SHOW);
            m_pCommDevView->UpdateWindow();
        }
*/
        //    pChildWnd->LoadFrame(IDD_MTerm1CommDevView2, WS_VISIBLE | WS_CHILD, this,&cx);
//        pChildWnd->CreateView(&cx, 23456);
    }
//    this->UnlockWindowUpdate();
}
void CMainFrame::OnDeviceConfig()
{
    // TODO: 在此添加命令处理程序代码
//    this->LockWindowUpdate();
    if (m_pConfigToolView == nullptr) {
        CMDIChildWnd* pChildWnd = this->CreateNewChild(RUNTIME_CLASS(CMyChildFrameConfig), IDR_MTerm1TYPE);
    }
    //    this->UnlockWindowUpdate();
}
MTerm1/MainFrm.h
@@ -14,7 +14,8 @@
#include "MyDialogLog.h"
#include "MyDlgBarInputShow.h"
#include "CMyPaneInputShow.h"
#include "MTerm1CommDevView.h"
#include "ConfigToolView.h"
class CMainFrame : public CMDIFrameWndEx
{
@@ -63,6 +64,8 @@
    CMyPaneInputShow m_wndMyPaneInputShow;
    CMTerm1CommDevView* m_pCommDevView = nullptr;
    CConfigToolView* m_pConfigToolView = nullptr;
// 生成的消息映射函数
protected:
@@ -101,6 +104,11 @@
    afx_msg void OnMenuShowDev();
    afx_msg void OnMenuShownav();
    virtual BOOL PreTranslateMessage(MSG* pMsg);
    afx_msg void OnCommtest();
    afx_msg void OnDeviceConfig();
};
MTerm1/MyChildFrm.cpp
New file
@@ -0,0 +1,164 @@

// ChildFrm.cpp: CMyChildFrame 类的实现
//
#include "pch.h"
#include "framework.h"
#include "MTerm1.h"
#include "MyChildFrm.h"
#include "MTerm1CommDevView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CMyChildFrame
IMPLEMENT_DYNCREATE(CMyChildFrame, CMDIChildWndEx)
BEGIN_MESSAGE_MAP(CMyChildFrame, CMDIChildWndEx)
    ON_WM_CREATE()
END_MESSAGE_MAP()
static UINT indicators[] =
{
    ID_INDICATOR_MACHINE_TYPE,            // 状态行指示器
    ID_INDICATOR_PROGRAM_POS,
    ID_INDICATOR_CONNECTIVITY,
    ID_INDICATOR_RUN_STATUS,
    ID_INDICATOR_MONITOR_STATUS,
    ID_INDICATOR_TARGET_ADDRESS,
    ID_INDICATOR_INFO_DISPLAY,
};
// CMyChildFrame 构造/析构
CMyChildFrame::CMyChildFrame() noexcept
{
    // TODO: 在此添加成员初始化代码
}
CMyChildFrame::~CMyChildFrame()
{
}
BOOL CMyChildFrame::PreCreateWindow(CREATESTRUCT& cs)
{
    // TODO: 在此处通过修改 CREATESTRUCT cs 来修改窗口类或样式
    if( !CMDIChildWndEx::PreCreateWindow(cs) )
        return FALSE;
    //修改窗口的类型为最大化样式
//    cs.style = cs.style | WS_MAXIMIZE | WS_VISIBLE;
    return TRUE;
}
// CMyChildFrame 诊断
#ifdef _DEBUG
void CMyChildFrame::AssertValid() const
{
    CMDIChildWndEx::AssertValid();
}
void CMyChildFrame::Dump(CDumpContext& dc) const
{
    CMDIChildWndEx::Dump(dc);
}
#endif //_DEBUG
// CMyChildFrame 消息处理程序
int CMyChildFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    if (CMDIChildWndEx::OnCreate(lpCreateStruct) == -1)
        return -1;
    // TODO:  在此添加您专用的创建代码
    this->ModifyStyle(WS_SIZEBOX,0);
///*
    if (!m_wndStatusBar.Create(this , (WS_CHILD | WS_VISIBLE | CBRS_TOP), IDW_CHILD_STATUS_BAR))
    {
        TRACE0("未能创建状态栏\n");
        return -1;      // 未能创建
    }
    m_wndStatusBar.SetIndicators(indicators, sizeof(indicators) / sizeof(UINT));
//*/
    this->ModifyStyle(0,WS_SIZEBOX);
/*
    if (!m_wndStatusBar.Create(this) || !m_wndStatusBar.SetIndicators(indicators, sizeof(indicators) / sizeof(UINT)))
    {
        TRACE0("未能创建状态栏\n");
        return -1;      // 未能创建
    }
*/
    m_wndStatusBar.SetPaneInfo(0, 0, 0, 100);
    m_wndStatusBar.SetPaneInfo(1, 0, 0, 100);
    m_wndStatusBar.SetPaneInfo(2, 0, 0, 100);
//
//    m_wndStatusBar.SetPaneText(0, _T("机型参数"), false);
//    m_wndStatusBar.SetPaneText(1, _T("程序位置/总数"), false);
    m_wndStatusBar.SetPaneInfo(6, 0, 0, 9999);
//    m_wndStatusBar.MoveWindow(0, 0, 1800, 28);
//    m_wndStatusBar.EnableDocking(CBRS_ALIGN_TOP);
//    EnableDocking(CBRS_ALIGN_ANY);
//    AdjustClientArea();
//    DockPane(&m_wndStatusBar);
/*
    if (!m_wndToolBar_InfoShow.CreateEx(this, TBSTYLE_FLAT,
        WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_GRIPPER | CBRS_FLYBY | CBRS_SIZE_DYNAMIC,
        CRect(1, 1, 1, 1), IDR_TOOLBAR_INFO_SHOW) ||
        !m_wndToolBar_InfoShow.LoadToolBar(IDR_TOOLBAR_INFO_SHOW))
    {
        TRACE0("未能创建数字工具栏\n");
        return -1;      // 未能创建
    }
    CRect rect1;
    int index = m_wndToolBar_InfoShow.CommandToIndex(ID_BUTTON_INPUT_SHOW);
    index = 0;
    UINT nID, nStyle;
    int iImage;
    m_wndToolBar_InfoShow.GetButtonInfo(0, nID, nStyle, iImage);
    m_wndToolBar_InfoShow.SetButtonInfo(index, nID, TBBS_SEPARATOR, 100);
    m_wndToolBar_InfoShow.GetItemRect(0, &rect1);
    rect1.left = 1;
    rect1.top = 2;
    rect1.right = rect1.left + 100;
    rect1.bottom = rect1.top + 20;
    if (!m_StaticShowMachine.Create(_T("Test1"), WS_CHILD | WS_VISIBLE | WS_EX_CLIENTEDGE, rect1, \
        &m_wndToolBar_InfoShow, nID))
    {
        TRACE(_T("Failed to create CStaticEx\n"));
        return FALSE;
    }
    //*/
//    m_InputShowStatic.SetBkColor(RGB(255, 255, 255));
//    m_InputShowStatic.SetTextColor(RGB(255, 128, 128));
//    m_InputShowStatic.SetTextSize(20);
//m_InputShowEdit.SetReadOnly(true);
//    m_wndToolBar_InfoShow.EnableDocking(CBRS_ALIGN_ANY);
//    this->RecalcLayout();
//    DockPane(&m_wndTBar_InputShow);
    return 0;
}
BOOL CMyChildFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
    // TODO: 在此添加专用代码和/或调用基类
    CCreateContext newContext;
    newContext.m_pNewViewClass = RUNTIME_CLASS(CMTerm1CommDevView); // CMyView是你的CView派生类
    newContext.m_pCurrentDoc = NULL;
    newContext.m_pNewDocTemplate = NULL;
    newContext.m_pLastView = NULL;
    newContext.m_pCurrentFrame = this;
    return CMDIChildWndEx::OnCreateClient(lpcs, &newContext);
}
MTerm1/MyChildFrm.h
New file
@@ -0,0 +1,50 @@

// ChildFrm.h: CChildFrame 类的接口
//
#pragma once
#include "../MyLib/StaticEx.h"
class CMyChildFrame : public CMDIChildWndEx
{
    DECLARE_DYNCREATE(CMyChildFrame)
public:
    CMyChildFrame() noexcept;
// 特性
protected:
    CSplitterWndEx m_wndSplitter;
    CMFCStatusBar  m_wndStatusBar;
    CMFCToolBar m_wndToolBar_InfoShow;
    CStaticEx    m_StaticShowMachine;
    CStaticEx    m_StaticShowProgPos;
    CStaticEx    m_StaticShowOnline;
    CStaticEx    m_StaticShowPLC;
    CStaticEx    m_StaticShowMonitor;
    CStaticEx    m_StaticShowAddress;
public:
    CMFCStatusBar *GetStatusBar()
    {
        return &m_wndStatusBar;
    }
// 操作
public:
// 重写
    virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
// 实现
public:
    virtual ~CMyChildFrame();
#ifdef _DEBUG
    virtual void AssertValid() const;
    virtual void Dump(CDumpContext& dc) const;
#endif
// 生成的消息映射函数
protected:
    DECLARE_MESSAGE_MAP()
public:
    afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
    virtual BOOL OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext);
};
MTerm1/MyChildFrmConfig.cpp
New file
@@ -0,0 +1,164 @@

// ChildFrm.cpp: CMyChildFrameConfig 类的实现
//
#include "pch.h"
#include "framework.h"
#include "MTerm1.h"
#include "MyChildFrmConfig.h"
#include "ConfigToolView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CMyChildFrameConfig
IMPLEMENT_DYNCREATE(CMyChildFrameConfig, CMDIChildWndEx)
BEGIN_MESSAGE_MAP(CMyChildFrameConfig, CMDIChildWndEx)
    ON_WM_CREATE()
END_MESSAGE_MAP()
static UINT indicators[] =
{
    ID_INDICATOR_MACHINE_TYPE,            // 状态行指示器
    ID_INDICATOR_PROGRAM_POS,
    ID_INDICATOR_CONNECTIVITY,
    ID_INDICATOR_RUN_STATUS,
    ID_INDICATOR_MONITOR_STATUS,
    ID_INDICATOR_TARGET_ADDRESS,
    ID_INDICATOR_INFO_DISPLAY,
};
// CMyChildFrameConfig 构造/析构
CMyChildFrameConfig::CMyChildFrameConfig() noexcept
{
    // TODO: 在此添加成员初始化代码
}
CMyChildFrameConfig::~CMyChildFrameConfig()
{
}
BOOL CMyChildFrameConfig::PreCreateWindow(CREATESTRUCT& cs)
{
    // TODO: 在此处通过修改 CREATESTRUCT cs 来修改窗口类或样式
    if( !CMDIChildWndEx::PreCreateWindow(cs) )
        return FALSE;
    //修改窗口的类型为最大化样式
//    cs.style = cs.style | WS_MAXIMIZE | WS_VISIBLE;
    return TRUE;
}
// CMyChildFrameConfig 诊断
#ifdef _DEBUG
void CMyChildFrame::AssertValid() const
{
    CMDIChildWndEx::AssertValid();
}
void CMyChildFrame::Dump(CDumpContext& dc) const
{
    CMDIChildWndEx::Dump(dc);
}
#endif //_DEBUG
// CMyChildFrameConfig 消息处理程序
int CMyChildFrameConfig::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    if (CMDIChildWndEx::OnCreate(lpCreateStruct) == -1)
        return -1;
    // TODO:  在此添加您专用的创建代码
    this->ModifyStyle(WS_SIZEBOX,0);
///*
    if (!m_wndStatusBar.Create(this , (WS_CHILD | WS_VISIBLE | CBRS_TOP), IDW_CHILD_STATUS_BAR))
    {
        TRACE0("未能创建状态栏\n");
        return -1;      // 未能创建
    }
    m_wndStatusBar.SetIndicators(indicators, sizeof(indicators) / sizeof(UINT));
//*/
    this->ModifyStyle(0,WS_SIZEBOX);
/*
    if (!m_wndStatusBar.Create(this) || !m_wndStatusBar.SetIndicators(indicators, sizeof(indicators) / sizeof(UINT)))
    {
        TRACE0("未能创建状态栏\n");
        return -1;      // 未能创建
    }
*/
    m_wndStatusBar.SetPaneInfo(0, 0, 0, 100);
    m_wndStatusBar.SetPaneInfo(1, 0, 0, 100);
    m_wndStatusBar.SetPaneInfo(2, 0, 0, 100);
//
//    m_wndStatusBar.SetPaneText(0, _T("机型参数"), false);
//    m_wndStatusBar.SetPaneText(1, _T("程序位置/总数"), false);
    m_wndStatusBar.SetPaneInfo(6, 0, 0, 9999);
//    m_wndStatusBar.MoveWindow(0, 0, 1800, 28);
//    m_wndStatusBar.EnableDocking(CBRS_ALIGN_TOP);
//    EnableDocking(CBRS_ALIGN_ANY);
//    AdjustClientArea();
//    DockPane(&m_wndStatusBar);
/*
    if (!m_wndToolBar_InfoShow.CreateEx(this, TBSTYLE_FLAT,
        WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_GRIPPER | CBRS_FLYBY | CBRS_SIZE_DYNAMIC,
        CRect(1, 1, 1, 1), IDR_TOOLBAR_INFO_SHOW) ||
        !m_wndToolBar_InfoShow.LoadToolBar(IDR_TOOLBAR_INFO_SHOW))
    {
        TRACE0("未能创建数字工具栏\n");
        return -1;      // 未能创建
    }
    CRect rect1;
    int index = m_wndToolBar_InfoShow.CommandToIndex(ID_BUTTON_INPUT_SHOW);
    index = 0;
    UINT nID, nStyle;
    int iImage;
    m_wndToolBar_InfoShow.GetButtonInfo(0, nID, nStyle, iImage);
    m_wndToolBar_InfoShow.SetButtonInfo(index, nID, TBBS_SEPARATOR, 100);
    m_wndToolBar_InfoShow.GetItemRect(0, &rect1);
    rect1.left = 1;
    rect1.top = 2;
    rect1.right = rect1.left + 100;
    rect1.bottom = rect1.top + 20;
    if (!m_StaticShowMachine.Create(_T("Test1"), WS_CHILD | WS_VISIBLE | WS_EX_CLIENTEDGE, rect1, \
        &m_wndToolBar_InfoShow, nID))
    {
        TRACE(_T("Failed to create CStaticEx\n"));
        return FALSE;
    }
    //*/
//    m_InputShowStatic.SetBkColor(RGB(255, 255, 255));
//    m_InputShowStatic.SetTextColor(RGB(255, 128, 128));
//    m_InputShowStatic.SetTextSize(20);
//m_InputShowEdit.SetReadOnly(true);
//    m_wndToolBar_InfoShow.EnableDocking(CBRS_ALIGN_ANY);
//    this->RecalcLayout();
//    DockPane(&m_wndTBar_InputShow);
    return 0;
}
BOOL CMyChildFrameConfig::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
    // TODO: 在此添加专用代码和/或调用基类
    CCreateContext newContext;
    newContext.m_pNewViewClass = RUNTIME_CLASS(CConfigToolView); // CMyView是你的CView派生类
    newContext.m_pCurrentDoc = NULL;
    newContext.m_pNewDocTemplate = NULL;
    newContext.m_pLastView = NULL;
    newContext.m_pCurrentFrame = this;
    return CMDIChildWndEx::OnCreateClient(lpcs, &newContext);
}
MTerm1/MyChildFrmConfig.h
New file
@@ -0,0 +1,50 @@

// ChildFrm.h: CChildFrame 类的接口
//
#pragma once
#include "../MyLib/StaticEx.h"
class CMyChildFrameConfig : public CMDIChildWndEx
{
    DECLARE_DYNCREATE(CMyChildFrameConfig)
public:
    CMyChildFrameConfig() noexcept;
// 特性
protected:
    CSplitterWndEx m_wndSplitter;
    CMFCStatusBar  m_wndStatusBar;
    CMFCToolBar m_wndToolBar_InfoShow;
    CStaticEx    m_StaticShowMachine;
    CStaticEx    m_StaticShowProgPos;
    CStaticEx    m_StaticShowOnline;
    CStaticEx    m_StaticShowPLC;
    CStaticEx    m_StaticShowMonitor;
    CStaticEx    m_StaticShowAddress;
public:
    CMFCStatusBar *GetStatusBar()
    {
        return &m_wndStatusBar;
    }
// 操作
public:
// 重写
    virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
// 实现
public:
    virtual ~CMyChildFrameConfig();
#ifdef _DEBUG
    virtual void AssertValid() const;
    virtual void Dump(CDumpContext& dc) const;
#endif
// 生成的消息映射函数
protected:
    DECLARE_MESSAGE_MAP()
public:
    afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
    virtual BOOL OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext);
};
MTerm1/MyFormLog.cpp
@@ -87,17 +87,21 @@
{
    CFormView::OnSize(nType, cx, cy);
    // TODO: 在此处添加消息处理程序代码
    CString s1;
    CWnd * pwnd;
/*
///*
    pwnd=GetDlgItem(IDC_EDIT_LOG);
    if (pwnd!=NULL)
    {
//        RECT    rect1;
        pwnd->SetWindowPos(NULL,0,0,cx,cy-20,NULL);
    }
//*/
//        s1.Format(_T("OnSize %d  %d %d \r\n"), nType, cx, cy);
        // ((CEdit*)GetDlgItem(IDC_EDIT_LOG))->ReplaceSel(s1);
///*
    }
// */
/*
    pwnd = GetDlgItem(IDC_RICHEDIT2_LOG);
    if (pwnd != NULL)
    {
@@ -132,7 +136,9 @@
    CString BuildStr = _T("20210728");
    // TODO: 在此添加专用代码和/或调用基类
    myLogger1.SetLogPathName(_T("D:\\Logs\\MTerm1"), _T("MTerm1"));
    myLogger1.AttachWnd(m_richedit_log.m_hWnd);
    myLogger1.AttachWnd(m_edit_log.m_hWnd);
//    myLogger1.AttachWnd(m_richedit_log.m_hWnd);
    myLogger1.bShowLog[0] = 1;
    myLogger1.bShowThreadId = 0;
    myLogger1.bShowChannel = 0;
MTerm1/MyPaneLog.cpp
@@ -81,7 +81,8 @@
    { 
        CRect rect; 
        GetClientRect(rect); 
        m_pMyFormLog->SetWindowPos(NULL, rect.left, rect.top, rect.Width(), rect.Height(), SWP_NOACTIVATE | SWP_NOZORDER);
//        m_pMyFormLog->SetWindowPos(NULL, rect.left, rect.top, rect.Width(), rect.Height(), SWP_NOACTIVATE | SWP_NOZORDER);
        m_pMyFormLog->SetWindowPos(NULL, rect.left, rect.top, cx, cy, SWP_NOACTIVATE | SWP_NOZORDER);
    }
//*/
/*
MTerm1/NavView.cpp
@@ -6,6 +6,7 @@
#include "NavView.h"
#include "MTerm1.h"
#include "../MyLib/Functions.hpp"
#define IDC_NAVTREE1 1046
class CClassViewMenuButton : public CMFCToolBarMenuButton
@@ -57,6 +58,9 @@
//    ON_COMMAND(ID_CLASS_DEFINITION, OnClassDefinition)
//    ON_COMMAND(ID_CLASS_PROPERTIES, OnClassProperties)
    ON_COMMAND(ID_NEW_FOLDER, OnNewFolder)
    ON_COMMAND(ID_NAV_SETCOMM, OnSetComm)
    ON_COMMAND(ID_NAV_CONNECT, OnConnect)
    ON_COMMAND(ID_NAV_DISCONNECT, OnDisConnect)
    ON_WM_PAINT()
    ON_WM_SETFOCUS()
    ON_COMMAND_RANGE(ID_SORTING_GROUPBYTYPE, ID_SORTING_SORTBYACCESS, OnSort)
@@ -65,6 +69,23 @@
    ON_NOTIFY(NM_CLICK, IDC_NAVTREE1, OnNMClkNavTree1)
    ON_WM_TIMER()
    ON_COMMAND(ID_MENU_NAV_SET_CONN, &CNavView::OnMenuNavSetConn)
    ON_COMMAND(ID_MENU_NAV_CONNECT, &CNavView::OnMenuNavConnect)
    ON_COMMAND(ID_MENU_NAV_DISCONNECT, &CNavView::OnMenuNavDisconnect)
    ON_COMMAND(ID_MENU_NV_UPDATE_FIRMWARE, &CNavView::OnMenuNvUpdateFirmware)
    ON_COMMAND(ID_MENU_NV_DEVICE_READ_INFO, &CNavView::OnMenuNvDeviceReadInfo)
    ON_COMMAND(ID_LED_BLINK, &CNavView::OnLedBlink)
    ON_COMMAND(ID_RESET_DEVICE, &CNavView::OnResetDevice)
    ON_COMMAND(ID_REMOTE_REFRESH_DATA, &CNavView::OnRemoteRefreshData)
    ON_COMMAND(ID_REMOTE_BLINK, &CNavView::OnRemoteBlinkLED)
    ON_COMMAND(ID_REMOTE_DEVICE_RESET, &CNavView::OnRemoteDeviceReset)
    ON_COMMAND(ID_REMOTE_UPDATE_FIRMWARE, &CNavView::OnRemoteUpdateFirmware)
    ON_COMMAND(ID_REMOTE_BLINK_LED_ALL, &CNavView::OnRemoteBlinkLedAll)
    ON_COMMAND(ID_PORT_RESET, &CNavView::OnPortReset)
    ON_COMMAND(ID_PORT_RESET_ALL_CHILD, &CNavView::OnPortResetAllChild)
//    ON_COMMAND(ID_COMMTEST, &CNavView::OnCommtest)
//    ON_COMMAND(ID_DEVICE_CONFIG, &CNavView::OnDeviceConfig)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
@@ -88,8 +109,8 @@
    }
    m_NavViewTree.SetExtendedStyle(TVS_EX_DOUBLEBUFFER, TVS_EX_DOUBLEBUFFER);
    // 加载图像: 
    m_wndToolBar.Create(this, AFX_DEFAULT_TOOLBAR_STYLE, IDR_SORT);
    m_wndToolBar.LoadToolBar(IDR_SORT, 0, 0, TRUE /* 已锁定*/);
    m_wndToolBar.Create(this, AFX_DEFAULT_TOOLBAR_STYLE, IDR_NAV_TOOLBAR);
    m_wndToolBar.LoadToolBar(IDR_NAV_TOOLBAR, 0, 0, TRUE /* 已锁定*/);
    OnChangeVisualStyle();
@@ -102,7 +123,7 @@
    m_wndToolBar.SetRouteCommandsViaFrame(FALSE);
    CMenu menuSort;
    menuSort.LoadMenu(IDR_POPUP_SORT);
    menuSort.LoadMenu(IDR_POPUP_NAV);
    m_wndToolBar.ReplaceButton(ID_SORT_MENU, CClassViewMenuButton(menuSort.GetSubMenu(0)->GetSafeHmenu()));
@@ -127,117 +148,6 @@
    AdjustLayout();
}
void CNavView::FillClassView()
{
    HTREEITEM hRoot1 = m_NavViewTree.InsertItem(_T("连接1 Via COM3 230400 8-N-1 KLinkV1.00"), 0, 0);
    m_NavViewTree.SetItemState(hRoot1, TVIS_BOLD, TVIS_BOLD);
    HTREEITEM hItem;
    HTREEITEM hClass1 = m_NavViewTree.InsertItem(_T("KL10-E16D-N1  1/1 Run, Good"), 5, 5, hRoot1);
    m_NavViewTree.SetItemData(hClass1, 10);
    hItem = m_NavViewTree.InsertItem(_T("设备信息"), 3, 3, hClass1);
    m_NavViewTree.SetItemData(hItem, 11);
    hItem = m_NavViewTree.InsertItem(_T("工作状态,系统参数"), 3, 3, hClass1);
    m_NavViewTree.SetItemData(hItem, 12);
    HTREEITEM hPort2 = m_NavViewTree.InsertItem(_T("端口2 485 KBus 本机地址(0)/5 Run "), 1, 1, hClass1);
    m_NavViewTree.SetItemData(hPort2, 13);
    hItem = m_NavViewTree.InsertItem(_T("1 KL10-E08D-N1 Run Good"), 5, 5, hPort2);
    m_NavViewTree.SetItemData(hItem, 131);
    hItem = m_NavViewTree.InsertItem(_T("2 KL10-E08D-N1 Run bad"), 5, 5, hPort2);
    m_NavViewTree.SetItemData(hItem, 132);
    hItem = m_NavViewTree.InsertItem(_T("3 KL10-E08D-N1 Run Good"), 5, 5, hPort2);
    m_NavViewTree.SetItemData(hItem, 133);
    hItem = m_NavViewTree.InsertItem(_T("4 KL10-E08D-N1 Run Good"), 5, 5, hPort2);
    m_NavViewTree.SetItemData(hItem, 134);
    hItem = m_NavViewTree.InsertItem(_T("5 KL10-E08D-N1 Run bad"), 5, 5, hPort2);
    m_NavViewTree.SetItemData(hItem, 135);
    HTREEITEM hPort3 = m_NavViewTree.InsertItem(_T("端口3 WireLess "), 1, 1, hClass1);
    m_NavViewTree.SetItemData(hPort3, 14);
    m_NavViewTree.SetBkColor(COLORREF(0xf0f0f0f0) );
    m_NavViewTree.Expand(hRoot1, TVE_EXPAND);
    HTREEITEM hClass2 = m_NavViewTree.InsertItem(_T("CFakeAboutDlg"), 1, 1, hRoot1);
    m_NavViewTree.SetItemData(hClass2, 20);
    hItem = m_NavViewTree.InsertItem(_T("CFakeAboutDlg()"), 3, 3, hClass2);
    m_NavViewTree.SetItemData(hItem, 21);
    HTREEITEM hClass3 = m_NavViewTree.InsertItem(_T("CFakeAppDoc"), 1, 1, hRoot1);
    m_NavViewTree.SetItemData(hClass3, 30);
    hItem = m_NavViewTree.InsertItem(_T("CFakeAppDoc()"), 4, 4, hClass3);
    m_NavViewTree.SetItemData(hItem, 31);
    hItem = m_NavViewTree.InsertItem(_T("~CFakeAppDoc()"), 3, 3, hClass3);
    m_NavViewTree.SetItemData(hItem, 32);
    hItem = m_NavViewTree.InsertItem(_T("OnNewDocument()"), 3, 3, hClass3);
    m_NavViewTree.SetItemData(hItem, 33);
    HTREEITEM hClass4 = m_NavViewTree.InsertItem(_T("CFakeAppView"), 1, 1, hRoot1);
    m_NavViewTree.SetItemData(hClass4, 40);
    hItem = m_NavViewTree.InsertItem(_T("CFakeAppView()"), 4, 4, hClass4);
    m_NavViewTree.SetItemData(hItem, 41);
    hItem = m_NavViewTree.InsertItem(_T("~CFakeAppView()"), 3, 3, hClass4);
    m_NavViewTree.SetItemData(hItem, 42);
    hItem = m_NavViewTree.InsertItem(_T("GetDocument()"), 3, 3, hClass4);
    m_NavViewTree.SetItemData(hItem, 43);
    m_NavViewTree.Expand(hClass4, TVE_EXPAND);
    HTREEITEM hClass5 = m_NavViewTree.InsertItem(_T("Globals"), 2, 2, hRoot1);
    m_NavViewTree.SetItemData(hClass5, 50);
    hItem = m_NavViewTree.InsertItem(_T("theFakeApp"), 5, 5, hClass5);
    m_NavViewTree.SetItemData(hItem, 51);
    m_NavViewTree.Expand(hClass5, TVE_EXPAND);
    HTREEITEM hRoot2 = m_NavViewTree.InsertItem(_T("连接状态2"), 0, 0);
    m_NavViewTree.SetItemState(hRoot2, TVIS_BOLD, TVIS_BOLD);
}
void CNavView::OnContextMenu(CWnd* pWnd, CPoint point)
{
    CTreeCtrl* pWndTree = (CTreeCtrl*)&m_NavViewTree;
    ASSERT_VALID(pWndTree);
    if (pWnd != pWndTree)
    {
        CDockablePane::OnContextMenu(pWnd, point);
        return;
    }
    if (point != CPoint(-1, -1))
    {
        // 选择已单击的项:
        CPoint ptTree = point;
        pWndTree->ScreenToClient(&ptTree);
        UINT flags = 0;
        HTREEITEM hTreeItem = pWndTree->HitTest(ptTree, &flags);
        if (hTreeItem != nullptr)
        {
            pWndTree->SelectItem(hTreeItem);
        }
    }
    pWndTree->SetFocus();
    CMenu menu;
    menu.LoadMenu(IDR_POPUP_SORT);
    CMenu* pSumMenu = menu.GetSubMenu(0);
    if (AfxGetMainWnd()->IsKindOf(RUNTIME_CLASS(CMDIFrameWndEx)))
    {
        CMFCPopupMenu* pPopupMenu = new CMFCPopupMenu;
        if (!pPopupMenu->Create(this, point.x, point.y, (HMENU)pSumMenu->m_hMenu, FALSE, TRUE))
            return;
        ((CMDIFrameWndEx*)AfxGetMainWnd())->OnShowPopupMenu(pPopupMenu);
        UpdateDialogControls(this, FALSE);
    }
}
void CNavView::AdjustLayout()
{
@@ -304,52 +214,8 @@
int CNavView::DelayInit()
{
    // TODO: 在此处添加实现代码.
    FillClassView();
    FillDeviceView();
    return 0;
}
int CNavView::UpdateDisplay()
{
    // TODO: 在此处添加实现代码.
//    m_NavViewTree.DeleteAllItems();
//    FillClassView();
    CString s1;
    HTREEITEM hroot1 =  m_NavViewTree.GetRootItem();
    HTREEITEM hItem1 = m_NavViewTree.GetChildItem(hroot1);
    nDisplayCount++;
    s1.Format(_T("KL10-E16D-N1  1/1 Run, Good  %d"), nDisplayCount);
    m_NavViewTree.SetItemText(hItem1, s1);
    return 0;
}
void CNavView::OnUpdateSort(CCmdUI* pCmdUI)
{
    pCmdUI->SetCheck(pCmdUI->m_nID == m_nCurrSort);
}
void CNavView::OnClassAddMemberFunction()
{
    AfxMessageBox(_T("添加成员函数..."));
}
void CNavView::OnClassAddMemberVariable()
{
    // TODO: 在此处添加命令处理程序代码
}
void CNavView::OnClassDefinition()
{
    // TODO: 在此处添加命令处理程序代码
}
void CNavView::OnClassProperties()
{
    // TODO: 在此处添加命令处理程序代码
}
void CNavView::OnNewFolder()
{
    AfxMessageBox(_T("新建文件夹..."));
}
void CNavView::OnPaint()
@@ -398,9 +264,405 @@
    m_NavViewTree.SetImageList(&m_NavViewImages, TVSIL_NORMAL);
    m_wndToolBar.CleanUpLockedImages();
    m_wndToolBar.LoadBitmap(theApp.m_bHiColorIcons ? IDB_SORT_24 : IDR_SORT, 0, 0, TRUE /* 锁定*/);
    m_wndToolBar.LoadBitmap(theApp.m_bHiColorIcons ? IDB_NAV_TOOLBAR_24 : IDR_NAV_TOOLBAR, 0, 0, TRUE /* 锁定*/);
}
void CNavView::FillDeviceView()
{
    HTREEITEM hRoot1 = m_NavViewTree.InsertItem(_T("连接1 No Connect"), 0, 0);
    m_NavViewTree.SetItemState(hRoot1, TVIS_BOLD, TVIS_BOLD);
    HTREEITEM hItem;
    HTREEITEM hDevice1 = m_NavViewTree.InsertItem(_T("KL10-E08D-N1  1/1"), 5, 5, hRoot1);
    m_NavViewTree.SetItemData(hDevice1, MENU_DEVICE|0);
    m_NavViewTree.Expand(hRoot1, TVE_EXPAND);
/*
    hItem = m_NavViewTree.InsertItem(_T("设备信息"), 3, 3, hDevice1);
    m_NavViewTree.SetItemData(hItem, MENU_PROPERTY|0);
    hItem = m_NavViewTree.InsertItem(_T("工作状态,系统参数"), 3, 3, hDevice1);
    m_NavViewTree.SetItemData(hItem, MENU_PROPERTY|1);
    HTREEITEM hPort1 = m_NavViewTree.InsertItem(_T("端口1 232 KLink 本机地址(1)/5 Run "), 1, 1, hDevice1);
    m_NavViewTree.SetItemData(hPort1, MENU_PORT|0);
    HTREEITEM hPort2 = m_NavViewTree.InsertItem(_T("端口2 485 KBus 本机地址(0)/5 Run "), 1, 1, hDevice1);
    m_NavViewTree.SetItemData(hPort2, MENU_PORT|1);
    hItem = m_NavViewTree.InsertItem(_T("1 KL10-E08D-N1 Run Good"), 5, 5, hPort2);
    m_NavViewTree.SetItemData(hItem, MENU_REMOTE_DEVICE|0);
    HTREEITEM hPort3 = m_NavViewTree.InsertItem(_T("端口3 WireLess "), 1, 1, hDevice1);
    m_NavViewTree.SetItemData(hPort3, MENU_PORT|2);
    m_NavViewTree.SetBkColor(COLORREF(0xf0f0f0f0));
    HTREEITEM hDevice2 = m_NavViewTree.InsertItem(_T("KL10-E16D-N1  1/1"), 5, 5, hRoot1);
    m_NavViewTree.SetItemData(hDevice2, MENU_DEVICE | 1);
    // */
}
void CNavView::OnContextMenu(CWnd* pWnd, CPoint point)
{
    CTreeCtrl* pWndTree = (CTreeCtrl*)&m_NavViewTree;
    ASSERT_VALID(pWndTree);
    if (pWnd != pWndTree)
    {
        CDockablePane::OnContextMenu(pWnd, point);
        return;
    }
    HTREEITEM hTreeItem = nullptr;
    if (point != CPoint(-1, -1))
    {
        // 选择已单击的项:
        CPoint ptTree = point;
        pWndTree->ScreenToClient(&ptTree);
        UINT flags = 0;
        hTreeItem = pWndTree->HitTest(ptTree, &flags);
        if (hTreeItem != nullptr)
        {
            pWndTree->SelectItem(hTreeItem);
        }
    }
    pWndTree->SetFocus();
    DWORD_PTR ItemData = 0;
    if (hTreeItem != nullptr) {
        ItemData = m_NavViewTree.GetItemData(hTreeItem);
    }
    CMenu menu;
    //    menu.LoadMenu(IDR_POPUP_SORT);
    menu.LoadMenu(IDR_POPUP_NAV);
    CMenu* pSubMenu;
    HTREEITEM hRoot1 = m_NavViewTree.GetRootItem();
    HTREEITEM hDevice1 = m_NavViewTree.GetNextItem(hRoot1, TVGN_CHILD);
    if (hTreeItem == hRoot1) {
        pSubMenu = menu.GetSubMenu(1);        // 连接菜单
    }
    else if (hTreeItem == hDevice1 ){
        pSubMenu = menu.GetSubMenu(2);        //设备菜单
    }
    else if (ItemData & MENU_PROPERTY){
        pSubMenu = menu.GetSubMenu(3);        //属性菜单
    }
    else if (ItemData & MENU_PORT) {
        pSubMenu = menu.GetSubMenu(4);        //端口菜单
    }
    else if (ItemData & MENU_REMOTE_DEVICE) {
        pSubMenu = menu.GetSubMenu(5);        //远程设备菜单
    }
    else {
        pSubMenu = menu.GetSubMenu(0);        //默认菜单
    }
    pSubMenu->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y, this);
/*
    if (AfxGetMainWnd()->IsKindOf(RUNTIME_CLASS(CMDIFrameWndEx)))
    {
        CMFCPopupMenu* pPopupMenu = new CMFCPopupMenu;
        if (!pPopupMenu->Create(this, point.x, point.y, (HMENU)pSubMenu->m_hMenu, FALSE, TRUE))
            return;
        ((CMDIFrameWndEx*)AfxGetMainWnd())->OnShowPopupMenu(pPopupMenu);
        UpdateDialogControls(this, FALSE);
    }
*/
    menu.DestroyMenu();
}
void CNavView::OnUpdateSort(CCmdUI* pCmdUI)
{
    pCmdUI->SetCheck(pCmdUI->m_nID == m_nCurrSort);
}
void CNavView::OnClassAddMemberFunction()
{
    AfxMessageBox(_T("添加成员函数..."));
}
void CNavView::OnClassAddMemberVariable()
{
    // TODO: 在此处添加命令处理程序代码
}
void CNavView::OnClassDefinition()
{
    // TODO: 在此处添加命令处理程序代码
}
void CNavView::OnClassProperties()
{
    // TODO: 在此处添加命令处理程序代码
}
void CNavView::OnNewFolder()
{
    AfxMessageBox(_T("新建文件夹..."));
}
int CNavView::GetDocCount()
{
    // TODO: 在此处添加实现代码.
/*
    int nCount1 = 0;
    POSITION Templatepos = AfxGetApp()->m_pDocManager->GetFirstDocTemplatePosition();
    while (Templatepos != NULL)
    {
        CDocTemplate* pDocTemplate = AfxGetApp()->m_pDocManager->GetNextDocTemplate(Templatepos);
        POSITION pos = pDocTemplate->GetFirstDocPosition();
        while (pos != NULL)
        {
            CDocument * pDoc = pDocTemplate->GetNextDoc(pos);
            nCount1++;
            //if (pDoc->IsModified()) // 只保存被修改的文档
            //{
            //    pDoc->DoFileSave();
            //}
        }
    }
    return nCount1;
*/
    return 0;
}
int CNavView::UpdateDisplay()
{
    // TODO: 在此处添加实现代码.
//    m_NavViewTree.DeleteAllItems();
//    FillDeviceView();
    nDisplayCount++;
    KLink1* pMyKLink1 = &theApp.MyKLink1;
    CString s1;
    HTREEITEM hRoot1 = m_NavViewTree.GetRootItem();
    if (theApp.MyKLink1.m_bOpened) {
        s1.Format(_T("连接1 "));
        s1.AppendFormat(_T("COM%d %d %s "), pMyKLink1->MySerPort1.m_nPort, pMyKLink1->MySerPort1.m_nBaudRate, pMyKLink1->MySerPort1.m_Settings);
        s1.AppendFormat(_T("S %d R %d D %d"), theApp.MyKLink1.m_nTotalSendCount,theApp.MyKLink1.m_nTotalRecvCount, nDisplayCount);
///*
        if ( (nDisplayCount & 0x1f) == 0) {
            bPortRegsUpdated[0] = 0;
            bPortRegsUpdated[1] = 0;
            bPortRegsUpdated[2] = 0;
        }
// */
    }
    else {
        s1.Format(_T("连接1 No Connect"));
    }
    m_NavViewTree.SetItemText(hRoot1, s1);
    HTREEITEM hDevice1 = m_NavViewTree.GetChildItem(hRoot1);
//    m_NavViewTree.DeleteItem(hDevice1);
    if (!theApp.MyKLink1.m_bOpened) {
        s1.Format(_T("No Connect"));
    }
    else {
        s1.Format(_T("Dev %04X %s Run"), m_DeviceInfo.nDeviceTypeVer,DeviceTypeToStr(m_DeviceInfo.nDeviceTypeVer));
    }
    m_NavViewTree.SetItemText(hDevice1, s1);
    if (!theApp.MyKLink1.m_bOpened)
    {
        HTREEITEM hItem11 = m_NavViewTree.GetNextItem(hDevice1, TVGN_CHILD);
        s1.Format(_T("设备参数"));
        m_NavViewTree.SetItemText(hItem11, s1);
        HTREEITEM hItem12 = m_NavViewTree.GetNextItem(hItem11, TVGN_NEXT);
        m_NavViewTree.SetItemText(hItem12, _T("工作状态"));
        HTREEITEM hItem13 = m_NavViewTree.GetNextItem(hItem12, TVGN_NEXT);
        if (hItem13 != nullptr) {
            bPortRegsUpdated[0] = 0;
            bPortRegsUpdated[1] = 0;
            bPortRegsUpdated[2] = 0;
            m_NavViewTree.DeleteItem(hItem13);
            HTREEITEM hItem13 = m_NavViewTree.GetNextItem(hItem12, TVGN_NEXT);
        }
    }else
    {
        HTREEITEM hItem11 = m_NavViewTree.GetNextItem(hDevice1, TVGN_CHILD);
        if (hItem11 == nullptr) {
            hItem11 = m_NavViewTree.InsertItem(_T("设备参数 "), 3, 3, hDevice1);
            m_NavViewTree.Expand(hDevice1, TVE_EXPAND);
        }
        s1.Format(_T("设备参数 V%d.%02d KLink %04X KBus %04X In %d Out %d"),
            m_infoblock.nProgVerMajor, m_infoblock.nProgVerMinor, m_infoblock.nKLinkVer, m_infoblock.nKBusVer, m_DeviceInfo.InBitCount, m_DeviceInfo.OutBitCount);
        m_NavViewTree.SetItemText(hItem11, s1);
        HTREEITEM hItem12 = m_NavViewTree.GetNextItem(hItem11, TVGN_NEXT);
        if (hItem12 == nullptr) {
            hItem12 = m_NavViewTree.InsertItem(_T("工作状态 "), 3, 3, hDevice1);
            m_NavViewTree.Expand(hDevice1, TVE_EXPAND);
        }
        m_NavViewTree.SetItemText(hItem12, _T("工作状态,系统参数,IO状态 hItem12"));
        HTREEITEM hPort1 = hItem12;
        USHORT nReaded = 0;
        USHORT DataBuf1[256];
        for (int i = 0; i < m_DeviceInfo.nPortCount; i++) {
            hPort1 = m_NavViewTree.GetNextItem(hPort1, TVGN_NEXT);
            if (hPort1 == nullptr) {
                hPort1 = m_NavViewTree.InsertItem(_T("端口1 "), 1, 1, hDevice1);
                m_NavViewTree.Expand(hDevice1, TVE_EXPAND);
            }
            if (theApp.MyKLink1.m_bOpened && !bPortRegsUpdated[i]) {
                int res1 = theApp.MyKLink1.GetPortInfo(1, i, sizeof(stPortDef), &nReaded, DataBuf1);
                if (res1 == KLink1::KL_OK) {
                    pstPortDef thepPortReg = (pstPortDef)DataBuf1;
                    PortDefs[i] = *thepPortReg;
                    s1.Format(_T("端口%d (%02X)%s (%02X)%s 能力 %04X M %d 站号 %d/%d H %d"), i + 1,
                        thepPortReg->nPortHardType, PortHardTypeToStr(thepPortReg->nPortHardType), thepPortReg->nPortUseType,
                        PortUseTypeToStr(thepPortReg->nPortUseType), thepPortReg->ability, thepPortReg->bMaster, thepPortReg->StationId, thepPortReg->nMaxStations, thepPortReg->nHealth);
                    m_NavViewTree.SetItemText(hPort1, s1);
                    m_NavViewTree.SetItemData(hPort1, MENU_PORT | i);
                    bPortRegsUpdated[i] = 1;
                    break;
                }
                else {
                    s1.Format(_T("GetPortInfo %d = %d len %d  %s"), i, res1, &nReaded,theApp.MyKLink1.m_resultStr);
                    DbgLog(s1);
                    s1.Format(_T("端口%d --------- ???? "), i + 1);
                    m_NavViewTree.SetItemText(hPort1, s1);
                    m_NavViewTree.SetItemData(hPort1, MENU_PORT | i);
                }
            }
            if (bPortRegsUpdated[i] && (PortDefs[i].nPortUseType == PortUse_KBus || PortDefs[i].nPortUseType == PortUse_KRF)) {
                HTREEITEM hChild1 = m_NavViewTree.GetNextItem(hPort1, TVGN_CHILD);
                int nChildCount = PortDefs[i].nMaxStations;
                for (int j = 1; j <= nChildCount; j++) {
                    if (j != 1) hChild1 = m_NavViewTree.GetNextItem(hChild1, TVGN_NEXT);
                    if (hChild1 == nullptr) {
                        s1.Format(_T("子机%d "), j);
                        hChild1 = m_NavViewTree.InsertItem(s1, 5, 5, hPort1);
                        m_NavViewTree.SetItemData(hChild1, MENU_REMOTE_DEVICE | (j));
                        m_NavViewTree.Expand(hPort1, TVE_EXPAND);
                    }
                    //if (j < LastUpdateIndex) continue;
                    if (bPortDeviceUpdated[j]) continue;
                    int res2 = theApp.MyKLink1.GetPortChildInfo(1, i, j, sizeof(stDeviceInfo), &nReaded, DataBuf1);  //sizeof(stDeviceInfo)
                    if (res2 == KLink1::KL_OK) {
                        s1.Format(_T("GetChildInfo %d %d = %d B\r\n"), i, j, nReaded);
                        for (int k = 0; k < nReaded; k++) {
                            s1.AppendFormat(_T("%02X "), ((unsigned char*)DataBuf1)[k]);
                        }
                        // SysLog(s1);
                        stDeviceInfo* ptheInfo = (stDeviceInfo*)DataBuf1;
                        PortDeviceInfos[j] = *ptheInfo;
                        s1.Format(_T("子%d (%04X)%s V%d.%02d %d/%d "),
                            j, ptheInfo->DeviceType, DeviceTypeToStr(ptheInfo->DeviceType), ptheInfo->DeviceVerMajor, ptheInfo->DeviceVerMinor, ptheInfo->InBitCount, ptheInfo->OutBitCount);
                        m_NavViewTree.SetItemText(hChild1, s1);
                        m_NavViewTree.SetItemData(hChild1, MENU_REMOTE_DEVICE | (j));
                    }
                    bPortDeviceUpdated[j] = 1;
                    break;
                }
                LastUpdateIndex[i]++;
                if (LastUpdateIndex[i] > nChildCount) { LastUpdateIndex[i] = 0; }
                s1.Format(_T("i %d LastUpdated %d  nChildCount %d  nMaxStations %d \r\n"),i, LastUpdateIndex[i],nChildCount, PortDefs[i].nMaxStations);
            //    SysLog(s1);
            }
            ///*
            if (bPortRegsUpdated[i] && PortDefs[i].nPortUseType == PortUse_KBus ) {
                HTREEITEM hChild1 = m_NavViewTree.GetNextItem(hPort1, TVGN_CHILD);
                int nChildCount = PortDefs[i].nMaxStations;
                int j = LastUpdateIndex[i] + 1;
                for (int j = 1; j <= nChildCount; j++) {
                    if (j != 1) hChild1 = m_NavViewTree.GetNextItem(hChild1, TVGN_NEXT);
                    if (hChild1 == nullptr) {
                        s1.Format(_T("子机%d "), j);
                        hChild1 = m_NavViewTree.InsertItem(s1, 5, 5, hPort1);
                        m_NavViewTree.Expand(hPort1, TVE_EXPAND);
                    }
                    if (j < LastUpdateIndex[i]) continue;
                    //if (bPortDeviceUpdated[j]) continue;
                    int res2 = theApp.MyKLink1.GetPortChnInfo(1, i, j, sizeof(stChnStat), &nReaded, DataBuf1);  //sizeof(stDeviceInfo)
                    if (res2 == KLink1::KL_OK) {
                        s1.Format(_T("GetChnInfo %d %d = %d B\r\n"), i, j, nReaded);
                        for (int k = 0; k < nReaded; k++) {
                            s1.AppendFormat(_T("%02X "), ((unsigned char*)DataBuf1)[k]);
                        }
                        //    SysLog(s1);
                        stDeviceInfo* ptheInfo = &PortDeviceInfos[j];
                        stChnStat* ptheChnInfo = (stChnStat*)DataBuf1;
                        s1.Format(_T("子%d (%04X)%s V%d.%02d %d/%d 丢包率(%.2f%%) 收发(%d/%d) "), j,
                            ptheInfo->DeviceType, DeviceTypeToStr(ptheInfo->DeviceType), ptheInfo->DeviceVerMajor, ptheInfo->DeviceVerMinor, ptheInfo->InBitCount, ptheInfo->OutBitCount
                            , ptheChnInfo->LostPackets * 100.0 / ptheChnInfo->SendPackets, ptheChnInfo->RecvPackets, ptheChnInfo->SendPackets);
                        m_NavViewTree.SetItemText(hChild1, s1);
                    }
                    //    bPortDeviceUpdated[j] = 1;
                    break;
                }
            }
            // */
            ///*
            if (bPortRegsUpdated[i] &&  PortDefs[i].nPortUseType == PortUse_KRF) {
                HTREEITEM hChild1 = m_NavViewTree.GetNextItem(hPort1, TVGN_CHILD);
                int nChildCount = PortDefs[i].nMaxStations;
                int j = LastUpdateIndex[i] + 1;
                for (int j = 1; j <= nChildCount; j++) {
                    if (j != 1) hChild1 = m_NavViewTree.GetNextItem(hChild1, TVGN_NEXT);
                    if (hChild1 == nullptr) {
                        s1.Format(_T("子机%d "), j);
                        hChild1 = m_NavViewTree.InsertItem(s1, 5, 5, hPort1);
                        m_NavViewTree.Expand(hPort1, TVE_EXPAND);
                    }
                    if (j < LastUpdateIndex[i]) continue;
                    //if (bPortDeviceUpdated[j]) continue;
                    int res2 = theApp.MyKLink1.GetPortChnInfo(1, i, j, sizeof(stKwChnStat), &nReaded, DataBuf1);  //sizeof(stDeviceInfo)
                    if (res2 == KLink1::KL_OK) {
                        s1.Format(_T("GetChnInfo %d %d = %d B\r\n"), i, j, nReaded);
                        for (int k = 0; k < nReaded; k++) {
                            s1.AppendFormat(_T("%02X "), ((unsigned char*)DataBuf1)[k]);
                        }
                        //    SysLog(s1);
                        stDeviceInfo* ptheInfo = &PortDeviceInfos[j];
                        stKwChnStat* ptheChnInfo = (stKwChnStat*)DataBuf1;
                        s1.Format(_T("子%d (%04X)%s V%d.%02d %d/%d 丢包率(%.2f%%) 收发(%d/%d) "), j,
                            ptheInfo->DeviceType, DeviceTypeToStr(ptheInfo->DeviceType), ptheInfo->DeviceVerMajor, ptheInfo->DeviceVerMinor, ptheInfo->InBitCount, ptheInfo->OutBitCount
                            , ptheChnInfo->LostPackets * 100.0 / ptheChnInfo->sentCount, ptheChnInfo->recvCount, ptheChnInfo->sentCount);
                        m_NavViewTree.SetItemText(hChild1, s1);
                    }
                    else {
                        s1.Format(_T("GetChnInfo %d %d = %d B\r\n"), i, j, nReaded);
                        SysLog(s1);
                    }
                    //    bPortDeviceUpdated[j] = 1;
                    break;
                }
            }
            // */
        }
    }
    HTREEITEM hDevice2 = m_NavViewTree.GetNextItem(hDevice1, TVGN_NEXT);
    m_NavViewTree.SetItemText(hDevice2, _T("hDevice2"));
//    HTREEITEM hDevice1 = m_NavViewTree.InsertItem(s1, 5, 5, hRoot1);
//    m_NavViewTree.SetItemData(hDevice1, 10);
//    m_NavViewTree.SetItemText(hDevice1, s1);
    /*
        AfxGetApp()->m_pDocManager->GetFirstDocTemplatePosition
        CMDIFrameWnd* pFrame = (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd;
        CMDIChildWnd* pChild = (CMDIChildWnd*)pFrame->GetActiveFrame();
        CView* pV = (CView*)pChild->GetActiveView();
        CMTerm1Doc* pDoc = (CMTerm1Doc*)(pV->GetDocument());
    */
    return 0;
}
void CNavView::OnNMClkNavTree1(NMHDR* pNMHDR, LRESULT* pResult)
{
    LPNMTREEVIEW pNMTreeView = reinterpret_cast<LPNMTREEVIEW>(pNMHDR);
@@ -439,4 +701,852 @@
    *pResult = 0;
}
void CNavView::OnMenuNavSetConn()
{
    // TODO: 在此添加命令处理程序代码
    theApp.MyKLink1.SetCommParam();
}
void CNavView::OnSetComm()
{
    // TODO: 在此添加命令处理程序代码
    theApp.MyKLink1.SetCommParam();
}
void CNavView::OnConnect()
{
    // TODO: 在此添加命令处理程序代码
    CString s1;
    unsigned short buf1[64];
    unsigned short len1;
    if (!theApp.MyKLink1.m_bCommParamSet) {
        theApp.MyKLink1.m_nPort = 6;
    }
    int res = theApp.MyKLink1.Connect();
    if (res == KLink1::KL_OK) {
        Sleep(100);
        theApp.MyKLink1.MySerPort1.ClearBuf();
        int res2 = theApp.MyKLink1.GetInfo(1, &len1, buf1);
        s1.Format(_T("GetInfo = %d %d \r\n"), res2, len1);
        if (res2 == KLink1::KL_OK && len1 > 0) {
            pKMInfoBlock pinfob = (pKMInfoBlock)buf1;
            m_infoblock = *pinfob;
            for (int i = 0; i < 8; i++) {
                bPortRegsUpdated[i] = 0;
            }
            for (int i = 0; i < 16; i++) {
                bPortDeviceUpdated[i] = 0;
            }
            m_DeviceInfo.nDeviceTypeVer = pinfob->nDeviceTypeVer;
            m_DeviceInfo.InBitCount = pinfob->nDInput;
            m_DeviceInfo.OutBitCount = pinfob->nDOutput;
            m_DeviceInfo.nPortCount = pinfob->nPorts;
            HTREEITEM hRoot1 = m_NavViewTree.GetRootItem();
            if (theApp.MyKLink1.m_bOpened) {
                s1.Format(_T("连接1 "));
                s1.AppendFormat(_T("COM%d %d %s "), theApp.MyKLink1.MySerPort1.m_nPort, theApp.MyKLink1.MySerPort1.m_nBaudRate, theApp.MyKLink1.MySerPort1.m_Settings);
                s1.AppendFormat(_T("%d %d  %d \r\n"), theApp.MyKLink1.m_nTotalSendCount, theApp.MyKLink1.m_nTotalRecvCount, nDisplayCount);
            }
            else {
                s1.Format(_T("连接1 No Connect"));
            }
            m_NavViewTree.SetItemText(hRoot1, s1);
            HTREEITEM hDevice1 = m_NavViewTree.GetChildItem(hRoot1);
            m_NavViewTree.Expand(hDevice1, TVE_EXPAND);
            for (int i = 0; i < len1 / 2; i++) {
                s1.AppendFormat(_T("%04X "), buf1[i]);
            }
            s1 += _T("\r\n");
            s1.AppendFormat(_T(" DeviceType %04X \t "), pinfob->nDeviceTypeVer);
            s1.AppendFormat(_T(" nProgVer %04X \r\n"), pinfob->nProgVer);
            s1.AppendFormat(_T(" nKLinkVer %04X \t"), pinfob->nKLinkVer);
            s1.AppendFormat(_T(" nKBusVer %04X \r\n"), pinfob->nKBusVer);
            s1.AppendFormat(_T(" nCapacity1 %d k \t"), pinfob->nCapacity1);
            s1.AppendFormat(_T(" nCapacity2 %d k\r\n"), pinfob->nCapacity2);
            s1.AppendFormat(_T(" nDInput %d \t"), pinfob->nDInput);
            s1.AppendFormat(_T(" nDOutput %d \r\n"), pinfob->nDOutput);
            s1.AppendFormat(_T(" nAInput %d \t"), pinfob->nAInput);
            s1.AppendFormat(_T(" nAOutput %d \r\n"), pinfob->nAOutput);
            s1.AppendFormat(_T(" nHInput %d   \t"), pinfob->nHInput);
            s1.AppendFormat(_T(" nHOutput %d \r\n"), pinfob->nHOutput);
            s1.AppendFormat(_T(" nExt1 %d \t"), pinfob->nExt1);
            s1.AppendFormat(_T(" nExt2 %d \r\n"), pinfob->nExt2);
            s1.AppendFormat(_T(" nLogSize %d \r\n"), pinfob->nLogSize);
            s1.AppendFormat(_T(" nPorts %d \r\n"), pinfob->nPorts);
            s1.AppendFormat(_T(" nManSize %d \r\n"), pinfob->nManSize);
            s1.AppendFormat(_T(" nAbility %d \r\n"), pinfob->nAbility);
            s1.AppendFormat(_T(" nSwitchBits %d \r\n"), pinfob->nSwitchBits);
        }
        SysLog(s1);
        int len0 = sizeof(stKMSysCfg);
        UCHAR nType = 0;
        res2 = theApp.MyKLink1.ReadSysCfgData(1, nType, 0, len0, &len1, buf1);
        s1.Format(_T("GetSysCfg %d = %d %d \r\n"), len0, res2, len1);
        if (res2 == KLink1::KL_OK && len1 > 0) {
            for (int i = 0; i < len1 / 2; i++) {
                s1.AppendFormat(_T("%04X "), buf1[i]);
            }
            s1 += _T("\r\n");
            pstKMSysCfg pSysCfg = (pstKMSysCfg)buf1;
            s1.AppendFormat(_T("Version %04X \r\n"), pSysCfg->Version);
            s1.AppendFormat(_T("WorkMode %04X \r\n"), pSysCfg->workmode);
            s1.AppendFormat(_T("SwitchFunc %04X \r\n"), pSysCfg->SwitchFunc);
            s1.AppendFormat(_T("CfgBlockCount %d \r\n"), pSysCfg->nCfgBlockCount);
            for (int j = 0; j < 2; j++) {
                s1.AppendFormat(_T("COM %d \r\n"), j + 1);
                s1.AppendFormat(_T("WorkMode %d \r\n"), pSysCfg->PortParams[j].WorkMode);
                s1.AppendFormat(_T("Station %d \r\n"), pSysCfg->PortParams[j].Station);
                s1.AppendFormat(_T("BaudRate %d \r\n"), pSysCfg->PortParams[j].BaudRate*100);
                s1.AppendFormat(_T("ByteSize %d Parity %d StopBit %d \r\n"), pSysCfg->PortParams[j].ByteSize, pSysCfg->PortParams[j].Parity, pSysCfg->PortParams[j].StopBits);
                s1.AppendFormat(_T("EndType %d \r\n"), pSysCfg->PortParams[j].EndType);
                s1.AppendFormat(_T("EofChar %d \r\n"), pSysCfg->PortParams[j].EofChar);
                s1.AppendFormat(_T("SofChar %d \r\n"), pSysCfg->PortParams[j].SofChar);
                s1.AppendFormat(_T("EndTime %d \r\n"), pSysCfg->PortParams[j].EndTime);
                s1.AppendFormat(_T("RecvAddr %d \r\n"), pSysCfg->PortParams[j].RecvAddr);
                s1.AppendFormat(_T("RecvSize %d \r\n"), pSysCfg->PortParams[j].RecvSize);
            }
/*
            s1.AppendFormat(_T("InputParam \r\n"));
            for (int j = 0; j < 16; j++) {
                s1.AppendFormat(_T("%2d Filter0 %d  Filter1 %d \r\n"),j, pSysCfg->InputParams[j].Filter0, pSysCfg->InputParams[j].Filter1);
            }
            s1.AppendFormat(_T("OutputParam \r\n"));
            for (int j = 0; j < 16; j++) {
                s1.AppendFormat(_T("%2d Hold1 %d  Hold2 %d \r\n"),j, pSysCfg->OutputParams[j].Hold1, pSysCfg->OutputParams[j].Hold2);
            }
// */
            s1.AppendFormat(_T("OutMapping \r\n"));
            for (int j = 0; j < 8; j++) {
//                s1.AppendFormat(_T("%d Map %04X \r\n"),j, pSysCfg->OutMappings[j]);
                s1.AppendFormat(_T("%d Map %04X type %X Addr %02X bitPos %X\r\n"),j, pSysCfg->OutMappings[j].value,pSysCfg->OutMappings[j].type,pSysCfg->OutMappings[j].byteAddr,pSysCfg->OutMappings[j].bitPos);
            }
            s1.AppendFormat(_T("CfgBlockCount %d\r\n"), pSysCfg->nCfgBlockCount);
            for (int j = 0; j < pSysCfg->nCfgBlockCount; j++) {
                //                s1.AppendFormat(_T("%d Map %04X \r\n"),j, pSysCfg->OutMappings[j]);
                s1.AppendFormat(_T("%d type %X Size %d \r\n"), j, pSysCfg->CfgBlockInfos[j].nBlockType, pSysCfg->CfgBlockInfos[j].nBlockSize);
            }
        }
        SysLog(s1);
    }
}
static const uint16_t crctalbeabs[] = {
    0x0000, 0xCC01, 0xD801, 0x1400, 0xF001, 0x3C00, 0x2800, 0xE401,
    0xA001, 0x6C00, 0x7800, 0xB401, 0x5000, 0x9C01, 0x8801, 0x4400
};
static uint16_t crc16tablefast(uint8_t* ptr, uint16_t len)
{
    uint16_t crc = 0xffff;
    uint16_t i;
    uint8_t ch;
    for (i = 0; i < len; i++) {
        ch = *ptr++;
        crc = crctalbeabs[(ch ^ crc) & 15] ^ (crc >> 4);
        crc = crctalbeabs[((ch >> 4) ^ crc) & 15] ^ (crc >> 4);
    }
    return crc;
}
void CNavView::OnDisConnect()
{
    // TODO: 在此添加命令处理程序代码
    theApp.MyKLink1.DisConnect();
}
void CNavView::OnMenuNavConnect()
{
    // TODO: 在此添加命令处理程序代码
    OnConnect();
}
void CNavView::OnMenuNavDisconnect()
{
    // TODO: 在此添加命令处理程序代码
    OnDisConnect();
}
void CNavView::OnMenuNvDeviceReadInfo()
{
    // TODO: 在此添加命令处理程序代码
    CString s1;
    s1.Format(_T("读取设备 信息"));
    SysLog(s1);
    USHORT len1;
    USHORT buf1[1024];
    int r2 = theApp.MyKLink1.GetInfo(1, &len1, buf1);
    pKMInfoBlock pinfob = (pKMInfoBlock)buf1;
    if (r2 == 0 && len1 > 0) {
        for (int i = 0; i < len1 / 2; i++) {
            s1.AppendFormat(_T("%04X "), buf1[i]);
        }
        s1 += _T("\r\n");
        s1.AppendFormat(_T(" DeviceType %04X \t "), pinfob->nDeviceTypeVer);
        s1.AppendFormat(_T(" nProgVer %04X \r\n"), pinfob->nProgVer);
    }
    SysLog(s1);
    myLogger1.UpdateLogDisplay();
}
void CNavView::OnDeviceConfig()
{
    // TODO: 在此添加命令处理程序代码
    CString s1;
    s1.Format(_T("设置参数"));
    SysLog(s1);
    USHORT len1;
    USHORT buf1[1024];
    int r2 = theApp.MyKLink1.GetInfo(1, &len1, buf1);
    pKMInfoBlock pinfob = (pKMInfoBlock)buf1;
    if (r2 == 0 && len1 > 0) {
        for (int i = 0; i < len1 / 2; i++) {
            s1.AppendFormat(_T("%04X "), buf1[i]);
        }
        s1 += _T("\r\n");
        s1.AppendFormat(_T(" DeviceType %04X \t "), pinfob->nDeviceTypeVer);
        s1.AppendFormat(_T(" nProgVer %04X \r\n"), pinfob->nProgVer);
    }
    SysLog(s1);
    myLogger1.UpdateLogDisplay();
}
void CNavView::OnLedBlink()
{
    // TODO: 在此添加命令处理程序代码
    CString s1;
    theApp.MyKLink1.BlinkLED(1, 5);
}
void CNavView::OnResetDevice()
{
    // TODO: 在此添加命令处理程序代码
    CString s1;
    int r5 = theApp.MyKLink1.ResetDevice(1, 0);
    s1.Format(_T("ResetDevice  = %d"), r5);
    SysLog(s1);
    for (int i = 0; i < 8; i++) {
        bPortRegsUpdated[i] = 0;
    }
    for (int i = 0; i < 16; i++) {
        bPortDeviceUpdated[i] = 0;
    }
}
void CNavView::OnCommtest()
{
    // TODO: 在此添加命令处理程序代码
    CString s1;
    /*
        CView* pView;
        pView = FindView(RUNTIME_CLASS(CMTerm1CtrlView));
        if (pView != NULL) {
            ((CMDIFrameWndEx*)AfxGetMainWnd())->MDIActivate(pView->GetParent());
            //        pView->SetActiveWindow();
        }
        else {
            s1 = GetTitle();
            //AfxMessageBox(s1);
            ASSERT_VALID(theApp.m_pCtrlViewTemplate);
            CFrameWnd* pFrame = theApp.m_pCtrlViewTemplate->CreateNewFrame(this, NULL);
            ASSERT_KINDOF(CFrameWnd, pFrame);
            theApp.m_pCtrlViewTemplate->InitialUpdateFrame(pFrame, this);
        }
    */
    int a = 0;
#pragma omp parrelle for
    for (int i = 0; i < 1000; i++) {
        a += i;
    }
    s1.Format(_T("a = %d "), a);
    DbgLog(s1);
}
void CNavView::OnMenuNvUpdateFirmware()
{
    // TODO: 在此添加命令处理程序代码
    CString s1;
    s1.Format(_T("更新设备 固件"));
    SysLog(s1);
    USHORT len1;
    USHORT buf1[1024];
    int r2 = theApp.MyKLink1.GetInfo(1, &len1, buf1);
    pKMInfoBlock pinfob = (pKMInfoBlock)buf1;
    if (r2 == 0 && len1 > 0) {
        for (int i = 0; i < len1 / 2; i++) {
            s1.AppendFormat(_T("%04X "), buf1[i]);
        }
        s1 += _T("\r\n");
        s1.AppendFormat(_T(" DeviceType %04X \t "), pinfob->nDeviceTypeVer);
        s1.AppendFormat(_T(" nProgVer %04X \r\n"), pinfob->nProgVer);
    }
    SysLog(s1);
    myLogger1.UpdateLogDisplay();
    unsigned char Appbuf[131072];
    unsigned char firmwarebuf[262144];
    int nBtldrInfoOffset = 256;
    int AppOffset = 4096;
    int nAppInfoOffset = 256;
    int btldrLength = 0;
    int AppLength = 0;
    int FirmwareSize = 0;
    bool btldrfileLoaded = false;
    bool appfileLoaded = false;
    bool combinefileSaved = false;
    unsigned char filebuf[65536];
    unsigned int blocksize = 64;
    stNewAppInfoBlock NewAppInfo;
    CFileDialog dialog1(true);
    INT_PTR r = dialog1.DoModal();
    if (r == IDOK)
    {
        CString sFilePathName = dialog1.GetPathName();
        //OpenFile
        CFile file1;
        CFileException e;
        bool r = file1.Open(sFilePathName, CFile::modeRead | CFile::typeBinary, &e);
        s1.Format(_T("Open File %s = %d"), sFilePathName, r);
        DbgLog(s1);
        if (r)
        {
            int fileLen1 = (int)file1.GetLength();
            file1.Read(filebuf, fileLen1);
            file1.Close();
            unsigned int nBlkType = 0;
            unsigned int nBlkVer = 0;
            s1.Empty();
            pAppInfoBlock pAppinfo = (pAppInfoBlock)(filebuf + nAppInfoOffset);
            s1.Format(_T("文件信息  \r\n"));
//            SetDlgItemText(IDC_STATIC_APP_INFO, s1);
            if (pAppinfo->Hdr.nBlkSign == 0xaa55) {
                s1.Empty();
                s1.Format(_T("文件信息  "));
                // s1.AppendFormat(_T("启动文件 %s \r\n"), sFilePathName);
                s1.AppendFormat(_T("文件大小: %d \r\n"), fileLen1);
                s1.AppendFormat(_T("信息块位置: 0x%04X  信息块大小: %d  \r\n"), nAppInfoOffset, pAppinfo->Hdr.nBlkSize);
                s1.AppendFormat(_T("信息块类型: 0x%04X  "), pAppinfo->Hdr.nBlkTypeVer);
                nBlkType = (pAppinfo->Hdr.nBlkTypeVer) >> 8;
                nBlkVer = pAppinfo->Hdr.nBlkTypeVer & 0xff;
                if (nBlkType == 0x01) { s1.AppendFormat(_T(" (BootLoader 类型1 版本 %d) "), nBlkVer); }
                else if (nBlkType == 0x02) { s1.AppendFormat(_T(" (BootLoader 类型2 版本 %d) "), nBlkVer); }
                else if (nBlkType == 0x03) { s1.AppendFormat(_T(" (App类型1 版本 %d) "), nBlkVer); }
                else if (nBlkType == 0x04) { s1.AppendFormat(_T(" (App类型2 版本 %d) "), nBlkVer); }
                else { s1.AppendFormat(_T(" (未知类型)  ")); }
                s1.AppendFormat(_T("\r\n"));
                s1.AppendFormat(_T("应用区版本: 0x%04X  对应模块类型: 0x%04X\r\n"), pAppinfo->nAppVer, pAppinfo->nAppDevice);
                s1.AppendFormat(_T("应用区大小: 0x%04X  实际代码大小: 0x%04X \r\n"), pAppinfo->nAppSize, pAppinfo->nAppDataSize);
                s1.AppendFormat(_T("应用区地址: 0x%08X (偏移 %d )\r\n"), pAppinfo->nAppStartAddr, pAppinfo->nAppStartAddr - 0x08000000);
                s1.AppendFormat(_T("信息暂存区: 0x%08X \r\n应用暂存区: 0x%08X \r\n"), pAppinfo->nAppStartOffset, pAppinfo->nApp);
//                SetDlgItemText(IDC_STATIC_APP_INFO, s1);
                if (nBlkType == 0x03 || nBlkType == 0x04) {
                    memmove(Appbuf, filebuf , fileLen1);
                    appfileLoaded = true;
                    AppLength = fileLen1;
                }
                else {
                    if ((nBlkType == 0x01 || nBlkType == 0x02) && fileLen1 >= AppOffset + nAppInfoOffset + sizeof(stAppInfoBlock))
                    {
                        pAppInfoBlock pAppinfo2 = (pAppInfoBlock)(filebuf + AppOffset + nAppInfoOffset);
                        if ((pAppinfo2->Hdr.nBlkSign == 0xaa55) && pAppinfo2->Hdr.nBlkTypeVer == 0x0301) {
                            s1.Format(_T("文件是bootloader和App合成的文件 , 是否从中提取固件并继续"));
                            int r3 = AfxMessageBox(s1, MB_YESNO);
                            if (r3 == IDYES) {
                                memmove(Appbuf, filebuf + AppOffset, fileLen1 - AppOffset);
                                appfileLoaded = true;
                                AppLength = fileLen1 - AppOffset;
                            }
                        }
                        else {
                            s1.Format(_T("文件 不是App文件 , 是否继续 "));
                            int r3 = AfxMessageBox(s1, MB_YESNO);
                            if (r3 == IDYES) {
                                memmove(Appbuf, filebuf , fileLen1 );
                                appfileLoaded = true;
                                AppLength = fileLen1;
                            }
                        }
                    }
                    else {
                        s1.Format(_T("文件 不是App文件 , 是否继续 "));
                        int r3 = AfxMessageBox(s1, MB_YESNO);
                        if (r3 == IDYES) {
                            memmove(Appbuf, filebuf , fileLen1 );
                            appfileLoaded = true;
                            AppLength = fileLen1;
                        }
                    }
                }
                //            s1.Format(_T("  BootLoader启动文件  版本 %04X 硬件类型 %04X 占用空间 %04X,  %d Bytes\r\n 是否继续"), pinfob->nBtldrVer, pinfob->nBtldrDevice, pinfob->nBtldrSize, fileLen1);
            }
            else {
                s1.Format(_T("文件中未找到信息块, 文件大小  %d Bytes\r\n 是否继续"), fileLen1);
                int r3 = AfxMessageBox(s1, MB_YESNO);
                if (r3 == IDYES) {
                    memmove(Appbuf, filebuf , fileLen1 );
                    appfileLoaded = true;
                    AppLength = fileLen1;
                }
            }
            unsigned short crc2 = crc16tablefast(Appbuf, AppLength);
            unsigned char* buf2 = Appbuf + 0x1000; ;
            //s1.Format(_T("GetInfo From File  = %d %d \r\n"), j, fileLen1);
            pKMInfoBlock pinfof = (pKMInfoBlock)buf2;
            s1.Format(_T(" 目标模块 类型 %04X 版本 %d.%02d, \r\n 固件文件 类型 %04X 版本 %d.%02d,  %d Bytes\r\n 是否继续"),
                pinfob->nDeviceTypeVer, pinfob->nProgVerMajor,pinfob->nProgVerMinor,
                pinfof->nDeviceTypeVer, pinfof->nProgVerMajor,pinfof->nProgVerMinor, fileLen1);
            int r3 = AfxMessageBox(s1, MB_YESNO);
            if (r3 == IDYES) {
                int bError = 0;
                for (int i = 0; i < AppLength; i += blocksize)
                {
                    int sendsize = AppLength - i;
                    if (sendsize > blocksize) { sendsize = blocksize; }
                    int k = 999;
                    int j = 0;
                    double time1 = GetTimemS();
                    for (j = 0; j < 5 && k != 0; j++) {
                        k = theApp.MyKLink1.WriteFirmware(1, 0, i, sendsize, Appbuf + i);
                        if (k) {
                            double time2 = GetTimemS();
                            s1.Format(_T("Wr@ %x %dB = %d  re %d %.2fmS %s "), i, sendsize, k, j, time2 - time1, theApp.MyKLink1.m_resultStr);
                            SysLog(s1);
                            myLogger1.UpdateLogDisplay();
                            Sleep(30);
                        }
                    }
                    double time2 = GetTimemS();
                    s1.Format(_T("Wr@ %x %dB = %d  re %d %.2fmS"), i, sendsize, k, j, time2 - time1);
                    SysLog(s1);
                    myLogger1.UpdateLogDisplay();
                    if (k) {   // 出现错误;
                        bError = 1;
                        CString sErr;
                        sErr = KLink1::GetErrDescStr(k);
                        s1.Format(_T("下载出错 %d, %s"), k, sErr);
                        int r3 = AfxMessageBox(s1);
                        break;  //跳出
                    }
                }
                if (bError == 0) {
                    NewAppInfo.Length = AppLength;
                    NewAppInfo.Sign = 0x55AA;
                    NewAppInfo.Version = 0x109;
                    NewAppInfo.nCRC = crc2;
                    int k = theApp.MyKLink1.WriteFirmInfo(1, 0, 0, sizeof(NewAppInfo), (UCHAR*)&NewAppInfo);
                    s1.Format(_T("Write InfoBlock %d bytes = %d"), sizeof(NewAppInfo), k);
                    SysLog(s1);
                    Sleep(100);
                    int r5 = theApp.MyKLink1.ResetDevice(1, 0);
                    s1.Format(_T("ResetDevice  = %d"), r5);
                    SysLog(s1);
                    myLogger1.UpdateLogDisplay();
                    Sleep(2000);
                }
                theApp.MyKLink1.DisConnect();;
                Sleep(1000);
                OnMenuNavConnect();
            }
        }
    }
}
void CNavView::OnRemoteBlinkLedAll()
{
    // TODO: 在此添加命令处理程序代码
    CString s1;
    int n = m_NavViewTree.GetSelectedCount();
    HTREEITEM hItem1 = nullptr;
    DWORD_PTR itemData = 0;
    if (n == 1) {
        hItem1 = m_NavViewTree.GetSelectedItem();
        itemData = m_NavViewTree.GetItemData(hItem1);
    }
    s1.Format(_T("Selected Count %d  Data %08X"), n, itemData);
    SysLog(s1);
    int nDst = 1;
    int nPort = 1;
    int nTime = 5;
    if (itemData & MENU_PORT) {
        int nChildId = 0xff;
        theApp.MyKLink1.RunRemoteReq(nDst, nPort, nChildId, ReqBlinkLED, nTime, 0, 0, 0);
        s1.Format(_T("Remote BlinkLED Port %d Child %d Timer %d"), nPort, nChildId, nTime);
        SysLog(s1);
    }
}
void CNavView::OnPortReset()
{
    // TODO: 在此添加命令处理程序代码
}
void CNavView::OnPortResetAllChild()
{
    // TODO: 在此添加命令处理程序代码
    CString s1;
    int n = m_NavViewTree.GetSelectedCount();
    HTREEITEM hItem1 = nullptr;
    DWORD_PTR itemData = 0;
    if (n == 1) {
        hItem1 = m_NavViewTree.GetSelectedItem();
        itemData = m_NavViewTree.GetItemData(hItem1);
    }
    s1.Format(_T("Selected Count %d  Data %08X"), n, itemData);
    SysLog(s1);
    int nDst = 1;
    int nPort = 1;
    int nTime = 5;
    if (itemData & MENU_PORT) {
        int nChildId =  0xff;
        theApp.MyKLink1.RunRemoteReq(nDst, nPort, nChildId, ReqReset, nTime, 0, 0, 0);
        s1.Format(_T("Remote Reset Port %d Child %d Timer %d"), nPort, nChildId, nTime);
        SysLog(s1);
    }
}
void CNavView::OnRemoteRefreshData()
{
    // TODO: 在此添加命令处理程序代码
    CString s1;
    int n = m_NavViewTree.GetSelectedCount();
    HTREEITEM hItem1 = nullptr;
    DWORD_PTR itemData =0;
    if (n == 1) {
        hItem1 = m_NavViewTree.GetSelectedItem();
        itemData = m_NavViewTree.GetItemData(hItem1);
    }
    s1.Format(_T("Selected Count %d  Data %08X"), n, itemData);
    SysLog(s1);
}
void CNavView::OnRemoteBlinkLED()
{
    // TODO: 在此添加命令处理程序代码
    CString s1;
    int n = m_NavViewTree.GetSelectedCount();
    HTREEITEM hItem1 = nullptr;
    DWORD_PTR itemData = 0;
    if (n == 1) {
        hItem1 = m_NavViewTree.GetSelectedItem();
        itemData = m_NavViewTree.GetItemData(hItem1);
    }
    s1.Format(_T("Selected Count %d  Data %08X"), n, itemData);
    SysLog(s1);
    int nDst = 1;
    int nPort = 1;
    int nTime = 5;
    if (itemData & MENU_REMOTE_DEVICE) {
        int nChildId = itemData & 0xff;
        theApp.MyKLink1.RunRemoteReq(nDst, nPort, nChildId, ReqBlinkLED, nTime, 0, 0, 0);
        s1.Format(_T("Remote BlinkLED Port %d Child %d Timer %d"), nPort, nChildId,nTime);
        SysLog(s1);
    }
}
void CNavView::OnRemoteDeviceReset()
{
    // TODO: 在此添加命令处理程序代码
    CString s1;
    int n = m_NavViewTree.GetSelectedCount();
    HTREEITEM hItem1 = nullptr;
    DWORD_PTR itemData = 0;
    if (n == 1) {
        hItem1 = m_NavViewTree.GetSelectedItem();
        itemData = m_NavViewTree.GetItemData(hItem1);
    }
    s1.Format(_T("Selected Count %d  Data %08X"), n, itemData);
    SysLog(s1);
    int nDst = 1;
    int nPort = 1;
    int nTime = 5;
    if (itemData & MENU_REMOTE_DEVICE) {
        int nChildId = itemData & 0xff;
        theApp.MyKLink1.RunRemoteReq(nDst, nPort, nChildId, ReqReset, nTime, 0, 0, 0);
        s1.Format(_T("Remote Reset Port %d Child %d Timer %d"), nPort, nChildId, nTime);
        SysLog(s1);
    }
}
void CNavView::OnRemoteUpdateFirmware()
{
    // TODO: 在此添加命令处理程序代码
    CString s1;
    int n = m_NavViewTree.GetSelectedCount();
    HTREEITEM hItem1 = nullptr;
    DWORD_PTR itemData = 0;
    if (n == 1) {
        hItem1 = m_NavViewTree.GetSelectedItem();
        itemData = m_NavViewTree.GetItemData(hItem1);
    }
    s1.Format(_T("Selected Count %d  Data %08X"), n, itemData);
    SysLog(s1);
    int nDst = 1;
    int nPort = 1;
    int nChildId = 0;
    if (itemData & MENU_REMOTE_DEVICE) {
        nChildId = itemData & 0xff;
    }
    else { return; }
//    CString s1;
    s1.Format(_T("更新远程设备 固件"));
    SysLog(s1);
    USHORT len1 = 0;
    USHORT buf1[1024];
    int r2 = 0;
    stDeviceInfo* ptheDeviceInfo =&PortDeviceInfos[nChildId];
    int res2 = theApp.MyKLink1.GetPortChildInfo(1, nPort, nChildId , sizeof(stDeviceInfo), &len1, buf1);  //sizeof(stDeviceInfo)
    if (res2 == KLink1::KL_OK) {
        s1.Format(_T("GetChildInfo %d %d = %d B\r\n"), nPort, nChildId , len1);
//        for (int k = 0; k < len1; k++) {
//            s1.AppendFormat(_T("%02X "), ((unsigned char*)buf1)[k]);
//        }
        SysLog(s1);
        stDeviceInfo* ptheInfo = (stDeviceInfo*)buf1;
//        PortDeviceInfos[nChildId] = *ptheInfo;
        s1.Format(_T("子%d (%04X)%s V%d.%02d %d/%d "),
            nChildId, ptheInfo->DeviceType, DeviceTypeToStr(ptheInfo->DeviceType), ptheInfo->DeviceVerMajor, ptheInfo->DeviceVerMinor, ptheInfo->InBitCount, ptheInfo->OutBitCount);
        SysLog(s1);
    }
    myLogger1.UpdateLogDisplay();
    unsigned char Appbuf[131072];
    unsigned char firmwarebuf[262144];
    int nBtldrInfoOffset = 256;
    int AppOffset = 4096;
    int nAppInfoOffset = 256;
    int btldrLength = 0;
    int AppLength = 0;
    int FirmwareSize = 0;
    bool btldrfileLoaded = false;
    bool appfileLoaded = false;
    bool combinefileSaved = false;
    unsigned char filebuf[65536];
    unsigned int blocksize = 32;
    stNewAppInfoBlock NewAppInfo;
    CFileDialog dialog1(true);
    INT_PTR r = dialog1.DoModal();
    if (r != IDOK) { return; }
    CString sFilePathName = dialog1.GetPathName();
    //OpenFile
    CFile file1;
    CFileException e;
    bool r3 = file1.Open(sFilePathName, CFile::modeRead | CFile::typeBinary, &e);
    s1.Format(_T("Open File %s = %d"), sFilePathName, r);
    DbgLog(s1);
    if (!r3) {
        return;
    }
    int fileLen2 = (int)file1.GetLength();
    file1.Read(filebuf, fileLen2);
    file1.Close();
    unsigned int nBlkType = 0;
    unsigned int nBlkVer = 0;
    s1.Empty();
    pAppInfoBlock pAppinfo = (pAppInfoBlock)(filebuf + nAppInfoOffset);
    s1.Format(_T("文件信息  \r\n"));
    //            SetDlgItemText(IDC_STATIC_APP_INFO, s1);
    if (pAppinfo->Hdr.nBlkSign == 0xaa55) {
        s1.Empty();
        s1.Format(_T("文件信息  "));
        // s1.AppendFormat(_T("启动文件 %s \r\n"), sFilePathName);
        s1.AppendFormat(_T("文件大小: %d \r\n"), fileLen2);
        s1.AppendFormat(_T("信息块位置: 0x%04X  信息块大小: %d  \r\n"), nAppInfoOffset, pAppinfo->Hdr.nBlkSize);
        s1.AppendFormat(_T("信息块类型: 0x%04X  "), pAppinfo->Hdr.nBlkTypeVer);
        nBlkType = (pAppinfo->Hdr.nBlkTypeVer) >> 8;
        nBlkVer = pAppinfo->Hdr.nBlkTypeVer & 0xff;
        if (nBlkType == 0x01) { s1.AppendFormat(_T(" (BootLoader 类型1 版本 %d) "), nBlkVer); }
        else if (nBlkType == 0x02) { s1.AppendFormat(_T(" (BootLoader 类型2 版本 %d) "), nBlkVer); }
        else if (nBlkType == 0x03) { s1.AppendFormat(_T(" (App类型1 版本 %d) "), nBlkVer); }
        else if (nBlkType == 0x04) { s1.AppendFormat(_T(" (App类型2 版本 %d) "), nBlkVer); }
        else { s1.AppendFormat(_T(" (未知类型)  ")); }
        s1.AppendFormat(_T("\r\n"));
        s1.AppendFormat(_T("应用区版本: 0x%04X  对应模块类型: 0x%04X\r\n"), pAppinfo->nAppVer, pAppinfo->nAppDevice);
        s1.AppendFormat(_T("应用区大小: 0x%04X  实际代码大小: 0x%04X \r\n"), pAppinfo->nAppSize, pAppinfo->nAppDataSize);
        s1.AppendFormat(_T("应用区地址: 0x%08X (偏移 %d )\r\n"), pAppinfo->nAppStartAddr, pAppinfo->nAppStartAddr - 0x08000000);
        s1.AppendFormat(_T("信息暂存区: 0x%08X \r\n应用暂存区: 0x%08X \r\n"), pAppinfo->nAppStartOffset, pAppinfo->nApp);
        //                SetDlgItemText(IDC_STATIC_APP_INFO, s1);
        if (nBlkType == 0x03 || nBlkType == 0x04) {
            memmove(Appbuf, filebuf, fileLen2);
            appfileLoaded = true;
            AppLength = fileLen2;
        }
        else {
            if ((nBlkType == 0x01 || nBlkType == 0x02) && fileLen2 >= AppOffset + nAppInfoOffset + sizeof(stAppInfoBlock))
            {
                pAppInfoBlock pAppinfo2 = (pAppInfoBlock)(filebuf + AppOffset + nAppInfoOffset);
                if ((pAppinfo2->Hdr.nBlkSign == 0xaa55) && pAppinfo2->Hdr.nBlkTypeVer == 0x0301) {
                    s1.Format(_T("文件是bootloader和App合成的文件 , 是否从中提取固件并继续"));
                    int r3 = AfxMessageBox(s1, MB_YESNO);
                    if (r3 == IDYES) {
                        memmove(Appbuf, filebuf + AppOffset, fileLen2 - AppOffset);
                        appfileLoaded = true;
                        AppLength = fileLen2 - AppOffset;
                    }
                }
                else {
                    s1.Format(_T("文件 不是App文件 , 是否继续 "));
                    int r3 = AfxMessageBox(s1, MB_YESNO);
                    if (r3 == IDYES) {
                        memmove(Appbuf, filebuf, fileLen2);
                        appfileLoaded = true;
                        AppLength = fileLen2;
                    }
                }
            }
            else {
                s1.Format(_T("文件 不是App文件 , 是否继续 "));
                int r3 = AfxMessageBox(s1, MB_YESNO);
                if (r3 == IDYES) {
                    memmove(Appbuf, filebuf, fileLen2);
                    appfileLoaded = true;
                    AppLength = fileLen2;
                }
            }
        }
        //            s1.Format(_T("  BootLoader启动文件  版本 %04X 硬件类型 %04X 占用空间 %04X,  %d Bytes\r\n 是否继续"), pinfob->nBtldrVer, pinfob->nBtldrDevice, pinfob->nBtldrSize, fileLen1);
    }
    else {
        s1.Format(_T("文件中未找到信息块, 文件大小  %d Bytes\r\n 是否继续"), fileLen2);
        int r3 = AfxMessageBox(s1, MB_YESNO);
        if (r3 == IDYES) {
            memmove(Appbuf, filebuf, fileLen2);
            appfileLoaded = true;
            AppLength = fileLen2;
        }
    }
    unsigned short crc2 = crc16tablefast(Appbuf, AppLength);
    unsigned char* buf2 = Appbuf + 0x1000; ;
    //s1.Format(_T("GetInfo From File  = %d %d \r\n"), j, fileLen1);
    pKMInfoBlock pinfof = (pKMInfoBlock)buf2;
    s1.Format(_T(" 目标模块 类型 %04X 版本 %d.%02d, \r\n 固件文件 类型 %04X 版本 %d.%02d,  %d Bytes\r\n 是否继续"),
        ptheDeviceInfo->DeviceType, ptheDeviceInfo->DeviceVerMajor,ptheDeviceInfo->DeviceVerMinor,
        pinfof->nDeviceTypeVer, pinfof->nProgVerMajor,pinfof->nProgVerMinor, fileLen2);
    int r4 = AfxMessageBox(s1, MB_YESNO);
    if (r4 != IDYES) { return; }
    {
        int bError = 0;
        for (int i = 0; i < AppLength; i += blocksize)
        {
            int sendsize = AppLength - i;
            if (sendsize > blocksize) { sendsize = blocksize; }
            int k = 999;
            int j = 0;
            double time1 = GetTimemS();
            for (j = 0; j < 5 && k != 0; j++) {
                k = theApp.MyKLink1.RunRemoteReq(nDst, nPort,nChildId, ReqUpdateFirm,0,i, sendsize, Appbuf + i);
                Sleep(10);
                if (k) {
                    double time2 = GetTimemS();
                    s1.Format(_T("Wr@ %x %dB = %d  re %d %.2fmS %s "), i, sendsize, k, j, time2 - time1, theApp.MyKLink1.m_resultStr);
                    SysLog(s1);
                    myLogger1.UpdateLogDisplay();
                    Sleep(30);
                }
            }
            double time2 = GetTimemS();
            s1.Format(_T("Wr@ %x %dB = %d  re %d %.2fmS"), i, sendsize, k, j, time2 - time1);
            SysLog(s1);
            myLogger1.UpdateLogDisplay();
            if (k) {   // 出现错误;
                bError = 1;
                CString sErr;
                sErr = KLink1::GetErrDescStr(k);
                s1.Format(_T("下载出错 %d, %s"), k, sErr);
                int r3 = AfxMessageBox(s1);
                break;  //跳出
            }
        }
        if (bError == 0) {
            NewAppInfo.Length = AppLength;
            NewAppInfo.Sign = 0x55AA;
            NewAppInfo.Version = 0x109;
            NewAppInfo.nCRC = crc2;
            int k = theApp.MyKLink1.RunRemoteReq(nDst, nPort, nChildId, ReqUpdateFirmInfo, 0, 0,sizeof(NewAppInfo), (UCHAR*)&NewAppInfo);
            s1.Format(_T("Write InfoBlock %d bytes = %d"), sizeof(NewAppInfo), k);
            SysLog(s1);
            Sleep(100);
            int r5 = theApp.MyKLink1.RunRemoteReq(nDst, nPort, nChildId, ReqReset, 0);
            s1.Format(_T("ResetRemoteDevice Port %d Child %d = %d"), nPort, nChildId, r5);
            SysLog(s1);
/*
            int r6 = theApp.MyKLink1.ResetDevice(nDst, 0);
            s1.Format(_T("ResetDevice  = %d"), r6);
            SysLog(s1);
            for (int i = 0; i < 8; i++) {
                bPortRegsUpdated[i] = 0;
            }
            for (int i = 0; i < 16; i++) {
                bPortDeviceUpdated[i] = 0;
            }
            myLogger1.UpdateLogDisplay();
*/
        //    Sleep(2000);
        }
    //    theApp.MyKLink1.DisConnect();;
    //    OnMenuNavConnect();
    }
}
MTerm1/NavView.h
@@ -2,6 +2,8 @@
#pragma once
#include "ViewTree.h"
#include "KMachine.h"
#include <vector>
class CNavToolBar : public CMFCToolBar
{
@@ -13,6 +15,91 @@
    virtual BOOL AllowShowOnList() const { return FALSE; }
};
#define MENU_DEVICE            0x10000000
#define MENU_PROPERTY        0x01000000
#define MENU_PORT            0x00100000
#define MENU_REMOTE_DEVICE    0x00010000
// #pragma anon_unions
typedef struct tagChnStat
{
    unsigned short Stat;
    unsigned short SendPackets;
    unsigned short RecvPackets;
    unsigned short LastSentTimeTick;
    unsigned short LostPackets;
    unsigned short CtnLstPkts;
    unsigned short MaxCtnLstPkts;
    unsigned short NotPkgErr;
    unsigned short PkgLenErr;
    unsigned short BCCErr;
    unsigned short TimeOutErr;
    unsigned short Delay;
    unsigned short MaxDelay;
    unsigned short SendTimeInterval;
    union
    {
        unsigned short ClientDatas[10];
        struct {
            unsigned short ClientRecvPkts;    //
            unsigned short ClientSendPkts;    //
            unsigned short ClientNotPktErr;    //
            unsigned short ClientMisIdPkts;    //
    //        unsigned int ClientNoEndErr;    //
            unsigned short ClientPkgLenErr;    //
            unsigned short ClientBccErr;        //
            unsigned short ClientTimeOutErr;    //
        };
    };
} stChnStat;
typedef struct tagKwChnStat
{
    union {
        unsigned char MStat;
        struct {
            unsigned char bOnline : 1;
            unsigned char bErr1 : 1;
            unsigned char bErr2 : 1;
            unsigned char bReq : 1;
        };
    };
    unsigned char SStat;
    uint32_t sentCount;                    //发送计数
    uint32_t recvCount;                    //接收计数
    uint32_t latancy;                        //延迟
    uint32_t cycleTime;                    //循环时间
    uint16_t LostPackets;                //丢包计数
    uint16_t CtnLstPkts;                //连续丢包计数
    uint16_t MaxCtnLstPkts;            //最大连续丢包计数
    uint16_t TXErr;                            //发送错误计数
    uint16_t RXErr;                            //接收错误计数
    uint16_t CRCErr;                         //CRC错误计数
    uint16_t PktErr;                        //包错误    ;
    uint16_t ChnErr;                        //频道错误;
    uint16_t nErrChn;                        //错误的频道号;
    uint16_t StepErr1;                    //步骤错误1
    uint16_t StepErr2;                    //步骤错误2
    uint16_t Err1Count;                    //微闪报警次数
    uint16_t Err2Count;                    //大闪报警次数
    uint16_t Err3Count;                    //严重丢失信号次数
    int8_t RSSI;                                //信号强度
    int8_t SNR;                                //信噪比
    int8_t tRSSI;                            //对方信号强度
    int8_t tSNR;                            //对方信噪比
    uint32_t targetSentCount;            //对方发送数量
    uint32_t targetRecvdCount;        //对方接受数量
} stKwChnStat;
class CNavView : public CDockablePane
{
public:
@@ -21,14 +108,26 @@
    void AdjustLayout();
    void OnChangeVisualStyle();
    stDeviceDef m_DeviceInfo = {0};
    stKMInfoBlock m_infoblock;
    int bPortRegsUpdated[8] = { 0 };
    stPortDef PortDefs[8];
    std::vector<stDeviceDef>  PortDeviceList[8];
    int bPortDeviceUpdated[16] = { 0 };
    stDeviceInfo PortDeviceInfos[16];
    int LastUpdateIndex[16] = { 0 };
protected:
    CNavToolBar m_wndToolBar;
    CViewTree m_NavViewTree;
//    HTREEITEM hRoot1;
    CImageList m_NavViewImages;
    UINT m_nCurrSort;
    void FillClassView();
    void FillDeviceView();
// 重写
public:
@@ -43,6 +142,9 @@
    afx_msg void OnClassDefinition();
    afx_msg void OnClassProperties();
    afx_msg void OnNewFolder();
    afx_msg void OnSetComm();
    afx_msg void OnConnect();
    afx_msg void OnDisConnect();
    afx_msg void OnPaint();
    afx_msg void OnSetFocus(CWnd* pOldWnd);
    afx_msg LRESULT OnChangeActiveTab(WPARAM, LPARAM);
@@ -56,5 +158,22 @@
    int DelayInit();
    int UpdateDisplay();
    int nDisplayCount = 0;
    afx_msg void OnMenuNavSetConn();
    afx_msg void OnMenuNavConnect();
    afx_msg void OnMenuNavDisconnect();
    int GetDocCount();
    afx_msg void OnMenuNvUpdateFirmware();
    afx_msg void OnMenuNvDeviceReadInfo();
    afx_msg void OnRemoteRefreshData();
    afx_msg void OnRemoteBlinkLED();
    afx_msg void OnRemoteUpdateFirmware();
    afx_msg void OnLedBlink();
    afx_msg void OnResetDevice();
    afx_msg void OnRemoteDeviceReset();
    afx_msg void OnRemoteBlinkLedAll();
    afx_msg void OnPortReset();
    afx_msg void OnPortResetAllChild();
    afx_msg void OnCommtest();
    afx_msg void OnDeviceConfig();
};
MTerm1/RCa14640
Binary files differ
MTerm1/RCb14640
Binary files differ
MTerm1/RCc14640
Binary files differ
MTerm1/RCd14640
Binary files differ
MTerm1/Resource.h
@@ -77,7 +77,14 @@
#define IDD_DIALOGBAR                   351
#define IDD_DIALOGBAR_INPUT_SHOW        351
#define IDD_PROP_OUTPUT_MAPPING         352
#define IDR_NAV_TOOLBAR                 352
#define IDD_FORM_INPUTSHOW              353
#define IDB_NAV_TOOLBAR_24              353
#define IDD_MTerm1BnlView               354
#define IDD_CONFIGTOOL_FORM             355
#define IDD_PROP_SYSREG2                356
#define IDR_POPUP_NAV                   359
#define IDD_DIALOG2                     360
#define IDC_EDIT1                       1000
#define IDC_BUTTON1                     1001
#define IDC_BUTTON_LOAD                 1001
@@ -89,11 +96,14 @@
#define IDC_COMBOBOXEX1                 1004
#define IDC_BUTTON_CONVERT              1004
#define IDC_EDIT_CAP_AIN_I              1004
#define IDC_BUTTON_UPLOAD               1004
#define IDC_EDIT_DISPLAY                1005
#define IDC_BUTTON4                     1005
#define IDC_BUTTON_DOWNLOAD             1005
#define IDC_COMBO_INPUT                 1006
#define IDC_BUTTON_TRNS_TOTXT           1006
#define IDC_EDIT_CAP_AOUT_I             1006
#define IDC_BUTTON_COMM_SET             1006
#define IDC_BUTTON_SEND                 1007
#define IDC_BUTTON_TRNS_PRG             1007
#define IDC_EDIT_CAP_AIN_E              1007
@@ -103,6 +113,7 @@
#define IDC_BUTTON_START                1009
#define IDC_RADIO_SET_OFF               1009
#define IDC_EDIT_CAP_HIN                1009
#define IDC_BUTTON_EVENTLOG             1009
#define IDC_COMBO_COMPORT               1010
#define IDC_STATIC_INFO2                1010
#define IDC_EDIT_CAP_HOUT               1010
@@ -203,12 +214,14 @@
#define IDC_COMBO_OUTPUT_SET_5          1040
#define IDC_CHECK_AUTO_CONN             1040
#define IDC_COMBO_INPUT_FILTER_12       1040
#define IDC_BUTTON_LOAD_SYSCFG_FILE     1040
#define IDC_COMBO_NETWORK_TYPE          1041
#define IDC_STATIC_OUTPUT_NAME_5        1041
#define IDC_BUTTON_CONN                 1041
#define IDC_BUTTON_WRITE_TO_PLC         1041
#define IDC_STATIC_INPUT_NAME_13        1041
#define IDC_EDIT_MON4                   1041
#define IDC_BUTTON_SAVE_SYSCFG_FILE     1041
#define IDC_COMBO_PORT                  1042
#define IDC_COMBO_OUTPUT_SET_6          1042
#define IDC_EDIT_DEVICE_TYPE            1042
@@ -226,6 +239,7 @@
#define IDC_STATIC_OUTPUT_NAME_7        1045
#define IDC_EDIT_LOT_NO                 1045
#define IDC_STATIC_INPUT_NAME_15        1045
#define IDC_BUTTON_TIME_NOW             1045
#define IDC_RADIO_DATA_LENGTH_8B        1046
#define IDC_COMBO_OUTPUT_SET_8          1046
#define IDC_EDIT_FACT_SN                1046
@@ -258,6 +272,7 @@
#define IDC_EDIT_ORG_FAC_DATE           1057
#define IDC_BUTTON31                    1057
#define IDC_BUTTON3                     1058
#define IDC_EDIT_ORG_FAC_DATE2          1058
#define IDC_LIST_STATUS1                1059
#define IDC_EDIT31                      1059
#define IDC_EDIT_CAP_COM                1059
@@ -282,9 +297,11 @@
#define IDC_STATIC_PROP                 1066
#define IDC_BUTTON_BACKSPACE            1066
#define IDC_COMBO_EOF_CHAR              1066
#define IDC_COMBO_BYTE_SIZE1            1066
#define IDC_SCROLLBAR1                  1067
#define IDC_BUTTON_0                    1067
#define IDC_COMBO_SOF_CHAR              1067
#define IDC_COMBO_PARITY1               1067
#define IDC_BUTTON_EQ                   1068
#define IDC_COMBO_END_TYPE              1068
#define IDC_BUTTON1_DOT                 1069
@@ -314,69 +331,121 @@
#define IDC_COMBO_WORKMODE              1077
#define IDC_BUTTON_CLEAR_STAT           1078
#define IDC_COMBO_STATION               1078
#define IDC_COMBO_STATION1              1078
#define IDC_PROGRESS1                   1079
#define IDC_EDIT_END_TIME               1079
#define IDC_EDIT_END_TIME1              1079
#define IDC_BUTTON_READ                 1080
#define IDC_STATIC_PIN_NAME_1           1080
#define IDC_EDIT_BUF_ADDR1              1080
#define IDC_STATIC_HINT                 1081
#define IDC_COMBO_FROM_COIL_TYPE_1      1081
#define IDC_EDIT_BUF_SIZE1              1081
#define IDC_BUTTON_CONNECT              1082
#define IDC_COMBO_FROM_COIL_ADDR_1      1082
#define IDC_COMBO_STOP_BIT1             1082
#define IDC_LIST_EVENTLOG               1083
#define IDC_BUTTON_DISCONNECT           1083
#define IDC_COMBO_FROM_COIL_TYPE_2      1083
#define IDC_COMBO4                      1083
#define IDC_COMBO_EOF_CHAR1             1083
#define IDC_EDIT_EVENT_COUNT            1084
#define IDC_COMBO_FROM_COIL_ADDR_2      1084
#define IDC_COMBO5                      1084
#define IDC_COMBO_SOF_CHAR1             1084
#define IDC_BUTTON_CLEAR_EVENTLOG       1085
#define IDC_STATIC_PIN_NAME_2           1085
#define IDC_COMBO6                      1085
#define IDC_COMBO_END_TYPE1             1085
#define IDC_BUTTON_RELOAD               1086
#define IDC_COMBO_FROM_COIL_TYPE_3      1086
#define IDC_COMBO_BAUDRATE1             1086
#define IDC_LIST_FORCE_IO               1087
#define IDC_COMBO_FROM_COIL_ADDR_3      1087
#define IDC_COMBO_WORKMODE3             1087
#define IDC_HOTKEY1                     1087
#define IDC_BUTTON_FREE                 1088
#define IDC_STATIC_PIN_NAME_3           1088
#define IDC_EDIT_END_TIME2              1088
#define IDC_EDIT9                       1088
#define IDC_BUTTON_RELEASE              1089
#define IDC_COMBO_FROM_COIL_TYPE_4      1089
#define IDC_COMBO_WORKMODE1             1089
#define IDC_EDIT10                      1089
#define IDC_BUTTON_EP_ADD               1090
#define IDC_COMBO_FROM_COIL_ADDR_4      1090
#define IDC_COMBO_WORKMODE2             1090
#define IDC_COMBO7                      1090
#define IDC_BUTTON_DELETE               1091
#define IDC_STATIC_PIN_NAME_4           1091
#define IDC_COMBO_STATION2              1091
#define IDC_COMBO8                      1091
#define IDC_BUTTON_HELP                 1092
#define IDC_COMBO_FROM_COIL_TYPE_5      1092
#define IDC_EDIT_BUF_ADDR2              1092
#define IDC_COMBO9                      1092
#define IDC_BUTTON_CLOSE                1093
#define IDC_COMBO_FROM_COIL_ADDR_5      1093
#define IDC_EDIT_BUF_SIZE2              1093
#define IDC_COMBO10                     1093
#define IDC_BUTTON_ON                   1094
#define IDC_STATIC_PIN_NAME_5           1094
#define IDC_COMBO_BYTE_SIZE2            1094
#define IDC_COMBO11                     1094
#define IDC_BUTTON_OFF                  1095
#define IDC_COMBO_FROM_COIL_TYPE_6      1095
#define IDC_COMBO_PARITY2               1095
#define IDC_COMBO12                     1095
#define IDC_STATIC_INFO                 1096
#define IDC_COMBO_FROM_COIL_ADDR_6      1096
#define IDC_COMBO_STOP_BIT2             1096
#define IDC_COMBO13                     1096
#define IDC_CHECK_SYSTIME               1097
#define IDC_STATIC_PIN_NAME_6           1097
#define IDC_COMBO_EOF_CHAR2             1097
#define IDC_COMBO14                     1097
#define IDC_BUTTON_SUBMIT               1098
#define IDC_COMBO_FROM_COIL_TYPE_7      1098
#define IDC_COMBO_SOF_CHAR2             1098
#define IDC_EDIT_YEAR                   1099
#define IDC_COMBO_FROM_COIL_ADDR_7      1099
#define IDC_COMBO_END_TYPE2             1099
#define IDC_EDIT_MONTH                  1100
#define IDC_STATIC_PIN_NAME_7           1100
#define IDC_COMBO_BAUDRATE2             1100
#define IDC_STATIC_CONNECT              1101
#define IDC_COMBO_FROM_COIL_TYPE_8      1101
#define IDC_COMBO_FROM_COIL_TYPE_00     1101
#define IDC_BUTTON11                    1102
#define IDC_COMBO_FROM_COIL_ADDR_8      1102
#define IDC_COMBO_FROM_COIL_ADDR_00     1102
#define IDC_BUTTON12                    1103
#define IDC_STATIC_PIN_NAME_8           1103
#define IDC_BUTTON13                    1104
#define IDC_COMBO_FROM_COIL_BIT_1       1104
#define IDC_COMBO_FROM_COIL_TYPE_01     1104
#define IDC_COMBO_FROM_COIL_BIT_2       1105
#define IDC_COMBO_FROM_COIL_ADDR_01     1105
#define IDC_COMBO_FROM_COIL_BIT_3       1106
#define IDC_COMBO_FROM_COIL_BIT_4       1107
#define IDC_COMBO_FROM_COIL_TYPE_02     1107
#define IDC_COMBO_FROM_COIL_BIT_5       1108
#define IDC_COMBO_FROM_COIL_ADDR_02     1108
#define IDC_COMBO_FROM_COIL_BIT_6       1109
#define IDC_COMBO_FROM_COIL_BIT_7       1110
#define IDC_COMBO_FROM_COIL_TYPE_03     1110
#define IDC_COMBO_FROM_COIL_BIT_8       1111
#define IDC_COMBO_FROM_COIL_ADDR_03     1111
#define IDC_COMBO_FROM_COIL_TYPE_04     1113
#define IDC_COMBO_FROM_COIL_ADDR_04     1114
#define IDC_COMBO_FROM_COIL_TYPE_05     1116
#define IDC_COMBO_FROM_COIL_ADDR_05     1117
#define IDC_COMBO_FROM_COIL_BIT_00      1125
#define IDC_COMBO_FROM_COIL_BIT_01      1126
#define IDC_COMBO_FROM_COIL_BIT_02      1127
#define IDC_COMBO_FROM_COIL_BIT_03      1128
#define IDC_COMBO_FROM_COIL_BIT_04      1129
#define IDC_COMBO_FROM_COIL_BIT_05      1130
#define IDC_CHECK_PAUSE                 1157
#define IDC_CHECK_NOSCROLL              1158
#define IDC_CHECK_PAUSEUPDATE           1161
@@ -443,10 +512,6 @@
#define ID_32829                        32829
#define ID_Menu32833                    32833
#define ID_32834                        32834
#define ID_32835                        32835
#define ID_32836                        32836
#define ID_32837                        32837
#define ID_32839                        32839
#define ID_32840                        32840
#define ID_32844                        32844
#define ID_32845                        32845
@@ -659,17 +724,71 @@
#define IDC_BUTTON_MC                   33110
#define IDC_BUTTON_MCE                  33111
#define IDC_BUTTON_E                    33183
#define ID_SORT                         33185
#define ID_SORT_33186                   33186
#define ID_SORT_33187                   33187
#define ID_SORT_33188                   33188
#define ID_SORT_33189                   33189
#define ID_33190                        33190
#define ID_33191                        33191
#define ID_33192                        33192
#define ID_33193                        33193
#define ID_33194                        33194
#define ID_33195                        33195
#define ID_MENU_CONNECT                 33196
#define ID_MENU_NAV_DISCONNECT          33197
#define ID_MENU_NAV_CONNECT             33198
#define ID_MENU_NAV_SET_CONN            33199
#define ID_MENU_NAV_CONN_STAT           33200
#define IDC_BUTTON_SET                  33201
#define ID_33201                        33201
#define IDC_BUTTON_RESET                33202
#define ID_33202                        33202
#define IDC_BUTTON_DF                   33203
#define ID_MENU_NV_UPDATE_FIRMWARE      33203
#define IDC_BUTTON_END                  33204
#define ID_MENU_NV_DEVICE_READ_INFO     33204
#define IDC_BUTTON_COMPARE              33205
#define ID_33205                        33205
#define IDC_BUTTON_PFUN                 33206
#define ID_33206                        33206
#define IDC_BUTTON_UPDOWN               33207
#define ID_33207                        33207
#define IDC_BUTTON_BIT                  33208
#define ID_33208                        33208
#define IDC_BUTTON_WORD                 33209
#define ID_33209                        33209
#define IDC_BUTTON_INSTRUCTION1         33210
#define ID_UPDATE_REMOTE_FIRMWARE       33210
#define IDC_BUTTON_INSTRUCTION2         33211
#define ID_REMOTE_BLINK                 33211
#define ID_REMOTE_REFRESH_DATA          33212
#define ID_33213                        33213
#define ID_33214                        33214
#define ID_NAV_CONNECT                  33215
#define ID_NAV_DISCONNECT               33216
#define ID_33217                        33217
#define ID_33218                        33218
#define ID_LED_BLINK                    33219
#define ID_33220                        33220
#define ID_33221                        33221
#define ID_33222                        33222
#define ID_33223                        33223
#define ID_PORT_RESET                   33224
#define ID_PORT_RESET_ALL_CHILD         33225
#define ID_PORT_ACTION                  33226
#define ID_33227                        33227
#define ID_REMOTE_DEVICE_RESET          33228
#define ID_REMOTE_UPDATE_FIRMWARE       33229
#define ID_RESET_DEVICE                 33230
#define ID_33231                        33231
#define ID_REMOTE_BLINK_LED_ALL         33232
#define ID_NAV_SETCOMM                  33233
#define ID_33234                        33234
#define ID_COMMTEST                     33235
#define ID_33236                        33236
#define ID_33237                        33237
#define ID_DEVICE_CONFIG                33238
#define IDC_BUTTON_PGCONVERT            33301
#define IDC_BUTTON_ONLINE               33302
#define IDC_BUTTON_OFFLINE              33303
@@ -703,9 +822,9 @@
// 
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE        359
#define _APS_NEXT_COMMAND_VALUE         33185
#define _APS_NEXT_CONTROL_VALUE         1087
#define _APS_NEXT_RESOURCE_VALUE        363
#define _APS_NEXT_COMMAND_VALUE         33239
#define _APS_NEXT_CONTROL_VALUE         1098
#define _APS_NEXT_SYMED_VALUE           319
#endif
#endif
MTerm1/res/sort.bmp

MTerm1/res/sort1.bmp
MTerm1/res/sort_25.bmp
MTerm2/NavView.cpp
@@ -113,7 +113,7 @@
    }
    // 填入一些静态树视图数据(此处只需填入虚拟代码,而不是复杂的数据)
    FillClassView();
    FillDeviceView();
    return 0;
}
@@ -124,7 +124,7 @@
    AdjustLayout();
}
void CNavView::FillClassView()
void CNavView::FillDeviceView()
{
    HTREEITEM hRoot1 = m_wndNavView.InsertItem(_T("连接状态"), 0, 0);
    m_wndNavView.SetItemState(hRoot1, TVIS_BOLD, TVIS_BOLD);
MTerm2/NavView.h
@@ -28,7 +28,7 @@
    CImageList m_NavViewImages;
    UINT m_nCurrSort;
    void FillClassView();
    void FillDeviceView();
// 重写
public:
MultiTerminal1/MultiTerminal1.vcxproj
@@ -44,7 +44,7 @@
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
    <ConfigurationType>Application</ConfigurationType>
    <UseDebugLibraries>true</UseDebugLibraries>
    <PlatformToolset>v143</PlatformToolset>
    <PlatformToolset>v142</PlatformToolset>
    <CharacterSet>Unicode</CharacterSet>
    <UseOfMfc>Dynamic</UseOfMfc>
  </PropertyGroup>
@@ -117,6 +117,7 @@
      <SDLCheck>true</SDLCheck>
      <PreprocessorDefinitions>_WINDOWS;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
      <LanguageStandard_C>stdc11</LanguageStandard_C>
    </ClCompile>
    <Link>
      <SubSystem>Windows</SubSystem>
MyLib/LOGGER/Logger.hpp
@@ -531,6 +531,7 @@
            {
                m_pLogWnd->LineScroll(line1-line2);
            }
            m_pLogWnd->UpdateWindow();
        }else if (IsLogWndAttached==2 && m_pRichLogWnd && IsWindow(m_pRichLogWnd->m_hWnd))
        {
            if (LogTextLength[channel]>2000000)
@@ -562,7 +563,9 @@
            {
                m_pRichLogWnd->LineScroll(line1-line2);
            }
            m_pRichLogWnd->PostMessage(WM_VSCROLL, SB_BOTTOM, 0);
        //    m_pRichLogWnd->PostMessage(WM_VSCROLL, SB_BOTTOM, 0);
            m_pRichLogWnd->SendMessage(WM_VSCROLL, SB_BOTTOM, 0);
            m_pRichLogWnd->UpdateWindow();
        }
        strChangedLog[channel].Empty();
MyLib/MHashINI/MHash.hpp
@@ -164,16 +164,16 @@
    Hashelement OverFlow;
public:
    Hash::~Hash()
    ~Hash()
    {
    }
    Hash::Hash(void)
    Hash(void)
    {
        TotalKey=0;
        OverFlow = _T("OverFlow");
    };
    Hash::Hash(CString thisName)
    Hash(CString thisName)
    {
        TotalKey=0;
        this->Name=thisName;
@@ -237,12 +237,12 @@
        if (index == -1) return false;
        else return true;
    }
    Hashelement & Hash::operator [] (const char * str)
    Hashelement & operator [] (const char * str)
    {
        CString s1(str);
        return this->operator [] (s1);
    };
    Hashelement & Hash::operator [] (CString s)
    Hashelement & operator [] (CString s)
    {
        int left = 0;
        int right = TotalKey - 1;
@@ -287,7 +287,7 @@
        return elements[index];
    };
    Hashelement & Hash::operator [] (int k)
    Hashelement & operator [] (int k)
    {
        return elements[k];
    };
@@ -439,7 +439,7 @@
        }
        return nCount;
    }
    int Hash::SaveToFile(CString FilePathName,CString Section)
    int SaveToFile(CString FilePathName,CString Section)
    {
        int i;
        CString Key,Value;
@@ -457,7 +457,7 @@
        return 1;
    };
    int Hash::LoadFromFile(CString FilePathName,CString Section)
    int LoadFromFile(CString FilePathName,CString Section)
    {
        CString Key;
        CString value,value1,value2;
@@ -820,7 +820,7 @@
    for (int i=0; i<h2.TotalKey; ++i)
    {
        CString key = *(h2.elements[i].Key);
        CString value1 = h1[key];
        CString value1 = *(h1[key].Value);
        CString value2 = *(h2.elements[i].Value);
        if (value1.GetLength()>256 || value2.GetLength()>256)
        {