#
Junjie
2023-11-13 c49760bdbfa8d1f3ea17fb9f0b59a557ab38a0f9
#
5个文件已修改
120 ■■■■■ 已修改文件
src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java 27 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/core/MainProcess.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/core/ServerBootstrap.java 4 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/core/thread/BarcodeThread.java 83 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/core/thread/SiemensDevpThread.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -2287,6 +2287,33 @@
        return false;
    }
    /**
     * AGV补货(悬挂线通知AGV取货)
     */
    public void agvRestockIntoByHangingWire() {
        //检测350和351扫码器
        int[] barcodeStaNo = {10, 11};//10 => 350站扫码器,11 => 351站扫码器
        for (int staNo : barcodeStaNo) {
            // 获取条码扫描仪信息
            BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, staNo);
            if (barcodeThread == null) {
                continue;
            }
            String barcode = barcodeThread.getBarcode();
            if(!Cools.isEmpty(barcode)) {
                String agvStaNo = null;
                if (staNo == 10) {
                    agvStaNo = "303-1";
                }else {
                    agvStaNo = "304-1";
                }
                //通知AGV取货
                agvRestockCall(agvStaNo, barcode);
                log.info(staNo + "号扫码器,通知AGV取货,条码号:" + barcode);
            }
        }
    }
    // 300站拣料
    public void pick300() {
        //检测300站是否自动、有物、工作号
src/main/java/com/zy/core/MainProcess.java
@@ -76,6 +76,8 @@
                    mainService.agvRestockByRobot();
                    // AGV补货(通知AGV取货)
                    mainService.agvRestockInto();
                    // AGV补货(悬挂线通知AGV取货)
                    mainService.agvRestockIntoByHangingWire();
                    // 300站拣料
                    mainService.pick300();
                    // 出库  ===>> 工作档信息写入led显示器
src/main/java/com/zy/core/ServerBootstrap.java
@@ -109,7 +109,9 @@
        News.info("初始化条码扫描仪线程...................................................");
        for (Slave barcode : slaveProperties.getBarcode()) {
            BarcodeThread barcodeThread = new BarcodeThread(barcode);
            new Thread(barcodeThread).start();
            if (barcode.getId() >= 11) {
                new Thread(barcodeThread).start();
            }
            SlaveConnection.put(SlaveType.Barcode, barcode.getId(), barcodeThread);
        }
        // 初始化LED线程
src/main/java/com/zy/core/thread/BarcodeThread.java
@@ -10,6 +10,13 @@
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.SocketAddress;
import java.net.SocketTimeoutException;
import java.util.Date;
/**
@@ -22,6 +29,10 @@
    private Slave slave;
    private StringBuffer barcode = new StringBuffer();
    private Socket socket;
    private DataOutputStream dataOutputStream;
    private DataInputStream dataInputStream;
    public Integer connCount = 0;
    public BarcodeThread(Slave slave) {
        this.slave = slave;
@@ -48,17 +59,83 @@
    @Override
    public boolean connect() {
        return false;
        try {
            close();  //1.主动释放连接 //2.某些服务器对指定ip有链路数限制
            socket = new Socket();
            SocketAddress socketAddress = new InetSocketAddress(slave.getIp(), slave.getPort());
            socket.connect(socketAddress, 1000); //某些服务器ping延迟高时要增加,否则会报错connect timeout
            dataOutputStream = new DataOutputStream(socket.getOutputStream());
            dataInputStream = new DataInputStream(socket.getInputStream());
//            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());
            return false;
        }
        return true;
    }
    @Override
    public void close() {
        try {
            if (null != dataOutputStream) {
                dataOutputStream.close();
            }
            if (null != dataInputStream) {
                dataInputStream.close();
            }
            if (null != socket){
                socket.close();
            }
            socket = null;
        } catch (IOException e) {
            log.error("SocketClient close Exception:" + e.getMessage());
        }
    }
    @Override
    @SuppressWarnings("InfiniteLoopStatement")
    public void run() {
        connect();
        while (true) {
            try {
                byte[] read = read(14, 5000);
                if (null != read) {
                    String s = new String(read);
                    if (!Cools.isEmpty(s)) {
                        setBarcode(new String(read));
                    }
                }else{
                    setBarcode("");
                }
                Thread.sleep(50);
            } catch (SocketTimeoutException ignore) {
                connCount++;
            } catch (Exception e) {
                setBarcode("");
                e.printStackTrace();
            }
        }
    }
    public byte[] read(int bufferSize, int timeOut) throws IOException {
        if (socket == null || !socket.isConnected() || socket.isClosed() || connCount > 120) {
            connect();
            connCount = 0;
            return null;
        }
        socket.setSoTimeout(timeOut);
        byte[] bytes = new byte[bufferSize];
        int len = dataInputStream.read(bytes);
        byte[] tempBytes = null;
        if (len > 0) {
            tempBytes = new byte[len];
            System.arraycopy(bytes, 0, tempBytes, 0, len);
        } else {
            connect();
        }
        return tempBytes;
    }
}
src/main/java/com/zy/core/thread/SiemensDevpThread.java
@@ -180,6 +180,10 @@
        OperateResultExOne<byte[]> result2 = siemensS7Net.Read("DB1000.200", (short) 98);
        if (result2.IsSuccess) {
            for (int i = 0; i < barcodeSize; i++) {
                if (i >= 10) {
                    continue;
                }
                String barcode = null;
                if (i == 8) {
                    barcode = siemensS7Net.getByteTransform().TransString(result2.Content,i*8,13, "UTF-8");