|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
|
using System.Threading.Tasks;
|
|
|
using System.Reflection;
|
|
|
using ICSharpCode.Core;
|
|
|
|
|
|
namespace Mesnac.Action.ChemicalWeighing.ChemicalWeighingPlc
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// 料仓参数设置下传辅助类
|
|
|
/// </summary>
|
|
|
public class PlcStorageBinParaSetHelper
|
|
|
{
|
|
|
#region 料仓参数下传方法
|
|
|
|
|
|
/// <summary>
|
|
|
/// 下传料仓参数至PLC
|
|
|
/// </summary>
|
|
|
/// <param name="msgList">输出消息列表</param>
|
|
|
/// <param name="plcNodeName">PlcSchema.xml对应的节点名称</param>
|
|
|
/// <param name="entity">收集到的要下传的数据</param>
|
|
|
/// <param name="binNum">料仓号</param>
|
|
|
/// <returns>成功返回true,失败返回false</returns>
|
|
|
public static bool DownloadStorageBinPara(List<string> msgList, string plcNodeName, Entity.RT_Parameter entity,int binNum)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
#region 定义变量
|
|
|
|
|
|
string msg = String.Empty;
|
|
|
List<Int16> writeDataList = new List<Int16>();
|
|
|
PropertyInfo[] ps = typeof(Entity.RT_Parameter).GetProperties();
|
|
|
if (msgList == null)
|
|
|
{
|
|
|
msgList = new List<string>();
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 验证处理
|
|
|
|
|
|
PlcWriter writer = PlcSchemaHelper.Instance.GetPlcWriter(plcNodeName).FirstOrDefault();
|
|
|
if (writer == null)
|
|
|
{
|
|
|
msg = StringParser.Parse(ResourceService.GetString("Mesnac_Action_ChemicalWeighing_ChemicalWeighingPlc_PlcStorageBinParaSetHelper_RT_Parameter_msg10")); //料仓参数下传PLC失败:在PlcSchema.xml中没有RT_Parameter配置节!
|
|
|
msgList.Add(msg);
|
|
|
ICSharpCode.Core.LoggingService<PlcStorageBinParaSetHelper>.Error(msg);
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 获取PLC品牌名称,处理西门子与其他PLC差异
|
|
|
|
|
|
string equipBrand = Mesnac.Equips.Factory.Instance.GetEquipBrandByRunName(writer.EquipRunName);
|
|
|
writer.EquipBrand = equipBrand;
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 整理数据
|
|
|
|
|
|
if (entity != null)
|
|
|
{
|
|
|
foreach (PlcWriteItem item in writer.SchemaList)
|
|
|
{
|
|
|
item.ClearData();
|
|
|
item.EquipBrand = equipBrand; //设置PLC设备品牌
|
|
|
foreach (PropertyInfo pi in ps)
|
|
|
{
|
|
|
if (item.DataFieldName == pi.Name)
|
|
|
{
|
|
|
item.SetValue = pi.GetValue(entity, null);
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
writeDataList.AddRange(item.WriteData());
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
foreach (PlcWriteItem item in writer.SchemaList)
|
|
|
{
|
|
|
item.ClearData();
|
|
|
item.EquipBrand = equipBrand; //设置PLC设备品牌
|
|
|
writeDataList.AddRange(item.WriteData());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 下传数据
|
|
|
|
|
|
object[] buff = new object[writeDataList.Count];
|
|
|
Array.Copy(writeDataList.ToArray(), buff, buff.Length);
|
|
|
|
|
|
ICSharpCode.Core.LoggingService<PlcStorageBinParaSetHelper>.Debug(String.Format("开始下传" + binNum + "号料仓的参数"));
|
|
|
if (!BasePlcHelper.Instance.PlcWriteByRunName(writer.EquipRunName, buff))
|
|
|
{
|
|
|
msg = StringParser.Parse(ResourceService.GetString("Mesnac_Action_ChemicalWeighing_ChemicalWeighingPlc_PlcStorageBinParaSetHelper_RT_Parameter_msg2")); //下传料仓参数失败!
|
|
|
msgList.Add(msg);
|
|
|
ICSharpCode.Core.LoggingService<PlcStorageBinParaSetHelper>.Error(msg);
|
|
|
return false;
|
|
|
}
|
|
|
ICSharpCode.Core.LoggingService<PlcStorageBinParaSetHelper>.Debug(String.Format("下传料仓参数完毕!"));
|
|
|
#endregion
|
|
|
|
|
|
return true;
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
msgList.Add(ex.Message);
|
|
|
ICSharpCode.Core.LoggingService<PlcStorageBinParaSetHelper>.Error(ex.Message, ex);
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
}
|
|
|
}
|