master
wangsr 1 year ago
commit febbba11c9

@ -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; IBaseControl starttime = mcControllist.Where(t => t.BaseControl.MCKey != null && t.BaseControl.MCKey.ToLower() == "starttime").FirstOrDefault().BaseControl;
if (startdate != null && starttime != null) 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 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; IBaseControl endtime = mcControllist.Where(t => t.BaseControl.MCKey != null && t.BaseControl.MCKey.ToLower() == "endtime").FirstOrDefault().BaseControl;
if (enddate != null && endtime != null) 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 else
{ {

@ -1,12 +1,15 @@
using DevExpress.Xpo.DB; using DevExpress.Xpo.DB;
using FastReport.Export.Dbf;
using HslCommunication; using HslCommunication;
using Mesnac.Codd.Session; using Mesnac.Codd.Session;
using Mesnac.DoUtils;
using Mesnac.PlcUtils; using Mesnac.PlcUtils;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Data; using System.Data;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading;
namespace Mesnac.Action.ChemicalWeighing.FinishBatch.SaveHelper namespace Mesnac.Action.ChemicalWeighing.FinishBatch.SaveHelper
{ {
@ -23,6 +26,8 @@ namespace Mesnac.Action.ChemicalWeighing.FinishBatch.SaveHelper
private static PlcBusiness plcBusiness = PlcBusiness.Instance; private static PlcBusiness plcBusiness = PlcBusiness.Instance;
private static DoControl doControl = DoControl.Instance;
/// <summary> /// <summary>
/// 保存报警信息 /// 保存报警信息
/// </summary> /// </summary>
@ -123,6 +128,10 @@ namespace Mesnac.Action.ChemicalWeighing.FinishBatch.SaveHelper
{ {
sai.AlarmData = Convert.ToInt16(result.Content); //对起始字偏移,为当前字的报警值 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)); Entity.PmtAlarmInfo alarmInfo = Cache.CacheHelper.GetPmtAlarmInfoFromCache(sai.AlramPLC, sai.AlarmBlock, sai.AlarmAddress, Convert.ToInt32(sai.AlarmBit));
if (alarmInfo != null) if (alarmInfo != null)
@ -145,9 +154,7 @@ namespace Mesnac.Action.ChemicalWeighing.FinishBatch.SaveHelper
alarmLogData.Alarm_Status = 1; alarmLogData.Alarm_Status = 1;
alarmLogData.Alarm_GUID = Guid.NewGuid().ToString().ToUpper(); alarmLogData.Alarm_GUID = Guid.NewGuid().ToString().ToUpper();
Alarm.AlarmHelper.InsertAlarmLogData(alarmLogData); //这里保存数据库有问题 Alarm.AlarmHelper.InsertAlarmLogData(alarmLogData);
ICSharpCode.Core.LoggingService<AlarmSaveHelper>.Error("这里保存数据库有问题");
Global.PublicVar.Instance.AlarmStrList.Add(alarmInfo.AlarmName); Global.PublicVar.Instance.AlarmStrList.Add(alarmInfo.AlarmName);
Global.PublicVar.Instance.isFlashFlag = true; Global.PublicVar.Instance.isFlashFlag = true;
Global.PublicVar.Instance.isFlashFlagExtend = 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 触发事件 #region 触发事件

@ -791,6 +791,10 @@
<Project>{28acacf1-9936-4e97-a866-f84366ec5286}</Project> <Project>{28acacf1-9936-4e97-a866-f84366ec5286}</Project>
<Name>Mesnac.Basic</Name> <Name>Mesnac.Basic</Name>
</ProjectReference> </ProjectReference>
<ProjectReference Include="..\..\..\Mesnac.DoUtils\Mesnac.DoUtils.csproj">
<Project>{ad132cad-5288-44dc-a38f-4b0658fc228c}</Project>
<Name>Mesnac.DoUtils</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\Mesnac.PlcUtils\Mesnac.PlcUtils.csproj"> <ProjectReference Include="..\..\..\Mesnac.PlcUtils\Mesnac.PlcUtils.csproj">
<Project>{88eac8d1-8783-478c-ad9d-f916673b7004}</Project> <Project>{88eac8d1-8783-478c-ad9d-f916673b7004}</Project>
<Name>Mesnac.PlcUtils</Name> <Name>Mesnac.PlcUtils</Name>

@ -251,6 +251,10 @@
<Project>{d0c0324f-434e-47eb-8f7c-ba6cd7f233b4}</Project> <Project>{d0c0324f-434e-47eb-8f7c-ba6cd7f233b4}</Project>
<Name>Mesnac.Controls.Feeding</Name> <Name>Mesnac.Controls.Feeding</Name>
</ProjectReference> </ProjectReference>
<ProjectReference Include="..\..\Mesnac.DoUtils\Mesnac.DoUtils.csproj">
<Project>{ad132cad-5288-44dc-a38f-4b0658fc228c}</Project>
<Name>Mesnac.DoUtils</Name>
</ProjectReference>
<ProjectReference Include="..\..\Mesnac.PlcUtils\Mesnac.PlcUtils.csproj"> <ProjectReference Include="..\..\Mesnac.PlcUtils\Mesnac.PlcUtils.csproj">
<Project>{88eac8d1-8783-478c-ad9d-f916673b7004}</Project> <Project>{88eac8d1-8783-478c-ad9d-f916673b7004}</Project>
<Name>Mesnac.PlcUtils</Name> <Name>Mesnac.PlcUtils</Name>

@ -10,6 +10,7 @@ using Mesnac.Gui.Run.Global;
namespace MCRun namespace MCRun
{ {
using Mesnac.Core.Service; using Mesnac.Core.Service;
using Mesnac.DoUtils;
using Mesnac.Gui.Workbench; using Mesnac.Gui.Workbench;
using Mesnac.PlcUtils; using Mesnac.PlcUtils;
using Mesnac.PlcUtils.common; using Mesnac.PlcUtils.common;
@ -120,6 +121,7 @@ namespace MCRun
WorkbenchSingleton.InitializeWorkbench(); WorkbenchSingleton.InitializeWorkbench();
PlcBusiness.Instance.InitPlcConnect(PlcType.SiemensPlc, "127.0.0.1", 12); PlcBusiness.Instance.InitPlcConnect(PlcType.SiemensPlc, "127.0.0.1", 12);
DoControl.Instance.ComOn();
ICSharpCode.Core.LoggingService<Program>.Debug("starting workbench..."); ICSharpCode.Core.LoggingService<Program>.Debug("starting workbench...");
Form frmMain = WorkbenchSingleton.Workbench as Form; Form frmMain = WorkbenchSingleton.Workbench as Form;

@ -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
{
/// <summary>
/// 报警灯控制类
/// </summary>
public class DoControl
{
public SerialPort serialPort = new SerialPort("COM5");
private static readonly Lazy<DoControl> lazy = new Lazy<DoControl>(() => 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;
}
/// <summary>
/// 串口启动
/// </summary>
public void ComOn()
{
if (!serialPort.IsOpen)
{
serialPort.Open();
}
}
/// <summary>
/// 串口关闭
/// </summary>
public void ComOff()
{
if (serialPort.IsOpen)
{
serialPort.Close();
}
}
/// <summary>
/// DO1设备启动红灯
/// </summary>
public void redLightOn()
{
DOControl(DOName.Red, DOOnOff.On);
}
/// <summary>
/// DO2设备启动绿灯
/// </summary>
public void greenLightOn()
{
DOControl(DOName.Green, DOOnOff.On);
}
/// <summary>
/// DO3设备启动蜂鸣器
/// </summary>
public void buzzerOn()
{
DOControl(DOName.Buzzer, DOOnOff.On);
}
/// <summary>
/// DO1设备关闭红灯
/// </summary>
public void redLightOff()
{
DOControl(DOName.Red, DOOnOff.Off);
}
/// <summary>
/// DO2设备关闭绿灯
/// </summary>
public void greenLightOff()
{
DOControl(DOName.Green, DOOnOff.Off);
}
/// <summary>
/// DO3设备关闭蜂鸣器
/// </summary>
public void buzzerOff()
{
DOControl(DOName.Buzzer, DOOnOff.On);
}
/// <summary>
/// 重置串口和DO状态
/// </summary>
public void Reset()
{
SetOff();
ComOff();
}
/// <summary>
/// 重置DO状态
/// </summary>
public void SetOff()
{
foreach (DOName dOName in Enum.GetValues(typeof(DOName)))
{
DOControl(dOName, DOOnOff.Off);
}
}
/// <summary>
/// DO启停控制
/// </summary>
/// <param name="dOName">DegitalOut接口名称</param>
/// <param name="dOOnOff">启停状态</param>
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);
}
/// <summary>
/// 文本框传输数据控制COM5串口
/// </summary>
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);
}
}
}

@ -0,0 +1,53 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{AD132CAD-5288-44DC-A38F-4B0658FC228C}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Mesnac.DoUtils</RootNamespace>
<AssemblyName>Mesnac.DoUtils</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<AutoGenerateBindingRedirects>false</AutoGenerateBindingRedirects>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="DoControl.cs" />
<Compile Include="enumInfo\DOName.cs" />
<Compile Include="enumInfo\DOOnOff.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

@ -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")]

@ -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,
}
}

@ -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
}
}

