master
nodyang 1 year ago
parent 6c0ba7c4db
commit 73320cb736

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

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

@ -25,9 +25,9 @@ namespace Mesnac.Action.ChemicalWeighing.EngineeringDebuggingMode.ValveStateCont
public ValveStateControl() public ValveStateControl()
{ {
InitializeComponent(); InitializeComponent();
DoControl AlarmLight = DoControl.Instance; // DoControl AlarmLight = DoControl.Instance;
DoControl.Instance.ComOn(); // DoControl.Instance.ComOn();
DoControl.Instance.DOControl(DoUtils.enumInfo.DOName.Green, DoUtils.enumInfo.DOOnOff.On); // DoControl.Instance.DOControl(DoUtils.enumInfo.DOName.Green, DoUtils.enumInfo.DOOnOff.On);
StateMonitor(); StateMonitor();
} }
@ -199,8 +199,8 @@ namespace Mesnac.Action.ChemicalWeighing.EngineeringDebuggingMode.ValveStateCont
private void Alarm_Click(object sender, EventArgs e) private void Alarm_Click(object sender, EventArgs e)
{ {
SetDataValue("_Alarm", 1); SetDataValue("_Alarm", 1);
DoControl.Instance.DOControl(DoUtils.enumInfo.DOName.Red, DoUtils.enumInfo.DOOnOff.On); // 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.Green, DoUtils.enumInfo.DOOnOff.Off);
} }
/// <summary> /// <summary>
@ -211,8 +211,8 @@ namespace Mesnac.Action.ChemicalWeighing.EngineeringDebuggingMode.ValveStateCont
private void AlarmSet_Click(object sender, EventArgs e) private void AlarmSet_Click(object sender, EventArgs e)
{ {
SetDataValue("_Alarm", 0); SetDataValue("_Alarm", 0);
DoControl.Instance.DOControl(DoUtils.enumInfo.DOName.Green, DoUtils.enumInfo.DOOnOff.On); // 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.Red, DoUtils.enumInfo.DOOnOff.Off);
} }
/// <summary> /// <summary>
@ -232,9 +232,9 @@ namespace Mesnac.Action.ChemicalWeighing.EngineeringDebuggingMode.ValveStateCont
/// <param name="e"></param> /// <param name="e"></param>
private void ValveStateControl_FormClosing(object sender, FormClosingEventArgs e) 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.Green, DoUtils.enumInfo.DOOnOff.Off);
DoControl.Instance.DOControl(DoUtils.enumInfo.DOName.Red, DoUtils.enumInfo.DOOnOff.Off); // DoControl.Instance.DOControl(DoUtils.enumInfo.DOName.Red, DoUtils.enumInfo.DOOnOff.Off);
DoControl.Instance.ComOff(); // DoControl.Instance.ComOff();
} }
private IDictionary<string, string> dmNameValue = new Dictionary<string, string>() 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 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()); 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> /// <param name="flag">是否报警</param>
private void AlarmLight(bool flag) private void AlarmLight(bool flag)
{ {
if(flag) // if(flag)
{ // {
//打开报警灯:FIRST 关闭绿灯 SECOND 打开红灯 // //打开报警灯:FIRST 关闭绿灯 SECOND 打开红灯
doControl.DOControl(DoUtils.enumInfo.DOName.Green, DoUtils.enumInfo.DOOnOff.Off); // doControl.DOControl(DoUtils.enumInfo.DOName.Green, DoUtils.enumInfo.DOOnOff.Off);
doControl.DOControl(DoUtils.enumInfo.DOName.Red, DoUtils.enumInfo.DOOnOff.On); // doControl.DOControl(DoUtils.enumInfo.DOName.Red, DoUtils.enumInfo.DOOnOff.On);
} // }
else // else
{ // {
// 关闭报警灯:FIRST 打开红灯 SECOND 关闭绿灯 // // 关闭报警灯:FIRST 打开红灯 SECOND 关闭绿灯
doControl.DOControl(DoUtils.enumInfo.DOName.Red, DoUtils.enumInfo.DOOnOff.Off); // doControl.DOControl(DoUtils.enumInfo.DOName.Red, DoUtils.enumInfo.DOOnOff.Off);
doControl.DOControl(DoUtils.enumInfo.DOName.Green, DoUtils.enumInfo.DOOnOff.On); // doControl.DOControl(DoUtils.enumInfo.DOName.Green, DoUtils.enumInfo.DOOnOff.On);
} // }
} }
} }
} }

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

