#
pang.jiabao
2024-06-06 220508203309f181f14cb551f9195134b89211ac
src/main/java/com/zy/core/thread/SiemensDevpThread.java
@@ -9,11 +9,11 @@
import com.core.common.DateUtils;
import com.core.common.SpringUtils;
import com.core.exception.CoolException;
import com.zy.asrs.entity.BasDevp;
import com.zy.asrs.entity.BasRgvMap;
import com.zy.asrs.service.BasDevpService;
import com.zy.asrs.service.BasRgvMapService;
import com.zy.common.utils.News;
import com.zy.entity.BasDevp;
import com.zy.entity.BasRgvMap;
import com.zy.service.BasDevpService;
import com.zy.service.BasRgvMapService;
import com.zy.utils.News;
import com.zy.core.DevpThread;
import com.zy.core.cache.MessageQueue;
import com.zy.core.cache.OutputQueue;
@@ -22,6 +22,7 @@
import com.zy.core.enums.SlaveType;
import com.zy.core.model.DevpSlave;
import com.zy.core.model.Task;
import com.zy.core.model.protocol.StaError1;
import com.zy.core.model.protocol.StaProtocol;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
@@ -45,43 +46,31 @@
    private SiemensS7Net siemensS7Net;
    private Map<Integer, StaProtocol> station = new ConcurrentHashMap<>();
    private short heartBeatVal = 1;
    private StaError1 staError1;
//    public static final ArrayList<Integer> staNos = new ArrayList<Integer>() {{
//
//    }};
    public static final ArrayList<Integer> staNos1 = new ArrayList<Integer>() {{
        add(100);add(101);add(102);add(103);
        add(104);add(105);add(106);add(107);
        add(108);add(109);add(110);add(111);
        add(112);add(113);add(114);add(115);
        add(116);add(117);add(118);add(119);
        add(120);add(121);add(122);add(123);
        add(124);add(125);add(126);add(127);
        add(128);add(129);add(130);add(131);
        add(132);add(133);add(134);add(135);
        add(136);add(137);add(138);add(139);
        add(140);add(141);add(142);add(143);
        add(144);add(145);add(146);add(147);
        add(148);add(149);add(150);add(151);
        add(152);add(153);add(154);add(155);
        add(156);add(157);add(158);add(159);
        add(160);add(161);
        add(1);
//        add(200);add(201);add(202);
        add(104);add(105);add(106);
    }};
    public static final ArrayList<Integer> staNos2 = new ArrayList<Integer>() {{
        add(200);add(201);add(202);add(203);add(210);
        add(300);add(301);add(302);add(303);add(304);add(305);
    }};
    public static final ArrayList<Integer> BarcodeList = new ArrayList<Integer>() {{
        add(0); add(1); add(2);
        add(0); add(1);
    }};
    public static final ArrayList<Integer> staNosErrList = new ArrayList<Integer>() {{
        add(106); add(107); add(159);
        add(100); add(102);
    }};
    private Integer count=0;
    /**
     * 条码数量
     */
    private int barcodeSize = 6;
    private int barcodeSize = 2;
    /**
     * 入出库模式
@@ -91,9 +80,11 @@
     * 3.出库启动中 (不能生成入库工作档)
     * 4.出库模式
     */
    public IoModeType ioModeOf2F = IoModeType.NONE;
    public IoModeType ioModeOf101 = IoModeType.NONE;
    public IoModeType ioModeOf103 = IoModeType.NONE;
    public IoModeType ioModeOf305 = IoModeType.NONE;
//    public IoModeType ioMode = IoModeType.NONE;
    public IoModeType ioModeOf4F = IoModeType.NONE;
//    public IoModeType ioModeOf4F = IoModeType.NONE;
//    public IoModeType ioMode = IoModeType.NONE;
    public SiemensDevpThread(DevpSlave slave) {
@@ -104,6 +95,8 @@
        switch (slave.getId()) {
            case 1:
                return staNos1;
            case 2:
                return staNos2;
            default:
                throw new CoolException("服务器异常");
        }
@@ -135,7 +128,7 @@
                }
                // 心跳
