You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

99 lines
3.5 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using System;
using System.Collections.Generic;
using System.Net.NetworkInformation;
using System.Text;
using System.Linq;
using System.Data;
using System.Threading;
using Mesnac.Action.Base;
using Mesnac.Controls.Base;
using System.Windows.Forms;
using Mesnac.Codd.Session;
using System.IO;
using Mesnac.Action.Feeding.Qingquan.BasicInfo;
namespace Mesnac.Action.Feeding.Qingquan.FeedingPlc
{
/// <summary>
/// 系统复位
/// </summary>
public class SystemReset : FeedingAction, IAction
{
/// <summary>
/// 系统复位关键业务
/// </summary>
/// <returns>成功返回1失败返回其他值密炼机有物料-1下传复位信号失败-2清除完成数失败-3</returns>
public int ExecuteReset()
{
try
{
int iExistsMaterial = 0;
//if (int.TryParse(PlcData.Instance.HasMaterial.LastValue.ToInt().ToString(), out iExistsMaterial))
if (PlcData.Instance.CurrentMixingTime.LastValue.ToInt() == 0)
{
iExistsMaterial = iExistsMaterial & 0x0001; //取最低位
if (iExistsMaterial == 1)
{
return -1;
}
int sysReset = 0;
if (int.TryParse(PlcData.Instance.SysReset.LastValue.ToInt().ToString(), out sysReset))
{
sysReset = sysReset | 0x01; //或1进行复位操作
if (!PlcData.Instance.PlcWriteByDataKey(PlcData.Instance.SysReset, new object[] { sysReset }))
{
return -2;
}
//if (!PlcData.Instance.PlcWriteByDataKey(PlcData.Instance.MixingFinishedCountReset, new object[] { 0 }))
//{
// return -3;
//}
ICSharpCode.Core.LoggingService.Debug("系统复位成功!");
return 1;
}
else
{
ICSharpCode.Core.LoggingService.Warn("系统复位失败:正在密炼不允许复位!");
return 0;
}
}
else
{
ICSharpCode.Core.LoggingService.Warn("系统复位失败:从PLC读取HasMaterial失败!");
return 0;
}
}
catch (Exception ex)
{
ICSharpCode.Core.LoggingService.Error("系统复位失败:" + ex.Message, ex);
return 0;
}
}
/// <summary>
/// 系统复位入口
/// </summary>
/// <param name="runtime"></param>
public void Run(RuntimeParameter runtime)
{
base.LogDebug("系统复位...");
if (MessageBox.Show("确认系统复位吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
{
return;
}
int result = ExecuteReset();
if (result == -1)
{
MessageBox.Show("存在物料,不能进行复位!");
return;
}
if (result == -2)
{
MessageBox.Show("写入复位标志失败!");
return;
}
MessageBox.Show("写入复位标志成功!");
}
}
}