|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using ICSharpCode.Core;
|
|
|
|
|
using Mesnac.Equips;
|
|
|
|
|
using Mesnac.Codd.Session;
|
|
|
|
|
using Mesnac.Controls.Base;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Timers;
|
|
|
|
|
|
|
|
|
|
namespace Mesnac.Action.ChemicalWeighing.FinishBatch
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 生产管理-后台业务-生产数据存盘业务服务类
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class FinishBatchService
|
|
|
|
|
{
|
|
|
|
|
#region 字段定义
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 运行状态,true:已运行,false:未运行
|
|
|
|
|
/// </summary>
|
|
|
|
|
private bool runState = false;
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
bool flag = true;
|
|
|
|
|
bool flag2 = true;
|
|
|
|
|
#region 单例实现
|
|
|
|
|
|
|
|
|
|
private static FinishBatchService _instance = null;
|
|
|
|
|
|
|
|
|
|
private FinishBatchService()
|
|
|
|
|
{
|
|
|
|
|
System.Timers.Timer timer = new System.Timers.Timer(1000);
|
|
|
|
|
timer.Elapsed += new ElapsedEventHandler(ReadData);
|
|
|
|
|
timer.AutoReset = true;
|
|
|
|
|
timer.Enabled = true;
|
|
|
|
|
timer.Start();
|
|
|
|
|
|
|
|
|
|
System.Timers.Timer timer2 = new System.Timers.Timer(1000);
|
|
|
|
|
timer2.Elapsed += new ElapsedEventHandler(UpdatePlanStateData);
|
|
|
|
|
timer2.AutoReset = true;
|
|
|
|
|
timer2.Enabled = true;
|
|
|
|
|
timer2.Start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static FinishBatchService Instance
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
lock (String.Empty)
|
|
|
|
|
{
|
|
|
|
|
if (_instance == null)
|
|
|
|
|
{
|
|
|
|
|
_instance = new FinishBatchService();
|
|
|
|
|
}
|
|
|
|
|
return _instance;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 启动服务
|
|
|
|
|
|
|
|
|
|
public void Start()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (this.runState)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
lock (String.Empty)
|
|
|
|
|
{
|
|
|
|
|
//Mesnac.Equips.Factory.Instance.SetMinHZReadDataEvent(ReadData);
|
|
|
|
|
|
|
|
|
|
//System.Timers.Timer timer = new System.Timers.Timer(3000);
|
|
|
|
|
//timer.Elapsed += new ElapsedEventHandler(StartServer1);
|
|
|
|
|
//timer.AutoReset = true;
|
|
|
|
|
//timer.Enabled = true;
|
|
|
|
|
//timer.Start();
|
|
|
|
|
this.runState = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch(Exception ex)
|
|
|
|
|
{
|
|
|
|
|
ICSharpCode.Core.LoggingService<FinishBatchService>.Error("自动更新计划状态服务异常:" + ex.Message, ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 停止服务
|
|
|
|
|
|
|
|
|
|
public void Stop()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (!this.runState)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
lock (String.Empty)
|
|
|
|
|
{
|
|
|
|
|
ICSharpCode.Core.LoggingService<FinishBatchService>.Debug("开始停止生产数据存盘服务...");
|
|
|
|
|
//Mesnac.Equips.Factory.Instance.ClearMinHZReadDataEvent(ReadData);
|
|
|
|
|
ICSharpCode.Core.LoggingService<FinishBatchService>.Debug("停止生产数据存盘服务完毕!");
|
|
|
|
|
this.runState = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
ICSharpCode.Core.LoggingService<FinishBatchService>.Error("停止生产数据存盘业务服务异常:" + ex.Message, ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 事件处理 普力通物料下传2023-06-12
|
|
|
|
|
//private void ReadData(object sender, Mesnac.Equips.ReadEventArgs e)
|
|
|
|
|
private void ReadData(object sender, ElapsedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (flag)
|
|
|
|
|
{
|
|
|
|
|
flag = false;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
lock (String.Empty)
|
|
|
|
|
{
|
|
|
|
|
#region 更新溶剂称量计划状态地磅
|
|
|
|
|
|
|
|
|
|
PlcWeighbridgePlanHelper.UpdateWeighbridge1PlanData();
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
ICSharpCode.Core.LoggingService<FinishBatchService>.Error(ex.Message, ex);
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
GC.Collect();
|
|
|
|
|
flag=true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 地磅2
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void UpdatePlanStateData(object sender, ElapsedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (flag2)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
flag2 = false;
|
|
|
|
|
lock (String.Empty)
|
|
|
|
|
{
|
|
|
|
|
PlcWeighbridgePlanHelper.UpdateWeighbridge2PlanData();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
ICSharpCode.Core.LoggingService<FinishBatchService>.Error(ex.Message, ex);
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
GC.Collect();
|
|
|
|
|
flag2 = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|