From a6ec5f0bd1899bb8fe9e6e2e7a695f448111ec7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=94=84=E5=A4=B4?= Date: Mon, 9 Sep 2024 10:17:11 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Tool/PlcConnect.cs | 33 ++++++++++++++++++++++++++++++ Tool/{Class1.cs => RfidSetting.cs} | 6 ++++++ Tool/Tool.csproj | 3 ++- 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 Tool/PlcConnect.cs rename Tool/{Class1.cs => RfidSetting.cs} (79%) diff --git a/Tool/PlcConnect.cs b/Tool/PlcConnect.cs new file mode 100644 index 0000000..1da5904 --- /dev/null +++ b/Tool/PlcConnect.cs @@ -0,0 +1,33 @@ +using System; +using HslCommunication.Profinet.AllenBradley; +using HslCommunication.Profinet.Siemens; + +namespace Tool +{ + public class PlcConnect + { + + + private static readonly Lazy lazy = new Lazy(() => new PlcConnect().CreateAb()); + public static AllenBradleyNet Instance => lazy.Value; + + private PlcConnect() + { + + } + + private AllenBradleyNet CreateAb() + { + var rfidSetting = RfidSetting.Current; + + AllenBradleyNet ab = new AllenBradleyNet(); + ab.IpAddress = rfidSetting.PlcIp; + ab.Port = rfidSetting.Port; + ab.ConnectServer(); + return ab; + } + } +} + + + diff --git a/Tool/Class1.cs b/Tool/RfidSetting.cs similarity index 79% rename from Tool/Class1.cs rename to Tool/RfidSetting.cs index d342656..145ae3e 100644 --- a/Tool/Class1.cs +++ b/Tool/RfidSetting.cs @@ -14,5 +14,11 @@ namespace Tool public class RfidSetting : Config { public string Db { get; set; } = "server=127.0.0.1;database=postgres;uid=postgres;pwd=yangwei"; + + + public string PlcIp { get; set; } = "127.0.0.1"; + + public int Port { get; set; }=44818; + } } diff --git a/Tool/Tool.csproj b/Tool/Tool.csproj index 4ca5971..68b7f66 100644 --- a/Tool/Tool.csproj +++ b/Tool/Tool.csproj @@ -58,7 +58,8 @@ - + +