| | |
| | | /// </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); |
| | |
| | | |
| | | 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}"; |
| | |
| | | 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 $"连接成功"; |
| | | } |