自动化立体仓库 - WCS系统
#
luxiaotao1123
2020-08-19 bc0a69ea4a4fb49dadc02bf548d8f3fd3f60d18a
src/main/java/com/zy/core/thread/DevpThread.java
@@ -31,12 +31,12 @@
    public DevpThread(Slave slave) {
        this.slave = slave;
        connect();
    }
    @Override
    @SuppressWarnings("InfiniteLoopStatement")
    public void run() {
        connect();
        while (true) {
            try {
                int step = 1;
@@ -56,6 +56,9 @@
                    default:
                        break;
                }
                // 心跳
                heartbeat();
                Thread.sleep(400);
            } catch (Exception e) {
                e.printStackTrace();
@@ -82,7 +85,7 @@
    }
    /**
     * 读取状态
     * 读取状态 ====> 整块plc
     */
    private void read(){
        OperateResultExOne<byte[]> result = siemensS7Net.Read("DB100.0", (short) 40);
@@ -111,7 +114,7 @@
    }
    /**
     * 写入
     * 写入 =====> 单站点写入
     */
    private void write(StaProtocol staProtocol){
        if (null == staProtocol) {
@@ -131,6 +134,16 @@
        }
    }
    /**
     * 心跳
     */
    private void heartbeat(){
        OperateResult write = siemensS7Net.Write("DB100.50", (short) 1);
        if (!write.IsSuccess) {
            log.error("输送线plc编号={} 心跳失败", slave.getId());
        }
    }
    @Override
    public void close() {
        siemensS7Net.ConnectClose();
@@ -140,12 +153,13 @@
        Slave slave = new Slave();
        slave.setIp("192.168.2.125");
        DevpThread devpThread = new DevpThread(slave);
        devpThread.connect();
        devpThread.read();
        // 写
        StaProtocol staProtocol = devpThread.getStation().get(1);
        staProtocol.setWorkNo((short) 222);
        staProtocol.setStaNo((short) 2);
        staProtocol.setAutoing(false);
        staProtocol.setWorkNo((short) 232);
        staProtocol.setStaNo((short) 6);
        staProtocol.setAutoing(true);
        staProtocol.setEmptyMk(true);
        staProtocol.setInEnable(true);
        devpThread.write(staProtocol);