From 969946be459ec79b812f87153c534b13c436876f Mon Sep 17 00:00:00 2001 From: wenjy Date: Tue, 8 Aug 2023 11:24:03 +0800 Subject: [PATCH] =?UTF-8?q?add=20-=20=E5=A2=9E=E5=8A=A0=E6=8A=A5=E8=AD=A6?= =?UTF-8?q?=E7=81=AF=E6=8E=A7=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FinishBatch/SaveHelper/AlarmSaveHelper.cs | 6 + .../Mesnac.Action.ChemicalWeighing.csproj | 4 + Mesnac.DoUtils/DoControl.cs | 152 ++++++++++++++++++ Mesnac.DoUtils/Mesnac.DoUtils.csproj | 50 ++++++ Mesnac.DoUtils/Properties/AssemblyInfo.cs | 36 +++++ Mesnac.DoUtils/enumInfo/DOName.cs | 20 +++ Mesnac.DoUtils/enumInfo/DOOnOff.cs | 14 ++ SlnMix.VS2013.sln | 17 ++ 8 files changed, 299 insertions(+) create mode 100644 Mesnac.DoUtils/DoControl.cs create mode 100644 Mesnac.DoUtils/Mesnac.DoUtils.csproj create mode 100644 Mesnac.DoUtils/Properties/AssemblyInfo.cs create mode 100644 Mesnac.DoUtils/enumInfo/DOName.cs create mode 100644 Mesnac.DoUtils/enumInfo/DOOnOff.cs diff --git a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/FinishBatch/SaveHelper/AlarmSaveHelper.cs b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/FinishBatch/SaveHelper/AlarmSaveHelper.cs index 81d7503..e4b2696 100644 --- a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/FinishBatch/SaveHelper/AlarmSaveHelper.cs +++ b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/FinishBatch/SaveHelper/AlarmSaveHelper.cs @@ -1,6 +1,7 @@ using DevExpress.Xpo.DB; using HslCommunication; using Mesnac.Codd.Session; +using Mesnac.DoUtils; using Mesnac.PlcUtils; using System; using System.Collections.Generic; @@ -23,6 +24,8 @@ namespace Mesnac.Action.ChemicalWeighing.FinishBatch.SaveHelper private static PlcBusiness plcBusiness = PlcBusiness.Instance; + private static DoControl doControl = DoControl.Instance; + /// /// 保存报警信息 /// @@ -123,6 +126,9 @@ namespace Mesnac.Action.ChemicalWeighing.FinishBatch.SaveHelper { sai.AlarmData = Convert.ToInt16(result.Content); //对起始字偏移,为当前字的报警值 + //打开报警灯 + doControl.DOControl(DoUtils.enumInfo.DOName.Red, DoUtils.enumInfo.DOOnOff.On); + //更新报警状态 Entity.PmtAlarmInfo alarmInfo = Cache.CacheHelper.GetPmtAlarmInfoFromCache(sai.AlramPLC, sai.AlarmBlock, sai.AlarmAddress, Convert.ToInt32(sai.AlarmBit)); if (alarmInfo != null) diff --git a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/Mesnac.Action.ChemicalWeighing.csproj b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/Mesnac.Action.ChemicalWeighing.csproj index 40e356d..bc6905a 100644 --- a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/Mesnac.Action.ChemicalWeighing.csproj +++ b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/Mesnac.Action.ChemicalWeighing.csproj @@ -733,6 +733,10 @@ {28acacf1-9936-4e97-a866-f84366ec5286} Mesnac.Basic + + {ad132cad-5288-44dc-a38f-4b0658fc228c} + Mesnac.DoUtils + {88eac8d1-8783-478c-ad9d-f916673b7004} Mesnac.PlcUtils diff --git a/Mesnac.DoUtils/DoControl.cs b/Mesnac.DoUtils/DoControl.cs new file mode 100644 index 0000000..b58862c --- /dev/null +++ b/Mesnac.DoUtils/DoControl.cs @@ -0,0 +1,152 @@ +using Mesnac.DoUtils.enumInfo; +using System; +using System.Collections.Generic; +using System.IO.Ports; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace Mesnac.DoUtils +{ + /// + /// 报警灯控制类 + /// + public sealed class DoControl + { + public SerialPort serialPort; + + private static readonly Lazy lazy = new Lazy(() => new DoControl()); + public static DoControl Instance + { + get + { + return lazy.Value; + } + } + + private DoControl() + { + serialPort.BaudRate = 115200; + serialPort.DataBits = 8; + serialPort.StopBits = StopBits.One; + serialPort.Parity = Parity.None; + serialPort = new SerialPort("COM5"); + } + + /// + /// 串口启动 + /// + public void ComOn() + { + if (!serialPort.IsOpen) + { + serialPort.Open(); + } + } + /// + /// 串口关闭 + /// + public void ComOff() + { + if (serialPort.IsOpen) + { + serialPort.Close(); + } + } + + /// + /// DO1设备启动(红灯) + /// + public void redLightOn() + { + DOControl(DOName.Red, DOOnOff.On); + } + + /// + /// DO2设备启动(绿灯) + /// + public void greenLightOn() + { + DOControl(DOName.Green, DOOnOff.On); + } + + /// + /// DO3设备启动(蜂鸣器) + /// + public void buzzerOn() + { + DOControl(DOName.Buzzer, DOOnOff.On); + } + + /// + /// DO1设备关闭(红灯) + /// + public void redLightOff() + { + DOControl(DOName.Red, DOOnOff.Off); + } + + /// + /// DO2设备关闭(绿灯) + /// + public void greenLightOff() + { + DOControl(DOName.Green, DOOnOff.Off); + } + + /// + /// DO3设备关闭(蜂鸣器) + /// + public void buzzerOff() + { + DOControl(DOName.Buzzer, DOOnOff.On); + } + + /// + /// 重置串口和DO状态 + /// + public void Reset() + { + SetOff(); + ComOff(); + } + + /// + /// 重置DO状态 + /// + public void SetOff() + { + foreach (DOName dOName in Enum.GetValues(typeof(DOName))) + { + DOControl(dOName, DOOnOff.Off); + } + } + + /// + /// DO启停控制 + /// + /// DegitalOut接口名称 + /// 启停状态 + public void DOControl(DOName dOName, DOOnOff dOOnOff) + { + //ComOn(); + serialPort.Write(new byte[] { 0xE3, 0x01, 0x09, (byte)dOName, (byte)dOOnOff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0, 12); + } + + /// + /// 文本框传输数据控制COM5串口 + /// + public void DOTestSend(string str) + { + //ComOn(); + string[] strArray = str.Split(' '); + byte[] bytes = new byte[strArray.Length]; + for (int i = 0; i < bytes.Length; i++) + { + bytes[i] = Convert.ToByte(strArray[i], 16); + } + serialPort.Write(bytes, 0, bytes.Length); + } + } +} \ No newline at end of file diff --git a/Mesnac.DoUtils/Mesnac.DoUtils.csproj b/Mesnac.DoUtils/Mesnac.DoUtils.csproj new file mode 100644 index 0000000..f979560 --- /dev/null +++ b/Mesnac.DoUtils/Mesnac.DoUtils.csproj @@ -0,0 +1,50 @@ + + + + + Debug + AnyCPU + {AD132CAD-5288-44DC-A38F-4B0658FC228C} + Library + Properties + Mesnac.DoUtils + Mesnac.DoUtils + v4.5.2 + 512 + true + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Mesnac.DoUtils/Properties/AssemblyInfo.cs b/Mesnac.DoUtils/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..dab90a9 --- /dev/null +++ b/Mesnac.DoUtils/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 有关程序集的一般信息由以下 +// 控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("Mesnac.DoUtils")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Mesnac.DoUtils")] +[assembly: AssemblyCopyright("Copyright © 2023")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 会使此程序集中的类型 +//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 +//请将此类型的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("ad132cad-5288-44dc-a38f-4b0658fc228c")] + +// 程序集的版本信息由下列四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值 +//通过使用 "*",如下所示: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Mesnac.DoUtils/enumInfo/DOName.cs b/Mesnac.DoUtils/enumInfo/DOName.cs new file mode 100644 index 0000000..14a612b --- /dev/null +++ b/Mesnac.DoUtils/enumInfo/DOName.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Mesnac.DoUtils.enumInfo +{ + public enum DOName + { + Red = 0x01, + Green = 0x02, + Buzzer = 0x03, + dO_4 = 0x04, + dO_5 = 0x05, + dO_6 = 0x06, + dO_7 = 0x07, + dO_8 = 0x08, + } +} diff --git a/Mesnac.DoUtils/enumInfo/DOOnOff.cs b/Mesnac.DoUtils/enumInfo/DOOnOff.cs new file mode 100644 index 0000000..1457a15 --- /dev/null +++ b/Mesnac.DoUtils/enumInfo/DOOnOff.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Mesnac.DoUtils.enumInfo +{ + public enum DOOnOff + { + Off = 0x00, + On = 0x01 + } +} diff --git a/SlnMix.VS2013.sln b/SlnMix.VS2013.sln index 9e0c4ca..0dd68d4 100644 --- a/SlnMix.VS2013.sln +++ b/SlnMix.VS2013.sln @@ -162,6 +162,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "PlcUtils", "PlcUtils", "{DE EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mesnac.PlcUtils", "Mesnac.PlcUtils\Mesnac.PlcUtils.csproj", "{88EAC8D1-8783-478C-AD9D-F916673B7004}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "DoUtils", "DoUtils", "{9F21B6A6-9B19-4AAC-88EF-A430D8808540}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mesnac.DoUtils", "Mesnac.DoUtils\Mesnac.DoUtils.csproj", "{AD132CAD-5288-44DC-A38F-4B0658FC228C}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -328,6 +332,18 @@ Global {88EAC8D1-8783-478C-AD9D-F916673B7004}.Release|Mixed Platforms.Build.0 = Release|Any CPU {88EAC8D1-8783-478C-AD9D-F916673B7004}.Release|x86.ActiveCfg = Release|Any CPU {88EAC8D1-8783-478C-AD9D-F916673B7004}.Release|x86.Build.0 = Release|Any CPU + {AD132CAD-5288-44DC-A38F-4B0658FC228C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AD132CAD-5288-44DC-A38F-4B0658FC228C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AD132CAD-5288-44DC-A38F-4B0658FC228C}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {AD132CAD-5288-44DC-A38F-4B0658FC228C}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {AD132CAD-5288-44DC-A38F-4B0658FC228C}.Debug|x86.ActiveCfg = Debug|Any CPU + {AD132CAD-5288-44DC-A38F-4B0658FC228C}.Debug|x86.Build.0 = Debug|Any CPU + {AD132CAD-5288-44DC-A38F-4B0658FC228C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AD132CAD-5288-44DC-A38F-4B0658FC228C}.Release|Any CPU.Build.0 = Release|Any CPU + {AD132CAD-5288-44DC-A38F-4B0658FC228C}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {AD132CAD-5288-44DC-A38F-4B0658FC228C}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {AD132CAD-5288-44DC-A38F-4B0658FC228C}.Release|x86.ActiveCfg = Release|Any CPU + {AD132CAD-5288-44DC-A38F-4B0658FC228C}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -357,6 +373,7 @@ Global {D0C0324F-434E-47EB-8F7C-BA6CD7F233B4} = {DE938080-4A00-4686-9CE4-1C33FCA86346} {6A2190C6-B530-4D5B-BD34-29EFB0431F67} = {66F3B234-E56C-4EF4-AB6D-BB6D91467855} {88EAC8D1-8783-478C-AD9D-F916673B7004} = {DE8C4FC3-17D6-4217-8AB1-72ADE8D85810} + {AD132CAD-5288-44DC-A38F-4B0658FC228C} = {9F21B6A6-9B19-4AAC-88EF-A430D8808540} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {125BF7F5-E6EF-487C-B939-0631965DB3C1}