V1.0
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
*----------------------------------------------------------------*/
|
||||
#endregion << 版 本 注 释 >>
|
||||
|
||||
using ARI.EAP.HOST.SRD;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -29,8 +30,8 @@ namespace ARI.EAP.HOST.Common
|
||||
/// </summary>
|
||||
public static class Constants
|
||||
{
|
||||
public const string eapName = "ACOAT_01";
|
||||
public const string configuerPath = "Configuration/" + eapName + ".xml";
|
||||
public const string equipmentName = "ACOAT_01";
|
||||
public const string configuerPath = "Configuration/" + equipmentName + ".xml";
|
||||
}
|
||||
|
||||
public struct ConnectState
|
||||
@@ -38,5 +39,13 @@ namespace ARI.EAP.HOST.Common
|
||||
public static readonly string connected = "Connected";
|
||||
|
||||
public static readonly string disconnected = "Disconnected";
|
||||
|
||||
public static readonly string connecting = "Connecting";
|
||||
}
|
||||
|
||||
public enum RunState
|
||||
{
|
||||
Run,
|
||||
Stop
|
||||
}
|
||||
}
|
||||
@@ -10,14 +10,64 @@ 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;
|
||||
public static string S5F3 { get; set; } = "AlarmEnable";
|
||||
public static ushort SpoolingFlag { get; set; } = 0;
|
||||
public static Dictionary<string, IEventHandler> EventHandlers { get; set; }
|
||||
public static ushort commandCount { get; set; } = 0;
|
||||
public static bool initStatus { get; set; } = false;
|
||||
|
||||
public static MESHeartBit mESHeartBit;
|
||||
|
||||
private static string _MQstate = ConnectState.disconnected;
|
||||
|
||||
private static string _EqConnectState = ConnectState.disconnected;
|
||||
|
||||
private static RunState _EapState = RunState.Stop;
|
||||
|
||||
public static string MQstate
|
||||
{
|
||||
get { return _MQstate; }
|
||||
set
|
||||
{
|
||||
if (!_MQstate.Equals(value))
|
||||
{
|
||||
_MQstate = value;
|
||||
Global.MF.MQConnectStatusSet(value);
|
||||
PublishStatus();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static string EqConnectState
|
||||
{
|
||||
get { return _EqConnectState; }
|
||||
set
|
||||
{
|
||||
if (!_EqConnectState.Equals(value))
|
||||
{
|
||||
_EqConnectState = value;
|
||||
Global.MF.ConnectStatusSet(value);
|
||||
PublishStatus();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static RunState EapState
|
||||
{
|
||||
get { return _EapState; }
|
||||
set
|
||||
{
|
||||
if (!_EapState.Equals(value))
|
||||
{
|
||||
_EapState = value;
|
||||
PublishStatus();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static EquipmentStatus()
|
||||
{
|
||||
mESHeartBit = new MESHeartBit();
|
||||
EventHandlers = new Dictionary<string, IEventHandler>();
|
||||
foreach (Type item in MethodBase.GetCurrentMethod().DeclaringType.Assembly.GetTypes())
|
||||
{
|
||||
@@ -27,5 +77,10 @@ namespace ARI.EAP.HOST.Common
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void PublishStatus() {
|
||||
Task.Run(() => mESHeartBit.Method());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -54,15 +54,6 @@ namespace ARI.EAP.HOST.Common
|
||||
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]
|
||||
@@ -82,9 +73,9 @@ namespace ARI.EAP.HOST.Common
|
||||
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";
|
||||
this.connectStatus = EquipmentStatus.EqConnectState;
|
||||
this.mqStatus = EquipmentStatus.MQstate;
|
||||
this.eapStatus = EquipmentStatus.EapState.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@
|
||||
// + 创建 SECSContext.cs 文件. by Michael @2019/11/8 0:08
|
||||
// ********************************************************************************
|
||||
using ARI.EAP.HOST;
|
||||
using ARI.EAP.HOST.Common;
|
||||
using Glorysoft.SECS.EQP.Utilities;
|
||||
using Glorysoft.SECSwell;
|
||||
using System;
|
||||
@@ -127,7 +128,7 @@ namespace Glorysoft.SECS.EQP.Common
|
||||
if (IsConnected)
|
||||
{
|
||||
Port.ClosePort();
|
||||
Global.MF.ConnectStatusSet(false);
|
||||
EquipmentStatus.EqConnectState = ConnectState.disconnected;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
113
Common/SocketClient.cs
Normal file
113
Common/SocketClient.cs
Normal file
@@ -0,0 +1,113 @@
|
||||
#region << 版 本 注 释 >>
|
||||
/*----------------------------------------------------------------
|
||||
* 创建者:13118
|
||||
* 创建时间:2022/6/15 16:42:09
|
||||
* 版本:V1.0.0
|
||||
* 描述:
|
||||
*
|
||||
* ----------------------------------------------------------------
|
||||
* 修改人:
|
||||
* 时间:
|
||||
* 修改说明:
|
||||
*
|
||||
* 版本:V1.0.1
|
||||
*----------------------------------------------------------------*/
|
||||
#endregion << 版 本 注 释 >>
|
||||
|
||||
using Polly;
|
||||
using Polly.Retry;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
namespace ARI.EAP.HOST.Common
|
||||
{
|
||||
/// <summary>
|
||||
/// SocketClient 的摘要说明
|
||||
/// </summary>
|
||||
public class SocketClient
|
||||
{
|
||||
private static Socket socket;
|
||||
private Thread thread;
|
||||
private byte[] buffer = new byte[2048];
|
||||
private object sync_root = new object();
|
||||
|
||||
static SocketClient()
|
||||
{
|
||||
socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
||||
}
|
||||
|
||||
public SocketClient()
|
||||
{
|
||||
Task.Run(() => SocketConnect());
|
||||
}
|
||||
|
||||
private void SocketConnect()
|
||||
{
|
||||
lock (sync_root)
|
||||
{
|
||||
RetryPolicy policy = Policy.Handle<SocketException>()
|
||||
.WaitAndRetryForever(retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)), (ex, time) =>
|
||||
{
|
||||
});// 永远等待并重试,每次等待2的指数次冥的时间
|
||||
policy.Execute(() =>
|
||||
{
|
||||
socket.Connect(new IPEndPoint(IPAddress.Parse("127.0.0.1"), int.Parse("10086")));
|
||||
|
||||
thread = new Thread(StartReceive);
|
||||
thread.IsBackground = true;
|
||||
thread.Start(socket);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void StartReceive(object obj)
|
||||
{
|
||||
string str;
|
||||
while (true)
|
||||
{
|
||||
Socket receiveSocket = obj as Socket;
|
||||
try
|
||||
{
|
||||
int result = receiveSocket.Receive(buffer);
|
||||
if (result == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
str = Encoding.Default.GetString(buffer);
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Disconnected()
|
||||
{
|
||||
try
|
||||
{
|
||||
socket.Shutdown(SocketShutdown.Both);
|
||||
socket.Close();
|
||||
thread.Abort();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public void SendMessage(string message)
|
||||
{
|
||||
socket.Send(Encoding.Default.GetBytes(message));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user