| | |
| | | import com.core.common.Cools; |
| | | import com.core.common.DateUtils; |
| | | import com.core.common.SpringUtils; |
| | | import com.core.exception.CoolException; |
| | | import com.zy.asrs.entity.BasDevp; |
| | | import com.zy.asrs.mapper.BasDevpMapper; |
| | | import com.zy.asrs.service.BasDevpService; |
| | |
| | | private Map<Integer, StaProtocol> station = new ConcurrentHashMap<>(); |
| | | private short heartBeatVal = 1; |
| | | private int barcodeSize = 2; |
| | | public static final ArrayList<Integer> staNos = new ArrayList<Integer>() {{ |
| | | 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(108);add(109); |
| | | add(110);add(111); |
| | | add(200);add(201);add(202);add(203);add(204);add(205);add(206);add(207);add(208);add(209); |
| | | add(210);add(211); |
| | | add(300); |
| | | }}; |
| | | public static final ArrayList<Integer> staNos2 = new ArrayList<Integer>() {{ |
| | | add(112);add(113);add(114); |
| | | }}; |
| | | public static final ArrayList<Integer> staNos3 = new ArrayList<Integer>() {{ |
| | | add(212);add(213);add(214); |
| | | }}; |
| | | |
| | | public boolean charge0; |
| | |
| | | */ |
| | | public IoModeType ioModeOf1F = IoModeType.NONE; |
| | | public IoModeType ioModeOf2F = IoModeType.NONE; |
| | | public IoModeType ioModeOf3F = IoModeType.NONE; |
| | | public short ioModeOf3FX = 0; |
| | | public short ioModeOf3FD = 0; |
| | | public IoModeType ioModeOf4F = IoModeType.NONE; |
| | | public short ioModeOf4FX = 0; |
| | | public short ioModeOf4FD = 0; |
| | | |
| | | private ArrayList<Integer> getStaNo() { |
| | | switch (slave.getId()) { |
| | | case 1: |
| | | return staNos1; |
| | | case 2: |
| | | return staNos2; |
| | | case 3: |
| | | return staNos3; |
| | | default: |
| | | throw new CoolException("服务器异常"); |
| | | } |
| | | } |
| | | |
| | | |
| | | @Override |
| | | @SuppressWarnings("InfiniteLoopStatement") |
| | |
| | | private void read() throws InterruptedException { |
| | | // 更新入出库模式 |
| | | updateIoMode(); |
| | | OperateResultExOne<byte[]> result = siemensS7Net.Read("DB100.0", (short) 50); |
| | | ArrayList<Integer> staNos = getStaNo(); |
| | | OperateResultExOne<byte[]> result = siemensS7Net.Read("DB100.0", (short) (staNos.size()*2)); |
| | | if (result.IsSuccess) { |
| | | for (int i = 0; i < 25; i++) { |
| | | for (int i = 0; i < staNos.size(); i++) { |
| | | Integer siteId = staNos.get(i); // 站点编号 |
| | | StaProtocol staProtocol = station.get(siteId); |
| | | if (null == staProtocol) { |
| | |
| | | } |
| | | } |
| | | Thread.sleep(200); |
| | | OperateResultExOne<byte[]> result0 = siemensS7Net.Read("DB101.0", (short) 50); |
| | | OperateResultExOne<byte[]> result0 = siemensS7Net.Read("DB101.0", (short) (staNos.size()*2)); |
| | | if (result0.IsSuccess) { |
| | | for (int i = 0; i < 25; i++) { |
| | | for (int i = 0; i < staNos.size(); i++) { |
| | | Integer siteId = staNos.get(i); // 站点编号 |
| | | StaProtocol staProtocol = station.get(siteId); |
| | | if (null == staProtocol) { |
| | |
| | | staProtocol.setStaNo(siemensS7Net.getByteTransform().TransInt16(result0.Content, i*2)); // 目标站 |
| | | } |
| | | } |
| | | if (slave.getId()!=1){ |
| | | Thread.sleep(200); |
| | | OperateResultExOne<byte[]> result2F = siemensS7Net.Read("DB102.50", (short) (4)); |
| | | if (result2F.IsSuccess) { |
| | | if (slave.getId()==2){ |
| | | this.ioModeOf3FX = siemensS7Net.getByteTransform().TransInt16(result2F.Content, 0); |
| | | this.ioModeOf3FD = siemensS7Net.getByteTransform().TransInt16(result2F.Content, 2); |
| | | } if (slave.getId()==3){ |
| | | this.ioModeOf4FX = siemensS7Net.getByteTransform().TransInt16(result2F.Content, 0); |
| | | this.ioModeOf4FD = siemensS7Net.getByteTransform().TransInt16(result2F.Content, 2); |
| | | } |
| | | } |
| | | } |
| | | Thread.sleep(200); |
| | | OperateResultExOne<byte[]> result1 = siemensS7Net.Read("DB102.0", (short) 50); |
| | | OperateResultExOne<byte[]> result1 = siemensS7Net.Read("DB102.0", (short) (staNos.size()*2)); |
| | | if (result1.IsSuccess) { |
| | | for (int i = 0; i < 25; i++) { |
| | | for (int i = 0; i < staNos.size(); i++) { |
| | | Integer siteId = staNos.get(i); // 站点编号 |
| | | boolean[] status = siemensS7Net.getByteTransform().TransBool(result1.Content, i*2, 1); |
| | | boolean[] status = siemensS7Net.getByteTransform().TransBool(result1.Content, i * 2, 1); |
| | | StaProtocol staProtocol = station.get(siteId); |
| | | staProtocol.setAutoing(status[0]); // 自动 |
| | | staProtocol.setLoading(status[1]); // 有物 |
| | |
| | | |
| | | if (!staProtocol.isPakMk() && !staProtocol.isLoading()) { |
| | | staProtocol.setPakMk(true); |
| | | }else if (staProtocol.getSiteId().equals(300)){ |
| | | } else if (staProtocol.getSiteId().equals(300)) { |
| | | BasDevpMapper basDevpMapper = SpringUtils.getBean(BasDevpMapper.class); |
| | | BasDevp basDevp = basDevpMapper.selectByDevNo(300); |
| | | if (!basDevp.getWrkNo().equals(basDevp.getWrkNo1())){ |
| | | if (!basDevp.getWrkNo().equals(basDevp.getWrkNo1())) { |
| | | staProtocol.setPakMk(true); |
| | | } |
| | | } |
| | |
| | | |
| | | //读条码 |
| | | Thread.sleep(200); |
| | | OperateResultExOne<byte[]> result2 = siemensS7Net.Read("DB100.100",(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"); |
| | | BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, i + 1); |
| | | if (slave.getId()==1){ |
| | | OperateResultExOne<byte[]> result2 = siemensS7Net.Read("DB100.100",(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"); |
| | | BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, i + 1); |
| | | if(!Cools.isEmpty(barcodeThread) && !barcodeThread.getBarcode().equals(barcode)) { |
| | | barcodeThread.setBarcode(barcode); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | // 充电信号位 |
| | | Thread.sleep(200); |
| | | OperateResultExOne<byte[]> result3 = siemensS7Net.Read("DB102.50", (short)1); |
| | | if (result3.IsSuccess) { |
| | | boolean[] status = siemensS7Net.getByteTransform().TransBool(result3.Content, 0, 1); |
| | | charge0 = status[0]; |
| | | charge1 = status[1]; |
| | | charge2 = status[2]; |
| | | } |
| | | } else { |
| | | OperateResultExOne<byte[]> result2 = siemensS7Net.Read("DB100.100",(short)(8)); |
| | | if (result2.IsSuccess) { |
| | | String barcode = siemensS7Net.getByteTransform().TransString(result2.Content,0,8, "UTF-8"); |
| | | BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, slave.getId()+1); |
| | | if(!Cools.isEmpty(barcodeThread) && !barcodeThread.getBarcode().equals(barcode)) { |
| | | barcodeThread.setBarcode(barcode); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | // 充电信号位 |
| | | Thread.sleep(200); |
| | | OperateResultExOne<byte[]> result3 = siemensS7Net.Read("DB102.50", (short)1); |
| | | if (result3.IsSuccess) { |
| | | boolean[] status = siemensS7Net.getByteTransform().TransBool(result3.Content, 0, 1); |
| | | charge0 = status[0]; |
| | | charge1 = status[1]; |
| | | charge2 = status[2]; |
| | | } |
| | | |
| | | if (result.IsSuccess && result0.IsSuccess && result1.IsSuccess) { |
| | |
| | | if (null == staProtocol) { |
| | | return; |
| | | } |
| | | ArrayList<Integer> staNos = getStaNo(); |
| | | int index = staNos.indexOf(staProtocol.getSiteId()); |
| | | |
| | | OperateResult writeId,writeDest; |
| | |
| | | if (null == staProtocol || times > 3) { |
| | | return; |
| | | } |
| | | ArrayList<Integer> staNos = getStaNo(); |
| | | int index = staNos.indexOf(staProtocol.getSiteId()); |
| | | OperateResult write = siemensS7Net.Write("DB100." + index*2, staProtocol.getWorkNo()); // 工作号 |
| | | Thread.sleep(200); |
| | |
| | | |
| | | // 更新入出库模式 |
| | | private void updateIoMode() throws InterruptedException { |
| | | if (this.ioModeOf1F != IoModeType.NONE) { |
| | | if (!siemensS7Net.Write("DB100.180", this.ioModeOf1F.id).IsSuccess) { |
| | | OutputQueue.DEVP.offer(MessageFormat.format("【{0}】写入输送线103入出库模式失败。输送线plc编号={1}", slave.getId())); |
| | | News.error("写入输送线103入出库模式失败。输送线plc编号={}", slave.getId()); |
| | | if (slave.getId()==1){ |
| | | if (this.ioModeOf1F != IoModeType.NONE) { |
| | | if (!siemensS7Net.Write("DB100.180", this.ioModeOf1F.id).IsSuccess) { |
| | | OutputQueue.DEVP.offer(MessageFormat.format("【{0}】写入输送线103入出库模式失败。输送线plc编号={1}", slave.getId())); |
| | | // News.error("写入输送线103入出库模式失败。输送线plc编号={}", slave.getId()); |
| | | } |
| | | } |
| | | } |
| | | if (this.ioModeOf2F != IoModeType.NONE) { |
| | | if (!siemensS7Net.Write("DB100.182", this.ioModeOf2F.id).IsSuccess) { |
| | | OutputQueue.DEVP.offer(MessageFormat.format("【{0}】写入输送线203入出库模式失败。输送线plc编号={1}", slave.getId())); |
| | | News.error("写入输送线203入出库模式失败。输送线plc编号={}", slave.getId()); |
| | | if (this.ioModeOf2F != IoModeType.NONE) { |
| | | if (!siemensS7Net.Write("DB100.182", this.ioModeOf2F.id).IsSuccess) { |
| | | OutputQueue.DEVP.offer(MessageFormat.format("【{0}】写入输送线203入出库模式失败。输送线plc编号={1}", slave.getId())); |
| | | // News.error("写入输送线203入出库模式失败。输送线plc编号={}", slave.getId()); |
| | | } |
| | | } |
| | | } else if (slave.getId()==2){ |
| | | if (this.ioModeOf3F != IoModeType.NONE && this.ioModeOf3F.id/2 != this.ioModeOf3FX) { |
| | | if (!siemensS7Net.Write("DB102.50", (short) (this.ioModeOf3F.id/2)).IsSuccess) { |
| | | OutputQueue.DEVP.offer(MessageFormat.format("【{0}】写入输送线113入出库模式失败。输送线plc编号={1}", slave.getId())); |
| | | // News.error("写入输送线113入出库模式失败。输送线plc编号={}", slave.getId()); |
| | | } |
| | | } |
| | | } else if (slave.getId()==3){ |
| | | if (this.ioModeOf4F != IoModeType.NONE && this.ioModeOf4F.id/2 != this.ioModeOf4FX) { |
| | | if (!siemensS7Net.Write("DB102.50", (short) (this.ioModeOf4F.id/2)).IsSuccess) { |
| | | OutputQueue.DEVP.offer(MessageFormat.format("【{0}】写入输送线213入出库模式失败。输送线plc编号={1}", slave.getId())); |
| | | // News.error("写入输送线213入出库模式失败。输送线plc编号={}", slave.getId()); |
| | | } |
| | | } |
| | | } |
| | | } |