From ee31bca5de8694a848cbfa71a9fd6ab11a5f6c14 Mon Sep 17 00:00:00 2001 From: luxiaotao1123 <t1341870251@163.com> Date: 星期四, 28 一月 2021 14:10:40 +0800 Subject: [PATCH] #双边输送线严重bug --- src/main/java/com/zy/core/thread/BarcodeThread.java | 25 ++++++++++--------------- 1 files changed, 10 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/zy/core/thread/BarcodeThread.java b/src/main/java/com/zy/core/thread/BarcodeThread.java index cd3848b..15f8d1a 100644 --- a/src/main/java/com/zy/core/thread/BarcodeThread.java +++ b/src/main/java/com/zy/core/thread/BarcodeThread.java @@ -12,6 +12,7 @@ import java.net.InetSocketAddress; import java.net.Socket; import java.net.SocketAddress; +import java.net.SocketTimeoutException; /** * 鏉$爜鎵弿浠嚎绋� @@ -37,14 +38,18 @@ connect(); while (true) { try { - write("T".getBytes(), "T".length()); - byte[] read = read(11, 5); +// write("T".getBytes(), "T".length()); + byte[] read = read(11, 200); if (null != read) { - barcode = new String(read); + String s = new String(read); + if (!Cools.isEmpty(s)) { + barcode = new String(read); + } } Thread.sleep(100); + } catch (SocketTimeoutException ignore) { } catch (Exception e) { - e.printStackTrace(); +// e.printStackTrace(); } } } @@ -98,7 +103,7 @@ if (socket == null) { return null; } - socket.setSoTimeout(timeOut * 1000); + socket.setSoTimeout(timeOut); byte[] bytes = new byte[bufferSize]; int len = dataInputStream.read(bytes); byte[] tempBytes = null; @@ -123,16 +128,6 @@ return false; } return true; - } - - public String getBarcode() { - if (Cools.isEmpty(barcode)) { - return null; - } else if("NG".endsWith(barcode)) { - return null; - } else { - return barcode.trim(); - } } public static void main(String[] args) throws Exception { -- Gitblit v1.9.1