|  |  |  | 
|---|
|  |  |  | command2.setDestinationPosZ((short)0);     // 目标库位层 | 
|---|
|  |  |  | write5(command2); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | // 复位 | 
|---|
|  |  |  | // 双工位同时作业 | 
|---|
|  |  |  | case 7: | 
|---|
|  |  |  | write9((CrnCommandParam) task.getData()); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 写入数据  工位2 | 
|---|
|  |  |  | * 写入数据  双工位 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private boolean write9(CrnCommandParam command) throws InterruptedException { | 
|---|
|  |  |  | if (null == command) { | 
|---|
|  |  |  | log.error("堆垛机写入命令为空"); | 
|---|
|  |  |  | return false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //        convertRow(command); | 
|---|
|  |  |  | command.setCrnNo(slave.getId()); | 
|---|
|  |  |  | short[] array = new short[10]; | 
|---|
|  |  |  | short[] array = new short[20]; | 
|---|
|  |  |  | array[0] = command.getAckFinish(); | 
|---|
|  |  |  | array[1] = command.getTaskNo(); | 
|---|
|  |  |  | array[2] = command.getTaskMode(); | 
|---|
|  |  |  | 
|---|
|  |  |  | array[6] = command.getDestinationPosX(); | 
|---|
|  |  |  | array[7] = command.getDestinationPosY(); | 
|---|
|  |  |  | array[8] = command.getDestinationPosZ(); | 
|---|
|  |  |  | //        array[9] = command.getSourceStaNo(); | 
|---|
|  |  |  | //        array[10] = command.getDestinationStaNo(); | 
|---|
|  |  |  | array[9] = command.getCommand(); | 
|---|
|  |  |  | OperateResult result18 = siemensNet.Write("DB100.38", (short)0); | 
|---|
|  |  |  | OperateResult result = siemensNet.Write("DB100.20", array); | 
|---|
|  |  |  | array[10] = command.getAckFinish2(); | 
|---|
|  |  |  | array[11] = command.getTaskNo2(); | 
|---|
|  |  |  | array[12] = command.getTaskMode2(); | 
|---|
|  |  |  | array[13] = command.getSourcePosX2(); | 
|---|
|  |  |  | array[14] = command.getSourcePosY2(); | 
|---|
|  |  |  | array[15] = command.getSourcePosZ2(); | 
|---|
|  |  |  | array[16] = command.getDestinationPosX2(); | 
|---|
|  |  |  | array[17] = command.getDestinationPosY2(); | 
|---|
|  |  |  | array[18] = command.getDestinationPosZ2(); | 
|---|
|  |  |  | array[19] = command.getCommand(); | 
|---|
|  |  |  | OperateResult result18 = siemensNet.Write("DB100.18", (short)0); | 
|---|
|  |  |  | OperateResult result38 = siemensNet.Write("DB100.38", (short)0); | 
|---|
|  |  |  | OperateResult result = siemensNet.Write("DB100.0", array); | 
|---|
|  |  |  | //        OperateResult result = siemensNet.Write("DB100.20", array); | 
|---|
|  |  |  | log.info("堆垛机命令下发[id:{}] >>>>> {}", slave.getId(), array); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //堆垛机任务写入后,回读一次,看是否成功 | 
|---|
|  |  |  | 
|---|
|  |  |  | try{ | 
|---|
|  |  |  | if(!result.IsSuccess){ | 
|---|
|  |  |  | log.error("写入堆垛机plc数据失败,重新下发任务  写入直接失败 ===>> [id:{}],{},[写入次数:{}]", slave.getId(), JSON.toJSON(command),writeCount); | 
|---|
|  |  |  | result = siemensNet.Write("DB100.20", array); | 
|---|
|  |  |  | result = siemensNet.Write("DB100.0", array); | 
|---|
|  |  |  | Thread.sleep(100); | 
|---|
|  |  |  | writeCount++; | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | OperateResultExOne<byte[]> resultRead = siemensNet.Read("DB100.20", (short) 24); | 
|---|
|  |  |  | OperateResultExOne<byte[]> resultRead = siemensNet.Read("DB100.0", (short) 40); | 
|---|
|  |  |  | if (resultRead.IsSuccess) { | 
|---|
|  |  |  | CrnCommand one = new CrnCommand(); | 
|---|
|  |  |  | CrnCommandParam one = new CrnCommandParam(); | 
|---|
|  |  |  | one.setTaskNo(siemensNet.getByteTransform().TransInt16(resultRead.Content, 2)); | 
|---|
|  |  |  | one.setTaskMode(siemensNet.getByteTransform().TransInt16(resultRead.Content, 4)); | 
|---|
|  |  |  | one.setSourcePosX(siemensNet.getByteTransform().TransInt16(resultRead.Content, 6)); | 
|---|
|  |  |  | 
|---|
|  |  |  | one.setDestinationPosX(siemensNet.getByteTransform().TransInt16(resultRead.Content, 12)); | 
|---|
|  |  |  | one.setDestinationPosY(siemensNet.getByteTransform().TransInt16(resultRead.Content, 14)); | 
|---|
|  |  |  | one.setDestinationPosZ(siemensNet.getByteTransform().TransInt16(resultRead.Content, 16)); | 
|---|
|  |  |  | one.setTaskNo2(siemensNet.getByteTransform().TransInt16(resultRead.Content, 22)); | 
|---|
|  |  |  | one.setTaskMode2(siemensNet.getByteTransform().TransInt16(resultRead.Content, 24)); | 
|---|
|  |  |  | one.setSourcePosX2(siemensNet.getByteTransform().TransInt16(resultRead.Content, 26)); | 
|---|
|  |  |  | one.setSourcePosY2(siemensNet.getByteTransform().TransInt16(resultRead.Content, 28)); | 
|---|
|  |  |  | one.setSourcePosZ2(siemensNet.getByteTransform().TransInt16(resultRead.Content, 30)); | 
|---|
|  |  |  | one.setDestinationPosX2(siemensNet.getByteTransform().TransInt16(resultRead.Content, 32)); | 
|---|
|  |  |  | one.setDestinationPosY2(siemensNet.getByteTransform().TransInt16(resultRead.Content, 34)); | 
|---|
|  |  |  | one.setDestinationPosZ2(siemensNet.getByteTransform().TransInt16(resultRead.Content, 36)); | 
|---|
|  |  |  | if (!command.getTaskNo().equals(one.getTaskNo()) || !command.getTaskMode().equals(one.getTaskMode()) | 
|---|
|  |  |  | || !command.getSourcePosX().equals(one.getSourcePosX()) || !command.getSourcePosY().equals(one.getSourcePosY()) | 
|---|
|  |  |  | || !command.getSourcePosZ().equals(one.getSourcePosZ()) || !command.getDestinationPosX().equals(one.getDestinationPosX()) | 
|---|
|  |  |  | || !command.getDestinationPosY().equals(one.getDestinationPosY()) || !command.getDestinationPosZ().equals(one.getDestinationPosZ()) | 
|---|
|  |  |  | || | 
|---|
|  |  |  | !command.getTaskNo2().equals(one.getTaskNo2()) || !command.getTaskMode2().equals(one.getTaskMode2()) | 
|---|
|  |  |  | || !command.getSourcePosX2().equals(one.getSourcePosX2()) || !command.getSourcePosY2().equals(one.getSourcePosY2()) | 
|---|
|  |  |  | || !command.getSourcePosZ2().equals(one.getSourcePosZ2()) || !command.getDestinationPosX2().equals(one.getDestinationPosX2()) | 
|---|
|  |  |  | || !command.getDestinationPosY2().equals(one.getDestinationPosY2()) || !command.getDestinationPosZ2().equals(one.getDestinationPosZ2()) | 
|---|
|  |  |  | ){ | 
|---|
|  |  |  | try{ | 
|---|
|  |  |  | log.error("堆垛机命令地址写入后回读失败==>不一致[id:{}] >>>>> 写入[{}],===>>回读[{}]", slave.getId(), JSON.toJSON(command),JSON.toJSON(one)); | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | log.error("写入堆垛机plc数据失败,重新下发任务  回读不一致 ===>> [id:{}],{},[写入次数:{}]", slave.getId(), JSON.toJSON(command),writeCount); | 
|---|
|  |  |  | result = siemensNet.Write("DB100.20", array); | 
|---|
|  |  |  | result = siemensNet.Write("DB100.0", array); | 
|---|
|  |  |  | writeCount++; | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | 
|---|
|  |  |  | if (command.getAckFinish() == 0) { | 
|---|
|  |  |  | short commandFinish = 1; | 
|---|
|  |  |  | Thread.sleep(100L); | 
|---|
|  |  |  | result = siemensNet.Write("DB100.38", commandFinish); | 
|---|
|  |  |  | result18 = siemensNet.Write("DB100.18", commandFinish); | 
|---|
|  |  |  | result38 = siemensNet.Write("DB100.38", commandFinish); | 
|---|
|  |  |  | int signFinish = 1; | 
|---|
|  |  |  | while (signFinish<5){ | 
|---|
|  |  |  | OperateResultExOne<byte[]> result10018 = siemensNet.Read("DB100.38", (short) 2); | 
|---|
|  |  |  | short transInt16 = siemensNet.getByteTransform().TransInt16(result10018.Content, 0); | 
|---|
|  |  |  | if (transInt16 != commandFinish){ | 
|---|
|  |  |  | log.info("下发DB100.38  回读失败" + "commandFinish:"+commandFinish); | 
|---|
|  |  |  | log.info("下发DB100.38  回读失败" + "array:"+ JSON.toJSONString(array)); | 
|---|
|  |  |  | result = siemensNet.Write("DB100.38", commandFinish); | 
|---|
|  |  |  | OperateResultExOne<byte[]> result10018 = siemensNet.Read("DB100.18", (short) 2); | 
|---|
|  |  |  | OperateResultExOne<byte[]> result10038 = siemensNet.Read("DB100.38", (short) 2); | 
|---|
|  |  |  | short transInt1618 = siemensNet.getByteTransform().TransInt16(result10018.Content, 0); | 
|---|
|  |  |  | short transInt1638 = siemensNet.getByteTransform().TransInt16(result10038.Content, 0); | 
|---|
|  |  |  | if (transInt1618 != commandFinish || transInt1638 != commandFinish){ | 
|---|
|  |  |  | log.info("下发DB100.18/DB100.38  回读失败" + "commandFinish:"+commandFinish); | 
|---|
|  |  |  | log.info("下发DB100.18/DB100.38  回读失败" + "array:"+ JSON.toJSONString(array)); | 
|---|
|  |  |  | result18 = siemensNet.Write("DB100.18", commandFinish); | 
|---|
|  |  |  | result38 = siemensNet.Write("DB100.38", commandFinish); | 
|---|
|  |  |  | signFinish++; | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | log.info("下发DB100.38" + "commandFinish:"+commandFinish); | 
|---|
|  |  |  | log.info("下发DB100.38" + "array:"+ JSON.toJSONString(array)); | 
|---|
|  |  |  | log.info("下发DB100.18/DB100.38" + "commandFinish:"+commandFinish); | 
|---|
|  |  |  | log.info("下发DB100.18/DB100.38" + "array:"+ JSON.toJSONString(array)); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|