#
luxiaotao1123
2021-01-11 9042e885de0413ccfa89d231fc77ddf70c9e58d5
src/main/java/com/zy/core/thread/SiemensDevpThread.java
@@ -45,17 +45,6 @@
        add(200);add(201);add(202);add(203);add(204);add(205);
    }};
    public static void main(String[] args) {
        for (Integer siteId : staNos) {
            int divides = (int) Arith.divides(0, siteId, 100);
            int remainder = (int) Arith.remainder(siteId, 100);
            int index = ((divides - 1) * 50) + remainder;
            System.out.print(siteId + " 任务地址 : " + index*2);
            System.out.print(" 目标地址 : " + (index*2+200) );
            System.out.println(" 状态 : " + (index+500) );
        }
    }
    public SiemensDevpThread(DevpSlave slave) {
        this.slave = slave;
    }
@@ -83,9 +72,8 @@
                    default:
                        break;
                }
                // 心跳
                heartbeat();
//                heartbeat();
                Thread.sleep(400);
            } catch (Exception e) {
                e.printStackTrace();
@@ -141,16 +129,17 @@
                Integer siteId = staNos.get(i); // 站点编号
                int divides = (int) Arith.divides(0, siteId, 100);
                int remainder = (int) Arith.remainder(siteId, 100);
                int index = ((divides - 1) * 50) + remainder;
                boolean[] status = siemensS7Net.getByteTransform().TransBool(result1.Content, i-1, 1);
                StaProtocol staProtocol = station.get(i);
                int index = ((divides - 1) * 100) + remainder;
                boolean[] status = siemensS7Net.getByteTransform().TransBool(result1.Content, index, 1);
                StaProtocol staProtocol = station.get(siteId);
                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);
@@ -191,16 +180,13 @@
        if (null == staProtocol) {
            return;
        }
        OperateResult write = siemensS7Net.Write("DB100." + (staProtocol.getSiteId() - 1) * 2, staProtocol.getWorkNo());    // 工作号
        int divides = (int) Arith.divides(0, staProtocol.getSiteId(), 100);
        int remainder = (int) Arith.remainder(staProtocol.getSiteId(), 100);
        int index = ((divides - 1) * 50) + remainder;
        OperateResult write = siemensS7Net.Write("DB100." + index*2, staProtocol.getWorkNo());    // 工作号
        Thread.sleep(300);
        OperateResult write1 = siemensS7Net.Write("DB100." + ((staProtocol.getSiteId() - 1) * 2 + 20), staProtocol.getStaNo());    // 目标站
//        boolean[] status = new boolean[8];
//        status[0] = staProtocol.isAutoing();
//        status[1] = staProtocol.isLoading();
//        status[2] = staProtocol.isInEnable();
//        status[3] = staProtocol.isOutEnable();
//        status[4] = staProtocol.isEmptyMk();
//        OperateResult write2 = siemensS7Net.Write("DB100." + ((staProtocol.getSiteId() - 1) + 40), status);     //  状态
        OperateResult write1 = siemensS7Net.Write("DB100." + (index*2 + 200), staProtocol.getStaNo());    // 目标站
        if (!write.IsSuccess || !write1.IsSuccess) {
            staProtocol = station.get(staProtocol.getSiteId());
            if (staProtocol.getWorkNo() == 0 && staProtocol.getStaNo() ==0) {
@@ -245,25 +231,25 @@
        siemensS7Net.ConnectClose();
    }
//    public static void main(String[] args) throws Exception {
//        DevpSlave slave = new DevpSlave();
//        slave.setIp("192.168.2.125");
//        SiemensDevpThread devpThread = new SiemensDevpThread(slave);
//        devpThread.connect();
//        devpThread.read();
//        // 写
//        StaProtocol staProtocol = devpThread.getStation().get(1);
//        staProtocol.setWorkNo((short) 232);
//        staProtocol.setStaNo((short) 6);
//        staProtocol.setAutoing(true);
//        staProtocol.setEmptyMk(true);
//        staProtocol.setInEnable(true);
//        devpThread.write(staProtocol);
//        System.out.println("----------------------------------------");
//        // 读
//        devpThread.read();
//        System.out.println(JSON.toJSONString(devpThread.station));
//
//    }
    public static void main(String[] args) throws Exception {
        DevpSlave slave = new DevpSlave();
        slave.setIp("192.168.2.125");
        SiemensDevpThread devpThread = new SiemensDevpThread(slave);
        devpThread.connect();
        devpThread.read();
        // 写
        StaProtocol staProtocol = devpThread.getStation().get(1);
        staProtocol.setWorkNo((short) 232);
        staProtocol.setStaNo((short) 6);
        staProtocol.setAutoing(true);
        staProtocol.setEmptyMk(true);
        staProtocol.setInEnable(true);
        devpThread.write(staProtocol);
        System.out.println("----------------------------------------");
        // 读
        devpThread.read();
        System.out.println(JSON.toJSONString(devpThread.station));
    }
}