2014-08-27 update 1

This commit is contained in:
parallelbgls@outlook.com
2014-08-27 15:57:25 +08:00
parent aa1cbf85ba
commit ca030c8f59
24 changed files with 1159 additions and 2371 deletions

View File

@@ -1,39 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{fa929e21-544c-444e-b18d-184e98b427c6}</ProjectGuid>
<ArchitectureToolsVersion>2.0.0.0</ArchitectureToolsVersion>
<Name>ModBus.Net.Modeling</Name>
<RootNamespace>ModBus.Net.Modeling</RootNamespace>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<OutputPath>bin\Debug\</OutputPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<OutputPath>bin\Release\</OutputPath>
</PropertyGroup>
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)\ArchitectureTools\Microsoft.VisualStudio.TeamArchitect.ModelingProject.targets" Condition="'$(VSToolsPath)' != ''" />
<ItemGroup>
<Content Include="ModelDefinition\Package1_1514.uml">
<SubType>Content</SubType>
</Content>
<Content Include="ModelDefinition\Package2_1514.uml">
<SubType>Content</SubType>
</Content>
<Content Include="ModelDefinition\Package_1514.uml">
<SubType>Content</SubType>
</Content>
<Folder Include="ModelDefinition\" />
<Content Include="ModelDefinition\ModBus.Net.Modeling.uml">
<SubType>Content</SubType>
</Content>
</ItemGroup>
</Project>

View File

@@ -1,60 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<modelStoreModel xmlns:dm0="http://schemas.microsoft.com/VisualStudio/2008/DslTools/Core" xmlns:dm1="http://schemas.microsoft.com/dsltools/Kernel" xmlns:dm2="http://schemas.microsoft.com/dsltools/Component" xmlns:dm3="http://schemas.microsoft.com/dsltools/UseCase" xmlns:dm4="http://schemas.microsoft.com/dsltools/Activity" xmlns:dm5="http://schemas.microsoft.com/dsltools/Interaction" xmlns:dm6="http://schemas.microsoft.com/dsltools/UmlModelLibrary" xmlns:dm7="http://schemas.microsoft.com/dsltools/UmlDiagrams" xmlns:dm8="http://schemas.microsoft.com/dsltools/LogicalClassDesigner"
dslVersion="1.0.0.0"
Id="fd145486-0c29-495d-a330-60e368b0a72b"
name="ModBus.Net.Modeling" xmlns="http://schemas.microsoft.com/dsltools/ModelStore">
<profileInstances>
<packageHasProfileInstances
Id="0caec977-1f8c-4ba3-a7db-8cc9ad9cc73b">
<profileInstance
Id="e34d544e-0fea-4ed6-ac5e-1b74119ac791"
name="StandardProfileL2" />
</packageHasProfileInstances>
<packageHasProfileInstances
Id="29349502-908c-4fda-9054-c48619c59ed0">
<profileInstance
Id="532ea607-fb19-44b8-8502-3351b05452be"
name="StandardProfileL3" />
</packageHasProfileInstances>
<packageHasProfileInstances
Id="1487f277-beee-4eb6-960e-448622fa0c8d">
<profileInstance
Id="1c6134f1-8099-43e1-b7ee-8e71eb9375a8"
name="CSharpProfile" />
</packageHasProfileInstances>
</profileInstances>
<packagedElements>
<packageHasNamedElement>
<packageMoniker
Id="7e21a600-5ec3-4b66-9116-79de77e70eda"
LastKnownName="ModBus"
LastKnownLocation="Package_1514.uml" />
</packageHasNamedElement>
<packageHasNamedElement>
<packageMoniker
Id="9173fd98-70ed-48ee-9128-f08c92f0fd99"
LastKnownName="System"
LastKnownLocation="Package2_1514.uml" />
</packageHasNamedElement>
</packagedElements>
<primitiveType
Id="220a3521-e091-4221-bae9-3ef9018e845c"
name="Integer"
isAbstract="false"
isLeaf="false" />
<primitiveType
Id="8943dc84-709e-4f62-b15a-a3273aa6f165"
name="Boolean"
isAbstract="false"
isLeaf="false" />
<primitiveType
Id="59259974-6d55-42c6-b7bd-763d77ac8ef9"
name="String"
isAbstract="false"
isLeaf="false" />
<primitiveType
Id="3ab42e7d-4969-445a-b209-471f5cb8209c"
name="UnlimitedNatural"
isAbstract="false"
isLeaf="false" />
</modelStoreModel>

File diff suppressed because it is too large Load Diff

View File

@@ -1,176 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<package xmlns:dm0="http://schemas.microsoft.com/VisualStudio/2008/DslTools/Core" xmlns:dm1="http://schemas.microsoft.com/dsltools/Kernel" xmlns:dm2="http://schemas.microsoft.com/dsltools/Component" xmlns:dm3="http://schemas.microsoft.com/dsltools/UseCase" xmlns:dm4="http://schemas.microsoft.com/dsltools/Activity" xmlns:dm5="http://schemas.microsoft.com/dsltools/Interaction" xmlns:dm6="http://schemas.microsoft.com/dsltools/UmlModelLibrary" xmlns:dm7="http://schemas.microsoft.com/dsltools/UmlDiagrams" xmlns:dm8="http://schemas.microsoft.com/dsltools/LogicalClassDesigner"
dslVersion="1.0.0.0"
Id="9173fd98-70ed-48ee-9128-f08c92f0fd99"
name="System"
visibility="Private" xmlns="http://schemas.microsoft.com/dsltools/ModelStore">
<referencesInternal>
<reference
Id="5c837964-238d-4fdf-b6d8-de7d2f2e0d50"
handle="viewcode://./CodeSchema_Namespace?Namespace%3DSystem"
tag="ViewCode" />
</referencesInternal>
<packagedElements>
<packageHasNamedElement>
<class
Id="ca4f5130-7cc4-4902-951f-434ffd76a2a8"
name="Byte"
visibility="Private"
isAbstract="false"
isLeaf="false"
isActiveClass="false">
<referencesInternal>
<reference
Id="ea406bc8-5323-4373-aa88-c6ee35c3c472"
handle="viewcode://./CodeSchema_Class?Assembly%3D&quot;file:%2F%2F%2FC:%2FProgram Files (x86)%2FReference Assemblies%2FMicrosoft%2FFramework%2F.NETFramework%2Fv4.5%2Fmscorlib.dll&quot; Namespace%3DSystem Type%3D(Name%3DByte ArrayRank%3D1 ParentType%3DByte)"
tag="ViewCode" />
</referencesInternal>
<appliedStereotypesInternal>
<stereotypeInstance
Id="7f7d933f-199c-4b42-af53-a3804c6bb8cf"
name="class"
profile="CSharpProfile">
<propertyInstances>
<stereotypeInstanceHasPropertyInstances
Id="e477a408-6d48-487b-9d97-2b9a1c29d6f9">
<propertyInstance
Id="e45098a6-4ae0-428c-b01a-da430130aedf"
name="ClrAttributes" />
</stereotypeInstanceHasPropertyInstances>
<stereotypeInstanceHasPropertyInstances
Id="13b0c98d-06aa-434b-9a9f-0f79a3d10bc3">
<propertyInstance
Id="806257b1-7263-445c-8195-9baa4e56342f"
name="IsPartial"
value="false" />
</stereotypeInstanceHasPropertyInstances>
<stereotypeInstanceHasPropertyInstances
Id="bb665dde-bffa-4b20-ab92-118cf67a1375">
<propertyInstance
Id="2a616a5e-4bc6-4912-bb3c-cd665ced818c"
name="IsStatic"
value="False" />
</stereotypeInstanceHasPropertyInstances>
<stereotypeInstanceHasPropertyInstances
Id="12f4d521-7ac9-4679-8c41-3afb99fed318">
<propertyInstance
Id="2a77fa36-84b2-4abd-ba58-28952f243af6"
name="IsUnsafe"
value="false" />
</stereotypeInstanceHasPropertyInstances>
<stereotypeInstanceHasPropertyInstances
Id="b9900524-60e3-42ff-9505-4853eb384312">
<propertyInstance
Id="389c1266-f859-4af4-ad11-06eb0b68c145"
name="PackageVisibility"
value="internal" />
</stereotypeInstanceHasPropertyInstances>
</propertyInstances>
</stereotypeInstance>
</appliedStereotypesInternal>
</class>
</packageHasNamedElement>
<packageHasNamedElement>
<Interface
Id="52fd4b9d-c56a-4e97-a30f-d2d07c7a8b08"
name="IDisposable"
isAbstract="false"
isLeaf="false">
<referencesInternal>
<reference
Id="9417e968-f68b-4c40-9bf7-4406ea04de30"
handle="viewcode://./CodeSchema_Interface?Assembly%3D&quot;file:%2F%2F%2FC:%2FProgram Files (x86)%2FReference Assemblies%2FMicrosoft%2FFramework%2F.NETFramework%2Fv4.5%2Fmscorlib.dll&quot; Namespace%3DSystem Type%3DIDisposable"
tag="ViewCode" />
</referencesInternal>
<appliedStereotypesInternal>
<stereotypeInstance
Id="1a268377-4d09-4bc0-9253-308e746837ee"
name="interface"
profile="CSharpProfile">
<propertyInstances>
<stereotypeInstanceHasPropertyInstances
Id="56b1f904-6fe2-4dab-8873-252afac1865a">
<propertyInstance
Id="23e5e6bc-9bb1-422a-9153-eb8955cb6264"
name="ClrAttributes" />
</stereotypeInstanceHasPropertyInstances>
<stereotypeInstanceHasPropertyInstances
Id="fc73498d-de92-4163-b97e-ab595f9facf8">
<propertyInstance
Id="ed39586b-832a-4536-984c-3f735846ba04"
name="IsPartial"
value="false" />
</stereotypeInstanceHasPropertyInstances>
<stereotypeInstanceHasPropertyInstances
Id="7f868e94-e848-4ed8-a2df-ee2ce844e526">
<propertyInstance
Id="3dac89c5-907c-4db0-ab1b-867b95b43c48"
name="IsUnsafe"
value="false" />
</stereotypeInstanceHasPropertyInstances>
<stereotypeInstanceHasPropertyInstances
Id="af04e12f-9dbd-49b5-bc66-59587be5e2d6">
<propertyInstance
Id="e56827bb-2e60-4ba6-b476-3ffcbb6c9cc4"
name="PackageVisibility"
value="internal" />
</stereotypeInstanceHasPropertyInstances>
</propertyInstances>
</stereotypeInstance>
</appliedStereotypesInternal>
</Interface>
</packageHasNamedElement>
<packageHasNamedElement>
<class
Id="aed0afd4-f3fe-429d-9ac1-1a477d7b9a0d"
name="Int16"
visibility="Private"
isAbstract="false"
isLeaf="false"
isActiveClass="false">
<referencesInternal>
<reference
Id="3a475c63-a7f4-4c2d-84ba-19e4247f8d28"
handle="viewcode://./CodeSchema_Struct?Assembly%3D&quot;file:%2F%2F%2FC:%2FProgram Files (x86)%2FReference Assemblies%2FMicrosoft%2FFramework%2F.NETFramework%2Fv4.5%2Fmscorlib.dll&quot; Namespace%3DSystem Type%3DInt16"
tag="ViewCode" />
</referencesInternal>
<appliedStereotypesInternal>
<stereotypeInstance
Id="c642f687-96f5-4550-bb21-f8fade3e0fe1"
name="struct"
profile="CSharpProfile">
<propertyInstances>
<stereotypeInstanceHasPropertyInstances
Id="068f7672-b034-4643-b2b6-8b4245aa24c7">
<propertyInstance
Id="d36ffc7d-83e2-418f-90c0-4611b782af00"
name="ClrAttributes" />
</stereotypeInstanceHasPropertyInstances>
<stereotypeInstanceHasPropertyInstances
Id="2decb316-3044-4ee7-ac16-84190c0612b2">
<propertyInstance
Id="c6856039-4fe9-414e-94f4-105b350c04ed"
name="IsPartial"
value="false" />
</stereotypeInstanceHasPropertyInstances>
<stereotypeInstanceHasPropertyInstances
Id="c9a7d158-03ec-4cde-ac85-4d5f843357f8">
<propertyInstance
Id="ac2bf06d-e59b-4219-bbf5-dc915f2d0823"
name="IsUnsafe"
value="false" />
</stereotypeInstanceHasPropertyInstances>
<stereotypeInstanceHasPropertyInstances
Id="27fcce12-a915-41fd-bbf0-57e74ca9498a">
<propertyInstance
Id="8c3a86ea-2cf3-42e4-bb29-f70fa565edbc"
name="PackageVisibility"
value="internal" />
</stereotypeInstanceHasPropertyInstances>
</propertyInstances>
</stereotypeInstance>
</appliedStereotypesInternal>
</class>
</packageHasNamedElement>
</packagedElements>
</package>

