jiazx0107@163.com
2023-08-22 3f8f9133c3f0072f9c61428c0fb921b8021c990d
igds-protocol-modbus/src/main/java/com/ld/igds/protocol/modbus/command/RemoteControlServiceImpl.java
@@ -60,7 +60,6 @@
            ModbusTcp modbusTcp;
            ModbusTcp modbusTcpLink = null;
            String temp = Constant.YN_N;
            int addrExe = 65535;
            for (ExeDevice exeDevice : deviceList) {
                device = deviceService.getCacheDeviceById(exeDevice.getCompanyId(), exeDevice.getId());
@@ -95,8 +94,7 @@
                if (null == modbusTcpLink) {
                    //根据设备目标状态,调用MODBUS执行
                    addrExe = Integer.valueOf(temp) - 1;
                    modbusTcp.setAddrExe(addrExe);
                    modbusTcp.setAddrExe(this.getAddrExe(temp));
                    doWriteExe(modbusTcp, device.getTargetStatus());
                    continue;
                }
@@ -107,8 +105,7 @@
                    //先开窗口
                    temp = modbusTcp.getAddrOpen();
                    addrExe = Integer.valueOf(temp) - 1;
                    modbusTcp.setAddrExe(addrExe);
                    modbusTcp.setAddrExe(this.getAddrExe(temp));
                    doWriteExe(modbusTcp, DeviceStatus.OPEN.getCode());
@@ -117,8 +114,7 @@
                    //再开风机
                    temp = modbusTcpLink.getAddrOpen();
                    addrExe = Integer.valueOf(temp) - 1;
                    modbusTcpLink.setAddrExe(addrExe);
                    modbusTcpLink.setAddrExe(this.getAddrExe(temp));
                    doWriteExe(modbusTcpLink, DeviceStatus.OPEN.getCode());
                }
@@ -126,8 +122,7 @@
                //如果关风机
                if (DeviceStatus.F_CLOSE.equals(device.getTargetStatus())) {
                    temp = modbusTcpLink.getAddrClose();
                    addrExe = Integer.valueOf(temp) - 1;
                    modbusTcpLink.setAddrExe(addrExe);
                    modbusTcpLink.setAddrExe(this.getAddrExe(temp));
                    doWriteExe(modbusTcpLink, DeviceStatus.CLOSE.getCode());
                }
@@ -136,8 +131,7 @@
                //如果开窗
                if (DeviceStatus.W_OPEN.equals(device.getTargetStatus())) {
                    temp = modbusTcp.getAddrOpen();
                    addrExe = Integer.valueOf(temp) - 1;
                    modbusTcp.setAddrExe(addrExe);
                    modbusTcp.setAddrExe(this.getAddrExe(temp));
                    doWriteExe(modbusTcp, device.getTargetStatus());
                }
@@ -147,16 +141,14 @@
                    //先关风机
                    temp = modbusTcpLink.getAddrClose();
                    addrExe = Integer.valueOf(temp) - 1;
                    modbusTcpLink.setAddrExe(addrExe);
                    modbusTcpLink.setAddrExe(this.getAddrExe(temp));
                    doWriteExe(modbusTcpLink, DeviceStatus.CLOSE.getCode());
                    Thread.sleep(300);
                    //在关窗户
                    temp = modbusTcp.getAddrClose();
                    addrExe = Integer.valueOf(temp) - 1;
                    modbusTcp.setAddrExe(addrExe);
                    modbusTcp.setAddrExe(this.getAddrExe(temp));
                    doWriteExe(modbusTcp, DeviceStatus.CLOSE.getCode());
                }
@@ -170,6 +162,14 @@
        return new DeviceControlResponse(OrderRespEnum.ORDER_SUCCESS);
    }
    private int getAddrExe(String temp) {
        if (Constant.YN_N.equals(temp)) return 65535;
        if (temp.length() > 4) {
            temp = temp.substring(temp.length() - 4);
        }
        return Integer.valueOf(temp) - 1;
    }
    private void doWriteExe(ModbusTcp modbusTcp, String targetStatus) throws Exception {
        boolean exeResult = modbusUtil.writeValue05(modbusTcp.getIp(), modbusTcp.getPort(), modbusTcp.getAddrExe(), true);
        if (exeResult) {