Ver código fonte

增加五号机直轧功能,修复bug

oldwine 5 meses atrás
pai
commit
368d497e34
4 arquivos alterados com 92 adições e 38 exclusões
  1. 1 0
      conf/5#nodes.csv
  2. 5 5
      main.py
  3. 74 24
      models/billet_trace_pusher.py
  4. 12 9
      models/data_sender.py

+ 1 - 0
conf/5#nodes.csv

@@ -36,3 +36,4 @@ L5
 L6µ²°å,bool,136,40,0,1,TRUE,FALSE,500
 L7µ²°å,bool,137,40,0,1,TRUE,FALSE,500
 L8µ²°å,bool,138,40,0,1,TRUE,FALSE,500
+ÈÈË͵²°å,boollist,130,72,0,1,TRUE,FALSE,500

+ 5 - 5
main.py

@@ -45,7 +45,7 @@ logger_6.info('[PREPARE]6#机PLC连接成功')
 ##############################################################
 # MQTT数据源配置
 
-mqtt_mes = MqttClient('python-mqtt-biller_digitalization', 'readonly', '1qazxsw@')
+mqtt_mes = MqttClient('python-mqtt-biller_digitalization_test3', 'readonly', '1qazxsw@')
 mqtt_mes.connect('192.168.12.201', 1883)
 mqtt_mes.loop_start()
 data_mes = Mqttdata()
@@ -53,7 +53,7 @@ data_mes.set_mqtt_client(mqtt_mes)
 logger_5.info('[PREPARE]与MES使用MQTT连接成功')
 logger_6.info('[PREPARE]与MES使用MQTT连接成功')
 
-mqtt_web = MqttClient('python-mqtt-992')
+mqtt_web = MqttClient('python-mqtt-992_test3')
 mqtt_web.connect('192.168.0.119', 1883)
 mqtt_web.loop_start()
 data_web = Mqttdata()
@@ -65,7 +65,7 @@ logger_sender.info('[PREPARE]与WEB业务平台使用MQTT连接成功')
 # 数据发送服务
 
 sender = Sender(logger_sender)
-sender.set_mqtt_client(mqtt_web)
+#sender.set_mqtt_client(mqtt_web)
 
 # debug设置
 sender.http_flag = False
@@ -77,8 +77,8 @@ sender.http_flag = False
 position_5 = [10462, 11553, 12671, 14020, 31641, 16412, 17229, 18809]
 position_6 = [7610, 9175, 10425, 11700, 13000, 14350, 15577, 16952]
 
-pusher_5 = Trace_pusher(data_5, logger_5, sender, position_5)
+pusher_5 = Trace_pusher(data_5, logger_5, sender, position_5, True)
 pusher_6 = Trace_pusher(data_6, logger_6, sender, position_6)
 
 flfp_5 = Counter(data_mes, data_5, 5, logger_5, sender, pusher_5)
-flfp_6 = Counter(data_mes, data_6, 6, logger_6, sender, pusher_6)
+flfp_6 = Counter(data_mes, data_6, 6, logger_6, sender, pusher_6)

+ 74 - 24
models/billet_trace_pusher.py

@@ -4,20 +4,14 @@ 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):
+    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.billets_wait = []
-        for i in range(8):
-            tmp = self.data_s7.make_point('推钢机激光')
-            tmp.allow_update(False)
-            tmp.set_state(False)
-            self.billets_wait.append(tmp)
+        self.hostsend_flag = hostsend_flag
         
         self.old_heatNo = "00000000"
         self.current_heatNo = "00000000"
@@ -52,6 +46,18 @@ class Trace_pusher:
             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)
@@ -59,6 +65,13 @@ class Trace_pusher:
             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):
@@ -76,6 +89,47 @@ class Trace_pusher:
                 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':
@@ -89,14 +143,7 @@ class Trace_pusher:
                 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.old_heatNo = self.current_heatNo
-                            self.old_heatData = self.current_heatData
-                            self.current_heatNo = i[0][:8]
-                            self.current_heatData = i[1]
-                            # 上一炉终止信号在这里发
-                            self.total = 0
-                            self.strand = [0, 0, 0, 0, 0, 0, 0, 0]
+                            self.change_heat(i)
                             break
 
                     tmp = self.bed_left
@@ -114,14 +161,7 @@ class Trace_pusher:
                 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.old_heatNo = self.current_heatNo
-                            self.old_heatData = self.current_heatData
-                            self.current_heatNo = i[0][:8]
-                            self.current_heatData = i[1]
-                            # 上一炉终止信号在这里发
-                            self.total = 0
-                            self.strand = [0, 0, 0, 0, 0, 0, 0, 0]
+                            self.change_heat(i)
                             break
 
                     tmp = self.bed_right
@@ -151,5 +191,15 @@ class Trace_pusher:
                 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}")
+
 
 # [坯号, 炉次信息, 定尺, 拉速, 开浇时间, 停浇时间]

+ 12 - 9
models/data_sender.py

@@ -105,15 +105,18 @@ class Sender:
         self.send('heat_add', tmp)
 
     def end_pour(self, heat_data):
-        tmp = self._cache[heat_data['heatNo']]
-        tmp['optype'] = 2
-        tmp['grade'] = heat_data.get('grade', '')
-        tmp['spec'] = heat_data.get('spec', '')
-        tmp['stopPourTime'] = heat_data.get('sendTime', '')
-
-        #此处应存储进数据库,暂时使用缓存处理
-        self._cache[heat_data.get('heatNo', 'error')] = tmp
-        self.send('heat_add', tmp)
+        if heat_data['heatNo'] in self._cache:
+            tmp = self._cache[heat_data['heatNo']]
+            tmp['optype'] = 2
+            tmp['grade'] = heat_data.get('grade', '')
+            tmp['spec'] = heat_data.get('spec', '')
+            tmp['stopPourTime'] = heat_data.get('sendTime', '')
+
+            #此处应存储进数据库,暂时使用缓存处理
+            self._cache[heat_data.get('heatNo', 'error')] = tmp
+            self.send('heat_add', tmp)
+        else:
+            self.logger.error(f"[SENDER]停浇:找不到对应的开浇数据,炉号:{heat_data['heatNo']}")
 
     def heat_first(self, heat_data, cuttime = None):
         if not cuttime: