| | |
| | | } |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public boolean connect() { |
| | | boolean result = false; |
| | |
| | | } |
| | | StaProtocol staProtocol = station.get(barcodeSite2.get(i)); |
| | | if (staProtocol != null) { |
| | | while (iterator.hasNext()) { |
| | | String next = iterator.next(); |
| | | if (next.length() < 7 || next.length() > 10 || !next.matches("[0-9]*")) { |
| | | iterator.remove(); |
| | | } |
| | | } |
| | | staProtocol.setMatIdList(barcodeList); |
| | | } |
| | | } |
| | |
| | | } |
| | | |
| | | // 读正面故障反馈 |
| | | OperateResultExOne<byte[]> resultErr = siemensS7Net.Read("DB101.922.0", (short) (16 * 4)); |
| | | OperateResultExOne<byte[]> resultErr = siemensS7Net.Read("DB101.2340.0", (short) (16 * 2)); |
| | | if (resultErr.IsSuccess) { |
| | | for (int i = 0; i < 16; i++) { |
| | | Integer siteId = staNos.get(i); // 站点编号 |
| | | boolean[] status = siemensS7Net.getByteTransform().TransBool(resultErr.Content, i * 4, 1); |
| | | boolean[] status = siemensS7Net.getByteTransform().TransBool(resultErr.Content, i * 2, 2); |
| | | StaProtocol staProtocol = station.get(siteId); |
| | | staProtocol.setBreakerErr(status[0]); |
| | | staProtocol.setInfraredErr(status[1]); |
| | |
| | | staProtocol.setInverterErr(status[5]); |
| | | staProtocol.setContactErr(status[6]); |
| | | staProtocol.setUpcontactErr(status[7]); |
| | | |
| | | staProtocol.setPushTheEnvelopeErr(status[8]); |
| | | staProtocol.setRaiseTheLowerLimitErr(status[9]); |
| | | staProtocol.setLeftProtectionTriggersErr(status[10]); |
| | | staProtocol.setRightProtectionTriggersErr(status[11]); |
| | | staProtocol.setGratingBlockingErr(status[12]); |
| | | } |
| | | } |
| | | |
| | | // 读侧面故障反馈 |
| | | OperateResultExOne<byte[]> resultErrCM = siemensS7Net.Read("DB101.2540.0", (short) (12 * 4)); |
| | | OperateResultExOne<byte[]> resultErrCM = siemensS7Net.Read("DB101.2540.0", (short) (12 * 2)); |
| | | if (resultErrCM.IsSuccess) { |
| | | for (int i = 16; i < staNoSize; i++) { |
| | | Integer siteId = staNos.get(i); // 站点编号 |
| | | boolean[] status = siemensS7Net.getByteTransform().TransBool(resultErrCM.Content, (i - 16) * 4, 1); |
| | | boolean[] status = siemensS7Net.getByteTransform().TransBool(resultErrCM.Content, (i - 16) * 2, 1); |
| | | StaProtocol staProtocol = station.get(siteId); |
| | | staProtocol.setBreakerErr(status[0]); |
| | | staProtocol.setInfraredErr(status[1]); |
| | |
| | | //任务下发成功标识 |
| | | boolean writeFlag = false; |
| | | while (writeCount < 5) { |
| | | OperateResult writeResult1 = siemensS7Net.Write(workNoAddress, staProtocol.getWorkNo()); // 工作号 |
| | | OperateResult writeResult2 = siemensS7Net.Write(staNoAddress, staProtocol.getStaNo()); // 目标站 |
| | | if (!Cools.isEmpty(staProtocol.getHeight()) && heightAddress != null) { |
| | | OperateResult writeResult3 = siemensS7Net.Write(heightAddress, Short.parseShort(staProtocol.getHeight())); // 目标站 |
| | | log.info("写入高度地址:{},{}", heightAddress, writeResult3); |
| | | OperateResult writeResult3 = siemensS7Net.Write(heightAddress, Short.parseShort(staProtocol.getHeight())); |
| | | writeResult3 = siemensS7Net.Write(heightAddress, Short.parseShort(staProtocol.getHeight())); |
| | | writeResult3 = siemensS7Net.Write(heightAddress, Short.parseShort(staProtocol.getHeight())); |
| | | writeResult3 = siemensS7Net.Write(heightAddress, Short.parseShort(staProtocol.getHeight())); |
| | | log.info("写入高度地址:{},{}", heightAddress, writeResult3); |
| | | if (!writeResult3.IsSuccess) { |
| | | //fangzhi xierukushibai,jiu duoxiejici,meixunhuan |
| | | writeResult3 = siemensS7Net.Write(heightAddress, Short.parseShort(staProtocol.getHeight())); |
| | |
| | | } |
| | | } |
| | | } |
| | | // 侧面出库,给输送线写条码 |
| | | Short staNo = staProtocol.getStaNo(); |
| | | String barcode = staProtocol.getBarcode(); |
| | | if (staNo == 203 || staNo == 207 || staNo == 212) { |
| | | if (Cools.isEmpty(barcode)) { |
| | | log.error("侧面出库到:{}站点,条码值为空,任务号:{}", staNo, staProtocol.getWorkNo()); |
| | | } else { |
| | | |
| | | String[] split = barcode.split("#"); |
| | | int offset = 48 + (staNo - 201) * 24; |
| | | byte[] bytes = new byte[(split.length + 1) * 6]; |
| | | for (int j = 0, k = 0; j < split.length; j++) { |
| | | String s = split[j]; |
| | | for (int m = 0; m < s.length(); m++) { |
| | | bytes[k++] = (byte) s.charAt(m); |
| | | } |
| | | } |
| | | |
| | | OperateResult writeResult4 = siemensS7Net.Write("DB79" + offset, bytes); |
| | | if (writeResult4.IsSuccess) { |
| | | log.info("侧面出库到:{}站点,给输送线写条码:{}成功", staNo, barcode); |
| | | } else { |
| | | log.error("侧面出库到:{}站点,给输送线写条码:{}失败", staNo, barcode); |
| | | } |
| | | } |
| | | } |
| | | |
| | | OperateResult writeResult1 = siemensS7Net.Write(workNoAddress, staProtocol.getWorkNo()); // 工作号 |
| | | OperateResult writeResult2 = siemensS7Net.Write(staNoAddress, staProtocol.getStaNo()); // 目标站 |
| | | if (writeResult1.IsSuccess && writeResult2.IsSuccess) { |
| | | Thread.sleep(200); |
| | | OperateResultExOne<byte[]> readResult = siemensS7Net.Read("DB100." + index * 4, (short) 2); |
| | |
| | | |
| | | if (slave.getId() == 1 && this.ioModeOf2F1 != null) { |
| | | if (!siemensS7Net.Write("DB105.10", this.ioModeOf2F1.id).IsSuccess) { |
| | | OutputQueue.DEVP.offer(MessageFormat.format("【{0}】写入输送线2F2入出库模式失败。输送线plc编号={1}", slave.getId())); |
| | | OutputQueue.DEVP.offer(MessageFormat.format("【{0}】写入输送线2F1入出库模式失败。输送线plc编号={1}", slave.getId())); |
| | | log.error("写入输送线2F1入出库模式失败。输送线plc编号={}", slave.getId()); |
| | | } |
| | | } |
| | | if (slave.getId() == 1 && this.ioModeOf2F2 != null) { |
| | | if (!siemensS7Net.Write("DB105.12", this.ioModeOf2F2.id).IsSuccess) { |
| | | OutputQueue.DEVP.offer(MessageFormat.format("【{0}】写入输送线3F1入出库模式失败。输送线plc编号={1}", slave.getId())); |
| | | OutputQueue.DEVP.offer(MessageFormat.format("【{0}】写入输送线2F2入出库模式失败。输送线plc编号={1}", slave.getId())); |
| | | log.error("写入输送线2F2入出库模式失败。输送线plc编号={}", slave.getId()); |
| | | } |
| | | } |
| | | if (slave.getId() == 1 && this.ioModeOf2F3 != null) { |
| | | if (!siemensS7Net.Write("DB105.14", this.ioModeOf2F3.id).IsSuccess) { |
| | | OutputQueue.DEVP.offer(MessageFormat.format("【{0}】写入输送线3F2入出库模式失败。输送线plc编号={1}", slave.getId())); |
| | | OutputQueue.DEVP.offer(MessageFormat.format("【{0}】写入输送线2F3入出库模式失败。输送线plc编号={1}", slave.getId())); |
| | | log.error("写入输送线2F3入出库模式失败。输送线plc编号={}", slave.getId()); |
| | | } |
| | | } |
| | |
| | | public void close() { |
| | | siemensS7Net.ConnectClose(); |
| | | } |
| | | public static void main(String[] args) throws Exception { |
| | | DevpSlave slave = new DevpSlave(); |
| | | slave.setIp("10.49.210.41"); |
| | | // SiemensDevpThread devpThread = new SiemensDevpThread(slave); |
| | | // devpThread.connect(); |
| | | SiemensS7Net siemensS7Net = new SiemensS7Net(SiemensPLCS.S1200, slave.getIp()); |
| | | siemensS7Net.setRack(slave.getRack().byteValue()); |
| | | siemensS7Net.setSlot(slave.getSlot().byteValue()); |
| | | OperateResult connect = siemensS7Net.ConnectServer(); |
| | | // 侧面出库,给输送线写条码 |
| | | Short staNo = 212; |
| | | String barcode = "800001#123456#811112#811113"; |
| | | |
| | | |
| | | String[] split = barcode.split("#"); |
| | | int offset = 48 + (staNo - 201) * 24; |
| | | byte[] bytes = new byte[(split.length + 1) * 6]; |
| | | for (int j = 0, k = 0; j < split.length; j++) { |
| | | String s = split[j]; |
| | | for (int m = 0; m < s.length(); m++) { |
| | | bytes[k++] = (byte) s.charAt(m); |
| | | } |
| | | } |
| | | |
| | | OperateResult writeResult4 = siemensS7Net.Write("DB79" + offset, bytes); |
| | | if (writeResult4.IsSuccess) { |
| | | log.info("侧面出库到:{}站点,给输送线写条码:{}成功", staNo, barcode); |
| | | } else { |
| | | log.error("侧面出库到:{}站点,给输送线写条码:{}失败", staNo, barcode); |
| | | } |
| | | |
| | | // devpThread.write2(0); |
| | | // devpThread.read(); |
| | | // // 写 |
| | | // StaProtocol staProtocol = devpThread.getStation().get(1); |
| | | // staProtocol.setWorkNo((short) 232); |
| | | // staProtocol.setStaNo((short) 6); |
| | | // staProtocol.setAutoing(true); |
| | | // staProtocol.setEmptyMk(true); |
| | | // staProtocol.setInEnable(true); |
| | | // devpThread.write(staProtocol); |
| | | // System.out.println("----------------------------------------"); |
| | | // // 读 |
| | | // devpThread.read(); |
| | | // System.out.println(JSON.toJSONString(devpThread.station)); |
| | | |
| | | } |
| | | |
| | | } |