diff --git a/HighWayIot.Plc/PlcConnect.cs b/HighWayIot.Plc/PlcConnect.cs index c39a916..7c71b05 100644 --- a/HighWayIot.Plc/PlcConnect.cs +++ b/HighWayIot.Plc/PlcConnect.cs @@ -36,10 +36,11 @@ namespace HighWayIot.Plc SocketKeepAliveTime = -1, IsPersistentConnection = true, }; - var reslt= plc.ConnectServer(); - if (!reslt.IsSuccess) - { - logHelper.Info("链接失败:"+reslt.Message); + var a = plc.ConnectServer(); + logHelper.Info($"Plc连接 信息:[{a.Message}] 是否成功:[{a.IsSuccess.ToString()}] 错误代码:[{a.ErrorCode}]"); + if (!reslt.IsSuccess) + { + logHelper.Info("链接失败:"+reslt.Message); } } catch (Exception ex) @@ -47,24 +48,29 @@ namespace HighWayIot.Plc logHelper.Error("初始化PLC服务器发生错误!", ex); } - - + //string s = IsConnect ? "成功" : "失败"; + //logHelper.Info($"PLC连接:{s}"); return plc; } - /// - /// plc 是不是保持链接 - /// - public static bool IsConnect + ///// + ///// plc 是不是保持链接 + ///// + //public static bool IsConnect + //{ + // get + // { + // if (MelsecInstance == null) return false; + // var result = MelsecInstance.ReadPlcType(); + // logHelper.Info($"PLC型号:{result.Content}"); + // return result.IsSuccess; + // } + //} + + public static int Test() { - get - { - if (MelsecInstance == null) return false; - var result = MelsecInstance.ReadPlcType(); - logHelper.Info($"PLC型号:{result.Content}"); - return result.IsSuccess; - } + return MelsecInstance.ReadInt16("D1").Content; } /// diff --git a/HighWayIot.Winform/UserControlPages/TestPage.cs b/HighWayIot.Winform/UserControlPages/TestPage.cs index 944197c..b6852ce 100644 --- a/HighWayIot.Winform/UserControlPages/TestPage.cs +++ b/HighWayIot.Winform/UserControlPages/TestPage.cs @@ -48,8 +48,8 @@ namespace HighWayIot.Winform.UserControlPages private void button2_Click(object sender, EventArgs e) { - SqlLogHelper.AddLog("wdas", 7, 1231535246, 9); - SqlLogHelper.AddErrorLog("wocasda", 4, 5, 6); + var res = PlcConnect.Test(); + PlcShowValue.Text = res.ToString(); } ///