From b8fd1abf49ef63ce232db8be6ce03dfc87e21b32 Mon Sep 17 00:00:00 2001 From: nodyang Date: Sun, 15 Oct 2023 15:46:06 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B4=E6=94=B9Ip?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../InterfaceDocking/HttpResponse.cs | 2 +- .../Mesnac.Action.ChemicalWeighing.csproj | 1 - .../Pl/PlcConnect.cs | 52 +++++++++---------- .../PlcAddressUtil.cs | 13 ----- DataBlockHelper/PlcConnect.cs | 25 ++++----- 5 files changed, 38 insertions(+), 55 deletions(-) delete mode 100644 Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/PlcAddressUtil.cs diff --git a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/InterfaceDocking/HttpResponse.cs b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/InterfaceDocking/HttpResponse.cs index ed342bd..033622b 100644 --- a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/InterfaceDocking/HttpResponse.cs +++ b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/InterfaceDocking/HttpResponse.cs @@ -31,7 +31,7 @@ namespace Mesnac.Action.ChemicalWeighing.InterfaceDocking { HttpItem item = new HttpItem() { - Timeout = 5, + URL = url, //URL 必需项 Method = "post",//URL 可选项 默认为Get ContentType = "application/json",//返回类型 可选项有默认值 diff --git a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/Mesnac.Action.ChemicalWeighing.csproj b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/Mesnac.Action.ChemicalWeighing.csproj index 538cc63..95b5a4d 100644 --- a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/Mesnac.Action.ChemicalWeighing.csproj +++ b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/Mesnac.Action.ChemicalWeighing.csproj @@ -538,7 +538,6 @@ - diff --git a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/Pl/PlcConnect.cs b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/Pl/PlcConnect.cs index c500028..ba076a2 100644 --- a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/Pl/PlcConnect.cs +++ b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/Pl/PlcConnect.cs @@ -1,37 +1,37 @@ -using HslCommunication.Profinet.Siemens; +//using HslCommunication.Profinet.Siemens; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +//using System; +//using System.Collections.Generic; +//using System.Linq; +//using System.Text; +//using System.Threading.Tasks; -namespace Mesnac.Action.ChemicalWeighing.Pl -{ - public class PlcConnect - { +//namespace Mesnac.Action.ChemicalWeighing.Pl +//{ +// public class PlcConnect +// { - private static readonly Lazy lazy = new Lazy(() => new PlcConnect().SiemensS7NetConnection()); - public static SiemensS7Net Instance => lazy.Value; +// private static readonly Lazy lazy = new Lazy(() => new PlcConnect().SiemensS7NetConnection()); +// public static SiemensS7Net Instance => lazy.Value; - private PlcConnect() - { +// private PlcConnect() +// { - } +// } - private SiemensS7Net SiemensS7NetConnection() - { - SiemensPLCS siemensPLCS = SiemensPLCS.S1500; - SiemensS7Net s7 = new SiemensS7Net(siemensPLCS); - s7.IpAddress = PlcAddressUtil.IpAddress; - s7.Port = PlcAddressUtil.Port; - s7.ConnectServer(); - return s7; - } - } -} +// private SiemensS7Net SiemensS7NetConnection() +// { +// SiemensPLCS siemensPLCS = SiemensPLCS.S1500; +// SiemensS7Net s7 = new SiemensS7Net(siemensPLCS); +// s7.IpAddress = PlcAddressUtil.IpAddress; +// s7.Port = PlcAddressUtil.Port; +// s7.ConnectServer(); +// return s7; +// } +// } +//} diff --git a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/PlcAddressUtil.cs b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/PlcAddressUtil.cs deleted file mode 100644 index 6aefdc6..0000000 --- a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/PlcAddressUtil.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace Mesnac.Action.ChemicalWeighing -{ - public class PlcAddressUtil - { - public static string IpAddress = "172.18.4.100"; - public static int Port = 102; - - //测试的Plc - //public static string IpAddress = "192.168.0.100"; - //public static int Port = 7788; - - } -} \ No newline at end of file diff --git a/DataBlockHelper/PlcConnect.cs b/DataBlockHelper/PlcConnect.cs index fefb566..b199ce4 100644 --- a/DataBlockHelper/PlcConnect.cs +++ b/DataBlockHelper/PlcConnect.cs @@ -14,7 +14,7 @@ namespace DataBlockHelper public class PlcConnect { - public static PlcConfig Config; + private static readonly Lazy lazy = new Lazy(() => new PlcConnect().SiemensS7NetConnection()); public static SiemensS7Net Instance => lazy.Value; @@ -31,24 +31,21 @@ namespace DataBlockHelper { SiemensPLCS siemensPLCS = SiemensPLCS.S1500; SiemensS7Net s7 = new SiemensS7Net(siemensPLCS); + // s7.SetPersistentConnection(); s7.IpAddress = "172.18.4.100"; s7.Port = 102; - s7.ConnectServer(); + var su = s7.ConnectServer(); + + if (!su.IsSuccess) + { + s7.IpAddress = "192.168.0.100"; + s7.Port = 7788; + s7.ConnectServer(); + } return s7; } } - public class PlcConfig - { - public PlcConfig() - { - IpAddress = "192.168.1.50"; - Port = 102; - - } - - public string IpAddress { get; set; } - public int Port { get; set; } - } + }