master
nodyang 1 year ago
parent 6c0ba7c4db
commit 73320cb736

@ -26,9 +26,9 @@ namespace Mesnac.Action.ChemicalWeighing.EngineeringDebuggingMode.ElectronicMach
public ElectronicMachinery()
{
InitializeComponent();
DoControl AlarmLight = DoControl.Instance;
DoControl.Instance.ComOn();
DoControl.Instance.DOControl(DoUtils.enumInfo.DOName.Green, DoUtils.enumInfo.DOOnOff.On);
// DoControl AlarmLight = DoControl.Instance;
// DoControl.Instance.ComOn();
// DoControl.Instance.DOControl(DoUtils.enumInfo.DOName.Green, DoUtils.enumInfo.DOOnOff.On);
StateMonitor();
}
@ -249,8 +249,8 @@ namespace Mesnac.Action.ChemicalWeighing.EngineeringDebuggingMode.ElectronicMach
private void AlarmReset_Click(object sender, EventArgs e)
{
SetDataValue("_Alarm", 0);
DoControl.Instance.DOControl(DoUtils.enumInfo.DOName.Green, DoUtils.enumInfo.DOOnOff.On);
DoControl.Instance.DOControl(DoUtils.enumInfo.DOName.Red, DoUtils.enumInfo.DOOnOff.Off);
// DoControl.Instance.DOControl(DoUtils.enumInfo.DOName.Green, DoUtils.enumInfo.DOOnOff.On);
// DoControl.Instance.DOControl(DoUtils.enumInfo.DOName.Red, DoUtils.enumInfo.DOOnOff.Off);
}
/// <summary>
@ -281,8 +281,8 @@ namespace Mesnac.Action.ChemicalWeighing.EngineeringDebuggingMode.ElectronicMach
private void Alarm_Click(object sender, EventArgs e)
{
SetDataValue("_Alarm", 1);
DoControl.Instance.DOControl(DoUtils.enumInfo.DOName.Red, DoUtils.enumInfo.DOOnOff.On);
DoControl.Instance.DOControl(DoUtils.enumInfo.DOName.Green, DoUtils.enumInfo.DOOnOff.Off);
// DoControl.Instance.DOControl(DoUtils.enumInfo.DOName.Red, DoUtils.enumInfo.DOOnOff.On);
// DoControl.Instance.DOControl(DoUtils.enumInfo.DOName.Green, DoUtils.enumInfo.DOOnOff.Off);
}
/// <summary>
@ -292,9 +292,9 @@ namespace Mesnac.Action.ChemicalWeighing.EngineeringDebuggingMode.ElectronicMach
/// <param name="e"></param>
private void ElectronicMachinery_FormClosing(object sender, FormClosingEventArgs e)
{
DoControl.Instance.DOControl(DoUtils.enumInfo.DOName.Green, DoUtils.enumInfo.DOOnOff.Off);
DoControl.Instance.DOControl(DoUtils.enumInfo.DOName.Red, DoUtils.enumInfo.DOOnOff.Off);
DoControl.Instance.ComOff();
// DoControl.Instance.DOControl(DoUtils.enumInfo.DOName.Green, DoUtils.enumInfo.DOOnOff.Off);
// DoControl.Instance.DOControl(DoUtils.enumInfo.DOName.Red, DoUtils.enumInfo.DOOnOff.Off);
// DoControl.Instance.ComOff();
}

