add - 增加报警灯控制

master
wenjy 1 year ago
parent 22b6de500b
commit 969946be45

@ -1,6 +1,7 @@
using DevExpress.Xpo.DB; using DevExpress.Xpo.DB;
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;
@ -23,6 +24,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 +126,9 @@ namespace Mesnac.Action.ChemicalWeighing.FinishBatch.SaveHelper
{ {
sai.AlarmData = Convert.ToInt16(result.Content); //对起始字偏移,为当前字的报警值 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)); Entity.PmtAlarmInfo alarmInfo = Cache.CacheHelper.GetPmtAlarmInfoFromCache(sai.AlramPLC, sai.AlarmBlock, sai.AlarmAddress, Convert.ToInt32(sai.AlarmBit));
if (alarmInfo != null) if (alarmInfo != null)

@ -733,6 +733,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>

@ -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
{
/// <summary>
/// 报警灯控制类
/// </summary>
public sealed class DoControl
{
public SerialPort serialPort;
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;
serialPort = new SerialPort("COM5");
}
/// <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();
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,50 @@
<?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>
<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