@ -162,6 +162,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "PlcUtils", "PlcUtils", "{DE
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mesnac.PlcUtils", "Mesnac.PlcUtils\Mesnac.PlcUtils.csproj", "{88EAC8D1-8783-478C-AD9D-F916673B7004}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mesnac.PlcUtils", "Mesnac.PlcUtils\Mesnac.PlcUtils.csproj", "{88EAC8D1-8783-478C-AD9D-F916673B7004}"
EndProject 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 Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU 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|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.ActiveCfg = Release|Any CPU
{88EAC8D1-8783-478C-AD9D-F916673B7004}.Release|x86.Build.0 = 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 EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
@ -357,6 +373,7 @@ Global
{D0C0324F-434E-47EB-8F7C-BA6CD7F233B4} = {DE938080-4A00-4686-9CE4-1C33FCA86346} {D0C0324F-434E-47EB-8F7C-BA6CD7F233B4} = {DE938080-4A00-4686-9CE4-1C33FCA86346}
{6A2190C6-B530-4D5B-BD34-29EFB0431F67} = {66F3B234-E56C-4EF4-AB6D-BB6D91467855} {6A2190C6-B530-4D5B-BD34-29EFB0431F67} = {66F3B234-E56C-4EF4-AB6D-BB6D91467855}
{88EAC8D1-8783-478C-AD9D-F916673B7004} = {DE8C4FC3-17D6-4217-8AB1-72ADE8D85810} {88EAC8D1-8783-478C-AD9D-F916673B7004} = {DE8C4FC3-17D6-4217-8AB1-72ADE8D85810}
{AD132CAD-5288-44DC-A38F-4B0658FC228C} = {9F21B6A6-9B19-4AAC-88EF-A430D8808540}
EndGlobalSection EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {125BF7F5-E6EF-487C-B939-0631965DB3C1} SolutionGuid = {125BF7F5-E6EF-487C-B939-0631965DB3C1}

Loading…
Cancel
Save