@ -28,7 +28,7 @@ namespace MCRun
static void Main(string[] args) static void Main(string[] args)
{ {
Timer timer = new Timer();
if (Mesnac.Basic.ProcessHelper.HaveRunningInstance()) if (Mesnac.Basic.ProcessHelper.HaveRunningInstance())
{ {
@ -117,7 +117,7 @@ namespace MCRun
doc.Load(instance); doc.Load(instance);
var nodes = doc.ChildNodes[1].ChildNodes[0].ChildNodes[0].ChildNodes[4].ChildNodes[0]; var nodes = doc.ChildNodes[1].ChildNodes[0].ChildNodes[0].ChildNodes[4].ChildNodes[0];
var ip = nodes.Attributes["value"].Value; var ip = nodes.Attributes["value"].Value;
//初始化HslCommunication 11.0.6.0 //初始化HslCommunication 11.0.6.0
PlcBusiness.Instance.InitPlcConnect(PlcType.SiemensPlc,ip, 102); PlcBusiness.Instance.InitPlcConnect(PlcType.SiemensPlc,ip, 102);
} }
catch (Exception exception) catch (Exception exception)
@ -125,15 +125,10 @@ namespace MCRun
ICSharpCode.Core.LoggingService<Program>.Debug("HSLPlc读取失败"); 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();
} }
@ -192,15 +187,6 @@ namespace MCRun
Application.ExitThread(); Application.ExitThread();
Application.Exit(); Application.Exit();
} }
private void Timer_Tick(object sender, EventArgs e)
{
// 定时触发的操作
Task.Run(() => {
// FinishBatchService.Instance.Start();
});
}
} }
} }

