OffsetDataRecorder.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. using Aitex.Core.RT.DBCore;
  2. using Aitex.Sorter.Common;
  3. using MECF.Framework.Common.ControlDataContext;
  4. using MECF.Framework.Common.Equipment;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Data;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using CyberX8_Core;
  12. namespace MECF.Framework.Common.DBCore
  13. {
  14. public class OffsetDataRecorder
  15. {
  16. //数据库结构
  17. //"\"guid\",",
  18. //"\"source_module\",",
  19. //"\"source_slot\",",
  20. //"\"destination_module\",",
  21. //"\"destination_slot\",",
  22. //"\"origin_module\",",
  23. //"\"origin_slot\",",
  24. //"\"arm_position\",",
  25. //"\"arm_pan\",",
  26. //"\"offset_x\",",
  27. //"\"offset_y\",",
  28. //"\"offset_d\",",
  29. //"\"start_time\",",
  30. //"\"end_time\",",
  31. public static void RecordOffsetData(
  32. string guid,
  33. ModuleName source_module, int source_slot,
  34. ModuleName destination_module, int destination_slot,
  35. string origin_module, int origin_slot,
  36. Hand arm_position, RobotArmPan arm_pan,
  37. double offset_x, double offset_y, double offset_d,
  38. DateTime start_time, DateTime end_time)
  39. {
  40. string sql = string.Format(
  41. "INSERT INTO \"offset_data\"(" +
  42. "\"guid\"," +
  43. "\"source_module\"," +
  44. "\"source_slot\"," +
  45. "\"destination_module\"," +
  46. "\"destination_slot\"," +
  47. "\"origin_module\"," +
  48. "\"origin_slot\"," +
  49. "\"arm_position\"," +
  50. "\"arm_pan\"," +
  51. "\"offset_x\"," +
  52. "\"offset_y\"," +
  53. "\"offset_d\"," +
  54. "\"start_time\"," +
  55. "\"end_time\"" +
  56. ")VALUES (" +
  57. $"'{guid}'," +
  58. $"'{source_module}'," +
  59. $"'{source_slot + 1}'," +
  60. $"'{destination_module}'," +
  61. $"'{destination_slot + 1}'," +
  62. $"'{origin_module}'," +
  63. $"'{origin_slot + 1}'," +
  64. $"'{arm_position}'," +
  65. $"'{arm_pan}'," +
  66. $"'{offset_x}'," +
  67. $"'{offset_y}'," +
  68. $"'{offset_d}'," +
  69. $"'{start_time.ToString("yyyy/MM/dd HH:mm:ss.fff")}'," +
  70. $"'{end_time.ToString("yyyy/MM/dd HH:mm:ss.fff")}'" +
  71. ");");
  72. DB.Insert(sql);
  73. }
  74. public static List<OffsetItem> QueryOffsetDataByTime(string moduleName, DateTime from_time, DateTime to_time)
  75. {
  76. List<OffsetItem> result = new List<OffsetItem>();
  77. string sql = string.Format($"SELECT * FROM \"offset_data\" WHERE \"start_time\" >= '{from_time.ToString("yyyy/MM/dd HH:mm:ss.fff")}' AND \"start_time\" <= '{to_time.ToString("yyyy/MM/dd HH:mm:ss.fff")}' AND \"destination_module\" = '{moduleName}' ");
  78. DataSet ds = DB.ExecuteDataset(sql);
  79. if (ds == null || ds.Tables.Count == 0)
  80. return result;
  81. for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
  82. {
  83. result.Add(new OffsetItem()
  84. {
  85. Guid = ds.Tables[0].Rows[i]["guid"].ToString(),
  86. SourceModule = ds.Tables[0].Rows[i]["source_module"].ToString(),
  87. DestinationModule = ds.Tables[0].Rows[i]["destination_module"].ToString(),
  88. OriginModule = ds.Tables[0].Rows[i]["origin_module"].ToString(),
  89. SourceSlot = Convert.ToInt16(ds.Tables[0].Rows[i]["source_slot"]),
  90. DestinationSlot = Convert.ToInt16(ds.Tables[0].Rows[i]["destination_slot"]),
  91. OriginSlot = Convert.ToInt16(ds.Tables[0].Rows[i]["origin_slot"]),
  92. ArmPosition = ds.Tables[0].Rows[i]["arm_position"].ToString(),
  93. ArmPan = ds.Tables[0].Rows[i]["arm_pan"].ToString(),
  94. OffsetX = Convert.ToDouble(ds.Tables[0].Rows[i]["offset_x"]),
  95. OffsetY = Convert.ToDouble(ds.Tables[0].Rows[i]["offset_y"]),
  96. OffsetD = Convert.ToDouble(ds.Tables[0].Rows[i]["offset_d"]),
  97. StartTime = (DateTime)ds.Tables[0].Rows[i]["start_time"],
  98. EndTime = (DateTime)ds.Tables[0].Rows[i]["end_time"],
  99. });
  100. }
  101. ds.Clear();
  102. return result;
  103. }
  104. }
  105. }