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
{
///
/// 把开始称量信号下传到PLC
///
public class StartWeightToPlc : FeedingAction, IAction
{
///
/// 把开始称量信号下传到PLC 业务入口
///
///
public void Run(RuntimeParameter runtime)
{
base.RunIni(runtime);
bool IsSuccess = DownLoadStartWeight();
if (!IsSuccess)
{
throw new Exception("开始称量信息下载错误!");
}
}
///
/// 把开始称量信号下传到PLC
///
/// 成功返回true,失败返回false
public bool DownLoadStartWeight()
{
try
{
bool isSuccess = false;
int data = 0;
isSuccess = int.TryParse(PlcData.Instance.StartWeight.LastValue.ToInt().ToString(), out data);
//Mesnac.Equips.Factory.Instance.Read();
//isSuccess = int.TryParse(PlcData.Instance.StartWeight.EquipData.LastBeforeMathValue.FirstOrDefault().ToString(), out data);
if (isSuccess)
{
data = data | 1;
isSuccess = PlcData.Instance.PlcWriteByDataKey(PlcData.Instance.StartWeight, new object[] { data });
if (isSuccess)
{
ICSharpCode.Core.LoggingService.Debug("把开始称量信号下传到PLC成功!");
}
else
{
ICSharpCode.Core.LoggingService.Warn("把开始称量信号下传到PLC失败!");
}
}
else
{
ICSharpCode.Core.LoggingService.Debug("把开始称量信号下传到PLC失败!");
}
return isSuccess;
}
catch (Exception ex)
{
ICSharpCode.Core.LoggingService.Error("把开始称量信号下传到PLC失败:" + ex.Message, ex);
return false;
}
}
}
}