自动化立体仓库 - WCS系统
#
luxiaotao1123
2020-11-23 b53dff5d5ee6ab0d4ab138e14be643843869d00d
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,15 @@
        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);
                }
                Thread.sleep(1000);
                Thread.sleep(100);
            } catch (SocketTimeoutException ignore) {
            } catch (Exception e) {
                e.printStackTrace();
//                e.printStackTrace();
            }
        }
    }
@@ -97,7 +100,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;
@@ -124,6 +127,16 @@
        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 {
        BarcodeThread barcodeThread = new BarcodeThread(new Slave());
        barcodeThread.getSlave().setIp("192.168.2.150");
@@ -131,7 +144,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));
    }
}