zjj
2024-05-07 ab18ecb1c25613535c2047467cf8c14d3b41b047
src/main/java/com/zy/core/thread/SiemensDevpThread.java
@@ -59,9 +59,7 @@
    }};
    public static final ArrayList<Integer> staNos3 = new ArrayList<Integer>() {{
        add(2007);add(2008);add(2009);add(2010);add(2011);add(2012);add(2013);
        add(2108);add(2109);add(2110);add(2111);add(2112);add(2113);add(2114);
        add(2401);add(2402);add(2403);
        add(5001);add(5002);
    }};
    public static final ArrayList<Integer> staNos4 = new ArrayList<Integer>() {{
@@ -88,15 +86,13 @@
    }};
    public static final ArrayList<Integer> writeStaNos2 = new ArrayList<Integer>() {{
        add(2001);add(2002);add(2003);
        add(2101);add(2102);add(2103);
        add(2301);
        add(2001);add(2002);add(2101);add(2102);add(2301);add(2302);
        add(2303);add(2304);add(2305);add(2306);add(2003);add(2004);add(2005);
        add(2006);add(2103);add(2104);add(2105);add(2106);add(2107);
    }};
    public static final ArrayList<Integer> writeStaNos3 = new ArrayList<Integer>() {{
        add(2013);
        add(2114);
        add(2401);add(2402);
        add(5001);add(5002);
    }};
    public static final ArrayList<Integer> writeStaNos4 = new ArrayList<Integer>() {{
@@ -209,7 +205,12 @@
                switch (step) {
                    // 读数据
                    case 1:
                        read();
                        if (slave.getId() ==3){
                            read30();
                        }else {
                            read();
                        }
                        break;
                    // 写数据 ID+目标站
                    case 2:
@@ -356,6 +357,66 @@
        }
    }
    private void read30() throws InterruptedException {
        ArrayList<Integer> staNos = getStaNo();
        int staNoSize = staNos.size();
        OperateResultExOne<byte[]> result = siemensS7Net.Read("DB101.0", (short) (getStaNo().size() * 8));
        result = siemensS7Net.Read("DB101.0", (short) (getStaNo().size()*4));
        if (result.IsSuccess) {
            for (int i = 0; i < staNoSize; i++) {
                Integer siteId = staNos.get(i); // 站点编号
                boolean[] status = siemensS7Net.getByteTransform().TransBool(result.Content, i*4, 1);
                short count = siemensS7Net.getByteTransform().TransInt16(result.Content, i * 4 + 2);
                StaProtocol staProtocol = station.get(siteId);
                if (null == staProtocol) {
                    staProtocol = new StaProtocol();
                    staProtocol.setSiteId(siteId);
                    station.put(siteId, staProtocol);
                }
                staProtocol.setAutoing(status[0]);  // 自动
                staProtocol.setLoading(status[1]);  // 有物
                staProtocol.setInEnable(status[2]); // 可入
                staProtocol.setOutEnable(status[3]);// 可出
                staProtocol.setForce(status[4]);
                staProtocol.setAmount(count);
                if (!staProtocol.isPakMk() && !staProtocol.isLoading()) {
                    staProtocol.setPakMk(true);
                }
            }
        }
        if (result.IsSuccess) {
            OutputQueue.DEVP.offer(MessageFormat.format("【{0}】[id:{1}] <<<<< 实时数据更新成功",DateUtils.convert(new Date()), slave.getId()));
            // 根据实时信息更新数据库
            try {
                List<BasDevp> basDevps = new ArrayList<>();
                for (Integer siteId : staNos) {
                    StaProtocol staProtocol = station.get(siteId);
                    basDevps.add(staProtocol.toSqlModel());
                }
                BasDevpService basDevpService = SpringUtils.getBean(BasDevpService.class);
                if (null != basDevpService && !basDevpService.updateBatchById(basDevps)) {
                    throw new Exception("更新数据库数据失败");
                }
            } catch (Exception e) {
                e.printStackTrace();
                OutputQueue.DEVP.offer(MessageFormat.format("【{0}】更新数据库数据失败 ===>> [id:{1}] [ip:{2}] [port:{3}] [rack:{4}] [slot:{5}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot()));
                log.error("更新数据库数据失败 ===>> [id:{}] [ip:{}] [port:{}] [rack:{}] [slot:{}]", slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot());
            }
        } else {
            OutputQueue.DEVP.offer(MessageFormat.format("【{0}】读取输送线plc状态信息失败 ===>> [id:{1}] [ip:{2}] [port:{3}] [rack:{4}] [slot:{5}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot()));
//            log.error("读取输送线plc状态信息失败 ===>> [id:{}] [ip:{}] [port:{}] [rack:{}] [slot:{}]", slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot());
        }
    }
    /**
     * 写入 ID+目标站 =====> 单站点写入
     */