123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209 |
- import logging
- from utils.statepoint import *
- from utils.s7data import *
- from models.data_sender import *
- class Trace_pusher:
- def __init__(self, data_s7: S7data, logger: logging.Logger, sender: Sender, strand_position: list, hostsend_flag=False):
- self.data_s7 = data_s7
- self.logger = logger
- self.sender = sender
- self.strands = [[], [], [], [], [], [], [], []]
- self.locks = [threading.Lock() for i in range(8)]
- self.strand_position = strand_position
- self.hostsend_flag = hostsend_flag
-
- self.old_heatNo = "00000000"
- self.current_heatNo = "00000000"
- self.old_heatData = {}
- self.current_heatData = {}
- self.total = 0
- self.strand = [0, 0, 0, 0, 0, 0, 0, 0]
- self.count_lock = threading.Lock()
- self.pusher_left_list = []
- self.pusher_right_list = []
- self.bed_left = []
- self.bed_right = []
- self.pusher_left = data_s7.make_point('推钢机激光')
- self.pusher_right = data_s7.make_point('推钢机激光')
- self.pusher_left.set_convertor(lambda data: data < min(self.strand_position))
- self.pusher_right.set_convertor(lambda data: data > max(self.strand_position))
- self.pusher_left.set_excite_action(lambda: self.arrive_cooling_bed('left'))
- self.pusher_right.set_excite_action(lambda: self.arrive_cooling_bed('right'))
- self.barrier = [
- self.data_s7.make_point('L1挡板'),
- self.data_s7.make_point('L2挡板'),
- self.data_s7.make_point('L3挡板'),
- self.data_s7.make_point('L4挡板'),
- self.data_s7.make_point('L5挡板'),
- self.data_s7.make_point('L6挡板'),
- self.data_s7.make_point('L7挡板'),
- self.data_s7.make_point('L8挡板')
- ]
- if self.hostsend_flag:
- self.hostsend_barrier = [
- self.data_s7.make_point('热送挡板[0]'),
- self.data_s7.make_point('热送挡板[1]'),
- self.data_s7.make_point('热送挡板[2]'),
- self.data_s7.make_point('热送挡板[3]'),
- self.data_s7.make_point('热送挡板[4]'),
- self.data_s7.make_point('热送挡板[5]'),
- self.data_s7.make_point('热送挡板[6]'),
- self.data_s7.make_point('热送挡板[7]'),
- ]
- for i in range(8):
- self.barrier[i].allow_update(False)
- self.barrier[i].set_state(False)
- self.barrier[i].set_convertor(lambda data: not bool(data))
- self.barrier[i].set_excite_action(lambda i=i: self.barrier_up_action(i))
- self.barrier[i].set_reset_action(lambda i=i: self.logger.debug(f"{i+1}流挡板关闭"))
- self.barrier[i].allow_update()
- if self.hostsend_flag:
- self.hostsend_barrier[i].allow_update(False)
- self.hostsend_barrier[i].set_state(False)
- self.hostsend_barrier[i].set_convertor(lambda data: not bool(data))
- self.hostsend_barrier[i].set_excite_action(lambda i=i: self.hostsend_barrier_up_action(i))
- self.hostsend_barrier[i].set_reset_action(lambda i=i: self.logger.debug(f"{i+1}流热送挡板关闭"))
- self.hostsend_barrier[i].allow_update()
- def barrier_up_action(self, i):
- with self.locks[i]:
- if self.strands[i]:
- billetData = self.strands[i]
- self.strands[i] = []
- if self.strand_position[i] <= self.pusher_left.data:
- self.logger.info(f"[TRACE]{i+1}流钢坯通过挡板进入推钢区域,在推钢机左侧")
- self.pusher_left_list.append(billetData)
- else:
- self.logger.info(f"[TRACE]{i+1}流钢坯通过挡板进入推钢区域,在推钢机右侧")
- self.pusher_right_list.append(billetData)
- else:
- self.logger.error(f"[TRACE]{i+1}流挡板打开但挡板后无已计入系统的钢坯")
- return None
-
- def hostsend_barrier_up_action(self, i):
- with self.count_lock:
- gp_tmp = []
- if self.strand_position[i] <= self.pusher_left.data:
- index = -1
- for j in range(len(self.pusher_left_list)-1, -1, -1):
- if self.pusher_left_list[j][0][-3] == str(i+1):
- index = j
- break
- if index == -1:
- self.logger.warning(f"[TRACE]推钢机左侧未找到{i+1}流的热送钢坯")
- else:
- gp_tmp = self.pusher_left_list[index]
- self.pusher_left_list = self.pusher_left_list[:index] + self.pusher_left_list[index+1:]
- else:
- index = -1
- for j in range(len(self.pusher_right_list)-1, -1, -1):
- if self.pusher_right_list[j][0][-3] == str(i+1):
- index = j
- break
- if index == -1:
- self.logger.warning(f"[TRACE]推钢机右侧未找到{i+1}流的热送钢坯")
- else:
- gp_tmp = self.pusher_right_list[index]
- self.pusher_right_list = self.pusher_right_list[:index] + self.pusher_right_list[index+1:]
- if gp_tmp:
- if not (gp_tmp[0].startswith(self.current_heatNo) or gp_tmp[0].startswith(self.old_heatNo)):
- self.change_heat(gp_tmp)
- self.hostsend(gp_tmp)
-
- def change_heat(self, data):
- # 换炉代码
- self.old_heatNo = self.current_heatNo
- self.old_heatData = self.current_heatData
- self.current_heatNo = data[0][:8]
- self.current_heatData = data[1]
- # 上一炉终止信号在这里发
- self.total = 0
- self.strand = [0, 0, 0, 0, 0, 0, 0, 0]
- def arrive_cooling_bed(self, direc):
- with self.count_lock:
- if direc == 'left':
- if len(self.pusher_left_list) >= 4:
- if len(self.bed_left):
- self.logger.warning(f"有冷床上的钢坯无法录入:{'、'.join([i[0] for i in self.bed_right])}")
- self.bed_left = []
-
- self.bed_left.extend(self.pusher_left_list)
- self.pusher_left_list = []
- if len(self.bed_left) >= 4:
- for i in self.bed_left:
- if not (i[0].startswith(self.current_heatNo) or i[0].startswith(self.old_heatNo)):
- self.change_heat(i)
- break
- tmp = self.bed_left
- self.bed_left = []
- self.billet_union(tmp)
- elif direc == 'right':
- if len(self.pusher_right_list) >= 4:
- if len(self.bed_right):
- self.logger.warning(f"有冷床上的钢坯无法录入:{'、'.join([i[0] for i in self.bed_right])}")
- self.bed_right = []
-
- self.bed_right.extend(self.pusher_right_list)
- self.pusher_right_list = []
- if len(self.bed_right) >= 4:
- for i in self.bed_right:
- if not (i[0].startswith(self.current_heatNo) or i[0].startswith(self.old_heatNo)):
- self.change_heat(i)
- break
- tmp = self.bed_right
- self.bed_right = []
- self.billet_union(tmp)
- def billet_union(self, billets):
- billetsNo = []
- ccmNo = self.current_heatData['ccmNo']
- for i in billets:
- strandNo = i[0][9]
- self.total += 1
- self.strand[int(strandNo)-1] += 1
- billetNo = self.current_heatNo + ccmNo + strandNo + '{:0>2}'.format(self.strand[int(strandNo)-1])
- billetsNo.append(billetNo)
- self.sender.billet_upload(self.current_heatData, billetNo, self.total, i[2], i[3], i[4], i[5])
-
- self.logger.info(f"{self.current_heatNo}炉{len(billets)}根钢坯组成了一夹子:{'、'.join(billetsNo)}")
- def data_from_casting(self, i, data, extend=False):
- with self.locks[i]:
- if self.strands[i] and self.strands[i][0] != data[0]:
- self.logger.warning(f"{i+1}流有未经过挡板的钢坯被后坯顶出系统")
- self.strands[i] = data
- elif self.strands[i] and self.strands[i][0] == data[0]:
- self.logger.info(f"{i+1}流补充了钢坯停切时间")
- elif extend:
- self.logger.warning(f"{i+1}流对已经离开的钢坯补充停切时间,无效")
- else:
- self.logger.info(f"{i+1}流新增钢坯存储")
- self.strands[i] = data
- def hostsend(self, i):
- ccmNo = self.current_heatData['ccmNo']
- strandNo = i[0][9]
- self.total += 1
- self.strand[int(strandNo)] += 1
- billetNo = self.current_heatNo + ccmNo + strandNo + '{:0>2}'.format(self.strand[int(strandNo)])
- self.sender.billet_upload(self.current_heatData, billetNo, self.total, i[2], i[3], i[4], i[5])
- self.logger.info(f"{self.current_heatNo}炉钢坯热送:{billetNo}")
- # [坯号, 炉次信息, 定尺, 拉速, 开浇时间, 停浇时间]
|