| | |
| | | //根据设备目标状态,调用MODBUS执行 |
| | | addrExe = Integer.valueOf(temp) - 1; |
| | | modbusTcp.setAddrExe(addrExe); |
| | | doExe(modbusTcp, device.getTargetStatus()); |
| | | doWriteExe(modbusTcp, device.getTargetStatus()); |
| | | continue; |
| | | } |
| | | |
| | |
| | | addrExe = Integer.valueOf(temp) - 1; |
| | | modbusTcp.setAddrExe(addrExe); |
| | | |
| | | doExe(modbusTcp, DeviceStatus.OPEN.getCode()); |
| | | doWriteExe(modbusTcp, DeviceStatus.OPEN.getCode()); |
| | | |
| | | |
| | | Thread.sleep(300); |
| | |
| | | addrExe = Integer.valueOf(temp) - 1; |
| | | modbusTcpLink.setAddrExe(addrExe); |
| | | |
| | | doExe(modbusTcpLink, DeviceStatus.OPEN.getCode()); |
| | | doWriteExe(modbusTcpLink, DeviceStatus.OPEN.getCode()); |
| | | } |
| | | |
| | | //如果关风机 |
| | |
| | | addrExe = Integer.valueOf(temp) - 1; |
| | | modbusTcpLink.setAddrExe(addrExe); |
| | | |
| | | doExe(modbusTcpLink, DeviceStatus.CLOSE.getCode()); |
| | | doWriteExe(modbusTcpLink, DeviceStatus.CLOSE.getCode()); |
| | | } |
| | | |
| | | |
| | |
| | | addrExe = Integer.valueOf(temp) - 1; |
| | | modbusTcp.setAddrExe(addrExe); |
| | | |
| | | doExe(modbusTcp, device.getTargetStatus()); |
| | | doWriteExe(modbusTcp, device.getTargetStatus()); |
| | | } |
| | | |
| | | //如果是关窗户 |
| | |
| | | temp = modbusTcpLink.getAddrClose(); |
| | | addrExe = Integer.valueOf(temp) - 1; |
| | | modbusTcpLink.setAddrExe(addrExe); |
| | | doExe(modbusTcpLink, DeviceStatus.CLOSE.getCode()); |
| | | doWriteExe(modbusTcpLink, DeviceStatus.CLOSE.getCode()); |
| | | |
| | | Thread.sleep(300); |
| | | |
| | |
| | | addrExe = Integer.valueOf(temp) - 1; |
| | | modbusTcp.setAddrExe(addrExe); |
| | | |
| | | doExe(modbusTcp, DeviceStatus.CLOSE.getCode()); |
| | | doWriteExe(modbusTcp, DeviceStatus.CLOSE.getCode()); |
| | | } |
| | | |
| | | } |
| | |
| | | return new DeviceControlResponse(OrderRespEnum.ORDER_SUCCESS); |
| | | } |
| | | |
| | | private void doExe(ModbusTcp modbusTcp, String targetStatus) throws Exception { |
| | | private void doWriteExe(ModbusTcp modbusTcp, String targetStatus) throws Exception { |
| | | boolean exeResult = modbusUtil.writeValue05(modbusTcp.getIp(), modbusTcp.getPort(), modbusTcp.getAddrExe(), true); |
| | | if (exeResult) { |
| | | ServerUtil.add2StatusMap(modbusTcp.getCompanyId(), modbusTcp.getSerId(), modbusTcp.getDeviceCode(), targetStatus); |
| | |
| | | |
| | | ModbusTcp modbusTcp; |
| | | ModbusTcp modbusTcpLink; |
| | | int addrStart; |
| | | boolean[] result; |
| | | int addrExe; |
| | | for (Device device : list) { |
| | | |
| | | if (null == device.getModbus()) continue; |
| | | |
| | | |
| | | modbusTcp = new ModbusTcp(device.getModbus()); |
| | | modbusTcp.setIp(request.getIp()); |
| | | modbusTcp.setPort(request.getPort()); |
| | | modbusTcp.setDeviceCode(device.getPassCode() + ""); |
| | | modbusTcp.setSerId(request.getSerId()); |
| | | modbusTcp.setSerId(device.getSerId()); |
| | | modbusTcp.setCompanyId(device.getCompanyId()); |
| | | |
| | | addrStart = Integer.valueOf(modbusTcp.getAddrOpenEnd()) - 1; |
| | | |
| | | result = modbusUtil.readStatus02(modbusTcp.getIp(), modbusTcp.getPort(), addrStart, 2); |
| | | log.debug("---------读取状态------{}--{}", modbusTcp.getDeviceCode(), result.toString()); |
| | | analysisResult(device.getCompanyId(), device.getSerId(), modbusTcp.getDeviceCode(), result); |
| | | if (Constant.YN_N.equals(modbusTcp.getAddrOpenEnd())) continue; |
| | | |
| | | if (null != device.getLinkModbus()) { |
| | | addrExe = Integer.valueOf(modbusTcp.getAddrOpenEnd()) - 1; |
| | | modbusTcp.setAddrExe(addrExe); |
| | | |
| | | doReadExe(modbusTcp); |
| | | |
| | | if (null == device.getLinkModbus()) continue; |
| | | |
| | | Thread.sleep(300); |
| | | |
| | | modbusTcpLink = new ModbusTcp(device.getModbus()); |
| | | modbusTcpLink.setIp(request.getIp()); |
| | | modbusTcpLink.setPort(request.getPort()); |
| | | modbusTcpLink.setSerId(request.getSerId()); |
| | | modbusTcpLink.setSerId(device.getSerId()); |
| | | modbusTcpLink.setDeviceCode(device.getLink()); |
| | | addrStart = Integer.valueOf(modbusTcpLink.getAddrOpenEnd()) - 1; |
| | | result = modbusUtil.readStatus02(modbusTcpLink.getIp(), modbusTcpLink.getPort(), addrStart, 2); |
| | | log.debug("---------读取状态-LINK------{}--{}", modbusTcpLink.getDeviceCode(), result.toString()); |
| | | modbusTcpLink.setCompanyId(device.getCompanyId()); |
| | | addrExe = Integer.valueOf(modbusTcpLink.getAddrOpenEnd()) - 1; |
| | | modbusTcpLink.setAddrExe(addrExe); |
| | | |
| | | analysisResult(device.getCompanyId(), device.getSerId(), modbusTcpLink.getDeviceCode(), result); |
| | | } |
| | | doReadExe(modbusTcpLink); |
| | | |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * 返回两位,第一位是开到位,第二位是关到位,根据这两个标记确认当前设备的状态 |
| | | * 读取状态,同时读取开状态和关闭状态 |
| | | * |
| | | * @param deviceCode |
| | | * @param result |
| | | * @param modbusTcp |
| | | * @throws Exception |
| | | */ |
| | | private void analysisResult(String companyId, String serId, String deviceCode, boolean[] result) { |
| | | private void doReadExe(ModbusTcp modbusTcp) throws Exception { |
| | | |
| | | if (Constant.YN_N.equals(modbusTcp.getAddrOpenEnd())) return; |
| | | |
| | | boolean[] result = modbusUtil.readStatus02(modbusTcp.getIp(), modbusTcp.getPort(), modbusTcp.getAddrExe(), 2); |
| | | log.debug("---------读取状态------{}--{}", modbusTcp.getDeviceCode(), result.toString()); |
| | | |
| | | if (result[0]) { |
| | | ServerUtil.add2StatusMap(companyId, serId, deviceCode, DeviceStatus.OPEN.getCode()); |
| | | ServerUtil.add2StatusMap(modbusTcp.getCompanyId(), modbusTcp.getSerId(), modbusTcp.getDeviceCode(), DeviceStatus.OPEN.getCode()); |
| | | } |
| | | if (result[1]) { |
| | | ServerUtil.add2StatusMap(companyId, serId, deviceCode, DeviceStatus.CLOSE.getCode()); |
| | | ServerUtil.add2StatusMap(modbusTcp.getCompanyId(), modbusTcp.getSerId(), modbusTcp.getDeviceCode(), DeviceStatus.CLOSE.getCode()); |
| | | } |
| | | } |
| | | |