自动化立体仓库 - WCS系统
whycq
2022-10-18 97fb61157e1f007c00c10c01a7307b0cc374a745
src/main/java/com/zy/core/thread/SiemensDevpThread.java
@@ -8,6 +8,7 @@
import com.core.common.Cools;
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.service.BasDevpService;
import com.zy.core.DevpThread;
@@ -41,10 +42,15 @@
    private SiemensS7Net siemensS7Net;
    private Map<Integer, StaProtocol> station = new ConcurrentHashMap<>();
    private short heartBeatVal = 1;
    public static final ArrayList<Integer> staNos = new ArrayList<Integer>() {{
    public static final ArrayList<Integer> staNos1 = new ArrayList<Integer>() {{
        add(101);add(102);add(103);add(104);
        add(201);add(202);add(203);add(204);
        add(301);add(302);add(303);add(304);add(305);add(306);add(401);add(402);
        add(301);add(302);add(303);add(304);add(305);add(306);
    }};
    public static final ArrayList<Integer> staNos2 = new ArrayList<Integer>() {{
        add(401);add(402);
    }};
    /**
@@ -67,6 +73,17 @@
    public SiemensDevpThread(DevpSlave slave) {
        this.slave = slave;
    }
    private ArrayList<Integer> getStaNo() {
        switch (slave.getId()) {
            case 1:
                return staNos1;
            case 2:
                return staNos2;
            default:
                throw new CoolException("服务器异常");
        }
    }
    @Override
@@ -102,6 +119,33 @@
        }
    }
    /**
     * 初始化站点状态
     */
    private void initSite() {
        ArrayList<Integer> staNos = getStaNo();
        // 站点编号
        for (Integer siteId : staNos) {
            StaProtocol staProtocol = station.get(siteId);
            if (null == staProtocol) {
                staProtocol = new StaProtocol();
                staProtocol.setSiteId(siteId);
                station.put(siteId, staProtocol);
            }
            staProtocol.setWorkNo((short) 0);    // ID
            staProtocol.setAutoing(false);      // 自动
            staProtocol.setLoading(false);      // 有物
            staProtocol.setInEnable(false);     // 可入
            staProtocol.setOutEnable(false);    // 可出
            staProtocol.setEmptyMk(false);      // 空板信号
            staProtocol.setStaNo((short) 0);     // 目标站
            if (!staProtocol.isPakMk() && !staProtocol.isLoading()) {
                staProtocol.setPakMk(true);
            }
        }
    }
    @Override
    public boolean connect() {
        boolean result = false;
@@ -116,6 +160,7 @@
        } else {
            OutputQueue.DEVP.offer(MessageFormat.format( "【{0}】输送线plc连接失败!!! ===>> [id:{1}] [ip:{2}] [port:{3}]  [rack:{4}] [slot:{5}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot()));
            log.error("输送线plc连接失败!!! ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
            initSite();
        }
        siemensS7Net.ConnectClose();
        return result;
@@ -127,6 +172,7 @@
    private void read() throws InterruptedException {
//        // 更新入出库模式
        updateIoMode();
        ArrayList<Integer> staNos = getStaNo();
        int staNoSize = staNos.size();
        OperateResultExOne<byte[]> result = siemensS7Net.Read("DB100.0", (short) (staNoSize*4));
        if (result.IsSuccess) {
@@ -220,6 +266,7 @@
            }
        } else {
            initSite();
            OutputQueue.DEVP.offer(MessageFormat.format("【{0}】读取输送线plc状态信息失败 ===>> [id:{1}] [ip:{2}] [port:{3}] [rack:{4}] [slot:{5}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot()));
//            log.error("读取输送线plc状态信息失败 ===>> [id:{}] [ip:{}] [port:{}] [rack:{}] [slot:{}]", slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot());
        }
@@ -232,6 +279,7 @@
        if (null == staProtocol) {
            return;
        }
        ArrayList<Integer> staNos = getStaNo();
        int index = staNos.indexOf(staProtocol.getSiteId());
        short[] array = new short[2];
        array[0] = staProtocol.getWorkNo();
@@ -297,14 +345,14 @@
    }
    public static void main(String[] args) {
        System.out.println(staNos.indexOf(129));
        System.out.println(staNos.size());
        for (int i = 0; i<staNos.size(); i++) {
        System.out.println(staNos1.indexOf(129));
        System.out.println(staNos1.size());
        for (int i = 0; i< staNos1.size(); i++) {
//            System.out.println(i*2);
//            System.out.println(i*2 + 200);
//            System.out.println(i);
        }
        int index = staNos.indexOf(128);
        int index = staNos1.indexOf(128);
        System.out.println(index*2);
        System.out.println(index*2 + 200);
    }