自动化立体仓库 - WCS系统
#
luxiaotao1123
2022-03-16 6f3dba8f0db1e0992d9c755fd232b4a5c4d5b66c
src/main/java/com/zy/core/thread/BarcodeThread.java
@@ -1,8 +1,11 @@
package com.zy.core.thread;
import com.alibaba.fastjson.JSONObject;
import com.core.common.Cools;
import com.core.common.DateUtils;
import com.zy.core.Slave;
import com.zy.core.ThreadHandler;
import com.zy.core.cache.OutputQueue;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
@@ -13,6 +16,7 @@
import java.net.Socket;
import java.net.SocketAddress;
import java.net.SocketTimeoutException;
import java.util.Date;
/**
 * 条码扫描仪线程
@@ -43,6 +47,11 @@
                    String s = new String(read);
                    if (!Cools.isEmpty(s)) {
                        barcode = new String(read);
                        log.info("{}号条码器,检索数据:{}", slave.getId(), this.barcode);
                        JSONObject jsonObject = new JSONObject();
                        jsonObject.put("time", DateUtils.convert(new Date(), DateUtils.yyyyMMddHHmmss_F));
                        jsonObject.put("barcode", barcode);
                        OutputQueue.BARCODE.offer(jsonObject);
                    }
                }
                Thread.sleep(100);
@@ -76,18 +85,18 @@
    public void close() {
        try {
            if (null != dataOutputStream) {
            dataOutputStream.close();
        }
        if (null != dataInputStream) {
            dataInputStream.close();
        }
                dataOutputStream.close();
            }
            if (null != dataInputStream) {
                dataInputStream.close();
            }
//        if (null != socket && !socket.isClosed()) {
//            socket.close();
//        }
        if (null != socket){
            socket.close();
        }
        socket = null;
            if (null != socket){
                socket.close();
            }
            socket = null;
        } catch (IOException e) {
            log.error("SocketClient close Exception:" + e.getMessage());
        }
@@ -111,8 +120,8 @@
        int len = dataInputStream.read(bytes);
        byte[] tempBytes = null;
        if (len > 0) {
        tempBytes = new byte[len];
        System.arraycopy(bytes, 0, tempBytes, 0, len);
            tempBytes = new byte[len];
            System.arraycopy(bytes, 0, tempBytes, 0, len);
        }
        return tempBytes;
    }