@ -23,9 +23,9 @@ namespace Mesnac.Action.ChemicalWeighing.EngineeringDebuggingMode.ElectronicMach
public ElectronicMachinery_2()
{
InitializeComponent();
DoControl AlarmLight = DoControl.Instance;
DoControl.Instance.ComOn();
DoControl.Instance.DOControl(DoUtils.enumInfo.DOName.Green, DoUtils.enumInfo.DOOnOff.On);
// DoControl AlarmLight = DoControl.Instance;
// DoControl.Instance.ComOn();
// DoControl.Instance.DOControl(DoUtils.enumInfo.DOName.Green, DoUtils.enumInfo.DOOnOff.On);
StateMonitor();
}
@ -129,15 +129,15 @@ namespace Mesnac.Action.ChemicalWeighing.EngineeringDebuggingMode.ElectronicMach
private void Alarm_Click(object sender, EventArgs e)
{
SetDataValue("_Alarm", 1);
DoControl.Instance.DOControl(DoUtils.enumInfo.DOName.Red, DoUtils.enumInfo.DOOnOff.On);
DoControl.Instance.DOControl(DoUtils.enumInfo.DOName.Green, DoUtils.enumInfo.DOOnOff.Off);
// DoControl.Instance.DOControl(DoUtils.enumInfo.DOName.Red, DoUtils.enumInfo.DOOnOff.On);
// DoControl.Instance.DOControl(DoUtils.enumInfo.DOName.Green, DoUtils.enumInfo.DOOnOff.Off);
}
private void AlarmReset_Click(object sender, EventArgs e)
{
SetDataValue("_Alarm", 0);
DoControl.Instance.DOControl(DoUtils.enumInfo.DOName.Green, DoUtils.enumInfo.DOOnOff.On);
DoControl.Instance.DOControl(DoUtils.enumInfo.DOName.Red, DoUtils.enumInfo.DOOnOff.Off);
// DoControl.Instance.DOControl(DoUtils.enumInfo.DOName.Green, DoUtils.enumInfo.DOOnOff.On);
// DoControl.Instance.DOControl(DoUtils.enumInfo.DOName.Red, DoUtils.enumInfo.DOOnOff.Off);
}
/// <summary>

@ -25,9 +25,9 @@ namespace Mesnac.Action.ChemicalWeighing.EngineeringDebuggingMode.ValveStateCont
public ValveStateControl()
{
InitializeComponent();
DoControl AlarmLight = DoControl.Instance;
DoControl.Instance.ComOn();
DoControl.Instance.DOControl(DoUtils.enumInfo.DOName.Green, DoUtils.enumInfo.DOOnOff.On);
// DoControl AlarmLight = DoControl.Instance;
// DoControl.Instance.ComOn();
// DoControl.Instance.DOControl(DoUtils.enumInfo.DOName.Green, DoUtils.enumInfo.DOOnOff.On);
StateMonitor();
}
@ -199,8 +199,8 @@ namespace Mesnac.Action.ChemicalWeighing.EngineeringDebuggingMode.ValveStateCont
private void Alarm_Click(object sender, EventArgs e)
{
SetDataValue("_Alarm", 1);
DoControl.Instance.DOControl(DoUtils.enumInfo.DOName.Red, DoUtils.enumInfo.DOOnOff.On);
DoControl.Instance.DOControl(DoUtils.enumInfo.DOName.Green, DoUtils.enumInfo.DOOnOff.Off);
// DoControl.Instance.DOControl(DoUtils.enumInfo.DOName.Red, DoUtils.enumInfo.DOOnOff.On);
// DoControl.Instance.DOControl(DoUtils.enumInfo.DOName.Green, DoUtils.enumInfo.DOOnOff.Off);
}
/// <summary>
@ -211,8 +211,8 @@ namespace Mesnac.Action.ChemicalWeighing.EngineeringDebuggingMode.ValveStateCont
private void AlarmSet_Click(object sender, EventArgs e)
{
SetDataValue("_Alarm", 0);
DoControl.Instance.DOControl(DoUtils.enumInfo.DOName.Green, DoUtils.enumInfo.DOOnOff.On);
DoControl.Instance.DOControl(DoUtils.enumInfo.DOName.Red, DoUtils.enumInfo.DOOnOff.Off);
// DoControl.Instance.DOControl(DoUtils.enumInfo.DOName.Green, DoUtils.enumInfo.DOOnOff.On);
// DoControl.Instance.DOControl(DoUtils.enumInfo.DOName.Red, DoUtils.enumInfo.DOOnOff.Off);
}
/// <summary>
@ -232,9 +232,9 @@ namespace Mesnac.Action.ChemicalWeighing.EngineeringDebuggingMode.ValveStateCont
/// <param name="e"></param>
private void ValveStateControl_FormClosing(object sender, FormClosingEventArgs e)
{
DoControl.Instance.DOControl(DoUtils.enumInfo.DOName.Green, DoUtils.enumInfo.DOOnOff.Off);
DoControl.Instance.DOControl(DoUtils.enumInfo.DOName.Red, DoUtils.enumInfo.DOOnOff.Off);
DoControl.Instance.ComOff();
// DoControl.Instance.DOControl(DoUtils.enumInfo.DOName.Green, DoUtils.enumInfo.DOOnOff.Off);
// DoControl.Instance.DOControl(DoUtils.enumInfo.DOName.Red, DoUtils.enumInfo.DOOnOff.Off);
// DoControl.Instance.ComOff();
}
private IDictionary<string, string> dmNameValue = new Dictionary<string, string>()

