From 0a20f73829d9d53e060927f23c2777f10347ac65 Mon Sep 17 00:00:00 2001
From: QuakeGod <QuakeGod@sina.com>
Date: 星期三, 29 十二月 2021 13:43:59 +0800
Subject: [PATCH] add Klink Dll project

---
 MTerm2/MTerm2CommDevView.cpp  |   26 
 MTerm2/MTerm2CtrlView.cpp     |    3 
 MTerm2/MTerm2.cpp             |    3 
 KLink2/pch.cpp                |    5 
 KLink1/KLink1.vcxproj         |  182 +++
 MTerm2/MTerm2Doc.cpp          |   26 
 MTerm1.sln                    |   20 
 KLink1/KLink1.h               |   22 
 KLink1/framework.h            |    5 
 MTerm2/MTerm2View.h           |   40 
 MTerm2/MTerm2Doc.h            |   12 
 KLink2/CDialogCommSet1.cpp    |  214 ++++
 MTerm2/MTerm2.vcxproj         |    1 
 KLink2/framework.h            |   36 
 KLink1/pch.h                  |   13 
 KLink2/KLink2.cpp             |  101 +
 KLink2/KLink2.vcxproj.filters |   67 +
 KLink1/dllmain.cpp            |   19 
 KLink2/KLink2.h               |   29 
 KLink2/Resource.h             |   34 
 KLink2/targetver.h            |    8 
 KLink2/CDialogCommSet1.h      |   38 
 KLink2/res/KLink2.rc2         |    0 
 MTerm2/MTerm2View.cpp         |  123 ++
 KLink1/KLink1.vcxproj.filters |   42 
 KLink2/KLink2.vcxproj         |  220 ++++
 KLink2/pch.h                  |   13 
 KLink2/KLink.cpp              |  928 +++++++++++++++++
 KLink2/KDefine.h              |  270 +++++
 KLink1/pch.cpp                |    5 
 KLink2/KLink.h                |  643 ++++++++++++
 KLink1/cpp.hint               |    2 
 KLink2/KLink2.def             |    7 
 KLink1/KLink1.cpp             |   22 
 KLink2/KLink2.rc              |    0 
 35 files changed, 3,138 insertions(+), 41 deletions(-)

diff --git a/KLink1/KLink1.cpp b/KLink1/KLink1.cpp
new file mode 100644
index 0000000..6261ba7
--- /dev/null
+++ b/KLink1/KLink1.cpp
@@ -0,0 +1,22 @@
+锘�// KLink1.cpp : 瀹氫箟 DLL 鐨勫鍑哄嚱鏁般��
+//
+
+#include "pch.h"
+#include "framework.h"
+#include "KLink1.h"
+
+
+// 杩欐槸瀵煎嚭鍙橀噺鐨勪竴涓ず渚�
+KLINK1_API int nKLink1=0;
+
+// 杩欐槸瀵煎嚭鍑芥暟鐨勪竴涓ず渚嬨��
+KLINK1_API int fnKLink1(void)
+{
+    return 0;
+}
+
+// 杩欐槸宸插鍑虹被鐨勬瀯閫犲嚱鏁般��
+CKLink1::CKLink1()
+{
+    return;
+}
diff --git a/KLink1/KLink1.h b/KLink1/KLink1.h
new file mode 100644
index 0000000..2520438
--- /dev/null
+++ b/KLink1/KLink1.h
@@ -0,0 +1,22 @@
+锘�// 涓嬪垪 ifdef 鍧楁槸鍒涘缓浣夸粠 DLL 瀵煎嚭鏇寸畝鍗曠殑
+// 瀹忕殑鏍囧噯鏂规硶銆傛 DLL 涓殑鎵�鏈夋枃浠堕兘鏄敤鍛戒护琛屼笂瀹氫箟鐨� KLINK1_EXPORTS
+// 绗﹀彿缂栬瘧鐨勩�傚湪浣跨敤姝� DLL 鐨�
+// 浠讳綍椤圭洰涓婁笉搴斿畾涔夋绗﹀彿銆傝繖鏍凤紝婧愭枃浠朵腑鍖呭惈姝ゆ枃浠剁殑浠讳綍鍏朵粬椤圭洰閮戒細灏�
+// KLINK1_API 鍑芥暟瑙嗕负鏄粠 DLL 瀵煎叆鐨勶紝鑰屾 DLL 鍒欏皢鐢ㄦ瀹忓畾涔夌殑
+// 绗﹀彿瑙嗕负鏄瀵煎嚭鐨勩��
+#ifdef KLINK1_EXPORTS
+#define KLINK1_API __declspec(dllexport)
+#else
+#define KLINK1_API __declspec(dllimport)
+#endif
+
+// 姝ょ被鏄粠 dll 瀵煎嚭鐨�
+class KLINK1_API CKLink1 {
+public:
+	CKLink1(void);
+	// TODO: 鍦ㄦ澶勬坊鍔犳柟娉曘��
+};
+
+extern KLINK1_API int nKLink1;
+
+KLINK1_API int fnKLink1(void);
diff --git a/KLink1/KLink1.vcxproj b/KLink1/KLink1.vcxproj
new file mode 100644
index 0000000..455bf57
--- /dev/null
+++ b/KLink1/KLink1.vcxproj
@@ -0,0 +1,182 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="15.0" 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>15.0</VCProjectVersion>
+    <ProjectGuid>{A9132770-20D8-423A-8F25-4B5F5B4459D3}</ProjectGuid>
+    <Keyword>Win32Proj</Keyword>
+    <RootNamespace>KLink1</RootNamespace>
+    <WindowsTargetPlatformVersion>10.0.17763.0</WindowsTargetPlatformVersion>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
+    <ConfigurationType>DynamicLibrary</ConfigurationType>
+    <UseDebugLibraries>true</UseDebugLibraries>
+    <PlatformToolset>v141</PlatformToolset>
+    <CharacterSet>Unicode</CharacterSet>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+    <ConfigurationType>DynamicLibrary</ConfigurationType>
+    <UseDebugLibraries>false</UseDebugLibraries>
+    <PlatformToolset>v141</PlatformToolset>
+    <WholeProgramOptimization>true</WholeProgramOptimization>
+    <CharacterSet>Unicode</CharacterSet>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
+    <ConfigurationType>DynamicLibrary</ConfigurationType>
+    <UseDebugLibraries>true</UseDebugLibraries>
+    <PlatformToolset>v141</PlatformToolset>
+    <CharacterSet>Unicode</CharacterSet>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
+    <ConfigurationType>DynamicLibrary</ConfigurationType>
+    <UseDebugLibraries>false</UseDebugLibraries>
+    <PlatformToolset>v141</PlatformToolset>
+    <WholeProgramOptimization>true</WholeProgramOptimization>
+    <CharacterSet>Unicode</CharacterSet>
+  </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'">
+    <TargetName>KLINK1</TargetName>
+    <LinkIncremental>true</LinkIncremental>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <TargetName>KLINK1</TargetName>
+    <LinkIncremental>true</LinkIncremental>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <TargetName>KLINK1</TargetName>
+    <LinkIncremental>false</LinkIncremental>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+    <TargetName>KLINK1</TargetName>
+    <LinkIncremental>false</LinkIncremental>
+  </PropertyGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+    <ClCompile>
+      <PrecompiledHeader>Use</PrecompiledHeader>
+      <WarningLevel>Level3</WarningLevel>
+      <Optimization>Disabled</Optimization>
+      <SDLCheck>true</SDLCheck>
+      <PreprocessorDefinitions>_DEBUG;KLINK1_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <ConformanceMode>true</ConformanceMode>
+      <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
+    </ClCompile>
+    <Link>
+      <SubSystem>Windows</SubSystem>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <EnableUAC>false</EnableUAC>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <ClCompile>
+      <PrecompiledHeader>Use</PrecompiledHeader>
+      <WarningLevel>Level3</WarningLevel>
+      <Optimization>Disabled</Optimization>
+      <SDLCheck>true</SDLCheck>
+      <PreprocessorDefinitions>WIN32;_DEBUG;KLINK1_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <ConformanceMode>true</ConformanceMode>
+      <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
+    </ClCompile>
+    <Link>
+      <SubSystem>Windows</SubSystem>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <EnableUAC>false</EnableUAC>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <ClCompile>
+      <PrecompiledHeader>Use</PrecompiledHeader>
+      <WarningLevel>Level3</WarningLevel>
+      <Optimization>MaxSpeed</Optimization>
+      <FunctionLevelLinking>true</FunctionLevelLinking>
+      <IntrinsicFunctions>true</IntrinsicFunctions>
+      <SDLCheck>true</SDLCheck>
+      <PreprocessorDefinitions>WIN32;NDEBUG;KLINK1_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <ConformanceMode>true</ConformanceMode>
+      <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
+    </ClCompile>
+    <Link>
+      <SubSystem>Windows</SubSystem>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
+      <OptimizeReferences>true</OptimizeReferences>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <EnableUAC>false</EnableUAC>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+    <ClCompile>
+      <PrecompiledHeader>Use</PrecompiledHeader>
+      <WarningLevel>Level3</WarningLevel>
+      <Optimization>MaxSpeed</Optimization>
+      <FunctionLevelLinking>true</FunctionLevelLinking>
+      <IntrinsicFunctions>true</IntrinsicFunctions>
+      <SDLCheck>true</SDLCheck>
+      <PreprocessorDefinitions>NDEBUG;KLINK1_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <ConformanceMode>true</ConformanceMode>
+      <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
+    </ClCompile>
+    <Link>
+      <SubSystem>Windows</SubSystem>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
+      <OptimizeReferences>true</OptimizeReferences>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <EnableUAC>false</EnableUAC>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemGroup>
+    <None Include="cpp.hint" />
+  </ItemGroup>
+  <ItemGroup>
+    <ClInclude Include="framework.h" />
+    <ClInclude Include="KLink1.h" />
+    <ClInclude Include="pch.h" />
+  </ItemGroup>
+  <ItemGroup>
+    <ClCompile Include="dllmain.cpp" />
+    <ClCompile Include="KLink1.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>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+  <ImportGroup Label="ExtensionTargets">
+  </ImportGroup>
+</Project>
\ No newline at end of file
diff --git a/KLink1/KLink1.vcxproj.filters b/KLink1/KLink1.vcxproj.filters
new file mode 100644
index 0000000..e1bc292
--- /dev/null
+++ b/KLink1/KLink1.vcxproj.filters
@@ -0,0 +1,42 @@
+锘�<?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;def;odl;idl;hpj;bat;asm;asmx</Extensions>
+    </Filter>
+    <Filter Include="澶存枃浠�">
+      <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
+      <Extensions>h;hh;hpp;hxx;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>
+    <None Include="cpp.hint" />
+  </ItemGroup>
+  <ItemGroup>
+    <ClInclude Include="framework.h">
+      <Filter>澶存枃浠�</Filter>
+    </ClInclude>
+    <ClInclude Include="KLink1.h">
+      <Filter>澶存枃浠�</Filter>
+    </ClInclude>
+    <ClInclude Include="pch.h">
+      <Filter>澶存枃浠�</Filter>
+    </ClInclude>
+  </ItemGroup>
+  <ItemGroup>
+    <ClCompile Include="KLink1.cpp">
+      <Filter>婧愭枃浠�</Filter>
+    </ClCompile>
+    <ClCompile Include="dllmain.cpp">
+      <Filter>婧愭枃浠�</Filter>
+    </ClCompile>
+    <ClCompile Include="pch.cpp">
+      <Filter>婧愭枃浠�</Filter>
+    </ClCompile>
+  </ItemGroup>
+</Project>
\ No newline at end of file
diff --git a/KLink1/cpp.hint b/KLink1/cpp.hint
new file mode 100644
index 0000000..b6e3576
--- /dev/null
+++ b/KLink1/cpp.hint
@@ -0,0 +1,2 @@
+#define KLINK1_API __declspec(dllexport)
+#define KLINK1_API __declspec(dllimport)
diff --git a/KLink1/dllmain.cpp b/KLink1/dllmain.cpp
new file mode 100644
index 0000000..d37928e
--- /dev/null
+++ b/KLink1/dllmain.cpp
@@ -0,0 +1,19 @@
+锘�// dllmain.cpp : 瀹氫箟 DLL 搴旂敤绋嬪簭鐨勫叆鍙g偣銆�
+#include "pch.h"
+
+BOOL APIENTRY DllMain( HMODULE hModule,
+                       DWORD  ul_reason_for_call,
+                       LPVOID lpReserved
+                     )
+{
+    switch (ul_reason_for_call)
+    {
+    case DLL_PROCESS_ATTACH:
+    case DLL_THREAD_ATTACH:
+    case DLL_THREAD_DETACH:
+    case DLL_PROCESS_DETACH:
+        break;
+    }
+    return TRUE;
+}
+
diff --git a/KLink1/framework.h b/KLink1/framework.h
new file mode 100644
index 0000000..3f0fc4a
--- /dev/null
+++ b/KLink1/framework.h
@@ -0,0 +1,5 @@
+锘�#pragma once
+
+#define WIN32_LEAN_AND_MEAN             // 浠� Windows 澶存枃浠朵腑鎺掗櫎鏋佸皯浣跨敤鐨勫唴瀹�
+// Windows 澶存枃浠�
+#include <windows.h>
diff --git a/KLink1/pch.cpp b/KLink1/pch.cpp
new file mode 100644
index 0000000..db1a479
--- /dev/null
+++ b/KLink1/pch.cpp
@@ -0,0 +1,5 @@
+锘�// pch.cpp: 涓庨缂栬瘧鏍囧ご瀵瑰簲鐨勬簮鏂囦欢
+
+#include "pch.h"
+
+// 褰撲娇鐢ㄩ缂栬瘧鐨勫ご鏃讹紝闇�瑕佷娇鐢ㄦ婧愭枃浠讹紝缂栬瘧鎵嶈兘鎴愬姛銆�
diff --git a/KLink1/pch.h b/KLink1/pch.h
new file mode 100644
index 0000000..aa4549e
--- /dev/null
+++ b/KLink1/pch.h
@@ -0,0 +1,13 @@
+锘�// pch.h: 杩欐槸棰勭紪璇戞爣澶存枃浠躲��
+// 涓嬫柟鍒楀嚭鐨勬枃浠朵粎缂栬瘧涓�娆★紝鎻愰珮浜嗗皢鏉ョ敓鎴愮殑鐢熸垚鎬ц兘銆�
+// 杩欒繕灏嗗奖鍝� IntelliSense 鎬ц兘锛屽寘鎷唬鐮佸畬鎴愬拰璁稿浠g爜娴忚鍔熻兘銆�
+// 浣嗘槸锛屽鏋滄澶勫垪鍑虹殑鏂囦欢涓殑浠讳綍涓�涓湪鐢熸垚涔嬮棿鏈夋洿鏂帮紝瀹冧滑鍏ㄩ儴閮藉皢琚噸鏂扮紪璇戙��
+// 璇峰嬁鍦ㄦ澶勬坊鍔犺棰戠箒鏇存柊鐨勬枃浠讹紝杩欏皢浣垮緱鎬ц兘浼樺娍鏃犳晥銆�
+
+#ifndef PCH_H
+#define PCH_H
+
+// 娣诲姞瑕佸湪姝ゅ棰勭紪璇戠殑鏍囧ご
+#include "framework.h"
+
+#endif //PCH_H
diff --git a/KLink2/CDialogCommSet1.cpp b/KLink2/CDialogCommSet1.cpp
new file mode 100644
index 0000000..1a9b47d
--- /dev/null
+++ b/KLink2/CDialogCommSet1.cpp
@@ -0,0 +1,214 @@
+锘�// CDialogCommSet1.cpp: 瀹炵幇鏂囦欢
+//
+
+#include "pch.h"
+#include "KLink2.h"
+#include "afxdialogex.h"
+#include <devguid.h>
+#include <SetupAPI.h>
+#include <Dbt.h>
+#include "CDialogCommSet1.h"
+
+#include <devguid.h>
+#include <SetupAPI.h>
+
+#pragma comment(lib,"SetupAPI.lib")
+
+// CDialogCommSet1 瀵硅瘽妗�
+
+IMPLEMENT_DYNAMIC(CDialogCommSet1, CDialogEx)
+
+CDialogCommSet1::CDialogCommSet1(CWnd* pParent /*=nullptr*/)
+	: CDialogEx(IDD_DIALOG_COMMSET1, pParent)
+{
+
+}
+
+CDialogCommSet1::~CDialogCommSet1()
+{
+}
+
+void CDialogCommSet1::DoDataExchange(CDataExchange* pDX)
+{
+	CDialogEx::DoDataExchange(pDX);
+	DDX_Control(pDX, IDC_COMBO_PORT, m_combo_comport);
+}
+
+
+BEGIN_MESSAGE_MAP(CDialogCommSet1, CDialogEx)
+	
+	ON_WM_DEVICECHANGE()
+
+	ON_BN_CLICKED(IDOK, &CDialogCommSet1::OnBnClickedOk)
+	ON_BN_CLICKED(IDC_BUTTON_INIT, &CDialogCommSet1::OnBnClickedButtonInit)
+END_MESSAGE_MAP()
+
+
+
+// CDialogCommSet1 娑堟伅澶勭悊绋嬪簭
+
+BOOL CDialogCommSet1::OnInitDialog()
+{
+	CDialogEx::OnInitDialog();
+
+	// TODO:  鍦ㄦ娣诲姞棰濆鐨勫垵濮嬪寲
+	ShowParams();
+	return TRUE;  // return TRUE unless you set the focus to a control
+				  // 寮傚父: OCX 灞炴�ч〉搴旇繑鍥� FALSE
+}
+
+//寰楀埌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;//鎴愬姛鎵惧埌浜咰OMx鐨勫悕瀛�
+			//}
+		}
+	}
+	return res;
+}
+
+int CDialogCommSet1::UpdateComPortList()
+{
+	// TODO: 鍦ㄦ澶勬坊鍔犲疄鐜颁唬鐮�.
+	CString s1, s2;
+	
+	m_combo_comport.ResetContent();
+	for (int i = 1; i <= 16; i++)
+	{
+		s1.Format(_T("COM%d"), i);
+		if (get_com_name(s1, s2)) s1 = s2;
+		m_combo_comport.AddString(s1);
+	}
+	sComSelStr = _T("COM3");
+	m_combo_comport.SelectString(0, sComSelStr);
+	m_combo_comport.SetCurSel(2);
+	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_comport.ResetContent();
+		while (true)
+		{
+			dwLong = dwSize = 256;
+			if (RegEnumValue(hKey, nCount, szPortName, &dwLong, NULL, NULL, (PUCHAR)szComName, &dwSize) == ERROR_NO_MORE_ITEMS)
+				break;
+
+			m_combo_comport.InsertString(nCount, szComName);
+			nCount++;
+		}
+		RegCloseKey(hKey);
+		m_combo_comport.SetCurSel(0);
+	}
+
+	return 0;
+}
+
+BOOL CDialogCommSet1::OnDeviceChange(UINT nEventType, DWORD_PTR dwData)
+{
+	if (nEventType == DBT_DEVNODES_CHANGED)
+		UpdateComPortList();
+
+	return  TRUE;
+}
+
+int CDialogCommSet1::DisplayParams()
+{
+	// TODO: 鍦ㄦ澶勬坊鍔犲疄鐜颁唬鐮�.
+	return 0;
+}
+
+int CDialogCommSet1::ShowParams()
+{
+	// TODO: 鍦ㄦ澶勬坊鍔犲疄鐜颁唬鐮�.
+	((CComboBox *)GetDlgItem(IDC_COMBO_NETWORK_TYPE))->SetCurSel(0);
+	((CComboBox *)GetDlgItem(IDC_COMBO_PORT))->SetCurSel(0);
+	((CComboBox *)GetDlgItem(IDC_COMBO_BAUD))->SetCurSel(8);
+
+	((CButton *)GetDlgItem(IDC_RADIO_DATA_LENGTH_8B))->SetCheck(1);
+
+	((CButton *)GetDlgItem(IDC_RADIO_STOP_1B))->SetCheck(1);
+
+	((CButton *)GetDlgItem(IDC_RADIO_PARITY_NONE))->SetCheck(1);
+
+	((CComboBox *)GetDlgItem(IDC_COMBO_COMM_TIMEOUT))->SetCurSel(5);
+	((CButton *)GetDlgItem(IDC_CHECK_AUTO_BAUD))->SetCheck(1);
+	((CButton *)GetDlgItem(IDC_CHECK_AUTO_DATA_LENGTH))->SetCheck(1);
+	((CButton *)GetDlgItem(IDC_CHECK_AUTO_PARITY))->SetCheck(1);
+
+	UpdateComPortList();
+	return 0;
+}
+
+int CDialogCommSet1::GetParams()
+{
+	// TODO: 鍦ㄦ澶勬坊鍔犲疄鐜颁唬鐮�.
+	((CComboBox *)GetDlgItem(IDC_COMBO_NETWORK_TYPE))->GetCurSel();
+	m_nComNum = ((CComboBox *)GetDlgItem(IDC_COMBO_PORT))->GetCurSel() + 1;
+	//((CComboBox *)GetDlgItem(IDC_COMBO_BAUD))->GetCurSel();
+	CString baudstr;
+	GetDlgItemText(IDC_COMBO_BAUD, baudstr);
+	m_nBaudRate = _tstoi(baudstr);
+	m_Settings = "8,N,1";
+
+	((CButton *)GetDlgItem(IDC_RADIO_DATA_LENGTH_8B))->GetCheck();
+
+	((CButton *)GetDlgItem(IDC_RADIO_STOP_1B))->GetCheck();
+
+	((CButton *)GetDlgItem(IDC_RADIO_PARITY_NONE))->GetCheck();
+
+	((CComboBox *)GetDlgItem(IDC_COMBO_COMM_TIMEOUT))->GetCurSel();
+	((CButton *)GetDlgItem(IDC_CHECK_AUTO_BAUD))->GetCheck();
+	((CButton *)GetDlgItem(IDC_CHECK_AUTO_DATA_LENGTH))->GetCheck();
+	((CButton *)GetDlgItem(IDC_CHECK_AUTO_PARITY))->GetCheck();
+
+	return 0;
+}
+
+void CDialogCommSet1::OnOK()
+{
+	// TODO: 鍦ㄦ娣诲姞涓撶敤浠g爜鍜�/鎴栬皟鐢ㄥ熀绫�
+	GetParams();
+	CDialogEx::OnOK();
+}
+
+void CDialogCommSet1::OnBnClickedOk()
+{
+	// TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
+	GetParams();
+	CDialogEx::OnOK();
+}
+
+void CDialogCommSet1::OnBnClickedButtonInit()
+{
+	// TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
+}
+
diff --git a/KLink2/CDialogCommSet1.h b/KLink2/CDialogCommSet1.h
new file mode 100644
index 0000000..abd8f1a
--- /dev/null
+++ b/KLink2/CDialogCommSet1.h
@@ -0,0 +1,38 @@
+锘�#pragma once
+
+
+// CDialogCommSet1 瀵硅瘽妗�
+
+class CDialogCommSet1 : public CDialogEx
+{
+	DECLARE_DYNAMIC(CDialogCommSet1)
+
+public:
+	CDialogCommSet1(CWnd* pParent = nullptr);   // 鏍囧噯鏋勯�犲嚱鏁�
+	virtual ~CDialogCommSet1();
+
+// 瀵硅瘽妗嗘暟鎹�
+#ifdef AFX_DESIGN_TIME
+	enum { IDD = IDD_DIALOG_COMMSET1 };
+#endif
+
+protected:
+	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV 鏀寔
+	DECLARE_MESSAGE_MAP()
+	afx_msg BOOL OnDeviceChange(UINT nEventType, DWORD_PTR dwData);
+public:
+	virtual BOOL OnInitDialog();
+	virtual void OnOK();
+	int DisplayParams();
+	int GetParams();
+	int ShowParams();
+	int UpdateComPortList();
+	CComboBox m_combo_comport;
+	CString sComSelStr;
+	int m_nComNum;
+	int m_nBaudRate;
+	CStringA m_Settings;
+
+	afx_msg void OnBnClickedOk();
+	afx_msg void OnBnClickedButtonInit();
+};
diff --git a/KLink2/KDefine.h b/KLink2/KDefine.h
new file mode 100644
index 0000000..9d5faa1
--- /dev/null
+++ b/KLink2/KDefine.h
@@ -0,0 +1,270 @@
+/*
+
+
+
+
+*/
+#pragma once
+
+#define TYPECOIL 0x00
+#define TYPEDATA 0x80
+
+#define TOTAL_WDFS (16)		//Total DF Count
+#define TOTAL_CurVAL (16)		//
+
+//extern unsigned short X[256];
+//extern unsigned short Y[256];
+//extern unsigned short R[256];
+
+#define TOTALTIMERS (64)
+#define TICK_OF_MS (10)		//1ms
+#define TICK_OF_RS (100)		//10mS
+#define TICK_OF_XS (1000)			//100mS
+#define TICK_OF_YS (10000)		//1S
+
+
+enum enKLCoilTypes
+{
+	KLCoilTypeX = 0 | TYPECOIL,		//X Input
+	KLCoilTypeY = 1 | TYPECOIL,		//Y Output
+	KLCoilTypeR = 2 | TYPECOIL,		//R register
+	KLCoilTypeLX = 3 | TYPECOIL,		//Link register
+	KLCoilTypeLY = 4 | TYPECOIL,		//Link register
+	KLCoilTypeT = 5 | TYPECOIL,		//Timer
+	KLCoilTypeC = 6 | TYPECOIL,		//Counter
+	KLCoilTypeLR = 7 | TYPECOIL,		//Link register
+	KLCoilTypeSR = 8 | TYPECOIL,		//Link register
+
+};
+enum enKLDataTypes
+{
+	KLDataTypeDEC = 0 | TYPEDATA,
+	KLDataTypeHEX = 1 | TYPEDATA,
+	KLDataTypeFloat = 2 | TYPEDATA,
+	KLDataTypeWX = 3 | TYPEDATA,
+	KLDataTypeWY = 4 | TYPEDATA,
+	KLDataTypeWR = 5 | TYPEDATA,
+	KLDataTypeWLX = 6 | TYPEDATA,
+	KLDataTypeWLY = 7 | TYPEDATA,
+	KLDataTypeDT = 8 | TYPEDATA,
+	KLDataTypeSDT = 9 | TYPEDATA,
+	KLDataTypeWSR = 10 | TYPEDATA,
+	KLDataTypeSV = 11 | TYPEDATA,
+	KLDataTypeEV = 12 | TYPEDATA,
+	KLDataTypeLD = 13 | TYPEDATA,
+	KLDataSysCfg = 25 | TYPEDATA,
+	KLDataTypeFlash = 33 | TYPEDATA,
+	KLDataTypeTest = 254 | TYPEDATA,
+};
+enum enKLDataCounts
+{
+	KLDataDTCount = 256,
+	KLDataSDTCount = 256,
+
+	KLDataWXCount = 16,
+	KLDataWYCount = 16,
+	KLDataWRCount = 16,
+	KLDataLDCount = 64,
+	KLDataWLCount = 8,
+
+	KLCoilXCount = KLDataWXCount * 16,
+	KLCoilYCount = KLDataWYCount * 16,
+	KLCoilRCount = KLDataWRCount * 16,
+
+	KLCoilTCount = 64,
+	KLCoilCCount = KLCoilTCount,
+	KLDataSVCount = KLCoilTCount,
+	KLDataEVCount = KLCoilTCount,
+
+	KLCoilLXCount = 128,
+	KLCoilLYCount = 128,
+	KLCoilLRCount = 128,
+	KLCoilSRCount = 128,
+
+
+};
+
+
+
+typedef struct tagTimer
+{
+	unsigned int LastActTime;
+	union {
+		unsigned short StatByte;
+		struct
+		{
+			unsigned short nScale : 2;	//Time Scale, 0:1ms 1:10ms 2:100ms 3:1S
+			unsigned short nType : 1;		//0 : timer 1	:	counter ;
+			unsigned short nDir : 1;		//0 : count down. 1 count up;
+			unsigned short nInited : 1;
+			unsigned short bSet : 1;
+			unsigned short bTon : 1;
+
+		};
+		//		stTimerStat Stat;
+	};
+}stTimer;
+
+typedef struct tagKMem
+{
+	unsigned short WDFs[TOTAL_WDFS];
+	unsigned char CurVALs[TOTAL_CurVAL];
+	unsigned char CurVAL;
+
+	stTimer Timers[TOTALTIMERS];
+
+	unsigned short WX[KLDataWXCount];		//
+	unsigned short WY[KLDataWYCount];		//
+	unsigned short WR[KLDataWRCount];
+	unsigned short WT[16];
+
+	unsigned short WC[16];
+	unsigned short EV[KLDataEVCount];
+	unsigned short SV[KLDataSVCount];
+
+	unsigned short WLX[16];		//
+	unsigned short WLY[16];
+	unsigned short WLR[16];
+	unsigned short WSR[16];
+	unsigned short DT[KLDataDTCount];
+
+	union {
+		unsigned int SDD[KLDataSDTCount / 2];
+		unsigned short SDT[KLDataSDTCount];
+		unsigned char SDB[KLDataSDTCount * 2];
+		struct {
+			unsigned int EffJumperSW;
+			unsigned int CurJumperSW;
+			unsigned int haltick;
+			unsigned int nRunCount;
+			unsigned int RunStat;
+			unsigned int ErrStat;
+			unsigned int PwrOnCount;
+			unsigned int ThisRunTime;
+			unsigned int TotalRunTime;
+			unsigned int CurTimeSec;
+			unsigned int PwrFailCount;
+			unsigned int LastPwrFailTime;
+			unsigned int LastScanTime;
+			unsigned int ScanTimeuS;
+			unsigned int MinScanTimeuS;
+			unsigned int MaxScanTimeuS;
+			unsigned int nEventCount;
+			unsigned int nEventMinIndex;
+			unsigned int nEventMaxIndex;
+			unsigned int Rev2[5];
+			unsigned short ADCValues[20];
+		};
+	};
+	int Reserverd5[1024];
+}stKMem;
+
+
+enum enOpType
+{
+	OP_NONE = 0,
+	OP_NOP = 0,
+	OP_ST = 1,		//
+	OP_ST_ = 2,		//
+	OP_AN = 3,		//
+	OP_AN_ = 4,		//
+	OP_OR = 5,		//
+	OP_OR_ = 6,		//
+	OP_NOT = 7,		//
+	OP_ANS = 8,	//
+	OP_ORS = 9,	//
+
+	OP_PSHS = 10,	//
+	OP_RDS = 11,		//
+	OP_POPS = 12,	//
+
+	OP_OUT = 16,		//
+	OP_SET = 17,	//
+	OP_RESET = 18,	//
+	OP_DF = 19,		//
+	OP_DF_ = 20,	//
+
+	OP_ST_EQ,	//
+	OP_ST_LT,	//
+	OP_ST_GT,	//
+	OP_ST_LE,	//
+	OP_ST_GE,		//
+	OP_ST_NE,		//
+	OP_AN_EQ,		//
+	OP_AN_LT,		//
+	OP_AN_GT,
+	OP_AN_LE,
+	OP_AN_GE,
+	OP_AN_NE,
+	OP_OR_EQ,
+	OP_OR_LT,
+	OP_OR_GT,
+	OP_OR_LE,
+	OP_OR_GE,
+	OP_OR_NE,
+
+
+	OP_MV = 51,
+	OP_INC = 52,
+	OP_ADD2 = 53,
+	OP_ADD3 = 54,
+	OP_DEC = 55,
+	OP_SUB2 = 56,
+	OP_SUB3 = 57,
+	OP_MUL = 58,
+	OP_DIV = 59,
+	OP_BKMV = 60,
+	OP_COPY = 61,
+	OP_CLR = 62,
+
+	OP_BRK,
+	OP_PAUSE,
+	OP_JP,
+	OP_CALL,
+
+	OP_TML = 0xC8,	//
+	OP_TMR = 0xDC,	//
+	OP_TMX = 0xDD,	//
+	OP_TMY = 0xFA,	//
+
+};
+
+typedef struct stBinProg1
+{
+	unsigned char nOp;
+	unsigned char nParamType;
+	unsigned short nParamAddr;
+}stBinProg1;
+typedef struct stBinProg15
+{	//定时器
+	//单参数高级指令
+	unsigned char nOp;
+	unsigned char nOpNum;
+	unsigned short nParamAddr1;
+	unsigned char nParamType1;
+	unsigned char resvr1;
+	unsigned short resvr2;
+}stBinProg15;
+typedef struct stBinProg2
+{	//比较指令
+	//双参数高级指令
+	unsigned char nOp;
+	unsigned char nOpNum;
+	unsigned short nParamAddr1;
+	unsigned char nParamType1;
+	unsigned char nParamType2;
+	unsigned short nParamAddr2;
+}stBinProg2;
+typedef struct stBinProg3
+{	//三参数高级指令
+	unsigned char nOp;
+	unsigned char nOpNum;
+	unsigned short nParamAddr1;
+	unsigned char nParamType1;
+	unsigned char nParamType2;
+	unsigned short nParamAddr2;
+	unsigned char resvr1;
+	unsigned char nParamType3;
+	unsigned short nParamAddr3;
+}stBinProg3;
+
diff --git a/KLink2/KLink.cpp b/KLink2/KLink.cpp
new file mode 100644
index 0000000..29ac596
--- /dev/null
+++ b/KLink2/KLink.cpp
@@ -0,0 +1,928 @@
+#include "pch.h"
+#include "KLink2.h"
+#include "KLink.h"
+#include <afxdialogex.h>
+#include "CDialogCommSet1.h"
+
+KLink2::KLink2()
+{
+
+}
+
+KLink2::~KLink2()
+{
+
+}
+
+int KLink2::fnTest1(int n)
+{
+	AFX_MANAGE_STATE(AfxGetStaticModuleState());
+/*
+	//方法2的状态变更
+	HINSTANCE save_hInstance = AfxGetResourceHandle();
+
+	AfxSetResourceHandle(theApp.m_hInstance);
+
+	//	CDialog dlg(IDD_DLL_DIALOG);//打开ID为2000的对话框
+	//	dlg.DoModal();
+*/
+	CDialogCommSet1 dialog1;
+	INT_PTR r = dialog1.DoModal();
+	//方法2的状态还原
+
+//	AfxSetResourceHandle(save_hInstance);
+
+	return 0;
+}
+
+static const KLink2::stKLTypeName KLCoilTypeNames[] =
+{
+	{KLink2::KLCoilTypeX,"X",KLink2::KLCoilXCount},
+	{KLink2::KLCoilTypeY,"Y",KLink2::KLCoilYCount},
+	{KLink2::KLCoilTypeR,"R",KLink2::KLCoilRCount},
+	{KLink2::KLCoilTypeLX,"LX",KLink2::KLCoilLXCount},
+	{KLink2::KLCoilTypeLY,"LY",KLink2::KLCoilLYCount},
+	{KLink2::KLCoilTypeT,"T",KLink2::KLCoilTCount},
+	{KLink2::KLCoilTypeC,"C",KLink2::KLCoilCCount}
+};
+
+static const KLink2::stKLTypeName KLDataTypeNames[] =
+{
+
+	KLink2::KLDataTypeWX,"WX", KLink2::KLDataWXCount,
+	KLink2::KLDataTypeWY,"WY", KLink2::KLDataWYCount,
+	KLink2::KLDataTypeWR,"WR",KLink2::KLDataWRCount,
+	KLink2::KLDataTypeWLX,"WLX",KLink2::KLDataWLCount,
+	KLink2::KLDataTypeWLY,"WLY",KLink2::KLDataWLCount,
+	KLink2::KLDataTypeDT,"DT",KLink2::KLDataDTCount,
+	KLink2::KLDataTypeSDT,"SDT",KLink2::KLDataSDTCount,
+	KLink2::KLDataTypeSV,"SV",KLink2::KLDataSVCount ,
+	KLink2::KLDataTypeEV,"EV",KLink2::KLDataEVCount ,
+	KLink2::KLDataTypeLD,"LD",KLink2::KLDataLDCount,
+	KLink2::KLDataSysCfg,"Cfg",128,
+	KLink2::KLDataTypeFlash,"Flash",256,
+	KLink2::KLDataTypeTest,"Test",256
+};
+
+const char * KLink2::GetErrDescStr(int nErrNo)
+{
+	switch (nErrNo)
+	{
+	case KL_ERR:
+		return "ERROR";
+	case KL_OK: //=0
+		return "OK";
+	case KL_NG:// = 1,
+		return "NG";
+	case KL_UNKNOWN: // = 2,
+		return "KL_UNKNOWN";
+	case KL_TIMEOUT: // = 3,
+		return "KL_TIMEOUT";
+	case KL_BCC_ERR: // = 4,
+		return "KL_BCC_ERR";
+	case KL_PKG_ERR: // = 5,
+		return "KL_PKG_ERR";
+	case KL_SEQ_ERR: // = 6,
+		return "KL_SEQ_ERR";
+	case KL_LENTH_EXCEED: //,
+		return "KL_LENTH_EXCEED";
+	case KL_NEED_PASS: //,
+		return "KL_NEED_PASS";
+	case KL_NOT_SUPPORT://,
+		return "KL_NOT_SUPPORT";
+	default:
+		return "KL_OTHER_ERR";
+		break;
+	}
+}
+
+int KLink2::xtoi(const char * hexstr, int len)
+{
+	int len1 = len;
+	if (len <= 0) len1 = (int)strlen(hexstr);
+	int j = 0;
+	for (int i = 0; i < len1; i++)
+	{
+		unsigned char ch = hexstr[i];
+		if (ch >= '0'&&ch <= '9') { int k = ch - '0';	j = j * 16 + k;	 continue; }
+		if (ch >= 'A'&&ch <= 'F') { int k = ch - 'A' + 10;	j = j * 16 + k;	continue; }
+		if (ch >= 'a'&&ch <= 'f') { int k = ch - 'a' + 10;	j = j * 16 + k;	continue; }
+		if (ch == ' ' || ch == '	') { continue; }
+		break;
+	}
+	return j;
+}
+
+unsigned char KLink2::KLBCC(void * pData, int nSize)
+{
+	unsigned char k = 0;
+	for (int i = 0; i < nSize; i++)
+	{
+		k ^= ((unsigned char *)pData)[i];
+	}
+	return k;
+}
+int KLink2::CalCRC(void * pBuf, int nSize)
+{
+	return 0;
+}
+
+int KLink2::SetSendCallBackFunc(std::function<int(void *, int)> pSendFunc)
+{
+	SendPkgFunc = pSendFunc;
+	m_bSendCallBackSet = 1;
+	return KL_OK;
+}
+
+int KLink2::SetRecvCallBackFunc(std::function<int(void *, int)> pRecvFunc)
+{
+	RecvPkgFunc = pRecvFunc;
+	m_bRecvCallBackSet = 1;
+	return KL_OK;
+}
+
+int KLink2::SetOpenCallBackFunc(std::function<int(int)> pOpenFunc)
+{
+	OpenFunc = pOpenFunc;
+	m_bOpenCallBackSet = 1;
+	return KL_OK;
+}
+int KLink2::SetCloseCallBackFunc(std::function<int(int)> pCloseFunc)
+{
+	CloseFunc = pCloseFunc;
+	m_bCloseCallBackSet = 1;
+	return KL_OK;
+}
+int KLink2::MakeExtDataFrame(void * pBuf, UCHAR nDst, UCHAR nType, UCHAR len2, void * pData)
+{
+	int framelen1 = 0;
+	pKLExtDataFrame pF1 = (pKLExtDataFrame)pBuf;
+	pF1->Dst = nDst;
+	pF1->nType = nType;
+	pF1->Len2 = len2;
+	memcpy(pF1->Data, pData, len2);
+	UCHAR bcc = KLBCC(pBuf, sizeof(tagKLExtDataFrame) + len2 - 1);
+	pF1->Data[len2] = bcc;
+
+	framelen1 = sizeof(tagKLExtDataFrame) + len2;
+	return framelen1;
+}
+/*
+int KLink2::MakeReqPacket(void * pBuf, UCHAR nDst, UCHAR Stat, UCHAR nCMD, UCHAR Type, USHORT nAddr, USHORT nCount, void * pData)
+{
+	int PkgLen1 = 0;
+	pKLReqPacket pPacket = (pKLReqPacket)pBuf;
+	pPacket->StartSign = KLSignStart;
+	pPacket->DstAddr = nDst;
+	pPacket->Stat = Stat;
+	pPacket->Cmd = nCMD;
+	pPacket->Type1 = Type;
+	int Datalen = 0;
+	int nWordAddr;
+	int nWordCount;
+
+	switch (nCMD)
+	{
+	case KLCmdNone:
+		break;
+	case KLCmdPing:
+		Datalen = Type;
+		memcpy(pPacket->Params, pData, Datalen);
+		PkgLen1 = sizeof(stKLReqPacket) + Datalen;
+		break;
+	case KLCmdGetInfo:
+		break;
+	case KLCmdRead:
+		Datalen = 0;
+		pPacket->Params[0] = nAddr % 256;
+		pPacket->Params[1] = nAddr / 256;
+		pPacket->Params[2] = nCount % 256;
+		pPacket->Params[3] = nCount / 256;
+		PkgLen1 = sizeof(stKLReqPacket) + 4 + Datalen;
+		break;
+	case KLCmdWrite:
+		pPacket->Params[0] = nAddr % 256;
+		pPacket->Params[1] = nAddr / 256;
+		pPacket->Params[2] = nCount % 256;
+		pPacket->Params[3] = nCount / 256;
+		Datalen = nCount;
+		memcpy(pPacket->Params + 4, pData, Datalen);
+		PkgLen1 = sizeof(stKLReqPacket) + 4 + Datalen;
+
+		break;
+	case KLCmdSaveToFlash:
+		break;
+	case KLCmdExChgData:
+		break;
+	case KLCmdGetEventLogCount:
+		pPacket->Params[0] = 0;
+		pPacket->Params[1] = 0;
+		pPacket->Params[2] = 0;
+		pPacket->Params[3] = 0;
+		Datalen = 0;
+		memcpy(pPacket->Params + 4, pData, Datalen);
+		PkgLen1 = sizeof(stKLReqPacket) + 4 + Datalen;
+	default:
+		break;
+	}
+	if (PkgLen1 >= sizeof(stKLReqPacket))
+	{
+		UCHAR BCC = KLBCC(pBuf, PkgLen1 - 1);
+		pPacket->Params[PkgLen1-sizeof(stKLReqPacket)] = BCC;
+	}
+	return PkgLen1;
+}
+*/
+int KLink2::MakeReqPacketEx(void * pBuf, UCHAR nDst, UCHAR Stat, UCHAR nCMD, UCHAR Type, 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 = nCMD;
+	pPacket->Type1 = Type;
+
+	pKLStat pStat = (pKLStat)&(pPacket->Stat);
+	int Datalen = 0;
+	int nWordAddr = nAddr;
+	int nWordCount = nCount;
+	pPacket->Params[0] = LOBYTE(nAddr);
+	pPacket->Params[1] = HIBYTE(nAddr);
+	pPacket->Params[2] = nCount % 256;
+	pPacket->Params[3] = nCount / 256;
+
+	switch (nCMD)
+	{
+	case KLCmdNone:
+		break;
+	case KLCmdPing:
+		Datalen = Type;
+		memcpy(pPacket->Params, pData, Datalen);
+		PkgLen1 = sizeof(stKLReqPacket) + Datalen;
+		break;
+	case KLCmdGetInfo:
+		break;
+	case KLCmdRead:
+		Datalen = 0;
+		PkgLen1 = sizeof(stKLReqPacket) + 4 + Datalen;
+		break;
+	case KLCmdWrite:
+		Datalen = nCount;
+		memcpy(pPacket->Params + 4, pData, Datalen);
+		PkgLen1 = sizeof(stKLReqPacket) + 4 + Datalen;
+		break;
+	case KLCmdRead1Bit:
+		Datalen = 0;
+		PkgLen1 = sizeof(stKLReqPacket) + 2 + Datalen;
+		break;
+	case KLCmdWrite1Bit:
+		Datalen = 1;
+		memcpy(pPacket->Params + 2, pData, Datalen);
+		PkgLen1 = sizeof(stKLReqPacket) + 2 + Datalen;
+		break;
+
+	case KLCmdReadBits:
+		Datalen = 0;
+		PkgLen1 = sizeof(stKLReqPacket) + 4 + Datalen;
+		break;
+	case KLCmdWriteBits:
+		Datalen = 0;
+		PkgLen1 = sizeof(stKLReqPacket) + 4 + Datalen;
+		break;
+	case KLCmdReadDataByte:
+	case KLCmdReadDataWord:
+	case KLCmdReadData:
+		Datalen = 0;
+		PkgLen1 = sizeof(stKLReqPacket) + 4 + Datalen;
+		break;
+	case KLCmdWriteDataByte:
+	case KLCmdWriteDataWord:
+	case KLCmdWriteData:
+		Datalen = nCount;
+		memcpy(pPacket->Params + 4, pData, Datalen);
+		PkgLen1 = sizeof(stKLReqPacket) + 4 + Datalen;
+		break;
+	case KLCmdSaveToFlash:
+		break;
+	case KLCmdExChgData:
+		break;
+	case KLCmdReadProgram:
+		Datalen = 0;
+		PkgLen1 = sizeof(stKLReqPacket) + 4 + Datalen;
+		break;
+	case KLCmdStartProgram:
+		Datalen = 0;
+		PkgLen1 = sizeof(stKLReqPacket) + 4 + Datalen;
+		break;
+	case KLCmdWriteProgram:
+		Datalen = nCount;
+		memcpy(pPacket->Params + 4, pData, Datalen);
+		PkgLen1 = sizeof(stKLReqPacket) + 4 + Datalen;
+		break;
+	case KLCmdFinishProgram:
+		Datalen = 0;
+		PkgLen1 = sizeof(stKLReqPacket) + 4 + Datalen;
+		break;
+
+	case KLCmdReadRunStat:
+		Datalen = 0;
+		PkgLen1 = sizeof(stKLReqPacket) + 4 + Datalen;
+		break;
+
+	case KLCmdSaveSysCfg:
+		pPacket->Params[0] = 0;
+		pPacket->Params[1] = 0;
+		pPacket->Params[2] = 0;
+		pPacket->Params[3] = 0;
+		Datalen = 0;
+		memcpy(pPacket->Params + 4, pData, Datalen);
+		PkgLen1 = sizeof(stKLReqPacket) + 4 + Datalen;
+		break;
+	case KLCmdSaveRunStat:
+		pPacket->Params[0] = 0;
+		pPacket->Params[1] = 0;
+		pPacket->Params[2] = 0;
+		pPacket->Params[3] = 0;
+		Datalen = 0;
+		memcpy(pPacket->Params + 4, pData, Datalen);
+		PkgLen1 = sizeof(stKLReqPacket) + 4 + Datalen;
+		break;
+	case KLCmdClearEventLog:
+		pPacket->Params[0] = 0;
+		pPacket->Params[1] = 0;
+		pPacket->Params[2] = 0;
+		pPacket->Params[3] = 0;
+		Datalen = 0;
+		memcpy(pPacket->Params + 4, pData, Datalen);
+		PkgLen1 = sizeof(stKLReqPacket) + 4 + Datalen;
+
+	case KLCmdGetEventLogCount:
+		pPacket->Params[0] = 0;
+		pPacket->Params[1] = 0;
+		pPacket->Params[2] = 0;
+		pPacket->Params[3] = 0;
+		Datalen = 0;
+		memcpy(pPacket->Params + 4, pData, Datalen);
+		PkgLen1 = sizeof(stKLReqPacket) + 4 + Datalen;
+		break;
+	case KLCmdGetEventLog:
+		pPacket->Params[0] = nAddr % 256;
+		pPacket->Params[1] = nAddr / 256;
+		pPacket->Params[2] = nCount % 256;
+		pPacket->Params[3] = nCount / 256;
+		Datalen = 0;
+		memcpy(pPacket->Params + 4, pData, Datalen);
+		PkgLen1 = sizeof(stKLReqPacket) + 4 + Datalen;
+		break;
+
+	default:
+		pPacket->Params[0] = nAddr % 256;
+		pPacket->Params[1] = nAddr / 256;
+		pPacket->Params[2] = nCount % 256;
+		pPacket->Params[3] = nCount / 256;
+		Datalen = 0;
+		memcpy(pPacket->Params + 4, pData, Datalen);
+		PkgLen1 = sizeof(stKLReqPacket) + 4 + Datalen;
+		break;
+	}
+
+	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 KLink2::CheckPackage(void * pBuf, int nSize)
+{
+	pKLRplyPktHdr p1 = (pKLRplyPktHdr)pBuf;
+	if (p1->RplyStSgn != KLSignReply)
+	{
+		return KL_UNKNOWN;
+	}
+
+	int DataLen = 0;	//p1->LoadLen;
+	if (DataLen > KLMaxPacketLength)
+	{
+		return KL_PKG_ERR;
+	}
+	if (nSize < DataLen + sizeof(stKLRplyPktHdr))
+	{
+		//len4=sprintf(str3,"%d < %d + %d \r\n",len2,DataLen,sizeof(stPacket));
+		//PutStr(str3,len4);
+		return KL_PKG_ERR;	//not long enough					
+	}
+	//	if (p1->data[DataLen+1] != EndSign)
+	//	{
+	//		ClientStat[nCurPollId].NoEndErr++;
+	//		Uart2Stat.LengthErr++;		
+	//		return -2;
+	//	}
+	unsigned char thisBCC = KLBCC(p1, nSize - 1);
+	if (thisBCC != ((UCHAR *)pBuf)[nSize - 1])
+	{//BCC Error;
+		return KL_BCC_ERR;
+	}
+	return KL_OK;
+
+	return true;
+	return false;
+}
+
+int KLink2::ProcessPacket(void *pBuf, int nLen)
+{
+	return false;
+}
+
+int KLink2::ParseRplyPacket(void *pBuf, int nPkgLen, UCHAR * nCmd, UCHAR * Status, USHORT* nCount, void * pData)
+{
+	if (nPkgLen < 0) { return KL_ERR; }
+	int res = CheckPackage(pBuf, nPkgLen);
+	if (res != KL_OK) return res;
+	int len1 = 0;
+	pKLRplyPktHdr pPacket = (pKLRplyPktHdr)pBuf;
+	UCHAR Sign = pPacket->RplyStSgn;
+	UCHAR nDst = pPacket->DstAddr;
+	*nCmd = pPacket->nRplyCMD;
+	UCHAR nStatus = pPacket->nStatus;
+	*Status = nStatus;
+	m_nRSeq = ((pKLStat)&nStatus)->nSEQ;
+	int Datalen = pPacket->nSize1;
+	*nCount = Datalen;
+	switch (*nCmd)
+	{
+	case KLCmdNone:
+		break;
+	case KLCmdPing:
+	case KLCmdPingReply:
+		*nCount = Datalen;
+		memcpy(pPacket->Datas, pData, Datalen);
+		break;
+	case KLCmdGetInfo:
+	case KLCmdVerInfo:
+		*nCount = Datalen;
+		memcpy(pPacket->Datas, pData, Datalen);
+		break;
+	case KLCmdRead:
+	case KLCmdReadReply:
+		*nCount = Datalen;
+		memcpy(pData, pPacket->Datas, Datalen);
+		break;
+	case KLCmdWrite:
+	case KLCmdWriteReply:
+		*nCount = Datalen;
+		break;
+	case KLCmdRead1Bit:
+	case KLCmdReadBits:
+		*nCount = Datalen;
+		memcpy(pData, pPacket->Datas, Datalen);
+		break;
+	case KLCmdReadDataByte:
+		*nCount = Datalen;
+		memcpy(pData, pPacket->Datas, Datalen);
+		break;
+	case KLCmdReadDataWord:
+	case KLCmdReadData:
+		*nCount = Datalen;
+		memcpy(pData, pPacket->Datas, Datalen);
+		break;
+	case KLCmdWriteDataByte:
+	case KLCmdWriteDataWord:
+	case KLCmdWriteData:
+		*nCount = Datalen;
+		break;
+
+	case KLCmdSaveToFlash:
+		break;
+
+	case KLCmdReadProgram:
+		*nCount = Datalen;
+		memcpy(pData, pPacket->Datas, Datalen);
+		break;
+	case KLCmdStartProgram:
+		*nCount = Datalen;
+		break;
+	case KLCmdWriteProgram:
+		*nCount = Datalen;
+		break;
+	case KLCmdFinishProgram:
+		*nCount = Datalen;
+		break;
+
+	case KLCmdReadRunStat:
+		*nCount = Datalen;
+		memcpy(pData, pPacket->Datas, Datalen);
+		break;
+	case KLCmdExChgData:
+	case KLCmdExChgDataReply:
+		break;
+	case KLCmdGetEventLogCount:
+		*nCount = Datalen;
+		memcpy(pData, pPacket->Datas, Datalen);
+		break;
+	case KLCmdGetEventLog:
+		*nCount = Datalen;
+		memcpy(pData, pPacket->Datas, Datalen);
+		break;
+
+	case KLCmdErrRply:
+		*nCount = Datalen;
+		memcpy(pData, pPacket->Datas, Datalen);
+		break;
+	default:
+		*nCount = Datalen;
+		//memcpy(pData, pPacket->Datas, Datalen);
+		break;
+	}
+	return KL_OK;
+
+	return false;
+}
+
+int KLink2::ReadBit(UCHAR nDst, UCHAR nType, USHORT nBitAddr, UCHAR * Value)
+{
+	m_Dst = nDst;
+	int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdRead1Bit, nType, nBitAddr);
+	SendPacket(m_Packetbuf, len1);
+	int numToRead = sizeof(stKLRplyPktHdr) + 1;
+
+	int len2 = RecvPacket(m_RecvBuf, numToRead);
+	unsigned char nCmd;
+	unsigned short nCount;
+	ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nCount, m_DataBuf);
+	Value[0] = m_DataBuf[0];
+	return KL_OK;
+}
+int KLink2::WriteBit(UCHAR nDst, UCHAR nType, USHORT nBitAddr, UCHAR Value)
+{
+	m_Dst = nDst;
+	m_DataBuf[0] = Value;
+	int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdWrite1Bit, nType, nBitAddr, 1, m_DataBuf);
+	SendPacket(m_Packetbuf, len1);
+	int len2 = RecvPacket(m_RecvBuf, 64);
+	unsigned char nCmd;
+	unsigned short nCount;
+	ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nCount, m_DataBuf);
+	return KL_OK;
+}
+int KLink2::ReadBits(UCHAR nDst, UCHAR nBitCount, UCHAR nType, USHORT nBitAddr, UCHAR * Values)
+{
+	return KL_OK;
+}
+int KLink2::WriteBits(UCHAR nDst, UCHAR nBitCount, UCHAR nType, USHORT nBitAddr, UCHAR * Values)
+{
+	return KL_OK;
+}
+int KLink2::ReadBitsByWord(UCHAR nDst, UCHAR nWordCount, UCHAR nType, USHORT nWordAddr, USHORT *Values)
+{
+	return KL_OK;
+}
+int KLink2::WriteBitsByWord(UCHAR nDst, UCHAR nWordCount, UCHAR nType, USHORT nWordAddr, USHORT *Values)
+{
+	return KL_OK;
+}
+int KLink2::GetNextSeq()
+{
+	m_nSeq++;
+	if (m_nSeq >= 8) m_nSeq = 0;
+	m_Stat1.nSEQ = m_nSeq;
+	return m_nSeq;
+}
+
+int KLink2::ReadDataByte(UCHAR nDst, UCHAR nByteCount, UCHAR nType, USHORT nByteAddr, UCHAR * Values)
+{
+	m_Dst = nDst;
+	m_resultStr.Empty();
+	UCHAR nExpSeq = GetNextSeq();
+	int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdReadDataByte, nType, nByteAddr / 2, nByteCount);
+	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;
+	int res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, m_DataBuf);
+	if (res == KL_OK)
+	{
+		for (int i = 0; i < nnCount; i++)
+		{
+			Values[i] = m_DataBuf[i];
+		}
+	}
+	else
+	{
+		m_resultStr.AppendFormat(_T("Res=%d ToRead %d Count %d "), res, numToRead, len2);
+		return res;
+	}
+
+	return KL_OK;
+}
+int KLink2::WriteDataByte(UCHAR nDst, UCHAR nByteCount, UCHAR nType, USHORT nByteAddr, UCHAR * Values)
+{
+	m_Dst = nDst;
+	UCHAR nExpSeq = GetNextSeq();
+	int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdWriteDataByte, nType, nByteAddr / 2, nByteCount, Values);
+	SendPacket(m_Packetbuf, len1);
+	int len2 = RecvPacket(m_RecvBuf, 64);
+	if (len2 == 0) { len2 = RecvPacket(m_RecvBuf, 64); }
+	if (len2 == 0) return KL_ERR;
+	unsigned char nCmd;
+	unsigned short nnCount;
+	int res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, m_DataBuf);
+	return res;
+}
+
+int KLink2::ReadDataWord(UCHAR nDst, UCHAR nWordCount, UCHAR nType, USHORT nWordAddr, USHORT * Values)
+{
+	m_Dst = nDst;
+	UCHAR nExpSeq = GetNextSeq();
+	int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdReadDataWord, nType, nWordAddr, nWordCount);
+	SendPacket(m_Packetbuf, len1);
+	int numToRead = sizeof(stKLRplyPktHdr) + nWordCount;
+
+	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;
+	int res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, m_DataBuf);
+	for (int i = 0; i < nnCount / 2; i++)
+	{
+		//		Values[0] = m_DataBuf[0];
+		Values[i] = m_DataBuf[i * 2] + (m_DataBuf[i * 2 + 1] << 8);
+	}
+	return res;
+}
+int KLink2::WriteDataWord(UCHAR nDst, UCHAR nWordCount, UCHAR nType, USHORT nWordAddr, USHORT * Values)
+{
+	m_Dst = nDst;
+	UCHAR nExpSeq = GetNextSeq();
+	int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdWriteDataWord, nType, nWordAddr, nWordCount, Values);
+	SendPacket(m_Packetbuf, len1);
+	int len2 = RecvPacket(m_RecvBuf, 64);
+	if (len2 == 0) { len2 = RecvPacket(m_RecvBuf, 64); }
+	if (len2 == 0) return KL_ERR;
+	unsigned char nCmd;
+	unsigned short nnCount;
+	int res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, m_DataBuf);
+	Values[0] = m_DataBuf[0];
+	return res;
+}
+
+int KLink2::ReadData(UCHAR nDst, UCHAR nWordCount, UCHAR nType, USHORT nWordAddr, USHORT * Values)
+{
+	m_Dst = nDst;
+	UCHAR nExpSeq = GetNextSeq();
+	int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdReadData, nType, nWordAddr, nWordCount);
+	SendPacket(m_Packetbuf, len1);
+	int len2 = RecvPacket(m_RecvBuf, 64);
+	if (len2 == 0) { len2 = RecvPacket(m_RecvBuf, 64); }
+	if (len2 == 0) return KL_ERR;
+	unsigned char nCmd;
+	unsigned short nnCount;
+	int res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, m_DataBuf);
+	for (int i = 0; i < nnCount; i++)	Values[i] = m_DataBuf[i];
+	return res;
+
+	return KL_OK;
+}
+int KLink2::WriteData(UCHAR nDst, UCHAR nWordCount, UCHAR nType, USHORT nWordAddr, USHORT * Values)
+{
+	m_Dst = nDst;
+	UCHAR nExpSeq = GetNextSeq();
+	int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdWriteData, nType, nWordAddr, nWordCount, Values);
+	SendPacket(m_Packetbuf, len1);
+	int len2 = RecvPacket(m_RecvBuf, 64);
+	if (len2 == 0) { len2 = RecvPacket(m_RecvBuf, 64); }
+	if (len2 == 0) return KL_ERR;
+	unsigned char nCmd;
+	unsigned short nnCount;
+	int res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, m_DataBuf);
+	//	Values[0] = m_DataBuf[0];
+	return res;
+
+	return KL_OK;
+}
+int KLink2::GetInfo(UCHAR nDst, UCHAR nWordCount, UCHAR nType, USHORT nWordAddr, USHORT * Values)
+{
+	m_Dst = nDst;
+	UCHAR nExpSeq = GetNextSeq();
+	int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdGetInfo, nType, nWordAddr, nWordCount, Values);
+	SendPacket(m_Packetbuf, len1);
+	int len2 = RecvPacket(m_RecvBuf, 64);
+	if (len2 == 0) { len2 = RecvPacket(m_RecvBuf, 64); }
+	if (len2 == 0) return KL_ERR;
+	unsigned char nCmd;
+	unsigned short nnCount;
+	int res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, m_DataBuf);
+	//	Values[0] = m_DataBuf[0];
+	return res;
+
+	return KL_OK;
+}
+int KLink2::GetEventLogCount(UCHAR nDst, int * nCount)
+{
+	m_Dst = nDst;
+	UCHAR nExpSeq = GetNextSeq();
+	int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdGetEventLogCount, 0);
+	SendPacket(m_Packetbuf, len1);
+	int len2 = RecvPacket(m_RecvBuf, 64);
+	if (len2 == 0) { len2 = RecvPacket(m_RecvBuf, 64); }
+	if (len2 == 0) return KL_ERR;
+	unsigned char nCmd;
+	unsigned short nnCount;
+	int res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, m_DataBuf);
+	nCount[0] = *(int *)m_DataBuf;
+	return res;
+
+	return KL_OK;
+}
+
+int KLink2::GetEventLog(UCHAR nDst, int nStartIndex, int nCount, stEventLog * theEventLogs)
+{
+	m_Dst = nDst;
+	UCHAR nExpSeq = GetNextSeq();
+	int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdGetEventLog, 0, nStartIndex, nCount, 0);
+	SendPacket(m_Packetbuf, len1);
+	int len2 = RecvPacket(m_RecvBuf, 64);
+	if (len2 == 0) { len2 = RecvPacket(m_RecvBuf, 64); }
+	if (len2 == 0) return KL_ERR;
+	unsigned char nCmd;
+	unsigned short nnCount;
+	int res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, m_DataBuf);
+
+	memcpy(theEventLogs, m_DataBuf, nCount * sizeof(stEventLog));
+
+	return res;
+
+	return KL_OK;
+}
+
+int  KLink2::GetDateTime32(UCHAR nDst, UINT * pValue)
+{
+	int res = KL_OK;
+	res = ReadDataByte(nDst, 4, KLDataTypeSDT, 36, (UCHAR *)pValue);
+	return res;
+
+}
+
+int  KLink2::SetDateTime32(UCHAR nDst, UINT  Value)
+{
+	int res = KL_OK;
+	res = WriteDataByte(nDst, 4, KLDataTypeSDT, 36, (UCHAR *)&Value);
+	return res;
+}
+
+int KLink2::GetMode(UCHAR nDst, UCHAR nType)
+{
+	int res = KL_OK;
+	//	res = ReadDataByte(nDst, 4, KLDataTypeSDT, 36, (UCHAR *)pValue);
+	m_Dst = nDst;
+	UCHAR nExpSeq = GetNextSeq();
+	int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdGetMode, nType);
+	SendPacket(m_Packetbuf, len1);
+	int len2 = RecvPacket(m_RecvBuf, 64);
+	if (len2 == 0) { len2 = RecvPacket(m_RecvBuf, 64); }
+	if (len2 == 0) return KL_ERR;
+	unsigned char nCmd;
+	unsigned short nnCount;
+	res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, m_DataBuf);
+	return res;
+
+}
+
+
+int KLink2::ChangeMode(UCHAR nDst, UCHAR nType)
+{
+	int res = KL_OK;
+	//	res = WriteDataByte(nDst, 4, KLDataTypeSDT, 36, (UCHAR *)&Value);
+	m_Dst = nDst;
+	UCHAR nExpSeq = GetNextSeq();
+	int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdChgMode, nType);
+	SendPacket(m_Packetbuf, len1);
+	int len2 = RecvPacket(m_RecvBuf, 64);
+	if (len2 == 0) { len2 = RecvPacket(m_RecvBuf, 64); }
+	if (len2 == 0) return KL_ERR;
+	unsigned char nCmd;
+	unsigned short nnCount;
+	res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, m_DataBuf);
+	return res;
+
+}
+
+
+
+int KLink2::ReadProgram(UCHAR nDst, UCHAR nType, USHORT nWordAddr, UCHAR nWordCount, USHORT * Values)
+{
+	int res = KL_OK;
+	m_Dst = nDst;
+	UCHAR nExpSeq = GetNextSeq();
+	int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdReadProgram, nType, nWordAddr, nWordCount);
+	SendPacket(m_Packetbuf, len1);
+	int nByteCount = nWordCount;
+	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;
+	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];
+	return res;
+
+}
+
+int KLink2::StartProgram(UCHAR nDst, UCHAR nType)
+{
+	int res = KL_OK;
+	m_Dst = nDst;
+	UCHAR nExpSeq = GetNextSeq();
+	int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdStartProgram, nType);
+	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;
+	res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, m_DataBuf);
+	return res;
+
+}
+int KLink2::WriteProgram(UCHAR nDst, UCHAR nType, USHORT nWordAddr, UCHAR nWordCount, 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);
+
+	SendPacket(m_Packetbuf, len1);
+	int len2 = RecvPacket(m_RecvBuf, 6);
+	if (len2 <= 0) { len2 = RecvPacket(m_RecvBuf, 6, 30); }
+	if (len2 <= 0) return KL_ERR;
+	unsigned char nCmd;
+	unsigned short nnCount;
+	res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, m_DataBuf);
+	//	Values[0] = m_DataBuf[0];
+	return res;
+
+}
+int KLink2::FinishProgram(UCHAR nDst, UCHAR nType, USHORT nStepSize)
+{
+	int res = KL_OK;
+
+	m_Dst = nDst;
+	UCHAR nExpSeq = GetNextSeq();
+	int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdFinishProgram, nType, nStepSize);
+	SendPacket(m_Packetbuf, len1);
+	int len2 = RecvPacket(m_RecvBuf, 6);
+	if (len2 <= 0) { len2 = RecvPacket(m_RecvBuf, 6, 30); }
+	if (len2 <= 0) return KL_ERR;
+	unsigned char nCmd;
+	unsigned short nnCount;
+	res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, m_DataBuf);
+	return res;
+}
+
+int KLink2::ReadRunStat(UCHAR nDst, UCHAR nType, USHORT nWordAddr, UCHAR nWordCount, USHORT * Values)
+{
+	int res = KL_OK;
+	m_Dst = nDst;
+	UCHAR nExpSeq = GetNextSeq();
+	int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdReadRunStat, nType, nWordAddr, nWordCount);
+	SendPacket(m_Packetbuf, len1);
+	int nByteCount = nWordCount;
+	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;
+	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];
+	return res;
+
+}
diff --git a/KLink2/KLink.h b/KLink2/KLink.h
new file mode 100644
index 0000000..5ab4c85
--- /dev/null
+++ b/KLink2/KLink.h
@@ -0,0 +1,643 @@
+#pragma once
+// 下列 ifdef 块是创建使从 DLL 导出更简单的
+// 宏的标准方法。此 DLL 中的所有文件都是用命令行上定义的 MDH_SOCKET_EXPORTS
+// 符号编译的。在使用此 DLL 的
+// 任何其他项目上不应定义此符号。这样,源文件中包含此文件的任何其他项目都会将
+// MDH_SOCKET_API 函数视为是从 DLL 导入的,而此 DLL 则将用此宏定义的
+// 符号视为是被导出的。
+#ifdef KLINK_EXPORTS
+#define KLINK2_API __declspec(dllexport)
+#else
+#define KLINK2_API __declspec(dllimport)
+#endif
+
+//#include "KDefine.h"
+#include <functional>
+/*
+
+
+
+*/
+
+// 此类是从KLink2.dll 导出的
+class KLINK2_API KLink2 {
+
+
+	typedef unsigned char UCHAR;
+	typedef unsigned short USHORT;
+	typedef unsigned int UINT;
+
+public:
+	KLink2();
+	virtual ~KLink2();
+
+
+#define TYPECOIL 0x00
+#define TYPEDATA 0x80
+	enum enKLCoilTypes
+	{
+		KLCoilTypeX = 0 | TYPECOIL,		//X Input
+		KLCoilTypeY = 1 | TYPECOIL,		//Y Output
+		KLCoilTypeR = 2 | TYPECOIL,		//R register
+		KLCoilTypeLX = 3 | TYPECOIL,		//Link register
+		KLCoilTypeLY = 4 | TYPECOIL,		//Link register
+		KLCoilTypeT = 5 | TYPECOIL,		//Timer
+		KLCoilTypeC = 6 | TYPECOIL,		//Counter
+		KLCoilTypeLR = 7 | TYPECOIL,		//Link register
+		KLCoilTypeSR = 8 | TYPECOIL,		//Link register
+
+
+	};
+	enum enKLDataTypes
+	{
+		KLDataTypeDEC = 0 | TYPEDATA,
+		KLDataTypeHEX = 1 | TYPEDATA,
+		KLDataTypeFloat = 2 | TYPEDATA,
+		KLDataTypeWX = 3 | TYPEDATA,
+		KLDataTypeWY = 4 | TYPEDATA,
+		KLDataTypeWR = 5 | TYPEDATA,
+		KLDataTypeWLX = 6 | TYPEDATA,
+		KLDataTypeWLY = 7 | TYPEDATA,
+		KLDataTypeDT = 8 | TYPEDATA,
+		KLDataTypeSDT = 9 | TYPEDATA,
+		KLDataTypeWSR = 10 | TYPEDATA,
+		KLDataTypeSV = 11 | TYPEDATA,
+		KLDataTypeEV = 12 | TYPEDATA,
+		KLDataTypeLD = 13 | TYPEDATA,
+		KLDataSysCfg = 25 | TYPEDATA,
+		KLDataTypeFlash = 33 | TYPEDATA,
+		KLDataTypeTest = 254 | TYPEDATA,
+	};
+	enum enKLDataCounts
+	{
+		KLDataDTCount = 256,
+		KLDataSDTCount = 256,
+
+		KLDataWXCount = 16,
+		KLDataWYCount = 16,
+		KLDataWRCount = 16,
+		KLDataLDCount = 64,
+		KLDataWLCount = 8,
+
+		KLCoilXCount = KLDataWXCount * 16,
+		KLCoilYCount = KLDataWYCount * 16,
+		KLCoilRCount = KLDataWRCount * 16,
+
+		KLCoilTCount = 64,
+		KLCoilCCount = KLCoilTCount,
+		KLDataSVCount = KLCoilTCount,
+		KLDataEVCount = KLCoilTCount,
+
+		KLCoilLXCount = 128,
+		KLCoilLYCount = 128,
+		KLCoilLRCount = 128,
+		KLCoilSRCount = 128,
+
+	};
+	typedef struct tagKLTypeName
+	{
+		int nType;
+		const char * sName;
+		int nRange = 0;
+	}stKLTypeName;
+	static const stKLTypeName KLCoilTypeNames[];
+	static const stKLTypeName KLDataTypeNames[];
+
+	enum eKLResult
+	{
+		KL_ERR = -1,
+		KL_OK = 0,
+		KL_NG = 1,
+		KL_UNKNOWN = 2,
+		KL_TIMEOUT = 3,
+		KL_BCC_ERR = 4,
+		KL_PKG_ERR = 5,
+		KL_SEQ_ERR = 6,
+		KL_LENTH_EXCEED,
+		KL_NEED_PASS,
+		KL_NOT_SUPPORT,
+	};
+	const char * GetErrDescStr(int nErrNo);
+	enum
+	{
+		KLSignStart = '%',
+		KLSignReply = 'U',
+		KLSignEnd = 0x0D,
+		KLMaxPacketLength = 128,
+
+	};
+	enum ExtraDataType
+	{
+		KLExtTypeNone = 0,
+		KLExtTypeText = 1,
+		KLExtTypeCmd = 2,
+		KLExtTypePassTh = 3,
+
+		KLExtTypeTestData = 8,
+	};
+
+	enum enCMDs
+	{
+		//		cmdOK = '1',		//Reply OK
+		//		cmdNG = '2',		//Rplay NG
+		KLCmdNone = 0x00,		//Nothing
+		KLCmdPing = 0x01,			//Ping
+		KLCmdPingReply = 0x02,		//PingReply
+		KLCmdGetInfo = 0x03,			//GetInfo
+		KLCmdVerInfo = 0x04,			//InfoReply
+
+		KLCmdRead = 0x05,			//Read
+		KLCmdReadReply = 0x06,		//ReadReply
+		KLCmdWrite = 0x07,			//Write
+		KLCmdWriteReply = 0x08,	//WriteReply
+		KLCmdSaveToFlash = 0x09,				//Write
+
+		KLCmdExChgData = 0x0A,				//ExChangeDate, = Wirte + Read
+		KLCmdExChgDataReply,			//ExchangeData Reply
+
+		KLCmdSyncRead = 0x0D,				//SyncRead
+		KLCmdSyncWrite,						//SyncWrite
+		KLCmdSequenRead,					//Sequence Read
+		KLCmdSyncTime,						//SyncTime
+
+		KLCmdChgMode = 0x11,
+		KLCmdGetMode = 0x12,
+
+		KLCmdChkPass,
+		KLCmdSetPass,
+		KLCmdEraseAll,
+		KLCmdReadProgram,
+		KLCmdStartProgram,
+		KLCmdWriteProgram,
+		KLCmdFinishProgram,
+
+		KLCmdRead1Bit = 0x21,				//ReadSingleBit
+		KLCmdWrite1Bit = 0x22,				//WriteSingleBit
+
+		KLCmdReadBits = 0x23,				//ReadBits		n = 1 - 8
+		KLCmdWriteBits = 0x24,				//ReadBits		n = 1 - 8
+
+		KLCmdReadBitsByByte = 0x25,			//ReadBitsByByte	,byteCount
+		KLCmdWriteBitsByByte = 0x26,		//ReadBitsByByte	,ByteCount
+
+		KLCmdReadBitsByWord = 0x27,			//ReadBitsByWord	,WordCount
+		KLCmdWriteBitsByWord = 0x28,		//ReadBitsByWord	,WordCount
+
+		KLCmdReadDataByte = 0x31,			//ByteCount
+		KLCmdWriteDataByte = 0x32,
+
+		KLCmdReadDataWord = 0x33,			//WordCount
+		KLCmdWriteDataWord = 0x34,
+
+		KLCmdReadData = 0x35,				//?Count
+		KLCmdWriteData = 0x36,
+
+		KLCmdReadProg = 0x51,
+		KLCmdWriteProg,
+		KLCmdReadSysCfg,
+		KLCmdWriteSysCfg,
+		KLCmdSaveSysCfg,
+		KLCmdSaveRunStat,
+		KLCmdReadRunStat,
+
+		KLCmdEraseFlashPage = 0x61,
+		KLCmdWriteToFlash = 0x62,
+
+		KLCmdGetEventLogCount,
+		KLCmdGetEventLog,
+		KLCmdClearEventLog,
+		KLCmdGetFactoryData,
+		KLCmdWriteFactoryData,
+		KLCmdResetMachine,
+		KLCmdGetUid,
+		KLCmdSetTime,
+
+		KLCmdMC,
+		KLCmdMD,
+		KLCmdMG,
+
+		KLCmdErrRply = 0xEE,				//ERRORReply
+	};
+
+	typedef struct tagRunStat
+	{
+		unsigned short Sign1;
+		unsigned short Seq1;
+		volatile unsigned short PowerCount;	//
+		volatile unsigned short Reserved1;
+		volatile unsigned int UpTime;		//Seconds;
+		volatile unsigned int UserData1;
+		volatile unsigned short WorkMode;
+		volatile unsigned short WorkMode2;
+		volatile unsigned short nBinProgBank;
+		volatile unsigned short nBinProgSize;
+		unsigned int Reserved2[1];
+		unsigned short CRC1;
+		unsigned short EndSign1;
+	}stRunStat, *pRunStat;
+
+	stRunStat KMRunStat;
+
+	enum enKeventType
+	{
+		EventTypeNone = 0,
+		EventTypePowerUp = 1,
+		EventTypePowerDown = 2,
+		EventTypePowerRecover = 3,
+		EventTypeConnected = 4,
+		EventTypeLostCon = 5,
+		EventTypeSetTime = 6,
+		EventTypeSysCfg = 7,
+		EventTypeProg = 8,
+		EventTypeForce = 9,
+		EventTypeClearEvent = 10,
+
+		EventType
+	};
+
+	typedef struct tagEventLog
+	{
+		unsigned short Sign1;
+		unsigned short Seq1;
+		unsigned int nTime;
+		unsigned short nType;
+		unsigned short nParam1;
+		unsigned int nParam2;
+	}stEventLog, *pEventLog;
+
+
+	typedef struct tagKLCmdName
+	{
+		const int nCmd;
+		const char * sName;
+		const char * sType;
+
+	}KLCmdName;
+
+	const KLCmdName KLCmdNames[42] =
+	{
+		{KLCmdNone,"None",""},	//==0	//Nothing
+		{KLCmdPing,"Ping"},	//=1		//Ping
+		{KLCmdPingReply,"PingReply"}, //2		//PingReply
+		{KLCmdGetInfo,"GetInfo"},//3			//GetInfo
+		{KLCmdVerInfo,"VerInfo"},// = 0x04,			//InfoReply
+
+		{KLCmdRead,"Read","WX;WY;DT;SDT;EV;SV;LD;WL;CFG;FLASH;RAM"},// = 0x05,			//Read
+		{KLCmdReadReply,"ReadReply"},// = 0x06,		//ReadReply
+		{KLCmdWrite,"Write"},// = 0x07,			//Write
+		{KLCmdWriteReply,"WriteReply"},// = 0x08,	//WriteReply
+		{KLCmdSaveToFlash,"SaveToFlash"},// = 0x09,				//Write
+
+		{KLCmdExChgData,"ExChgData"},// = 0x0A,				//ExChangeDate, = Wirte + Read
+		{KLCmdExChgDataReply,"ExChgDataReply"},//,			//ExchangeData Reply
+
+		{	KLCmdSyncRead,"SyncRead"},// = 0x0D,				//SyncRead
+		{	KLCmdSyncWrite,	"SyncWrite"},// 					//SyncWrite
+		{	KLCmdSequenRead,"SequenRead"},// 					//Sequence Read
+		{	KLCmdSyncTime,"SyncTime"},// 						//SyncTime
+
+		{	KLCmdGetMode,"GetMode"},//  = 0x12,
+
+		{	KLCmdChkPass,"ChkPass"},// 
+		{	KLCmdSetPass,"SetPass"},// 
+		{	KLCmdEraseAll,"EraseAll"},// 
+		{	KLCmdReadProgram,"ReadProgram"},// 
+		{	KLCmdWriteProgram,"WriteProgram"},// 
+
+		{	KLCmdRead1Bit,"Read1Bit"},//  = 0x21,				//ReadSingleBit
+		{	KLCmdWrite1Bit,"Write1Bit"},//  = 0x22,				//WriteSingleBit
+
+		{	KLCmdReadBits,"ReadBits"},//  = 0x23,				//ReadBits		n = 1 - 8
+		{	KLCmdWriteBits,"WriteBits"},//  = 0x24,				//ReadBits		n = 1 - 8
+
+		{	KLCmdReadBitsByByte,"ReadBitsByByte"},//  = 0x25,			//ReadBitsByByte
+		{	KLCmdWriteBitsByByte,"WriteBitsByByte"},//  = 0x26,		//ReadBitsByByte
+
+		{	KLCmdReadBitsByWord,"ReadBitsByWord"},//  = 0x27,			//ReadBitsByWord
+		{	KLCmdWriteBitsByWord,"WriteBitsByWord"},//  = 0x28,		//ReadBitsByWord
+
+		{	KLCmdReadDataByte,"ReadDataByte"},//  = 0x31,
+		{	KLCmdWriteDataByte,"WriteDataByte"},//  = 0x32,
+
+		{	KLCmdReadDataWord,"ReadDataWord"},//  = 0x33,
+		{	KLCmdWriteDataWord,"WriteDataWord"},//  = 0x34,
+
+		{	KLCmdReadData,"ReadData"},//  = 0x35,
+		{	KLCmdWriteData,"WriteData"},//  = 0x36,
+
+		{	KLCmdReadProg,"ReadProg"},//  = 0x51,
+		{	KLCmdWriteProg,"WriteProg"},// 
+		{	KLCmdReadSysCfg,"ReadSysCfg"},// 
+		{	KLCmdWriteSysCfg,"WriteSysCfg"},// 
+
+		{	KLCmdSaveSysCfg,"SaveSysCfg"},// 
+	//		KLCmdReadRunStat,
+
+
+		{	KLCmdErrRply,"ErrRply"}//  = 0xEE,				//ERRORReply
+	};
+
+	typedef struct tagKLExtDataFrame
+	{
+		UCHAR Dst;
+		UCHAR nType;
+		UCHAR Len2;
+		UCHAR Data[1];
+	}*pKLExtDataFrame;
+
+
+	typedef union tagKLStatDef
+	{
+		UCHAR StatByte;
+		struct {
+			UCHAR nSEQ : 4;
+			UCHAR HasExt : 1;
+			UCHAR HasErr : 1;
+		};
+	}unKLStat, *pKLStat;
+
+	int m_nSeq = 0;
+	int m_nRSeq = 0;
+	unsigned char m_Dst;
+
+	//unsigned char m_Stat;
+
+	unKLStat m_Stat1 = { 0 };
+	unKLStat m_DstStat;
+	typedef struct tagKLReqPacketDef
+	{
+
+		UCHAR StartSign;
+		UCHAR DstAddr;
+		UCHAR Stat;
+		UCHAR Cmd;
+		UCHAR Type1;
+		UCHAR Params[1];
+	}stKLReqPacket, *pKLReqPacket;
+
+	typedef struct tagKLRplyPktHdr
+	{
+		unsigned char RplyStSgn;	//
+		unsigned char DstAddr;		//
+		unsigned char nStatus;		//
+		unsigned char nRplyCMD;		//
+		unsigned char nSize1;			//
+		unsigned char Datas[1];		//
+	}stKLRplyPktHdr, *pKLRplyPktHdr;
+
+	unsigned char m_Packetbuf[256];
+	unsigned char m_SendBuf[1024];
+	unsigned char m_RecvBuf[1024];
+	unsigned char m_DataBuf[1024];
+
+	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;
+		union
+		{
+			unsigned int ClientDatas[10];
+			struct {
+				unsigned int ClientRecvPkts;	//
+				unsigned int ClientSendPkts;	//
+				unsigned int ClientNotPktErr;	//
+				unsigned int ClientMisIdPkts;	//
+				unsigned int ClientPkgLenErr;	//
+				unsigned int ClientBccErr;		//
+				unsigned int ClientTimeOutErr;	//
+			};
+		};
+	} stChnStat, *pChnStat;
+
+	struct tagMEM
+	{
+		union //tagWX
+		{
+			USHORT WX[64];
+			UCHAR WXB[128];
+			UINT WXD[32];
+		};
+		union //tagWY
+		{
+			USHORT WY[64];
+			UCHAR WYB[128];
+			UINT WYD[32];
+		};
+		union //tagDT
+		{
+			USHORT DT[256];
+			UCHAR DTB[512];
+			UINT DTD[128];
+		};
+		union //tagWR
+		{
+			USHORT WR[64];
+			UCHAR WRB[128];
+			UINT WRD[32];
+		};
+		union //tagSDT
+		{
+			UCHAR SDB[512];
+			USHORT SDT[256];
+			UINT SDD[128];
+			struct {
+				unsigned int EffJumperSW;
+				unsigned int CurJumperSW;
+				unsigned int haltick;
+				unsigned int RunStat;
+				unsigned int ErrStat;
+				unsigned int nTickCount;
+				unsigned int TotalRunTime;
+				unsigned int ThisRunTime;
+				unsigned int PwrOnCount;
+				unsigned int LastScanTime;
+				unsigned int ScanTimeuS;
+				unsigned int MinScanTimeuS;
+				unsigned int MaxScanTimeuS;
+				unsigned short ADCValues[20];
+			};
+		};
+	}MEM;
+
+	CString m_resultStr;
+
+	static int xtoi(const char * hexstr, int len = 0);
+	unsigned char KLBCC(void * pData, int nSize);
+
+	int CalCRC(void * pBuf, int nSize);
+
+	/*
+		连接状态
+		开始连接(未定)-> 心跳包正常->已连接 -> 心跳包连续正常 -> 连接很好
+
+		连接很好 -> 心跳包 失败 / 数据包失败 -> 已连接 (有错误)
+
+		已连接 (有错误) -> 心跳包正常 -> 已连接
+
+
+
+	*/
+
+	int fnTest1(int n);
+
+	int ParseReqPacket();
+	int MakeRplyPacket();
+
+	typedef int(*pSend)(void *, int);
+	typedef int(*pRecv)(void *, int);
+	typedef int(*pOpen)(int);
+	typedef int(*pClose)(int);
+
+	// pSend SendPkgFunc;
+	//  pRecv RecvPkgFunc;
+	//  pOpen OpenFunc;
+	//  pClose CloseFunc;
+
+	std::function<int(void *, int)> SendPkgFunc;
+	std::function<int(void *, int)> RecvPkgFunc;
+	std::function<int(int)> OpenFunc;
+	std::function<int(int)> CloseFunc;
+
+
+
+	int m_bSendCallBackSet = 0;
+	int m_bRecvCallBackSet = 0;
+	int m_bOpenCallBackSet = 0;
+	int m_bCloseCallBackSet = 0;
+
+	bool m_bOpened = false;
+
+	int SetSendCallBackFunc(std::function<int(void *, int)> pSendFunc);
+	int SetRecvCallBackFunc(std::function<int(void *, int)> pRecvFunc);
+	int SetOpenCallBackFunc(std::function<int(int)> pOpenFunc);
+	int SetCloseCallBackFunc(std::function<int(int)> pCloseFunc);
+
+	int m_nErrCount = 0;
+	int m_nContinueErrCount = 0;
+	int Open(int OpenParam = 0)
+	{
+		if (m_bOpenCallBackSet)
+		{
+			OpenFunc(OpenParam);
+		}
+		m_bOpened = true;
+		return KL_OK;
+	};
+	int Close(int CloseParam = 0)
+	{
+		if (m_bCloseCallBackSet)
+		{
+			CloseFunc(CloseParam);
+		}
+		m_bOpened = false;
+		return KL_OK;
+	};
+	int SendPacket(void * pBuf, int Len)
+	{
+		if (m_bOpened && m_bSendCallBackSet) return SendPkgFunc(pBuf, Len);
+		else return KL_ERR;
+	}
+
+	int RecvPacket(void * pBuf, int LenToRead, int ReTryCount = 3)
+	{
+
+		if (m_bOpened && m_bRecvCallBackSet)
+		{
+			int len2 = 0;
+			char * pBufByte = (char *)pBuf;
+			for (int i = 0; i < ReTryCount; i++)
+			{
+				int len1 = RecvPkgFunc(pBufByte + len2, LenToRead - len2);
+				len2 += len1;
+				if (len2 >= LenToRead) break;
+			}
+			if (len2 >= LenToRead) {
+				m_nContinueErrCount = 0;
+				return len2;
+			}
+			else if (len2 <= 0) {
+				m_nErrCount++;
+				m_nContinueErrCount++;
+				if (m_nContinueErrCount > 10)
+				{
+					//	Close(-1);
+				}
+				return KL_ERR;
+			}
+			else {
+				return len2;
+			}
+		}
+		else
+		{
+			return KL_ERR;
+		}
+	}
+	int GetNextSeq();
+
+	int MakeExtDataFrame(void * pBuf, UCHAR nDst, UCHAR nType, UCHAR len2, void * pData);
+
+	//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 CheckPackage(void * pBuf, int nSize);
+	int ProcessPacket(void *pBuf, int nLen);
+	int ParseRplyPacket(void *pBuf, int nPkgLen, UCHAR * nCmd, UCHAR * Status, USHORT* nCount, void * pData);
+
+	int GetInfo(UCHAR nDst, UCHAR nWordCount, UCHAR nType, USHORT nWordAddr, USHORT * Values);
+	int GetSN(UCHAR nDst, int * nCount);
+	int GetUID(UCHAR nDst, int * nCount);
+	//int GetTime32(UCHAR nDst, int * nCount);
+	//int SetTime32(UCHAR nDst, int * nCount);
+	int GetDateTime32(UCHAR nDst, UINT * pValue);
+	int SetDateTime32(UCHAR nDst, UINT Value);
+
+
+	int GetEventLogCount(UCHAR nDst, int * nCount);
+	int GetEventLog(UCHAR nDst, int nStartIndex, int nCount, stEventLog * pEventLogs);
+
+
+	int ReadBit(UCHAR nDst, UCHAR nType, USHORT nBitAddr, UCHAR * Value);//Read 1 Single bit
+	int WriteBit(UCHAR nDst, UCHAR nType, USHORT nBitAddr, UCHAR Value);//Write 1 Single bit
+	int ReadBits(UCHAR nDst, UCHAR nBitCount, UCHAR nType, USHORT nBitAddr, UCHAR * Values);
+	int WriteBits(UCHAR nDst, UCHAR nBitCount, UCHAR nType, USHORT nBitAddr, UCHAR * Values);
+	int ReadBitsByWord(UCHAR nDst, UCHAR nWordCount, UCHAR nType, USHORT nWordAddr, USHORT *Values);
+	int WriteBitsByWord(UCHAR nDst, UCHAR nWordCount, UCHAR nType, USHORT nWordAddr, USHORT *Values);
+
+	int ReadDataByte(UCHAR nDst, UCHAR nByteCount, UCHAR nType, USHORT nByteAddr, UCHAR * Values);
+	int WriteDataByte(UCHAR nDst, UCHAR nByteCount, UCHAR nType, USHORT nByteAddr, UCHAR * Values);
+
+	int ReadDataWord(UCHAR nDst, UCHAR nWordCount, UCHAR nType, USHORT nWordAddr, USHORT * Values);
+	int WriteDataWord(UCHAR nDst, UCHAR nWordCount, UCHAR nType, USHORT nWordAddr, USHORT * Values);
+
+	int ReadData(UCHAR nDst, UCHAR nWordCount, UCHAR nType, USHORT nWordAddr, USHORT * Values);
+	int WriteData(UCHAR nDst, UCHAR nWordCount, UCHAR nType, USHORT nWordAddr, USHORT * Values);
+
+	int GetMode(UCHAR nDst, UCHAR nType);
+	int ChangeMode(UCHAR nDst, UCHAR nType);
+
+
+	int ReadProgram(UCHAR nDst, UCHAR nType, USHORT nWordAddr, UCHAR nWordCount, USHORT * Values);
+
+	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 ReadRunStat(UCHAR nDst, UCHAR nType, USHORT nWordAddr, UCHAR nWordCount, USHORT * Values);
+
+
+};
+
diff --git a/KLink2/KLink2.cpp b/KLink2/KLink2.cpp
new file mode 100644
index 0000000..26ec597
--- /dev/null
+++ b/KLink2/KLink2.cpp
@@ -0,0 +1,101 @@
+锘�// KLink2.cpp: 瀹氫箟 DLL 鐨勫垵濮嬪寲渚嬬▼銆�
+//
+
+#include "pch.h"
+#include "framework.h"
+#include "KLink2.h"
+#include "afxdialogex.h"
+#include "CDialogCommSet1.h"
+
+#ifdef _DEBUG
+#define new DEBUG_NEW
+#endif
+
+//
+//TODO:  濡傛灉姝� DLL 鐩稿浜� MFC DLL 鏄姩鎬侀摼鎺ョ殑锛�
+//		鍒欎粠姝� DLL 瀵煎嚭鐨勪换浣曡皟鍏�
+//		MFC 鐨勫嚱鏁板繀椤诲皢 AFX_MANAGE_STATE 瀹忔坊鍔犲埌
+//		璇ュ嚱鏁扮殑鏈�鍓嶉潰銆�
+//
+//		渚嬪: 
+//
+//		extern "C" BOOL PASCAL EXPORT ExportedFunction()
+//		{
+//			AFX_MANAGE_STATE(AfxGetStaticModuleState());
+//			// 姝ゅ涓烘櫘閫氬嚱鏁颁綋
+//		}
+//
+//		姝ゅ畯鍏堜簬浠讳綍 MFC 璋冪敤
+//		鍑虹幇鍦ㄦ瘡涓嚱鏁颁腑鍗佸垎閲嶈銆�  杩欐剰鍛崇潃
+//		瀹冨繀椤讳綔涓轰互涓嬮」涓殑绗竴涓鍙�:
+//		鍑虹幇锛岀敋鑷冲厛浜庢墍鏈夊璞″彉閲忓0鏄庯紝
+//		杩欐槸鍥犱负瀹冧滑鐨勬瀯閫犲嚱鏁板彲鑳界敓鎴� MFC
+//		DLL 璋冪敤銆�
+//
+//		鏈夊叧鍏朵粬璇︾粏淇℃伅锛�
+//		璇峰弬闃� MFC 鎶�鏈鏄� 33 鍜� 58銆�
+//
+
+// CKLink2App
+
+BEGIN_MESSAGE_MAP(CKLink2App, CWinApp)
+END_MESSAGE_MAP()
+
+
+// CKLink2App 鏋勯��
+
+CKLink2App::CKLink2App()
+{
+	// TODO:  鍦ㄦ澶勬坊鍔犳瀯閫犱唬鐮侊紝
+	// 灏嗘墍鏈夐噸瑕佺殑鍒濆鍖栨斁缃湪 InitInstance 涓�
+}
+
+
+// 鍞竴鐨� CKLink2App 瀵硅薄
+
+CKLink2App theApp;
+
+
+// CKLink2App 鍒濆鍖�
+
+BOOL CKLink2App::InitInstance()
+{
+	CWinApp::InitInstance();
+
+	if (!AfxSocketInit())
+	{
+		AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
+		return FALSE;
+	}
+	
+	return TRUE;
+}
+
+
+int CKLink2App::ExitInstance()
+{
+	// TODO: 鍦ㄦ娣诲姞涓撶敤浠g爜鍜�/鎴栬皟鐢ㄥ熀绫�
+
+	return CWinApp::ExitInstance();
+}
+
+int DoConfig(int n)
+{
+	//AFX_MANAGE_STATE(AfxGetStaticModuleState());
+
+	//鏂规硶2鐨勭姸鎬佸彉鏇�
+	HINSTANCE save_hInstance = AfxGetResourceHandle();
+
+	AfxSetResourceHandle(theApp.m_hInstance);
+
+//	CDialog dlg(IDD_DLL_DIALOG);//鎵撳紑ID涓�2000鐨勫璇濇
+//	dlg.DoModal();
+	
+	CDialogCommSet1 dialog1;
+	INT_PTR r = dialog1.DoModal();
+	//鏂规硶2鐨勭姸鎬佽繕鍘�
+
+	AfxSetResourceHandle(save_hInstance);
+
+	return 0;
+}
\ No newline at end of file
diff --git a/KLink2/KLink2.def b/KLink2/KLink2.def
new file mode 100644
index 0000000..7917457
--- /dev/null
+++ b/KLink2/KLink2.def
@@ -0,0 +1,7 @@
+锘�; KLink2.def: 澹版槑 DLL 鐨勬ā鍧楀弬鏁般��
+
+LIBRARY
+
+EXPORTS
+    ; 姝ゅ鍙互鏄樉寮忓鍑�
+	DoConfig
diff --git a/KLink2/KLink2.h b/KLink2/KLink2.h
new file mode 100644
index 0000000..7c4cb39
--- /dev/null
+++ b/KLink2/KLink2.h
@@ -0,0 +1,29 @@
+锘�// KLink2.h: KLink2 DLL 鐨勪富鏍囧ご鏂囦欢
+//
+
+#pragma once
+
+#ifndef __AFXWIN_H__
+	#error "include 'pch.h' before including this file for PCH"
+#endif
+
+#include "resource.h"		// 涓荤鍙�
+
+
+// CKLink2App
+// 鏈夊叧姝ょ被瀹炵幇鐨勪俊鎭紝璇峰弬闃� KLink2.cpp
+//
+
+class CKLink2App : public CWinApp
+{
+public:
+	CKLink2App();
+
+// 閲嶅啓
+public:
+	virtual BOOL InitInstance();
+
+	DECLARE_MESSAGE_MAP()
+	virtual int ExitInstance();
+};
+
diff --git a/KLink2/KLink2.rc b/KLink2/KLink2.rc
new file mode 100644
index 0000000..7565944
--- /dev/null
+++ b/KLink2/KLink2.rc
Binary files differ
diff --git a/KLink2/KLink2.vcxproj b/KLink2/KLink2.vcxproj
new file mode 100644
index 0000000..cf49369
--- /dev/null
+++ b/KLink2/KLink2.vcxproj
@@ -0,0 +1,220 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="15.0" 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>15.0</VCProjectVersion>
+    <ProjectGuid>{1F782E34-9087-4F87-9674-E4BDAA319726}</ProjectGuid>
+    <Keyword>MFCDLLProj</Keyword>
+    <RootNamespace>KLink2</RootNamespace>
+    <WindowsTargetPlatformVersion>10.0.17763.0</WindowsTargetPlatformVersion>
+    <ProjectName>KLink2</ProjectName>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
+    <ConfigurationType>DynamicLibrary</ConfigurationType>
+    <UseDebugLibraries>true</UseDebugLibraries>
+    <PlatformToolset>v141</PlatformToolset>
+    <CharacterSet>Unicode</CharacterSet>
+    <UseOfMfc>Dynamic</UseOfMfc>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+    <ConfigurationType>DynamicLibrary</ConfigurationType>
+    <UseDebugLibraries>false</UseDebugLibraries>
+    <PlatformToolset>v141</PlatformToolset>
+    <WholeProgramOptimization>true</WholeProgramOptimization>
+    <CharacterSet>Unicode</CharacterSet>
+    <UseOfMfc>Dynamic</UseOfMfc>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
+    <ConfigurationType>DynamicLibrary</ConfigurationType>
+    <UseDebugLibraries>true</UseDebugLibraries>
+    <PlatformToolset>v141</PlatformToolset>
+    <CharacterSet>Unicode</CharacterSet>
+    <UseOfMfc>Dynamic</UseOfMfc>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
+    <ConfigurationType>DynamicLibrary</ConfigurationType>
+    <UseDebugLibraries>false</UseDebugLibraries>
+    <PlatformToolset>v141</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>
+      <Optimization>Disabled</Optimization>
+      <SDLCheck>true</SDLCheck>
+      <PreprocessorDefinitions>KLINK_EXPORTS;_WINDOWS;_DEBUG;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
+    </ClCompile>
+    <Link>
+      <SubSystem>Windows</SubSystem>
+      <ModuleDefinitionFile>.\KLink2.def</ModuleDefinitionFile>
+    </Link>
+    <Midl>
+      <MkTypLibCompatible>false</MkTypLibCompatible>
+      <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>
+      <Optimization>Disabled</Optimization>
+      <SDLCheck>true</SDLCheck>
+      <PreprocessorDefinitions>WIN32;_WINDOWS;_DEBUG;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
+    </ClCompile>
+    <Link>
+      <SubSystem>Windows</SubSystem>
+      <ModuleDefinitionFile>.\KLink2.def</ModuleDefinitionFile>
+    </Link>
+    <Midl>
+      <MkTypLibCompatible>false</MkTypLibCompatible>
+      <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>
+      <Optimization>MaxSpeed</Optimization>
+      <FunctionLevelLinking>true</FunctionLevelLinking>
+      <IntrinsicFunctions>true</IntrinsicFunctions>
+      <SDLCheck>true</SDLCheck>
+      <PreprocessorDefinitions>WIN32;_WINDOWS;NDEBUG;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
+    </ClCompile>
+    <Link>
+      <SubSystem>Windows</SubSystem>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
+      <OptimizeReferences>true</OptimizeReferences>
+      <ModuleDefinitionFile>.\KLink2.def</ModuleDefinitionFile>
+    </Link>
+    <Midl>
+      <MkTypLibCompatible>false</MkTypLibCompatible>
+      <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>
+      <Optimization>MaxSpeed</Optimization>
+      <FunctionLevelLinking>true</FunctionLevelLinking>
+      <IntrinsicFunctions>true</IntrinsicFunctions>
+      <SDLCheck>true</SDLCheck>
+      <PreprocessorDefinitions>_WINDOWS;NDEBUG;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
+    </ClCompile>
+    <Link>
+      <SubSystem>Windows</SubSystem>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
+      <OptimizeReferences>true</OptimizeReferences>
+      <ModuleDefinitionFile>.\KLink2.def</ModuleDefinitionFile>
+    </Link>
+    <Midl>
+      <MkTypLibCompatible>false</MkTypLibCompatible>
+      <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+    </Midl>
+    <ResourceCompile>
+      <Culture>0x0804</Culture>
+      <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+    </ResourceCompile>
+  </ItemDefinitionGroup>
+  <ItemGroup>
+    <ClCompile Include="CDialogCommSet1.cpp" />
+    <ClCompile Include="KLink.cpp" />
+    <ClCompile Include="KLink2.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>
+    <None Include="KLink2.def" />
+    <None Include="res\KLink2.rc2" />
+  </ItemGroup>
+  <ItemGroup>
+    <ClInclude Include="CDialogCommSet1.h" />
+    <ClInclude Include="framework.h" />
+    <ClInclude Include="KLink.h" />
+    <ClInclude Include="KLink2.h" />
+    <ClInclude Include="pch.h" />
+    <ClInclude Include="Resource.h" />
+    <ClInclude Include="targetver.h" />
+  </ItemGroup>
+  <ItemGroup>
+    <ResourceCompile Include="KLink2.rc" />
+  </ItemGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+  <ImportGroup Label="ExtensionTargets">
+  </ImportGroup>
+</Project>
\ No newline at end of file
diff --git a/KLink2/KLink2.vcxproj.filters b/KLink2/KLink2.vcxproj.filters
new file mode 100644
index 0000000..5ecf439
--- /dev/null
+++ b/KLink2/KLink2.vcxproj.filters
@@ -0,0 +1,67 @@
+锘�<?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;def;odl;idl;hpj;bat;asm;asmx</Extensions>
+    </Filter>
+    <Filter Include="澶存枃浠�">
+      <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
+      <Extensions>h;hh;hpp;hxx;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>
+    <ClCompile Include="KLink2.cpp">
+      <Filter>婧愭枃浠�</Filter>
+    </ClCompile>
+    <ClCompile Include="pch.cpp">
+      <Filter>婧愭枃浠�</Filter>
+    </ClCompile>
+    <ClCompile Include="CDialogCommSet1.cpp">
+      <Filter>婧愭枃浠�</Filter>
+    </ClCompile>
+    <ClCompile Include="KLink.cpp">
+      <Filter>婧愭枃浠�</Filter>
+    </ClCompile>
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="KLink2.def">
+      <Filter>婧愭枃浠�</Filter>
+    </None>
+    <None Include="res\KLink2.rc2">
+      <Filter>璧勬簮鏂囦欢</Filter>
+    </None>
+  </ItemGroup>
+  <ItemGroup>
+    <ClInclude Include="framework.h">
+      <Filter>澶存枃浠�</Filter>
+    </ClInclude>
+    <ClInclude Include="targetver.h">
+      <Filter>澶存枃浠�</Filter>
+    </ClInclude>
+    <ClInclude Include="Resource.h">
+      <Filter>澶存枃浠�</Filter>
+    </ClInclude>
+    <ClInclude Include="KLink2.h">
+      <Filter>澶存枃浠�</Filter>
+    </ClInclude>
+    <ClInclude Include="pch.h">
+      <Filter>澶存枃浠�</Filter>
+    </ClInclude>
+    <ClInclude Include="CDialogCommSet1.h">
+      <Filter>澶存枃浠�</Filter>
+    </ClInclude>
+    <ClInclude Include="KLink.h">
+      <Filter>澶存枃浠�</Filter>
+    </ClInclude>
+  </ItemGroup>
+  <ItemGroup>
+    <ResourceCompile Include="KLink2.rc">
+      <Filter>璧勬簮鏂囦欢</Filter>
+    </ResourceCompile>
+  </ItemGroup>
+</Project>
\ No newline at end of file
diff --git a/KLink2/Resource.h b/KLink2/Resource.h
new file mode 100644
index 0000000..d83ed85
--- /dev/null
+++ b/KLink2/Resource.h
@@ -0,0 +1,34 @@
+锘�//{{NO_DEPENDENCIES}}
+// Microsoft Visual C++ 鐢熸垚鐨勫寘鍚枃浠躲��
+// 渚� KLink2.rc 浣跨敤
+//
+#define IDP_SOCKETS_INIT_FAILED         104
+#define IDD_DIALOG_COMMSET1             137
+#define IDC_BUTTON_INIT                 1039
+#define IDC_BUTTON2                     1040
+#define IDC_COMBO_NETWORK_TYPE          1041
+#define IDC_COMBO_PORT                  1042
+#define IDC_COMBO_BAUD                  1043
+#define IDC_COMBO_COMM_TIMEOUT          1044
+#define IDC_RADIO_DATA_LENGTH_7B        1045
+#define IDC_RADIO_DATA_LENGTH_8B        1046
+#define IDC_RADIO_STOP_1B               1047
+#define IDC_RADIO_STOP_2B               1048
+#define IDC_RADIO_PARITY_NONE           1049
+#define IDC_RADIO_PARITY_ODD            1050
+#define IDC_RADIO_PARITY_EVEN           1051
+#define IDC_RADIO_PARITY_0              1052
+#define IDC_CHECK_AUTO_BAUD             1053
+#define IDC_CHECK_AUTO_DATA_LENGTH      1054
+#define IDC_CHECK_AUTO_PARITY           1055
+
+// Next default values for new objects
+// 
+#ifdef APSTUDIO_INVOKED
+#ifndef APSTUDIO_READONLY_SYMBOLS
+#define _APS_NEXT_RESOURCE_VALUE        1000
+#define _APS_NEXT_COMMAND_VALUE         32771
+#define _APS_NEXT_CONTROL_VALUE         1000
+#define _APS_NEXT_SYMED_VALUE           1000
+#endif
+#endif
diff --git a/KLink2/framework.h b/KLink2/framework.h
new file mode 100644
index 0000000..ac1c66f
--- /dev/null
+++ b/KLink2/framework.h
@@ -0,0 +1,36 @@
+锘�#pragma once
+
+#ifndef VC_EXTRALEAN
+#define VC_EXTRALEAN            // 浠� Windows 澶翠腑鎺掗櫎鏋佸皯浣跨敤鐨勮祫鏂�
+#endif
+
+#include "targetver.h"
+
+#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS      // 鏌愪簺 CString 鏋勯�犲嚱鏁板皢鏄樉寮忕殑
+
+#include <afxwin.h>         // MFC 鏍稿績缁勪欢鍜屾爣鍑嗙粍浠�
+#include <afxext.h>         // MFC 鎵╁睍
+
+#ifndef _AFX_NO_OLE_SUPPORT
+#include <afxole.h>         // MFC OLE 绫�
+#include <afxodlgs.h>       // MFC OLE 瀵硅瘽妗嗙被
+#include <afxdisp.h>        // MFC 鑷姩鍖栫被
+#endif // _AFX_NO_OLE_SUPPORT
+
+#ifndef _AFX_NO_DB_SUPPORT
+#include <afxdb.h>                      // MFC ODBC 鏁版嵁搴撶被
+#endif // _AFX_NO_DB_SUPPORT
+
+#ifndef _AFX_NO_DAO_SUPPORT
+#include <afxdao.h>                     // MFC DAO 鏁版嵁搴撶被
+#endif // _AFX_NO_DAO_SUPPORT
+
+#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 <afxsock.h>            // MFC 濂楁帴瀛楁墿灞�
+
diff --git a/KLink2/pch.cpp b/KLink2/pch.cpp
new file mode 100644
index 0000000..db1a479
--- /dev/null
+++ b/KLink2/pch.cpp
@@ -0,0 +1,5 @@
+锘�// pch.cpp: 涓庨缂栬瘧鏍囧ご瀵瑰簲鐨勬簮鏂囦欢
+
+#include "pch.h"
+
+// 褰撲娇鐢ㄩ缂栬瘧鐨勫ご鏃讹紝闇�瑕佷娇鐢ㄦ婧愭枃浠讹紝缂栬瘧鎵嶈兘鎴愬姛銆�
diff --git a/KLink2/pch.h b/KLink2/pch.h
new file mode 100644
index 0000000..aa4549e
--- /dev/null
+++ b/KLink2/pch.h
@@ -0,0 +1,13 @@
+锘�// pch.h: 杩欐槸棰勭紪璇戞爣澶存枃浠躲��
+// 涓嬫柟鍒楀嚭鐨勬枃浠朵粎缂栬瘧涓�娆★紝鎻愰珮浜嗗皢鏉ョ敓鎴愮殑鐢熸垚鎬ц兘銆�
+// 杩欒繕灏嗗奖鍝� IntelliSense 鎬ц兘锛屽寘鎷唬鐮佸畬鎴愬拰璁稿浠g爜娴忚鍔熻兘銆�
+// 浣嗘槸锛屽鏋滄澶勫垪鍑虹殑鏂囦欢涓殑浠讳綍涓�涓湪鐢熸垚涔嬮棿鏈夋洿鏂帮紝瀹冧滑鍏ㄩ儴閮藉皢琚噸鏂扮紪璇戙��
+// 璇峰嬁鍦ㄦ澶勬坊鍔犺棰戠箒鏇存柊鐨勬枃浠讹紝杩欏皢浣垮緱鎬ц兘浼樺娍鏃犳晥銆�
+
+#ifndef PCH_H
+#define PCH_H
+
+// 娣诲姞瑕佸湪姝ゅ棰勭紪璇戠殑鏍囧ご
+#include "framework.h"
+
+#endif //PCH_H
diff --git a/KLink2/res/KLink2.rc2 b/KLink2/res/KLink2.rc2
new file mode 100644
index 0000000..8a55539
--- /dev/null
+++ b/KLink2/res/KLink2.rc2
Binary files differ
diff --git a/KLink2/targetver.h b/KLink2/targetver.h
new file mode 100644
index 0000000..d7bf688
--- /dev/null
+++ b/KLink2/targetver.h
@@ -0,0 +1,8 @@
+锘�#pragma once
+
+// 鍖呮嫭 SDKDDKVer.h 灏嗗畾涔夊彲鐢ㄧ殑鏈�楂樼増鏈殑 Windows 骞冲彴銆�
+
+// 濡傛灉瑕佷负浠ュ墠鐨� Windows 骞冲彴鐢熸垚搴旂敤绋嬪簭锛岃鍖呮嫭 WinSDKVer.h锛屽苟灏�
+// 灏� _WIN32_WINNT 瀹忚缃负瑕佹敮鎸佺殑骞冲彴锛岀劧鍚庡啀鍖呮嫭 SDKDDKVer.h銆�
+
+#include <SDKDDKVer.h>
diff --git a/MTerm1.sln b/MTerm1.sln
index 8d971d2..bd1b92d 100644
--- a/MTerm1.sln
+++ b/MTerm1.sln
@@ -11,6 +11,10 @@
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MTerm1", "MTerm1\MTerm1.vcxproj", "{7AA827E9-4264-4C9C-A5EA-A04CA08C6D12}"
 EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "KLink1", "KLink1\KLink1.vcxproj", "{A9132770-20D8-423A-8F25-4B5F5B4459D3}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "KLink2", "KLink2\KLink2.vcxproj", "{1F782E34-9087-4F87-9674-E4BDAA319726}"
+EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|x64 = Debug|x64
@@ -51,6 +55,22 @@
 		{7AA827E9-4264-4C9C-A5EA-A04CA08C6D12}.Release|x64.Build.0 = Release|x64
 		{7AA827E9-4264-4C9C-A5EA-A04CA08C6D12}.Release|x86.ActiveCfg = Release|Win32
 		{7AA827E9-4264-4C9C-A5EA-A04CA08C6D12}.Release|x86.Build.0 = Release|Win32
+		{A9132770-20D8-423A-8F25-4B5F5B4459D3}.Debug|x64.ActiveCfg = Debug|x64
+		{A9132770-20D8-423A-8F25-4B5F5B4459D3}.Debug|x64.Build.0 = Debug|x64
+		{A9132770-20D8-423A-8F25-4B5F5B4459D3}.Debug|x86.ActiveCfg = Debug|Win32
+		{A9132770-20D8-423A-8F25-4B5F5B4459D3}.Debug|x86.Build.0 = Debug|Win32
+		{A9132770-20D8-423A-8F25-4B5F5B4459D3}.Release|x64.ActiveCfg = Release|x64
+		{A9132770-20D8-423A-8F25-4B5F5B4459D3}.Release|x64.Build.0 = Release|x64
+		{A9132770-20D8-423A-8F25-4B5F5B4459D3}.Release|x86.ActiveCfg = Release|Win32
+		{A9132770-20D8-423A-8F25-4B5F5B4459D3}.Release|x86.Build.0 = Release|Win32
+		{1F782E34-9087-4F87-9674-E4BDAA319726}.Debug|x64.ActiveCfg = Debug|x64
+		{1F782E34-9087-4F87-9674-E4BDAA319726}.Debug|x64.Build.0 = Debug|x64
+		{1F782E34-9087-4F87-9674-E4BDAA319726}.Debug|x86.ActiveCfg = Debug|Win32
+		{1F782E34-9087-4F87-9674-E4BDAA319726}.Debug|x86.Build.0 = Debug|Win32
+		{1F782E34-9087-4F87-9674-E4BDAA319726}.Release|x64.ActiveCfg = Release|x64
+		{1F782E34-9087-4F87-9674-E4BDAA319726}.Release|x64.Build.0 = Release|x64
+		{1F782E34-9087-4F87-9674-E4BDAA319726}.Release|x86.ActiveCfg = Release|Win32
+		{1F782E34-9087-4F87-9674-E4BDAA319726}.Release|x86.Build.0 = Release|Win32
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE
diff --git a/MTerm2/MTerm2.cpp b/MTerm2/MTerm2.cpp
index f06c4e3..3d6e525 100644
--- a/MTerm2/MTerm2.cpp
+++ b/MTerm2/MTerm2.cpp
@@ -44,8 +44,9 @@
 #pragma comment(lib,"SetupAPI.lib")
 #pragma comment(lib,"gdiplus.lib")
 
