|  |  | 
 |  |  |     /** | 
 |  |  |      * 读取状态 ====> 整块plc | 
 |  |  |      */ | 
 |  |  |     private void read(){ | 
 |  |  |     private void read() throws InterruptedException { | 
 |  |  |         OperateResultExOne<byte[]> result = siemensS7Net.Read("DB100.0", (short) 40); | 
 |  |  |         if (result.IsSuccess) { | 
 |  |  |             for (int i = 1; i <= 8; i++) { | 
 |  |  | 
 |  |  |                 staProtocol.setStaNo(siemensS7Net.getByteTransform().TransInt16(result.Content, (i-1)*2+20));   // 目标站 | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |         Thread.sleep(100); | 
 |  |  |         OperateResultExOne<byte[]> result1 = siemensS7Net.Read("DB100.40", (short) 8); | 
 |  |  |         if (result1.IsSuccess) { | 
 |  |  |             for (int i = 1; i <= 8; i++) { | 
 |  |  | 
 |  |  |                 staProtocol.setInEnable(status[2]); // 可入 | 
 |  |  |                 staProtocol.setOutEnable(status[3]);// 可出 | 
 |  |  |                 staProtocol.setEmptyMk(status[4]);  // 空板信号 | 
 |  |  |  | 
 |  |  |                 if (!staProtocol.isPakMk() && !staProtocol.isLoading()) { | 
 |  |  |                     staProtocol.setPakMk(true); | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |         // 台车位置 | 
 |  |  |         OperateResultExOne<Short> result2 = siemensS7Net.ReadInt16("DB100.48"); | 
 |  |  |         if (result2.IsSuccess) { | 
 |  |  |             StaProtocol staProtocol = station.get(8); | 
 |  |  |             staProtocol.setPosition(result2.Content); | 
 |  |  |         } else { | 
 |  |  |             OutputQueue.DEVP.offer(MessageFormat.format("【{0}】8号台车获取实时位置失败!!!", DateUtils.convert(new Date()))); | 
 |  |  |             log.error("8号台车获取实时位置失败!!!"); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         if (result.IsSuccess && result1.IsSuccess) { | 
 |  |  |  | 
 |  |  |             OutputQueue.DEVP.offer(MessageFormat.format("【{0}】[id:{1}] <<<<< 实时数据更新成功",DateUtils.convert(new Date()), slave.getId())); | 
 |  |  |  | 
 |  |  |             // 根据实时信息更新数据库 | 
 |  |  | 
 |  |  |     /** | 
 |  |  |      * 写入 ID+目标站 =====> 单站点写入 | 
 |  |  |      */ | 
 |  |  |     private void write(StaProtocol staProtocol){ | 
 |  |  |     private void write(StaProtocol staProtocol) throws InterruptedException { | 
 |  |  |         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[4] = staProtocol.isEmptyMk(); | 
 |  |  | //        OperateResult write2 = siemensS7Net.Write("DB100." + ((staProtocol.getSiteId() - 1) + 40), status);     //  状态 | 
 |  |  |         if (!write.IsSuccess || !write1.IsSuccess) { | 
 |  |  |             staProtocol = station.get(staProtocol.getSiteId()); | 
 |  |  |             if (staProtocol.getWorkNo() == 0 && staProtocol.getStaNo() ==0) { | 
 |  |  |                 staProtocol.setPakMk(true); | 
 |  |  |             } | 
 |  |  |             OutputQueue.DEVP.offer(MessageFormat.format("【{0}】写入输送线站点数据失败。输送线plc编号={1},站点数据={2}", slave.getId(), JSON.toJSON(staProtocol))); | 
 |  |  |             log.error("写入输送线站点数据失败。输送线plc编号={},站点数据={}", slave.getId(), JSON.toJSON(staProtocol)); | 
 |  |  |         } else { | 
 |  |  |             OutputQueue.DEVP.offer(MessageFormat.format("【{0}】[id:{1}] >>>>> 命令下发: {2}", DateUtils.convert(new Date()), slave.getId(), JSON.toJSON(staProtocol))); | 
 |  |  |             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)); | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 设置入库标记 | 
 |  |  |      */ | 
 |  |  |     public void setPakMk(Integer siteId, boolean pakMk) { | 
 |  |  |         StaProtocol staProtocol = station.get(siteId); | 
 |  |  |         if (null != staProtocol) { | 
 |  |  |             staProtocol.setPakMk(pakMk); | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     public void close() { | 
 |  |  |         siemensS7Net.ConnectClose(); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     public static void main(String[] args) { | 
 |  |  |     public static void main(String[] args) throws Exception { | 
 |  |  |         DevpSlave slave = new DevpSlave(); | 
 |  |  |         slave.setIp("192.168.2.125"); | 
 |  |  |         DevpThread devpThread = new DevpThread(slave); |