View File

@@ -1,21 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<package xmlns:dm0="http://schemas.microsoft.com/VisualStudio/2008/DslTools/Core" xmlns:dm1="http://schemas.microsoft.com/dsltools/Kernel" xmlns:dm2="http://schemas.microsoft.com/dsltools/Component" xmlns:dm3="http://schemas.microsoft.com/dsltools/UseCase" xmlns:dm4="http://schemas.microsoft.com/dsltools/Activity" xmlns:dm5="http://schemas.microsoft.com/dsltools/Interaction" xmlns:dm6="http://schemas.microsoft.com/dsltools/UmlModelLibrary" xmlns:dm7="http://schemas.microsoft.com/dsltools/UmlDiagrams" xmlns:dm8="http://schemas.microsoft.com/dsltools/LogicalClassDesigner"
dslVersion="1.0.0.0"
Id="7e21a600-5ec3-4b66-9116-79de77e70eda"
name="ModBus"
visibility="Private" xmlns="http://schemas.microsoft.com/dsltools/ModelStore">
<referencesInternal>
<reference
Id="8b9c69f4-5916-45c1-9b7b-0f8da12bcda7"
handle="viewcode://./CodeSchema_Namespace?Namespace%3DModBus"
tag="ViewCode" />
</referencesInternal>
<packagedElements>
<packageHasNamedElement>
<packageMoniker
Id="4bf62f03-f5b2-4927-bb5e-ed26fcf882c2"
LastKnownName="Net"
LastKnownLocation="Package1_1514.uml" />
</packageHasNamedElement>
</packagedElements>
</package>

View File

@@ -1,39 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="file:///C:/PROGRAM FILES (X86)/MICROSOFT VISUAL STUDIO 12.0/COMMON7/IDE/EXTENSIONS/MICROSOFT/ARCHITECTURE TOOLS/EXTENSIBILITY/Logging/ReverseEngineeringLog.xslt"?>
<Log xmlns="http://schemas.microsoft.com/VisualStudio/2010/CodeGen.RE.Log" Label="代码生成/文本转换记录">
<MessageClass Name="Message" Label="消息" Option="显示提供相关信息的消息" />
<MessageClass Name="Warning" Label="警告" Option="显示警告" />
<MessageClass Name="Error" Label="错误" Option="显示错误" />
<MessageClass Name="Property" Label="属性" Option="显示元数据" />
<MessageClass Name="Diagnostic" Label="消息" Option="显示诊断消息" />
<Message Timestamp="2014-07-28T15:15:02" Importance="High" Text="已启动反向工程。" />
<Message Timestamp="2014-07-28T15:15:03" Importance="Diagnostic" Text="已将以下元素反向工程到 UML 模型中: “Boolean”- (PrimitiveType)" />
<Message Timestamp="2014-07-28T15:15:03" Importance="Diagnostic" Text="已将以下元素反向工程到 UML 模型中: “Integer”- (PrimitiveType)" />
<Message Timestamp="2014-07-28T15:15:03" Importance="Diagnostic" Text="已将以下元素反向工程到 UML 模型中: “ModBus.Net.Modeling::ModBus”- (Package)" />
<Message Timestamp="2014-07-28T15:15:03" Importance="Diagnostic" Text="已将以下元素反向工程到 UML 模型中: “ModBus.Net.Modeling::ModBus::Net”- (Package)" />
<Message Timestamp="2014-07-28T15:15:03" Importance="Medium" Text="已将以下元素反向工程到 UML 模型中: “ModBus.Net.Modeling::ModBus::Net::ModBusTCPIPWrapper”- (Class)" />
<Message Timestamp="2014-07-28T15:15:03" Importance="Diagnostic" Text="已将以下元素反向工程到 UML 模型中: “ModBus.Net.Modeling::ModBus::Net::ModBusTCPIPWrapper::Connect”- (Operation)" />
<Message Timestamp="2014-07-28T15:15:03" Importance="Diagnostic" Text="已将以下元素反向工程到 UML 模型中: “ModBus.Net.Modeling::ModBus::Net::ModBusTCPIPWrapper::connected”- (Property)" />
<Message Timestamp="2014-07-28T15:15:03" Importance="Diagnostic" Text="已将以下元素反向工程到 UML 模型中: “ModBus.Net.Modeling::ModBus::Net::ModBusTCPIPWrapper::Dispose”- (Operation)" />
<Message Timestamp="2014-07-28T15:15:03" Importance="Diagnostic" Text="已将以下元素反向工程到 UML 模型中: “ModBus.Net.Modeling::ModBus::Net::ModBusTCPIPWrapper::Instance”- (Property)" />
<Message Timestamp="2014-07-28T15:15:03" Importance="Diagnostic" Text="已将以下元素反向工程到 UML 模型中: “ModBus.Net.Modeling::ModBus::Net::ModBusTCPIPWrapper::ModBusTCPIPWrapper”- (Operation)" />
<Message Timestamp="2014-07-28T15:15:03" Importance="Diagnostic" Text="已将以下元素反向工程到 UML 模型中: “ModBus.Net.Modeling::ModBus::Net::ModBusTCPIPWrapper::Receive”- (Operation)" />
<Message Timestamp="2014-07-28T15:15:03" Importance="Diagnostic" Text="已将以下元素反向工程到 UML 模型中: “ModBus.Net.Modeling::ModBus::Net::ModBusTCPIPWrapper::Receive::receiveByteCount”- (Parameter)" />
<Message Timestamp="2014-07-28T15:15:03" Importance="Diagnostic" Text="已将以下元素反向工程到 UML 模型中: “ModBus.Net.Modeling::ModBus::Net::ModBusTCPIPWrapper::Send”- (Operation)" />
<Message Timestamp="2014-07-28T15:15:03" Importance="Diagnostic" Text="已将以下元素反向工程到 UML 模型中: “ModBus.Net.Modeling::ModBus::Net::ModBusTCPIPWrapper::Send::data”- (Parameter)" />
<Message Timestamp="2014-07-28T15:15:03" Importance="Diagnostic" Text="已将以下元素反向工程到 UML 模型中: “ModBus.Net.Modeling::ModBus::Net::ModBusTCPIPWrapper::socketWrapper”- (Property)" />
<Message Timestamp="2014-07-28T15:15:03" Importance="Diagnostic" Text="已将以下元素反向工程到 UML 模型中: “ModBus.Net.Modeling::ModBus::Net::ModBusTCPIPWrapper::StartingAddress”- (Property)" />
<Message Timestamp="2014-07-28T15:15:03" Importance="Diagnostic" Text="已将以下元素反向工程到 UML 模型中: “ModBus.Net.Modeling::ModBus::Net::ModBusWrapper”- (Class) (已进行部分反向工程 - 定义未更新) " />
<Message Timestamp="2014-07-28T15:15:03" Importance="Diagnostic" Text="已将以下元素反向工程到 UML 模型中: “ModBus.Net.Modeling::ModBus::Net::SocketWrapper”- (Class) (已进行部分反向工程 - 定义未更新) " />
<Message Timestamp="2014-07-28T15:15:03" Importance="Diagnostic" Text="已将以下元素反向工程到 UML 模型中: “ModBus.Net.Modeling::System”- (Package)" />
<Message Timestamp="2014-07-28T15:15:03" Importance="Diagnostic" Text="已将以下元素反向工程到 UML 模型中: “ModBus.Net.Modeling::System::Byte”- (Class) (已进行部分反向工程 - 定义未更新) " />
<Message Timestamp="2014-07-28T15:15:03" Importance="Diagnostic" Text="已将以下元素反向工程到 UML 模型中: “ModBus.Net.Modeling::System::IDisposable”- (Interface) (已进行部分反向工程 - 定义未更新) " />
<Message Timestamp="2014-07-28T15:15:03" Importance="Diagnostic" Text="已将以下元素反向工程到 UML 模型中: “ModBus.Net.Modeling::System::Int16”- (Class) (已进行部分反向工程 - 定义未更新) " />
<Message Timestamp="2014-07-28T15:15:03" Importance="Diagnostic" Text="已将以下关系反向工程到 UML 模型中: ModBus.Net.Modeling::ModBus::Net::ModBusTCPIPWrapper 到 ModBus.Net.Modeling::System::IDisposable (InterfaceRealization)" />
<Message Timestamp="2014-07-28T15:15:03" Importance="Diagnostic" Text="已将以下关系反向工程到 UML 模型中: ModBus.Net.Modeling::ModBus::Net::ModBusTCPIPWrapper 到 ModBus.Net.Modeling::ModBus::Net::ModBusWrapper (Generalization)" />
<Message Timestamp="2014-07-28T15:15:03" Importance="Diagnostic" Text="已将以下关系反向工程到 UML 模型中: ModBus.Net.Modeling::ModBus::Net::SocketWrapper 到 ModBus.Net.Modeling::System::IDisposable (InterfaceRealization)" />
<Message Timestamp="2014-07-28T15:15:03" Importance="Diagnostic" Text="已将以下关系反向工程到 UML 模型中: ModBus.Net.Modeling::ModBus::Net::ModBusWrapper 到 ModBus.Net.Modeling::System::IDisposable (InterfaceRealization)" />
<Message Timestamp="2014-07-28T15:15:03" Importance="High" Text="已对(1)个类型进行完全反向工程。" />
<Message Timestamp="2014-07-28T15:15:03" Importance="High" Text="已对(5)个类型进行部分反向工程。 这些类型未包含在原始选定内容中,因此未对其整个定义进行反向工程。 相反,此浅表操作只确保这些类型存在于 UML 模型中,因为需要用它们来完全描述其他元素。" />
<Message Timestamp="2014-07-28T15:15:03" Importance="High" Text="反向工程操作已完成,出现了(0)个错误和(0)个警告。" />
</Log>

