diff --git a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/Alarm/LRAlarmLog/SelectAction.cs b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/Alarm/LRAlarmLog/SelectAction.cs
index e8a6d2f..6c50831 100644
--- a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/Alarm/LRAlarmLog/SelectAction.cs
+++ b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/Alarm/LRAlarmLog/SelectAction.cs
@@ -31,7 +31,7 @@ namespace Mesnac.Action.ChemicalWeighing.Alarm.LRAlarmLog
IBaseControl starttime = mcControllist.Where(t => t.BaseControl.MCKey != null && t.BaseControl.MCKey.ToLower() == "starttime").FirstOrDefault().BaseControl;
if (startdate != null && starttime != null)
{
- sbSql.AppendLine(@"AND LR_Alarmlog.Alarm_OccurTime>='" + Convert.ToDateTime(startdate.MCValue).ToString("yyyy-MM-dd") + " " + Convert.ToDateTime(starttime.MCValue).ToShortTimeString() + "' ");
+ sbSql.AppendLine(@"AND CONVERT(datetime, LR_Alarmlog.Alarm_OccurTime)>='" + Convert.ToDateTime(startdate.MCValue).ToString("yyyy-MM-dd") + " " + Convert.ToDateTime(starttime.MCValue).ToShortTimeString() + "' ");
}
else
{
@@ -42,7 +42,7 @@ namespace Mesnac.Action.ChemicalWeighing.Alarm.LRAlarmLog
IBaseControl endtime = mcControllist.Where(t => t.BaseControl.MCKey != null && t.BaseControl.MCKey.ToLower() == "endtime").FirstOrDefault().BaseControl;
if (enddate != null && endtime != null)
{
- sbSql.AppendLine(@"AND LR_Alarmlog.Alarm_OccurTime<='" + Convert.ToDateTime(enddate.MCValue).ToString("yyyy-MM-dd") + " " + Convert.ToDateTime(endtime.MCValue).ToShortTimeString() + "' ");
+ sbSql.AppendLine(@"AND CONVERT(datetime, LR_Alarmlog.Alarm_OccurTime)<='" + Convert.ToDateTime(enddate.MCValue).ToString("yyyy-MM-dd") + " " + Convert.ToDateTime(endtime.MCValue).ToShortTimeString() + "' ");
}
else
{
diff --git a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/FinishBatch/SaveHelper/AlarmSaveHelper.cs b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/FinishBatch/SaveHelper/AlarmSaveHelper.cs
index 8573197..2702761 100644
--- a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/FinishBatch/SaveHelper/AlarmSaveHelper.cs
+++ b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/FinishBatch/SaveHelper/AlarmSaveHelper.cs
@@ -1,12 +1,15 @@
using DevExpress.Xpo.DB;
+using FastReport.Export.Dbf;
using HslCommunication;
using Mesnac.Codd.Session;
+using Mesnac.DoUtils;
using Mesnac.PlcUtils;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
+using System.Threading;
namespace Mesnac.Action.ChemicalWeighing.FinishBatch.SaveHelper
{
@@ -23,6 +26,8 @@ namespace Mesnac.Action.ChemicalWeighing.FinishBatch.SaveHelper
private static PlcBusiness plcBusiness = PlcBusiness.Instance;
+ private static DoControl doControl = DoControl.Instance;
+
///
/// 保存报警信息
///
@@ -123,6 +128,10 @@ namespace Mesnac.Action.ChemicalWeighing.FinishBatch.SaveHelper
{
sai.AlarmData = Convert.ToInt16(result.Content); //对起始字偏移,为当前字的报警值
+ //打开报警灯:FIRST 关闭绿灯 SECOND 打开红灯
+ doControl.DOControl(DoUtils.enumInfo.DOName.Green, DoUtils.enumInfo.DOOnOff.Off);
+ 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)
@@ -145,9 +154,7 @@ namespace Mesnac.Action.ChemicalWeighing.FinishBatch.SaveHelper
alarmLogData.Alarm_Status = 1;
alarmLogData.Alarm_GUID = Guid.NewGuid().ToString().ToUpper();
- Alarm.AlarmHelper.InsertAlarmLogData(alarmLogData); //这里保存数据库有问题
- ICSharpCode.Core.LoggingService.Error("这里保存数据库有问题");
-
+ Alarm.AlarmHelper.InsertAlarmLogData(alarmLogData);
Global.PublicVar.Instance.AlarmStrList.Add(alarmInfo.AlarmName);
Global.PublicVar.Instance.isFlashFlag = true;
Global.PublicVar.Instance.isFlashFlagExtend = true;
@@ -155,8 +162,18 @@ namespace Mesnac.Action.ChemicalWeighing.FinishBatch.SaveHelper
}
}
}
+ else
+ {
+ // 关闭报警灯:FIRST 打开红灯 SECOND 关闭绿灯
+ doControl.DOControl(DoUtils.enumInfo.DOName.Red, DoUtils.enumInfo.DOOnOff.Off);
+ doControl.DOControl(DoUtils.enumInfo.DOName.Green, DoUtils.enumInfo.DOOnOff.On);
+ }
}
+ else
+ {
+ doControl.DOControl(DoUtils.enumInfo.DOName.Red, DoUtils.enumInfo.DOOnOff.Off);
+ }
}
#region 触发事件
diff --git a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/Mesnac.Action.ChemicalWeighing.csproj b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/Mesnac.Action.ChemicalWeighing.csproj
index 5c98ca4..92c9fc2 100644
--- a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/Mesnac.Action.ChemicalWeighing.csproj
+++ b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/Mesnac.Action.ChemicalWeighing.csproj
@@ -791,6 +791,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/Main/MCRun/MCRun.csproj b/Main/MCRun/MCRun.csproj
index 9dec82d..f9f7c87 100644
--- a/Main/MCRun/MCRun.csproj
+++ b/Main/MCRun/MCRun.csproj
@@ -251,6 +251,10 @@
{d0c0324f-434e-47eb-8f7c-ba6cd7f233b4}
Mesnac.Controls.Feeding
+
+ {ad132cad-5288-44dc-a38f-4b0658fc228c}
+ Mesnac.DoUtils
+
{88eac8d1-8783-478c-ad9d-f916673b7004}
Mesnac.PlcUtils
diff --git a/Main/MCRun/Program.cs b/Main/MCRun/Program.cs
index baf2532..7a9ee0c 100644
--- a/Main/MCRun/Program.cs
+++ b/Main/MCRun/Program.cs
@@ -10,6 +10,7 @@ using Mesnac.Gui.Run.Global;
namespace MCRun
{
using Mesnac.Core.Service;
+ using Mesnac.DoUtils;
using Mesnac.Gui.Workbench;
using Mesnac.PlcUtils;
using Mesnac.PlcUtils.common;
@@ -120,6 +121,7 @@ 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
new file mode 100644
index 0000000..fdefe6a
--- /dev/null
+++ b/Mesnac.DoUtils/DoControl.cs
@@ -0,0 +1,155 @@
+using Mesnac.DoUtils.enumInfo;
+using System;
+using System.Collections.Generic;
+using System.IO.Ports;
+using System.Linq;
+using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
+using System.Xml.Linq;
+
+namespace Mesnac.DoUtils
+{
+ ///
+ /// 报警灯控制类
+ ///
+ public class DoControl
+ {
+ public SerialPort serialPort = new SerialPort("COM5");
+ 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;
+ }
+
+ ///
+ /// 串口启动
+ ///
+ 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();
+ if (!serialPort.IsOpen)
+ {
+ serialPort.Open();
+ }
+ 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..d8ad2d4
--- /dev/null
+++ b/Mesnac.DoUtils/Mesnac.DoUtils.csproj
@@ -0,0 +1,53 @@
+
+
+
+
+ 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
+
+
+ false
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ 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}