using iWareSda.Common;
|
|
using System;
|
using System.Collections.Generic;
|
using System.Threading;
|
|
namespace iWareSda
|
{
|
public class LineEntity : IDevice
|
{
|
public LineEntity()
|
{
|
this.View = new LineView();
|
}
|
|
#region OPC相关
|
|
/// <summary>
|
/// 线体 写的DB块
|
/// </summary>
|
public LineDBForWrite DBBlockForWrite { get; set; }
|
|
/// <summary>
|
/// 线体 读的DB块
|
/// </summary>
|
public LineDBForRead DBBlockForRead { get; set; }
|
|
/// <summary>
|
/// 读取PLC实例
|
/// </summary>
|
public PLCService plcService { get; set; }
|
|
/// <summary>
|
/// 视图对象
|
/// </summary>
|
public LineView View { get; set; }
|
|
|
#endregion
|
|
/// <summary>
|
/// 初始化数据
|
/// </summary>
|
public void InitData()
|
{
|
//IsConnected = false;
|
//IsHeartBeat = false;
|
|
}
|
public LineEntity(string DeviceName, int deviceId, LineDBForWrite _dbBlockForWrite, LineDBForRead _dbBlockForRead, PLCService _plcService)
|
{
|
this.View = new LineView();
|
this.View.DeviceName = DeviceName;
|
this.View.DeviceId = deviceId;
|
plcService = _plcService;
|
DBBlockForWrite = _dbBlockForWrite;
|
DBBlockForRead = _dbBlockForRead;
|
}
|
|
|
public void SetPropertyValueForRead()
|
{
|
var r_dbHeader = Line_CacheEntity.R_DBHeader;
|
var r_dbBlock = this.DBBlockForRead;
|
SdaHelper.SetPropertyValueForDB<LineDBForRead, LineView>(r_dbBlock, this.View, this.plcService, r_dbHeader);
|
//this.R_HeartBeat = Convert.ToInt16(this.S7.ReadValuePoint(r_dbHeader, this.DBBlockForRead.R_HeartBeat, typeof(short)));
|
//this.R_InOutWay = Convert.ToInt16(this.S7.ReadValuePoint(r_dbHeader, this.DBBlockForRead.R_InOutWay, typeof(short)));
|
//this.R_InOutStoreFlag = Convert.ToInt16(this.S7.ReadValuePoint(r_dbHeader, this.DBBlockForRead.R_InOutStoreFlag, typeof(short)));
|
//this.R_IsHasCargo = Convert.ToInt16(this.S7.ReadValuePoint(r_dbHeader, this.DBBlockForRead.R_IsHasCargo, typeof(short)));
|
//this.R_IsInPlace = Convert.ToBoolean(this.S7.ReadValuePoint(r_dbHeader, this.DBBlockForRead.R_IsInPlace, typeof(bool)));
|
//this.R_MouldNo = Convert.ToInt16(this.S7.ReadValuePoint(r_dbHeader, this.DBBlockForRead.R_MouldNo, typeof(short)));
|
}
|
|
public void SetPropertyValueForWrite()
|
{
|
var w_dbHeader = Line_CacheEntity.W_DBHeader;
|
var w_dbBlock = this.DBBlockForWrite;
|
SdaHelper.SetPropertyValueForDB<LineDBForWrite, LineView>(w_dbBlock, this.View, this.plcService, w_dbHeader);
|
//this.W_HeartBeat = Convert.ToInt16(this.S7.ReadValuePoint(w_dbHeader, this.DBBlockForWrite.W_HeartBeat, typeof(short)));
|
//this.W_IsHasCargo = Convert.ToInt16(this.S7.ReadValuePoint(w_dbHeader, this.DBBlockForWrite.W_IsHasCargo, typeof(short)));
|
//this.W_IsHasEmptyPlace = Convert.ToInt16(this.S7.ReadValuePoint(w_dbHeader, this.DBBlockForWrite.W_IsHasEmptyPlace, typeof(short)));
|
}
|
|
public bool IsHaveHeatBeat()
|
{
|
try
|
{
|
var r_dbHeader = Line_CacheEntity.R_DBHeader;
|
var r_dbBlock = this.DBBlockForRead;
|
short value = Convert.ToInt16(this.plcService.ReadValuePoint(r_dbHeader, r_dbBlock.R_HeartBeat, typeof(short)));
|
//约定 等待2秒
|
Thread.Sleep(2000);
|
short value_next = Convert.ToInt16(this.plcService.ReadValuePoint(r_dbHeader, r_dbBlock.R_HeartBeat, typeof(short)));
|
if (value == value_next)
|
{//没有心跳
|
return false;
|
}
|
else
|
{//有心跳
|
return true;
|
}
|
}
|
catch (Exception ex)
|
{
|
throw ex;
|
}
|
}
|
|
|
#region 获取当前报警信息
|
|
|
|
/// <summary>
|
/// 获取当前报警信息
|
/// </summary>
|
/// <returns></returns>
|
public System.Collections.Generic.List<string> GetAlertDatas()
|
{
|
List<string> db_warningList = new List<string>();
|
try
|
{
|
System.Collections.Generic.List<string> alertList = new System.Collections.Generic.List<string>();
|
|
string _dbValue;
|
var isHasAlert = false;
|
IDictionary<string, string> srmAlertDict = new Dictionary<string, string>();
|
//srmAlertDict = WareSdaStruct.lineAlertDict_1;
|
foreach (var item in srmAlertDict)
|
{
|
_dbValue = item.Key;
|
isHasAlert = Convert.ToBoolean(this.plcService.ReadValuePoint(Line_CacheEntity.R_DBHeader, item.Key, typeof(bool)));
|
if (isHasAlert)
|
{
|
db_warningList.Add(item.Value.Trim());
|
}
|
}
|
}
|
catch (Exception ex)
|
{
|
throw ex;
|
}
|
return db_warningList;
|
}
|
|
|
#endregion
|
}
|
}
|