| | |
| | | if (result.IsSuccess) { |
| | | for (int i = 0; i < statusList.size(); i++) { |
| | | ZyStationStatusEntity statusEntity = statusList.get(i); // 站点编号 |
| | | statusEntity.setTaskNo((int) siemensNet.getByteTransform().TransInt16(result.Content, i * 8)); // 工作号 |
| | | statusEntity.setTaskNo(siemensNet.getByteTransform().TransInt32(result.Content, i * 8)); // 工作号 |
| | | statusEntity.setTargetStaNo((int) siemensNet.getByteTransform().TransInt16(result.Content, i * 8 + 4)); // 目标站 |
| | | |
| | | boolean[] status = siemensNet.getByteTransform().TransBool(result.Content, i * 8 + 6, 2); |
| | |
| | | statusEntity.setOutEnable(status[3]);// 可出 |
| | | statusEntity.setEmptyMk(status[4]); // 空板信号 |
| | | statusEntity.setFullPlt(status[5]); // 满托盘 |
| | | |
| | | if (statusEntity.getStationId()==1015){ |
| | | OperateResultExOne<byte[]> result1 = siemensNet.Read("DB101.3826", (short) (4)); |
| | | if (result1.IsSuccess) { |
| | | statusEntity.setWeight((double) siemensNet.getByteTransform().TransSingle(result1.Content, 0)); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 条码扫描器 |
| | | OperateResultExOne<byte[]> result2 = siemensNet.Read("DB101.840", (short) (barcodeOriginList.size() * 8)); |
| | | OperateResultExOne<byte[]> result2 = siemensNet.Read("DB101.3760", (short) (barcodeOriginList.size() * 52)); |
| | | if (result2.IsSuccess) { |
| | | 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 * 8, 8, "UTF-8"); |
| | | String barcode = siemensNet.getByteTransform().TransString(result2.Content, i * 52, 52, "UTF-8"); |
| | | barcode = barcode.trim(); |
| | | barcodeEntity.setBarcode(barcode); |
| | | } |
| | | } |
| | | |
| | | // 报警信息 |
| | | OperateResultExOne<byte[]> result3 = siemensNet.Read("DB101.800", (short) (barcodeOriginList.size() * 3)); |
| | | OperateResultExOne<byte[]> result3 = siemensNet.Read("DB101.2400", (short) (barcodeOriginList.size() * 3)); |
| | | if (result3.IsSuccess) { |
| | | for (int i = 0; i < barcodeOriginList.size(); i++) { |
| | | ZyStationStatusEntity barcodeEntity = findStatusEntityByBarcodeIdx(i + 1); |
| | |
| | | @Override |
| | | public CommandResponse sendCommand(Integer deviceNo, StationCommand command) { |
| | | CommandResponse commandResponse = new CommandResponse(false); |
| | | if (null == command) { |
| | | commandResponse.setMessage("命令为空"); |
| | | return commandResponse; |
| | | } |
| | | try { |
| | | if (null == command) { |
| | | commandResponse.setMessage("命令为空"); |
| | | return commandResponse; |
| | | } |
| | | |
| | | int index = findIndex(command.getStationId()); |
| | | if (index < 0) { |
| | | commandResponse.setMessage("站点不存在"); |
| | | return commandResponse; |
| | | } |
| | | int index = findIndex(command.getStationId()); |
| | | if (index < 0) { |
| | | commandResponse.setMessage("站点不存在"); |
| | | return commandResponse; |
| | | } |
| | | |
| | | OperateResult write = null; |
| | | // 任务下发次数 |
| | | int writeCount = 0; |
| | | do { |
| | | short[] data = new short[2]; |
| | | data[0] = command.getTaskNo().shortValue(); |
| | | data[1] = command.getTargetStaNo().shortValue(); |
| | | boolean commandSendResult = false; |
| | | // 任务下发次数 |
| | | int writeCount = 0; |
| | | do { |
| | | // short[] data = new short[2]; |
| | | // data[0] = command.getTaskNo(); |
| | | // data[1] = command.getTargetStaNo().shortValue(); |
| | | |
| | | write = siemensNet.Write("DB100." + index * 4, data); |
| | | if (write.IsSuccess) { |
| | | log.error("写入输送线命令成功。站点编号={},站点数据={},写入次数={}", command.getStationId(), JSON.toJSON(command), |
| | | writeCount); |
| | | commandResponse.setResult(true); |
| | | break; |
| | | } else { |
| | | OperateResult write = siemensNet.Write("DB100." + index * 6, command.getTaskNo()); |
| | | OperateResult write1 = siemensNet.Write("DB100." + (index * 6 + 4), command.getTargetStaNo().shortValue()); |
| | | if (write.IsSuccess && write1.IsSuccess) { |
| | | commandSendResult = true; |
| | | break; |
| | | } |
| | | writeCount++; |
| | | Thread.sleep(300); |
| | | } while (writeCount < 5); |
| | | |
| | | if(!commandSendResult) { |
| | | log.error("写入输送线命令失败。站点编号={},站点数据={},写入次数={}", command.getStationId(), JSON.toJSON(command), |
| | | writeCount); |
| | | commandResponse.setResult(false); |
| | | commandResponse.setMessage("写入命令失败"); |
| | | return commandResponse; |
| | | } |
| | | } while (writeCount < 5); |
| | | |
| | | if (write == null) { |
| | | commandResponse.setMessage("写入命令失败"); |
| | | return commandResponse; |
| | | } |
| | | |
| | | if (!write.IsSuccess) { |
| | | ZyStationStatusEntity staProtocol = findStatusEntity(command.getStationId()); |
| | | OutputQueue.DEVP.offer(MessageFormat.format("写入输送线站点数据失败。站点编号={1},站点数据={2}", command.getStationId(), |
| | | JSON.toJSON(staProtocol))); |
| | | News.error("写入输送线站点数据失败。站点编号={},站点数据={}", command.getStationId(), JSON.toJSON(staProtocol)); |
| | | } else { |
| | | OutputQueue.DEVP.offer(MessageFormat.format("【{0}】 输送线命令下发 [id:{1}] >>>>> {2}", |
| | | DateUtils.convert(new Date()), command.getStationId(), JSON.toJSON(command))); |
| | | News.info("输送线命令下发 [id:{}] >>>>> 命令下发: {}", command.getStationId(), |
| | | JSON.toJSON(command)); |
| | | commandResponse.setResult(true); |
| | | commandResponse.setMessage("命令下发成功"); |
| | | return commandResponse; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return commandResponse; |
| | | } |