wangxinhui
2024-11-06 8f392cc88b0768b74efca3b68785cf5aa1c38e70
wcs-server-hbf/WIDESEA_WCS/WCSClient/Siemens/SiemensPLCClient.cs
@@ -128,31 +128,12 @@
        /// </summary>
        public string Connect()
        {
            if (PLCIPAddress == "127.0.0.3")
            {
                Port = 103;
            }
            if (PLCIPAddress == "127.0.0.4")
            {
                Port = 104;
            }
            List<string> specialSlotIp = new List<string>()
            {
                "192.168.12.166",
                "192.168.12.160",
                "192.168.12.161",
                "192.168.12.163",
                "192.168.12.164",
            };
            if (specialSlotIp.Contains(PLCIPAddress))
            {
                Slot = 1;
            }
            this.SiemensS7NetClient.IpAddress = PLCIPAddress;
            this.SiemensS7NetClient.Port = Port;
            this.SiemensS7NetClient.Rack = Rack;
            this.SiemensS7NetClient.Slot = Slot;
            this.SiemensS7NetClient.ConnectTimeOut = 5;
            this.SiemensS7NetClient.ConnectTimeOut = 2000;
            this.SiemensS7NetClient.ReceiveTimeOut = 2000;
            this.SiemensS7NetClient?.ConnectClose();
            logNet = new LogNetFileSize(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Log2"), 2 * 1024 * 1024);
@@ -162,7 +143,7 @@
            if (!result.IsSuccess)
            {
                WIDESEA_Common.Tools.WriteLog.GetLog().Write($"Error:{PLCName}连接失败{Environment.NewLine}错误信息:{result.Message}", PLCName);
                WIDESEA_Common.Tools.WriteLog.GetLog().Write($"Error:{PLCName}连接失败---{DateTime.Now}{Environment.NewLine}错误信息:{result.Message}", PLCName);
                IsConnected = false;
                logNet.WriteInfo($"{PLCIPAddress}连接失败,错误信息:{result.Message}");
                return $"连接失败,错误信息:{result.Message}";
@@ -170,7 +151,7 @@
            else
            {
                IsConnected = true;
                WIDESEA_Common.Tools.WriteLog.GetLog().Write($"Info:{PLCName}连接成功!", PLCName);
                WIDESEA_Common.Tools.WriteLog.GetLog().Write($"Info:{PLCName}连接成功!---{DateTime.Now}", PLCName);
                logNet.WriteInfo($"{PLCIPAddress}连接成功");
                return $"连接成功";
            }