Junjie
2023-06-10 a9d4000e3b8ad44ffbea3064d2d6cf0d1350c30d
src/main/java/com/zy/core/thread/SiemensDevpThread.java
@@ -42,11 +42,11 @@
    private SiemensS7Net siemensS7Net;
    private Map<Integer, StaProtocol> station = new ConcurrentHashMap<>();
    private short heartBeatVal = 1;
    private int barcodeSize = 2;
    private int barcodeSize = 1;
    public static final ArrayList<Integer> staNos = new ArrayList<Integer>() {{
        add(100);add(101);add(102);
        add(200);add(201);add(202);
        add(300);add(301);add(302);
        add(103);add(104);add(105);
        add(106);add(107);add(108);
    }};
    public boolean charge0;
@@ -132,7 +132,7 @@
            }
        }
        Thread.sleep(200);
        OperateResultExOne<byte[]> result1 = siemensS7Net.Read("DB102.100", (short) (staNos.size()));
        OperateResultExOne<byte[]> result1 = siemensS7Net.Read("DB101.0", (short) (staNos.size()));
        if (result1.IsSuccess) {
            for (int i = 0; i < staNos.size(); i++) {
                Integer siteId = staNos.get(i); // 站点编号
@@ -155,7 +155,7 @@
        //读条码
        Thread.sleep(100);
        OperateResultExOne<byte[]> result2 = siemensS7Net.Read("DB100.150",(short)24);
        OperateResultExOne<byte[]> result2 = siemensS7Net.Read("DB100.200",(short)24);
        if (result2.IsSuccess) {
            for (int i = 0; i <= barcodeSize; i++) {
                String barcode = siemensS7Net.getByteTransform().TransString(result2.Content,i*8,8, "UTF-8");
@@ -195,38 +195,37 @@
            staProtocol.setWeightErr(status[5]); // 超重
            staProtocol.setBarcodeErr(status[6]);// 扫码失败
        }
        // 外形检测 - 201
        Thread.sleep(50);
        OperateResultExOne<byte[]> result201 = siemensS7Net.Read("DB102.112", (short)1);
        if (result201.IsSuccess) {
            boolean[] status = siemensS7Net.getByteTransform().TransBool(result201.Content, 0, 1);
            StaProtocol staProtocol = station.get(201);
            staProtocol.setFrontErr(status[0]);
            staProtocol.setBackErr(status[1]);
            staProtocol.setHighErr(status[2]);
            staProtocol.setLeftErr(status[3]);
            staProtocol.setRightErr(status[4]);
            staProtocol.setWeightErr(status[5]);
            staProtocol.setBarcodeErr(status[6]);
        }
        // 外形检测 - 301
        Thread.sleep(50);
        OperateResultExOne<byte[]> result301 = siemensS7Net.Read("DB102.114", (short)1);
        if (result301.IsSuccess) {
            boolean[] status = siemensS7Net.getByteTransform().TransBool(result301.Content, 0, 1);
            StaProtocol staProtocol = station.get(301);
            staProtocol.setFrontErr(status[0]);
            staProtocol.setBackErr(status[1]);
            staProtocol.setHighErr(status[2]);
            staProtocol.setLeftErr(status[3]);
            staProtocol.setRightErr(status[4]);
            staProtocol.setWeightErr(status[5]);
            staProtocol.setBarcodeErr(status[6]);
        }
//        // 外形检测 - 201
//        Thread.sleep(50);
//        OperateResultExOne<byte[]> result201 = siemensS7Net.Read("DB102.112", (short)1);
//        if (result201.IsSuccess) {
//            boolean[] status = siemensS7Net.getByteTransform().TransBool(result201.Content, 0, 1);
//            StaProtocol staProtocol = station.get(201);
//            staProtocol.setFrontErr(status[0]);
//            staProtocol.setBackErr(status[1]);
//            staProtocol.setHighErr(status[2]);
//            staProtocol.setLeftErr(status[3]);
//            staProtocol.setRightErr(status[4]);
//            staProtocol.setWeightErr(status[5]);
//            staProtocol.setBarcodeErr(status[6]);
//        }
//        // 外形检测 - 301
//        Thread.sleep(50);
//        OperateResultExOne<byte[]> result301 = siemensS7Net.Read("DB102.114", (short)1);
//        if (result301.IsSuccess) {
//            boolean[] status = siemensS7Net.getByteTransform().TransBool(result301.Content, 0, 1);
//            StaProtocol staProtocol = station.get(301);
//            staProtocol.setFrontErr(status[0]);
//            staProtocol.setBackErr(status[1]);
//            staProtocol.setHighErr(status[2]);
//            staProtocol.setLeftErr(status[3]);
//            staProtocol.setRightErr(status[4]);
//            staProtocol.setWeightErr(status[5]);
//            staProtocol.setBarcodeErr(status[6]);
//        }
        if (result.IsSuccess && result1.IsSuccess) {
            OutputQueue.DEVP.offer(MessageFormat.format("【{0}】[id:{1}] <<<<< 实时数据更新成功",DateUtils.convert(new Date()), slave.getId()));
            // 根据实时信息更新数据库
@@ -250,6 +249,33 @@
//            News.error("读取输送线plc状态信息失败 ===>> [id:{}] [ip:{}] [port:{}] [rack:{}] [slot:{}]", slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot());
        }
    }
    /**
     * plc与提升机交互
     */
    private void write4(Integer siteId, Integer direction) throws InterruptedException {
        if (Cools.isEmpty(siteId, direction)) {
            return;
        }
        switch (siteId) {
            case 102:
                siemensS7Net.Write("DB100.300", direction.shortValue());
                break;
            case 105:
                siemensS7Net.Write("DB100.302", direction.shortValue());
                break;
            case 106:
                siemensS7Net.Write("DB100.304", direction.shortValue());
                break;
            case 107:
                siemensS7Net.Write("DB100.306", direction.shortValue());
                break;
            case 108:
                siemensS7Net.Write("DB100.308", direction.shortValue());
                break;
        }
    }
    /**
     * 写入 ID+目标站 =====> 单站点写入
     */