New file |
| | |
| | | // 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;
|
| | | }
|
New file |
| | |
| | | // 下列 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);
|
New file |
| | |
| | | <?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> |
New file |
| | |
| | | <?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> |
New file |
| | |
| | | #define KLINK1_API __declspec(dllexport)
|
| | | #define KLINK1_API __declspec(dllimport)
|
New file |
| | |
| | | // dllmain.cpp : 定义 DLL 应用程序的入口点。
|
| | | #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;
|
| | | }
|
| | |
|
New file |
| | |
| | | #pragma once
|
| | |
|
| | | #define WIN32_LEAN_AND_MEAN // 从 Windows 头文件中排除极少使用的内容
|
| | | // Windows 头文件
|
| | | #include <windows.h>
|
New file |
| | |
| | | // pch.cpp: 与预编译标头对应的源文件
|
| | |
|
| | | #include "pch.h"
|
| | |
|
| | | // 当使用预编译的头时,需要使用此源文件,编译才能成功。
|
New file |
| | |
| | | // pch.h: 这是预编译标头文件。
|
| | | // 下方列出的文件仅编译一次,提高了将来生成的生成性能。
|
| | | // 这还将影响 IntelliSense 性能,包括代码完成和许多代码浏览功能。
|
| | | // 但是,如果此处列出的文件中的任何一个在生成之间有更新,它们全部都将被重新编译。
|
| | | // 请勿在此处添加要频繁更新的文件,这将使得性能优势无效。
|
| | |
|
| | | #ifndef PCH_H
|
| | | #define PCH_H
|
| | |
|
| | | // 添加要在此处预编译的标头
|
| | | #include "framework.h"
|
| | |
|
| | | #endif //PCH_H
|
New file |
| | |
| | | // 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;//成功找到了COMx的名字
|
| | | //}
|
| | | }
|
| | | }
|
| | | 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: 在此添加专用代码和/或调用基类
|
| | | GetParams();
|
| | | CDialogEx::OnOK();
|
| | | }
|
| | |
|
| | | void CDialogCommSet1::OnBnClickedOk()
|
| | | {
|
| | | // TODO: 在此添加控件通知处理程序代码
|
| | | GetParams();
|
| | | CDialogEx::OnOK();
|
| | | }
|
| | |
|
| | | void CDialogCommSet1::OnBnClickedButtonInit()
|
| | | {
|
| | | // TODO: 在此添加控件通知处理程序代码
|
| | | }
|
| | |
|
New file |
| | |
| | | #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();
|
| | | };
|
New file |
| | |
| | | /*
|
| | |
|
| | |
|
| | |
|
| | |
|
| | | */
|
| | | #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;
|
| | |
|
New file |
| | |
| | | #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;
|
| | |
|
| | | }
|
New file |
| | |
| | | #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);
|
| | |
|
| | |
|
| | | };
|
| | |
|
New file |
| | |
| | | // 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 调用
|
| | | // 出现在每个函数中十分重要。 这意味着
|
| | | // 它必须作为以下项中的第一个语句:
|
| | | // 出现,甚至先于所有对象变量声明,
|
| | | // 这是因为它们的构造函数可能生成 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: 在此添加专用代码和/或调用基类
|
| | |
|
| | | 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;
|
| | | } |
New file |
| | |
| | | ; KLink2.def: 声明 DLL 的模块参数。
|
| | |
|
| | | LIBRARY
|
| | |
|
| | | EXPORTS
|
| | | ; 此处可以是显式导出
|
| | | DoConfig
|
New file |
| | |
| | | // 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();
|
| | | };
|
| | |
|
New file |
| | |
| | | <?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> |
New file |
| | |
| | | <?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> |
New file |
| | |
| | | //{{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
|
New file |
| | |
| | | #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 套接字扩展
|
| | |
|
New file |
| | |
| | | // pch.cpp: 与预编译标头对应的源文件
|
| | |
|
| | | #include "pch.h"
|
| | |
|
| | | // 当使用预编译的头时,需要使用此源文件,编译才能成功。
|
New file |
| | |
| | | // pch.h: 这是预编译标头文件。
|
| | | // 下方列出的文件仅编译一次,提高了将来生成的生成性能。
|
| | | // 这还将影响 IntelliSense 性能,包括代码完成和许多代码浏览功能。
|
| | | // 但是,如果此处列出的文件中的任何一个在生成之间有更新,它们全部都将被重新编译。
|
| | | // 请勿在此处添加要频繁更新的文件,这将使得性能优势无效。
|
| | |
|
| | | #ifndef PCH_H
|
| | | #define PCH_H
|
| | |
|
| | | // 添加要在此处预编译的标头
|
| | | #include "framework.h"
|
| | |
|
| | | #endif //PCH_H
|
New file |
| | |
| | | #pragma once
|
| | |
|
| | | // 包括 SDKDDKVer.h 将定义可用的最高版本的 Windows 平台。
|
| | |
|
| | | // 如果要为以前的 Windows 平台生成应用程序,请包括 WinSDKVer.h,并将
|
| | | // 将 _WIN32_WINNT 宏设置为要支持的平台,然后再包括 SDKDDKVer.h。
|
| | |
|
| | | #include <SDKDDKVer.h>
|
| | |
| | | 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
|
| | |
| | | {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
|
| | |
| | | #pragma comment(lib,"SetupAPI.lib")
|
| | | #pragma comment(lib,"gdiplus.lib")
|
| | |
|
| | | #include "../KLink2/KLink.h"
|
| | |
|
| | |
|
| | | #pragma comment(lib,"KLink2.lib")
|
| | | MHash MyCfg1;
|
| | | Logger myLogger1;
|
| | |
|
| | |
| | | </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>
|
| | |
| | | #include "framework.h"
|
| | | #include "MTerm2.h"
|
| | | #include "MTerm2Doc.h"
|
| | | #include "ChildFrm.h"
|
| | |
|
| | | #include "MTerm2CommDevView.h"
|
| | |
|
| | |
| | | {
|
| | | CFormView::OnInitialUpdate();
|
| | | // TODO: 在此添加专用代码和/或调用基类
|
| | |
|
| | | // ResizeParentToFit();
|
| | | // ((CChildFrame *)GetParentFrame())->RecalcLayout();
|
| | | m_bResourceOpened = 0;
|
| | |
|
| | | LoadResourceList();
|
| | |
| | | // 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));
|
| | |
| | | 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]);
|
| | |
| | | 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]);
|
| | |
| | | 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);
|
| | |
|
| | |
|
| | |
|
| | |
| | | void CMTerm2CtrlView::OnBnClickedButton4()
|
| | | {
|
| | | // TODO: 在此添加控件通知处理程序代码
|
| | | 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);
|
| | |
| | | };
|
| | | 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},
|
| | |
| | |
|
| | |
|
| | | };
|
| | | int CMTerm2Doc::nProgDefCount = sizeof(CMTerm2Doc::ProgDef) / sizeof(stProgDef);
|
| | | int CMTerm2Doc::nOpDefCount = sizeof(CMTerm2Doc::OpDef) / sizeof(stOpDef);
|
| | |
|
| | | IMPLEMENT_DYNCREATE(CMTerm2Doc, CDocument)
|
| | |
|
| | |
| | |
|
| | | 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;
|
| | | }
|
| | | }
|
| | |
| | |
|
| | | 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;
|
| | | }
|
| | | }
|
| | |
| | | #include "KLink.h"
|
| | | #include "KMachine.h"
|
| | |
|
| | | #include "../KLink2/KLink.h"
|
| | |
|
| | | #pragma comment(lib,"KLink2.lib")
|
| | |
|
| | | class CMTerm2Doc : public CDocument
|
| | | {
|
| | | protected: // 仅从序列化创建
|
| | |
| | | // CSerialCom MySerialCom1;
|
| | | HvSerialPort myHvSerialPort1;
|
| | | KMachine myKMachine1;
|
| | |
|
| | | KLink2 MyKlink2;
|
| | |
|
| | |
|
| | | bool m_bCommParamSet = false;
|
| | |
| | | KLParamNum,
|
| | |
|
| | | };
|
| | | struct stProgDef
|
| | | struct stOpDef
|
| | | {
|
| | | int nOpType1;
|
| | | CStringA OpTxt;
|
| | |
| | | int nParamType;
|
| | | CStringA ShowTxt;
|
| | | };
|
| | | static stProgDef ProgDef[];
|
| | | static stOpDef OpDef[];
|
| | |
|
| | | static int nProgDefCount;
|
| | | static int nOpDefCount;
|
| | | struct stParam
|
| | | {
|
| | | CStringA sParamStr;
|
| | |
| | | #include "DialogSetCoil.h"
|
| | | #include "DialogSetData.h"
|
| | | #include "DialogIoComment.h"
|
| | |
|
| | | #include "KDefine.h"
|
| | |
|
| | | #ifdef _DEBUG
|
| | | #define new DEBUG_NEW
|
| | |
| | | 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)
|
| | | {
|
| | |
| | | int CMTerm2View::TransLDSToProg()
|
| | | {
|
| | | // TODO: 在此处添加实现代码.
|
| | | CMTerm2Doc * pDoc = GetDocument();
|
| | | CString s1;
|
| | | s1.Format(_T("Trans LDS to PRrog"));
|
| | | DbgLog(s1);
|
| | |
| | | nDivCount++;
|
| | | }
|
| | | }
|
| | | stProgSection allprogs;
|
| | | //每段单独处理
|
| | | for (int i = 0; i < nDivCount; i++) {
|
| | | int nStartLine, nEndLine;
|
| | |
| | | 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;
|
| | |
| | | //先处理当前单元;
|
| | | 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);
|
| | |
| | | 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;
|
| | |
| | | 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;
|
| | |
| | | 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;
|
| | |
| | | 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
|
| | |
| | | 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
|
| | |
| | | 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
|
| | |
| | | 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
|
| | |
| | | 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
|
| | |
| | | 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;
|
| | |
| | | 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;
|
| | |
| | | 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;
|
| | |
| | | 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;
|
| | |
| | | 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;
|
| | |
| | | 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;
|
| | |
| | | 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;
|
| | |
| | | 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);
|
| | | }
|
| | |
| | | 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);
|
| | |
| | |
|
| | | #pragma once
|
| | |
|
| | | #include <memory>
|
| | | #include <vector>
|
| | |
|
| | | #include "MTerm2Doc.h"
|
| | | class CMTerm2View : public CScrollView
|
| | | {
|
| | | protected: // 仅从序列化创建
|
| | |
| | | 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;
|
| | |
| | | }
|
| | | };
|
| | | 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; //显示注释
|
| | |
| | | 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); // 重写以绘制该视图
|
| | |
| | | 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 中的调试版本
|