| | |
| | | import com.ld.igds.modbus.service.HDeviceModbusService; |
| | | import com.ld.igds.models.Device; |
| | | import com.ld.igds.models.DeviceModbus; |
| | | import com.ld.igds.protocol.modbus.ModbusUtil; |
| | | import com.ld.igds.protocol.modbus.ModbusUtil2; |
| | | import com.ld.igds.protocol.modbus.ServerUtil; |
| | | import com.ld.igds.protocol.modbus.data.ModbusTcp; |
| | | import lombok.extern.slf4j.Slf4j; |
| | |
| | | private HDeviceModbusService deviceModbusService; |
| | | @Resource |
| | | private AnalysisService analysisService; |
| | | @Resource |
| | | private ModbusUtil modbusUtil; |
| | | |
| | | |
| | | @Override |
| | |
| | | temp = modbusTcp.getDeviceModbus().getOpen(); |
| | | } |
| | | |
| | | |
| | | if (StringUtils.isEmpty(exeDevice.getLink())) { |
| | | if (StringUtils.isBlank(exeDevice.getLink()) || "null".equals(exeDevice.getLink())) { |
| | | //根据设备目标状态,调用MODBUS执行 |
| | | modbusTcp.setAddrExe(this.getAddrExe(temp)); |
| | | doWriteExe(modbusTcp, exeDevice.getTargetStatus()); |
| | |
| | | } |
| | | |
| | | private void doWriteExe(ModbusTcp modbusTcp, String targetStatus) throws Exception { |
| | | boolean exeResult = modbusUtil.writeValue05(modbusTcp.getIp(), modbusTcp.getPort(), modbusTcp.getAddrExe(), true); |
| | | boolean exeResult = ModbusUtil2.writeCoilStatus(modbusTcp.getIp(), modbusTcp.getPort(), modbusTcp.getAddrExe(), true); |
| | | if (exeResult) { |
| | | log.debug("--------写入值---{}-{}-{}", modbusTcp.getSerId(), modbusTcp.getDeviceCode(), targetStatus); |
| | | ServerUtil.add2StatusMap(modbusTcp.getCompanyId(), modbusTcp.getSerId(), modbusTcp.getDeviceCode(), targetStatus); |
| | | } |
| | | } |
| | |
| | | if (null == list || list.isEmpty()) { |
| | | return new DeviceControlResponse(OrderRespEnum.ORDER_ERROR.getCode(), "未获取到设备列表信息"); |
| | | } |
| | | |
| | | DeviceModbus deviceModbus; |
| | | ModbusTcp modbusTcp; |
| | | ModbusTcp modbusTcpLink; |
| | | int i = 1; |
| | | for (Device device : list) { |
| | | |
| | | deviceModbus = deviceModbusService.getCacheDeviceModbus(request.getCompanyId(), device.getPassCode() + ""); |
| | | |
| | | if (null == deviceModbus) { |
| | |
| | | modbusTcp.setSerId(device.getSerId()); |
| | | modbusTcp.setCompanyId(device.getCompanyId()); |
| | | |
| | | // modbusTcp.setAddrExe(this.getAddrExe(modbusTcp.getDeviceModbus().getOpenEnd())); |
| | | doReadStatus(modbusTcp); |
| | | |
| | | modbusTcp.setAddrExe(1024); |
| | | doReadExe(modbusTcp); |
| | | |
| | | if (i == 1) break; |
| | | |
| | | if (StringUtils.isEmpty(device.getLink())) continue; |
| | | if (StringUtils.isBlank(device.getLink()) || "null".equals(device.getLink())) continue; |
| | | |
| | | Thread.sleep(300); |
| | | |
| | |
| | | |
| | | modbusTcpLink.setAddrExe(this.getAddrExe(modbusTcp.getDeviceModbus().getOpenEnd())); |
| | | |
| | | doReadExe(modbusTcpLink); |
| | | doReadStatus(modbusTcpLink); |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | |
| | | * @param modbusTcp |
| | | * @throws Exception |
| | | */ |
| | | private void doReadExe(ModbusTcp modbusTcp) throws Exception { |
| | | private void doReadStatus(ModbusTcp modbusTcp) throws Exception { |
| | | |
| | | if (Constant.YN_N.equals(modbusTcp.getDeviceModbus().getOpen())) return; |
| | | |
| | | boolean[] result = modbusUtil.readStatus02(modbusTcp.getIp(), modbusTcp.getPort(), modbusTcp.getAddrExe(), 2); |
| | | log.debug("---------读取状态------{}--{}", modbusTcp.getDeviceCode(), result.toString()); |
| | | int addrExe = getAddrExe(modbusTcp.getDeviceModbus().getOpenEnd()); |
| | | |
| | | if (result[0]) { |
| | | boolean result = ModbusUtil2.readInputStatus(modbusTcp.getIp(), modbusTcp.getPort(), addrExe); |
| | | log.debug("---------读开到位状态------{}-{}-{}", modbusTcp.getDeviceCode(), addrExe, result); |
| | | |
| | | if (result) { |
| | | ServerUtil.add2StatusMap(modbusTcp.getCompanyId(), modbusTcp.getSerId(), modbusTcp.getDeviceCode(), DeviceStatus.OPEN.getCode()); |
| | | } |
| | | if (result[1]) { |
| | | |
| | | |
| | | addrExe = getAddrExe(modbusTcp.getDeviceModbus().getCloseEnd()); |
| | | result = ModbusUtil2.readInputStatus(modbusTcp.getIp(), modbusTcp.getPort(), addrExe); |
| | | log.debug("---------读关到位状态------{}-{}-{}", modbusTcp.getDeviceCode(), addrExe, result); |
| | | |
| | | if (result) { |
| | | ServerUtil.add2StatusMap(modbusTcp.getCompanyId(), modbusTcp.getSerId(), modbusTcp.getDeviceCode(), DeviceStatus.CLOSE.getCode()); |
| | | } |
| | | } |