using Leit.FrameWork;
|
|
using Leit.FrameWork.Log;
|
|
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Leit.StationFunction
|
|
{
|
|
public class UpperCommunication
|
|
{
|
|
|
|
public static event Action<string, string> BarcodeDelegate;
|
|
|
|
public static UdpHelper UdpCommunication { get; set; }
|
|
|
|
|
|
public static MqAdapter Mq_Adapter { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 初始化通讯组件
|
|
/// </summary>
|
|
public static void InitCommunication()
|
|
{
|
|
try
|
|
{
|
|
UdpCommunication = new UdpHelper(UserConfiguration.UdpReceivePort);
|
|
UdpCommunication.ReceiveUdpMsg += UdpCommunication_ReceiveUdpMsg; ;
|
|
UdpCommunication.ReciveMsg();
|
|
|
|
Publisher publisher = new Publisher(UserConfiguration.ServerIp, UserConfiguration.MqPubPort);
|
|
Mq_Adapter = new MqAdapter(publisher);
|
|
|
|
|
|
|
|
Responser responser = new Responser(UserConfiguration.ServerIp, UserConfiguration.ResponsePort);
|
|
responser.responseAction += Responser_responseFunc;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogHelper.WriteLog(LogHelper.GetMethodInfo(), ex);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 接收前端请求
|
|
/// </summary>
|
|
/// <param name="arg"></param>
|
|
/// <returns></returns>
|
|
private static void Responser_responseFunc(string arg)
|
|
{
|
|
|
|
MsgStruct msgStruct = (MsgStruct)JsonConvert.DeserializeObject(arg, typeof(MsgStruct));
|
|
|
|
if (msgStruct.MsgVerifyCode == "SendOrderInfo")
|
|
{
|
|
Function_OP20.PlanChanged(msgStruct.MsgContent.ToString());
|
|
}
|
|
|
|
if (msgStruct.MsgVerifyCode == "barcode")
|
|
{
|
|
BarcodeDelegate?.Invoke(msgStruct.StationCode, msgStruct.MsgText);
|
|
|
|
// LogHelper.WriteLog($"收到条码:{ msgStruct.MsgText}");
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Udp接收条码信息
|
|
/// </summary>
|
|
/// <param name="msg"></param>
|
|
private static void UdpCommunication_ReceiveUdpMsg(MsgStruct msg)
|
|
{
|
|
if (msg.MsgVerifyCode == "barcode")
|
|
{
|
|
BarcodeDelegate?.Invoke(msg.StationCode, msg.MsgText);
|
|
}
|
|
}
|
|
}
|
|
}
|