You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
2.4 KiB

3 years ago
  1. using Leit.FrameWork;
  2. using Leit.FrameWork.Log;
  3. using Newtonsoft.Json;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. namespace Leit.StationFunction
  10. {
  11. public class UpperCommunication
  12. {
  13. public static event Action<string, string> BarcodeDelegate;
  14. public static UdpHelper UdpCommunication { get; set; }
  15. public static MqAdapter Mq_Adapter { get; set; }
  16. /// <summary>
  17. /// 初始化通讯组件
  18. /// </summary>
  19. public static void InitCommunication()
  20. {
  21. try
  22. {
  23. UdpCommunication = new UdpHelper(UserConfiguration.UdpReceivePort);
  24. UdpCommunication.ReceiveUdpMsg += UdpCommunication_ReceiveUdpMsg; ;
  25. UdpCommunication.ReciveMsg();
  26. Publisher publisher = new Publisher(UserConfiguration.ServerIp, UserConfiguration.MqPubPort);
  27. Mq_Adapter = new MqAdapter(publisher);
  28. Responser responser = new Responser(UserConfiguration.ServerIp, UserConfiguration.ResponsePort);
  29. responser.responseAction += Responser_responseFunc;
  30. }
  31. catch (Exception ex)
  32. {
  33. LogHelper.WriteLog(LogHelper.GetMethodInfo(), ex);
  34. }
  35. }
  36. /// <summary>
  37. /// 接收前端请求
  38. /// </summary>
  39. /// <param name="arg"></param>
  40. /// <returns></returns>
  41. private static void Responser_responseFunc(string arg)
  42. {
  43. MsgStruct msgStruct = (MsgStruct)JsonConvert.DeserializeObject(arg, typeof(MsgStruct));
  44. if (msgStruct.MsgVerifyCode == "SendOrderInfo")
  45. {
  46. Function_OP20.PlanChanged(msgStruct.MsgContent.ToString());
  47. }
  48. if (msgStruct.MsgVerifyCode == "barcode")
  49. {
  50. BarcodeDelegate?.Invoke(msgStruct.StationCode, msgStruct.MsgText);
  51. // LogHelper.WriteLog($"收到条码:{ msgStruct.MsgText}");
  52. }
  53. }
  54. /// <summary>
  55. /// Udp接收条码信息
  56. /// </summary>
  57. /// <param name="msg"></param>
  58. private static void UdpCommunication_ReceiveUdpMsg(MsgStruct msg)
  59. {
  60. if (msg.MsgVerifyCode == "barcode")
  61. {
  62. BarcodeDelegate?.Invoke(msg.StationCode, msg.MsgText);
  63. }
  64. }
  65. }
  66. }