| | |
| | | |
| | | import HslCommunication.Core.Types.OperateResult; |
| | | import HslCommunication.Profinet.Siemens.SiemensS7Net; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.zy.acs.common.utils.News; |
| | | import com.zy.acs.conveyor.core.constant.PlcConstant; |
| | | import com.zy.acs.conveyor.core.enums.SafeSignalField; |
| | |
| | | |
| | | public void writeSafe(StaProtocol staProtocol) throws InterruptedException { |
| | | if (staProtocol == null) { |
| | | News.warn("写入数据为空,跳过 [id:{}]", JSON.toJSONString(staProtocol)); |
| | | News.warn("写入安全信号,站点数据为空"); |
| | | return; |
| | | } |
| | | |
| | | SiemensS7Net siemensS7Net = devpS7Service.get(staProtocol.getPlcId()); |
| | | if (siemensS7Net == null) { |
| | | News.error("PLC未连接,无法写入 [id:{}]", JSON.toJSONString(staProtocol)); |
| | | News.error("PLC未连接,无法写入 [id:{}]", staProtocol.getSafeSignalData()); |
| | | return; |
| | | } |
| | | |
| | | List<DevpSlave> devp = slaveProperties.getDevp(); |
| | | DevpSlave devpSlave = devp.stream().filter(slave -> slave.getId().equals(staProtocol.getPlcId())).findFirst().orElse(null); |
| | | if (devpSlave == null) { |
| | | News.error("PLC未配置,无法写入 [id:{}]", JSON.toJSONString(staProtocol)); |
| | | News.error("PLC未配置,无法写入 [id:{}]", staProtocol.getSafeSignalData()); |
| | | return; |
| | | } |
| | | int index = devpSlave.getStaNos().indexOf(staProtocol.getSiteId()); |
| | |
| | | OperateResult writeResult = siemensS7Net.Write(flagAddr, array); |
| | | |
| | | if (writeResult.IsSuccess) { |
| | | News.info("写入安全信号输送线命令成功 [id:{}] [siteId:{}] [workNo:{}] [destSta:{}] [retry:{}]", |
| | | News.info("写入安全信号成功 [id:{}] [siteId:{}] [workNo:{}] [destSta:{}] [retry:{}]", |
| | | staProtocol.getPlcId(), staProtocol.getSiteId(), staProtocol.getWorkNo(), |
| | | staProtocol.getStaNo(), writeCount); |
| | | OutputQueue.DEVP.offer(MessageFormat.format("【{0}】写入安全信号输送线命令成功。输送线plc编号={1},站点数据={2}", |
| | | staProtocol.getPlcId(), JSON.toJSON(staProtocol))); |
| | | OutputQueue.DEVP.offer(MessageFormat.format("写入安全信号输送线命令成功。输送线plc编号={0},站点数据={1}", |
| | | staProtocol.getPlcId(), staProtocol.getSafeSignalData())); |
| | | success = true; |
| | | break; |
| | | } |
| | | |
| | | writeCount++; |
| | | News.error("写入安全信号输送线命令失败 [id:{}] [siteId:{}] [retry:{}] [workErr:{}] ", |
| | | News.error("写入安全信号失败 [id:{}] [siteId:{}] [retry:{}] [workErr:{}] ", |
| | | staProtocol.getPlcId(), staProtocol.getSiteId(), writeCount, |
| | | writeResult.Message); |
| | | if (writeCount <= WRITE_RETRY) { |
| | |
| | | } |
| | | |
| | | if (!success) { |
| | | String errorMsg = MessageFormat.format("【{0}】写入安全信号输送线站点数据失败。输送线plc编号={1},站点数据={2}", |
| | | staProtocol.getPlcId(), JSON.toJSON(staProtocol)); |
| | | String errorMsg = MessageFormat.format("写入安全信号失败。输送线plc编号={0},站点数据={1}", |
| | | staProtocol.getPlcId(), staProtocol.getSafeSignalData()); |
| | | OutputQueue.DEVP.offer(errorMsg); |
| | | News.error("SiemensDevp - 4 - 写入安全信号输送线站点数据失败。输送线plc编号={},站点数据={}", |
| | | staProtocol.getPlcId(), JSON.toJSON(staProtocol)); |
| | | News.error("SiemensDevp - 4 - 写入安全信号失败。输送线plc编号={},站点数据={}", |
| | | staProtocol.getPlcId(), staProtocol.getSafeSignalData()); |
| | | } |
| | | |
| | | } |
| | | |
| | | public void write(StaProtocol staProtocol) throws InterruptedException { |
| | | if (staProtocol == null) { |
| | | News.warn("写入数据为空,跳过 [id:{}]", JSON.toJSONString(staProtocol)); |
| | | News.warn("写入任务数据,站点数据为空"); |
| | | return; |
| | | } |
| | | |
| | | SiemensS7Net siemensS7Net = devpS7Service.get(staProtocol.getPlcId()); |
| | | if (siemensS7Net == null) { |
| | | News.error("PLC未连接,无法写入 [id:{}]", JSON.toJSONString(staProtocol)); |
| | | News.error("PLC未连接,无法写入 [id:{}]", staProtocol.getTaskData()); |
| | | return; |
| | | } |
| | | |
| | | List<DevpSlave> devp = slaveProperties.getDevp(); |
| | | DevpSlave devpSlave = devp.stream().filter(slave -> slave.getId().equals(staProtocol.getPlcId())).findFirst().orElse(null); |
| | | if (devpSlave == null) { |
| | | News.error("PLC未配置,无法写入 [id:{}]", JSON.toJSONString(staProtocol)); |
| | | News.error("PLC未配置,无法写入 [id:{}]", staProtocol.getTaskData()); |
| | | return; |
| | | } |
| | | int index = devpSlave.getStaNos().indexOf(staProtocol.getSiteId()); |
| | |
| | | News.info("写入输送线命令成功 [id:{}] [siteId:{}] [workNo:{}] [destSta:{}] [retry:{}]", |
| | | staProtocol.getPlcId(), staProtocol.getSiteId(), staProtocol.getWorkNo(), |
| | | staProtocol.getStaNo(), writeCount); |
| | | OutputQueue.DEVP.offer(MessageFormat.format("【{0}】写入输送线命令成功。输送线plc编号={1},站点数据={2}", |
| | | staProtocol.getPlcId(), JSON.toJSON(staProtocol))); |
| | | OutputQueue.DEVP.offer(MessageFormat.format("写入输送线命令成功。输送线plc编号={0},站点数据={1}", |
| | | staProtocol.getPlcId(), staProtocol.getTaskData())); |
| | | success = true; |
| | | break; |
| | | } |
| | |
| | | } |
| | | |
| | | if (!success) { |
| | | String errorMsg = MessageFormat.format("【{0}】写入输送线站点数据失败。输送线plc编号={1},站点数据={2}", |
| | | staProtocol.getPlcId(), JSON.toJSON(staProtocol)); |
| | | String errorMsg = MessageFormat.format("写入输送线站点数据失败。输送线plc编号={0},站点数据={1}", |
| | | staProtocol.getPlcId(), staProtocol.getTaskData()); |
| | | OutputQueue.DEVP.offer(errorMsg); |
| | | News.error("SiemensDevp - 4 - 写入输送线站点数据失败。输送线plc编号={},站点数据={}", |
| | | staProtocol.getPlcId(), JSON.toJSON(staProtocol)); |
| | | staProtocol.getPlcId(), staProtocol.getTaskData()); |
| | | } |
| | | |
| | | } |