自动化立体仓库 - WCS系统
pang.jiabao
昨天 e9a5f5c065e7232e9d5ca1f2a4948d2f8e6e0c03
src/main/java/com/zy/core/thread/SiemensDevpThread.java
@@ -43,10 +43,15 @@
    private short heartBeatVal = 1;
    private StaError1 staError1;
    public static final ArrayList<Integer> staNos = new ArrayList<Integer>() {{
        add(1002);add(1020);add(1035);add(103);
        add(104);add(105);add(106);add(107);
        add(200);add(201);add(202);add(203);add(210);
        add(300);add(301);add(302);add(303);add(304);add(305);
        add(1001);add(1002);add(1004);add(1005);add(1006);add(1007);add(1008);add(1009);add(1010);add(1011);add(1012);
        add(1041);add(1042);add(1043);add(1013);add(1014);add(1015);add(1016);add(1017);add(1018);add(1019);add(1020);
        add(1034);add(1035);add(1036);add(1038);add(1039);add(1040);
        add(1022);add(1023);add(1024);add(1025);add(1026);add(1027);add(1028);add(1030);add(1031);add(1032);add(1033);
        add(1044);add(1045);add(1046);add(1047);add(1049);add(1050);add(1051);add(1052);add(1053);add(1054);add(1056);add(1057);
        add(1061);add(1063);add(1064);add(1065);add(1066);add(1067);add(1068);add(1073);add(1074);add(1075);add(1077);add(1078);add(1079);
        add(1081);add(1082);add(1083);add(1084);add(1085);add(1086);add(1087);add(1088);add(1089);add(1090);
        add(1091);add(1092);add(1093);add(1094);add(1095);add(1096);add(1097);add(1098);add(1099);add(1100);add(1101);add(1102);add(1103);add(1104);
        add(1105);add(1106);add(1107);
    }};
    public static final ArrayList<Integer> BarcodeList = new ArrayList<Integer>() {{
@@ -55,6 +60,9 @@
    public static final ArrayList<Integer> staNosErrList = new ArrayList<Integer>() {{
        add(101); add(103);
    }};
    // 罐装线要桶标识
    private volatile Map<Integer,String> wantBucketFlag =  new HashMap<>();
    /**
     * 条码数量
@@ -105,10 +113,6 @@
                        write((StaProtocol)task.getData());
//                        log.error("输送线下发命令:"+((StaProtocol) task.getData()).getWorkNo()+","+((StaProtocol) task.getData()).getStaNo());
                        break;
                    // 写开门
                    case 3:
                        write2((Integer) task.getData());
                        break;
                    default:
                        break;
                }
@@ -119,44 +123,6 @@
                e.printStackTrace();
            }
        }
    }
    private void write2(int flag) throws InterruptedException {
        if (flag == 0) {
            OperateResultExOne<byte[]> readOpenResult = siemensS7Net.Read("DB100.826", (short) 1);
            if (readOpenResult.IsSuccess) {
                boolean[] booleans = siemensS7Net.getByteTransform().TransBool(readOpenResult.Content, 0, 1);
                booleans[1] = true; // 关门信号
                booleans[0] = false;
                siemensS7Net.Write("DB100.826",booleans);
                log.info("下发关门信号成功:" + Arrays.toString(booleans));
            }
        } else if(flag == 1) {
            OperateResultExOne<byte[]> readOpenResult = siemensS7Net.Read("DB100.826", (short) 1);
            if (readOpenResult.IsSuccess) {
                boolean[] booleans = siemensS7Net.getByteTransform().TransBool(readOpenResult.Content, 0, 1);
                booleans[0] = true; // 开门信号
                booleans[1] = false;
                siemensS7Net.Write("DB100.826",booleans);
                log.info("下发开门信号成功:" + Arrays.toString(booleans));
            }
        }
        Thread.sleep(500);
        OperateResultExOne<byte[]> readOpenResult = siemensS7Net.Read("DB100.826", (short) 1);
        if (readOpenResult.IsSuccess) {
            boolean[] booleans = siemensS7Net.getByteTransform().TransBool(readOpenResult.Content, 0, 1);
            StaProtocol staProtocol = station.get(305);
            if (null == staProtocol) {
                staProtocol = new StaProtocol();
                staProtocol.setSiteId(305);
                station.put(305, staProtocol);
            }
            staProtocol.setOpenAskDoor(booleans[0]);
            staProtocol.setCloseAskDoor(booleans[1]);
            staProtocol.setIfOpenDoor(booleans[2]);
            staProtocol.setIfCloseDoor(booleans[3]);
            log.info("下发开关门后回读:" + Arrays.toString(booleans));
        }
    }
@@ -211,10 +177,10 @@
     * 读取状态 ====> 整块plc
     */
    private void read() throws InterruptedException {
//        // 更新入出库模式
//        updateIoMode();
//        ArrayList<Integer> staNos = getStaNo();
//        int staNoSize = staNos.size();
        wantBucketFlag.clear();
        //todo 读取罐装线PLC要桶标识
        wantBucketFlag.put(1,"IBC");
        // 读一楼连续8个站点
        OperateResultExOne<byte[]> result = siemensS7Net.Read("DB101.0", (short) (8*8));
        if (result.IsSuccess) {
@@ -245,112 +211,6 @@
                }
            }
        }
        // 读二楼连续4个站点
        OperateResultExOne<byte[]> result2 = siemensS7Net.Read("DB101.800", (short) (4*8));
        if (result2.IsSuccess) {
            for (int i = 8; i < 12; i++) {
                Integer siteId = staNos.get(i); // 站点编号
                StaProtocol staProtocol = station.get(siteId);
                if (null == staProtocol) {
                    staProtocol = new StaProtocol();
                    staProtocol.setSiteId(siteId);
                    station.put(siteId, staProtocol);
                }
                staProtocol.setWorkNo(siemensS7Net.getByteTransform().TransInt32(result2.Content, (i-8)*8));     // 工作号
                staProtocol.setStaNo(siemensS7Net.getByteTransform().TransInt16(result2.Content, (i-8)*8 + 4));   // 目标站
                boolean[] status = siemensS7Net.getByteTransform().TransBool(result2.Content, (i-8)*8 + 6, 2);
                staProtocol.setAutoing(status[0]);  // 自动
                staProtocol.setLoading(status[1]);  // 有物
                staProtocol.setInEnable(status[2]); // 可入
                staProtocol.setOutEnable(status[3]);// 可出
                staProtocol.setEmptyMk(status[4]);  // 空板信号
                staProtocol.setFullPlt(status[5]);  // 满托盘
                staProtocol.setHigh(status[6]);     // 高库位
                staProtocol.setLow(status[7]);      // 低库位
                if (!staProtocol.isPakMk() && !staProtocol.isLoading()) {
                    staProtocol.setPakMk(true);
                }
            }
        }
        // 读二楼210
        OperateResultExOne<byte[]> result3 = siemensS7Net.Read("DB101.880", (short) (8));
        if (result3.IsSuccess) {
                Integer siteId = staNos.get(12); // 站点编号210
                StaProtocol staProtocol = station.get(siteId);
                if (null == staProtocol) {
                    staProtocol = new StaProtocol();
                    staProtocol.setSiteId(siteId);
                    station.put(siteId, staProtocol);
                }
                staProtocol.setWorkNo(siemensS7Net.getByteTransform().TransInt32(result3.Content, 0));     // 工作号
                staProtocol.setStaNo(siemensS7Net.getByteTransform().TransInt16(result3.Content, 4));   // 目标站
                boolean[] status = siemensS7Net.getByteTransform().TransBool(result3.Content, 6, 2);
                staProtocol.setAutoing(status[0]);  // 自动
                staProtocol.setLoading(status[1]);  // 有物
                staProtocol.setInEnable(status[2]); // 可入
                staProtocol.setOutEnable(status[3]);// 可出
                staProtocol.setEmptyMk(status[4]);  // 空板信号
                staProtocol.setFullPlt(status[5]);  // 满托盘
                staProtocol.setHigh(status[6]);     // 高库位
                staProtocol.setLow(status[7]);      // 低库位
                if (!staProtocol.isPakMk() && !staProtocol.isLoading()) {
                    staProtocol.setPakMk(true);
                }
        }
        // 读二楼3区
        OperateResultExOne<byte[]> result4 = siemensS7Net.Read("DB101.1600", (short) (6*8));
        if (result2.IsSuccess) {
            for (int i = 13; i < staNos.size(); i++) {
                Integer siteId = staNos.get(i); // 站点编号
                StaProtocol staProtocol = station.get(siteId);
                if (null == staProtocol) {
                    staProtocol = new StaProtocol();
                    staProtocol.setSiteId(siteId);
                    station.put(siteId, staProtocol);
                }
                staProtocol.setWorkNo(siemensS7Net.getByteTransform().TransInt32(result4.Content, (i-13)*8));     // 工作号
                staProtocol.setStaNo(siemensS7Net.getByteTransform().TransInt16(result4.Content, (i-13)*8 + 4));   // 目标站
                boolean[] status = siemensS7Net.getByteTransform().TransBool(result4.Content, (i-13)*8 + 6, 2);
                staProtocol.setAutoing(status[0]);  // 自动
                staProtocol.setLoading(status[1]);  // 有物
                staProtocol.setInEnable(status[2]); // 可入
                staProtocol.setOutEnable(status[3]);// 可出
                staProtocol.setEmptyMk(status[4]);  // 空板信号
                staProtocol.setFullPlt(status[5]);  // 满托盘
                staProtocol.setHigh(status[6]);     // 高库位
                staProtocol.setLow(status[7]);      // 低库位
                if (!staProtocol.isPakMk() && !staProtocol.isLoading()) {
                    staProtocol.setPakMk(true);
                }
            }
        }
//        BasRgvMapService basRgvMapService = SpringUtils.getBean(BasRgvMapService.class);
        //RGV小车1
//        Thread.sleep(100);
//        OperateResultExOne<byte[]> result3 = siemensS7Net.Read("DB50.200",(short)10);
//        if (result3.IsSuccess) {
//            BasRgvMap basRgvMap = basRgvMapService.selectByRgvNo((int) siemensS7Net.getByteTransform().TransInt16(result3.Content, 0));
//            if (!Cools.isEmpty(basRgvMap)){
//                Integer siteId = 1;
//                StaProtocol staProtocol = station.get(siteId);
//                if (null == staProtocol) {
//                    staProtocol = new StaProtocol();
//                    staProtocol.setSiteId(siteId);
//                    station.put(siteId, staProtocol);
//                }
//                staProtocol.setAutoing(true);
//                staProtocol.setNearbySta(String.valueOf(siemensS7Net.getByteTransform().TransInt16(result3.Content, 8)));
//            }
//        }
        // 条码扫描器
        OperateResultExOne<byte[]> barcodeResult = siemensS7Net.Read("DB101.1672", (short) ((BarcodeList.size()+1) * 8)); // 不连续
@@ -396,145 +256,6 @@
            }
        }
        // 读二楼连续4个站点,故障信息反馈
        OperateResultExOne<byte[]> resultErr3 = siemensS7Net.Read("DB101.3512", (short) (4*2));
        if (resultErr3.IsSuccess) {
            for (int i = 8; i < 12; i++) {
                boolean[] status = siemensS7Net.getByteTransform().TransBool(resultErr3.Content, (i-8) * 2 + 1, 1);
                StaProtocol staProtocol = station.get(staNos.get(i)); // 站点编号
                staProtocol.setBreakerErr(status[0]);
                staProtocol.setInfraredErr(status[1]);
                staProtocol.setOutTimeErr(status[2]);
                staProtocol.setSeizeSeatErr(status[3]);
                staProtocol.setWrkYgoodsN(status[4]);
                staProtocol.setInverterErr(status[5]);
                staProtocol.setContactErr(status[6]);
                staProtocol.setUpcontactErr(status[7]);
            }
        }
        // 读三区故障信息反馈
        OperateResultExOne<byte[]> resultErr4 = siemensS7Net.Read("DB101.2096", (short) (6*2));
        if (resultErr4.IsSuccess) {
            for (int i = 13; i < staNos.size(); i++) {
                boolean[] status = siemensS7Net.getByteTransform().TransBool(resultErr4.Content, (i-13) * 2 + 1, 1);
                StaProtocol staProtocol = station.get(staNos.get(i)); // 站点编号
                staProtocol.setBreakerErr(status[0]);
                staProtocol.setInfraredErr(status[1]);
                staProtocol.setOutTimeErr(status[2]);
                staProtocol.setSeizeSeatErr(status[3]);
                staProtocol.setWrkYgoodsN(status[4]);
                staProtocol.setInverterErr(status[5]);
                staProtocol.setContactErr(status[6]);
                staProtocol.setUpcontactErr(status[7]);
            }
        }
        // 一楼出入库模式切换
