XiaomiMqttClient_StationInputBegin.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. using BZFAStandardLib;
  2. using Newtonsoft.Json;
  3. using System;
  4. using System.Threading.Tasks;
  5. namespace MainForm.ClassFile.XiaomiAPI
  6. {
  7. /// <summary>
  8. /// 小米 MqttClient类 - API拓展方法
  9. /// 节拍⽇志(OEE)
  10. /// • 节拍发⽣时上传
  11. /// 上料开始->上料结束->作业开始->作业结束->下料开始->下料结束
  12. /// </summary>
  13. public partial class XiaomiMqttClient_Extend : XiaomiMqttClient
  14. {
  15. /// <summary>
  16. /// 节拍⽇志(OEE)- 事件Id
  17. /// 上料开始->上料结束->作业开始->作业结束->下料开始->下料结束
  18. /// 上料开始:beat_log/business/OEE/station_input_begin
  19. /// 上料结束:beat_log/business/OEE/station_input_end
  20. /// 作业开始:beat_log/business/OEE/station_work_begin
  21. /// 作业结束:beat_log/business/OEE/station_work_end
  22. /// 下料开始:beat_log/business/OEE/station_output_begin
  23. /// 下料结束:beat_log/business/OEE/station_output_end
  24. /// </summary>
  25. private static string StationInputBeginId { get; set; } = "beat_log/business/OEE/{0}";
  26. /// <summary>
  27. /// 节拍⽇志(OEE)- 事件方法
  28. /// XiaomiDeviceState
  29. /// </summary>
  30. /// <param name="msg">事件数据;Json</param>
  31. /// <param name="dataId">自定义事件Id;如:guid</param>
  32. /// <returns></returns>
  33. public static (int, string) Write_StationInputBegin(StationInputBeginRequest request, string deviceCode = "")
  34. {
  35. int result = 0;
  36. string resultStr = "";
  37. string msg = JsonConvert.SerializeObject(request);
  38. byte[] bytes = ToUTF8(msg);
  39. //request.action = string.Format(StationInputBeginId, request.action);
  40. // 发送
  41. if (string.IsNullOrEmpty(deviceCode))
  42. {
  43. bool isOk = Task.Run(() => { result = Write(request.action, bytes); }).Wait(10000);
  44. if (!isOk) // 无响应
  45. return (-999, "上位机调用Iot的dll无响应[方法名Write]!");
  46. }
  47. else
  48. {
  49. bool isOk = Task.Run(() => { result = WriteWithDeviceCode(request.action, bytes, deviceCode); }).Wait(10000);
  50. if (!isOk) // 无响应
  51. return (-999, "上位机调用Iot的dll无响应[方法名WriteWithDeviceCode]!");
  52. }
  53. var try1 = Enum.TryParse(result.ToString(), out XiaomiMqttResponse_ErrCode errCode);
  54. if (try1)
  55. resultStr = errCode.ToString();
  56. else
  57. resultStr = XiaomiMqttResponse_ErrCode.ERR_UNKOWN.ToString();
  58. string logPath = GlobalContext.MqttInputBeginDir + "beatType" + DateTime.Now.ToString("yyyyMMdd") + ".txt";
  59. FileOperate.NewTxtFile(logPath, DateTime.Now+"===>MQTT【节拍日志】提交:" + msg + "\r\n==>提交结果:" + resultStr + "");
  60. return (result, resultStr);
  61. }
  62. /// <summary>
  63. /// 节拍⽇志(OEE)- 参数
  64. /// </summary>
  65. public class StationInputBeginRequest
  66. {
  67. /// <summary>
  68. /// 节拍动作(XiaomiDeviceOEE)
  69. /// string[1,64]
  70. /// 上料开始:beat_log/business/OEE/station_input_begin
  71. /// 上料结束:beat_log/business/OEE/station_input_end
  72. /// 作业开始:beat_log/business/OEE/station_work_begin
  73. /// 作业结束:beat_log/business/OEE/station_work_end
  74. /// 下料开始:beat_log/business/OEE/station_output_begin
  75. /// 下料结束:beat_log/business/OEE/station_output_end
  76. /// </summary>
  77. public string action { get; set; } = string.Empty;
  78. /// <summary>
  79. /// 节拍发⽣时间
  80. /// string[1,32]
  81. /// 时间,精确到毫秒。如:2022-06-01 14:27:57.283
  82. /// </summary>
  83. public string beat_tm { get; set; } = string.Empty;
  84. /// <summary>
  85. /// 该动作操作的⽬标对象(SN)
  86. /// string[1,64]
  87. /// </summary>
  88. public string action_subject { get; set; } = string.Empty;
  89. /// <summary>
  90. /// ⼤板SN/载具SN
  91. /// 若使用虚拟SN,虚拟SN格式为:SN-编号
  92. /// string[1,64]
  93. /// </summary>
  94. public string action_subject_parent { get; set; } = string.Empty;
  95. /// <summary>
  96. /// 该动作的位置信息(⼯位、槽位),如:F06-GSTPLA11_01-SLOT-01
  97. /// string[1,32]
  98. /// ⼯位
  99. /// </summary>
  100. public string action_location { get; set; } = string.Empty;
  101. /// <summary>
  102. /// 该动作的物料信息
  103. /// string[1,256]
  104. /// 若动作的位置信息有多级,则考虑使⽤"_"分隔,如:"⼯位号_槽位号"
  105. /// </summary>
  106. public string action_material { get; set; } = string.Empty;
  107. /// <summary>
  108. /// 额外信息
  109. /// ⽤于携带额外信息
  110. /// </summary>
  111. public string extra { get; set; } = string.Empty;
  112. /// <summary>
  113. /// 数据字典中定义的分类层级1
  114. /// string[1,64]
  115. /// </summary>
  116. public string class_level_1 { get; set; } = string.Empty;
  117. /// <summary>
  118. /// 数据字典中定义的分类层级2
  119. /// string[1,64]
  120. /// </summary>
  121. public string class_level_2 { get; set; } = string.Empty;
  122. /// <summary>
  123. /// 数据字典中定义的分类层级3
  124. /// string[1,64]
  125. /// </summary>
  126. public string class_level_3 { get; set; } = string.Empty;
  127. }
  128. }
  129. }