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.

422 lines
14 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.Linq;
using System.Text;
using Mesnac.Action.Feeding.BasicInfo;
namespace Mesnac.Action.Feeding.FinishBatch
{
/// <summary>
/// PLC每车报表存盘数据区解析类
/// </summary>
public class SaveDataPerLotHandler
{
#region 字段定义
private int _nowche; //密炼完成次数
private int _rubFinshNum; //胶料完成次数
private int _cBFinshNum; //炭黑完成次数
private int _fLFinshNum; //粉料完成次数
private int _oilFinshNum; //油1完成次数
private byte _rubStatus; //胶料秤称量状态
private byte _cBStatus; //炭黑秤称量状态
private byte _fLStatus; //粉料秤称量状态
private byte _oilStatus; //油料秤称量状态
private byte _mixStatus; //密炼机状态
private double _powerOpenDoor; //排胶功率
private double _energyOpenDoor; //排胶能量
private double _tempOpenDoor; //排胶温度
private int _timeOpenDoor; //排胶时间
private int _startYear; //密炼开始年份
private int _startMonth; //密炼开始月份
private int _startDay; //密炼开始天
private int _startHour; //密炼开始小时
private int _startMinute; //密炼开始分钟
private int _startSecond; //密炼开始秒
private int _done_allrtime; //炼胶总时间
private int _rubTime; //加胶时间
private int _cBTime; //加炭黑时间
private int _oilTime; //加油1时间
private int _oil2FinshNum; //油2完成数
private byte _oil2Status; //油秤2称量状态
private int _oil2Time; //加油2时间
private int _flTime; //加粉料时间
private string _strTime; //日期时间格式yyyy-MM-dd HH:mm:ss
private static int _recipeTime; //实时保存配方时间
#endregion
#region 构造方法
/// <summary>
/// 构造方法
/// </summary>
public SaveDataPerLotHandler() { this.ParseSaveDataPerLotFromPlc(); }
#endregion
#region 属性定义
/// <summary>
/// 密炼完成次数
/// </summary>
public int Nowche
{
get { return _nowche; }
set { _nowche = value; }
}
/// <summary>
/// 胶料完成次数
/// </summary>
public int RubFinshNum
{
get { return _rubFinshNum; }
set { _rubFinshNum = value; }
}
/// <summary>
/// 炭黑完成次数
/// </summary>
public int CBFinshNum
{
get { return _cBFinshNum; }
set { _cBFinshNum = value; }
}
/// <summary>
/// 粉料完成次数
/// </summary>
public int FLFinshNum
{
get { return _fLFinshNum; }
set { _fLFinshNum = value; }
}
/// <summary>
/// 油料1完成次数
/// </summary>
public int OilFinshNum
{
get { return _oilFinshNum; }
set { _oilFinshNum = value; }
}
/// <summary>
/// 胶料秤称量状态
/// </summary>
public byte RubStatus
{
get { return _rubStatus; }
set { _rubStatus = value; }
}
/// <summary>
/// 炭黑秤称量状态
/// </summary>
public byte CBStatus
{
get { return _cBStatus; }
set { _cBStatus = value; }
}
/// <summary>
/// 粉料秤称量状态
/// </summary>
public byte FLStatus
{
get { return _fLStatus; }
set { _fLStatus = value; }
}
/// <summary>
/// 油料秤1称量状态
/// </summary>
public byte OilStatus
{
get { return _oilStatus; }
set { _oilStatus = value; }
}
/// <summary>
/// 密炼机状态
/// </summary>
public byte MixStatus
{
get { return _mixStatus; }
set { _mixStatus = value; }
}
/// <summary>
/// 炼胶时间
/// </summary>
public int TimeOpenDoor
{
get { return _timeOpenDoor; }
set { _timeOpenDoor = value; }
}
/// <summary>
/// 排胶温度
/// </summary>
public double TempOpenDoor
{
get { return _tempOpenDoor; }
set { _tempOpenDoor = value; }
}
/// <summary>
/// 排胶功率
/// </summary>
public double PowerOpenDoor
{
get { return _powerOpenDoor; }
set { _powerOpenDoor = value; }
}
/// <summary>
/// 排胶能量
/// </summary>
public double EnergyOpenDoor
{
get { return _energyOpenDoor; }
set { _energyOpenDoor = value; }
}
/// <summary>
/// 密炼开始年份
/// </summary>
public int StartYear
{
get { return _startYear; }
set { _startYear = value; }
}
/// <summary>
/// 密炼开始月份
/// </summary>
public int StartMonth
{
get { return _startMonth; }
set { _startMonth = value; }
}
/// <summary>
/// 密炼开始天
/// </summary>
public int StartDay
{
get { return _startDay; }
set { _startDay = value; }
}
/// <summary>
/// 密炼开始小时
/// </summary>
public int StartHour
{
get { return _startHour; }
set { _startHour = value; }
}
/// <summary>
/// 密炼开始分钟
/// </summary>
public int StartMinute
{
get { return _startMinute; }
set { _startMinute = value; }
}
/// <summary>
/// 密炼开始秒
/// </summary>
public int StartSecond
{
get { return _startSecond; }
set { _startSecond = value; }
}
/// <summary>
/// 炼胶总时间(卸料门关到位时刻)
/// </summary>
public int Done_allrtime
{
get { return _done_allrtime; }
set { _done_allrtime = value; }
}
/// <summary>
/// 加胶时间
/// </summary>
public int RubTime
{
get { return _rubTime; }
set { _rubTime = value; }
}
/// <summary>
/// 加炭黑时间
/// </summary>
public int CBTime
{
get { return _cBTime; }
set { _cBTime = value; }
}
/// <summary>
/// 加油1时间
/// </summary>
public int OilTime
{
get { return _oilTime; }
set { _oilTime = value; }
}
/// <summary>
/// 油2完成数
/// </summary>
public int Oil2FinshNum
{
get { return _oil2FinshNum; }
set { _oil2FinshNum = value; }
}
/// <summary>
/// 油秤2称量状态
/// </summary>
public byte Oil2Status
{
get { return _oil2Status; }
set { _oil2Status = value; }
}
/// <summary>
/// 加油2时间
/// </summary>
public int Oil2Time
{
get { return _oil2Time; }
set { _oil2Time = value; }
}
/// <summary>
/// 加粉料时间
/// </summary>
public int FlTime
{
get { return _flTime; }
set { _flTime = value; }
}
/// <summary>
/// 密开始时间日期时间格式yyyy-MM-dd HH:mm:ss
/// </summary>
public string StrTime
{
get { return _strTime; }
set { _strTime = value; }
}
/// <summary>
/// 用于实时保存配方时间
/// </summary>
public static int RecipeTime
{
get { return SaveDataPerLotHandler._recipeTime; }
set { SaveDataPerLotHandler._recipeTime = value; }
}
#endregion
#region 解析方法
/// <summary>
/// 解析方法
/// </summary>
private void ParseSaveDataPerLotFromPlc()
{
object saveDataPerLot = PlcData.Instance.SaveDataPerLot.LastValue.ToObject();
if (saveDataPerLot == null)
{
ICSharpCode.Core.LoggingService.Warn("从PLC中获取每车存盘SaveDataPerLot数据失败_NULL");
return;
}
if (!(saveDataPerLot is object[]))
{
ICSharpCode.Core.LoggingService.Warn("从PLC中获取每车存盘SaveDataPerLot数据失败_Not Array");
return;
}
object[] values = saveDataPerLot as object[];
if (values.Length != 28)
{
ICSharpCode.Core.LoggingService.Warn("从PLC中获取每车存盘SaveDataPerLot数据失败_长度不争取应该为28个字");
return;
}
this._nowche = this.ToInt(values[0]); //密炼完成次数
this._rubFinshNum = this.ToInt(values[1]); //胶料完成次数
this._cBFinshNum = this.ToInt(values[2]); //炭黑完成次数
this._fLFinshNum = this.ToInt(values[3]); //粉料完成数
this._oilFinshNum = this.ToInt(values[4]); //油1完成次数
this._rubStatus = this.ToByte(values[5]); //胶料秤称量状态
this._cBStatus = this.ToByte(values[6]); //炭黑秤称量状态
this._fLStatus = this.ToByte(values[7]); //粉料秤称量状态
this._oilStatus = this.ToByte(values[8]); //油1秤称量状态
this._mixStatus = this.ToByte(values[9]); //密炼机状态
this._timeOpenDoor = this.ToInt(values[10]); //炼胶时间(卸料门开到位时刻)
this._tempOpenDoor = this.ToDouble(values[11]) / 10.0; //排胶温度
this._powerOpenDoor = this.ToDouble(values[12]); //排胶功率
this._energyOpenDoor = this.ToDouble(values[13]) / 10.0; //排胶能量
this._startYear = this.ToInt(values[14]); //密炼开始年份
this._startMonth = this.ToInt(values[15]); //密炼开始月份
this._startDay = this.ToInt(values[16]); //密炼开始天
this._startHour = this.ToInt(values[17]); //密炼开始小时
this._startMinute = this.ToInt(values[18]); //密炼开始分钟
this._startSecond = this.ToInt(values[19]); //密炼开始秒
this._done_allrtime = this.ToInt(values[20]); //炼胶总时间(卸料门关到位时刻)
this._rubTime = this.ToInt(values[21]); //加胶时间
this._cBTime = this.ToInt(values[22]); //一次加炭黑
this._oilTime = this.ToInt(values[23]); //1号油秤加油时间
this._oil2FinshNum = this.ToInt(values[24]); //油2完成数
this._oil2Status = this.ToByte(values[25]); //油秤2称量状态
this._oil2Time = this.ToInt(values[26]); //2号油秤加油时间
this._flTime = this.ToInt(values[27]); //加粉料时间
this._strTime = String.Format("{0:D4}-{1:D2}-{2:D2} {3:D2}:{4:D2}:{5:D2}", this._startYear, this._startMonth, this._startDay, this._startHour, this._startMinute, this._startSecond);
//DateTime nowtime = DateTime.Now;
//DateTime mixtime = Convert.ToDateTime(_strTime);
ICSharpCode.Core.LoggingService.Debug("=================================================");
ICSharpCode.Core.LoggingService.Debug("密炼开始时间(PLC原始值)" + this._strTime);
DateTime strTime = DateTime.Now;
if (DateTime.TryParse(this._strTime, out strTime))
{
if ((DateTime.Now - Convert.ToDateTime(this._strTime)).TotalSeconds > 300 || (DateTime.Now - Convert.ToDateTime(this._strTime)).TotalSeconds < 0)
{
this._strTime = String.Format("{0:yyyy-MM-dd HH:mm:ss}", DateTime.Now.AddSeconds(-this._done_allrtime));
}
}
else
{
this._strTime = String.Format("{0:yyyy-MM-dd HH:mm:ss}", DateTime.Now.AddSeconds(-this._done_allrtime));
ICSharpCode.Core.LoggingService.Warn("PLC密炼开始时间无法转换为日期格式!");
}
ICSharpCode.Core.LoggingService.Debug("密炼开始时间(处理后的值)" + this._strTime);
ICSharpCode.Core.LoggingService.Debug("=================================================");
}
private byte ToByte(object value)
{
byte result = 0;
if (value != null && value != System.DBNull.Value)
{
byte.TryParse(value.ToString(), out result);
}
return result;
}
private int ToInt(object value)
{
int result = 0;
if (value != null && value != System.DBNull.Value)
{
int.TryParse(value.ToString(), out result);
}
return result;
}
private double ToDouble(object value)
{
double result = 0;
if (value != null && value != System.DBNull.Value)
{
double.TryParse(value.ToString(), out result);
}
return result;
}
#endregion
}
}