自动化立体仓库 - WCS系统
#
luxiaotao1123
2022-09-13 d90e160a7659b21dbfd6bb225b00b86a0a68f24c
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);
@@ -66,7 +75,7 @@
//            log.info("条码扫描仪连接成功 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
        } catch (Exception e) {
            socket = null;
            log.error("条码扫描仪连接失败!!! ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
//            log.error("条码扫描仪连接失败!!! ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
            return false;
        }
        return true;
@@ -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;
    }