608
NA200H/ModBus.Net/CRC16.cs Normal file
View File

@@ -0,0 +1,608 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ModBus.Net
{
public class Crc16
{
/// <summary>
/// CRC验证表
/// </summary>
public byte[] crc_table = new byte[512];
private static Crc16 _crc16 = null;
public static Crc16 GetInstance()
{
if (_crc16 == null)
{
_crc16 = new Crc16();
}
return _crc16;
}
private Crc16()
{
crc_table[0] = 0x0;
crc_table[1] = 0xC1;
crc_table[2] = 0x81;
crc_table[3] = 0x40;
crc_table[4] = 0x1;
crc_table[5] = 0xC0;
crc_table[6] = 0x80;
crc_table[7] = 0x41;
crc_table[8] = 0x1;
crc_table[9] = 0xC0;
crc_table[10] = 0x80;
crc_table[11] = 0x41;
crc_table[12] = 0x0;
crc_table[13] = 0xC1;
crc_table[14] = 0x81;
crc_table[15] = 0x40;
crc_table[16] = 0x1;
crc_table[17] = 0xC0;
crc_table[18] = 0x80;
crc_table[19] = 0x41;
crc_table[20] = 0x0;
crc_table[21] = 0xC1;
crc_table[22] = 0x81;
crc_table[23] = 0x40;
crc_table[24] = 0x0;
crc_table[25] = 0xC1;
crc_table[26] = 0x81;
crc_table[27] = 0x40;
crc_table[28] = 0x1;
crc_table[29] = 0xC0;
crc_table[30] = 0x80;
crc_table[31] = 0x41;
crc_table[32] = 0x1;
crc_table[33] = 0xC0;
crc_table[34] = 0x80;
crc_table[35] = 0x41;
crc_table[36] = 0x0;
crc_table[37] = 0xC1;
crc_table[38] = 0x81;
crc_table[39] = 0x40;
crc_table[40] = 0x0;
crc_table[41] = 0xC1;
crc_table[42] = 0x81;
crc_table[43] = 0x40;
crc_table[44] = 0x1;
crc_table[45] = 0xC0;
crc_table[46] = 0x80;
crc_table[47] = 0x41;
crc_table[48] = 0x0;
crc_table[49] = 0xC1;
crc_table[50] = 0x81;
crc_table[51] = 0x40;
crc_table[52] = 0x1;
crc_table[53] = 0xC0;
crc_table[54] = 0x80;
crc_table[55] = 0x41;
crc_table[56] = 0x1;
crc_table[57] = 0xC0;
crc_table[58] = 0x80;
crc_table[59] = 0x41;
crc_table[60] = 0x0;
crc_table[61] = 0xC1;
crc_table[62] = 0x81;
crc_table[63] = 0x40;
crc_table[64] = 0x1;
crc_table[65] = 0xC0;
crc_table[66] = 0x80;
crc_table[67] = 0x41;
crc_table[68] = 0x0;
crc_table[69] = 0xC1;
crc_table[70] = 0x81;
crc_table[71] = 0x40;
crc_table[72] = 0x0;
crc_table[73] = 0xC1;
crc_table[74] = 0x81;
crc_table[75] = 0x40;
crc_table[76] = 0x1;
crc_table[77] = 0xC0;
crc_table[78] = 0x80;
crc_table[79] = 0x41;
crc_table[80] = 0x0;
crc_table[81] = 0xC1;
crc_table[82] = 0x81;
crc_table[83] = 0x40;
crc_table[84] = 0x1;
crc_table[85] = 0xC0;
crc_table[86] = 0x80;
crc_table[87] = 0x41;
crc_table[88] = 0x1;
crc_table[89] = 0xC0;
crc_table[90] = 0x80;
crc_table[91] = 0x41;
crc_table[92] = 0x0;
crc_table[93] = 0xC1;
crc_table[94] = 0x81;
crc_table[95] = 0x40;
crc_table[96] = 0x0;
crc_table[97] = 0xC1;
crc_table[98] = 0x81;
crc_table[99] = 0x40;
crc_table[100] = 0x1;
crc_table[101] = 0xC0;
crc_table[102] = 0x80;
crc_table[103] = 0x41;
crc_table[104] = 0x1;
crc_table[105] = 0xC0;
crc_table[106] = 0x80;
crc_table[107] = 0x41;
crc_table[108] = 0x0;
crc_table[109] = 0xC1;
crc_table[110] = 0x81;
crc_table[111] = 0x40;
crc_table[112] = 0x1;
crc_table[113] = 0xC0;
crc_table[114] = 0x80;
crc_table[115] = 0x41;
crc_table[116] = 0x0;
crc_table[117] = 0xC1;
crc_table[118] = 0x81;
crc_table[119] = 0x40;
crc_table[120] = 0x0;
crc_table[121] = 0xC1;
crc_table[122] = 0x81;
crc_table[123] = 0x40;
crc_table[124] = 0x1;
crc_table[125] = 0xC0;
crc_table[126] = 0x80;
crc_table[127] = 0x41;
crc_table[128] = 0x1;
crc_table[129] = 0xC0;
crc_table[130] = 0x80;
crc_table[131] = 0x41;
crc_table[132] = 0x0;
crc_table[133] = 0xC1;
crc_table[134] = 0x81;
crc_table[135] = 0x40;
crc_table[136] = 0x0;
crc_table[137] = 0xC1;
crc_table[138] = 0x81;
crc_table[139] = 0x40;
crc_table[140] = 0x1;
crc_table[141] = 0xC0;
crc_table[142] = 0x80;
crc_table[143] = 0x41;
crc_table[144] = 0x0;
crc_table[145] = 0xC1;
crc_table[146] = 0x81;
crc_table[147] = 0x40;
crc_table[148] = 0x1;
crc_table[149] = 0xC0;
crc_table[150] = 0x80;
crc_table[151] = 0x41;
crc_table[152] = 0x1;
crc_table[153] = 0xC0;
crc_table[154] = 0x80;
crc_table[155] = 0x41;
crc_table[156] = 0x0;
crc_table[157] = 0xC1;
crc_table[158] = 0x81;
crc_table[159] = 0x40;
crc_table[160] = 0x0;
crc_table[161] = 0xC1;
crc_table[162] = 0x81;
crc_table[163] = 0x40;
crc_table[164] = 0x1;
crc_table[165] = 0xC0;
crc_table[166] = 0x80;
crc_table[167] = 0x41;
crc_table[168] = 0x1;
crc_table[169] = 0xC0;
crc_table[170] = 0x80;
crc_table[171] = 0x41;
crc_table[172] = 0x0;
crc_table[173] = 0xC1;
crc_table[174] = 0x81;
crc_table[175] = 0x40;
crc_table[176] = 0x1;
crc_table[177] = 0xC0;
crc_table[178] = 0x80;
crc_table[179] = 0x41;
crc_table[180] = 0x0;
crc_table[181] = 0xC1;
crc_table[182] = 0x81;
crc_table[183] = 0x40;
crc_table[184] = 0x0;
crc_table[185] = 0xC1;
crc_table[186] = 0x81;
crc_table[187] = 0x40;
crc_table[188] = 0x1;
crc_table[189] = 0xC0;
crc_table[190] = 0x80;
crc_table[191] = 0x41;
crc_table[192] = 0x0;
crc_table[193] = 0xC1;
crc_table[194] = 0x81;
crc_table[195] = 0x40;
crc_table[196] = 0x1;
crc_table[197] = 0xC0;
crc_table[198] = 0x80;
crc_table[199] = 0x41;
crc_table[200] = 0x1;
crc_table[201] = 0xC0;
crc_table[202] = 0x80;
crc_table[203] = 0x41;
crc_table[204] = 0x0;
crc_table[205] = 0xC1;
crc_table[206] = 0x81;
crc_table[207] = 0x40;
crc_table[208] = 0x1;
crc_table[209] = 0xC0;
crc_table[210] = 0x80;
crc_table[211] = 0x41;
crc_table[212] = 0x0;
crc_table[213] = 0xC1;
crc_table[214] = 0x81;
crc_table[215] = 0x40;
crc_table[216] = 0x0;
crc_table[217] = 0xC1;
crc_table[218] = 0x81;
crc_table[219] = 0x40;
crc_table[220] = 0x1;
crc_table[221] = 0xC0;
crc_table[222] = 0x80;
crc_table[223] = 0x41;
crc_table[224] = 0x1;
crc_table[225] = 0xC0;
crc_table[226] = 0x80;
crc_table[227] = 0x41;
crc_table[228] = 0x0;
crc_table[229] = 0xC1;
crc_table[230] = 0x81;
crc_table[231] = 0x40;
crc_table[232] = 0x0;
crc_table[233] = 0xC1;
crc_table[234] = 0x81;
crc_table[235] = 0x40;
crc_table[236] = 0x1;
crc_table[237] = 0xC0;
crc_table[238] = 0x80;
crc_table[239] = 0x41;
crc_table[240] = 0x0;
crc_table[241] = 0xC1;
crc_table[242] = 0x81;
crc_table[243] = 0x40;
crc_table[244] = 0x1;
crc_table[245] = 0xC0;
crc_table[246] = 0x80;
crc_table[247] = 0x41;
crc_table[248] = 0x1;
crc_table[249] = 0xC0;
crc_table[250] = 0x80;
crc_table[251] = 0x41;
crc_table[252] = 0x0;
crc_table[253] = 0xC1;
crc_table[254] = 0x81;
crc_table[255] = 0x40;
crc_table[256] = 0x0;
crc_table[257] = 0xC0;
crc_table[258] = 0xC1;
crc_table[259] = 0x1;
crc_table[260] = 0xC3;
crc_table[261] = 0x3;
crc_table[262] = 0x2;
crc_table[263] = 0xC2;
crc_table[264] = 0xC6;
crc_table[265] = 0x6;
crc_table[266] = 0x7;
crc_table[267] = 0xC7;
crc_table[268] = 0x5;
crc_table[269] = 0xC5;
crc_table[270] = 0xC4;
crc_table[271] = 0x4;
crc_table[272] = 0xCC;
crc_table[273] = 0xC;
crc_table[274] = 0xD;
crc_table[275] = 0xCD;
crc_table[276] = 0xF;
crc_table[277] = 0xCF;
crc_table[278] = 0xCE;
crc_table[279] = 0xE;
crc_table[280] = 0xA;
crc_table[281] = 0xCA;
crc_table[282] = 0xCB;
crc_table[283] = 0xB;
crc_table[284] = 0xC9;
crc_table[285] = 0x9;
crc_table[286] = 0x8;
crc_table[287] = 0xC8;
crc_table[288] = 0xD8;
crc_table[289] = 0x18;
crc_table[290] = 0x19;
crc_table[291] = 0xD9;
crc_table[292] = 0x1B;
crc_table[293] = 0xDB;
crc_table[294] = 0xDA;
crc_table[295] = 0x1A;
crc_table[296] = 0x1E;
crc_table[297] = 0xDE;
crc_table[298] = 0xDF;
crc_table[299] = 0x1F;
crc_table[300] = 0xDD;
crc_table[301] = 0x1D;
crc_table[302] = 0x1C;
crc_table[303] = 0xDC;
crc_table[304] = 0x14;
crc_table[305] = 0xD4;
crc_table[306] = 0xD5;
crc_table[307] = 0x15;
crc_table[308] = 0xD7;
crc_table[309] = 0x17;
crc_table[310] = 0x16;
crc_table[311] = 0xD6;
crc_table[312] = 0xD2;
crc_table[313] = 0x12;
crc_table[314] = 0x13;
crc_table[315] = 0xD3;
crc_table[316] = 0x11;
crc_table[317] = 0xD1;
crc_table[318] = 0xD0;
crc_table[319] = 0x10;
crc_table[320] = 0xF0;
crc_table[321] = 0x30;
crc_table[322] = 0x31;
crc_table[323] = 0xF1;
crc_table[324] = 0x33;
crc_table[325] = 0xF3;
crc_table[326] = 0xF2;
crc_table[327] = 0x32;
crc_table[328] = 0x36;
crc_table[329] = 0xF6;
crc_table[330] = 0xF7;
crc_table[331] = 0x37;
crc_table[332] = 0xF5;
crc_table[333] = 0x35;
crc_table[334] = 0x34;
crc_table[335] = 0xF4;
crc_table[336] = 0x3C;
crc_table[337] = 0xFC;
crc_table[338] = 0xFD;
crc_table[339] = 0x3D;
crc_table[340] = 0xFF;
crc_table[341] = 0x3F;
crc_table[342] = 0x3E;
crc_table[343] = 0xFE;
crc_table[344] = 0xFA;
crc_table[345] = 0x3A;
crc_table[346] = 0x3B;
crc_table[347] = 0xFB;
crc_table[348] = 0x39;
crc_table[349] = 0xF9;
crc_table[350] = 0xF8;
crc_table[351] = 0x38;
crc_table[352] = 0x28;
crc_table[353] = 0xE8;
crc_table[354] = 0xE9;
crc_table[355] = 0x29;
crc_table[356] = 0xEB;
crc_table[357] = 0x2B;
crc_table[358] = 0x2A;
crc_table[359] = 0xEA;
crc_table[360] = 0xEE;
crc_table[361] = 0x2E;
crc_table[362] = 0x2F;
crc_table[363] = 0xEF;
crc_table[364] = 0x2D;
crc_table[365] = 0xED;
crc_table[366] = 0xEC;
crc_table[367] = 0x2C;
crc_table[368] = 0xE4;
crc_table[369] = 0x24;
crc_table[370] = 0x25;
crc_table[371] = 0xE5;
crc_table[372] = 0x27;
crc_table[373] = 0xE7;
crc_table[374] = 0xE6;
crc_table[375] = 0x26;
crc_table[376] = 0x22;
crc_table[377] = 0xE2;
crc_table[378] = 0xE3;
crc_table[379] = 0x23;
crc_table[380] = 0xE1;
crc_table[381] = 0x21;
crc_table[382] = 0x20;
crc_table[383] = 0xE0;
crc_table[384] = 0xA0;
crc_table[385] = 0x60;
crc_table[386] = 0x61;
crc_table[387] = 0xA1;
crc_table[388] = 0x63;
crc_table[389] = 0xA3;
crc_table[390] = 0xA2;
crc_table[391] = 0x62;
crc_table[392] = 0x66;
crc_table[393] = 0xA6;
crc_table[394] = 0xA7;
crc_table[395] = 0x67;
crc_table[396] = 0xA5;
crc_table[397] = 0x65;
crc_table[398] = 0x64;
crc_table[399] = 0xA4;
crc_table[400] = 0x6C;
crc_table[401] = 0xAC;
crc_table[402] = 0xAD;
crc_table[403] = 0x6D;
crc_table[404] = 0xAF;
crc_table[405] = 0x6F;
crc_table[406] = 0x6E;
crc_table[407] = 0xAE;
crc_table[408] = 0xAA;
crc_table[409] = 0x6A;
crc_table[410] = 0x6B;
crc_table[411] = 0xAB;
crc_table[412] = 0x69;
crc_table[413] = 0xA9;
crc_table[414] = 0xA8;
crc_table[415] = 0x68;
crc_table[416] = 0x78;
crc_table[417] = 0xB8;
crc_table[418] = 0xB9;
crc_table[419] = 0x79;
crc_table[420] = 0xBB;
crc_table[421] = 0x7B;
crc_table[422] = 0x7A;
crc_table[423] = 0xBA;
crc_table[424] = 0xBE;
crc_table[425] = 0x7E;
crc_table[426] = 0x7F;
crc_table[427] = 0xBF;
crc_table[428] = 0x7D;
crc_table[429] = 0xBD;
crc_table[430] = 0xBC;
crc_table[431] = 0x7C;
crc_table[432] = 0xB4;
crc_table[433] = 0x74;
crc_table[434] = 0x75;
crc_table[435] = 0xB5;
crc_table[436] = 0x77;
crc_table[437] = 0xB7;
crc_table[438] = 0xB6;
crc_table[439] = 0x76;
crc_table[440] = 0x72;
crc_table[441] = 0xB2;
crc_table[442] = 0xB3;
crc_table[443] = 0x73;
crc_table[444] = 0xB1;
crc_table[445] = 0x71;
crc_table[446] = 0x70;
crc_table[447] = 0xB0;
crc_table[448] = 0x50;
crc_table[449] = 0x90;
crc_table[450] = 0x91;
crc_table[451] = 0x51;
crc_table[452] = 0x93;
crc_table[453] = 0x53;
crc_table[454] = 0x52;
crc_table[455] = 0x92;
crc_table[456] = 0x96;
crc_table[457] = 0x56;
crc_table[458] = 0x57;
crc_table[459] = 0x97;
crc_table[460] = 0x55;
crc_table[461] = 0x95;
crc_table[462] = 0x94;
crc_table[463] = 0x54;
crc_table[464] = 0x9C;
crc_table[465] = 0x5C;
crc_table[466] = 0x5D;
crc_table[467] = 0x9D;
crc_table[468] = 0x5F;
crc_table[469] = 0x9F;
crc_table[470] = 0x9E;
crc_table[471] = 0x5E;
crc_table[472] = 0x5A;
crc_table[473] = 0x9A;
crc_table[474] = 0x9B;
crc_table[475] = 0x5B;
crc_table[476] = 0x99;
crc_table[477] = 0x59;
crc_table[478] = 0x58;
crc_table[479] = 0x98;
crc_table[480] = 0x88;
crc_table[481] = 0x48;
crc_table[482] = 0x49;
crc_table[483] = 0x89;
crc_table[484] = 0x4B;
crc_table[485] = 0x8B;
crc_table[486] = 0x8A;
crc_table[487] = 0x4A;
crc_table[488] = 0x4E;
crc_table[489] = 0x8E;
crc_table[490] = 0x8F;
crc_table[491] = 0x4F;
crc_table[492] = 0x8D;
crc_table[493] = 0x4D;
crc_table[494] = 0x4C;
crc_table[495] = 0x8C;
crc_table[496] = 0x44;
crc_table[497] = 0x84;
crc_table[498] = 0x85;
crc_table[499] = 0x45;
crc_table[500] = 0x87;
crc_table[501] = 0x47;
crc_table[502] = 0x46;
crc_table[503] = 0x86;
crc_table[504] = 0x82;
crc_table[505] = 0x42;
crc_table[506] = 0x43;
crc_table[507] = 0x83;
crc_table[508] = 0x41;
crc_table[509] = 0x81;
crc_table[510] = 0x80;
crc_table[511] = 0x40;
}
#region CRC码
/// <summary>
/// 生成CRC码
/// </summary>
/// <param name="message">发送或返回的命令CRC码除外</param>
/// <param name="CRC">生成的CRC码</param>
public short GetCRC(byte[] message, ref byte[] Rcvbuf)
{
int IX,IY,CRC;
int Len = message.Length;
CRC=0xFFFF;
//set all 1
if (Len<=0)
CRC = 0;
else
{
Len--;
for (IX=0;IX<=Len;IX++)
{
CRC=CRC^(message[IX]);
for(IY=0;IY<=7;IY++)
{
if ((CRC&1)!=0 )
CRC=(CRC>>1)^0xA001;
else
CRC=CRC>>1;
//
}
}
}
Rcvbuf[1] = (byte)((CRC & 0xff00)>>8);//高位置
Rcvbuf[0] = (byte)(CRC & 0x00ff); //低位置
CRC= Rcvbuf[0]<<8;
CRC+= Rcvbuf[1];
return (short)CRC;
}
#endregion
#region CRC验证
/// <summary>
/// CRC校验
/// </summary>
/// <param name="src">ST开头&&结尾</param>
/// <returns>十六进制数</returns>
public bool CrcEfficacy(byte[] byteframe)
{
byte[] recvbuff = new byte[2];
byte[] byteArr = new byte[byteframe.Length - 2];
Array.Copy(byteframe, 0, byteArr, 0, byteArr.Length);
GetCRC(byteArr, ref recvbuff);
if (recvbuff[0] == byteframe[byteframe.Length - 2] && recvbuff[1] == byteframe[byteframe.Length - 1])
{
return true;
}
else
{
return false;
}
}
#endregion
}
}

View File

@@ -0,0 +1,311 @@
using System;
using System.Collections.Generic;
using System.IO.Ports;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace ModBus.Net
{
public class ComConnector : Connector, IDisposable
{
private SerialPort serialPort1 = new SerialPort();
public delegate byte[] getDate(byte[] bts);
private getDate mygetDate;
private string com;
public ComConnector(string com)
{
this.com = com;
serialPort1.PortName = com; //端口号
serialPort1.BaudRate = 9600; //比特率
serialPort1.Parity = Parity.None; //奇偶校验
serialPort1.StopBits = StopBits.One; //停止位
serialPort1.DataBits = 8;
serialPort1.ReadTimeout = 1000; //读超时即在1000内未读到数据就引起超时异常
}
#region
public override bool Connect()
{
if (serialPort1 != null)
{
try
{
serialPort1.Open();
return true;
}
catch
{
return false;
}
}
return false;
}
public override bool Disconnect()
{
if (serialPort1 != null)
{
try
{
serialPort1.Close();
return true;
}
catch
{
return false;
}
}
return false;
}
public void SendMsg(string senStr)
{
byte[] myByte = StringToByte_2(senStr);
SendMsg(myByte);
}
public override byte[] SendMsg(byte[] sendbytes)
{
try
{
if (!serialPort1.IsOpen)
{
serialPort1.Open();
}
serialPort1.Write(sendbytes, 0, sendbytes.Length);
return ReadMsg();
}
catch
{
return null;
}
}
public override bool SendMsgWithoutReturn(byte[] sendbytes)
{
try
{
serialPort1.Write(sendbytes, 0, sendbytes.Length);
return true;
}
catch (Exception)
{
return false;
}
}
public string ReadMsgStr()
{
string rd = "";
byte[] data = ReadMsg();
rd = ByteToString(data);
return rd;
}
public byte[] ReadMsg()
{
if (!serialPort1.IsOpen)
{
serialPort1.Open();
}
byte[] data = new byte[200];
int i = serialPort1.Read(data, 0, serialPort1.BytesToRead);
byte[] returndata = new byte[i];
Array.Copy(data, 0, returndata, 0, i);
serialPort1.Close();
return returndata;
}
#endregion
/// <summary>
/// 串口读(非阻塞方式读串口,直到串口缓冲区中没有数据
/// </summary>
/// <param name="readBuf">串口数据缓冲 </param>
/// <param name="bufRoom">串口数据缓冲空间大小 </param>
/// <param name="HowTime">设置串口读放弃时间 </param>
/// <param name="ByteTime">字节间隔最大时间 </param>
/// <returns>串口实际读入数据个数 </returns>
public int ReadComm(out Byte[] readBuf, int bufRoom, int HowTime, int ByteTime)
{
//throw new System.NotImplementedException();
readBuf = new Byte[64];
Array.Clear(readBuf, 0, readBuf.Length);
int nReadLen, nBytelen;
if (serialPort1.IsOpen == false)
return -1;
nBytelen = 0;
serialPort1.ReadTimeout = HowTime;
try
{
readBuf[nBytelen] = (byte) serialPort1.ReadByte();
byte[] bTmp = new byte[1023];
Array.Clear(bTmp, 0, bTmp.Length);
nReadLen = ReadBlock(out bTmp, bufRoom - 1, ByteTime);
if (nReadLen > 0)
{
Array.Copy(bTmp, 0, readBuf, 1, nReadLen);
nBytelen = 1 + nReadLen;
}
else if (nReadLen == 0)
nBytelen = 1;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
return nBytelen;
}
/// <summary>
/// 串口同步读(阻塞方式读串口,直到串口缓冲区中没有数据,靠字符间间隔超时确定没有数据)
/// </summary>
/// <param name="ReadBuf">串口数据缓冲 </param>
/// <param name="ReadRoom">串口数据缓冲空间大小 </param>
/// <param name="ByteTime">字节间隔最大时间 </param>
/// <returns>从串口实际读入的字节个数 </returns>
public int ReadBlock(out byte[] ReadBuf, int ReadRoom, int ByteTime)
{
//throw new System.NotImplementedException();
ReadBuf = new byte[1024];
Array.Clear(ReadBuf, 0, ReadBuf.Length);
sbyte nBytelen;
//long nByteRead;
if (serialPort1.IsOpen == false)
return 0;
nBytelen = 0;
serialPort1.ReadTimeout = ByteTime;
while (nBytelen < (ReadRoom - 1))
{
try
{
ReadBuf[nBytelen] = (byte) serialPort1.ReadByte();
nBytelen++; // add one
}
catch (Exception ex)
{
throw new Exception(ex.Message);
break;
}
}
ReadBuf[nBytelen] = 0x00;
return nBytelen;
}
/// <summary>
/// 字符数组转字符串16进制
/// </summary>
/// <param name="InBytes"> 二进制字节 </param>
/// <returns>类似"01 02 0F" </returns>
public static string ByteToString(byte[] InBytes)
{
string StringOut = "";
foreach (byte InByte in InBytes)
{
StringOut = StringOut + String.Format("{0:X2}", InByte) + " ";
}
return StringOut.Trim();
}
/// <summary>
/// strhex 转字节数组
/// </summary>
/// <param name="InString">类似"01 02 0F" 用空格分开的 </param>
/// <returns> </returns>
public static byte[] StringToByte(string InString)
{
string[] ByteStrings;
ByteStrings = InString.Split(" ".ToCharArray());
byte[] ByteOut;
ByteOut = new byte[ByteStrings.Length];
for (int i = 0; i <= ByteStrings.Length - 1; i++)
{
ByteOut[i] = byte.Parse(ByteStrings[i], System.Globalization.NumberStyles.HexNumber);
}
return ByteOut;
}
/// <summary>
/// strhex 转字节数组
/// </summary>
/// <param name="InString">类似"01 02 0F" 中间无空格 </param>
/// <returns> </returns>
public static byte[] StringToByte_2(string InString)
{
byte[] ByteOut;
InString = InString.Replace(" ", "");
try
{
string[] ByteStrings = new string[InString.Length/2];
int j = 0;
for (int i = 0; i < ByteStrings.Length; i++)
{
ByteStrings[i] = InString.Substring(j, 2);
j += 2;
}
ByteOut = new byte[ByteStrings.Length];
for (int i = 0; i <= ByteStrings.Length - 1; i++)
{
ByteOut[i] = byte.Parse(ByteStrings[i], System.Globalization.NumberStyles.HexNumber);
}
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
return ByteOut;
}
/// <summary>
/// 字符串 转16进制字符串
/// </summary>
/// <param name="InString">unico </param>
/// <returns>类似“01 0f” </returns>
public static string Str_To_0X(string InString)
{
return ByteToString(UnicodeEncoding.Default.GetBytes(InString));
}
public void Dispose()
{
if (serialPort1 != null)
{
serialPort1.Close();
serialPort1.Dispose();
}
}
}
}

View File

@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ModBus.Net
{
public abstract class ComProtocalLinker : ProtocalLinker
{
protected ComProtocalLinker()
{
//初始化连对象
_baseConnector = new ComConnector(ConfigurationManager.COM);
}
protected ComProtocalLinker(string com)
{
_baseConnector = new ComConnector(com);
}
}
}

View File

@@ -60,6 +60,15 @@ namespace ModBus.Net {
}
}
/// <summary>
/// 查找类似 COM3 的本地化字符串。
/// </summary>
internal static string COM {
get {
return ResourceManager.GetString("COM", resourceCulture);
}
}
/// <summary>
/// 查找类似 192.168.3.247 的本地化字符串。
/// </summary>

View File

@@ -117,6 +117,9 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="COM" xml:space="preserve">
<value>COM3</value>
</data>
<data name="IP" xml:space="preserve">
<value>192.168.3.247</value>
</data>

View File

@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ModBus.Net
{
public abstract class Connector
{
public abstract bool Connect();
public abstract bool Disconnect();
public abstract bool SendMsgWithoutReturn(byte[] message);
public abstract byte[] SendMsg(byte[] message);
}
}

View File

@@ -43,24 +43,29 @@
<ItemGroup>
<Compile Include="AddressTranslator.cs" />
<Compile Include="BaseProtocal.cs" />
<Compile Include="ComConnector.cs" />
<Compile Include="ComProtocalLinker.cs" />
<Compile Include="ConfigurationManager.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>ConfigurationManager.resx</DependentUpon>
</Compile>
<Compile Include="Connector.cs" />
<Compile Include="CRC16.cs" />
<Compile Include="IProtocalFormatting.cs" />
<Compile Include="ModbusComProtocal.cs" />
<Compile Include="ModbusComProtocalLinker.cs" />
<Compile Include="ModbusTcpProtocalLinker.cs" />
<Compile Include="Prodave\ProdavePackLv1.cs" />
<Compile Include="ProtocalLinker.cs" />
<Compile Include="ProtocalLinkerBytesExtend.cs" />
<Compile Include="ProtocalUnit.cs" />
<Compile Include="ModbusProtocal.cs" />
<Compile Include="ModbusTCPProtocal.cs" />
<Compile Include="ModbusTcpProtocal.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TCPSocket.cs">
<Compile Include="TcpSocket.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="TCPProtocalLinker.cs" />
<Compile Include="TcpProtocalLinker.cs" />
<Compile Include="ValueHelper.cs" />
</ItemGroup>
<ItemGroup>

View File

@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ModBus.Net
{
public class ModbusComProtocal : ModbusProtocal
{
public ModbusComProtocal()
{
_protocalLinker = new ModbusComProtocalLinker();
}
public ModbusComProtocal(string com)
{
_protocalLinker = new ModbusComProtocalLinker(com);
}
}
}

View File

@@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ModBus.Net
{
class ModbusComProtocalLinker : ComProtocalLinker
{
public override bool CheckRight(byte[] content)
{
if (!Crc16.GetInstance().CrcEfficacy(content))
{
throw new ModbusProtocalErrorException(501);
}
if (content[1] > 127)
{
throw new ModbusProtocalErrorException(content[2]);
}
return true;
}
public ModbusComProtocalLinker() : base()
{
}
public ModbusComProtocalLinker(string com) : base(com)
{
}
}
}

View File

@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
public enum ModbusProtocalReg
{
@@ -782,4 +783,35 @@ namespace ModBus.Net
}
}
public class ProtocalErrorException : Exception
{
public ProtocalErrorException(string message)
: base(message)
{
}
}
public class ModbusProtocalErrorException : ProtocalErrorException
{
public int ErrorMessageNumber { get; private set; }
private static readonly Dictionary<int, string> ProtocalErrorDictionary = new Dictionary<int, string>()
{
{1, "ILLEGAL_FUNCTION"},
{2, "ILLEGAL_DATA_ACCESS"},
{3, "ILLEGAL_DATA_VALUE"},
{4, "SLAVE_DEVICE_FAILURE"},
{5, "ACKNOWLWDGE"},
{6, "SLAVE_DEVICE_BUSY"},
{500, "TCP_ILLEGAL_LENGTH"},
{501, "RTU_ILLEGAL_CRC"},
};
public ModbusProtocalErrorException(int messageNumber)
: base(ProtocalErrorDictionary[messageNumber])
{
ErrorMessageNumber = messageNumber;
}
}
}

