| | |
| | | |
| | | private List<ZyStationStatusEntity> statusList; |
| | | private List<StationObjModel> barcodeOriginList; |
| | | private List<StationObjModel> inStationOriginList; |
| | | private SiemensS7Net siemensNet; |
| | | private DeviceConfig deviceConfig; |
| | | private RedisUtil redisUtil; |
| | |
| | | statusList.sort(Comparator.comparing(ZyStationStatusEntity::getStationId)); |
| | | } |
| | | barcodeOriginList = basDevp.getBarcodeStationList$(); |
| | | inStationOriginList = sortStationObjModelsByStationId(basDevp.getInStationList$()); |
| | | } |
| | | |
| | | if (siemensNet == null) { |
| | |
| | | |
| | | String alarmMsg = buildConveyorCommonAlarmMessage(status1, status2, status3, status4); |
| | | applyAlarmMessage(statusEntity, mergeAlarmMessages(statusEntity.getErrorMsg(), alarmMsg)); |
| | | } |
| | | } |
| | | |
| | | // 出入库模式 |
| | | OperateResultExOne<byte[]> result6 = siemensNet.Read("DB167.2", (short) (inStationOriginList.size() * 2)); |
| | | if (result6.IsSuccess) { |
| | | clearInStationIoModes(); |
| | | for (int i = 0; i < inStationOriginList.size(); i++) { |
| | | ZyStationStatusEntity inStationEntity = findStatusEntityByInStationIdx(i); |
| | | if (inStationEntity == null) { |
| | | continue; |
| | | } |
| | | Integer ioMode = normalizeIoMode((int) siemensNet.getByteTransform().TransInt16(result6.Content, i * 2)); |
| | | inStationEntity.setIoMode(ioMode); |
| | | } |
| | | } |
| | | |
| | |
| | | return null; |
| | | } |
| | | |
| | | private ZyStationStatusEntity findStatusEntityByInStationIdx(Integer idx) { |
| | | Integer stationId = findInStationIdByOrder(inStationOriginList, idx); |
| | | |
| | | for (ZyStationStatusEntity zyStationStatusEntity : statusList) { |
| | | if(zyStationStatusEntity.getStationId().equals(stationId)) { |
| | | return zyStationStatusEntity; |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | private void clearInStationIoModes() { |
| | | if (inStationOriginList == null || statusList == null) { |
| | | return; |
| | | } |
| | | for (StationObjModel stationObjModel : inStationOriginList) { |
| | | if (stationObjModel == null || stationObjModel.getStationId() == null) { |
| | | continue; |
| | | } |
| | | for (ZyStationStatusEntity statusEntity : statusList) { |
| | | if (stationObjModel.getStationId().equals(statusEntity.getStationId())) { |
| | | statusEntity.setIoMode(null); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | private int getTaskWriteIdx(int stationIdx, Integer taskWriteIdx) { |
| | | int useIdx = -1; |
| | | if (stationIdx < 0 || taskWriteIdx == null || taskWriteIdx <= 0) { |
| | |
| | | return current + append; |
| | | } |
| | | |
| | | static Integer normalizeIoMode(Integer rawMode) { |
| | | if (rawMode == null) { |
| | | return null; |
| | | } |
| | | if (rawMode == 1 || rawMode == 2) { |
| | | return rawMode; |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | static Integer findInStationIdByOrder(List<StationObjModel> inStationOriginList, Integer orderIdx) { |
| | | if (inStationOriginList == null || orderIdx == null || orderIdx < 0 || orderIdx >= inStationOriginList.size()) { |
| | | return null; |
| | | } |
| | | StationObjModel stationObjModel = inStationOriginList.get(orderIdx); |
| | | return stationObjModel == null ? null : stationObjModel.getStationId(); |
| | | } |
| | | |
| | | static List<StationObjModel> sortStationObjModelsByStationId(List<StationObjModel> stationObjModels) { |
| | | if (stationObjModels == null) { |
| | | return Collections.emptyList(); |
| | | } |
| | | stationObjModels.sort(Comparator.comparing(StationObjModel::getStationId, Comparator.nullsLast(Integer::compareTo))); |
| | | return stationObjModels; |
| | | } |
| | | |
| | | private static void appendConveyorCommonAlarmMessages(StringBuilder sb, boolean[] status, int startIdx) { |
| | | if (status == null) { |
| | | return; |