#
lsh
2022-10-26 864068a49c985982577808e49ba2fe0b7a698839
src/main/java/com/zy/core/thread/SiemensDevpThread.java
@@ -42,9 +42,8 @@
    private Map<Integer, StaProtocol> station = new ConcurrentHashMap<>();
    private short heartBeatVal = 1;
    public static final ArrayList<Integer> staNos = new ArrayList<Integer>() {{
        add(101);add(102);add(103);add(104);
        add(201);add(202);add(203);add(204);
        add(301);add(302);add(303);add(304);add(305);add(306);
        add(101);add(102);add(103);add(104);add(105);add(106);add(107);add(108);add(109);add(110);add(111);add(112);
        add(201);add(202);add(203);add(204);add(205);add(206);add(207);add(208);add(209);add(210);add(211);add(212);
    }};
    /**
@@ -124,7 +123,7 @@
     */
    private void read() throws InterruptedException {
//        // 更新入出库模式
        updateIoMode();
//        updateIoMode();
        int staNoSize = staNos.size();
        OperateResultExOne<byte[]> result = siemensS7Net.Read("DB100.0", (short) (staNoSize*4));
        if (result.IsSuccess) {
@@ -143,11 +142,11 @@
        }
        Thread.sleep(200);
        OperateResultExOne<byte[]> result1 = siemensS7Net.Read("DB100.100", (short) (staNoSize));
        OperateResultExOne<byte[]> result1 = siemensS7Net.Read("DB100.100", (short) (staNoSize*2));
        if (result1.IsSuccess) {
            for (int i = 0; i < staNoSize; i++) {
                Integer siteId = staNos.get(i); // 站点编号
                boolean[] status = siemensS7Net.getByteTransform().TransBool(result1.Content, i, 1);
                boolean[] status = siemensS7Net.getByteTransform().TransBool(result1.Content, i*2, 1);
                StaProtocol staProtocol = station.get(siteId);
                staProtocol.setAutoing(status[0]);  // 自动
                staProtocol.setLoading(status[1]);  // 有物
@@ -164,23 +163,23 @@
            }
        }
        //条码
        Thread.sleep(200);
        OperateResultExOne<byte[]> result2 = siemensS7Net.Read("DB100.160",(short)4);
        if (result2.IsSuccess) {
            for (int i = 0; i < barcodeSize; i++) {
                String barcode = siemensS7Net.getByteTransform().TransString(result2.Content,i*8,8, "UTF-8");
                BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, i + 1);
                if(!Cools.isEmpty(barcodeThread) && !barcodeThread.getBarcode().equals(barcode)) {
                    barcodeThread.setBarcode(barcode);
                }
            }
        }
//            //条码
//            Thread.sleep(200);
//            OperateResultExOne<byte[]> result2 = siemensS7Net.Read("DB100.160",(short)4);
//            if (result2.IsSuccess) {
//                for (int i = 0; i < barcodeSize; i++) {
//                    String barcode = siemensS7Net.getByteTransform().TransString(result2.Content,i*8,8, "UTF-8");
//                    BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, i + 1);
//                    if(!Cools.isEmpty(barcodeThread) && !barcodeThread.getBarcode().equals(barcode)) {
//                        barcodeThread.setBarcode(barcode);
//                    }
//                }
//
//            }
        //RGV台车位置
        Thread.sleep(200);
        OperateResultExOne<byte[]> result3 = siemensS7Net.Read("DB100.150",(short)(barcodeSize*8));
        OperateResultExOne<byte[]> result3 = siemensS7Net.Read("DB100.160",(short)4);
        if (result3.IsSuccess) {
            for (int i = 0; i < 2; i++) {
                Integer siteId = i==0 ? 112 : 212; // 站点编号
@@ -190,7 +189,9 @@
                    staProtocol.setSiteId(siteId);
                    station.put(siteId, staProtocol);
                }
                staProtocol.setNearbySta(String.valueOf(siemensS7Net.getByteTransform().TransInt16(result.Content, i*2)));
                staProtocol.setNearbySta(String.valueOf(siemensS7Net.getByteTransform().TransInt16(result3.Content, i*2)));
//                String aa = staProtocol.getNearbySta();
//                System.out.println(siteId + "===>>" + staProtocol.getNearbySta());
            }
        }
@@ -254,6 +255,12 @@
        } else {
            OutputQueue.DEVP.offer(MessageFormat.format("【{0}】 输送线命令下发 [id:{1}] >>>>> {2}", DateUtils.convert(new Date()), slave.getId(), JSON.toJSON(staProtocol)));
            log.info("输送线命令下发 [id:{}] >>>>> 命令下发: {}",  slave.getId(), JSON.toJSON(staProtocol));
            Integer siteId = staProtocol.getSiteId();
            staProtocol = station.get(siteId);
            if ((siteId == 101 || siteId == 201)&&(staProtocol.getWorkNo() == 0 && staProtocol.getStaNo() ==0)) {
                staProtocol.setPakMk(true);
            }
        }
    }