@ -28,7 +28,7 @@ namespace Mesnac.Action.ChemicalWeighing.FinishBatch.SaveHelper
private PlcBusiness plcBusiness = PlcBusiness.Instance;
private DoControl doControl = DoControl.Instance;
// private DoControl doControl = DoControl.Instance;
private static readonly Lazy<AlarmSaveHelper> lazy = new Lazy<AlarmSaveHelper>(() => new AlarmSaveHelper());
@ -239,18 +239,18 @@ namespace Mesnac.Action.ChemicalWeighing.FinishBatch.SaveHelper
/// <param name="flag">是否报警</param>
private void AlarmLight(bool flag)
{
if(flag)
{
//打开报警灯:FIRST 关闭绿灯 SECOND 打开红灯
doControl.DOControl(DoUtils.enumInfo.DOName.Green, DoUtils.enumInfo.DOOnOff.Off);
doControl.DOControl(DoUtils.enumInfo.DOName.Red, DoUtils.enumInfo.DOOnOff.On);
}
else
{
// 关闭报警灯:FIRST 打开红灯 SECOND 关闭绿灯
doControl.DOControl(DoUtils.enumInfo.DOName.Red, DoUtils.enumInfo.DOOnOff.Off);
doControl.DOControl(DoUtils.enumInfo.DOName.Green, DoUtils.enumInfo.DOOnOff.On);
}
// if(flag)
// {
// //打开报警灯:FIRST 关闭绿灯 SECOND 打开红灯
// doControl.DOControl(DoUtils.enumInfo.DOName.Green, DoUtils.enumInfo.DOOnOff.Off);
// doControl.DOControl(DoUtils.enumInfo.DOName.Red, DoUtils.enumInfo.DOOnOff.On);
// }
// else
// {
// // 关闭报警灯:FIRST 打开红灯 SECOND 关闭绿灯
// doControl.DOControl(DoUtils.enumInfo.DOName.Red, DoUtils.enumInfo.DOOnOff.Off);
// doControl.DOControl(DoUtils.enumInfo.DOName.Green, DoUtils.enumInfo.DOOnOff.On);
// }
}
}
}

@ -153,6 +153,9 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\PlugInPlatform\Mesnac.PlugIn.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Office.Interop.Excel">
<HintPath>..\..\Microsoft.Office.Interop.Excel.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />

@ -28,7 +28,7 @@ namespace MCRun
static void Main(string[] args)
{
Timer timer = new Timer();
if (Mesnac.Basic.ProcessHelper.HaveRunningInstance())
{
@ -125,15 +125,10 @@ namespace MCRun
ICSharpCode.Core.LoggingService<Program>.Debug("HSLPlc读取失败");
}
//初始化连接报警器
DoControl.Instance.ComOn();
// DoControl.Instance.ComOn();
// 设置触发间隔时间(以毫秒为单位)
timer.Interval = 1500; // 1000 毫秒 = 1 秒
// 绑定 Tick 事件处理程序
timer.Tick += new EventHandler(new Program().Timer_Tick);
// 启动 Timer
timer.Start();
}
@ -193,14 +188,5 @@ namespace MCRun
Application.Exit();
}
private void Timer_Tick(object sender, EventArgs e)
{
// 定时触发的操作
Task.Run(() => {
// FinishBatchService.Instance.Start();
});
}
}
}

