using iWareCommon.Utils;
|
using iWareModel;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
|
namespace iWareSda
|
{
|
/// <summary>
|
/// 堆垛机实体类
|
/// </summary>
|
public static class Srm_CacheEntity
|
{
|
public static LogType curLogType = LogType.SrmSdaService;
|
|
#region 堆垛机地址
|
|
/// <summary>
|
/// 写入DB的地址(带分隔符)
|
/// </summary>
|
public static string W_DBHeaderWithSeparate = "540" + WareSdaStruct.PLCDBADDRESS_SEPARATE;
|
/// <summary>
|
/// 读取DB的地址(带分隔符)
|
/// </summary>
|
public static string R_DBHeaderWithSeparate = "541" + WareSdaStruct.PLCDBADDRESS_SEPARATE;
|
|
/// <summary>
|
/// 入库取货请求 DB的地址(带分隔符)
|
/// </summary>
|
public static string R_RKQH_DBHeaderWithSeparate = "221" + WareSdaStruct.PLCDBADDRESS_SEPARATE;
|
|
/// <summary>
|
/// 读取DB(报警专用)
|
/// </summary>
|
public static string R_DBHeader_Alert = "542";
|
|
|
private static SrmDBForWrite _dbBlockForWrite = new SrmDBForWrite()
|
{
|
//TODO:这里写配置的DB地址
|
#region 写入
|
|
W_HandShake = W_DBHeaderWithSeparate + "0",
|
W_SrmNo = W_DBHeaderWithSeparate + "2",
|
W_PalletType = W_DBHeaderWithSeparate + "4",
|
|
W_SourcePosX = W_DBHeaderWithSeparate + "6",
|
W_SourcePosY = W_DBHeaderWithSeparate + "8",
|
W_SourcePosZ = W_DBHeaderWithSeparate + "10",
|
W_DestinationPosX = W_DBHeaderWithSeparate + "12",
|
W_DestinationPosY = W_DBHeaderWithSeparate + "14",
|
W_DestinationPosZ = W_DBHeaderWithSeparate + "16",
|
|
W_Command = W_DBHeaderWithSeparate + "18",
|
W_EmergencyStop = W_DBHeaderWithSeparate + "20",
|
W_CancleAlarm = W_DBHeaderWithSeparate + "22",
|
W_TaskFinishConfirm = W_DBHeaderWithSeparate + "24",
|
|
|
W_Stb = W_DBHeaderWithSeparate + "30",
|
W_Ack = W_DBHeaderWithSeparate + "32",
|
|
W_TaskNo = W_DBHeaderWithSeparate + "34",
|
|
#endregion
|
};
|
private static SrmDBForRead _dbBlockForRead = new SrmDBForRead()
|
{
|
//TODO:这里写配置的DB地址
|
#region 读取
|
|
R_PickReqForInStore = R_RKQH_DBHeaderWithSeparate + "2.0",
|
|
R_HandShake = R_DBHeaderWithSeparate + "0",
|
R_SrmNo = R_DBHeaderWithSeparate + "2",
|
R_Mode = R_DBHeaderWithSeparate + "4",
|
R_Alarm = R_DBHeaderWithSeparate + "6",
|
R_LiftFull = R_DBHeaderWithSeparate + "8",
|
|
R_PosX = R_DBHeaderWithSeparate + "10",
|
R_PosY = R_DBHeaderWithSeparate + "12",
|
R_PosZ = R_DBHeaderWithSeparate + "14",
|
R_PosXmm = R_DBHeaderWithSeparate + "16",
|
R_PosYmm = R_DBHeaderWithSeparate + "20",
|
R_PosZmm = R_DBHeaderWithSeparate + "24",
|
|
R_PickFinish = R_DBHeaderWithSeparate + "28",
|
R_DeliveryFinish = R_DBHeaderWithSeparate + "30",
|
R_TaskFinish = R_DBHeaderWithSeparate + "32",
|
|
R_AlarmCode = R_DBHeaderWithSeparate + "34",
|
R_State = R_DBHeaderWithSeparate + "36",
|
|
R_ActualLane = R_DBHeaderWithSeparate + "38",
|
R_TaskNo = R_DBHeaderWithSeparate + "40",
|
|
#endregion
|
};
|
|
#endregion
|
|
private static List<SrmEntity> _deviceObjList = null;
|
private static object objLock = new object();
|
|
/// <summary>
|
/// 生成设备实体类
|
/// </summary>
|
public static List<SrmEntity> DeviceObjs
|
{
|
get
|
{
|
if (_deviceObjList == null)
|
{
|
lock (objLock)
|
{
|
if (_deviceObjList == null)
|
{
|
_deviceObjList = new List<SrmEntity>();
|
_deviceObjList.AddRange(GetSrmList());
|
}
|
}
|
}
|
return Srm_CacheEntity._deviceObjList;
|
}
|
set { Srm_CacheEntity._deviceObjList = value; }
|
}
|
|
public static T GetDeviceObj<T>(int deviceId)
|
{
|
var device = Srm_CacheEntity.DeviceObjs.FirstOrDefault(x => x.View.DeviceId == deviceId);
|
return (T)(Object)device;
|
}
|
|
|
/// <summary>
|
/// 实例化SrmEntity集合
|
/// </summary>
|
/// <returns></returns>
|
private static List<SrmEntity> GetSrmList()
|
{
|
List<SrmEntity> srmList = new List<SrmEntity>();
|
srmList.Add(GetSingleSrmEntity(WareSdaStruct.Srm1_Address, EDevice.一号堆垛机));
|
srmList.Add(GetSingleSrmEntity(WareSdaStruct.Srm2_Address, EDevice.二号堆垛机));
|
srmList.Add(GetSingleSrmEntity(WareSdaStruct.Srm3_Address, EDevice.三号堆垛机));
|
srmList.Add(GetSingleSrmEntity(WareSdaStruct.Srm4_Address, EDevice.四号堆垛机));
|
|
return srmList;
|
}
|
|
/// <summary>
|
/// 实例化单个SrmEntity
|
/// </summary>
|
/// <param name="_ip"></param>
|
/// <param name="device"></param>
|
/// <returns></returns>
|
private static SrmEntity GetSingleSrmEntity(string _ip, EDevice device)
|
{
|
SS7Param s7Param = new SS7Param()
|
{
|
cpu = WareSdaStruct.Srm_PLC_CpuType,
|
ip = _ip,
|
rack = WareSdaStruct.Srm_Rack,
|
slot = WareSdaStruct.Srm_Slot,
|
};
|
HslCommunicationParam hslCommunicationParam = new HslCommunicationParam()
|
{
|
cpu = WareSdaStruct.Srm_SiemensPLCS,
|
ip = _ip,
|
rack = WareSdaStruct.Srm_Rack,
|
slot = WareSdaStruct.Srm_Slot,
|
port = WareSdaStruct.Srm_Port
|
};
|
PLCService PLCService = PLCFactory.GetOPCService(WareSdaStruct.System_PlcServiceTypeEnum, s7Param, hslCommunicationParam);
|
SrmEntity srm = new SrmEntity("Srm" + (int)device, (int)device, _dbBlockForWrite, _dbBlockForRead, PLCService);
|
return srm;
|
}
|
}
|
}
|