using HslCommunication; using HslCommunication.Profinet.Omron; using HslCommunication.Profinet.Siemens; namespace ZJ_BYD.Untils { public class ConnectPLC { private OmronCipNet omronCipNet = null; private SiemensS7Net siemensS7Net = null; public ConnectPLC(string plcIp = "", int plcPort = 0) { if (string.IsNullOrWhiteSpace(plcIp)) { plcIp = Program.PlcIpAddress; } if (plcPort == 0) { plcPort = Program.PlcPort; } /*omronCipNet = new OmronCipNet(plcIp, plcPort) { ConnectTimeOut = 3000 };*/ siemensS7Net = new SiemensS7Net(SiemensPLCS.S1500); siemensS7Net.IpAddress = plcIp; siemensS7Net.Port = plcPort; } public OmronCipNet GetOmronCipNet() { var connect = omronCipNet.ConnectServer(); if (connect.IsSuccess) { return omronCipNet; } else { LogHelper.WriteLog("PLC连接失败!"); return null; } } public SiemensS7Net GetSiemensS7Net() { OperateResult connect = siemensS7Net.ConnectServer(); if (connect.IsSuccess) { return siemensS7Net; } else { LogHelper.WriteLog("西门子PLC连接失败!"); return null; } } } }