This commit is contained in:
13118993771@163.com
2022-04-01 17:03:54 +08:00
commit 5e9d0f1e2d
1528 changed files with 1474439 additions and 0 deletions

9
Common/BaseMessage.cs Normal file
View File

@@ -0,0 +1,9 @@
using System;
namespace Glorysoft.SECS.EQP.Common
{
[Serializable]
public class BaseMessage
{
}
}

74
Common/Configuration.cs Normal file
View File

@@ -0,0 +1,74 @@
#region << >>
/*----------------------------------------------------------------
* 创建者Hupe
* 创建时间2021/11/15 15:15:17
* 版本V1.0.0
* 描述:
*
* ----------------------------------------------------------------
* 修改人:
* 时间:
* 修改说明:
*
* 版本V1.0.1
*----------------------------------------------------------------*/
#endregion << >>
using ARI.EAP.HOST.MQ;
using Glorysoft.SECS.EQP;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;
namespace ARI.EAP.HOST.SRD
{
/// <summary>
/// Configuration 的摘要说明
/// xml配置文件的实体类
/// </summary>
[Serializable]
public class Configuration
{
[XmlIgnore]
public static Configuration conf { get; set; }
public ConnectSetting connectSetting { get; set; }
public MQConnectionCfg mQConnectionCfg { get; set; }
public HttpConfiguration httpConfiguration { get; set; }
public ScenarioCollection scenarioCollection { get; set; }
public CommandContentCollection commandContentCollection { get; set; }
public SRDConfiguration sRDConfiguration { get; set; }
public Configuration()
{
connectSetting = new ConnectSetting();
mQConnectionCfg = new MQConnectionCfg();
httpConfiguration = new HttpConfiguration();
scenarioCollection = new ScenarioCollection();
sRDConfiguration = new SRDConfiguration();
commandContentCollection = new CommandContentCollection();
}
}
[Serializable]
public class ConnectSetting
{
[XmlAttribute]
public string name { get; set; }
[XmlAttribute]
public string deviceId { get; set; }
[XmlAttribute]
public string remoteIp { get; set; }
[XmlAttribute]
public string remotePort { get; set; }
}
[Serializable]
public class HttpConfiguration
{
public string heartBitUrl { get; set; }
public string fileDownloadUrl { get; set; }
public string contentType { get; set; }
}
}

42
Common/Constants.cs Normal file
View File

@@ -0,0 +1,42 @@
#region << >>
/*----------------------------------------------------------------
* 创建者hupe
* 创建时间2021/12/24 13:54:03
* 版本V1.0.0
* 描述:
*
* ----------------------------------------------------------------
* 修改人:
* 时间:
* 修改说明:
*
* 版本V1.0.1
*----------------------------------------------------------------*/
#endregion << >>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ARI.EAP.HOST.Common
{
/// <summary>
/// Constants 的摘要说明
/// 系统常量描述
/// </summary>
public static class Constants
{
public const string eapName = "ACOAT_01";
public const string configuerPath = "Configuration/" + eapName + ".xml";
}
public struct ConnectState
{
public static readonly string connected = "Connected";
public static readonly string disconnected = "Disconnected";
}
}

View File

@@ -0,0 +1,48 @@
#region << >>
/*----------------------------------------------------------------
* 创建者13118
* 创建时间2022/3/28 13:48:16
* 版本V1.0.0
* 描述:
*
* ----------------------------------------------------------------
* 修改人:
* 时间:
* 修改说明:
*
* 版本V1.0.1
*----------------------------------------------------------------*/
#endregion << >>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ARI.EAP.HOST.Common.Entity
{
/// <summary>
/// 下载文件接口传参实体类
/// </summary>
[Serializable]
public class DownLoadFileParam
{
public long attachmentId { get; set; }
public string fileName { get; set; }
public string type { get; set; }
//
// 摘要:
// downloadType:下载方式,"0"为预览,"1"为下载
public DownLoadFileParam(long fileId, string fileName,string downloadType)
{
this.attachmentId = fileId;
this.fileName = fileName;
this.type = downloadType;
}
}
}

31
Common/EquipmentStatus.cs Normal file
View File

