luxiaotao1123
2020-12-24 87ae3eac75d472d4ac5a5a68183bf55d99d8de7b
#newVersion
1个文件已修改
69 ■■■■■ 已修改文件
src/main/java/com/zy/core/thread/MelsecDevpThread.java 69 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/core/thread/MelsecDevpThread.java
@@ -40,6 +40,7 @@
    public static final ArrayList<Integer> staNos = new ArrayList<Integer>() {{
        add(101);add(102);add(103);add(104);add(105);add(106);add(107);
    }};
    private List<Integer> errors = new ArrayList<>();
    public MelsecDevpThread(DevpSlave slave) {
        this.slave = slave;
@@ -100,56 +101,52 @@
     * 读取状态 ====> 整块plc
     */
    private void read() throws InterruptedException {
        OperateResultExOne<byte[]> result = melsecMcNet.Read("DB100.0", (short) 40);
        OperateResultExOne<byte[]> result = melsecMcNet.Read("D101", (short) 30);
        if (result.IsSuccess) {
            for (int i = 1; i <= 7; i++) {
                Integer siteId = staNos.get(i); // 站点编号
                StaProtocol staProtocol = station.get(siteId);
                StaProtocol staProtocol = station.get(i);
                if (null == staProtocol) {
                    staProtocol = new StaProtocol();
                    staProtocol.setSiteId(siteId);
                    station.put(siteId, staProtocol);
                    staProtocol.setSiteId(i);
                    station.put(i, staProtocol);
                }
                staProtocol.setWorkNo(melsecMcNet.getByteTransform().TransInt16(result.Content, (i-1)*2));     // 工作号
                staProtocol.setStaNo(melsecMcNet.getByteTransform().TransInt16(result.Content, (i-1)*2+20));   // 目标站
                staProtocol.setStaNo(melsecMcNet.getByteTransform().TransInt16(result.Content, (i-1)*2+40));   // 目标站
            }
        }
        Thread.sleep(100);
        OperateResultExOne<byte[]> result1 = melsecMcNet.Read("DB100.40", (short) 8);
        OperateResultExOne<boolean[]> result1 = melsecMcNet.ReadBool("M800", (short) 64);
        if (result1.IsSuccess) {
            for (int i = 1; i <= 8; i++) {
                boolean[] status = melsecMcNet.getByteTransform().TransBool(result1.Content, i-1, 1);
            for (int i = 1; i <= 7; i++) {
                StaProtocol staProtocol = station.get(i);
                staProtocol.setAutoing(status[0]);  // 自动
                staProtocol.setLoading(status[1]);  // 有物
                staProtocol.setInEnable(status[2]); // 可入
                staProtocol.setOutEnable(status[3]);// 可出
                staProtocol.setEmptyMk(status[4]);  // 空板信号
                staProtocol.setAutoing(result1.Content[(i-1)*8]);  // 自动
                staProtocol.setLoading(result1.Content[(i-1)*8+1]);  // 有物
                staProtocol.setInEnable(result1.Content[(i-1)*8+2]); // 可入
                staProtocol.setOutEnable(result1.Content[(i-1)*8+3]);// 可出
                staProtocol.setEmptyMk(result1.Content[(i-1)*8+4]);  // 空板信号
                if (!staProtocol.isPakMk() && !staProtocol.isLoading()) {
                    staProtocol.setPakMk(true);
                }
            }
        }
        // 台车位置
        OperateResultExOne<Short> result2 = melsecMcNet.ReadInt16("DB100.48");
        if (result2.IsSuccess) {
            StaProtocol staProtocol = station.get(8);
            staProtocol.setPosition(result2.Content);
        } else {
            OutputQueue.DEVP.offer(MessageFormat.format("【{0}】8号台车获取实时位置失败!!!", DateUtils.convert(new Date())));
            log.error("8号台车获取实时位置失败!!!");
        }
//        Thread.sleep(100);
//        errors.clear();
//        OperateResultExOne<boolean[]> result2 = melsecMcNet.ReadBool("M1000", (short) 21);
//        if (result2.IsSuccess) {
//            for (int i = 0; i < result2.Content.length; i++) {
//                if (result2.Content[i]) {
//                    errors.add(i);
//                }
//            }
//        }
        if (result.IsSuccess && result1.IsSuccess) {
            OutputQueue.DEVP.offer(MessageFormat.format("【{0}】[id:{1}] <<<<< 实时数据更新成功",DateUtils.convert(new Date()), slave.getId()));
            // 根据实时信息更新数据库
            try {
                List<BasDevp> basDevps = new ArrayList<>();
                for (int i = 1; i <= 8; i++) {
                for (int i = 1; i <= 7; i++) {
                    StaProtocol staProtocol = station.get(i);
                    basDevps.add(staProtocol.toSqlModel());
                }
@@ -164,7 +161,7 @@
        } else {
            OutputQueue.DEVP.offer(MessageFormat.format("【{0}】读取输送线plc状态信息失败 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort()));
            log.error("读取堆垛机plc状态信息失败 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
            log.error("读取输送线plc状态信息失败 ===>> [id:{}] [ip:{}] [port:{}] ", slave.getId(), slave.getIp(), slave.getPort());
        }
    }
@@ -175,16 +172,9 @@
        if (null == staProtocol) {
            return;
        }
        OperateResult write = melsecMcNet.Write("DB100." + (staProtocol.getSiteId() - 1) * 2, staProtocol.getWorkNo());    // 工作号
        Thread.sleep(300);
        OperateResult write1 = melsecMcNet.Write("DB100." + ((staProtocol.getSiteId() - 1) * 2 + 20), staProtocol.getStaNo());    // 目标站
//        boolean[] status = new boolean[8];
//        status[0] = staProtocol.isAutoing();
//        status[1] = staProtocol.isLoading();
//        status[2] = staProtocol.isInEnable();
//        status[3] = staProtocol.isOutEnable();
//        status[4] = staProtocol.isEmptyMk();
//        OperateResult write2 = siemensS7Net.Write("DB100." + ((staProtocol.getSiteId() - 1) + 40), status);     //  状态
        OperateResult write = melsecMcNet.Write("D10" + staProtocol.getSiteId(), staProtocol.getWorkNo());    // 工作号
        Thread.sleep(400);
        OperateResult write1 = melsecMcNet.Write("D12" + staProtocol.getSiteId(), staProtocol.getStaNo());    // 目标站
        if (!write.IsSuccess || !write1.IsSuccess) {
            staProtocol = station.get(staProtocol.getSiteId());
            if (staProtocol.getWorkNo() == 0 && staProtocol.getStaNo() ==0) {
@@ -193,6 +183,7 @@
            OutputQueue.DEVP.offer(MessageFormat.format("【{0}】写入输送线站点数据失败。输送线plc编号={1},站点数据={2}", slave.getId(), JSON.toJSON(staProtocol)));
            log.error("写入输送线站点数据失败。输送线plc编号={},站点数据={}", slave.getId(), JSON.toJSON(staProtocol));
        } else {
            log.error("-------------------------------------------第三步、[站点号:{}][工作号:{}]==>> 下发输送线启动信号成功!!",staProtocol.getSiteId(),staProtocol.getWorkNo());
            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));
        }
@@ -207,7 +198,7 @@
        } else {
            heartBeatVal = 1;
        }
        OperateResult write = melsecMcNet.Write("DB100.50", heartBeatVal);
        OperateResult write = melsecMcNet.Write("D141", heartBeatVal);
        if (!write.IsSuccess) {
            log.error("输送线plc编号={} 心跳失败", slave.getId());
        }