@ -1,168 +1,168 @@
using Mesnac.DoUtils.enumInfo; // using Mesnac.DoUtils.enumInfo;
using System; // using System;
using System.Collections.Generic; // using System.Collections.Generic;
using System.IO.Ports; // using System.IO.Ports;
using System.Linq; // using System.Linq;
using System.Text; // using System.Text;
using System.Threading; // using System.Threading;
using System.Threading.Tasks; // using System.Threading.Tasks;
using System.Xml.Linq; // using System.Xml.Linq;
//
namespace Mesnac.DoUtils // namespace Mesnac.DoUtils
{ // {
/// <summary> // /// <summary>
/// 报警灯控制类 // /// 报警灯控制类
/// </summary> // /// </summary>
public sealed class DoControl // public sealed class DoControl
{ // {
public SerialPort serialPort = new SerialPort("COM5"); // public SerialPort serialPort = new SerialPort("COM5");
private static readonly Lazy<DoControl> lazy = new Lazy<DoControl>(() => new DoControl()); // private static readonly Lazy<DoControl> lazy = new Lazy<DoControl>(() => new DoControl());
public static DoControl Instance => lazy.Value; // public static DoControl Instance => lazy.Value;
public bool AlarmState { get; private set; } = false; // public bool AlarmState { get; private set; } = false;
private DoControl() // private DoControl()
{ // {
serialPort.BaudRate = 115200; // serialPort.BaudRate = 115200;
serialPort.DataBits = 8; // serialPort.DataBits = 8;
serialPort.StopBits = StopBits.One; // serialPort.StopBits = StopBits.One;
serialPort.Parity = Parity.None; // serialPort.Parity = Parity.None;
} // }
//
/// <summary> // /// <summary>
/// 串口启动 // /// 串口启动
/// </summary> // /// </summary>
public void ComOn() // public void ComOn()
{ // {
try // try
{ // {
if (!serialPort.IsOpen) // if (!serialPort.IsOpen)
{ // {
serialPort.Open(); // serialPort.Open();
ICSharpCode.Core.LoggingService<DoControl>.Debug($"打开报警器串口成功,串口:{serialPort.PortName};波特率:{serialPort.BaudRate}"); // ICSharpCode.Core.LoggingService<DoControl>.Debug($"打开报警器串口成功,串口:{serialPort.PortName};波特率:{serialPort.BaudRate}");
} // }
}catch (Exception ex) // }catch (Exception ex)
{ // {
ICSharpCode.Core.LoggingService<DoControl>.Error($"报警器串口打开异常,串口:{serialPort.PortName};波特率:{serialPort.BaudRate};异常信息:{ex.Message}"); // ICSharpCode.Core.LoggingService<DoControl>.Error($"报警器串口打开异常,串口:{serialPort.PortName};波特率:{serialPort.BaudRate};异常信息:{ex.Message}");
} // }
} // }
/// <summary> // /// <summary>
/// 串口关闭 // /// 串口关闭
/// </summary> // /// </summary>
public void ComOff() // public void ComOff()
{ // {
if (serialPort.IsOpen) // if (serialPort.IsOpen)
{ // {
serialPort.Close(); // serialPort.Close();
} // }
} // }
//
/// <summary> // /// <summary>
/// DO1设备启动红灯 // /// DO1设备启动红灯
/// </summary> // /// </summary>
public void redLightOn() // public void redLightOn()
{ // {
DOControl(DOName.Red, DOOnOff.On); // DOControl(DOName.Red, DOOnOff.On);
} // }
//
/// <summary> // /// <summary>
/// DO2设备启动绿灯 // /// DO2设备启动绿灯
/// </summary> // /// </summary>
public void greenLightOn() // public void greenLightOn()
{ // {
DOControl(DOName.Green, DOOnOff.On); // DOControl(DOName.Green, DOOnOff.On);
} // }
//
/// <summary> // /// <summary>
/// DO3设备启动蜂鸣器 // /// DO3设备启动蜂鸣器
/// </summary> // /// </summary>
public void buzzerOn() // public void buzzerOn()
{ // {
DOControl(DOName.Buzzer, DOOnOff.On); // DOControl(DOName.Buzzer, DOOnOff.On);
} // }
//
/// <summary> // /// <summary>
/// DO1设备关闭红灯 // /// DO1设备关闭红灯
/// </summary> // /// </summary>
public void redLightOff() // public void redLightOff()
{ // {
DOControl(DOName.Red, DOOnOff.Off); // DOControl(DOName.Red, DOOnOff.Off);
} // }
//
/// <summary> // /// <summary>
/// DO2设备关闭绿灯 // /// DO2设备关闭绿灯
/// </summary> // /// </summary>
public void greenLightOff() // public void greenLightOff()
{ // {
DOControl(DOName.Green, DOOnOff.Off); // DOControl(DOName.Green, DOOnOff.Off);
} // }
//
/// <summary> // /// <summary>
/// DO3设备关闭蜂鸣器 // /// DO3设备关闭蜂鸣器
/// </summary> // /// </summary>
public void buzzerOff() // public void buzzerOff()
{ // {
DOControl(DOName.Buzzer, DOOnOff.On); // DOControl(DOName.Buzzer, DOOnOff.On);
} // }
//
/// <summary> // /// <summary>
/// 重置串口和DO状态 // /// 重置串口和DO状态
/// </summary> // /// </summary>
public void Reset() // public void Reset()
{ // {
SetOff(); // SetOff();
ComOff(); // ComOff();
} // }
//
/// <summary> // /// <summary>
/// 重置DO状态 // /// 重置DO状态
/// </summary> // /// </summary>
public void SetOff() // public void SetOff()
{ // {
foreach (DOName dOName in Enum.GetValues(typeof(DOName))) // foreach (DOName dOName in Enum.GetValues(typeof(DOName)))
{ // {
DOControl(dOName, DOOnOff.Off); // DOControl(dOName, DOOnOff.Off);
} // }
} // }
//
/// <summary> // /// <summary>
/// DO启停控制 // /// DO启停控制
/// 如果收到红灯亮的信号AlarmState会变为True; 收到红灯灭的信号AlarmState设置为false // /// 如果收到红灯亮的信号AlarmState会变为True; 收到红灯灭的信号AlarmState设置为false
/// </summary> // /// </summary>
/// <param name="dOName">DegitalOut接口名称</param> // /// <param name="dOName">DegitalOut接口名称</param>
/// <param name="dOOnOff">启停状态</param> // /// <param name="dOOnOff">启停状态</param>
public void DOControl(DOName dOName, DOOnOff dOOnOff) // public void DOControl(DOName dOName, DOOnOff dOOnOff)
{ // {
if(dOName.Equals(DOName.Red) && dOOnOff.Equals(DOOnOff.On)) // if(dOName.Equals(DOName.Red) && dOOnOff.Equals(DOOnOff.On))
{ // {
AlarmState = true; // AlarmState = true;
} // }
if(dOName.Equals(DOName.Red) && dOOnOff.Equals(DOOnOff.Off)) // if(dOName.Equals(DOName.Red) && dOOnOff.Equals(DOOnOff.Off))
{ // {
AlarmState = false; // AlarmState = false;
} // }
if (serialPort.IsOpen) // if (serialPort.IsOpen)
{ // {
serialPort.Write(new byte[] { 0xE3, 0x01, 0x09, (byte)dOName, (byte)dOOnOff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0, 12); // serialPort.Write(new byte[] { 0xE3, 0x01, 0x09, (byte)dOName, (byte)dOOnOff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0, 12);
} // }
else // else
{ // {
ComOn(); // ComOn();
serialPort.Write(new byte[] { 0xE3, 0x01, 0x09, (byte)dOName, (byte)dOOnOff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0, 12); // serialPort.Write(new byte[] { 0xE3, 0x01, 0x09, (byte)dOName, (byte)dOOnOff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0, 12);
} // }
} // }
//
/// <summary> // /// <summary>
/// 文本框传输数据控制COM5串口 // /// 文本框传输数据控制COM5串口
/// </summary> // /// </summary>
public void DOTestSend(string str) // public void DOTestSend(string str)
{ // {
//ComOn(); // //ComOn();
string[] strArray = str.Split(' '); // string[] strArray = str.Split(' ');
byte[] bytes = new byte[strArray.Length]; // byte[] bytes = new byte[strArray.Length];
for (int i = 0; i < bytes.Length; i++) // for (int i = 0; i < bytes.Length; i++)
{ // {
bytes[i] = Convert.ToByte(strArray[i], 16); // bytes[i] = Convert.ToByte(strArray[i], 16);
} // }
serialPort.Write(bytes, 0, bytes.Length); // serialPort.Write(bytes, 0, bytes.Length);
} // }
} // }
} // }
Loading…
Cancel
Save