From 2d50bb5ae8d29c604ae03003295eeafbc6078e16 Mon Sep 17 00:00:00 2001 From: luxiaotao1123 <t1341870251@163.com> Date: 星期四, 28 一月 2021 11:40:47 +0800 Subject: [PATCH] # --- src/main/java/com/zy/core/thread/BarcodeThread.java | 20 +++++++++++++------- 1 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 4bc67d7..15f8d1a 100644 --- a/src/main/java/com/zy/core/thread/BarcodeThread.java +++ b/src/main/java/com/zy/core/thread/BarcodeThread.java @@ -1,5 +1,6 @@ package com.zy.core.thread; +import com.core.common.Cools; import com.zy.core.Slave; import com.zy.core.ThreadHandler; import lombok.Data; @@ -11,6 +12,7 @@ import java.net.InetSocketAddress; import java.net.Socket; import java.net.SocketAddress; +import java.net.SocketTimeoutException; /** * 鏉$爜鎵弿浠嚎绋� @@ -36,14 +38,18 @@ connect(); while (true) { try { - write("T".getBytes(), "T".length()); - byte[] read = read(11, 1000); +// 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(1000); + Thread.sleep(100); + } catch (SocketTimeoutException ignore) { } catch (Exception e) { - e.printStackTrace(); +// e.printStackTrace(); } } } @@ -97,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; @@ -131,7 +137,7 @@ boolean connect = barcodeThread.connect(); System.out.println(connect); barcodeThread.write("T".getBytes(), "T".length()); - byte[] read = barcodeThread.read(11, 1000); + byte[] read = barcodeThread.read(11, 1); System.out.println(new String(read)); } } -- Gitblit v1.9.1