dep_nodyang
nodyang 1 year ago
parent 5c12ca24f1
commit b8fd1abf49

@ -31,7 +31,7 @@ namespace Mesnac.Action.ChemicalWeighing.InterfaceDocking
{ {
HttpItem item = new HttpItem() HttpItem item = new HttpItem()
{ {
Timeout = 5,
URL = url, //URL 必需项 URL = url, //URL 必需项
Method = "post",//URL 可选项 默认为Get Method = "post",//URL 可选项 默认为Get
ContentType = "application/json",//返回类型 可选项有默认值 ContentType = "application/json",//返回类型 可选项有默认值

@ -538,7 +538,6 @@
<Compile Include="MaterialManage\MaterialHelper.cs" /> <Compile Include="MaterialManage\MaterialHelper.cs" />
<Compile Include="MaterialManage\ModifyMaterialAction.cs" /> <Compile Include="MaterialManage\ModifyMaterialAction.cs" />
<Compile Include="OliveEQSetting\InItDbAction.cs" /> <Compile Include="OliveEQSetting\InItDbAction.cs" />
<Compile Include="PlcAddressUtil.cs" />
<Compile Include="Pl\PlcConnect.cs" /> <Compile Include="Pl\PlcConnect.cs" />
<Compile Include="Product\ProductHelper.cs" /> <Compile Include="Product\ProductHelper.cs" />
<Compile Include="ProjectDebug\OpenProjectDebug.cs" /> <Compile Include="ProjectDebug\OpenProjectDebug.cs" />

@ -1,37 +1,37 @@
using HslCommunication.Profinet.Siemens; //using HslCommunication.Profinet.Siemens;
using System; //using System;
using System.Collections.Generic; //using System.Collections.Generic;
using System.Linq; //using System.Linq;
using System.Text; //using System.Text;
using System.Threading.Tasks; //using System.Threading.Tasks;
namespace Mesnac.Action.ChemicalWeighing.Pl //namespace Mesnac.Action.ChemicalWeighing.Pl
{ //{
public class PlcConnect // public class PlcConnect
{ // {
private static readonly Lazy<SiemensS7Net> lazy = new Lazy<SiemensS7Net>(() => new PlcConnect().SiemensS7NetConnection()); // private static readonly Lazy<SiemensS7Net> lazy = new Lazy<SiemensS7Net>(() => new PlcConnect().SiemensS7NetConnection());
public static SiemensS7Net Instance => lazy.Value; // public static SiemensS7Net Instance => lazy.Value;
private PlcConnect() // private PlcConnect()
{ // {
} // }
private SiemensS7Net SiemensS7NetConnection() // private SiemensS7Net SiemensS7NetConnection()
{ // {
SiemensPLCS siemensPLCS = SiemensPLCS.S1500; // SiemensPLCS siemensPLCS = SiemensPLCS.S1500;
SiemensS7Net s7 = new SiemensS7Net(siemensPLCS); // SiemensS7Net s7 = new SiemensS7Net(siemensPLCS);
s7.IpAddress = PlcAddressUtil.IpAddress; // s7.IpAddress = PlcAddressUtil.IpAddress;
s7.Port = PlcAddressUtil.Port; // s7.Port = PlcAddressUtil.Port;
s7.ConnectServer(); // s7.ConnectServer();
return s7; // return s7;
} // }
} // }
} //}

@ -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;
}
}

@ -14,7 +14,7 @@ namespace DataBlockHelper
public class PlcConnect public class PlcConnect
{ {
public static PlcConfig Config;
private static readonly Lazy<SiemensS7Net> lazy = new Lazy<SiemensS7Net>(() => new PlcConnect().SiemensS7NetConnection()); private static readonly Lazy<SiemensS7Net> lazy = new Lazy<SiemensS7Net>(() => new PlcConnect().SiemensS7NetConnection());
public static SiemensS7Net Instance => lazy.Value; public static SiemensS7Net Instance => lazy.Value;
@ -31,24 +31,21 @@ namespace DataBlockHelper
{ {
SiemensPLCS siemensPLCS = SiemensPLCS.S1500; SiemensPLCS siemensPLCS = SiemensPLCS.S1500;
SiemensS7Net s7 = new SiemensS7Net(siemensPLCS); SiemensS7Net s7 = new SiemensS7Net(siemensPLCS);
// s7.SetPersistentConnection();
s7.IpAddress = "172.18.4.100"; s7.IpAddress = "172.18.4.100";
s7.Port = 102; 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; return s7;
} }
} }
public class PlcConfig
{
public PlcConfig()
{
IpAddress = "192.168.1.50";
Port = 102;
}
public string IpAddress { get; set; }
public int Port { get; set; }
}
} }

Loading…
Cancel
Save