@@ -0,0 +1,31 @@
using Glorysoft.SECS.EQP.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace ARI.EAP.HOST.Common
{
public static class EquipmentStatus
{
public static string S5F3 = "AlarmEnable";
public static ushort SpoolingFlag = 0;
public static bool MQstate = false;
public static Dictionary<string, IEventHandler> EventHandlers;
public static ushort commandCount = 0;
public static bool initStatus = false;
static EquipmentStatus()
{
EventHandlers = new Dictionary<string, IEventHandler>();
foreach (Type item in MethodBase.GetCurrentMethod().DeclaringType.Assembly.GetTypes())
{
if (item.IsClass && item.GetInterface(nameof(IEventHandler)) != null)
{
EventHandlers.Add(item.Name, Activator.CreateInstance(item) as IEventHandler);
}
}
}
}
}

17
Common/IEventHandler.cs Normal file
View File

@@ -0,0 +1,17 @@
// ********************************************************************************
// 文件名字: IEventHandler
// 文件描述: IEventHandler
// 开发人员: Hupe
// 创建时间: 2021/10/14 16:22
// ********************************************************************************
using ARI.EAP.HOST.SRD;
using Glorysoft.SECSwell;
using System.Collections.Generic;
namespace Glorysoft.SECS.EQP.Common
{
public interface IEventHandler
{
void Execute(SECSTransaction trans, EVENT even);
}
}

View File

@@ -0,0 +1,18 @@
// ********************************************************************************
// 文件名字: ISECSMessageHandler
// 文件描述: ISECSMessageHandler
// 开发人员: Michael
// 创建时间: 2019/11/8 0:08
//
// 更新历史:
// + 创建 ISECSMessageHandler.cs 文件. by Michael @2019/11/8 0:08
// ********************************************************************************
using Glorysoft.SECSwell;
namespace Glorysoft.SECS.EQP.Common
{
public interface ISECSMessageHandler
{
void Execute(SECSContext context, SECSTransaction trans, SECSErrors err, string errmsg);
}
}

90
Common/MESHeartBit.cs Normal file
View File

@@ -0,0 +1,90 @@
#region << >>
/*----------------------------------------------------------------
* 创建者13118
* 创建时间2022/3/17 15:08:35
* 版本V1.0.0
* 描述:
*
* ----------------------------------------------------------------
* 修改人:
* 时间:
* 修改说明:
*
* 版本V1.0.1
*----------------------------------------------------------------*/
#endregion << >>
using ARI.EAP.HOST.SRD;
using ARI.EAP.HOST.Utilities;
using Glorysoft.SECS.EQP.Utilities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Timers;
namespace ARI.EAP.HOST.Common
{
/// <summary>
/// MESHeartBit 的摘要说明
/// 提供与MES的连接心跳
/// </summary>
public class MESHeartBit
{
private Timer timer;
private string url = Configuration.conf.httpConfiguration.heartBitUrl;
public MESHeartBit()
{
timer = new Timer(60000);
timer.Elapsed += new ElapsedEventHandler(Method);
timer.AutoReset = true;
timer.Enabled = true;
}
public void Method(object source, ElapsedEventArgs e)
{
string httpContent = SECSUtil.ToJson<MESHeartBitParam>(new MESHeartBitParam());
HttpUtils.sentPOST(url,httpContent);
}
public void Method()
{
string httpContent = SECSUtil.ToJson<MESHeartBitParam>(new MESHeartBitParam());
HttpUtils.sentPOST(url, httpContent);
}
public void MethodClose()
{
MESHeartBitParam mESHeartBitParam = new MESHeartBitParam();
mESHeartBitParam.eapStatus = "stop";
mESHeartBitParam.connectStatus = "disconnected";
mESHeartBitParam.mqStatus = "disconnected";
string httpContent = SECSUtil.ToJson<MESHeartBitParam>(mESHeartBitParam);
HttpUtils.sentPOST(url, httpContent);
}
}
[Serializable]
public class MESHeartBitParam
{
public string connectStatus { get; set; }
public string deviceId { get; set; }
public string eapStatus { get; set; }
public string equipmentName { get; set; }
public string ip { get; set; }
public string mqStatus { get; set; }
public string port { get; set; }
public MESHeartBitParam()
{
this.deviceId = Configuration.conf.connectSetting.deviceId;
this.equipmentName = Configuration.conf.connectSetting.name;
this.ip = Configuration.conf.connectSetting.remoteIp;
this.port = Configuration.conf.connectSetting.remotePort;
this.connectStatus = Global.MF.ConnectStatus.Text;
this.mqStatus = Global.MF.MQStatus.Text;
this.eapStatus = "start";
}
}
}