+#include "../KLink2/KLink.h"
 
-
+#pragma comment(lib,"KLink2.lib")
 MHash MyCfg1;
 Logger myLogger1;
 
diff --git a/MTerm2/MTerm2.vcxproj b/MTerm2/MTerm2.vcxproj
index b4491a4..9bdc6a9 100644
--- a/MTerm2/MTerm2.vcxproj
+++ b/MTerm2/MTerm2.vcxproj
@@ -80,6 +80,7 @@
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
     <LinkIncremental>true</LinkIncremental>
+    <LibraryPath>$(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64);$(NETFXKitsDir)Lib\um\x64;D:\WORK\VC_WORK\MTerm1\x64\Debug</LibraryPath>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
     <LinkIncremental>false</LinkIncremental>
diff --git a/MTerm2/MTerm2CommDevView.cpp b/MTerm2/MTerm2CommDevView.cpp
index d146392..04b3203 100644
--- a/MTerm2/MTerm2CommDevView.cpp
+++ b/MTerm2/MTerm2CommDevView.cpp
@@ -9,6 +9,7 @@
 #include "framework.h"
 #include "MTerm2.h"
 #include "MTerm2Doc.h"
+#include "ChildFrm.h"
 
 #include "MTerm2CommDevView.h"
 
@@ -165,7 +166,8 @@
 {
 	CFormView::OnInitialUpdate();
 	// TODO: 鍦ㄦ娣诲姞涓撶敤浠g爜鍜�/鎴栬皟鐢ㄥ熀绫�
-
+//	ResizeParentToFit();
+//	((CChildFrame *)GetParentFrame())->RecalcLayout();
 	m_bResourceOpened = 0;
 
 	LoadResourceList();
@@ -237,7 +239,7 @@
 	//	InitCamera();
 	//	InitPlcComm();
 		//	InitAnalyzer();
-	SetTimer(1, 50, NULL);  //plc
+	SetTimer(1, 20, NULL);  //plc
 	SetTimer(3, 300, NULL);	//Analyzer
 	SetTimer(4, 1000, NULL); //Speed;
 	m_static_connect.SetCtlColor(RGB(255, 0, 0));
@@ -365,9 +367,9 @@
 		s1.Empty();
 		s1.Format(_T("涓绘満\r\n"));
 
-		s1.AppendFormat(_T("璺崇嚎 %02X %s 褰撳墠 %02X\r\n"), pDoc->MyKLink1.MEM.SDD[0], intToBinString(pDoc->MyKLink1.MEM.SDD[0]), pDoc->MyKLink1.MEM.SDD[1]);
+		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("Tick璁℃暟 %u \r\n"), pDoc->MyKLink1.MEM.SDD[2]);
+		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]);
@@ -404,7 +406,7 @@
 		s3 = ctime1.Format(_T("%Y-%m-%d %H:%M:%S"));
 		s1.Append(s3 + _T("\r\n"));
 
