| | |
| | | import HslCommunication.Profinet.Siemens.SiemensPLCS; |
| | | import HslCommunication.Profinet.Siemens.SiemensS7Net; |
| | | import com.alibaba.fastjson.JSON; |
| | | 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; |
| | | import com.zy.common.utils.News; |
| | | import com.zy.core.DevpThread; |
| | | import com.zy.core.cache.MessageQueue; |
| | | import com.zy.core.cache.OutputQueue; |
| | | import com.zy.core.cache.SlaveConnection; |
| | | import com.zy.core.enums.IoModeType; |
| | | import com.zy.core.enums.SlaveType; |
| | | import com.zy.core.model.DevpSlave; |
| | | import com.zy.core.model.Task; |
| | |
| | | private SiemensS7Net siemensS7Net; |
| | | private Map<Integer, StaProtocol> station = new ConcurrentHashMap<>(); |
| | | private short heartBeatVal = 1; |
| | | private int barcodeSize = 2; |
| | | 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 boolean charge1; |
| | | public boolean charge2; |
| | | |
| | | public SiemensDevpThread(DevpSlave slave) { |
| | | this.slave = slave; |
| | | } |
| | | |
| | | /** |
| | | * 入出库模式 |
| | | * 0:未知 |
| | | * 1:入库启动中 |
| | | * 2.入库模式 |
| | | * 3.出库启动中 (不能生成入库工作档) |
| | | * 4.出库模式 |
| | | */ |
| | | public IoModeType ioModeOf1F = IoModeType.NONE; |
| | | public IoModeType ioModeOf2F = IoModeType.NONE; |
| | | |
| | | 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") |
| | |
| | | break; |
| | | // 写数据 ID+目标站 |
| | | case 2: |
| | | // write((StaProtocol)task.getData(), 0); |
| | | write((StaProtocol)task.getData()); |
| | | Thread.sleep(300); |
| | | read(); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | |
| | | // 心跳 |
| | | heartbeat(); |
| | | // heartbeat(); |
| | | Thread.sleep(400); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | |
| | | if(connect.IsSuccess){ |
| | | result = true; |
| | | 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())); |
| | | log.info("输送线plc连接成功 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); |
| | | News.info("输送线plc连接成功 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); |
| | | } else { |
| | | 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())); |
| | | log.error("输送线plc连接失败!!! ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); |
| | | News.error("输送线plc连接失败!!! ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); |
| | | } |
| | | siemensS7Net.ConnectClose(); |
| | | // siemensS7Net.ConnectClose(); |
| | | return result; |
| | | } |
| | | |
| | |
| | | * 读取状态 ====> 整块plc |
| | | */ |
| | | private void read() throws InterruptedException { |
| | | OperateResultExOne<byte[]> result = siemensS7Net.Read("DB100.0", (short) 40); |
| | | // 更新入出库模式 |
| | | updateIoMode(); |
| | | ArrayList<Integer> staNos = getStaNo(); |
| | | OperateResultExOne<byte[]> result = siemensS7Net.Read("DB100.0", (short) 50); |
| | | if (result.IsSuccess) { |
| | | for (int i = 1; i <= 8; i++) { |
| | | StaProtocol staProtocol = station.get(i); |
| | | for (int i = 0; i < 25; i++) { |
| | | Integer siteId = staNos.get(i); // 站点编号 |
| | | StaProtocol staProtocol = station.get(siteId); |
| | | if (null == staProtocol) { |
| | | staProtocol = new StaProtocol(); |
| | | staProtocol.setSiteId(i); |
| | | station.put(i, staProtocol); |
| | | staProtocol.setSiteId(siteId); |
| | | station.put(siteId, staProtocol); |
| | | } |
| | | staProtocol.setWorkNo(siemensS7Net.getByteTransform().TransInt16(result.Content, (i-1)*2)); // 工作号 |
| | | staProtocol.setStaNo(siemensS7Net.getByteTransform().TransInt16(result.Content, (i-1)*2+20)); // 目标站 |
| | | staProtocol.setWorkNo(siemensS7Net.getByteTransform().TransInt16(result.Content, i*2)); // 工作号 |
| | | } |
| | | } |
| | | Thread.sleep(100); |
| | | OperateResultExOne<byte[]> result1 = siemensS7Net.Read("DB100.40", (short) 8); |
| | | Thread.sleep(200); |
| | | OperateResultExOne<byte[]> result0 = siemensS7Net.Read("DB101.0", (short) 50); |
| | | if (result0.IsSuccess) { |
| | | for (int i = 0; i < 25; 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 = siemensS7Net.Read("DB102.0", (short) 50); |
| | | if (result1.IsSuccess) { |
| | | for (int i = 1; i <= 8; i++) { |
| | | boolean[] status = siemensS7Net.getByteTransform().TransBool(result1.Content, i-1, 1); |
| | | StaProtocol staProtocol = station.get(i); |
| | | for (int i = 0; i < 25; 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); |
| | | }else if (staProtocol.getSiteId().equals(300)){ |
| | | BasDevpMapper basDevpMapper = SpringUtils.getBean(BasDevpMapper.class); |
| | | BasDevp basDevp = basDevpMapper.selectByDevNo(300); |
| | | if (!basDevp.getWrkNo().equals(basDevp.getWrkNo1())){ |
| | | staProtocol.setPakMk(true); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (result.IsSuccess && result1.IsSuccess) { |
| | | //读条码 |
| | | 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(!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) { |
| | | |
| | | OutputQueue.DEVP.offer(MessageFormat.format("【{0}】[id:{1}] <<<<< 实时数据更新成功",DateUtils.convert(new Date()), slave.getId())); |
| | | |
| | | // 根据实时信息更新数据库 |
| | | try { |
| | | List<BasDevp> basDevps = new ArrayList<>(); |
| | | for (int i = 1; i <= 8; i++) { |
| | | StaProtocol staProtocol = station.get(i); |
| | | for (Integer siteId : staNos) { |
| | | StaProtocol staProtocol = station.get(siteId); |
| | | basDevps.add(staProtocol.toSqlModel()); |
| | | } |
| | | BasDevpService basDevpService = SpringUtils.getBean(BasDevpService.class); |
| | |
| | | } |
| | | } catch (Exception e) { |
| | | OutputQueue.DEVP.offer(MessageFormat.format("【{0}】更新数据库数据失败 ===>> [id:{1}] [ip:{2}] [port:{3}] [rack:{4}] [slot:{5}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot())); |
| | | log.error("更新数据库数据失败 ===>> [id:{}] [ip:{}] [port:{}] [rack:{}] [slot:{}]", slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot()); |
| | | News.error("更新数据库数据失败 ===>> [id:{}] [ip:{}] [port:{}] [rack:{}] [slot:{}]", slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot()); |
| | | } |
| | | |
| | | } else { |
| | | 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())); |
| | | log.error("读取堆垛机plc状态信息失败 ===>> [id:{}] [ip:{}] [port:{}] [rack:{}] [slot:{}]", slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot()); |
| | | // News.error("读取输送线plc状态信息失败 ===>> [id:{}] [ip:{}] [port:{}] [rack:{}] [slot:{}]", slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot()); |
| | | } |
| | | } |
| | | |
| | |
| | | if (null == staProtocol) { |
| | | return; |
| | | } |
| | | OperateResult write = siemensS7Net.Write("DB100." + (staProtocol.getSiteId() - 1) * 2, staProtocol.getWorkNo()); // 工作号 |
| | | Thread.sleep(300); |
| | | OperateResult write1 = siemensS7Net.Write("DB100." + ((staProtocol.getSiteId() - 1) * 2 + 20), staProtocol.getStaNo()); // 目标站 |
| | | // boolean[] status = new boolean[8]; |
| | | // status[0] = staProtocol.isAutoing(); |
| | | // status[1] = staProtocol.isLoading(); |
| | | // status[2] = staProtocol.isInEnable(); |
| | | // status[3] = staProtocol.isOutEnable(); |
| | | // status[4] = staProtocol.isEmptyMk(); |
| | | // OperateResult write2 = siemensS7Net.Write("DB100." + ((staProtocol.getSiteId() - 1) + 40), status); // 状态 |
| | | if (!write.IsSuccess || !write1.IsSuccess) { |
| | | ArrayList<Integer> staNos = getStaNo(); |
| | | int index = staNos.indexOf(staProtocol.getSiteId()); |
| | | |
| | | OperateResult writeId,writeDest; |
| | | // //任务ID下发次数 |
| | | int idCount = 0; |
| | | boolean idFlag = false; |
| | | while(idCount < 5){ |
| | | writeId = siemensS7Net.Write("DB100." + index*2, staProtocol.getWorkNo()); // 工作号 |
| | | if(writeId.IsSuccess){ |
| | | Thread.sleep(200); |
| | | OperateResultExOne<byte[]> readId = siemensS7Net.Read("DB100." + index*2, (short)2); |
| | | if(readId.IsSuccess){ |
| | | short workNo = siemensS7Net.getByteTransform().TransInt16(readId.Content, 0); |
| | | if(staProtocol.getWorkNo().equals(workNo)){ |
| | | //工作号写入成功 |
| | | idFlag = true; |
| | | break; |
| | | } else {//返回结果是成功了,但是真实值不相同 |
| | | idCount++; |
| | | OutputQueue.DEVP.offer(MessageFormat.format("【{0}】写入输送线工作号后返回成功,但是读取工作号值不一致。输送线plc编号={1},站点数据={2},写入次数={3}", |
| | | slave.getId(), JSON.toJSON(staProtocol),idCount)); |
| | | log.error("写入输送线工作号后返回成功,但是读取工作号值不一致。输送线plc编号={},{},写入次数={}", slave.getId(), JSON.toJSON(staProtocol), idCount); |
| | | } |
| | | } else { |
| | | idCount++; |
| | | OutputQueue.DEVP.offer(MessageFormat.format("【{0}】写入输送线工作号后读取工作号失败。输送线plc编号={1},站点数据={2},写入次数={3}", |
| | | slave.getId(), JSON.toJSON(staProtocol), idCount)); |
| | | log.error("写入输送线工作号后读取工作号失败{}。输送线plc编号={},站点数据={},写入次数={}", readId.Message, slave.getId(), JSON.toJSON(staProtocol), idCount); |
| | | } |
| | | } else { |
| | | idCount++; |
| | | OutputQueue.DEVP.offer(MessageFormat.format("【{0}】写入输送线工作号失败。输送线plc编号={1},站点数据={2},写入次数={3}", |
| | | slave.getId(), JSON.toJSON(staProtocol),idCount)); |
| | | log.error("写入输送线工作号失败{}。输送线plc编号={},站点数据={},写入次数={}", writeId.Message, slave.getId(), JSON.toJSON(staProtocol), idCount); |
| | | } |
| | | Thread.sleep(200); |
| | | } |
| | | |
| | | //写ID尝试了5次还是失败了 |
| | | if(!idFlag){ |
| | | staProtocol = station.get(staProtocol.getSiteId()); |
| | | if (staProtocol.getWorkNo() == 0 && staProtocol.getStaNo() ==0) { |
| | | staProtocol.setPakMk(true); |
| | | } |
| | | OutputQueue.DEVP.offer(MessageFormat.format("【{0}】写入输送线工作号尝试5次失败。输送线plc编号={1},站点数据={2}", slave.getId(), JSON.toJSON(staProtocol))); |
| | | log.error("写入输送线工作号尝试5次失败。输送线plc编号={},站点数据={}", slave.getId(), JSON.toJSON(staProtocol)); |
| | | |
| | | //重新添加数据到任务队列 |
| | | boolean result = MessageQueue.offer(SlaveType.Devp, slave.getId(), new Task(2, staProtocol)); |
| | | // read();//读取1次设备状态 |
| | | return; |
| | | } |
| | | |
| | | //任务目标站下发次数 |
| | | int destCount = 0; |
| | | boolean destFlag = false; |
| | | while(destCount < 5){ |
| | | writeDest = siemensS7Net.Write("DB101." + index*2, staProtocol.getStaNo()); // 目标站 |
| | | if(writeDest.IsSuccess){ |
| | | Thread.sleep(200); |
| | | OperateResultExOne<byte[]> readDest = siemensS7Net.Read("DB101." + index*2, (short)2); |
| | | if(readDest.IsSuccess){ |
| | | short staNo = siemensS7Net.getByteTransform().TransInt16(readDest.Content, 0); |
| | | if(staProtocol.getStaNo().equals(staNo)){ |
| | | //目标站写入成功 |
| | | destFlag = true; |
| | | break; |
| | | } else {//返回结果是成功了,但是真实值不相同 |
| | | destCount++; |
| | | OutputQueue.DEVP.offer(MessageFormat.format("【{0}】写入输送线目标站后返回成功,但是读取目标站值不一致。输送线plc编号={1},站点数据={2},写入次数={3}", |
| | | slave.getId(), JSON.toJSON(staProtocol),destCount)); |
| | | log.error("写入输送线目标站后返回成功,但是读取目标站值不一致。输送线plc编号={},{},写入次数={}", slave.getId(), JSON.toJSON(staProtocol), destCount); |
| | | } |
| | | } else { |
| | | destCount++; |
| | | OutputQueue.DEVP.offer(MessageFormat.format("【{0}】写入输送线目标站后读取目标站失败。输送线plc编号={1},站点数据={2},写入次数={3}", |
| | | slave.getId(), JSON.toJSON(staProtocol), destCount)); |
| | | log.error("写入输送线目标站后读取目标站失败{}。输送线plc编号={},站点数据={},写入次数={}", readDest.Message, slave.getId(), JSON.toJSON(staProtocol), destCount); |
| | | } |
| | | } else { |
| | | destCount++; |
| | | OutputQueue.DEVP.offer(MessageFormat.format("【{0}】写入输送线目标站失败。输送线plc编号={1},站点数据={2},写入次数={3}", |
| | | slave.getId(), JSON.toJSON(staProtocol),destCount)); |
| | | log.error("写入输送线目标站失败{}。输送线plc编号={},站点数据={},写入次数={}", writeDest.Message, slave.getId(), JSON.toJSON(staProtocol), destCount); |
| | | } |
| | | Thread.sleep(200); |
| | | } |
| | | |
| | | //写目标站尝试了5次还是失败了 |
| | | if(!destFlag){ |
| | | staProtocol = station.get(staProtocol.getSiteId()); |
| | | if (staProtocol.getWorkNo() == 0 && staProtocol.getStaNo() ==0) { |
| | | staProtocol.setPakMk(true); |
| | | } |
| | | OutputQueue.DEVP.offer(MessageFormat.format("【{0}】写入输送线目标站尝试5次失败。输送线plc编号={1},站点数据={2}", slave.getId(), JSON.toJSON(staProtocol))); |
| | | log.error("写入输送线目标站尝试5次失败。输送线plc编号={},站点数据={}", slave.getId(), JSON.toJSON(staProtocol)); |
| | | |
| | | //重新添加数据到任务队列 |
| | | boolean result = MessageQueue.offer(SlaveType.Devp, slave.getId(), new Task(2, staProtocol)); |
| | | // read();//读取1次设备状态 |
| | | return; |
| | | } |
| | | |
| | | OutputQueue.DEVP.offer(MessageFormat.format("【{0}】 输送线命令下发成功 [id:{1}] >>>>> {2}", DateUtils.convert(new Date()), slave.getId(), JSON.toJSON(staProtocol))); |
| | | log.info("输送线命令下发 [id:{}] >>>>> 命令下发成功: {}", slave.getId(), JSON.toJSON(staProtocol)); |
| | | } |
| | | |
| | | /** |
| | | * 写入 ID+目标站 =====> 单站点写入 |
| | | */ |
| | | private void write(StaProtocol staProtocol, int times) throws InterruptedException { |
| | | 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); |
| | | OperateResult write1 = siemensS7Net.Write("DB101." + index*2, staProtocol.getStaNo()); // 目标站 |
| | | |
| | | if (!write.IsSuccess || !write1.IsSuccess) { |
| | | // MessageQueue.offer(SlaveType.Devp, slave.getId(), new Task(2, staProtocol)); |
| | | OutputQueue.DEVP.offer(MessageFormat.format("【{0}】写入输送线站点数据失败。输送线plc编号={1},站点数据={2}", slave.getId(), JSON.toJSON(staProtocol))); |
| | | log.error("写入输送线站点数据失败。输送线plc编号={},站点数据={}", slave.getId(), JSON.toJSON(staProtocol)); |
| | | News.error("写入输送线站点数据失败==>>{}--{},重新添加任务到队列。输送线plc编号={},站点数据={}", write.Message, write1.Message, slave.getId(), JSON.toJSON(staProtocol)); |
| | | times++; |
| | | write(staProtocol, times); |
| | | // staProtocol = station.get(staProtocol.getSiteId()); |
| | | // if (staProtocol.getWorkNo() == 0 && staProtocol.getStaNo() ==0) { |
| | | // staProtocol.setPakMk(true); |
| | | // } |
| | | } else { |
| | | OutputQueue.DEVP.offer(MessageFormat.format("【{0}】 输送线命令下发 [id:{1}] >>>>> {2}", DateUtils.convert(new Date()), slave.getId(), JSON.toJSON(staProtocol))); |
| | | log.info("输送线命令下发 [id:{}] >>>>> 命令下发: {}", slave.getId(), JSON.toJSON(staProtocol)); |
| | | News.info("输送线命令下发 [id:{}] >>>>> 命令下发: {}", slave.getId(), JSON.toJSON(staProtocol)); |
| | | } |
| | | } |
| | | |
| | | // 更新入出库模式 |
| | | 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 (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()); |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | OperateResult write = siemensS7Net.Write("DB100.50", heartBeatVal); |
| | | if (!write.IsSuccess) { |
| | | log.error("输送线plc编号={} 心跳失败", slave.getId()); |
| | | News.error("输送线plc编号={} 心跳失败", slave.getId()); |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 充电控制 |
| | | * @param index 充电桩序号 0 开始 |
| | | * @param open true 开始充电;false 结束充电 |
| | | */ |
| | | public boolean charge(int index, boolean open) { |
| | | OperateResult write = siemensS7Net.Write("DB102.50." + (index + 3), open); |
| | | if (!write.IsSuccess) { |
| | | News.error("输送线plc编号={} {}号充电桩{}控制失败", slave.getId(), index + 1, open?"打开":"关闭"); |
| | | return false; |
| | | } else { |
| | | News.error("输送线plc编号={} {}号充电桩{}控制成功", slave.getId(), index + 1, open?"打开":"关闭"); |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | @Override |
| | | public void close() { |
| | | siemensS7Net.ConnectClose(); |
| | |
| | | |
| | | public static void main(String[] args) throws Exception { |
| | | DevpSlave slave = new DevpSlave(); |
| | | slave.setIp("192.168.2.125"); |
| | | slave.setIp("10.10.10.61"); |
| | | slave.setPort(102); |
| | | slave.setRack(0); |
| | | slave.setSlot(0); |
| | | SiemensDevpThread devpThread = new SiemensDevpThread(slave); |
| | | devpThread.connect(); |
| | | 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)); |
| | | // 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)); |
| | | |
| | | } |
| | | |