From 57cc190a41d94986fbdcf859c395f05daf1f3d0c Mon Sep 17 00:00:00 2001 From: "nodyang@aliyun.com" Date: Wed, 25 Dec 2024 15:05:26 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0dll?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HighWayIot.Plc/HighWayIot.Plc.csproj | 8 +++++--- HighWayIot.Plc/PlcConnect.cs | 6 ++++-- HighWayIot.Winform/HighWayIot.Winform.csproj | 7 +++++-- HighWayIot.Winform/Program.cs | 3 +++ 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/HighWayIot.Plc/HighWayIot.Plc.csproj b/HighWayIot.Plc/HighWayIot.Plc.csproj index fd0970d..b6e2b18 100644 --- a/HighWayIot.Plc/HighWayIot.Plc.csproj +++ b/HighWayIot.Plc/HighWayIot.Plc.csproj @@ -32,9 +32,6 @@ 4 - - ..\HighWayIot.Library\HslCommunication.dll - @@ -62,5 +59,10 @@ + + + 12.1.3 + + \ No newline at end of file diff --git a/HighWayIot.Plc/PlcConnect.cs b/HighWayIot.Plc/PlcConnect.cs index 551442c..72a95b1 100644 --- a/HighWayIot.Plc/PlcConnect.cs +++ b/HighWayIot.Plc/PlcConnect.cs @@ -36,14 +36,15 @@ namespace HighWayIot.Plc SocketKeepAliveTime = -1, IsPersistentConnection = true, }; + plc.ConnectServer(); } catch (Exception ex) { logHelper.Error("初始化PLC服务器发生错误!", ex); } - string s = IsConnect ? "正常" : "异常"; - logHelper.Info($"PLC连接:{s}"); + + return plc; } @@ -55,6 +56,7 @@ namespace HighWayIot.Plc { get { + if (MelsecInstance == null) return false; var result = MelsecInstance.ReadPlcType(); logHelper.Info($"PLC型号:{result.Content}"); return result.IsSuccess; diff --git a/HighWayIot.Winform/HighWayIot.Winform.csproj b/HighWayIot.Winform/HighWayIot.Winform.csproj index c1fb5dc..f042a9b 100644 --- a/HighWayIot.Winform/HighWayIot.Winform.csproj +++ b/HighWayIot.Winform/HighWayIot.Winform.csproj @@ -36,7 +36,6 @@ - @@ -313,6 +312,10 @@ Always - + + + 12.1.3 + + \ No newline at end of file diff --git a/HighWayIot.Winform/Program.cs b/HighWayIot.Winform/Program.cs index adc471e..30a819c 100644 --- a/HighWayIot.Winform/Program.cs +++ b/HighWayIot.Winform/Program.cs @@ -6,6 +6,7 @@ using System.Linq; using System.Runtime.InteropServices; using System.Threading.Tasks; using System.Windows.Forms; +using HighWayIot.Plc; namespace HighWayIot.Winform { @@ -30,6 +31,8 @@ namespace HighWayIot.Winform //Console.OutputEncoding = System.Text.Encoding.UTF8; //Console.InputEncoding = System.Text.Encoding.UTF8; + + AllocConsole();//调用系统API,调用控制台窗口 // 设置控制台编码为系统默认编码(解决乱码问题) Application.EnableVisualStyles();