From 81ac3e075484e2594d14aefa5848e9dbd2d87c1e Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <t1341870251@163.com>
Date: 星期五, 14 八月 2020 10:25:07 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/core/thread/BarcodeThread.java |   16 +++++++++++-----
 src/main/java/com/zy/core/thread/DevpThread.java    |    2 +-
 src/main/resources/application.yml                  |    2 +-
 3 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/src/main/java/com/zy/core/thread/BarcodeThread.java b/src/main/java/com/zy/core/thread/BarcodeThread.java
index 876c826..1687b35 100644
--- a/src/main/java/com/zy/core/thread/BarcodeThread.java
+++ b/src/main/java/com/zy/core/thread/BarcodeThread.java
@@ -38,7 +38,9 @@
             try {
                 write("T".getBytes(), "T".length());
                 byte[] read = read(11, 1000);
-                barcode = new String(read);
+                if (null != read) {
+                    barcode = new String(read);
+                }
                 Thread.sleep(1000);
             } catch (Exception e) {
                 e.printStackTrace();
@@ -85,13 +87,17 @@
     }
 
     public void write(byte[] msg, int len) throws IOException {
-        log.trace("dataOutputStream.write");
-        dataOutputStream.write(msg, 0, len);
-        log.trace("dataOutputStream.flush");
-        dataOutputStream.flush();
+        if (null != dataInputStream)
+        {
+            dataOutputStream.write(msg, 0, len);
+            dataOutputStream.flush();
+        }
     }
 
     public byte[] read(int bufferSize, int timeOut) throws IOException {
+        if (socket == null) {
+            return null;
+        }
         socket.setSoTimeout(timeOut * 1000);
         byte[] bytes = new byte[bufferSize];
         log.trace("dataInputStream.read");
diff --git a/src/main/java/com/zy/core/thread/DevpThread.java b/src/main/java/com/zy/core/thread/DevpThread.java
index 382a801..f7e1035 100644
--- a/src/main/java/com/zy/core/thread/DevpThread.java
+++ b/src/main/java/com/zy/core/thread/DevpThread.java
@@ -75,7 +75,7 @@
             result = true;
             log.info("杈撻�佺嚎plc杩炴帴鎴愬姛 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
         } else {
-            log.info("杈撻�佺嚎plc杩炴帴澶辫触锛侊紒锛� ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
+            log.error("杈撻�佺嚎plc杩炴帴澶辫触锛侊紒锛� ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
         }
         siemensS7Net.ConnectClose();
         return result;
diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml
index 023c2f3..89c53d4 100644
--- a/src/main/resources/application.yml
+++ b/src/main/resources/application.yml
@@ -59,7 +59,7 @@
   # 杈撻�佺嚎
   devp[0]:
     id: 1
-    ip: 192.168.1.125
+    ip: 192.168.2.125
     port: 102
     rack: 0
     slot: 1

--
Gitblit v1.9.1