From 3b09876d7797ca4f0d35129b83c72bec5d7ff82a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=A6=82=E6=84=8F=20=E5=BD=AD?= <2417589739@qq.com>
Date: Thu, 11 Aug 2022 14:15:00 +0800
Subject: [PATCH 1/2] =?UTF-8?q?=E5=90=88=E5=B9=B6=E4=BF=AE=E6=94=B9?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
SmartClient.sln | 2 --
1 file changed, 2 deletions(-)
diff --git a/SmartClient.sln b/SmartClient.sln
index d4c6d340..740fe85b 100644
--- a/SmartClient.sln
+++ b/SmartClient.sln
@@ -120,8 +120,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BPASmartClient.MilkWithTea"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BPASmartClient.KHKJ", "BPASmartClient.KHKJ\BPASmartClient.KHKJ.csproj", "{C0060FB3-7AEA-4D14-ADCE-DB78D3665D5B}"
EndProject
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BPASmartClient.KHKJ", "BPASmartClient.KHKJ\BPASmartClient.KHKJ.csproj", "{C0060FB3-7AEA-4D14-ADCE-DB78D3665D5B}"
-EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BPASmartClient.MorkTM", "BPASmartClient.MorkTM\BPASmartClient.MorkTM.csproj", "{1612F583-D328-45C6-8BB1-5D41B8F1D216}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BPASmartClient.Nfc", "BPASmartClient.Nfc\BPASmartClient.Nfc.csproj", "{42D35B7C-764C-4692-AA85-9B343A0F5B7F}"
From e1e0af0d72e4e11e015dc45775d23dea2dfb37ce Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=A6=82=E6=84=8F=20=E5=BD=AD?= <2417589739@qq.com>
Date: Thu, 11 Aug 2022 15:12:17 +0800
Subject: [PATCH 2/2] =?UTF-8?q?s7=20=E5=8D=8F=E8=AE=AE=E5=BC=80=E5=8F=91?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../BPASmartClient.S7Net.csproj | 13 ++++
BPASmartClient.S7Net/SiemensHelper.cs | 69 +++++++++++++++++++
SmartClient.sln | 24 +++++++
3 files changed, 106 insertions(+)
create mode 100644 BPASmartClient.S7Net/BPASmartClient.S7Net.csproj
create mode 100644 BPASmartClient.S7Net/SiemensHelper.cs
diff --git a/BPASmartClient.S7Net/BPASmartClient.S7Net.csproj b/BPASmartClient.S7Net/BPASmartClient.S7Net.csproj
new file mode 100644
index 00000000..ce772d6a
--- /dev/null
+++ b/BPASmartClient.S7Net/BPASmartClient.S7Net.csproj
@@ -0,0 +1,13 @@
+
+
+
+ net6.0
+ enable
+ enable
+
+
+
+
+
+
+
diff --git a/BPASmartClient.S7Net/SiemensHelper.cs b/BPASmartClient.S7Net/SiemensHelper.cs
new file mode 100644
index 00000000..482eae2b
--- /dev/null
+++ b/BPASmartClient.S7Net/SiemensHelper.cs
@@ -0,0 +1,69 @@
+using S7.Net;
+
+namespace BPASmartClient.S7Net
+{
+ public class SiemensHelper
+ {
+
+ Plc myPlc;
+
+ public bool IsConnected => myPlc is null ? false : myPlc.IsConnected;
+
+ ///
+ /// 打开连接
+ ///
+ /// PLC CPU 类型
+ /// plc ip 地址
+ /// plc 端口号
+ /// PLC 机架号
+ /// PLC 插槽号
+ public void Connect(CpuType cpuType, string ip, int port = 102, short rack = 0, short solt = 0)
+ {
+ myPlc = new Plc(cpuType, ip, port, rack, solt);
+ myPlc.Open();
+ }
+
+ ///
+ /// 断开和PLC的连接
+ ///
+ public void Disconnect()
+ {
+ myPlc?.Close();
+ }
+
+ public object Read(string address)
+ {
+ if (!IsConnected) return default;
+ return myPlc?.Read(address);
+ }
+
+ public void Write(string address, object value)
+ {
+ myPlc?.Write(address, value);
+ }
+
+ public ReadT ReadStruct(int db, int startAddress = 0)
+ {
+ if (!IsConnected) return default;
+ return (ReadT)myPlc.ReadStruct(typeof(ReadT), db, startAddress);
+ }
+
+ public void WriteStruct(object structValue, int db, int startAddress = 0)
+ {
+ myPlc?.WriteStruct(structValue, db, startAddress);
+ }
+
+
+ public int ReadClass(object sourceClass, int db, int startAddress = 0)
+ {
+ if (!IsConnected) return -1;
+ return myPlc.ReadClass(sourceClass, db, startAddress);
+ }
+
+ public void WriteClass(object sourceClass, int db, int startAddress = 0)
+ {
+ myPlc?.WriteClass(sourceClass, db, startAddress);
+ }
+
+ }
+}
\ No newline at end of file
diff --git a/SmartClient.sln b/SmartClient.sln
index 740fe85b..1fc6e8bd 100644
--- a/SmartClient.sln
+++ b/SmartClient.sln
@@ -126,6 +126,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BPASmartClient.Nfc", "BPASm
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BPASmartClient.Argox", "BPASmartClient.Argox\BPASmartClient.Argox.csproj", "{B8D499BA-A18A-4FD6-B036-44F02B4D164B}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BPASmartClient.S7Net", "BPASmartClient.S7Net\BPASmartClient.S7Net.csproj", "{D1F2379E-1755-4B50-9D67-15C960C33FFA}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -1200,6 +1202,26 @@ Global
{B8D499BA-A18A-4FD6-B036-44F02B4D164B}.Release|x64.Build.0 = Release|Any CPU
{B8D499BA-A18A-4FD6-B036-44F02B4D164B}.Release|x86.ActiveCfg = Release|Any CPU
{B8D499BA-A18A-4FD6-B036-44F02B4D164B}.Release|x86.Build.0 = Release|Any CPU
+ {D1F2379E-1755-4B50-9D67-15C960C33FFA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {D1F2379E-1755-4B50-9D67-15C960C33FFA}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {D1F2379E-1755-4B50-9D67-15C960C33FFA}.Debug|ARM.ActiveCfg = Debug|Any CPU
+ {D1F2379E-1755-4B50-9D67-15C960C33FFA}.Debug|ARM.Build.0 = Debug|Any CPU
+ {D1F2379E-1755-4B50-9D67-15C960C33FFA}.Debug|ARM64.ActiveCfg = Debug|Any CPU
+ {D1F2379E-1755-4B50-9D67-15C960C33FFA}.Debug|ARM64.Build.0 = Debug|Any CPU
+ {D1F2379E-1755-4B50-9D67-15C960C33FFA}.Debug|x64.ActiveCfg = Debug|Any CPU
+ {D1F2379E-1755-4B50-9D67-15C960C33FFA}.Debug|x64.Build.0 = Debug|Any CPU
+ {D1F2379E-1755-4B50-9D67-15C960C33FFA}.Debug|x86.ActiveCfg = Debug|Any CPU
+ {D1F2379E-1755-4B50-9D67-15C960C33FFA}.Debug|x86.Build.0 = Debug|Any CPU
+ {D1F2379E-1755-4B50-9D67-15C960C33FFA}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {D1F2379E-1755-4B50-9D67-15C960C33FFA}.Release|Any CPU.Build.0 = Release|Any CPU
+ {D1F2379E-1755-4B50-9D67-15C960C33FFA}.Release|ARM.ActiveCfg = Release|Any CPU
+ {D1F2379E-1755-4B50-9D67-15C960C33FFA}.Release|ARM.Build.0 = Release|Any CPU
+ {D1F2379E-1755-4B50-9D67-15C960C33FFA}.Release|ARM64.ActiveCfg = Release|Any CPU
+ {D1F2379E-1755-4B50-9D67-15C960C33FFA}.Release|ARM64.Build.0 = Release|Any CPU
+ {D1F2379E-1755-4B50-9D67-15C960C33FFA}.Release|x64.ActiveCfg = Release|Any CPU
+ {D1F2379E-1755-4B50-9D67-15C960C33FFA}.Release|x64.Build.0 = Release|Any CPU
+ {D1F2379E-1755-4B50-9D67-15C960C33FFA}.Release|x86.ActiveCfg = Release|Any CPU
+ {D1F2379E-1755-4B50-9D67-15C960C33FFA}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -1255,8 +1277,10 @@ Global
{2366AC9B-B662-4550-9486-AF848B4D2961} = {9FB27073-61A0-4FE3-94DB-5FDDE062332F}
{BFA4E222-BBCC-4AC7-9EA4-4549AEF3174B} = {8712125E-14CD-4E1B-A1CE-4BDE03805942}
{C0060FB3-7AEA-4D14-ADCE-DB78D3665D5B} = {666CB1A9-562E-453A-A2C7-FD9D77CFDFDD}
+ {1612F583-D328-45C6-8BB1-5D41B8F1D216} = {9FB27073-61A0-4FE3-94DB-5FDDE062332F}
{42D35B7C-764C-4692-AA85-9B343A0F5B7F} = {3D1D0E04-03FD-480A-8CF8-6E01A2E28625}
{B8D499BA-A18A-4FD6-B036-44F02B4D164B} = {3D1D0E04-03FD-480A-8CF8-6E01A2E28625}
+ {D1F2379E-1755-4B50-9D67-15C960C33FFA} = {3D1D0E04-03FD-480A-8CF8-6E01A2E28625}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {9AEC9B81-0222-4DE9-B642-D915C29222AC}