using System; using HslCommunication; using HslCommunication.LogNet; using HslCommunication.Profinet.AllenBradley; using HslCommunication.Profinet.Siemens; using Newtonsoft.Json; 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 plc = new AllenBradleyNet(); plc.Slot = 0; plc.CommunicationPipe = new HslCommunication.Core.Pipe.PipeTcpNet(rfidSetting.PlcIp, 44818) { ConnectTimeOut = 5000, // 连接超时时间,单位毫秒 ReceiveTimeOut = 10000, // 接收设备数据反馈的超时时间 SleepTime = 0, SocketKeepAliveTime = -1, IsPersistentConnection = true, }; return plc; } public OperateResult Write(string db, string value) { return Instance.Write(db, value); } } }