| | |
| | | import com.zy.core.cache.OutputQueue; |
| | | import com.zy.core.enums.StationCommandType; |
| | | import com.zy.core.model.CommandResponse; |
| | | import com.zy.core.model.StationObjModel; |
| | | import com.zy.core.model.command.StationCommand; |
| | | import com.zy.core.network.api.ZyStationConnectApi; |
| | | import com.zy.core.network.entity.ZyStationStatusEntity; |
| | |
| | | public class ZyStationV3RealConnect implements ZyStationConnectApi { |
| | | |
| | | private List<ZyStationStatusEntity> statusList; |
| | | private List<ZyStationStatusEntity> barcodeStatusList; |
| | | private List<StationObjModel> barcodeOriginList; |
| | | private SiemensS7Net siemensNet; |
| | | private DeviceConfig deviceConfig; |
| | | private RedisUtil redisUtil; |
| | |
| | | if (statusList != null) { |
| | | statusList.sort(Comparator.comparing(ZyStationStatusEntity::getStationId)); |
| | | } |
| | | barcodeStatusList = JSONObject.parseArray(basDevp.getBarcodeStationList(), ZyStationStatusEntity.class); |
| | | if (barcodeStatusList != null) { |
| | | barcodeStatusList.sort(Comparator.comparing(ZyStationStatusEntity::getStationId)); |
| | | } |
| | | barcodeOriginList = basDevp.getBarcodeStationList$(); |
| | | } |
| | | |
| | | if (siemensNet == null) { |
| | |
| | | boolean[] status2 = siemensNet.getByteTransform().TransBool(result.Content, i * 8 + 7, 1); |
| | | statusEntity.setRunBlock(status2[1]);//重新规划路线 |
| | | statusEntity.setEnableIn(status2[3]);//启动入库 |
| | | |
| | | Integer palletHeight = null; |
| | | if (status[7]) { |
| | | palletHeight = 1;//低 |
| | | } |
| | | if (status2[0]) { |
| | | palletHeight = 2;//中 |
| | | } |
| | | if (status[6]) { |
| | | palletHeight = 3;//高 |
| | | } |
| | | statusEntity.setPalletHeight(palletHeight);//高低信号 |
| | | |
| | | statusEntity.setError(0);//默认无报警 |
| | | } |
| | | } |
| | | |
| | | // 条码扫描器 |
| | | OperateResultExOne<byte[]> result2 = siemensNet.Read("DB101.0", (short) (statusList.size() * 10)); |
| | | OperateResultExOne<byte[]> result2 = siemensNet.Read("DB101.0", (short) (barcodeOriginList.size() * 16)); |
| | | if (result2.IsSuccess) { |
| | | for (int i = 0; i < barcodeStatusList.size(); i++) { |
| | | ZyStationStatusEntity barcodeEntity = barcodeStatusList.get(i); |
| | | ZyStationStatusEntity statusEntity = findStatusEntity(barcodeEntity.getStationId()); |
| | | if (statusEntity == null) { |
| | | for (int i = 0; i < barcodeOriginList.size(); i++) { |
| | | ZyStationStatusEntity barcodeEntity = findStatusEntityByBarcodeIdx(i + 1); |
| | | if (barcodeEntity == null) { |
| | | continue; |
| | | } |
| | | String barcode = siemensNet.getByteTransform().TransString(result2.Content, i * 10 + 2, 8, "UTF-8"); |
| | | String barcode = siemensNet.getByteTransform().TransString(result2.Content, i * 16 + 2, 14, "UTF-8"); |
| | | barcode = barcode.trim(); |
| | | barcodeEntity.setBarcode(barcode); |
| | | } |
| | | } |
| | | |
| | | // 称重 |
| | | OperateResultExOne<byte[]> result3 = siemensNet.Read("DB102.0", (short) (barcodeOriginList.size() * 4)); |
| | | if (result3.IsSuccess) { |
| | | for (int i = 0; i < barcodeOriginList.size(); i++) { |
| | | ZyStationStatusEntity barcodeEntity = findStatusEntityByBarcodeIdx(i + 1); |
| | | if (barcodeEntity == null) { |
| | | continue; |
| | | } |
| | | double weight = (double) siemensNet.getByteTransform().TransSingle(result3.Content, i * 4); |
| | | barcodeEntity.setWeight(weight); |
| | | } |
| | | } |
| | | |
| | | // 报警信息 |
| | | OperateResultExOne<byte[]> result4 = siemensNet.Read("DB103.0", (short) (barcodeOriginList.size() * 2)); |
| | | if (result4.IsSuccess) { |
| | | for (int i = 0; i < barcodeOriginList.size(); i++) { |
| | | ZyStationStatusEntity barcodeEntity = findStatusEntityByBarcodeIdx(i + 1); |
| | | if (barcodeEntity == null) { |
| | | continue; |
| | | } |
| | | |
| | | StringBuilder sb = new StringBuilder(); |
| | | boolean[] status1 = siemensNet.getByteTransform().TransBool(result4.Content, i * 2, 1); |
| | | boolean[] status2 = siemensNet.getByteTransform().TransBool(result4.Content, i * 2 + 1, 1); |
| | | |
| | | if(status1[0]){ |
| | | sb.append("左超宽报警;"); |
| | | } |
| | | if(status1[1]) { |
| | | sb.append("右超宽报警;"); |
| | | } |
| | | if(status1[2]) { |
| | | sb.append("前超长报警;"); |
| | | } |
| | | if(status1[3]) { |
| | | sb.append("后超长报警;"); |
| | | } |
| | | if(status1[4]) { |
| | | sb.append("超高报警;"); |
| | | } |
| | | if(status1[5]) { |
| | | sb.append("有货报警,空托入库时检测托盘上有无货物;"); |
| | | } |
| | | if(status1[6]) { |
| | | sb.append("重量异常报警;"); |
| | | } |
| | | if(status1[7]) { |
| | | sb.append("扫码异常;"); |
| | | } |
| | | |
| | | if(sb.length() > 0) { |
| | | barcodeEntity.setError(1); |
| | | }else { |
| | | barcodeEntity.setError(0); |
| | | } |
| | | barcodeEntity.setErrorMsg(sb.toString()); |
| | | } |
| | | } |
| | | |
| | |
| | | log.error("写入输送线命令失败。站点编号={},站点数据={}", command.getTaskNo(), JSON.toJSON(command)); |
| | | commandResponse.setResult(false); |
| | | } |
| | | } else if (command.getCommandType().equals(StationCommandType.WRITE_INFO)) { |
| | | int enableCommandIdx = -1; |
| | | while (true) { |
| | | enableCommandIdx = getEnableCommandIdx(command.getTaskNo()); |
| | | if(enableCommandIdx == -1) { |
| | | try { |
| | | Thread.sleep(300); |
| | | }catch (Exception e) {} |
| | | }else { |
| | | break; |
| | | } |
| | | tryCount++; |
| | | if (tryCount > maxTryCount) { |
| | | commandResponse.setMessage("命令下发超时,无法找到可用下发区域"); |
| | | return commandResponse; |
| | | } |
| | | } |
| | | |
| | | short[] data = new short[21]; |
| | | data[0] = command.getTargetStaNo().shortValue(); |
| | | data[1] = command.getTargetStaNo().shortValue(); |
| | | |
| | | OperateResult writeTask = siemensNet.Write("DB23." + (enableCommandIdx * taskAddressLength), command.getTaskNo()); |
| | | try { |
| | | Thread.sleep(50); |
| | | }catch (Exception e) {} |
| | | |
| | | OperateResult writeData = siemensNet.Write("DB23." + (enableCommandIdx * taskAddressLength + 4), data); |
| | | try { |
| | | Thread.sleep(200); |
| | | }catch (Exception e) {} |
| | | OperateResult writeConfirm = siemensNet.Write("DB23." + (enableCommandIdx * taskAddressLength + 46), (short) 1); |
| | | |
| | | if(writeTask.IsSuccess && writeData.IsSuccess && writeConfirm.IsSuccess) { |
| | | log.error("写入输送线命令成功。任务号={},站点数据={}", command.getTaskNo(), JSON.toJSON(command)); |
| | | commandResponse.setResult(true); |
| | | }else { |
| | | log.error("写入输送线命令失败。站点编号={},站点数据={}", command.getTaskNo(), JSON.toJSON(command)); |
| | | commandResponse.setResult(false); |
| | | } |
| | | } |
| | | return commandResponse; |
| | | } |
| | |
| | | return new byte[0]; |
| | | } |
| | | |
| | | private ZyStationStatusEntity findStatusEntity(Integer stationId) { |
| | | for (ZyStationStatusEntity statusEntity : statusList) { |
| | | if (statusEntity.getStationId().equals(stationId)) { |
| | | return statusEntity; |
| | | private ZyStationStatusEntity findStatusEntityByBarcodeIdx(Integer barcodeIdx) { |
| | | Integer stationId = null; |
| | | for (StationObjModel stationObjModel : barcodeOriginList) { |
| | | if (stationObjModel.getBarcodeIdx().equals(barcodeIdx)) { |
| | | stationId = stationObjModel.getStationId(); |
| | | break; |
| | | } |
| | | } |
| | | |
| | | for (ZyStationStatusEntity zyStationStatusEntity : statusList) { |
| | | if(zyStationStatusEntity.getStationId().equals(stationId)) { |
| | | return zyStationStatusEntity; |
| | | } |
| | | } |
| | | return null; |
| | |
| | | private int getEnableCommandIdx(int taskNo) { |
| | | int useIdx = -1; |
| | | for (int i = 0; i < taskAddressLimit; i++) { |
| | | OperateResultExOne<byte[]> resultTask = siemensNet.Read("DB23." + (i * taskAddressLength + 0), (short) 2); |
| | | OperateResultExOne<byte[]> resultTask = siemensNet.Read("DB23." + (i * taskAddressLength + 0), (short) 4); |
| | | OperateResultExOne<byte[]> resultStatus = siemensNet.Read("DB23." + (i * taskAddressLength + 46), (short) 2); |
| | | if(resultTask.IsSuccess && resultStatus.IsSuccess) { |
| | | if(!resultTask.IsSuccess || !resultStatus.IsSuccess) { |
| | | continue; |
| | | } |
| | | |