236
Common/SECSContext.cs Normal file
View File

@@ -0,0 +1,236 @@
// ********************************************************************************
// 文件名字: SECSContext
// 文件描述: SECSContext
// 开发人员: Michael
// 创建时间: 2019/11/8 0:08
//
// 更新历史:
// + 创建 SECSContext.cs 文件. by Michael @2019/11/8 0:08
// ********************************************************************************
using ARI.EAP.HOST;
using Glorysoft.SECS.EQP.Utilities;
using Glorysoft.SECSwell;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
namespace Glorysoft.SECS.EQP.Common
{
public class SECSContext
{
public string Name { get; set; }
public short DeviceID { get; set; } = 0;
public eHSMS_CONNECT_MODE ConnectionMode { get; set; } = eHSMS_CONNECT_MODE.ACTIVE;
public string RemoteIPAddress { get; set; } = "127.0.0.1";
public int RemoteIPPort { get; set; } = 6000;
public string LocalIPAddress { get; set; } = "127.0.0.1";
public int LocalIPPort { get; set; } = 20002;
public bool AsciiValueAutoFillSpace { get; set; } = true;
public int T1 { get; set; } = 1;
public int T2 { get; set; } = 2;
public int T3 { get; set; } = 45;
public int T4 { get; set; } = 4;
public int T5 { get; set; } = 10;
public int T6 { get; set; } = 6;
public int T7 { get; set; } = 10;
public int T8 { get; set; } = 5;
public eLOG_LEVEL LogLevel { get; set; } = eLOG_LEVEL.DEBUG;
public string LogPath { get; set; } = @"logs\";
public string SECSLibraryFile { get; set; } = @"Configuration\SECSLibrary.xml";
public bool IsConnected => Port != null && Port.Connected;
private readonly SECSwell.SECSPort Port;
private static Dictionary<string, ISECSMessageHandler> Handlers;
public SECSContext(string name, short deviceId, string remoteIPAddress, int remoteIPPort)
{
LogPath = string.Format(@"{0}{1}\", LogPath, name);
Name = name;
DeviceID = deviceId;
RemoteIPAddress = remoteIPAddress;
RemoteIPPort = remoteIPPort;
SECSwell.SECSPort.SetAsciiValueAutoFillSpace = AsciiValueAutoFillSpace;
Port = new SECSwell.SECSPort(Name)
{
Name = Name,
DeviceID = DeviceID,
LogPath = LogPath,
LogLevel = LogLevel
};
HSMSParameters parameters = new HSMSParameters
{
DeviceID = DeviceID,
ConnectionMode = ConnectionMode,
RemoteIP = RemoteIPAddress,
RemotePort = RemoteIPPort,
LocalIP = LocalIPAddress,
LocalPort = LocalIPPort,
T3 = T3,
T5 = T5,
T6 = T6,
T7 = T7,
T8 = T8
};
Port.Library.Load(SECSLibraryFile);
Port.HsmsParameters = parameters;
Port.IsS9FxCheck = false;
Port.OnSECSEvent += OnRecieved;
Handlers = new Dictionary<string, ISECSMessageHandler>();
foreach (Type item in MethodBase.GetCurrentMethod().DeclaringType.Assembly.GetTypes())
{
if (item.IsClass && item.GetInterface(nameof(ISECSMessageHandler)) != null)
{
Handlers.Add(item.Name, Activator.CreateInstance(item) as ISECSMessageHandler);
}
}
}
private void OnRecieved(SECSEventType type, SECSTransaction trans, SECSErrors err, string errmsg)
{
var msgName = string.Empty;
switch (type)
{
case SECSEventType.HSMSConnected:
msgName = $"{nameof(SECSEventType.HSMSConnected)}Handler";
break;
case SECSEventType.HSMSDisconnected:
msgName = $"{nameof(SECSEventType.HSMSDisconnected)}Handler";
break;
case SECSEventType.PrimaryRcvd:
msgName = $"S{trans.Primary.Stream}F{trans.Primary.Function}Handler";
break;
case SECSEventType.SecondaryRcvd:
msgName = $"S{trans.Secondary.Stream}F{trans.Secondary.Function}Handler";
break;
default:
msgName = $"{nameof(SECSEventType.Error)}Handler";
break;
}
if (Handlers.ContainsKey(msgName))
{
Task.Run(() => Handlers[msgName].Execute(this, trans, err, errmsg));
}
}
public virtual bool Close()
{
try
{
if (IsConnected)
{
Port.ClosePort();
Global.MF.ConnectStatusSet(false);
return true;
}
return false;
}
catch (Exception e)
{
LoggerService.SECSLogger.Error(e);
return false;
}
}
public virtual bool Open()
{
try
{
if (Port != null)
{
Port.OpenPort();
return Port.Connected;
}
return false;
}
catch (Exception e)
{
LoggerService.SECSLogger.Error(e);
return false;
}
}
public virtual void ReplyMessage(SECSTransaction trans)
{
try
{
if (Port != null && Port.PortIsOpen)
{
Port.Reply(trans);
}
}
catch (Exception e)
{
LoggerService.SECSLogger.Error(e);
}
}
public virtual void SendMessage(SECSTransaction trans)
{
try
{
if (Port != null && Port.PortIsOpen)
{
Port.Send(trans);
}
}
catch (Exception e)
{
LoggerService.SECSLogger.Error(e);
}
}
public virtual void SendMessage(string name)
{
try
{
if (Port != null && Port.PortIsOpen)
{
SECSTransaction transaction = new SECSTransaction
{
Primary = Port.Library.FindMessage(name)
};
transaction.Secondary = Port.Library.FindMessage(transaction.Primary.Stream, transaction.Primary.Function + 1).FirstOrDefault();
Port.Send(transaction);
}
}
catch (Exception e)
{
LoggerService.SECSLogger.Error(e);
}
}
public SECSTransaction GetTransaction(int stream, int function, string msgName = null)
{
try
{
string messageName = string.IsNullOrWhiteSpace(msgName) ? $"S{stream}F{function}" : msgName.ToUpper();
if (Port == null)
{
LoggerService.SECSLogger.Error($"Method: GetTransaction, Port is null!");
return null;
}
if (Port.Library == null)
{
LoggerService.SECSLogger.Error($"Method: GetTransaction, Port.Library is null!");
return null;
}
return Port.Library.FindTransaction(messageName);
}
catch (Exception e)
{
LoggerService.SECSLogger.Error(e);
return null;
}
}
}
}

93
Common/Scenario.cs Normal file
View File

@@ -0,0 +1,93 @@
using Glorysoft.SECS.EQP.Commands;
using Glorysoft.SECS.EQP.Message;
using Glorysoft.SECS.EQP.Utilities;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Serialization;
namespace Glorysoft.SECS.EQP
{
public static class ScenarioExtension
{
public static void ExecuteNextStep(this Scenario scenario)
{
if (scenario.CurrentStep > 1)
{
var prevWF = scenario.WorkFlows.FirstOrDefault(item => item.Step == scenario.CurrentStep);
SimulatorInfo.Instance.ShowInfo = $"ScenarioName: {scenario.Name}, StepCount: {scenario.WorkFlows.Count}, CurrentStep: {scenario.CurrentStep}, Message: {prevWF.MessageName}.";
}
scenario.CurrentStep++;
if (scenario.CurrentStep >= scenario.WorkFlows.Count)
{
return;
}
var nextWF = scenario.WorkFlows.FirstOrDefault(item => item.Step == scenario.CurrentStep);
SimulatorInfo.Instance.ShowInfo = $"ScenarioName: {scenario.Name}, StepCount: {scenario.WorkFlows.Count}, CurrentStep: {scenario.CurrentStep}, Message: {nextWF.MessageName}.";
switch (nextWF.MessageName)
{
case "S1F1": scenario.CurrentStep++; Command.S1F1Command(scenario); break;
case "S1F13": scenario.CurrentStep++; Command.S1F13Command(scenario); break;
case "S1F17": scenario.CurrentStep++; Command.S1F17Command(scenario); break;
case "S1F15": scenario.CurrentStep++; Command.S1F15Command(scenario); break;
case "S6F23": scenario.CurrentStep++; Command.S6F23Command(scenario); break;
case "S5F5": scenario.CurrentStep++; Command.S5F5Command(scenario); break;
case "S7F19": scenario.CurrentStep++; Command.S7F19Command(scenario); break;
case "S2F13": scenario.CurrentStep++; Command.S2F13Command(scenario); break;
case "S2F43": scenario.CurrentStep++; Command.S2F43Command(nextWF.MessageContent.FromJson<S2F43Item>(), scenario); break;
case "S2F23": scenario.CurrentStep++; Command.S2F23Command(nextWF.MessageContent.FromJson<S2F23Item>(), scenario); break;
case "S1F3": scenario.CurrentStep++; Command.S1F3Command(scenario); break;
case "S2F15": scenario.CurrentStep++; Command.S2F15Command(nextWF.MessageContent.FromJson<S2F15Item>(), scenario); break;
case "S2F15Rcp": scenario.CurrentStep++; Command.S2F15CommandRcp(nextWF.MessageContent.FromJson<S2F15Item>(), scenario); break;
case "S2F31": scenario.CurrentStep++; Command.S2F31Command(nextWF.MessageContent.FromJson<S2F31Item>(), scenario); break;
case "S2F33": scenario.CurrentStep++; Command.S2F33Command(nextWF.MessageContent.FromJson<S2F33Item>(), scenario); break;
case "S2F35": scenario.CurrentStep++; Command.S2F35Command(nextWF.MessageContent.FromJson<S2F35Item>(), scenario); break;
case "S2F37": scenario.CurrentStep++; Command.S2F37Command(nextWF.MessageContent.FromJson<S2F37Item>(), scenario); break;
case "S2F41": scenario.CurrentStep++; Command.S2F41Command(nextWF.MessageContent.FromJson<S2F41Item>(), scenario); break;
case "S5F3": scenario.CurrentStep++; Command.S5F3Command(nextWF.MessageContent.FromJson<S5F3Item>(), scenario); break;
case "S7F1": scenario.CurrentStep++; Command.S7F1Command(nextWF.MessageContent.FromJson<S7F1Item>(), scenario); break;
case "S7F3": scenario.CurrentStep++; Command.S7F3Command(nextWF.MessageContent.FromJson<S7F3Item>(), scenario); break;
case "S7F5": scenario.CurrentStep++; Command.S7F5Command(nextWF.MessageContent.FromJson<S7F5Item>(), scenario); break;
case "S7F17": scenario.CurrentStep++; Command.S7F17Command(nextWF.MessageContent.FromJson<S7F17Item>(), scenario); break;
}
}
}
[Serializable]
public class ScenarioCollection
{
public List<Scenario> Scenarios { get; set; }
public ScenarioCollection() => Scenarios = new List<Scenario>();
}
[Serializable]
public class Scenario
{
[XmlAttribute]
public string Name { get; set; }
[JsonIgnore]
[XmlIgnore]
public int CurrentStep { get; set; }
[XmlElement]
public List<WorkFlow> WorkFlows { get; set; }
public Scenario()
{
WorkFlows = new List<WorkFlow>();
}
}
[Serializable]
public class WorkFlow
{
[XmlAttribute]
public int Step { get; set; }
public string MessageName { get; set; }
public string MessageContent { get; set; }
}
}

44
Common/SimulatorInfo.cs Normal file
View File

@@ -0,0 +1,44 @@
using Glorysoft.SECS.EQP.Common;
using System;
using System.Collections;
namespace Glorysoft.SECS.EQP
{
public class SimulatorInfo
{
#region
public delegate void PropertyChangedEventHandler();
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged()
{
PropertyChanged?.Invoke();
}
#endregion
private static readonly Lazy<SimulatorInfo> LazyInstance = new Lazy<SimulatorInfo>(() => new SimulatorInfo());
private SimulatorInfo()
{
}
public static SimulatorInfo Instance => LazyInstance.Value;
public SECSContext Context { get; set; }
private bool _isConnected = false;
public bool IsConnected { get { return _isConnected; } set { if (_isConnected != value) { _isConnected = value; OnPropertyChanged(); } } }
private string _showInfo;
public string ShowInfo { get { return _showInfo; } set { if (_showInfo != value) { _showInfo = value; if (!string.IsNullOrWhiteSpace(value)) OnPropertyChanged(); } } }
private string _recipeList;
public string RecipeList { get { return _recipeList; } set { if (_recipeList != value) { _recipeList = value; if (!string.IsNullOrWhiteSpace(value)) OnPropertyChanged(); } } }
private string _workFLowFlag;
public string WorkFLowFlag { get { return _workFLowFlag; } set { if (_workFLowFlag != value) { _workFLowFlag = value; if (!string.IsNullOrWhiteSpace(value)) OnPropertyChanged(); } } }
public ScenarioCollection Scenarios { get; set; }
}
}