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.

85 lines
2.9 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.BasicInfo;
namespace Mesnac.Action.Feeding.FeedingPlc
{
/// <summary>
/// 终止称量
/// </summary>
public class StopWeight : FeedingAction, IAction
{
public void Run(RuntimeParameter runtime)
{
base.LogDebug("终止称量...");
string msg = String.Empty;
#region 判断当班计划界面是否打开
if (PlanCommon.IsInit == false)
{
msg = "当班计划还为初始化,请先打开当班计划,再进行此操作!";
ShowMsg(msg, Language(1), MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
#endregion
if (MessageBox.Show("确认终止称量吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
{
return;
}
string recipeName = new RecipeData().GetCurrentRecipeInfo().RecipeName;
base.LogInfo("终止称量:" + recipeName);
if (StopWeight.ExecStopWeight())
{
ShowMsg("写入终止称量至PLC成功...", Language(1), MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
ShowMsg("写入终止称量至PLC失败...", Language(1), MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
/// <summary>
/// 把终止称量信号下传至PLC位运算位或2
/// </summary>
/// <returns>下传成功返回true否则返回false</returns>
public static bool ExecStopWeight()
{
try
{
int readword = 0;
//Mesnac.Equips.Factory.Instance.Read();
if (int.TryParse(PlcData.Instance.AbortWeight.EquipData.LastBeforeMathValue.FirstOrDefault().ToString(), out readword))
{
readword = readword | 2;
if (PlcData.Instance.PlcWriteByDataKey(PlcData.Instance.AbortWeight, new object[] { readword }))
{
ICSharpCode.Core.LoggingService.Debug("写入终止称量成功...");
return true;
}
}
ICSharpCode.Core.LoggingService.Warn("写入终止称量失败...");
return false;
}
catch (Exception ex)
{
ICSharpCode.Core.LoggingService.Error("写入终止称量失败:" + ex.Message, ex);
return false;
}
}
}
}