From 2c63098b29ab54bf3cfdaeda985963c8453cbdfb Mon Sep 17 00:00:00 2001
From: pang.jiabao <pang_jiabao@163.com>
Date: 星期六, 02 十一月 2024 11:00:35 +0800
Subject: [PATCH] 堆垛机回读异常时再次下发回报未重置写入信号

---
 src/main/java/com/zy/core/thread/LedThread.java |  150 ++++++++++++++++++++++++++++++++-----------------
 1 files changed, 98 insertions(+), 52 deletions(-)

diff --git a/src/main/java/com/zy/core/thread/LedThread.java b/src/main/java/com/zy/core/thread/LedThread.java
index e5bd239..d7d061f 100644
--- a/src/main/java/com/zy/core/thread/LedThread.java
+++ b/src/main/java/com/zy/core/thread/LedThread.java
@@ -1,9 +1,7 @@
 package com.zy.core.thread;
 
-import com.alibaba.fastjson.JSON;
-import com.core.common.Cools;
-import com.zy.common.entity.Parameter;
 import com.zy.common.model.MatDto;
+import com.zy.common.utils.News;
 import com.zy.core.Slave;
 import com.zy.core.ThreadHandler;
 import com.zy.core.cache.MessageQueue;
@@ -52,8 +50,8 @@
     public LedThread(Slave slave) {
         this.slave = slave;
         try {
-//            Bx5GEnv.initial(3000);
-//            screen = new Bx5GScreenClient("my");
+            Bx5GEnv.initial(3000);
+            screen = new Bx5GScreenClient("my");
         } catch (Exception e) {
             e.printStackTrace();
             log.info("led杩炴帴鏋勯�犲櫒閿欒 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
@@ -105,6 +103,7 @@
     }
 
     private void write(List<LedCommand> list) throws Bx5GException {
+        try {
         if (!connect()) {
             return;
         }
@@ -115,24 +114,31 @@
         // 鍒涘缓涓�涓暟鎹〉
         TextBxPage page = new TextBxPage();
         for (LedCommand command : list) {
-            page.newLine(command.getTitle() +"锛�"+command.getWorkNo()+")");
-            page.newLine("搴撲綅锛�"+ (command.getIoType() < 100 ? command.getLocNo() : command.getSourceLocNo()));
-            page.newLine("鐩爣绔欙細"+command.getStaNo());
-            if (!command.isEmptyMk()) {
-                for (MatDto matDto : command.getMatDtos()) {
-                    //鍘绘帀灏忔暟鐐�
-                    String strQty = matDto.getCount().toString();
-                    int idx = strQty.lastIndexOf(".");
-                    if(idx >= 0){
-                        strQty.substring(0,idx);
-                    }
-                    page.newLine(matDto.getMaknx() + "[鏁伴噺" + strQty +"]");
+            if (command.getIoType() < 100) {
+                page.newLine(command.getTitle());
+                page.newLine("浠诲姟鍙凤細" + command.getWorkNo());
+                page.newLine("搴撲綅鍙凤細" + command.getLocNo());
+                page.newLine("鏉$爜锛�" + command.getBarcode());
+            } else {
+                page.newLine(command.getTitle() + "(" + command.getWorkNo() + ")");
+                if (!command.isEmptyMk()) {
+                    for (MatDto matDto : command.getMatDtos()) {
+                        //鍘绘帀灏忔暟鐐�
+                        String strQty = matDto.getCount().toString();
+                        int idx = strQty.lastIndexOf(".");
+                        if (idx >= 0) {
+                            strQty = strQty.substring(0, idx);
+                        }
+                        page.newLine(matDto.getMatnr());
+                        page.newLine(matDto.getMaknx());
+                        page.newLine("[鏁伴噺锛�" + strQty + "/" + matDto.getTotal().intValue() + "]");
+//                    page.newLine(matDto.getMaknx() + "[鏁伴噺" + strQty +"]");
 //                    page.newLine(matDto.getMaknx() + "銆愭暟閲�" + matDto.getCount() +"銆�");
+                    }
                 }
+                page.newLine("\n");
             }
-            page.newLine("\n");
         }
-
         // 璁剧疆瀛椾綋
         page.setFont(new Font("瀹嬩綋",Font.PLAIN,12));
         // 璁剧疆鏂囨湰棰滆壊
@@ -143,28 +149,32 @@
         area.addPage(page);
         pf.addArea(area);
         if (pf.validate() != null) {
-            log.info("pf out of range");
+            News.info("Led"+" - 2"+" - pf out of range");
         } else {
             // 鏇存柊鑺傜洰
             screen.writeProgram(pf);
 //            resetStatus = false;
         }
         close();
+        }catch (Exception e){
+
+        }
     }
 
     private void reset() throws Bx5GException {
-        if (!connect()) {
-            return;
-        }
+        try {
+            if (!connect()) {
+                return;
+            }
 //        if (resetStatus) {
 //            return;
 //        }
-        pf = new ProgramBxFile( 0, screen.getProfile());
-        pf.setFrameShow(false);
-        // 鍒嗗埆杈撳叆X锛孻锛寃idth锛宧eight
-        area = new TextCaptionBxArea( 0,0,96,48, screen.getProfile());
-        // 鍒涘缓涓�涓暟鎹〉
-        TextBxPage page = new TextBxPage();
+            pf = new ProgramBxFile(0, screen.getProfile());
+            pf.setFrameShow(false);
+            // 鍒嗗埆杈撳叆X锛孻锛寃idth锛宧eight
+            area = new TextCaptionBxArea(0, 0, 96, 48, screen.getProfile());
+            // 鍒涘缓涓�涓暟鎹〉
+            TextBxPage page = new TextBxPage();
 
 //        List<String> list = null;
 //        try {
@@ -180,26 +190,29 @@
 //            page.newLine("鑷姩鍖栫珛浣撲粨搴�");
 //            page.newLine("瑗挎牸杩堣偂浠芥湁闄愬叕鍙�");
 //        }
-        page.newLine("鍔涙簮鏅鸿兘浠撳偍");
+            page.newLine("鎹蜂紬鏅鸿兘浠撳偍");
 
-        // 璁剧疆瀛椾綋
-        page.setFont(new Font("瀹嬩綋",Font.PLAIN,13));
-        // 璁剧疆鏂囨湰棰滆壊
-        page.setForeground(Color.red);
-        // 璁剧疆鏄剧ず鐗规妧涓哄揩閫熸墦鍑�
-        page.setDisplayStyle(styles[6]);
-        area.clearPages();
-        area.addPage(page);
-        pf.addArea(area);
-        // 鏇存柊鑺傜洰
-        if (pf.validate() != null) {
-            log.info("pf out of range");
-        } else {
+            // 璁剧疆瀛椾綋
+            page.setFont(new Font("瀹嬩綋", Font.PLAIN, 13));
+            // 璁剧疆鏂囨湰棰滆壊
+            page.setForeground(Color.red);
+            // 璁剧疆鏄剧ず鐗规妧涓哄揩閫熸墦鍑�
+            page.setDisplayStyle(styles[6]);
+            area.clearPages();
+            area.addPage(page);
+            pf.addArea(area);
             // 鏇存柊鑺傜洰
-            screen.writeProgram(pf);
+            if (pf.validate() != null) {
+                News.info("Led" + " - 3" + " - pf out of range");
+            } else {
+                // 鏇存柊鑺傜洰
+                screen.writeProgram(pf);
 //            resetStatus = true;
+            }
+            close();
+        } catch (Exception e){
+
         }
-        close();
     }
 
     private void write7(List<LedCommand> list) {
@@ -212,8 +225,9 @@
             sb.append("鐩爣绔欙細").append(command.getStaNo()).append("\n");
             if (!command.isEmptyMk()) {
                 for (MatDto matDto : command.getMatDtos()) {
-                    sb.append("鐗╂枡缂栫爜锛�").append(matDto.getMatNo()).append("\n");
+                    sb.append("鐗╂枡缂栫爜锛�").append(matDto.getMatnr()).append("\n");
                     sb.append("鏁伴噺锛�").append(matDto.getCount()).append("\n");
+                    sb.append("瑙勬牸锛�").append(matDto.getSpecs()).append("\n");
                 }
             }
             sb.append("\n");
@@ -232,9 +246,41 @@
     }
 
 
-    private void error(String msg) {
-        errorMsg.delete(0, errorMsg.length());
-        errorMsg.append(msg);
+    private void error(String msg) throws Bx5GException {
+        if (slave.getId() <= 2) {
+            if (!connect()) {
+                return;
+            }
+            pf = new ProgramBxFile( 0, screen.getProfile());
+            pf.setFrameShow(false);
+            // 鍒嗗埆杈撳叆X锛孻锛寃idth锛宧eight
+            area = new TextCaptionBxArea( 0,0,96,48, screen.getProfile());
+            // 鍒涘缓涓�涓暟鎹〉
+            TextBxPage page = new TextBxPage();
+
+            page.newLine(msg);
+
+            // 璁剧疆瀛椾綋
+            page.setFont(new Font("瀹嬩綋",Font.PLAIN,12));
+            // 璁剧疆鏂囨湰棰滆壊
+            page.setForeground(Color.red);
+            // 璁剧疆鏄剧ず鐗规妧涓哄揩閫熸墦鍑�
+            page.setDisplayStyle(styles[6]);
+            area.clearPages();
+            area.addPage(page);
+            pf.addArea(area);
+            if (pf.validate() != null) {
+                News.info("Led"+" - 2"+" - pf out of range");
+            } else {
+                // 鏇存柊鑺傜洰
+                screen.writeProgram(pf);
+//            resetStatus = false;
+            }
+            close();
+        } else {
+            errorMsg.delete(0, errorMsg.length());
+            errorMsg.append(msg);
+        }
     }
 
     public void errorReset() {
@@ -250,9 +296,9 @@
         } catch (Exception ignore) {
         }
         if (connRes) {
-            log.info("led杩炴帴鎴愬姛 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
+            News.info("Led"+" - 4"+" - led杩炴帴鎴愬姛 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
         } else {
-            log.error("led杩炴帴澶辫触锛侊紒锛� ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
+            News.error("Led"+" - 5"+" - led杩炴帴澶辫触锛侊紒锛� ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
         }
         return connRes;
     }
@@ -309,7 +355,7 @@
             // 鏇存柊鑺傜洰
             if (pf.validate() != null) {
                 System.out.println("pf out of range");
-                log.info("pf out of range");
+                News.info("Led"+" - 6"+" - pf out of range");
             } else {
                 // 鏇存柊鑺傜洰
                 screen.writeProgram(pf);

--
Gitblit v1.9.1