View File

@@ -13,9 +13,9 @@ namespace ModBus.Net
_protocalLinker = new ModbusTcpProtocalLinker();
}
public ModbusTcpProtocal(string IP)
public ModbusTcpProtocal(string ip)
{
_protocalLinker = new ModbusTcpProtocalLinker(IP);
_protocalLinker = new ModbusTcpProtocalLinker(ip);
}
}
}

View File

@@ -10,7 +10,11 @@ namespace ModBus.Net
{
public override bool CheckRight(byte[] content)
{
if (content[1] > 127)
if (content[5] != content.Length - 6)
{
throw new ModbusProtocalErrorException(500);
}
if (content[7] > 127)
{
throw new ModbusProtocalErrorException(content[2]);
}
@@ -22,7 +26,7 @@ namespace ModBus.Net
}
public ModbusTcpProtocalLinker(string IP) : base(IP)
public ModbusTcpProtocalLinker(string ip) : base(ip)
{
}

View File

@@ -7,19 +7,32 @@ namespace ModBus.Net
/// </summary>
public abstract class ProtocalLinker
{
protected Connector _baseConnector;
/// <summary>
/// 发送并接收数据
/// </summary>
/// <param name="content">发送协议的内容</param>
/// <returns>接收协议的内容</returns>
public abstract byte[] SendReceive(byte[] content);
public virtual byte[] SendReceive(byte[] content)
{
//接收数据
byte[] receiveBytes = _baseConnector.SendMsg(BytesExtend(content));
//容错处理
if (!CheckRight(receiveBytes)) return null;
//返回数据
return BytesDecact(receiveBytes);
}
/// <summary>
/// 仅发送数据
/// </summary>
/// <param name="content">发送协议的内容</param>
/// <returns>协议是否正确发送</returns>
public abstract bool SendOnly(byte[] content);
public virtual bool SendOnly(byte[] content)
{
return _baseConnector.SendMsgWithoutReturn(BytesExtend(content));
}
/// <summary>
/// 检查接收的数据是否正确

View File

@@ -51,4 +51,26 @@ namespace ModBus.Net
return newContent;
}
}
public class ModbusComProtocalLinkerBytesExtend : ProtocalLinkerBytesExtend
{
public override byte[] BytesExtend(byte[] content)
{
byte[] crc = new byte[2];
//Modbus/Tcp协议扩张增加CRC校验
byte[] newFormat = new byte[content.Length + 2];
Crc16.GetInstance().GetCRC(content, ref crc);
Array.Copy(content, 0, newFormat, 0, content.Length);
Array.Copy(crc, 0, newFormat, newFormat.Length - 2, crc.Length);
return newFormat;
}
public override byte[] BytesDecact(byte[] content)
{
//Modbus/Com协议收缩抛弃后面1个字节的内容
byte[] newContent = new byte[content.Length - 2];
Array.Copy(content, 0, newContent, 0, newContent.Length);
return newContent;
}
}
}

