| | |
| | | add(2022);add(2024); |
| | | add(2028);add(2030); |
| | | add(2025);add(2027); |
| | | add(2031);add(2033); |
| | | add(2031);add(2032);add(2033); |
| | | add(2034);add(2035);add(2037); |
| | | // add(2041);add(2042);add(2043);add(2044); |
| | | // add(2045);add(2046);add(2047);add(2048); |
| | |
| | | boolean[] status1 = siemensS7Net.getByteTransform().TransBool(result.Content, offset + offset3 - 4, 3); |
| | | boolean[] statusErr = siemensS7Net.getByteTransform().TransBool(result.Content, offset + offset3 - 8, 3); |
| | | boolean[] statusSign = siemensS7Net.getByteTransform().TransBool(resultErr.Content, offsetSign, 3); |
| | | if(siteId == 2032){ |
| | | |
| | | } |
| | | boolean loading = false; |
| | | if(!status1[0]) |
| | | { |
| | |
| | | Integer offset = siteOffsetMap.get(siteId); |
| | | Integer offset2 = getOffsetBySiteId(siteId); |
| | | Integer offset3 = getOffsetBySiteId2(siteId); |
| | | //任务下发次数 |
| | | OperateResult write = null; |
| | | OperateResult write1 = null; |
| | | //任务下发次数 |
| | | int writeCount = 0; |
| | | do { |
| | | |
| | | String workNoAddress = ""; |
| | | String staNoAddress = ""; |
| | | |
| | | // 根据站点判断地址 |
| | | if (siteId < 1029) { |
| | | workNoAddress = "DB100." + (offset + offset2); |
| | | staNoAddress = "DB100." + (offset + offset2 + 12); |
| | | } else if (siteId < 1042) { |
| | | workNoAddress = "DB101." + (offset + offset2); |
| | | staNoAddress = "DB101." + (offset + offset2 + 12); |
| | | } else if (siteId < 1054) { |
| | | workNoAddress = "DB104." + (offset + offset2); |
| | | staNoAddress = "DB104." + (offset + offset2 + (specialSites2.contains(siteId) ? 48 : 12)); |
| | | } else if (siteId < 1080) { |
| | | workNoAddress = "DB103." + (offset + offset2); |
| | | staNoAddress = "DB103." + (offset + offset2 + (specialSites2.contains(siteId) ? 48 : 12)); |
| | | } else if (siteId < 1111) { |
| | | workNoAddress = "DB102." + (offset + offset2); |
| | | staNoAddress = "DB102." + (offset + offset2 + (specialSites2.contains(siteId) ? 48 : 12)); |
| | | } else if (siteId < 2031) { |
| | | workNoAddress = "DB200." + (offset + offset2); |
| | | staNoAddress = "DB200." + (offset + offset2 + (specialSites2.contains(siteId) ? 48 : 12)); |
| | | } else if (siteId < 2121) { |
| | | workNoAddress = "DB201." + (offset + offset2); |
| | | staNoAddress = "DB201." + (offset + offset2 + (specialSites2.contains(siteId) ? 48 : 12)); |
| | | } else if (siteId < 4000) { |
| | | Integer offsetBarcode = site2lBarcodeOffsetMap.get(siteId); |
| | | workNoAddress = "DB202." + offsetBarcode; |
| | | staNoAddress = "DB202." + offsetBarcode; // For barcode site, only one address used |
| | | } else { |
| | | workNoAddress = "DB400." + (offset + offset2); |
| | | staNoAddress = "DB400." + (offset + offset2 + (specialSites2.contains(siteId) ? 48 : 12)); |
| | | } |
| | | |
| | | // 执行写入 |
| | | write = siemensS7Net.Write(workNoAddress, staProtocol.getWorkNo()); // 写入工作号 |
| | | Thread.sleep(200); |
| | | write1 = siemensS7Net.Write(staNoAddress, staProtocol.getStaNo().intValue()); // 写入目标站 |
| | | |
| | | // 读取并验证 |
| | | if (write.IsSuccess && write1.IsSuccess) { |
| | | // 假设使用 ReadInt() 方法读取 Int32 数据 |
| | | OperateResultExOne<byte[]> readResult1 = siemensS7Net.Read(workNoAddress, (short) 4); // 读取工作号 |
| | | OperateResultExOne<byte[]> readResult2 = siemensS7Net.Read(staNoAddress,(short) 4); // 读取目标站 |
| | | if (readResult1.IsSuccess && readResult2.IsSuccess) { |
| | | Integer writtenWorkNo = staProtocol.getWorkNo(); |
| | | Integer writtenStaNo = staProtocol.getStaNo().intValue(); |
| | | Integer workNo = siemensS7Net.getByteTransform().TransInt32(readResult1.Content, 0); |
| | | Integer staNo = siemensS7Net.getByteTransform().TransInt32(readResult2.Content, 0); |
| | | |
| | | // 对比读取到的数据与写入的数据是否一致 |
| | | if (workNo == writtenWorkNo && staNo == writtenStaNo) { |
| | | log.error("写入输送线命令成功。输送线plc编号={},站点数据={},写入次数={}", slave.getId(), JSON.toJSON(staProtocol), writeCount); |
| | | break; // 数据一致,跳出循环 |
| | | } else { |
| | | writeCount++; |
| | | log.error("写入输送线命令失败,数据不一致。输送线plc编号={},站点数据={},写入次数={}", slave.getId(), JSON.toJSON(staProtocol), writeCount); |
| | | } |
| | | if(siteId < 1029){ |
| | | write = siemensS7Net.Write("DB100." + (offset + offset2), staProtocol.getWorkNo()); // 工作号 |
| | | Thread.sleep(200); |
| | | write1 = siemensS7Net.Write("DB100." + (offset + offset2 + 12), staProtocol.getStaNo().intValue()); // 目标站 |
| | | }else if(siteId < 1042){ |
| | | write = siemensS7Net.Write("DB101." + (offset + offset2), staProtocol.getWorkNo()); // 工作号 |
| | | Thread.sleep(200); |
| | | write1 = siemensS7Net.Write("DB101." + (offset + offset2 + 12), staProtocol.getStaNo().intValue()); // 目标站 |
| | | }else if(siteId < 1054){ |
| | | write = siemensS7Net.Write("DB104." + (offset + offset2), staProtocol.getWorkNo()); // 工作号 |
| | | Thread.sleep(200); |
| | | if(specialSites2.contains(siteId)){ |
| | | write1 = siemensS7Net.Write("DB104." + (offset + offset2 + 48), staProtocol.getStaNo().intValue()); // 目标站 |
| | | }else{ |
| | | write1 = siemensS7Net.Write("DB104." + (offset + offset2 + 12), staProtocol.getStaNo().intValue()); // 目标站 |
| | | } |
| | | } else { |
| | | }else if(siteId < 1080){ |
| | | write = siemensS7Net.Write("DB103." + (offset + offset2), staProtocol.getWorkNo()); // 工作号 |
| | | Thread.sleep(200); |
| | | if(specialSites2.contains(siteId)){ |
| | | write1 = siemensS7Net.Write("DB103." + (offset + offset2 + 48), staProtocol.getStaNo().intValue()); // 目标站 |
| | | }else{ |
| | | write1 = siemensS7Net.Write("DB103." + (offset + offset2 + 12), staProtocol.getStaNo().intValue()); // 目标站 |
| | | } |
| | | }else if(siteId < 1111){ |
| | | write = siemensS7Net.Write("DB102." + (offset + offset2), staProtocol.getWorkNo()); // 工作号 |
| | | Thread.sleep(200); |
| | | if(specialSites2.contains(siteId)){ |
| | | write1 = siemensS7Net.Write("DB102." + (offset + offset2 + 48), staProtocol.getStaNo().intValue()); // 目标站 |
| | | }else{ |
| | | write1 = siemensS7Net.Write("DB102." + (offset + offset2 + 12), staProtocol.getStaNo().intValue()); // 目标站 |
| | | } |
| | | }else if(siteId < 2031){ |
| | | write = siemensS7Net.Write("DB200." + (offset + offset2), staProtocol.getWorkNo()); // 工作号 |
| | | Thread.sleep(200); |
| | | if(specialSites2.contains(siteId)){ |
| | | write1 = siemensS7Net.Write("DB200." + (offset + offset2 + 48), staProtocol.getStaNo().intValue()); // 目标站 |
| | | }else{ |
| | | write1 = siemensS7Net.Write("DB200." + (offset + offset2 + 12), staProtocol.getStaNo().intValue()); // 目标站 |
| | | } |
| | | }else if(siteId < 2121){ |
| | | write = siemensS7Net.Write("DB201." + (offset + offset2), staProtocol.getWorkNo()); // 工作号 |
| | | Thread.sleep(200); |
| | | if(specialSites2.contains(siteId)){ |
| | | write1 = siemensS7Net.Write("DB201." + (offset + offset2 + 48), staProtocol.getStaNo().intValue()); // 目标站 |
| | | }else{ |
| | | write1 = siemensS7Net.Write("DB201." + (offset + offset2 + 12), staProtocol.getStaNo().intValue()); // 目标站 |
| | | } |
| | | } else if(siteId < 4000){ |
| | | Integer offsetBarcode = site2lBarcodeOffsetMap.get(siteId); |
| | | write = siemensS7Net.Write("DB202." + offsetBarcode, staProtocol.getBarcode()); // 条码 |
| | | write1 = siemensS7Net.Write("DB202." + offsetBarcode, staProtocol.getBarcode()); |
| | | Thread.sleep(200); |
| | | }else{ |
| | | write = siemensS7Net.Write("DB400." + (offset + offset2), staProtocol.getWorkNo()); // 工作号 |
| | | Thread.sleep(200); |
| | | if(specialSites2.contains(siteId)){ |
| | | write1 = siemensS7Net.Write("DB400." + (offset + offset2 + 48), staProtocol.getStaNo().intValue()); // 目标站 |
| | | }else{ |
| | | write1 = siemensS7Net.Write("DB400." + (offset + offset2 + 12), staProtocol.getStaNo().intValue()); // 目标站 |
| | | } |
| | | } |
| | | if(write.IsSuccess && write1.IsSuccess){ |
| | | log.error("写入输送线命令成功。输送线plc编号={},站点数据={},写入次数={}", slave.getId(), JSON.toJSON(staProtocol), writeCount); |
| | | break; |
| | | } |
| | | else { |
| | | writeCount++; |
| | | log.error("写入输送线命令失败。输送线plc编号={},站点数据={},写入次数={}", slave.getId(), JSON.toJSON(staProtocol), writeCount); |
| | | } |
| | | |
| | | } while (writeCount < 5); // 重试最多5次 |
| | | |
| | | |
| | | }while (writeCount<5); |
| | | try { |
| | | // 日志记录 |
| | | BasDevpOptService bean = SpringUtils.getBean(BasDevpOptService.class); |