using HslCommunication.Profinet.Siemens; using System; namespace Admin.Core.PlcServer { public class XlPlcConnect { private static readonly Lazy lazy = new Lazy(() => new XlPlcConnect().SiemensS7NetConnection()); public static SiemensS7Net Instance => lazy.Value; private XlPlcConnect() { } public SiemensS7Net SiemensS7NetConnection() { SiemensPLCS siemensPLCS = SiemensPLCS.S1500; SiemensS7Net s7 = new SiemensS7Net(siemensPLCS); //配料IP s7.IpAddress = "127.0.0.1"; // "192.168.10.100"; s7.Port = 102; var su = s7.ConnectServer(); if (!su.IsSuccess) { s7.IpAddress = "127.0.0.1"; // "192.168.10.100"; s7.Port = 102; var su1 = s7.ConnectServer(); if (!su1.IsSuccess) { return new SiemensS7Net(siemensPLCS); } } return s7; } } }