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.

75 lines
2.6 KiB
C#

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>
/// 把开始称量信号下传到PLC
/// </summary>
public class StartWeightToPlc : FeedingAction, IAction
{
/// <summary>
/// 把开始称量信号下传到PLC 业务入口
/// </summary>
/// <param name="runtime"></param>
public void Run(RuntimeParameter runtime)
{
base.RunIni(runtime);
bool IsSuccess = DownLoadStartWeight();
if (!IsSuccess)
{
throw new Exception("开始称量信息下载错误!");
}
}
/// <summary>
/// 把开始称量信号下传到PLC
/// </summary>
/// <returns>成功返回true失败返回false</returns>
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;
}
}
}
}