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 { /// /// 系统复位 /// public class SystemReset : FeedingAction, IAction { /// /// 系统复位关键业务 /// /// 成功返回1,失败返回其他值,密炼机有物料:-1,下传复位信号失败:-2,清除完成数失败:-3 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; } } /// /// 系统复位入口 /// /// 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("写入复位标志成功!"); } } }