//                heartbeat();
                Thread.sleep(300);
                Thread.sleep(100);
            } catch (Exception e) {
                e.printStackTrace();
            }
@@ -146,9 +139,7 @@
     * 初始化站点状态
     */
    private void initSite() {
        count ++;
        ArrayList<Integer> staNos = getStaNo();
        if(count > 77) {
            // 站点编号
            for (Integer siteId : staNos) {
                StaProtocol staProtocol = station.get(siteId);
@@ -169,8 +160,6 @@
                    staProtocol.setPakMk(true);
                }
            }
            count = 0;
        }
    }
    @Override
@@ -232,7 +221,7 @@
        }
        BasRgvMapService basRgvMapService = SpringUtils.getBean(BasRgvMapService.class);
        //RGV小车1
        Thread.sleep(100);
//        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));
@@ -246,41 +235,6 @@
                }
                staProtocol.setAutoing(true);
                staProtocol.setNearbySta(String.valueOf(siemensS7Net.getByteTransform().TransInt16(result3.Content, 8)));
            }
        }
        //RGV小车2
        Thread.sleep(100);
        OperateResultExOne<byte[]> result4 = siemensS7Net.Read("DB50.212",(short)10);
        if (result4.IsSuccess) {
            BasRgvMap basRgvMap = basRgvMapService.selectByRgvNo((int) siemensS7Net.getByteTransform().TransInt16(result4.Content, 0));
            if (!Cools.isEmpty(basRgvMap)){
                Integer siteId = 2;
                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(result4.Content, 8)));
            }
        }
        //RGV小车3
        Thread.sleep(100);
        OperateResultExOne<byte[]> result5 = siemensS7Net.Read("DB50.224",(short)10);
        if (result5.IsSuccess) {
            BasRgvMap basRgvMap = basRgvMapService.selectByRgvNo((int) siemensS7Net.getByteTransform().TransInt16(result5.Content, 0));
            if (!Cools.isEmpty(basRgvMap)){
                Integer siteId = 3;
                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(result5.Content, 8)));
            }
        }
@@ -302,7 +256,7 @@
        int staNoErrsSize = staNoErrs.size();
        OperateResultExOne<byte[]> resultErr = siemensS7Net.Read("DB101.800", (short) (staNoErrsSize*8));
        if (resultErr.IsSuccess){
            for (int i = 0;i<3;i++){
            for (int i = 0;i<staNoErrsSize;i++){
                Integer siteId = staNoErrs.get(i); // 站点编号
                boolean[] status = siemensS7Net.getByteTransform().TransBool(resultErr.Content, i*4+2, 1);
                StaProtocol staProtocol = station.get(siteId);
@@ -317,10 +271,10 @@
        }
        OperateResultExOne<byte[]> resultErr2 = siemensS7Net.Read("DB13.2", (short) (staNoSize*4));
        if (resultErr.IsSuccess) {
        if (resultErr2.IsSuccess) {
            for (int i = 0; i < staNoSize; i++) {
                Integer siteId = staNos.get(i); // 站点编号
                boolean[] status = siemensS7Net.getByteTransform().TransBool(resultErr.Content, i*4, 1);
                boolean[] status = siemensS7Net.getByteTransform().TransBool(resultErr2.Content, i*4, 1);
                StaProtocol staProtocol = station.get(siteId);
                staProtocol.setBreakerErr(status[0]);
                staProtocol.setInfraredErr(status[1]);
@@ -332,6 +286,33 @@
                staProtocol.setUpcontactErr(status[7]);
            }
        }
        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]);
        }
@@ -380,7 +361,7 @@
        do {
            write = siemensS7Net.Write("DB100." + index*6, staProtocol.getWorkNo());    // 工作号
            Thread.sleep(200);
            write1 = siemensS7Net.Write("DB100." + (index*6+4), staProtocol.getStaNo().shortValue());    // 目标站
            write1 = siemensS7Net.Write("DB100." + (index*6+4), staProtocol.getStaNo());    // 目标站
            if(write.IsSuccess && write1.IsSuccess){
                break;
            }
@@ -405,12 +386,12 @@
    // 更新入出库模式
    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());
            }
        }
//        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());
//            }
//        }
    }
    /**