View File

@@ -9,62 +9,16 @@ namespace ModBus.Net
/// <summary>
/// 连接对象
/// </summary>
private TcpSocket _socket;
protected TcpProtocalLinker()
{
//初始化连对象
_socket = new TcpSocket(ConfigurationManager.IP, int.Parse(ConfigurationManager.Port), false);
_baseConnector = new TcpSocket(ConfigurationManager.IP, int.Parse(ConfigurationManager.Port), false);
}
protected TcpProtocalLinker(string IP)
protected TcpProtocalLinker(string ip)
{
_socket = new TcpSocket(IP, int.Parse(ConfigurationManager.Port), false);
}
public override byte[] SendReceive(byte[] content)
{
//接收数据
byte[] receiveBytes = BytesDecact(_socket.SendMsg(BytesExtend(content)));
//容错处理
if (!CheckRight(receiveBytes)) return null;
//返回数据
return receiveBytes;
}
public override bool SendOnly(byte[] content)
{
return _socket.SendMsgWithoutReturn(BytesExtend(content));
}
}
public class ProtocalErrorException : Exception
{
public ProtocalErrorException(string message):base(message)
{
}
}
public class ModbusProtocalErrorException : ProtocalErrorException
{
public int ErrorMessageNumber { get; private set; }
private static readonly Dictionary<int, string> ProtocalErrorDictionary = new Dictionary<int, string>()
{
{1, "ILLEGAL_FUNCTION"},
{2, "ILLEGAL_DATA_ACCESS"},
{3, "ILLEGAL_DATA_VALUE"},
{4, "SLAVE_DEVICE_FAILURE"},
{5, "ACKNOWLWDGE"},
{6, "SLAVE_DEVICE_BUSY"},
};
public ModbusProtocalErrorException(int messageNumber) : base(ProtocalErrorDictionary[messageNumber])
{
ErrorMessageNumber = messageNumber;
_baseConnector = new TcpSocket(ip, int.Parse(ConfigurationManager.Port), false);
}
}
}

