自动化立体仓库 - WCS系统
#
18516761980
2022-08-30 e6eb8d8dc97c1fb40581ffa1d5b17ecc37d39e2e
src/main/java/com/zy/core/thread/SiemensDevpThread.java
@@ -5,14 +5,15 @@
import HslCommunication.Profinet.Siemens.SiemensPLCS;
import HslCommunication.Profinet.Siemens.SiemensS7Net;
import com.alibaba.fastjson.JSON;
import com.core.common.Cools;
import com.core.common.DateUtils;
import com.core.common.SpringUtils;
import com.zy.asrs.entity.BasDevp;
import com.zy.asrs.service.BasDevpService;
import com.zy.asrs.service.WrkMastService;
import com.zy.core.DevpThread;
import com.zy.core.cache.MessageQueue;
import com.zy.core.cache.OutputQueue;
import com.zy.core.cache.SlaveConnection;
import com.zy.core.enums.IoModeType;
import com.zy.core.enums.SlaveType;
import com.zy.core.model.DevpSlave;
@@ -41,17 +42,25 @@
    private Map<Integer, StaProtocol> station = new ConcurrentHashMap<>();
    private short heartBeatVal = 1;
    public static final ArrayList<Integer> staNos = new ArrayList<Integer>() {{
        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(101);add(102);add(103);add(104);add(105);add(106);add(107);add(108);add(109);add(110);add(111);add(112);
        add(201);add(202);add(203);add(204);add(205);add(206);add(207);add(208);add(209);add(210);add(211);add(212);
    }};
    public IoModeType ioMode = IoModeType.NONE;
    /**
     * 182站堆垛机执行中出库数量
     * 条码数量
     */
    public int PRE_COUNT=0;
    private int barcodeSize = 3;
    /**
     * 入出库模式
     * 0:未知
     * 1:入库启动中
     * 2.入库模式
     * 3.出库启动中 (不能生成入库工作档)
     * 4.出库模式
     */
    public IoModeType ioModeOf2F = IoModeType.NONE;
//    public IoModeType ioMode = IoModeType.NONE;
    public SiemensDevpThread(DevpSlave slave) {
        this.slave = slave;
@@ -115,9 +124,10 @@
    private void read() throws InterruptedException {
//        // 更新入出库模式
//        updateIoMode();
        OperateResultExOne<byte[]> result = siemensS7Net.Read("DB100.0", (short) 144);
        int staNoSize = staNos.size();
        OperateResultExOne<byte[]> result = siemensS7Net.Read("DB100.0", (short) (staNoSize*4));
        if (result.IsSuccess) {
            for (int i = 0; i < 36; i++) {
            for (int i = 0; i < staNoSize; i++) {
                Integer siteId = staNos.get(i); // 站点编号
                StaProtocol staProtocol = station.get(siteId);
                if (null == staProtocol) {
@@ -130,26 +140,13 @@
                staProtocol.setStaNo(siemensS7Net.getByteTransform().TransInt16(result.Content, i*4 + 2));   // 目标站
            }
        }
//        Thread.sleep(200);
//        OperateResultExOne<byte[]> result0 = siemensS7Net.Read("DB101.0", (short) 186);
//        if (result0.IsSuccess) {
//            for (int i = 0; i < 93; 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.setStaNo(siemensS7Net.getByteTransform().TransInt16(result0.Content, i*2));   // 目标站
//            }
//        }
        Thread.sleep(200);
        OperateResultExOne<byte[]> result1 = siemensS7Net.Read("DB150.0", (short) 72);
        OperateResultExOne<byte[]> result1 = siemensS7Net.Read("DB100.100", (short) (staNoSize));
        if (result1.IsSuccess) {
            for (int i = 0; i < 36; i++) {
            for (int i = 0; i < staNoSize; i++) {
                Integer siteId = staNos.get(i); // 站点编号
                boolean[] status = siemensS7Net.getByteTransform().TransBool(result1.Content, i*2, 1);
                boolean[] status = siemensS7Net.getByteTransform().TransBool(result1.Content, i, 1);
                StaProtocol staProtocol = station.get(siteId);
                staProtocol.setAutoing(status[0]);  // 自动
                staProtocol.setLoading(status[1]);  // 有物
@@ -163,6 +160,38 @@
                if (!staProtocol.isPakMk() && !staProtocol.isLoading()) {
                    staProtocol.setPakMk(true);
                }
            }
        }
//            //条码
//            Thread.sleep(200);
//            OperateResultExOne<byte[]> result2 = siemensS7Net.Read("DB100.160",(short)4);
//            if (result2.IsSuccess) {
//                for (int i = 0; i < barcodeSize; i++) {
//                    String barcode = siemensS7Net.getByteTransform().TransString(result2.Content,i*8,8, "UTF-8");
//                    BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, i + 1);
//                    if(!Cools.isEmpty(barcodeThread) && !barcodeThread.getBarcode().equals(barcode)) {
//                        barcodeThread.setBarcode(barcode);
//                    }
//                }
//
//            }
        //RGV台车位置
        Thread.sleep(200);
        OperateResultExOne<byte[]> result3 = siemensS7Net.Read("DB100.160",(short)4);
        if (result3.IsSuccess) {
            for (int i = 0; i < 2; i++) {
                Integer siteId = i==0 ? 112 : 212; // 站点编号
                StaProtocol staProtocol = station.get(siteId);
                if (null == staProtocol) {
                    staProtocol = new StaProtocol();
                    staProtocol.setSiteId(siteId);
                    station.put(siteId, staProtocol);
                }
                staProtocol.setNearbySta(String.valueOf(siemensS7Net.getByteTransform().TransInt16(result3.Content, i*2)));
//                String aa = staProtocol.getNearbySta();
//                System.out.println(siteId + "===>>" + staProtocol.getNearbySta());
            }
        }
@@ -207,7 +236,7 @@
            return;
        }
        int index = staNos.indexOf(staProtocol.getSiteId());
        short[] array = new short[10];
        short[] array = new short[2];
        array[0] = staProtocol.getWorkNo();
        array[1] = staProtocol.getStaNo();
        OperateResult write = siemensS7Net.Write("DB100." + index*4, array);
@@ -231,10 +260,10 @@
    // 更新入出库模式
    private void updateIoMode() throws InterruptedException {
        if (this.ioMode != IoModeType.NONE) {
            if (!siemensS7Net.Write("DB200", this.ioMode.id).IsSuccess) {
                OutputQueue.DEVP.offer(MessageFormat.format("【{0}】写入输送线1F入出库模式失败。输送线plc编号={1}", slave.getId()));
                log.error("写入输送线1F入出库模式失败。输送线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()));
                log.error("写入输送线2F入出库模式失败。输送线plc编号={}", slave.getId());
            }
        }
    }