-		s1.AppendFormat(_T("12 LastScanTime uS %d \r\n"), pDoc->MyKLink1.MEM.SDD[12]);
+		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]);
@@ -417,17 +419,19 @@
 		s1.AppendFormat(_T("22 %d \r\n"), pDoc->MyKLink1.MEM.SDD[22]);
 		s1.AppendFormat(_T("23 %d \r\n"), pDoc->MyKLink1.MEM.SDD[23]);
 
-		float Vref = 1.215f;
-		float V33 = Vref * 4096 / pDoc->MyKLink1.MEM.SDT[55];
+		float Vref = 1.2f;
+		float Vcor = (float)pDoc->MyKLink1.MEM.SDT[53] / pDoc->MyKLink1.MEM.SDT[55];
+		float V33 = 3.3f * Vcor;
 
-		s1.AppendFormat(_T("24 %d %.3f \r\n"), pDoc->MyKLink1.MEM.SDT[48], pDoc->MyKLink1.MEM.SDT[48] * V33 / 4096 * 11);
+		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 %d %.3f \r\n"), pDoc->MyKLink1.MEM.SDT[50], pDoc->MyKLink1.MEM.SDT[50] * V33 / 4096 * 2);
+		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]);
-		s1.AppendFormat(_T("30 %d \r\n"), pDoc->MyKLink1.MEM.SDT[54]);
-		s1.AppendFormat(_T("31 %d %.3f \r\n"), pDoc->MyKLink1.MEM.SDT[55], V33);
+		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);
 
 
 
