| | |
| | | |
| | | OperateResultExOne<byte[]> result = siemensNet.Read("DB100.0", (short) (statusList.size() * 10)); |
| | | if (result.IsSuccess) { |
| | | byte[] taskBufferRaw = readTaskBufferRaw(); |
| | | for (int i = 0; i < statusList.size(); i++) { |
| | | ZyStationStatusEntity statusEntity = statusList.get(i); // 站点编号 |
| | | statusEntity.setTaskNo(siemensNet.getByteTransform().TransInt32(result.Content, i * 10)); // 工作号 |
| | |
| | | statusEntity.setError(0);//默认无报警 |
| | | |
| | | statusEntity.setTaskWriteIdx((int) siemensNet.getByteTransform().TransInt16(result.Content, i * 10 + 8));//任务可写区 |
| | | fillTaskBufferStatus(i, statusEntity); |
| | | fillTaskBufferStatus(taskBufferRaw, i, statusEntity); |
| | | } |
| | | } |
| | | |
| | |
| | | return null; |
| | | } |
| | | |
| | | private void fillTaskBufferStatus(int stationIdx, ZyStationStatusEntity statusEntity) { |
| | | if (statusEntity == null || stationIdx < 0) { |
| | | private byte[] readTaskBufferRaw() { |
| | | int totalLength = statusList == null ? 0 : statusList.size() * TASK_AREA_LENGTH; |
| | | if (totalLength <= 0) { |
| | | return null; |
| | | } |
| | | OperateResultExOne<byte[]> resultTask = siemensNet.Read("DB13.0", (short) totalLength); |
| | | if (!resultTask.IsSuccess || resultTask.Content == null || resultTask.Content.length < totalLength) { |
| | | return null; |
| | | } |
| | | return resultTask.Content; |
| | | } |
| | | |
| | | private void fillTaskBufferStatus(byte[] taskBufferRaw, int stationIdx, ZyStationStatusEntity statusEntity) { |
| | | if (statusEntity == null || stationIdx < 0 || taskBufferRaw == null) { |
| | | statusEntity.setTaskBufferItems(new ArrayList<>()); |
| | | return; |
| | | } |
| | | List<StationTaskBufferItem> itemList = new ArrayList<>(); |
| | | OperateResultExOne<byte[]> resultTask = siemensNet.Read("DB13." + (stationIdx * TASK_AREA_LENGTH), (short) TASK_AREA_LENGTH); |
| | | if (resultTask.IsSuccess && resultTask.Content != null) { |
| | | for (int slotIdx = 1; slotIdx <= TASK_AREA_SLOT_COUNT; slotIdx++) { |
| | | int offset = slotIdx * TASK_AREA_SLOT_SIZE; |
| | | int taskNo = siemensNet.getByteTransform().TransInt32(resultTask.Content, offset); |
| | | int targetPoint = siemensNet.getByteTransform().TransInt16(resultTask.Content, offset + 6); |
| | | StationTaskBufferItem item = new StationTaskBufferItem(); |
| | | item.setSlotIdx(slotIdx); |
| | | item.setTaskNo(taskNo); |
| | | item.setTargetStaNo(targetPoint); |
| | | itemList.add(item); |
| | | } |
| | | int stationOffset = stationIdx * TASK_AREA_LENGTH; |
| | | if (stationOffset + TASK_AREA_LENGTH > taskBufferRaw.length) { |
| | | statusEntity.setTaskBufferItems(itemList); |
| | | return; |
| | | } |
| | | for (int slotIdx = 1; slotIdx <= TASK_AREA_SLOT_COUNT; slotIdx++) { |
| | | int offset = stationOffset + (slotIdx * TASK_AREA_SLOT_SIZE); |
| | | int taskNo = siemensNet.getByteTransform().TransInt32(taskBufferRaw, offset); |
| | | int targetPoint = siemensNet.getByteTransform().TransInt16(taskBufferRaw, offset + 6); |
| | | StationTaskBufferItem item = new StationTaskBufferItem(); |
| | | item.setSlotIdx(slotIdx); |
| | | item.setTaskNo(taskNo); |
| | | item.setTargetStaNo(targetPoint); |
| | | itemList.add(item); |
| | | } |
| | | statusEntity.setTaskBufferItems(itemList); |
| | | } |