From c29239fef07e73a91d6ba449a777e99a2d7fbf7b Mon Sep 17 00:00:00 2001 From: wenjy Date: Tue, 8 Aug 2023 13:30:38 +0800 Subject: [PATCH 1/2] =?UTF-8?q?change=20-=20=E5=88=9D=E5=A7=8B=E5=8C=96?= =?UTF-8?q?=E5=BC=95=E6=93=8E=E6=97=B6=E5=8A=A0=E8=BD=BDHsl=E3=80=81?= =?UTF-8?q?=E6=8A=A5=E8=AD=A6=E7=81=AF=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Main/MCRun/Program.cs | 8 +++++--- Mesnac.DoUtils/DoControl.cs | 11 +++++++++-- Mesnac.DoUtils/Mesnac.DoUtils.csproj | 6 ++++++ Mesnac.PlcUtils/Impl/OmronNJPlc.cs | 2 +- 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/Main/MCRun/Program.cs b/Main/MCRun/Program.cs index 7a9ee0c..b432696 100644 --- a/Main/MCRun/Program.cs +++ b/Main/MCRun/Program.cs @@ -102,6 +102,11 @@ namespace MCRun if (Mesnac.Gui.Common.RunEngine.Instance.Init(projectPath, true, true, true)) //初始化运行引擎 { AppConfigHandler.Instance.InitCustomerMenuAndToolStrip(WorkbenchSingleton.Workbench.TopMenu, WorkbenchSingleton.Workbench.ToolStrip); //初始化自定义系统菜单和工具栏 + + //初始化HslCommunication 11.0.6.0 + PlcBusiness.Instance.InitPlcConnect(PlcType.SiemensPlc, "127.0.0.1", 12); + //初始化连接报警器 + DoControl.Instance.ComOn(); } //if (!Mesnac.Basic.InfluxDbHelper.Instance.IsStartDbServer) @@ -120,9 +125,6 @@ namespace MCRun }; WorkbenchSingleton.InitializeWorkbench(); - PlcBusiness.Instance.InitPlcConnect(PlcType.SiemensPlc, "127.0.0.1", 12); - DoControl.Instance.ComOn(); - ICSharpCode.Core.LoggingService.Debug("starting workbench..."); Form frmMain = WorkbenchSingleton.Workbench as Form; diff --git a/Mesnac.DoUtils/DoControl.cs b/Mesnac.DoUtils/DoControl.cs index fdefe6a..4e90369 100644 --- a/Mesnac.DoUtils/DoControl.cs +++ b/Mesnac.DoUtils/DoControl.cs @@ -38,9 +38,16 @@ namespace Mesnac.DoUtils /// public void ComOn() { - if (!serialPort.IsOpen) + try { - serialPort.Open(); + if (!serialPort.IsOpen) + { + serialPort.Open(); + ICSharpCode.Core.LoggingService.Debug($"打开报警器串口成功,串口:{serialPort.PortName};波特率:{serialPort.BaudRate}"); + } + }catch (Exception ex) + { + ICSharpCode.Core.LoggingService.Error($"报警器串口打开异常,串口:{serialPort.PortName};波特率:{serialPort.BaudRate};异常信息:{ex.Message}"); } } /// diff --git a/Mesnac.DoUtils/Mesnac.DoUtils.csproj b/Mesnac.DoUtils/Mesnac.DoUtils.csproj index d8ad2d4..fae43aa 100644 --- a/Mesnac.DoUtils/Mesnac.DoUtils.csproj +++ b/Mesnac.DoUtils/Mesnac.DoUtils.csproj @@ -34,6 +34,12 @@ false + + Z:\Desktop\日常代码\榄菊项目\程序设计\lj_plc\PlugInPlatform\ICSharpCode.Core.dll + + + Z:\Desktop\日常代码\榄菊项目\程序设计\lj_plc\PlugInPlatform\ICSharpCode.Data.Core.dll + diff --git a/Mesnac.PlcUtils/Impl/OmronNJPlc.cs b/Mesnac.PlcUtils/Impl/OmronNJPlc.cs index de87a40..5ce008a 100644 --- a/Mesnac.PlcUtils/Impl/OmronNJPlc.cs +++ b/Mesnac.PlcUtils/Impl/OmronNJPlc.cs @@ -9,7 +9,7 @@ using System.Threading.Tasks; namespace Mesnac.PlcUtils.Impl { - public class OmronNJPlc + public class OmronNJPlc:IPlc { private StringChange stringChange = StringChange.Instance; From 00ebb2f69d673628aa58748b978dd1663d56fed0 Mon Sep 17 00:00:00 2001 From: wangsr Date: Tue, 8 Aug 2023 13:49:46 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=8A=A5=E8=AD=A6=E7=81=AF=E5=AE=8C?= =?UTF-8?q?=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Mesnac.DoUtils/DoControl.cs | 12 +++++++----- Mesnac.DoUtils/Mesnac.DoUtils.csproj | 4 ++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Mesnac.DoUtils/DoControl.cs b/Mesnac.DoUtils/DoControl.cs index 4e90369..e5b8f6c 100644 --- a/Mesnac.DoUtils/DoControl.cs +++ b/Mesnac.DoUtils/DoControl.cs @@ -13,7 +13,7 @@ namespace Mesnac.DoUtils /// /// 报警灯控制类 /// - public class DoControl + public sealed class DoControl { public SerialPort serialPort = new SerialPort("COM5"); private static readonly Lazy lazy = new Lazy(() => new DoControl()); @@ -136,12 +136,14 @@ namespace Mesnac.DoUtils /// 启停状态 public void DOControl(DOName dOName, DOOnOff dOOnOff) { - //ComOn(); - if (!serialPort.IsOpen) + if (serialPort.IsOpen) + { + serialPort.Write(new byte[] { 0xE3, 0x01, 0x09, (byte)dOName, (byte)dOOnOff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0, 12); + } + else { - serialPort.Open(); + ComOn(); } - serialPort.Write(new byte[] { 0xE3, 0x01, 0x09, (byte)dOName, (byte)dOOnOff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0, 12); } /// diff --git a/Mesnac.DoUtils/Mesnac.DoUtils.csproj b/Mesnac.DoUtils/Mesnac.DoUtils.csproj index fae43aa..4806769 100644 --- a/Mesnac.DoUtils/Mesnac.DoUtils.csproj +++ b/Mesnac.DoUtils/Mesnac.DoUtils.csproj @@ -35,10 +35,10 @@ - Z:\Desktop\日常代码\榄菊项目\程序设计\lj_plc\PlugInPlatform\ICSharpCode.Core.dll + ..\PlugInPlatform\ICSharpCode.Core.dll - Z:\Desktop\日常代码\榄菊项目\程序设计\lj_plc\PlugInPlatform\ICSharpCode.Data.Core.dll + ..\PlugInPlatform\ICSharpCode.Data.Core.dll