自动化立体仓库 - WCS系统
##
luxiaotao1123
2020-12-30 9fd40b787bdd4e0caaed213d1931d9c7fb8f846c
src/main/java/com/zy/core/thread/MelsecDevpThread.java
@@ -72,7 +72,7 @@
                }
                // 心跳
                heartbeat();
//                heartbeat();
                Thread.sleep(400);
            } catch (Exception e) {
                e.printStackTrace();
@@ -95,6 +95,9 @@
            log.error("输送线plc连接失败!!! ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
        }
        melsecMcNet.ConnectClose();
        try {
            Thread.sleep(1000);
        } catch (InterruptedException ignore) {}
        return result;
    }
@@ -105,7 +108,7 @@
        OperateResultExOne<byte[]> result = melsecMcNet.Read("D101", (short) 30);
        if (result.IsSuccess) {
            // 站点数据
            for (int i = 1; i <= staNos.size(); i++) {
            for (int i = 0; i < staNos.size(); i++) {
                Integer siteId = staNos.get(i); // 站点编号
                StaProtocol staProtocol = station.get(siteId);
                if (null == staProtocol) {
@@ -113,20 +116,22 @@
                    staProtocol.setSiteId(siteId);
                    station.put(siteId, staProtocol);
                }
                staProtocol.setWorkNo(melsecMcNet.getByteTransform().TransInt16(result.Content, (i-1)*2));     // 工作号
                staProtocol.setStaNo(melsecMcNet.getByteTransform().TransInt16(result.Content, (i-1)*2+40));   // 目标站
                short workNo = melsecMcNet.getByteTransform().TransInt16(result.Content, (i) * 2);
                staProtocol.setWorkNo(workNo==-1?0:workNo);     // 工作号
                staProtocol.setStaNo(melsecMcNet.getByteTransform().TransInt16(result.Content, (i)*2+40));   // 目标站
            }
        }
        Thread.sleep(3000);
        Thread.sleep(200);
        OperateResultExOne<boolean[]> result1 = melsecMcNet.ReadBool("M800", (short) 64);
        if (result1.IsSuccess) {
            for (int i = 1; i <= 7; i++) {
                StaProtocol staProtocol = station.get(i);
                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]);  // 空板信号
            for (int i = 0; i < staNos.size(); i++) {
                Integer siteId = staNos.get(i); // 站点编号
                StaProtocol staProtocol = station.get(siteId);
                staProtocol.setAutoing(result1.Content[(i)*8]);  // 自动
                staProtocol.setLoading(result1.Content[(i)*8+1]);  // 有物
                staProtocol.setInEnable(result1.Content[(i)*8+2]); // 可入
                staProtocol.setOutEnable(result1.Content[(i)*8+3]);// 可出
                staProtocol.setEmptyMk(result1.Content[(i)*8+4]);  // 空板信号
                if (!staProtocol.isPakMk() && !staProtocol.isLoading()) {
                    staProtocol.setPakMk(true);
@@ -175,9 +180,10 @@
        if (null == staProtocol) {
            return;
        }
        OperateResult write = melsecMcNet.Write("D1" + Utils.zerofill(String.valueOf(staNos.indexOf(staProtocol.getSiteId())+1), 2), staProtocol.getWorkNo());    // 工作号
        Thread.sleep(400);
        System.out.println();
        OperateResult write1 = melsecMcNet.Write("D1" + Utils.zerofill(String.valueOf(staNos.indexOf(staProtocol.getSiteId())+21), 2), staProtocol.getStaNo());    // 目标站
        Thread.sleep(200);
        OperateResult write = melsecMcNet.Write("D1" + Utils.zerofill(String.valueOf(staNos.indexOf(staProtocol.getSiteId())+1), 2), staProtocol.getWorkNo());    // 工作号
        if (!write.IsSuccess || !write1.IsSuccess) {
            staProtocol = station.get(staProtocol.getSiteId());
            if (staProtocol.getWorkNo() == 0 && staProtocol.getStaNo() ==0) {
@@ -186,7 +192,6 @@
            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));
        }