data_forward.py 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. from utils.s7data import *
  2. from models.data_sender import *
  3. from utils.statepoint import *
  4. import copy
  5. class Forward:
  6. def __init__(self, data_s7: S7data, sender: Sender, crane_flag: bool, ccmNo: str):
  7. self.data_s7 = data_s7
  8. self.sender = sender
  9. self.crane_flag = crane_flag
  10. self.ccmNo = ccmNo
  11. self.billet_position_list = []
  12. self.barrier_state_list = []
  13. for i in range(8):
  14. self.billet_position_list.append(data_s7.make_point(f"L{i+1}坯头位置"))
  15. self.barrier_state_list.append(data_s7.make_point(f"L{i+1}挡板"))
  16. self.pusher = data_s7.make_point("推钢机激光")
  17. if self.crane_flag:
  18. self.crane_A1 = data_s7.make_point("天车A1位置")
  19. self.crane_A2 = data_s7.make_point("天车A2位置")
  20. self.crane_A3 = data_s7.make_point("天车A3位置")
  21. self.roller_one_sig = Through_state_continues3(data_s7.make_point("爬坡监测点[1]"), data_s7.make_point("爬坡监测点[2]"), data_s7.make_point("爬坡监测点[3]"))
  22. self.roller_one_sig.set_excite_action(self.roller_one_hostsend)
  23. self.topic = 'trace/performance/billet/monitor'
  24. self.qos = 0
  25. self.template = {
  26. "type": "", # string 钢坯流道,行车,推钢机,辊道,车辆,堆垛
  27. "data": {
  28. "machine": 0, # number 如果是流道的话,哪个铸机
  29. "channel": 0, # number 如果是流道的话,第几流
  30. "direction": "", # string 运行方向 up, down, left, right
  31. "distance": 0, # number 运行距离 ,(应该是毫米)
  32. "has_billet": False, # boolean 是否夹起钢坯
  33. "position": 0, # number 车辆位置 , 从上到下,从左到右, 1 | 2 | 3 | 4, 行车位置 , 按图中位置,从左到右, A1 | A2 | A3 | B1 | B2
  34. "car_num": "", # string 车牌号
  35. "car_running": "", # string 车辆运行, in 表示车辆到站, out 车辆离开
  36. "billet_stacking": "", # string 堆垛 501 601 602 604 coolbed(步进冷床)
  37. "layers": 0, # number 堆垛层数
  38. "amount": 0 # number 堆垛夹数
  39. }
  40. }
  41. self.task_thread = None
  42. self.run_flag = False
  43. def billet_position(self, strandNo, position):
  44. tmp = copy.deepcopy(self.template)
  45. tmp['type'] = 'channel'
  46. tmp['data']['machine'] = self.ccmNo
  47. tmp['data']['channel'] = strandNo
  48. tmp['data']['direction'] = 'down'
  49. tmp['data']['distance'] = position
  50. self.sender.mqtt_publish(self.topic, tmp, self.qos)
  51. def barrier_state(self, strandNo, state):
  52. tmp = copy.deepcopy(self.template)
  53. tmp['type'] = 'channel_barrier'
  54. tmp['data']['machine'] = self.ccmNo
  55. tmp['data']['channel'] = strandNo
  56. if state:
  57. tmp['data']['direction'] = 'down'
  58. else:
  59. tmp['data']['direction'] = 'up'
  60. self.sender.mqtt_publish(self.topic, tmp, self.qos)
  61. def pusher_position(self, position):
  62. tmp = copy.deepcopy(self.template)
  63. tmp['type'] = 'steel_pusher'
  64. tmp['data']['machine'] = self.ccmNo
  65. tmp['data']['distance'] = position
  66. self.sender.mqtt_publish(self.topic, tmp, self.qos)
  67. def overhead_crane_position(self, craneNo, position):
  68. tmp = copy.deepcopy(self.template)
  69. tmp['type'] = 'train_working'
  70. tmp['data']['position'] = craneNo
  71. tmp['data']['direction'] = 'left'
  72. tmp['data']['distance'] = position
  73. tmp['data']['has_billet'] = False
  74. self.sender.mqtt_publish(self.topic, tmp, self.qos)
  75. def roller_one_hostsend(self):
  76. tmp = copy.deepcopy(self.template)
  77. tmp['type'] = 'roller_one'
  78. tmp['data']['has_billet'] = True
  79. if self.sender.mqtt_publish(self.topic, tmp, self.qos)[0]:
  80. print("发送失败")
  81. else:
  82. print('发送成功')
  83. def auto_forward(self):
  84. while self.run_flag:
  85. for i in range(8):
  86. self.billet_position(i+1, self.billet_position_list[i].data)
  87. self.barrier_state(i+1, self.barrier_state_list[i].data)
  88. self.pusher_position(self.pusher.data)
  89. if self.crane_flag:
  90. self.overhead_crane_position('A1', self.crane_A1.data)
  91. self.overhead_crane_position('A2', self.crane_A2.data)
  92. self.overhead_crane_position('A3', self.crane_A3.data)
  93. time.sleep(0.5)
  94. def start_auto_forward(self):
  95. if self.task_thread:
  96. self.run_flag = False
  97. self.task_thread.join()
  98. self.run_flag = True
  99. if self.crane_flag:
  100. self.roller_one_sig.allow_update()
  101. self.task_thread = threading.Thread(target=self.auto_forward)
  102. self.task_thread.start()