| | |
| | | add(10); add(11); add(12); add(13); |
| | | }}; |
| | | public static final ArrayList<Integer> staNosErrList2 = new ArrayList<Integer>() {{ |
| | | add(101); add(104);add(106);add(108); |
| | | add(202);add(204);add(207);add(210); |
| | | add(102); add(105);add(107);add(109); |
| | | add(203);add(205);add(208);add(211); |
| | | }}; |
| | | |
| | | public static final ArrayList<Integer> staNosErrList1 = new ArrayList<Integer>() {{ |
| | | add(122); |
| | | add(222);add(224);add(227);add(230); |
| | | add(123); |
| | | add(223);add(225);add(228);add(231); |
| | | }}; |
| | | |
| | | public static final ArrayList<Integer> staNoWeight1 = new ArrayList<Integer>() {{ |
| | | add(123); |
| | | add(223);add(225);add(228);add(231); |
| | | }}; |
| | | |
| | | public static final ArrayList<Integer> staNoWeight2 = new ArrayList<Integer>() {{ |
| | | add(102);add(105);add(107);add(109); |
| | | add(203);add(205);add(208);add(211); |
| | | }}; |
| | | |
| | | public static final ArrayList<Integer> staNosInList1 = new ArrayList<Integer>() {{ |
| | | add(122); |
| | | add(222);add(224);add(227);add(230); |
| | | }}; |
| | | |
| | | public static final ArrayList<Integer> staNosInList2 = new ArrayList<Integer>() {{ |
| | | add(101); add(104);add(106);add(108); |
| | | add(202);add(204);add(207);add(210); |
| | | }}; |
| | | |
| | | private Integer count=0; |
| | |
| | | |
| | | public SiemensDevpThread(DevpSlave slave) { |
| | | this.slave = slave; |
| | | } |
| | | |
| | | private ArrayList<Integer> getStaNoIn() { |
| | | switch (slave.getId()) { |
| | | case 1: |
| | | return staNosInList1; |
| | | case 2: |
| | | return staNosInList2; |
| | | default: |
| | | throw new CoolException("服务器异常"); |
| | | } |
| | | } |
| | | |
| | | private ArrayList<Integer> getStaNoErr() { |
| | |
| | | write((StaProtocol)task.getData()); |
| | | log.error("输送线下发命令:"+((StaProtocol) task.getData()).getWorkNo()+","+((StaProtocol) task.getData()).getStaNo()); |
| | | break; |
| | | case 3: |
| | | write2((StaProtocol)task.getData()); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | |
| | | OutputQueue.DEVP.offer(MessageFormat.format( "【{0}】输送线plc连接失败!!! ===>> [id:{1}] [ip:{2}] [port:{3}] [rack:{4}] [slot:{5}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot())); |
| | | News.error("SiemensDevp"+" - 2"+" - 输送线plc连接失败!!! ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); |
| | | } |
| | | siemensS7Net.ConnectClose(); |
| | | // siemensS7Net.ConnectClose(); |
| | | initSite(); |
| | | return result; |
| | | } |
| | |
| | | private void read() throws InterruptedException { |
| | | // // 更新入出库模式 |
| | | // updateIoMode(); |
| | | |
| | | // if (slave.getId()==1) return; |
| | | ArrayList<Integer> staNos = getStaNo(); |
| | | ArrayList<Integer> staNosErrList = getStaNoErr(); |
| | | ArrayList<Integer> staNoWeight = getStaNoWeight(); |
| | | ArrayList<Integer> staNosInList = getStaNoIn(); |
| | | int staNoSize = staNos.size(); |
| | | OperateResultExOne<byte[]> result = siemensS7Net.Read("DB101.0", (short) (500 * 8)); |
| | | OperateResultExOne<byte[]> resultWeight = siemensS7Net.Read("DB102.0", (short) (10 * 4)); |
| | | OperateResultExOne<byte[]> resultWeight1 = siemensS7Net.Read("DB102.8", (short) (10)); |
| | | OperateResultExOne<byte[]> resultWeight = null; |
| | | if(staNoWeight.size()>4){ |
| | | resultWeight = siemensS7Net.Read("DB102.0", (short) (8 * 4)); |
| | | }else{ |
| | | resultWeight = siemensS7Net.Read("DB102.0", (short) (4 * 4)); |
| | | } |
| | | OperateResultExOne<byte[]> resultWeight2 = siemensS7Net.Read("DB102.0", (short) (4 * 4)); |
| | | |
| | | if (result.IsSuccess && resultWeight.IsSuccess) { |
| | | int j = 0; |
| | |
| | | |
| | | staProtocol.setWorkNo(siemensS7Net.getByteTransform().TransInt32(result.Content, offset)); // 工作号 |
| | | if (staNoWeight.contains(siteId)) { |
| | | staProtocol.setWeight(siemensS7Net.getByteTransform().TransInt32(resultWeight.Content, j)); |
| | | j = j + 4; |
| | | if(staNoWeight.size() == 4){ |
| | | staProtocol.setWeight(siemensS7Net.getByteTransform().TransInt32(resultWeight2.Content, j)); |
| | | j = j + 4; |
| | | }else{ |
| | | staProtocol.setWeight(siemensS7Net.getByteTransform().TransInt32(resultWeight.Content, j)); |
| | | j = j + 4; |
| | | |
| | | } |
| | | } |
| | | staProtocol.setStaNo(siemensS7Net.getByteTransform().TransInt16(result.Content, offset+ 4)); // 目标站 |
| | | status = siemensS7Net.getByteTransform().TransBool(result.Content, offset+ 6, 2); |
| | |
| | | staProtocol.setBarcodeErr(status[6]); |
| | | } |
| | | } |
| | | |
| | | //入库满足 |
| | | ArrayList<Integer> staNosIns = staNosInList; |
| | | int staNosInSize = staNosIns.size(); |
| | | OperateResultExOne<byte[]> resultIn = siemensS7Net.Read("DB1000.0", (short) (staNosInSize * 6)); |
| | | if(resultIn.IsSuccess){ |
| | | for (int i = 0; i < staNosInSize; i++) { |
| | | Integer siteId = staNosIns.get(i); |
| | | StaProtocol staProtocol = station.get(siteId); |
| | | staProtocol.setStamp( siemensS7Net.getByteTransform().TransInt16(resultIn.Content, i*6)); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | // //plc故障 |
| | | // OperateResultExOne<byte[]> resultErr2 = siemensS7Net.Read("DB101.1728", (short) (staNoSize*4)); |
| | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 写入 ID+目标站 =====> 单站点写入 |
| | | */ |
| | | |
| | | private void write2(StaProtocol staProtocol) throws InterruptedException { |
| | | OperateResult write = null; |
| | | int writeCount = 0; |
| | | ArrayList<Integer> staNosInList = getStaNoIn(); |
| | | |
| | | ArrayList<Integer> staNosIns = staNosInList; |
| | | int staNosInSize = staNosIns.size(); |
| | | OperateResultExOne<byte[]> resultIn = siemensS7Net.Read("DB1000.0", (short) (staNosInSize * 6)); |
| | | int offset = 0; |
| | | if(resultIn.IsSuccess){ |
| | | for (int i = 0; i < staNosInSize; i++) { |
| | | Integer siteId = staNosIns.get(i); |
| | | if(staProtocol.getSiteId().equals(siteId)){ |
| | | offset = i*6 + 2; |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | do { |
| | | write = siemensS7Net.Write("DB1000.0" + offset,staProtocol.getWorkNo()); // 工作号 |
| | | |
| | | if(write.IsSuccess ){ |
| | | log.error("写入工作号{}",staProtocol.getWorkNo()); |
| | | log.error("写入输命令成功。输送线plc编号={},写入次数={}", slave.getId(), writeCount); |
| | | break; |
| | | } |
| | | else { |
| | | writeCount++; |
| | | log.error("写入命令失败。输送线plc编号={},站点数据={},写入次数={}", slave.getId(), JSON.toJSON(staProtocol), writeCount); |
| | | } |
| | | }while (writeCount<5); |
| | | } |
| | | |
| | | /** |
| | | * 写入 ID+目标站 =====> 单站点写入 |
| | | */ |
| | | private void write(StaProtocol staProtocol) throws InterruptedException { |
| | | if (null == staProtocol) { |
| | | return; |
| | |
| | | |
| | | OperateResult write = null; |
| | | OperateResult write1 = null; |
| | | boolean flag1 = false; |
| | | boolean flag2 = false; |
| | | //任务下发次数 |
| | | int writeCount = 0; |
| | | do { |
| | | write = siemensS7Net.Write("DB100." + offset, staProtocol.getWorkNo()); // 工作号 |
| | | Thread.sleep(200); |
| | | write1 = siemensS7Net.Write("DB100." + (offset+4), staProtocol.getStaNo().shortValue()); // 目标站 |
| | | if(write.IsSuccess && write1.IsSuccess){ |
| | | if (!flag1) { |
| | | write = siemensS7Net.Write("DB100." + offset, staProtocol.getWorkNo()); // 工作号 |
| | | if (write.IsSuccess) { |
| | | OperateResultExOne<byte[]> result = siemensS7Net.Read("DB100." + offset, (short) 2); |
| | | if (result.IsSuccess) { |
| | | if (staProtocol.getWorkNo().equals(siemensS7Net.getByteTransform().TransInt16(result.Content, (short) 0))) { |
| | | flag1 = true; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | if (!flag2) { |
| | | Thread.sleep(200); |
| | | write1 = siemensS7Net.Write("DB100." + (offset+4), staProtocol.getStaNo().shortValue()); // 目标站 |
| | | if (write1.IsSuccess) { |
| | | OperateResultExOne<byte[]> result2 = siemensS7Net.Read("DB100." + (offset+4), (short) 2); |
| | | if (result2.IsSuccess) { |
| | | if (staProtocol.getStaNo().equals(siemensS7Net.getByteTransform().TransInt16(result2.Content, (short) 0))) { |
| | | flag2 = true; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | if (flag1 && flag2) { |
| | | log.error("写入输送线命令成功。输送线plc编号={},站点数据={},写入次数={}", slave.getId(), JSON.toJSON(staProtocol), writeCount); |
| | | break; |
| | | } |
| | | else { |
| | | } else { |
| | | writeCount++; |
| | | log.error("写入输送线命令失败。输送线plc编号={},站点数据={},写入次数={}", slave.getId(), JSON.toJSON(staProtocol), writeCount); |
| | | } |
| | | // write = siemensS7Net.Write("DB100." + offset, staProtocol.getWorkNo()); // 工作号 |
| | | // Thread.sleep(200); |
| | | // write1 = siemensS7Net.Write("DB100." + (offset+4), staProtocol.getStaNo().shortValue()); // 目标站 |
| | | // 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); |
| | | |
| | | if (!write.IsSuccess) { |