| | |
| | | do { |
| | | if (!wrkNoFlag) { |
| | | write = siemensS7Net.Write("DB100." + index * 6, (int) staProtocol.getWorkNo()); // 工作号 |
| | | Thread.sleep(300); |
| | | if (write.IsSuccess) { |
| | | OperateResultExOne<byte[]> readResult = siemensS7Net.Read("DB100." + index * 6, (short) 4); |
| | | if (readResult.IsSuccess) { |
| | | short workNo = (short) siemensS7Net.getByteTransform().TransInt32(readResult.Content, 0); |
| | | if (staProtocol.getWorkNo().equals(workNo)) { |
| | | //任务命令写入成功 |
| | | log.info("写入工作号命令后返回成功,并且回读成功。堆垛机plc编号={},{},写入次数={}", slave.getId(), JSON.toJSON(staProtocol), writeCount); |
| | | wrkNoFlag = true; |
| | | } else {//返回结果是成功了,但是真实值不相同 |
| | | writeCount++; |
| | | log.error("写入工作号命令后返回成功,但是读取任务值不一致。堆垛机plc编号={},{},写入次数={}", slave.getId(), JSON.toJSON(staProtocol), writeCount); |
| | | } |
| | | } else { |
| | | writeCount++; |
| | | log.error("写入工作号命令后读取失败。堆垛机plc编号={},站点数据={},写入次数={}", slave.getId(), JSON.toJSON(staProtocol), writeCount); |
| | | } |
| | | wrkNoFlag = true; |
| | | // OperateResultExOne<byte[]> readResult = siemensS7Net.Read("DB100." + index * 6, (short) 4); |
| | | // if (readResult.IsSuccess) { |
| | | // short workNo = (short) siemensS7Net.getByteTransform().TransInt32(readResult.Content, 0); |
| | | // if (staProtocol.getWorkNo().equals(workNo)) { |
| | | // //任务命令写入成功 |
| | | // log.info("写入工作号命令后返回成功,并且回读成功。堆垛机plc编号={},{},{},写入次数={}", slave.getId(), staProtocol.getWorkNo(), workNo, writeCount); |
| | | // wrkNoFlag = true; |
| | | // } else {//返回结果是成功了,但是真实值不相同 |
| | | // writeCount++; |
| | | // log.error("写入工作号命令后返回成功,但是读取任务值不一致。堆垛机plc编号={},{},{},写入次数={}", slave.getId(), staProtocol.getWorkNo(), workNo, writeCount); |
| | | // } |
| | | // } else { |
| | | // writeCount++; |
| | | // log.error("写入工作号命令后读取失败。堆垛机plc编号={},站点数据={},写入次数={}", slave.getId(), JSON.toJSON(staProtocol), writeCount); |
| | | // } |
| | | } else { |
| | | writeCount++; |
| | | log.error("写入工作号命令失败。堆垛机plc编号={},站点数据={},写入次数={}", slave.getId(), JSON.toJSON(staProtocol), writeCount); |
| | |
| | | } |
| | | if (!staNoFlag) { |
| | | write1 = siemensS7Net.Write("DB100." + (index * 6 + 4), staProtocol.getStaNo()); // 目标站 |
| | | Thread.sleep(300); |
| | | if (write1.IsSuccess) { |
| | | OperateResultExOne<byte[]> readResult1 = siemensS7Net.Read("DB100." + (index * 6 + 4), (short) 2); |
| | | if (readResult1.IsSuccess) { |
| | | short staNo = siemensS7Net.getByteTransform().TransInt16(readResult1.Content, 0); |
| | | if (staProtocol.getStaNo().equals(staNo)) { |
| | | //任务命令写入成功 |
| | | log.info("写入目标站命令后返回成功,并且回读成功。堆垛机plc编号={},{},写入次数={}", slave.getId(), JSON.toJSON(staProtocol), writeCount); |
| | | staNoFlag = true; |
| | | } else {//返回结果是成功了,但是真实值不相同 |
| | | writeCount++; |
| | | log.error("写入目标站命令后返回成功,但是读取任务值不一致。堆垛机plc编号={},{},写入次数={}", slave.getId(), JSON.toJSON(staProtocol), writeCount); |
| | | } |
| | | } else { |
| | | writeCount++; |
| | | log.error("写入目标站命令后读取失败。堆垛机plc编号={},站点数据={},写入次数={}", slave.getId(), JSON.toJSON(staProtocol), writeCount); |
| | | } |
| | | staNoFlag = true; |
| | | // OperateResultExOne<byte[]> readResult1 = siemensS7Net.Read("DB100." + (index * 6 + 4), (short) 2); |
| | | // if (readResult1.IsSuccess) { |
| | | // short staNo = siemensS7Net.getByteTransform().TransInt16(readResult1.Content, 0); |
| | | // if (staProtocol.getStaNo().equals(staNo)) { |
| | | // //任务命令写入成功 |
| | | // log.info("写入目标站命令后返回成功,并且回读成功。堆垛机plc编号={},{},{},写入次数={}", slave.getId(), staProtocol.getStaNo(), staNo, writeCount); |
| | | // staNoFlag = true; |
| | | // } else {//返回结果是成功了,但是真实值不相同 |
| | | // writeCount++; |
| | | // log.error("写入目标站命令后返回成功,但是读取任务值不一致。堆垛机plc编号={},{},{},写入次数={}", slave.getId(), staProtocol.getStaNo(), staNo, writeCount); |
| | | // } |
| | | // } else { |
| | | // writeCount++; |
| | | // log.error("写入目标站命令后读取失败。堆垛机plc编号={},站点数据={},写入次数={}", slave.getId(), JSON.toJSON(staProtocol), writeCount); |
| | | // } |
| | | } else { |
| | | writeCount++; |
| | | log.error("写入目标站命令失败。堆垛机plc编号={},站点数据={},写入次数={}", slave.getId(), JSON.toJSON(staProtocol), writeCount); |
| | |
| | | if (wrkNoFlag && staNoFlag) { |
| | | break; |
| | | } |
| | | } while (writeCount < 12); |
| | | Thread.sleep(200); |
| | | } while (writeCount < 20); |
| | | |
| | | if (!write.IsSuccess) { |
| | | staProtocol = station.get(staProtocol.getSiteId()); |
| | |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | System.out.println(staNos1.indexOf(129)); |
| | | System.out.println(staNos1.size()); |
| | | for (int i = 0; i < staNos1.size(); i++) { |
| | | // System.out.println(i*2); |
| | | // System.out.println(i*2 + 200); |
| | | // System.out.println(i); |
| | | } |
| | | int index = staNos1.indexOf(128); |
| | | System.out.println(index * 2); |
| | | System.out.println(index * 2 + 200); |
| | | int i=1; |
| | | do { |
| | | System.out.println(i); |
| | | i++; |
| | | if (i==4){ |
| | | break; |
| | | } |
| | | |
| | | }while (i<6); |
| | | StaProtocol staProtocol = new StaProtocol(); |
| | | staProtocol.setWorkNo((short) 6071); |
| | | //short i = (short) 6071; |
| | | //System.out.println(staProtocol.getWorkNo().equals(i)); |
| | | // System.out.println(staNos1.indexOf(129)); |
| | | // System.out.println(staNos1.size()); |
| | | // for (int i = 0; i < staNos1.size(); i++) { |
| | | //// System.out.println(i*2); |
| | | //// System.out.println(i*2 + 200); |
| | | //// System.out.println(i); |
| | | // } |
| | | // int index = staNos1.indexOf(128); |
| | | // System.out.println(index * 2); |
| | | // System.out.println(index * 2 + 200); |
| | | } |
| | | |
| | | // public static void main(String[] args) throws Exception { |