@ -1,168 +1,168 @@
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 sealed class DoControl
{
public SerialPort serialPort = new SerialPort("COM5");
private static readonly Lazy<DoControl> lazy = new Lazy<DoControl>(() => new DoControl());
public static DoControl Instance => lazy.Value;
public bool AlarmState { get; private set; } = false;
private DoControl()
{
serialPort.BaudRate = 115200;
serialPort.DataBits = 8;
serialPort.StopBits = StopBits.One;
serialPort.Parity = Parity.None;
}
/// <summary>
/// 串口启动
/// </summary>
public void ComOn()
{
try
{
if (!serialPort.IsOpen)
{
serialPort.Open();
ICSharpCode.Core.LoggingService<DoControl>.Debug($"打开报警器串口成功,串口:{serialPort.PortName};波特率:{serialPort.BaudRate}");
}
}catch (Exception ex)
{
ICSharpCode.Core.LoggingService<DoControl>.Error($"报警器串口打开异常,串口:{serialPort.PortName};波特率:{serialPort.BaudRate};异常信息:{ex.Message}");
}
}
/// <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启停控制
/// 如果收到红灯亮的信号AlarmState会变为True; 收到红灯灭的信号AlarmState设置为false
/// </summary>
/// <param name="dOName">DegitalOut接口名称</param>
/// <param name="dOOnOff">启停状态</param>
public void DOControl(DOName dOName, DOOnOff dOOnOff)
{
if(dOName.Equals(DOName.Red) && dOOnOff.Equals(DOOnOff.On))
{
AlarmState = true;
}
if(dOName.Equals(DOName.Red) && dOOnOff.Equals(DOOnOff.Off))
{
AlarmState = false;
}
if (serialPort.IsOpen)
{
serialPort.Write(new byte[] { 0xE3, 0x01, 0x09, (byte)dOName, (byte)dOOnOff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0, 12);
}
else
{
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)
{
// 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 sealed class DoControl
// {
// public SerialPort serialPort = new SerialPort("COM5");
// private static readonly Lazy<DoControl> lazy = new Lazy<DoControl>(() => new DoControl());
// public static DoControl Instance => lazy.Value;
// public bool AlarmState { get; private set; } = false;
// private DoControl()
// {
// serialPort.BaudRate = 115200;
// serialPort.DataBits = 8;
// serialPort.StopBits = StopBits.One;
// serialPort.Parity = Parity.None;
// }
//
// /// <summary>
// /// 串口启动
// /// </summary>
// public void ComOn()
// {
// try
// {
// if (!serialPort.IsOpen)
// {
// serialPort.Open();
// ICSharpCode.Core.LoggingService<DoControl>.Debug($"打开报警器串口成功,串口:{serialPort.PortName};波特率:{serialPort.BaudRate}");
// }
// }catch (Exception ex)
// {
// ICSharpCode.Core.LoggingService<DoControl>.Error($"报警器串口打开异常,串口:{serialPort.PortName};波特率:{serialPort.BaudRate};异常信息:{ex.Message}");
// }
// }
// /// <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启停控制
// /// 如果收到红灯亮的信号AlarmState会变为True; 收到红灯灭的信号AlarmState设置为false
// /// </summary>
// /// <param name="dOName">DegitalOut接口名称</param>
// /// <param name="dOOnOff">启停状态</param>
// public void DOControl(DOName dOName, DOOnOff dOOnOff)
// {
// if(dOName.Equals(DOName.Red) && dOOnOff.Equals(DOOnOff.On))
// {
// AlarmState = true;
// }
// if(dOName.Equals(DOName.Red) && dOOnOff.Equals(DOOnOff.Off))
// {
// AlarmState = false;
// }
// if (serialPort.IsOpen)
// {
// serialPort.Write(new byte[] { 0xE3, 0x01, 0x09, (byte)dOName, (byte)dOOnOff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0, 12);
// }
// else
// {
// 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);
}
}
}
// 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);
// }
// }
// }
Loading…
Cancel
Save