View File

@@ -21,7 +21,7 @@ namespace ModBus.Net
/// Socket收发类
/// 作者本类来源于CSDN并由罗圣Chris L.)根据实际需要修改
/// </summary>
public class TcpSocket : IDisposable
public class TcpSocket : Connector, IDisposable
{
public delegate void ErrorShutdownEventHandler(object sender, EventArgs e);
@@ -70,7 +70,7 @@ namespace ModBus.Net
}
}
public bool Connect()
public override bool Connect()
{
if (m_socketClient != null)
{
@@ -99,23 +99,25 @@ namespace ModBus.Net
}
}
public void Disconnect()
public override bool Disconnect()
{
lock (this)
{
if (m_socketClient == null)
{
return;
return true;
}
try
{
m_socketClient.Close();
AddInfo("client disconnected successfully.");
return true;
}
catch (Exception err)
{
AddInfo("client disconnected exception: " + err.Message);
return false;
}
finally
{
@@ -134,7 +136,7 @@ namespace ModBus.Net
/// </summary>
/// <param name="message">发送的信息</param>
/// <returns>是否发送成功</returns>
public bool SendMsgWithoutReturn(byte[] message)
public override bool SendMsgWithoutReturn(byte[] message)
{
byte[] datagram = message;
@@ -159,7 +161,7 @@ namespace ModBus.Net
/// </summary>
/// <param name="message">发送的数据</param>
/// <returns>是否发送成功</returns>
public byte[] SendMsg(byte[] message)
public override byte[] SendMsg(byte[] message)
{
byte[] datagram = message;

View File

@@ -20,7 +20,7 @@ namespace NA200H.UI.ConsoleApp
BaseProtocal wrapper = new ModbusTcpProtocal(ip);
Console.WriteLine("link ip is {0}",ip);
//第一步先生成一个输入信息的object数组
object[] inputObjects = new object[] {(byte) 0x11, (byte) 0x01, (short) 0x13, (short) 0x25};
object[] inputObjects = new object[] {(byte) 0x02, (byte) 0x01, (short) 0x13, (short) 0x25};
//第二步:向仪器发送这个信息,并接收信息
byte[] outputBytes = wrapper.SendReceive(inputObjects);
//第三步:输出信息
@@ -38,7 +38,7 @@ namespace NA200H.UI.ConsoleApp
*/
string ip = "192.168.3.246";
/*string ip = "192.168.3.246";
try
{
Console.WriteLine("link ip is {0}",ip);
@@ -66,15 +66,34 @@ namespace NA200H.UI.ConsoleApp
Console.WriteLine("prodave link failed");
}
Console.Read();
*/
//先初始化一个协议转换器这里构造Modbus/Tcp协议。
/*BaseProtocal wrapper = new ModbusTcpProtocal();
//BaseProtocal wrapper = new ModbusTcpProtocal();
/*
//调用方法一:手动构造
//第一步先生成一个输入信息的object数组
object[] inputObjects = new object[]{(byte)0x02,(byte)0x01,(short)0x13,(short)0x25};
//第二步:向仪器发送这个信息,并接收信息
byte[] outputBytes = wrapper.SendReceive(inputObjects);
//第三步:输出信息
for (int i = 0; i < outputBytes.Length; i++)
{
Console.WriteLine(outputBytes[i]);
}
Console.WriteLine();
Console.Read();
Console.Read();
*/
//先初始化一个协议转换器这里构造Modbus/Rtu协议。
BaseProtocal wrapper = new ModbusComProtocal();
//调用方法一:手动构造
//第一步先生成一个输入信息的object数组
object[] inputObjects = new object[]{(byte)0x11,(byte)0x01,(short)0x13,(short)0x25};
object[] inputObjects = new object[]{(byte)0x02,(byte)0x01,(short)0x00,(short)0x03};
//第二步:向仪器发送这个信息,并接收信息
byte[] outputBytes = wrapper.SendReceive(inputObjects);
//第三步:输出信息
@@ -86,9 +105,10 @@ namespace NA200H.UI.ConsoleApp
Console.Read();
Console.Read();
/*
//调用方法二:自动构造
//第一步:先生成一个输入结构体,然后向这个结构体中填写数据
ReadCoilStatusModbusProtocal.ReadCoilStatusInputStruct readCoilStatusInputStruct = new ReadCoilStatusModbusProtocal.ReadCoilStatusInputStruct(0x11, "Q20", 0x25);
ReadCoilStatusModbusProtocal.ReadCoilStatusInputStruct readCoilStatusInputStruct = new ReadCoilStatusModbusProtocal.ReadCoilStatusInputStruct(0x02, "Q20", 0x25);
//第二步:再生成一个输出结构体,执行相应协议的发送指令,并将输出信息自动转换到输出结构体中
ReadCoilStatusModbusProtocal.ReadCoilStatusOutputStruct readCoilStatusOutputStruct = (ReadCoilStatusModbusProtocal.ReadCoilStatusOutputStruct)wrapper.SendReceive(wrapper["ReadCoilStatusModbusProtocal"], readCoilStatusInputStruct);
//第三步:读取这个输出结构体的信息。
@@ -100,7 +120,7 @@ namespace NA200H.UI.ConsoleApp
Console.Read();
Console.Read();
ReadInputStatusModbusProtocal.ReadInputStatusInputStruct readInputStatusInputStruct = new ReadInputStatusModbusProtocal.ReadInputStatusInputStruct(0x11, "I20", 0x25);
ReadInputStatusModbusProtocal.ReadInputStatusInputStruct readInputStatusInputStruct = new ReadInputStatusModbusProtocal.ReadInputStatusInputStruct(0x02, "I20", 0x25);
ReadInputStatusModbusProtocal.ReadInputStatusOutputStruct readInputStatusOutputStruct = (ReadInputStatusModbusProtocal.ReadInputStatusOutputStruct)wrapper.SendReceive(wrapper["ReadInputStatusModbusProtocal"], readInputStatusInputStruct);
for (int i = 0; i < readInputStatusOutputStruct.InputStatus.Length; i++)
{
@@ -110,7 +130,7 @@ namespace NA200H.UI.ConsoleApp
Console.Read();
Console.Read();
ReadHoldRegisterModbusProtocal.ReadHoldRegisterInputStruct readHoldRegisterInputStruct = new ReadHoldRegisterModbusProtocal.ReadHoldRegisterInputStruct(0x11, "0", 8);
ReadHoldRegisterModbusProtocal.ReadHoldRegisterInputStruct readHoldRegisterInputStruct = new ReadHoldRegisterModbusProtocal.ReadHoldRegisterInputStruct(0x02, "0", 8);
ReadHoldRegisterModbusProtocal.ReadHoldRegisterOutputStruct readHoldRegisterOutputStruct = (ReadHoldRegisterModbusProtocal.ReadHoldRegisterOutputStruct)wrapper.SendReceive(wrapper["ReadHoldRegisterModbusProtocal"], readHoldRegisterInputStruct);
for (int i = 0; i < readHoldRegisterOutputStruct.HoldRegisterStatus.Length; i++)
{
@@ -120,7 +140,7 @@ namespace NA200H.UI.ConsoleApp
Console.Read();
Console.Read();
ReadInputRegisterModbusProtocal.ReadInputRegisterInputStruct readInputRegisterInputStruct = new ReadInputRegisterModbusProtocal.ReadInputRegisterInputStruct(0x11, "IW1", 3);
ReadInputRegisterModbusProtocal.ReadInputRegisterInputStruct readInputRegisterInputStruct = new ReadInputRegisterModbusProtocal.ReadInputRegisterInputStruct(0x02, "IW1", 3);
ReadInputRegisterModbusProtocal.ReadInputRegisterOutputStruct readInputRegisterOutputStruct = (ReadInputRegisterModbusProtocal.ReadInputRegisterOutputStruct)wrapper.SendReceive(wrapper["ReadInputRegisterModbusProtocal"], readInputRegisterInputStruct);
for (int i = 0; i < readInputRegisterOutputStruct.InputRegisterStatus.Length; i++)
{
@@ -130,7 +150,7 @@ namespace NA200H.UI.ConsoleApp
Console.Read();
Console.Read();
ReadInputRegisterModbusProtocal.ReadInputRegisterInputStruct readInputRegisterInputStruct2 = new ReadInputRegisterModbusProtocal.ReadInputRegisterInputStruct(0x11, "E38", 8);
ReadInputRegisterModbusProtocal.ReadInputRegisterInputStruct readInputRegisterInputStruct2 = new ReadInputRegisterModbusProtocal.ReadInputRegisterInputStruct(0x02, "E38", 8);
ReadInputRegisterModbusProtocal.ReadEventOutputStruct readEventOutputStruct = (ReadInputRegisterModbusProtocal.ReadEventOutputStruct)wrapper.SendReceive(wrapper["ReadInputRegisterModbusProtocal"], readInputRegisterInputStruct2);
Console.WriteLine(readEventOutputStruct.SoeEvent);
Console.WriteLine(readEventOutputStruct.TestTime);
@@ -138,7 +158,7 @@ namespace NA200H.UI.ConsoleApp
Console.Read();
Console.Read();
WriteOneCoilModbusProtocal.WriteOneCoilInputStruct writeOneCoilInputStruct = new WriteOneCoilModbusProtocal.WriteOneCoilInputStruct(0x11, "Q173", true);
WriteOneCoilModbusProtocal.WriteOneCoilInputStruct writeOneCoilInputStruct = new WriteOneCoilModbusProtocal.WriteOneCoilInputStruct(0x02, "Q173", true);
WriteOneCoilModbusProtocal.WriteOneCoilOutputStruct writeOneCoilOutputStruct = (WriteOneCoilModbusProtocal.WriteOneCoilOutputStruct)wrapper.SendReceive(wrapper["WriteOneCoilModbusProtocal"], writeOneCoilInputStruct);
Console.WriteLine(writeOneCoilOutputStruct.StartAddress);
Console.WriteLine(writeOneCoilOutputStruct.WriteValue);
@@ -146,7 +166,7 @@ namespace NA200H.UI.ConsoleApp
Console.Read();
Console.Read();
WriteOneRegisterModbusProtocal.WriteOneRegisterInputStruct writeOneRegisterInputStruct = new WriteOneRegisterModbusProtocal.WriteOneRegisterInputStruct(0x11, "NW1", 100);
WriteOneRegisterModbusProtocal.WriteOneRegisterInputStruct writeOneRegisterInputStruct = new WriteOneRegisterModbusProtocal.WriteOneRegisterInputStruct(0x02, "NW1", 100);
WriteOneRegisterModbusProtocal.WriteOneRegisterOutputStruct writeOneRegisterOutputStruct = (WriteOneRegisterModbusProtocal.WriteOneRegisterOutputStruct)wrapper.SendReceive(wrapper["WriteOneRegisterModbusProtocal"], writeOneRegisterInputStruct);
Console.WriteLine(writeOneRegisterOutputStruct.StartAddress);
Console.WriteLine(writeOneRegisterOutputStruct.WriteValue);
@@ -154,7 +174,7 @@ namespace NA200H.UI.ConsoleApp
Console.Read();
Console.Read();
WriteMultiCoilModbusProtocal.WriteMultiCoilInputStruct writeMultiCoilInputStruct = new WriteMultiCoilModbusProtocal.WriteMultiCoilInputStruct(0x11, "Q20", new bool[] { true, false, true, true, false, false, true, true, true, false });
WriteMultiCoilModbusProtocal.WriteMultiCoilInputStruct writeMultiCoilInputStruct = new WriteMultiCoilModbusProtocal.WriteMultiCoilInputStruct(0x02, "Q20", new bool[] { true, false, true, true, false, false, true, true, true, false });
WriteMultiCoilModbusProtocal.WriteMultiCoilOutputStruct writeMultiCoilOutputStruct = (WriteMultiCoilModbusProtocal.WriteMultiCoilOutputStruct)wrapper.SendReceive(wrapper["WriteMultiCoilModbusProtocal"], writeMultiCoilInputStruct);
Console.WriteLine(writeMultiCoilOutputStruct.StartAddress);
Console.WriteLine(writeMultiCoilOutputStruct.WriteCount);
@@ -162,7 +182,7 @@ namespace NA200H.UI.ConsoleApp
Console.Read();
Console.Read();
WriteMultiRegisterModbusProtocal.WriteMultiRegisterInputStruct writeMultiRegisterInputStruct = new WriteMultiRegisterModbusProtocal.WriteMultiRegisterInputStruct(0x11, "MW2", new ushort[] { 0x000A, 0x0102 });
WriteMultiRegisterModbusProtocal.WriteMultiRegisterInputStruct writeMultiRegisterInputStruct = new WriteMultiRegisterModbusProtocal.WriteMultiRegisterInputStruct(0x02, "MW2", new ushort[] { 0x000A, 0x0102 });
WriteMultiRegisterModbusProtocal.WriteMultiRegisterOutputStruct writeMultiRegisterOutputStruct = (WriteMultiRegisterModbusProtocal.WriteMultiRegisterOutputStruct)wrapper.SendReceive(wrapper["WriteMultiRegisterModbusProtocal"], writeMultiRegisterInputStruct);
Console.WriteLine(writeMultiRegisterOutputStruct.StartAddress);
Console.WriteLine(writeMultiRegisterOutputStruct.WriteCount);
@@ -170,13 +190,13 @@ namespace NA200H.UI.ConsoleApp
Console.Read();
Console.Read();
GetSystemTimeModbusProtocal.GetSystemTimeInputStruct getSystemTimeInputStruct = new GetSystemTimeModbusProtocal.GetSystemTimeInputStruct(0x11);
GetSystemTimeModbusProtocal.GetSystemTimeInputStruct getSystemTimeInputStruct = new GetSystemTimeModbusProtocal.GetSystemTimeInputStruct(0x02);
GetSystemTimeModbusProtocal.GetSystemTimeOutputStruct getSystemTimeOutputStruct = (GetSystemTimeModbusProtocal.GetSystemTimeOutputStruct)wrapper.SendReceive(wrapper["GetSystemTimeModbusProtocal"], getSystemTimeInputStruct);
Console.WriteLine(getSystemTimeOutputStruct.Time);
Console.Read();
Console.Read();
SetSystemTimeModbusProtocal.SetSystemTimeInputStruct setSystemTimeInputStruct = new SetSystemTimeModbusProtocal.SetSystemTimeInputStruct(0x11, DateTime.Now);
SetSystemTimeModbusProtocal.SetSystemTimeInputStruct setSystemTimeInputStruct = new SetSystemTimeModbusProtocal.SetSystemTimeInputStruct(0x02, DateTime.Now);
SetSystemTimeModbusProtocal.SetSystemTimeOutputStruct setSystemTimeOutputStruct = (SetSystemTimeModbusProtocal.SetSystemTimeOutputStruct)wrapper.SendReceive(wrapper["SetSystemTimeModbusProtocal"], setSystemTimeInputStruct);
Console.WriteLine(setSystemTimeOutputStruct.StartAddress);
Console.WriteLine(setSystemTimeOutputStruct.WriteCount);

View File

@@ -1,14 +1,12 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.30501.0
VisualStudioVersion = 12.0.30723.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NA200H.UI.ConsoleApp", "NA200H.UI.Console\NA200H.UI.ConsoleApp.csproj", "{D06F6A34-93F6-4139-B485-8F5686E4E2C9}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ModBus.Net", "ModBus.Net\ModBus.Net.csproj", "{124EBEF2-8960-4447-84CF-1D683B1EF7CC}"
EndProject
Project("{F088123C-0E9E-452A-89E6-6BA2F21D5CAC}") = "ModBus.Net.Modeling", "ModBus.Net.Modeling\ModBus.Net.Modeling.modelproj", "{FA929E21-544C-444E-B18D-184E98B427C6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NA200H.UI.WPF", "NA200H.UI.WPF\NA200H.UI.WPF.csproj", "{78916B03-C910-468E-B593-667A3EFF68BE}"
EndProject
Global
@@ -25,10 +23,6 @@ Global
{124EBEF2-8960-4447-84CF-1D683B1EF7CC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{124EBEF2-8960-4447-84CF-1D683B1EF7CC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{124EBEF2-8960-4447-84CF-1D683B1EF7CC}.Release|Any CPU.Build.0 = Release|Any CPU
{FA929E21-544C-444E-B18D-184E98B427C6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FA929E21-544C-444E-B18D-184E98B427C6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FA929E21-544C-444E-B18D-184E98B427C6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FA929E21-544C-444E-B18D-184E98B427C6}.Release|Any CPU.Build.0 = Release|Any CPU
{78916B03-C910-468E-B593-667A3EFF68BE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{78916B03-C910-468E-B593-667A3EFF68BE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{78916B03-C910-468E-B593-667A3EFF68BE}.Release|Any CPU.ActiveCfg = Release|Any CPU