| | |
| | | private short heartBeatVal = 1; |
| | | |
| | | public static final ArrayList<Integer> staNos1 = new ArrayList<Integer>() {{ |
| | | add(100);add(101);add(102);add(103);add(104); |
| | | add(105);add(106);add(107); |
| | | add(100);add(101);add(102);add(103); |
| | | }}; |
| | | |
| | | public static final ArrayList<Integer> staNos2 = new ArrayList<Integer>() {{ |
| | | // add(401);add(402); |
| | | }}; |
| | | |
| | | private Integer count=0; |
| | | |
| | | /** |
| | | * 条码数量 |
| | | */ |
| | | private int barcodeSize = 4; |
| | | private int barcodeSize = 1; |
| | | |
| | | /** |
| | | * 入出库模式 |
| | |
| | | switch (slave.getId()) { |
| | | case 1: |
| | | return staNos1; |
| | | case 2: |
| | | return staNos2; |
| | | default: |
| | | throw new CoolException("服务器异常"); |
| | | } |
| | |
| | | updateIoMode(); |
| | | ArrayList<Integer> staNos = getStaNo(); |
| | | int staNoSize = staNos.size(); |
| | | OperateResultExOne<byte[]> result = siemensS7Net.Read("DB100.0", (short) (staNoSize*4)); |
| | | OperateResultExOne<byte[]> result = siemensS7Net.Read("DB101.0", (short) (staNoSize*8)); |
| | | 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().TransInt16(result.Content, i*4)); // 工作号 |
| | | staProtocol.setWorkNo((short)siemensS7Net.getByteTransform().TransInt32(result.Content, i*8)); // 工作号 |
| | | |
| | | staProtocol.setStaNo(siemensS7Net.getByteTransform().TransInt16(result.Content, i*4 + 2)); // 目标站 |
| | | } |
| | | } |
| | | Thread.sleep(200); |
| | | // OperateResultExOne<byte[]> result0 = siemensS7Net.Read("DB100.2", (short) (staNoSize*2)); |
| | | // if (result0.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.setStaNo(siemensS7Net.getByteTransform().TransInt16(result0.Content, i*2)); // 目标站 |
| | | // } |
| | | // } |
| | | // Thread.sleep(200); |
| | | OperateResultExOne<byte[]> result1 = null; |
| | | if(slave.getId()==1) { |
| | | result1 = siemensS7Net.Read("DB102.0", (short) (staNoSize*2)); |
| | | if (result1.IsSuccess) { |
| | | for (int i = 0; i < staNoSize; i++) { |
| | | Integer siteId = staNos.get(i); // 站点编号 |
| | | boolean[] status = siemensS7Net.getByteTransform().TransBool(result1.Content, i*2, 1); |
| | | StaProtocol staProtocol = station.get(siteId); |
| | | staProtocol.setAutoing(status[0]); // 自动 |
| | | staProtocol.setLoading(status[1]); // 有物 |
| | | staProtocol.setInEnable(status[2]); // 可入 |
| | | staProtocol.setOutEnable(status[3]);// 可出 |
| | | staProtocol.setEmptyMk(status[4]); // 空板信号 |
| | | staProtocol.setFullPlt(status[5]); // 满托盘 |
| | | staProtocol.setHigh(status[6]); // 高库位 |
| | | staProtocol.setLow(status[7]); // 低库位 |
| | | staProtocol.setStaNo(siemensS7Net.getByteTransform().TransInt16(result.Content, i*8 + 4)); // 目标站 |
| | | |
| | | if (!staProtocol.isPakMk() && !staProtocol.isLoading()) { |
| | | staProtocol.setPakMk(true); |
| | | } |
| | | count = 0; |
| | | boolean[] status = siemensS7Net.getByteTransform().TransBool(result.Content, i*8 + 6, 2); |
| | | staProtocol.setAutoing(status[0]); // 自动 |
| | | staProtocol.setLoading(status[1]); // 有物 |
| | | staProtocol.setInEnable(status[2]); // 可入 |
| | | staProtocol.setOutEnable(status[3]);// 可出 |
| | | staProtocol.setEmptyMk(status[4]); // 空板信号 |
| | | staProtocol.setFullPlt(status[5]); // 满托盘 |
| | | staProtocol.setHigh(status[6]); // 高库位 |
| | | staProtocol.setLow(status[7]); // 低库位 |
| | | |
| | | if (!staProtocol.isPakMk() && !staProtocol.isLoading()) { |
| | | staProtocol.setPakMk(true); |
| | | } |
| | | } |
| | | } else if(slave.getId()==2) { |
| | | // result1 = siemensS7Net.Read("DB100.100", (short) (staNoSize * 2)); |
| | | // if (result1.IsSuccess) { |
| | | // for (int i = 0; i < staNoSize; i++) { |
| | | // Integer siteId = staNos.get(i); // 站点编号 |
| | | // boolean[] status = siemensS7Net.getByteTransform().TransBool(result1.Content, i * 2, 1); |
| | | // StaProtocol staProtocol = station.get(siteId); |
| | | // staProtocol.setAutoing(status[0]); // 自动 |
| | | // staProtocol.setLoading(status[1]); // 有物 |
| | | // staProtocol.setInEnable(status[2]); // 可入 |
| | | // staProtocol.setOutEnable(status[3]);// 可出 |
| | | // staProtocol.setEmptyMk(status[4]); // 空板信号 |
| | | // staProtocol.setFullPlt(status[5]); // 满托盘 |
| | | // staProtocol.setHigh(status[6]); // 高库位 |
| | | // staProtocol.setLow(status[7]); // 低库位 |
| | | // |
| | | // if (!staProtocol.isPakMk() && !staProtocol.isLoading()) { |
| | | // staProtocol.setPakMk(true); |
| | | // } |
| | | // } |
| | | // count = 0; |
| | | // } |
| | | } |
| | | |
| | | //外形检测 |
| | | OperateResultExOne<byte[]> resultErr1 = siemensS7Net.Read("DB101.702.0", (short) (barcodeSize*1)); |
| | | StaProtocol staProtocol1 = station.get(101); |
| | | boolean[] status1 = siemensS7Net.getByteTransform().TransBool(resultErr1.Content, 0, 1); |
| | | staProtocol1.setFrontErr(status1[0]); |
| | | staProtocol1.setBackErr(status1[1]); |
| | | staProtocol1.setHighErr(status1[2]); |
| | | staProtocol1.setLeftErr(status1[3]); |
| | | staProtocol1.setRightErr(status1[4]); |
| | | staProtocol1.setWeightErr(status1[5]); |
| | | staProtocol1.setBarcodeErr(status1[6]); |
| | | |
| | | Thread.sleep(200); |
| | | if(slave.getId()==1) { |
| | | OperateResultExOne<byte[]> result2 = siemensS7Net.Read("DB102.40", (short) (barcodeSize * 8)); |
| | | OperateResultExOne<byte[]> result2 = siemensS7Net.Read("DB101.602.0", (short) (barcodeSize * 8)); |
| | | if (result2.IsSuccess) { |
| | | for (int i = 0; i < barcodeSize; i++) { |
| | | String barcode = siemensS7Net.getByteTransform().TransString(result2.Content, i * 8, 8, "UTF-8"); |
| | |
| | | } |
| | | } |
| | | |
| | | // OperateResultExOne<Short> result2 = siemensS7Net.ReadInt16("DB200.0"); |
| | | // if (result2.IsSuccess) { |
| | | // this.ioMode = IoModeType.get(result2.Content); |
| | | // } |
| | | |
| | | if (result.IsSuccess && !Cools.isEmpty(result1) && result1.IsSuccess) { |
| | | if (result.IsSuccess) { |
| | | |
| | | OutputQueue.DEVP.offer(MessageFormat.format("【{0}】[id:{1}] <<<<< 实时数据更新成功",DateUtils.convert(new Date()), slave.getId())); |
| | | |
| | |
| | | ArrayList<Integer> staNos = getStaNo(); |
| | | int index = staNos.indexOf(staProtocol.getSiteId()); |
| | | short[] array = new short[2]; |
| | | array[0] = staProtocol.getWorkNo(); |
| | | array[1] = staProtocol.getStaNo(); |
| | | OperateResult write = siemensS7Net.Write("DB100." + index*4, array); |
| | | OperateResult writeResult1 = siemensS7Net.Write("DB100." + index*6, staProtocol.getWorkNo().intValue()); // 工作号 |
| | | OperateResult writeResult2 = siemensS7Net.Write("DB100." + (index*6+4), staProtocol.getStaNo()); // 目标站 |
| | | |
| | | // OperateResult write = siemensS7Net.Write("DB100.0" + index*4, staProtocol.getWorkNo()); // 工作号 |
| | | // Thread.sleep(500); |
| | | // OperateResult write1 = siemensS7Net.Write("DB100.2" + index*4+2, staProtocol.getStaNo()); // 目标站 |
| | | |
| | | if (!write.IsSuccess) { |
| | | if (!writeResult1.IsSuccess&&!writeResult2.IsSuccess) { |
| | | staProtocol = station.get(staProtocol.getSiteId()); |
| | | if (staProtocol.getWorkNo() == 0 && staProtocol.getStaNo() ==0) { |
| | | staProtocol.setPakMk(true); |