| | |
| | | }}; |
| | | |
| | | public static final ArrayList<Integer> BarcodeList = new ArrayList<Integer>() {{ |
| | | add(1);add(2);add(3);add(4); |
| | | add(5);add(6);add(7);add(8); |
| | | add(0);add(1);add(2);add(3); |
| | | add(4);add(5);add(6);add(7); |
| | | }}; |
| | | |
| | | public static final ArrayList<Integer> staNosErrList = new ArrayList<Integer>() {{ |
| | |
| | | // updateIoMode(); |
| | | ArrayList<Integer> staNos = getStaNo(); |
| | | int staNoSize = staNos.size(); |
| | | OperateResultExOne<byte[]> result = siemensS7Net.Read("DB101.0", (short) (staNoSize*8)); |
| | | OperateResultExOne<byte[]> result = siemensS7Net.Read("DB101.0", (short) (staNoSize*2)); |
| | | if (result.IsSuccess) { |
| | | for (int i = 0; i < staNoSize; i++) { |
| | | Integer siteId = staNos.get(i); // 站点编号 |
| | |
| | | staProtocol.setSiteId(siteId); |
| | | station.put(siteId, staProtocol); |
| | | } |
| | | staProtocol.setWorkNo(siemensS7Net.getByteTransform().TransInt32(result.Content, i*8)); // 工作号 |
| | | |
| | | staProtocol.setStaNo(siemensS7Net.getByteTransform().TransInt16(result.Content, i*8 + 4)); // 目标站 |
| | | |
| | | boolean[] status = siemensS7Net.getByteTransform().TransBool(result.Content, i*8 + 6, 2); |
| | | boolean[] status = siemensS7Net.getByteTransform().TransBool(result.Content, i*2, 2); |
| | | staProtocol.setAutoing(status[0]); // 自动 |
| | | staProtocol.setLoading(status[1]); // 有物 |
| | | staProtocol.setInEnable(status[2]); // 可入 |
| | |
| | | } |
| | | } |
| | | |
| | | OperateResultExOne<byte[]> result1 = siemensS7Net.Read("DB100.0", (short) (staNoSize*4)); |
| | | if (result1.IsSuccess) { |
| | | for (int i = 0; i < staNoSize; i++) { |
| | | Integer siteId = staNos.get(i); // 站点编号 |
| | | StaProtocol staProtocol = station.get(siteId); |
| | | if (null == staProtocol) { |
| | | staProtocol = new StaProtocol(); |
| | | staProtocol.setSiteId(siteId); |
| | | station.put(siteId, staProtocol); |
| | | } |
| | | staProtocol.setWorkNo((int) siemensS7Net.getByteTransform().TransInt16(result1.Content, i*4)); // 工作号 |
| | | staProtocol.setStaNo(siemensS7Net.getByteTransform().TransInt16(result1.Content, i*4 + 2)); // 目标站 |
| | | } |
| | | } |
| | | |
| | | //条码扫描器 |
| | | ArrayList<Integer> barcodeList = BarcodeList; |
| | | OperateResultExOne<byte[]> result2 = siemensS7Net.Read("DB101.100", (short) (barcodeList.size() * 8)); |
| | | OperateResultExOne<byte[]> result2 = siemensS7Net.Read("DB101.100", (short) (barcodeList.size() * 10)); |
| | | if (result2.IsSuccess) { |
| | | for (int i = 0; i < barcodeList.size(); i++) { |
| | | Integer barcodeId = barcodeList.get(i); |
| | | String barcode = siemensS7Net.getByteTransform().TransString(result2.Content,i*8,8, "UTF-8"); |
| | | String barcode = siemensS7Net.getByteTransform().TransString(result2.Content,i*10+2,8, "UTF-8"); |
| | | barcode = barcode.trim(); |
| | | BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, barcodeId + 1); |
| | | if(!Cools.isEmpty(barcodeThread) && !barcodeThread.getBarcode().equals(barcode)) { |
| | | barcodeThread.setBarcode(barcode); |
| | |
| | | ArrayList<Integer> staNos = getStaNo(); |
| | | int index = staNos.indexOf(staProtocol.getSiteId()); |
| | | OperateResult write = null; |
| | | OperateResult write1 = null; |
| | | //任务下发次数 |
| | | int writeCount = 0; |
| | | do { |
| | | write = siemensS7Net.Write("DB108." + index*6, staProtocol.getWorkNo()); // 工作号 |
| | | Thread.sleep(200); |
| | | write1 = siemensS7Net.Write("DB108." + (index*6+4), staProtocol.getStaNo().shortValue()); // 目标站 |
| | | if(write.IsSuccess && write1.IsSuccess){ |
| | | short[] data = new short[2]; |
| | | data[0] = staProtocol.getWorkNo().shortValue(); |
| | | data[1] = staProtocol.getStaNo(); |
| | | |
| | | write = siemensS7Net.Write("DB100." + index*4, data); |
| | | if(write.IsSuccess){ |
| | | log.error("写入输送线命令成功。输送线plc编号={},站点数据={},写入次数={}", slave.getId(), JSON.toJSON(staProtocol), writeCount); |
| | | break; |
| | | } |