From d97b3ee3dafc404f3b1f0209ce93a081454bb8b2 Mon Sep 17 00:00:00 2001 From: SoulStar Date: Wed, 25 Dec 2024 15:40:37 +0800 Subject: [PATCH] =?UTF-8?q?test=20-=20=E6=B7=BB=E5=8A=A0=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=20=E5=87=86=E5=A4=87=E5=90=88=E5=B9=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HighWayIot.Plc/PlcConnect.cs | 34 +++++++++++-------- .../UserControlPages/TestPage.cs | 4 +-- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/HighWayIot.Plc/PlcConnect.cs b/HighWayIot.Plc/PlcConnect.cs index 72a95b1..d24140b 100644 --- a/HighWayIot.Plc/PlcConnect.cs +++ b/HighWayIot.Plc/PlcConnect.cs @@ -36,31 +36,37 @@ namespace HighWayIot.Plc SocketKeepAliveTime = -1, IsPersistentConnection = true, }; - plc.ConnectServer(); + var a = plc.ConnectServer(); + logHelper.Info($"Plc连接 信息:[{a.Message}] 是否成功:[{a.IsSuccess.ToString()}] 错误代码:[{a.ErrorCode}]"); } catch (Exception ex) { 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(); } ///