Zixuan 2 weeks ago
parent
commit
9cfedd69ab

+ 7 - 0
.gitignore

@@ -22,3 +22,10 @@
 /TLVProtocal
 /Universal/bin/Debug/net8.0
 /UniversalNetFrame451
+/CommunicationProtocols/FinsTcp/bin/Debug/net8.0
+/CommunicationProtocols/FinsTcp/obj
+/CommunicationProtocols/ModBusTcp/obj
+/CommunicationProtocols/ProtocalGeneral/bin/Debug/net8.0
+/CommunicationProtocols/ProtocalGeneral/obj
+/ConsoleData/RealtimeData/bin/Debug/net8.0
+/CommunicationProtocols/ModBusTcp/bin/Debug/net8.0

+ 13 - 0
CommunicationProtocols/FinsTcp/FinsTcp.csproj

@@ -0,0 +1,13 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+  <PropertyGroup>
+    <TargetFramework>net8.0</TargetFramework>
+    <ImplicitUsings>enable</ImplicitUsings>
+    <Nullable>enable</Nullable>
+  </PropertyGroup>
+
+  <ItemGroup>
+    <ProjectReference Include="..\ProtocalGeneral\ProtocalGeneral.csproj" />
+  </ItemGroup>
+
+</Project>

+ 3 - 2
Universal/IO/FinsTcpBase.cs

@@ -1,6 +1,7 @@
-using System.Text.RegularExpressions;
+using System.Net.Sockets;
+using System.Text.RegularExpressions;
 
-namespace Universal.IO;
+namespace FinsTcp;
 //This is a copy of a Open library POmronFinsTCP.Net
 //I have modified tcpclient sendtimeout and receivetimeout time to make sure it can know connect status when device connect into a switch
 //Please ignore all the warnings and Messages,I know the code is in a mess, but it is working.

+ 3 - 1
Universal/IO/Fins_Tcp.cs

@@ -1,4 +1,6 @@
-namespace Universal.IO;
+using ProtocalGeneral;
+
+namespace FinsTcp;
 
 public class Fins_Tcp : IDisposable
 {

+ 15 - 0
CommunicationProtocols/ModBusTcp/IModBus.cs

@@ -0,0 +1,15 @@
+using ProtocalGeneral;
+
+namespace ModBusTcp;
+
+public interface IModBus<T_buffer>
+{
+    bool Initialize(string name, ITcpConnectNority tcpConnect);
+
+    T_buffer GetBuffer(ushort index, ushort count, byte slaveAddress = 1);
+    bool SetUshort(ushort index, ushort value, byte slaveAddress = 1);
+    bool SetValue<T>(ushort index, T value, byte slaveAddress = 1) where T : struct;
+    bool SetFloat(ushort index, float value, byte slaveAddress = 1);
+    bool Open(string ip, ushort port, bool notify = true);
+    bool Close();
+}

+ 18 - 0
CommunicationProtocols/ModBusTcp/ModBusTcp.csproj

@@ -0,0 +1,18 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+  <PropertyGroup>
+    <TargetFramework>net8.0</TargetFramework>
+    <ImplicitUsings>enable</ImplicitUsings>
+    <Nullable>enable</Nullable>
+    <AllowUnsafeBlocks>True</AllowUnsafeBlocks>
+  </PropertyGroup>
+
+  <ItemGroup>
+    <PackageReference Include="FluentModbus" />
+  </ItemGroup>
+
+  <ItemGroup>
+    <ProjectReference Include="..\ProtocalGeneral\ProtocalGeneral.csproj" />
+  </ItemGroup>
+
+</Project>

+ 3 - 1
Universal/IO/Modbus_Tcp.cs

@@ -1,7 +1,9 @@
 using FluentModbus;
+using ProtocalGeneral;
+using System.Net;
 using System.Runtime.InteropServices;
 
-namespace Universal.IO;
+namespace ModBusTcp;
 
 public class Modbus_Tcp : IModBus<byte[]?>
 {

+ 7 - 0
CommunicationProtocols/ProtocalGeneral/ITcpConnectNority.cs

@@ -0,0 +1,7 @@
+namespace ProtocalGeneral;
+
+public interface ITcpConnectNority
+{
+    void Connect(string ip, int port);
+    void DisConnect(string ip, int port);
+}

+ 9 - 0
CommunicationProtocols/ProtocalGeneral/ProtocalGeneral.csproj

@@ -0,0 +1,9 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+  <PropertyGroup>
+    <TargetFramework>net8.0</TargetFramework>
+    <ImplicitUsings>enable</ImplicitUsings>
+    <Nullable>enable</Nullable>
+  </PropertyGroup>
+
+</Project>

+ 2 - 2
Communicators/Mini8Communicator/Mini8CommunicatorModbus/Mini8Communcator_Modbus_FluentModbus.cs

@@ -2,10 +2,10 @@
 using HardwareData;
 using Mini8Communicator;
 using Mini8CommunicatorData;
+using ModBusTcp;
+using ProtocalGeneral;
 using System.Collections.Concurrent;
-using System.Runtime.CompilerServices;
 using Universal;
-using Universal.IO;
 
 namespace Mini8CommunicatorModbus;
 

+ 2 - 0
Communicators/Mini8Communicator/Mini8CommunicatorModbus/Mini8CommunicatorModbus.csproj

@@ -8,6 +8,8 @@
   </PropertyGroup>
 
   <ItemGroup>
+    <ProjectReference Include="..\..\..\CommunicationProtocols\ModBusTcp\ModBusTcp.csproj" />
+    <ProjectReference Include="..\..\..\CommunicationProtocols\ProtocalGeneral\ProtocalGeneral.csproj" />
     <ProjectReference Include="..\..\..\Universal\Universal.csproj" />
     <ProjectReference Include="..\IMini8Communicator\Mini8Communicator.csproj" />
   </ItemGroup>

+ 23 - 0
Minics.sln

@@ -81,6 +81,14 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ToMcFile", "Tools\ToMcFile\
 EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UserTool", "Tools\UserTool\UserTool.csproj", "{22A738CB-6CA3-4D57-85BE-DEDFA62771CE}"
 EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "CommunicationProtocols", "CommunicationProtocols", "{165A518A-753D-4062-A100-9367AF27F900}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FinsTcp", "CommunicationProtocols\FinsTcp\FinsTcp.csproj", "{85D48105-88EC-4B80-B394-76DB988F6DD4}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ModBusTcp", "CommunicationProtocols\ModBusTcp\ModBusTcp.csproj", "{6B500EDB-EB90-4AA6-A0EB-90241292D370}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProtocalGeneral", "CommunicationProtocols\ProtocalGeneral\ProtocalGeneral.csproj", "{55EC57EB-3DA4-4289-803F-4661A6EAE1B9}"
+EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Any CPU = Debug|Any CPU
@@ -203,6 +211,18 @@ Global
 		{22A738CB-6CA3-4D57-85BE-DEDFA62771CE}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{22A738CB-6CA3-4D57-85BE-DEDFA62771CE}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{22A738CB-6CA3-4D57-85BE-DEDFA62771CE}.Release|Any CPU.Build.0 = Release|Any CPU
+		{85D48105-88EC-4B80-B394-76DB988F6DD4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{85D48105-88EC-4B80-B394-76DB988F6DD4}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{85D48105-88EC-4B80-B394-76DB988F6DD4}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{85D48105-88EC-4B80-B394-76DB988F6DD4}.Release|Any CPU.Build.0 = Release|Any CPU
+		{6B500EDB-EB90-4AA6-A0EB-90241292D370}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{6B500EDB-EB90-4AA6-A0EB-90241292D370}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{6B500EDB-EB90-4AA6-A0EB-90241292D370}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{6B500EDB-EB90-4AA6-A0EB-90241292D370}.Release|Any CPU.Build.0 = Release|Any CPU
+		{55EC57EB-3DA4-4289-803F-4661A6EAE1B9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{55EC57EB-3DA4-4289-803F-4661A6EAE1B9}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{55EC57EB-3DA4-4289-803F-4661A6EAE1B9}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{55EC57EB-3DA4-4289-803F-4661A6EAE1B9}.Release|Any CPU.Build.0 = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE
@@ -233,6 +253,9 @@ Global
 		{3AF5BCA8-B733-418D-A505-A612F3A86DEF} = {E83657AA-CDD7-4902-BB99-1069D6D13930}
 		{A70AB3BF-57A6-45A5-BE37-61A8BEA80924} = {2783D72A-0926-427D-B70D-5F3F5FA757FC}
 		{22A738CB-6CA3-4D57-85BE-DEDFA62771CE} = {2783D72A-0926-427D-B70D-5F3F5FA757FC}
+		{85D48105-88EC-4B80-B394-76DB988F6DD4} = {165A518A-753D-4062-A100-9367AF27F900}
+		{6B500EDB-EB90-4AA6-A0EB-90241292D370} = {165A518A-753D-4062-A100-9367AF27F900}
+		{55EC57EB-3DA4-4289-803F-4661A6EAE1B9} = {165A518A-753D-4062-A100-9367AF27F900}
 	EndGlobalSection
 	GlobalSection(ExtensibilityGlobals) = postSolution
 		SolutionGuid = {2E8CB4A6-1AFA-4CB2-BA42-1BAFC71AD68B}

+ 4 - 1
MinicsConsole/Connector/PLCNotifier.cs

@@ -1,4 +1,7 @@
-namespace MinicsConsole.Connector;
+using FinsTcp;
+using ProtocalGeneral;
+
+namespace MinicsConsole.Connector;
 
 public class PLCNotifier(HardwareAddress address, ILog log) : IMini8DataNotifier, ITcpConnectNority, IDisposable
 {

+ 8 - 0
MinicsConsole/GlobalSuppressions.cs

@@ -0,0 +1,8 @@
+// This file is used by Code Analysis to maintain SuppressMessage
+// attributes that are applied to this project.
+// Project-level suppressions either have no target or are given
+// a specific target and scoped to a namespace, type, member, etc.
+
+using System.Diagnostics.CodeAnalysis;
+
+[assembly: SuppressMessage("Usage", "CA1816:Dispose methods should call SuppressFinalize", Justification = "<Pending>", Scope = "member", Target = "~M:MinicsConsole.Connector.PLCNotifier.Dispose")]

+ 1 - 0
MinicsConsole/MinicsConsole.csproj

@@ -21,6 +21,7 @@
 	</ItemGroup>
 
 	<ItemGroup>
+	  <ProjectReference Include="..\CommunicationProtocols\FinsTcp\FinsTcp.csproj" />
 	  <ProjectReference Include="..\Communicators\Mini8Communicator\IMini8Communicator\Mini8Communicator.csproj" />
 	  <ProjectReference Include="..\Communicators\Mini8Communicator\Mini8CommunicatorModbus\Mini8CommunicatorModbus.csproj" />
 	  <ProjectReference Include="..\Communicators\Mini8Communicator\Mini8CommunicatorSim\Mini8CommunicatorSim.csproj" />

+ 4 - 1
Test/Program.cs

@@ -1,6 +1,9 @@
-using GeneralData;
+using FinsTcp;
+using GeneralData;
 using HardwareData;
+using ModBusTcp;
 using ORM;
+using ProtocalGeneral;
 using RTCommunicatorBase;
 using RTCommunicatorTLV;
 using SqlSugarORM;

+ 11 - 0
Test/Test.csproj

@@ -9,6 +9,14 @@
 		<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
 	</PropertyGroup>
 
+	<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
+	  <WarningLevel>0</WarningLevel>
+	</PropertyGroup>
+
+	<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
+	  <WarningLevel>0</WarningLevel>
+	</PropertyGroup>
+
 	<ItemGroup>
 		<PackageReference Include="FluentModbus" />
 		<PackageReference Include="MiniExcel" />
@@ -16,6 +24,9 @@
 	</ItemGroup>
 
 	<ItemGroup>
+	  <ProjectReference Include="..\CommunicationProtocols\FinsTcp\FinsTcp.csproj" />
+	  <ProjectReference Include="..\CommunicationProtocols\ModBusTcp\ModBusTcp.csproj" />
+	  <ProjectReference Include="..\CommunicationProtocols\ProtocalGeneral\ProtocalGeneral.csproj" />
 	  <ProjectReference Include="..\Communicators\RTCommunicator\RTCommunicatorTLV\RTCommunicatorTLV.csproj" />
 	  <ProjectReference Include="..\DataBase\ORM\ORM.csproj" />
 	  <ProjectReference Include="..\DataBase\SqlSugarORM\SqlSugarORM.csproj" />

+ 5 - 5
Universal/IO/IFilter.cs

@@ -26,11 +26,11 @@ public interface IConnect
     void Disconnected(Connection connection);
 }
 
-public interface ITcpConnectNority
-{
-    void Connect(string ip, int port);
-    void DisConnect(string ip, int port);
-}
+//public interface ITcpConnectNority
+//{
+//    void Connect(string ip, int port);
+//    void DisConnect(string ip, int port);
+//}
 
 
 public interface IFilter : ISender, IReceiver, IConnect

+ 0 - 12
Universal/IO/IIO.cs

@@ -15,16 +15,4 @@ public interface ITcpServer : IFilter, IDisposable
 
     bool Open(string ip, ushort port, bool noDelay = true, int receiveBufferSize = 4096);
     bool Close();
-}
-
-public interface IModBus<T_buffer> 
-{
-    bool Initialize(string name,ITcpConnectNority tcpConnect);
-
-    T_buffer GetBuffer(ushort index, ushort count, byte slaveAddress = 1);
-    bool SetUshort(ushort index, ushort value, byte slaveAddress = 1);
-    bool SetValue<T>(ushort index, T value, byte slaveAddress = 1) where T : struct;
-    bool SetFloat(ushort index, float value, byte slaveAddress = 1);
-    bool Open(string ip, ushort port,bool notify=true);
-    bool Close();
 }