//        OperateResultExOne<byte[]> ioModeResult = siemensS7Net.Read("DB101.3724", (short) 1);
//        if (ioModeResult.IsSuccess) {
//            boolean[] ioModelBooleans = siemensS7Net.getByteTransform().TransBool(ioModeResult.Content, 0, 1);
////            log.info("读取出入库模式:" + Arrays.toString(ioModelBooleans));
//            WrkMastService wrkMastService = SpringUtils.getBean(WrkMastService.class);
//            if (ioModelBooleans[0]) { // 100切入库
//                if (ioModeOf101 == IoModeType.PAKOUT_MODE) {
//                    int outCount = wrkMastService.selectCount(new EntityWrapper<WrkMast>().eq("io_type", 101)
//                            .eq("sta_no", 100).in("wrk_sts", 12, 13, 14));
//                    if (outCount == 0) {
//                        boolean[] booleans = new boolean[8];
//                        booleans[0]=true;
//                        ioModeOf101 = IoModeType.PAKIN_MODE;
//                        siemensS7Net.Write("DB100.824",booleans);
//                        log.info("101切换入库模式成功");
//                    }
//                }
//            }
//            if (ioModelBooleans[1]) { // 100切出库
//                if (ioModeOf101 == IoModeType.PAKIN_MODE) {
//                    int inCount = wrkMastService.selectCount(new EntityWrapper<WrkMast>().eq("io_type", 1)
//                            .eq("sta_no", 101).in("wrk_sts", 2, 3, 4));
//                    if (inCount == 0) {
//                        boolean[] booleans = new boolean[8];
//                        booleans[0]=true;
//                        ioModeOf101 = IoModeType.PAKOUT_MODE;
//                        siemensS7Net.Write("DB100.824",booleans);
//                        log.info("101切换出库模式成功");
//                    }
//                }
//            }
//            if (ioModelBooleans[2]) { // 102切入库
//                if (ioModeOf103 == IoModeType.PAKOUT_MODE) {
//                    int outCount = wrkMastService.selectCount(new EntityWrapper<WrkMast>().eq("io_type", 101)
//                            .eq("sta_no", 102).in("wrk_sts", 12, 13, 14));
//                    if (outCount == 0) {
//                        boolean[] booleans = new boolean[8];
//                        booleans[1]=true;
//                        ioModeOf103 = IoModeType.PAKIN_MODE;
//                        siemensS7Net.Write("DB100.824",booleans);
//                        log.info("103切换入库模式成功");
//                    }
//                }
//            }
//            if (ioModelBooleans[3]) { // 102切出库
//                if (ioModeOf103 == IoModeType.PAKIN_MODE) {
//                    int inCount = wrkMastService.selectCount(new EntityWrapper<WrkMast>().eq("io_type", 1)
//                            .eq("sta_no", 103).in("wrk_sts", 2, 3, 4));
//                    if (inCount == 0) {
//                        boolean[] booleans = new boolean[8];
//                        booleans[1]=true;
//                        ioModeOf103 = IoModeType.PAKOUT_MODE;
//                        siemensS7Net.Write("DB100.824",booleans);
//                        log.info("103切换出库模式成功");
//                    }
//                }
//            }
//        }
        // 读开门信号
