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.

123 lines
3.6 KiB

3 years ago
  1. using Leit.FrameWork.Log;
  2. using Leit.Model;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace Leit.StationFunction
  9. {
  10. public static class Function_OP80
  11. {
  12. /// <summary>
  13. /// 工位标签信息
  14. /// </summary>
  15. public static List<StationTagInfo> StationTagInfos { get; set; }
  16. /// <summary>
  17. /// 工位报警标签信息
  18. /// </summary>
  19. public static List<StationTagInfo> StationAlarmTagInfos { get; set; }
  20. /// <summary>
  21. /// 工位质量数据标签信息
  22. /// </summary>
  23. public static List<StationTagInfo> StationQualityTagInfos { get; set; }
  24. /// <summary>
  25. /// 工位交互数据标签信息
  26. /// </summary>
  27. public static List<StationTagInfo> StationCommunicatedTagInfos { get; set; }
  28. /// <summary>
  29. /// 工位信息
  30. /// </summary>
  31. public static StationInfo StationInf { get; set; }
  32. /// <summary>
  33. /// 托盘号
  34. /// </summary>
  35. public static byte PalletNum { get; set; }
  36. public static bool ReadDataOk { get; set; }
  37. /// <summary>
  38. /// 业务逻辑
  39. /// </summary>
  40. public static void CycleRunTimer()
  41. {
  42. try
  43. {
  44. //读取托盘号
  45. byte palletNum = ServiceData.OpcTags.Where(p => p.TagId == StationCommunicatedTagInfos.Where(q => q.TagMarkCode == 1010).First().TagId).First().GetValue<byte>();
  46. if (palletNum != 0)
  47. {
  48. //托盘号保持
  49. PalletNum = palletNum;
  50. }
  51. if (ServiceData.OpcTags.Where(p => p.TagId == StationCommunicatedTagInfos.Where(q => q.TagMarkCode == 1050).First().TagId).First().GetValue<byte>() == 1)
  52. {
  53. //收到允许保存 保存质量数据
  54. if (!ReadDataOk)
  55. {
  56. //读取质量数据.
  57. //读取质量数据.
  58. string sql = "update Deploy_Data set ";
  59. foreach (var item in StationQualityTagInfos)
  60. {
  61. if (item.TagDataType == "byte")
  62. {
  63. sql = sql + item.ColName + "='" + ServiceData.OpcTags.Where(p => p.TagId == item.TagId).First().GetValue<byte>()+"'";
  64. }
  65. else if (item.TagDataType == "float")
  66. {
  67. sql = sql + item.ColName + "='" + ServiceData.OpcTags.Where(p => p.TagId == item.TagId).First().GetValue<float>().ToString()+"'";
  68. }
  69. sql = sql + ",";
  70. }
  71. sql = sql.Remove(sql.Length - 1, 1);
  72. sql = sql + $",op80_time='{DateTime.Now}' where tuopan_id={PalletNum} and process_state=1";
  73. SqlSugarAdo.ExecuteCommand(sql);
  74. ReadDataOk = true;
  75. }
  76. //回写保存完成
  77. ServiceData.PlcServer.Write(StationCommunicatedTagInfos.Where(p => p.TagMarkCode == 1060).First().TagAddr, 1);
  78. }
  79. else
  80. {
  81. ReadDataOk = false;
  82. }
  83. }
  84. catch (Exception ex)
  85. {
  86. LogHelper.WriteLog(LogHelper.GetMethodInfo(), ex);
  87. }
  88. }
  89. }
  90. }