diff --git a/MTerm2/MTerm2CtrlView.cpp b/MTerm2/MTerm2CtrlView.cpp
index 67eb5d7..f9a4ccd 100644
--- a/MTerm2/MTerm2CtrlView.cpp
+++ b/MTerm2/MTerm2CtrlView.cpp
@@ -160,6 +160,9 @@
 void CMTerm2CtrlView::OnBnClickedButton4()
 {
 	// TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
+	CMTerm2Doc * pDoc = (CMTerm2Doc *)GetDocument();
+	pDoc->MyKlink2.fnTest1(2);
+
 	CRect rect1;
 	this->GetClientRect(&rect1);
 //	this->GetParentFrame()->SetWindowPos(NULL, rect1.left, rect1.top, 100, 200, SWP_NOZORDER);
diff --git a/MTerm2/MTerm2Doc.cpp b/MTerm2/MTerm2Doc.cpp
index 9ee69b6..4eab988 100644
--- a/MTerm2/MTerm2Doc.cpp
+++ b/MTerm2/MTerm2Doc.cpp
@@ -67,7 +67,7 @@
 };
 int CMTerm2Doc::nDataTypeDefCount = sizeof(CMTerm2Doc::DataTypeDef) / sizeof(stTypeDef);
 
-CMTerm2Doc::stProgDef CMTerm2Doc::ProgDef[] =
+CMTerm2Doc::stOpDef CMTerm2Doc::OpDef[] =
 {
 	{OP_NOP,"NOP",0},
 	{OP_ST,"ST",1,KLParamCoil},
@@ -126,7 +126,7 @@
 
 
 };