//        OperateResultExOne<byte[]> readOpenResult = siemensS7Net.Read("DB100.826", (short) 1);
//        if (readOpenResult.IsSuccess) {
//            boolean[] booleans = siemensS7Net.getByteTransform().TransBool(readOpenResult.Content, 0, 1);
//            StaProtocol staProtocol = station.get(305);
//            if (null == staProtocol) {
//                staProtocol = new StaProtocol();
//                staProtocol.setSiteId(305);
//                station.put(305, staProtocol);
//            }
//            staProtocol.setOpenAskDoor(booleans[0]);
//            staProtocol.setCloseAskDoor(booleans[1]);
//            staProtocol.setIfOpenDoor(booleans[2]);
//            staProtocol.setIfCloseDoor(booleans[3]);
////            log.info("开门信号:" + Arrays.toString(booleans));
//        }
////        OperateResultExOne<byte[]> resultErr3 = siemensS7Net.Read("DB13.400", (short) 3);
////        if (resultErr3.IsSuccess) {
////            if (staError1 == null){
////                staError1 = new StaError1();
//            }
//            boolean[] status = siemensS7Net.getByteTransform().TransBool(resultErr3.Content, 0, 3);
//            staError1.setEMERGENCY_Stop_Core(status[0]);
//            staError1.setEMERGENCY_STOP1(status[1]);
//            staError1.setEMERGENCY_STOP2(status[2]);
//            staError1.setEMERGENCY_STOP3(status[3]);
//            staError1.setEMERGENCY_STOP4(status[4]);
//
//            staError1.setDoor_EMERGENCY_STOP1(status[5]);
//            staError1.setDoor_EMERGENCY_STOP2(status[6]);
//            staError1.setDoor_EMERGENCY_STOP3(status[7]);
//            staError1.setDoor_EMERGENCY_STOP4(status[8]);
//            staError1.setDoor_EMERGENCY_STOP5(status[9]);
//            staError1.setDoor_EMERGENCY_STOP6(status[10]);
//
//            staError1.setDoor_Open_Err1(status[11]);
//            staError1.setDoor_Open_Err1(status[12]);
//            staError1.setDoor_Open_Err1(status[13]);
//            staError1.setDoor_Open_Err1(status[14]);
//            staError1.setDoor_Open_Err1(status[15]);
//            staError1.setDoor_Open_Err1(status[16]);
//
//        }
        if (result.IsSuccess) {
@@ -629,16 +350,6 @@
        }
    }
    // 更新入出库模式
    private void updateIoMode() throws InterruptedException {
//        if (this.ioModeOf2F != IoModeType.NONE) {
//            if (!siemensS7Net.Write("DB100.180", this.ioModeOf2F.id).IsSuccess) {
//                OutputQueue.DEVP.offer(MessageFormat.format("【{0}】写入输送线2F入出库模式失败。输送线plc编号={1}", slave.getId()));
//                News.error("SiemensDevp"+" - 6"+" - 写入输送线2F入出库模式失败。输送线plc编号={}", slave.getId());
//            }
//        }
    }
    /**
     * 心跳
     */
@@ -675,7 +386,6 @@
        slave.setIp("10.10.10.18");
        SiemensDevpThread devpThread = new SiemensDevpThread(slave);
        devpThread.connect();
        devpThread.write2(0);
        devpThread.read();
//        // 写
//        StaProtocol staProtocol = devpThread.getStation().get(1);