-int CMTerm2Doc::nProgDefCount = sizeof(CMTerm2Doc::ProgDef) / sizeof(stProgDef);
+int CMTerm2Doc::nOpDefCount = sizeof(CMTerm2Doc::OpDef) / sizeof(stOpDef);
 
 IMPLEMENT_DYNCREATE(CMTerm2Doc, CDocument)
 
@@ -429,20 +429,20 @@
 
 int CMTerm2Doc::TxtToOp(CStringA optxt, int* ParamCount, int* ParamType)
 {
-	for (int i = 0; i < nProgDefCount; i++){
-		if (ProgDef[i].OpTxt == optxt)	{
-			*ParamCount = ProgDef[i].nParamCount;
-			*ParamType = ProgDef[i].nParamType;
-			return ProgDef[i].nOpType1;
+	for (int i = 0; i < nOpDefCount; i++){
+		if (OpDef[i].OpTxt == optxt)	{
+			*ParamCount = OpDef[i].nParamCount;
+			*ParamType = OpDef[i].nParamType;
+			return OpDef[i].nOpType1;
 		}
 	}
 	return -1;
 }
 int CMTerm2Doc::OpToTxt(int nOp, CStringA & OpTxt)
 {
-	for (int i = 0; i < nProgDefCount; i++){
-		if (ProgDef[i].nOpType1 == nOp) {
-			OpTxt = ProgDef[i].OpTxt;
+	for (int i = 0; i < nOpDefCount; i++){
+		if (OpDef[i].nOpType1 == nOp) {
+			OpTxt = OpDef[i].OpTxt;
 			return true;
 		}
 	}
@@ -451,9 +451,9 @@
 
 int CMTerm2Doc::OpToShowTxt(int nOp, CStringA & OpShowTxt)
 {
-	for (int i = 0; i < nProgDefCount; i++) {
-		if (ProgDef[i].nOpType1 == nOp) {
-			OpShowTxt = ProgDef[i].ShowTxt;
+	for (int i = 0; i < nOpDefCount; i++) {
+		if (OpDef[i].nOpType1 == nOp) {
+			OpShowTxt = OpDef[i].ShowTxt;
 			return true;
 		}
 	}
diff --git a/MTerm2/MTerm2Doc.h b/MTerm2/MTerm2Doc.h
index c9167dd..af33870 100644
--- a/MTerm2/MTerm2Doc.h
+++ b/MTerm2/MTerm2Doc.h
@@ -11,6 +11,10 @@
 #include "KLink.h"
 #include "KMachine.h"
 
+#include "../KLink2/KLink.h"
+
+#pragma comment(lib,"KLink2.lib")
+
 class CMTerm2Doc : public CDocument
 {
 protected: // 浠呬粠搴忓垪鍖栧垱寤�
@@ -26,7 +30,7 @@
 	// CSerialCom MySerialCom1;
 	HvSerialPort myHvSerialPort1;
 	KMachine myKMachine1;
-
+	KLink2 MyKlink2;
 
 
 	bool m_bCommParamSet = false;
@@ -69,7 +73,7 @@
 		KLParamNum,
 
 	};
-	struct stProgDef
+	struct stOpDef
 	{
 		int nOpType1;
 		CStringA OpTxt;
@@ -77,9 +81,9 @@
 		int nParamType;
 		CStringA ShowTxt;
 	};
-	static stProgDef ProgDef[];
+	static stOpDef OpDef[];
 
-	static int nProgDefCount;
+	static int nOpDefCount;
 	struct stParam
 	{
 		CStringA sParamStr;
diff --git a/MTerm2/MTerm2View.cpp b/MTerm2/MTerm2View.cpp
index 54b99ed..067a778 100644
--- a/MTerm2/MTerm2View.cpp
+++ b/MTerm2/MTerm2View.cpp
@@ -16,7 +16,7 @@
 #include "DialogSetCoil.h"
 #include "DialogSetData.h"
 #include "DialogIoComment.h"
-
+#include "KDefine.h"
 
 #ifdef _DEBUG
 #define new DEBUG_NEW
@@ -209,6 +209,34 @@
 	return 0;
 }
 
+int CMTerm2View::ScrollToCell(int nRow, int nCol)
+{
+	int CellTotalHeight = m_CellHeight + (m_bShowComments ? m_CommentHeight : 0);
+
+	CSize sizeTotal;
+	// TODO: 璁$畻姝よ鍥剧殑鍚堣澶у皬
+	sizeTotal.cx = m_LeftMargin + m_CellWidth * m_CellPerLine + m_CellWidth * 2;
+	sizeTotal.cy = m_TopMargin + CellTotalHeight * (m_nTotalRow );
+	CSize sizeSb;
+	GetScrollBarSizes(sizeSb);
+	POINT pt1;
+	pt1.x = 0;
+	pt1.y = nRow * CellTotalHeight;
+	ScrollToPosition(pt1);
+	return 0;
+}
+
+int CMTerm2View::ScrollCellIntoView(int nRow, int nCol)
+{
+	int CellTotalHeight = m_CellHeight + (m_bShowComments ? m_CommentHeight : 0);
+	return 0;
+}
+
+int CMTerm2View::isCellInView(int nRow, int nCol)
+{
+	int CellTotalHeight = m_CellHeight + (m_bShowComments ? m_CommentHeight : 0);
+	return 0;
+}
 
 int CMTerm2View::DrawLDSGraph(CDC* pDC)
 {
@@ -2265,6 +2293,7 @@
 int CMTerm2View::TransLDSToProg()
 {
 	// TODO: 鍦ㄦ澶勬坊鍔犲疄鐜颁唬鐮�.
+	CMTerm2Doc * pDoc = GetDocument();
 	CString s1;
 	s1.Format(_T("Trans LDS to PRrog"));
 	DbgLog(s1);
@@ -2292,6 +2321,7 @@
 			nDivCount++;
 		}
 	}
+	stProgSection allprogs;
 	//姣忔鍗曠嫭澶勭悊
 	for (int i = 0; i < nDivCount; i++)	{
 		int nStartLine, nEndLine;
@@ -2342,25 +2372,54 @@
 		nCurPosX = 0;
 		CString sProg;
 		int nAllSteps=0;
+		stProgSection Progsec;
 		for (int i = nStartLine; i <= nEndLine; i++){
-			CString ProgSec;
+			CString sProgSec;
 			int nSteps = 0;;
 			nCurPosY = i;
+			stProgSection thisprogsec;
 			if (Cells[i][0].nType)
-			ScanLDSCells(nStartLine, nEndLine, nCurPosY, nCurPosX, 0, ProgSec,nSteps);
-			sProg += ProgSec;
+			ScanLDSCells(nStartLine, nEndLine, nCurPosY, nCurPosX, 0, thisprogsec, sProgSec,nSteps);
+			sProg += sProgSec;
 			nAllSteps += nSteps;
+			Progsec += thisprogsec;
 		}
 		DbgLog(_T("\r\n")+ sProg);
+		int n = Progsec.Progs.size();
+		s1.Format(_T("progSec steps %d "), n);
+		DbgLog(s1);
+		for (int i = 0; i < n; i++) {
+			int optype = Progsec.Progs[i].nOpType1;
+			CStringA OpTxtA, OpShowTxtA;
+			CString OpTxt, OpShowTxt;
+			pDoc->OpToTxt(optype, OpTxtA);
+			pDoc->OpToShowTxt(optype, OpShowTxtA);
+			OpTxt = OpTxtA;
+			OpShowTxt = OpShowTxtA;
+			s1.Format(_T("%d %s %s"), optype, OpTxt, OpShowTxt);
+			DbgLog(s1);
+		}
+		allprogs += Progsec;
 	}
 	//杈撳嚭绋嬪簭
-
-
-
+	int n=allprogs.Progs.size();
+	s1.Format(_T("all prog steps %d "), n);
+	DbgLog(s1);
+	for (int i = 0; i < n; i++)	{
+		int optype=allprogs.Progs[i].nOpType1;
+		CStringA OpTxtA,OpShowTxtA;
+		CString OpTxt,OpShowTxt;
+		pDoc->OpToTxt(optype, OpTxtA);
+		pDoc->OpToShowTxt(optype, OpShowTxtA);
+		OpTxt = OpTxtA;
+		OpShowTxt = OpShowTxtA;
+		s1.Format(_T("%d %s %s"), optype, OpTxt, OpShowTxt);
+		DbgLog(s1);
+	}
 	return 0;
 }
 
-int CMTerm2View::ScanLDSCells(int nStartLine, int nEndLine, int nPosY, int nPosX, int nLevel, CString & sProgSec, int &nSteps)
+int CMTerm2View::ScanLDSCells(int nStartLine, int nEndLine, int nPosY, int nPosX, int nLevel, stProgSection & progsec, CString & sProgSec, int &nSteps)
 {
 	// TODO: 鍦ㄦ澶勬坊鍔犲疄鐜颁唬鐮�.
 	CString s1;
@@ -2374,14 +2433,20 @@
 		//鍏堝鐞嗗綋鍓嶅崟鍏�;
 		int nType = Cells[nCurPosY][nCurPosX].nType;
 		CString sCellName = Cells[nCurPosY][nCurPosX].sCoilName;
+		CMTerm2Doc::stProg theprog;
+
 		if (nType == typeNO) {
 			if (j==0) {
 				s1.Format(_T("%d %d ST %s"), nCurPosY, nCurPosX,sCellName);
 				sProgSec.AppendFormat(_T("ST %s\r\n"),sCellName);
+				theprog.nOpType1 = OP_ST;
+				progsec.Append(theprog);
 			}
 			else {
 				s1.Format(_T("%d %d AN %s"), nCurPosY, nCurPosX, sCellName);
 				sProgSec.AppendFormat(_T("NO %s\r\n"), sCellName);
+				theprog.nOpType1 = OP_AN;
+				progsec.Append(theprog);
 			}
 			nSteps += 1;
 			DbgLog(s1);
@@ -2391,11 +2456,16 @@
 			if (j == 0) {
 				s1.Format(_T("%d %d ST/ %s"), nCurPosY, nCurPosX, sCellName);
 				sProgSec.AppendFormat(_T("ST/ %s\r\n"), sCellName);
+				theprog.nOpType1 = OP_ST_;
+				progsec.Append(theprog);
+
 			}
 			else
 			{
 				s1.Format(_T("%d %d AN/ %s"), nCurPosY, nCurPosX, sCellName);
 				sProgSec.AppendFormat(_T("AN/ %s\r\n"), sCellName);
+				theprog.nOpType1 = OP_AN_;
+				progsec.Append(theprog);
 			}
 			DbgLog(s1);
 			nSteps += 1;
@@ -2404,6 +2474,7 @@
 		if (nType == typePP) {
 			s1.Format(_T("%d %d PP %s"), nCurPosY, nCurPosX, sCellName);
 			DbgLog(s1);
+			//progsec.Append(theprog);
 			sProgSec.AppendFormat(_T("PP %s\r\n"), sCellName);
 			nSteps += 1;
 			nNextX =  1;
@@ -2411,6 +2482,7 @@
 		if (nType == typePN) {
 			s1.Format(_T("%d %d PN %s"), nCurPosY, nCurPosX, sCellName);
 			DbgLog(s1);
+			//progsec.Append(theprog);
 			sProgSec.AppendFormat(_T("PN %s\r\n"), sCellName, sCellName);
 			nSteps += 1;
 			nNextX =  1;
@@ -2419,6 +2491,8 @@
 			s1.Format(_T("%d %d NOT %s"), nCurPosY, nCurPosX, sCellName);
 			DbgLog(s1);
 			sProgSec.AppendFormat(_T("NOT %s\r\n"), sCellName);
+			theprog.nOpType1 = OP_NOT;
+			progsec.Append(theprog);
 			nSteps += 1;
 			nNextX =  1;
 		}else 
@@ -2426,6 +2500,8 @@
 			s1.Format(_T("%d %d DF %s"), nCurPosY, nCurPosX, sCellName);
 			DbgLog(s1);
 			sProgSec.AppendFormat(_T("DF %s\r\n"), sCellName);
+			theprog.nOpType1 = OP_DF;
+			progsec.Append(theprog);
 			nSteps += 1;
 			nNextX =  1;
 		}else 
@@ -2433,6 +2509,8 @@
 			s1.Format(_T("%d %d DF/ %s"), nCurPosY, nCurPosX, sCellName);
 			DbgLog(s1);
 			sProgSec.AppendFormat(_T("DF/ %s\r\n"), sCellName);
+			theprog.nOpType1 = OP_DF_;
+			progsec.Append(theprog);
 			nSteps += 1;
 			nNextX =  1;
 		}else 
@@ -2440,6 +2518,8 @@
 			s1.Format(_T("%d %d OUT %s"), nCurPosY, nCurPosX, sCellName);
 			DbgLog(s1);
 			sProgSec.AppendFormat(_T("OUT %s\r\n"), sCellName);
+			theprog.nOpType1 = OP_OUT;
+			progsec.Append(theprog);
 			nSteps += 1;
 			nNextX =  1;
 		}else 
@@ -2447,6 +2527,8 @@
 			s1.Format(_T("%d %d SET %s"), nCurPosY, nCurPosX, sCellName);
 			DbgLog(s1);
 			sProgSec.AppendFormat(_T("SET %s\r\n"), sCellName);
+			theprog.nOpType1 = OP_SET;
+			progsec.Append(theprog);
 			nSteps += 1;
 			nNextX =  1;
 		}else 
@@ -2454,12 +2536,16 @@
 			s1.Format(_T("%d %d RESET %s"), nCurPosY, nCurPosX, sCellName);
 			DbgLog(s1);
 			sProgSec.AppendFormat(_T("RESET %s\r\n"), sCellName);
+			theprog.nOpType1 = OP_RESET;
+			progsec.Append(theprog);
 			nSteps += 1;
 			nNextX =  1;
 		}else 
 		if (nType == typeCMP) {
 			s1.Format(_T("%d %d CMP %s %s %s"), nCurPosY, nCurPosX, sCellName,Cells[nCurPosY][nCurPosX+1].sParam,Cells[nCurPosY][nCurPosX + 2].sParam);
 			DbgLog(s1);
+			theprog.nOpType1 = OP_ST_GT;
+			progsec.Append(theprog);
 			sProgSec.AppendFormat(_T("CMP %s %s %s \r\n"), sCellName, Cells[nCurPosY][nCurPosX + 1].sParam, Cells[nCurPosY][nCurPosX + 2].sParam);
 			nSteps += 1;
 			nNextX =  3;
@@ -2467,6 +2553,8 @@
 		if (nType == typeTM) {
 			s1.Format(_T("%d %d TM %s %d %s"), nCurPosY, nCurPosX, sCellName,Cells[nCurPosY][nCurPosX+1].sParam,Cells[nCurPosY][nCurPosX + 2].sParam);
 			DbgLog(s1);
+			theprog.nOpType1 = OP_TMX;
+			progsec.Append(theprog);
 			sProgSec.AppendFormat(_T("TM %s %d %s\r\n"), sCellName, Cells[nCurPosY][nCurPosX+1].sParam, Cells[nCurPosY][nCurPosX + 2].sParam);
 			nSteps += 1;
 			nNextX =  3;
@@ -2474,6 +2562,8 @@
 		if (nType == typeFN1) {
 			s1.Format(_T("%d %d FN1 %s %s"), nCurPosY, nCurPosX, sCellName,Cells[nCurPosY][nCurPosX + 1].sParam);
 			DbgLog(s1);
+			theprog.nOpType1 = OP_INC;
+			progsec.Append(theprog);
 			sProgSec.AppendFormat(_T("FN1 %s %s\r\n"), sCellName, Cells[nCurPosY][nCurPosX + 1].sParam);
 			nSteps += 1;
 			nNextX =  2;
@@ -2481,6 +2571,8 @@
 		if (nType == typeFN2) {
 			s1.Format(_T("%d %d FN2 %s %s %s "), nCurPosY, nCurPosX, sCellName, Cells[nCurPosY][nCurPosX + 1].sParam, Cells[nCurPosY][nCurPosX + 2].sParam);
 			DbgLog(s1);
+			theprog.nOpType1 = OP_MV;
+			progsec.Append(theprog);
 			sProgSec.AppendFormat(_T("FN2 %s %s %s \r\n"), sCellName, Cells[nCurPosY][nCurPosX + 1].sParam, Cells[nCurPosY][nCurPosX + 2].sParam);
 			nSteps += 1;
 			nNextX =  3;
@@ -2488,6 +2580,8 @@
 		if (nType == typeFN3) {
 			s1.Format(_T("%d %d FN3 %s %s %s %s"), nCurPosY, nCurPosX, sCellName, Cells[nCurPosY][nCurPosX + 1].sParam, Cells[nCurPosY][nCurPosX + 2].sParam, Cells[nCurPosY][nCurPosX + 3].sParam);
 			DbgLog(s1);
+			theprog.nOpType1 = OP_ADD3;
+			progsec.Append(theprog);
 			sProgSec.AppendFormat(_T("FN3 %s %s %s %s\r\n"), sCellName, Cells[nCurPosY][nCurPosX + 1].sParam, Cells[nCurPosY][nCurPosX + 2].sParam, Cells[nCurPosY][nCurPosX + 3].sParam);
 			nSteps += 1;
 			nNextX =  4;
@@ -2495,12 +2589,15 @@
 			nNextX =  1;
 			//continue;
 		}
+
 		if (j + nNextX >= m_CellPerLine) continue;
 		if (Cells[nCurPosY][j + nNextX].bLeftLineUp || Cells[nCurPosY][j + nNextX].bLeftLineDn) {	// 鍙戠幇绔栫嚎
 			//鍏堢湅寰�涓婇潰鏈夋病鏈夎繛鎺�
 			if (Cells[nCurPosY][j + nNextX].bLeftLineUp) { // 寰�涓婇潰鏈夎繛鎺�
 				s1.Format(_T("%d %d ORS "), nCurPosY, nCurPosX);
 				DbgLog(s1);
+				theprog.nOpType1 = OP_ORS;
+				progsec.Append(theprog);
 				sProgSec.AppendFormat(_T("ORS \r\n"));
 				nSteps += 1;
 				nLevel -= 1;
@@ -2524,6 +2621,8 @@
 					if ( nPosX >0 || nLevel > 0) {
 					s1.Format(_T("%d %d ANS "), nCurPosY, nCurPosX);
 					DbgLog(s1);
+					theprog.nOpType1 = OP_ANS;
+					progsec.Append(theprog);
 					sProgSec.AppendFormat(_T("ANS \r\n"));
 					nSteps += 1;
 					nLevel -= 1;
@@ -2552,9 +2651,11 @@
 					DbgLog(s1);
 					CString ProgSec;
 					int theSteps = 0;
-					int r = ScanLDSCells(nStartLine, nEndLine, nLineTop, j + nNextX, nLevel,ProgSec,theSteps);
+					stProgSection thisprogsec;
+					int r = ScanLDSCells(nStartLine, nEndLine, nLineTop, j + nNextX, nLevel,thisprogsec, ProgSec,theSteps);
 					sProgSec += ProgSec;
 					nSteps += theSteps;
+					progsec += thisprogsec;
 					s1.Format(_T("<<<< Re %d : %d , Result %d "), nLineTop, j + nNextX, r);
 					DbgLog(s1);
 				}
@@ -2576,9 +2677,11 @@
 							CString ProgSec;
 							int theSteps = 0;
 							nLevel += 1;
-							res[nRightCount] = ScanLDSCells(nStartLine, nEndLine, k, j + nNextX, nLevel ,ProgSecs[nRightCount],theSteps);
+							stProgSection thisprogsec;
+							res[nRightCount] = ScanLDSCells(nStartLine, nEndLine, k, j + nNextX, nLevel ,thisprogsec,ProgSecs[nRightCount],theSteps);
 							nLastResult = res[nRightCount];
 							nSteps += theSteps;
+							progsec += thisprogsec;
 							//if (res[nRightCount] > 0) nLevel += 1;
 							sProgSec += ProgSec;
 							s1.Format(_T(" <<< Re %d : %d , Result %d Steps %d Last %d"), k, j + nNextX, res[nRightCount],theSteps,nLastSteps);
diff --git a/MTerm2/MTerm2View.h b/MTerm2/MTerm2View.h
index 1e7b9df..b235098 100644
--- a/MTerm2/MTerm2View.h
+++ b/MTerm2/MTerm2View.h
@@ -4,7 +4,10 @@
 
 #pragma once
 
+#include <memory>
+#include <vector>
 
+#include "MTerm2Doc.h"
 class CMTerm2View : public CScrollView
 {
 protected: // 浠呬粠搴忓垪鍖栧垱寤�
@@ -63,9 +66,11 @@
 		int nProgStep;
 		int bFocused = 0;
 		int bSelected = 0;
-
 		int bEditing = 0;
 		int bModified = 0;
+
+		int bErrFocus = 0;
+
 		int bLeftLineUp = 0;
 		int bLeftLineDn = 0;
 		int nStat = 0;
@@ -83,6 +88,32 @@
 		}
 	};
 	stCell Cells[2000][16] = { 0 };
+
+	struct stProgSection
+	{
+		std::vector <CMTerm2Doc::stProg> Progs;
+		int Append(CMTerm2Doc::stProg prog)	{
+			Progs.push_back(prog);
+			return 0;
+		};
+		int Append(struct stProgSection progsec){
+			int n=progsec.Progs.size();
+			for (int i = 0; i < n; i++) {
+				Progs.push_back(progsec.Progs[i]);
+			}
+			return 0;
+		};
+		int operator+=(const struct stProgSection progsec) { 
+			Append(progsec);
+			return 0; 
+		};
+
+		int Insert(CMTerm2Doc::stProg prog)	{
+			Progs.insert(Progs.begin(), prog);
+			return 0;
+		}
+	};
+
 	int m_nTotalRow=0;
 	bool m_bMonitoring = false;		//鐩戞帶涓�
 	bool m_bShowComments = true;	//鏄剧ず娉ㄩ噴
@@ -171,6 +202,11 @@
 	int DoReDraw();
 	int DrawLDSGraph(CDC* pDC);
 
+	int ScrollToCell(int nRow, int nCol);
+
+	int ScrollCellIntoView(int nRow, int nCol);
+	int isCellInView(int nRow, int nCol);
+
 // 閲嶅啓
 public:
 	virtual void OnDraw(CDC* pDC);  // 閲嶅啓浠ョ粯鍒惰瑙嗗浘
@@ -244,7 +280,7 @@
 	int TransLDSToProg();
 	afx_msg void OnInputIoComment();
 	afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
-	int ScanLDSCells(int nStartLine, int nEndLine, int nPosY, int nPosX, int nLevel, CString & sProgSec, int &nSteps);
+	int ScanLDSCells(int nStartLine, int nEndLine, int nPosY, int nPosX, int nLevel, stProgSection & progsec, CString & sProgSec, int &nSteps);
 };
 
 #ifndef _DEBUG  // MultiTerminal2View.cpp 涓殑璋冭瘯鐗堟湰

--
Gitblit v1.9.1