| | |
| | | } |
| | | |
| | | // 心跳 |
| | | heartbeat(); |
| | | // heartbeat(); |
| | | Thread.sleep(400); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | |
| | | * 读取状态 ====> 整块plc |
| | | */ |
| | | private void read(){ |
| | | OperateResultExOne<byte[]> result = melsecMcNet.Read("DB100.0", (short) 40); |
| | | OperateResultExOne<byte[]> result = melsecMcNet.Read("D101", (short) 30); |
| | | if (result.IsSuccess) { |
| | | for (int i = 1; i <= 8; i++) { |
| | | StaProtocol staProtocol = station.get(i); |
| | |
| | | station.put(i, staProtocol); |
| | | } |
| | | staProtocol.setWorkNo(melsecMcNet.getByteTransform().TransInt16(result.Content, (i-1)*2)); // 工作号 |
| | | staProtocol.setStaNo(melsecMcNet.getByteTransform().TransInt16(result.Content, (i-1)*2+20)); // 目标站 |
| | | staProtocol.setStaNo(melsecMcNet.getByteTransform().TransInt16(result.Content, (i-1)*2+40)); // 目标站 |
| | | } |
| | | } |
| | | OperateResultExOne<byte[]> result1 = melsecMcNet.Read("DB100.40", (short) 8); |
| | | OperateResultExOne<boolean[]> result1 = melsecMcNet.ReadBool("M800", (short) 64); |
| | | if (result1.IsSuccess) { |
| | | for (int i = 1; i <= 8; i++) { |
| | | boolean[] status = melsecMcNet.getByteTransform().TransBool(result1.Content, i-1, 1); |
| | | StaProtocol staProtocol = station.get(i); |
| | | staProtocol.setAutoing(status[0]); // 自动 |
| | | staProtocol.setLoading(status[1]); // 有物 |
| | | staProtocol.setInEnable(status[2]); // 可入 |
| | | staProtocol.setOutEnable(status[3]);// 可出 |
| | | staProtocol.setEmptyMk(status[4]); // 空板信号 |
| | | staProtocol.setAutoing(result1.Content[(i-1)*8]); // 自动 |
| | | staProtocol.setLoading(result1.Content[(i-1)*8+1]); // 有物 |
| | | staProtocol.setInEnable(result1.Content[(i-1)*8+2]); // 可入 |
| | | staProtocol.setOutEnable(result1.Content[(i-1)*8+3]);// 可出 |
| | | staProtocol.setEmptyMk(result1.Content[(i-1)*8+4]); // 空板信号 |
| | | } |
| | | } |
| | | if (result.IsSuccess && result1.IsSuccess) { |
| | |
| | | if (null == staProtocol) { |
| | | return; |
| | | } |
| | | OperateResult write = melsecMcNet.Write("DB100." + (staProtocol.getSiteId() - 1) * 2, staProtocol.getWorkNo()); // 工作号 |
| | | OperateResult write1 = melsecMcNet.Write("DB100." + ((staProtocol.getSiteId() - 1) * 2 + 20), staProtocol.getStaNo()); // 目标站 |
| | | OperateResult write = melsecMcNet.Write("D10" + staProtocol.getSiteId(), staProtocol.getWorkNo()); // 工作号 |
| | | OperateResult write1 = melsecMcNet.Write("D12" + staProtocol.getSiteId(), staProtocol.getStaNo()); // 目标站 |
| | | // boolean[] status = new boolean[8]; |
| | | // status[0] = staProtocol.isAutoing(); |
| | | // status[1] = staProtocol.isLoading(); |
| | |
| | | if (null == staProtocol) { |
| | | return; |
| | | } |
| | | OperateResult write = melsecMcNet.Write("DB100." + (staProtocol.getSiteId() - 1) * 2, staProtocol.getWorkNo()); // 工作号 |
| | | OperateResult write = melsecMcNet.Write("D10" + staProtocol.getSiteId(), staProtocol.getWorkNo()); // 工作号 |
| | | if (!write.IsSuccess ) { |
| | | OutputQueue.DEVP.offer(MessageFormat.format("【{0}】写入输送线站点数据失败。输送线plc编号={1},站点数据={2}", slave.getId(), JSON.toJSON(staProtocol))); |
| | | log.error("写入输送线站点数据失败。输送线plc编号={},站点数据={}", slave.getId(), JSON.toJSON(staProtocol)); |
| | |
| | | if (null == staProtocol) { |
| | | return; |
| | | } |
| | | OperateResult write = melsecMcNet.Write("DB100." + ((staProtocol.getSiteId() - 1) * 2 + 20), staProtocol.getStaNo()); // 目标站 |
| | | OperateResult write = melsecMcNet.Write("D12" + staProtocol.getSiteId(), staProtocol.getStaNo()); // 目标站 |
| | | if (!write.IsSuccess ) { |
| | | OutputQueue.DEVP.offer(MessageFormat.format("【{0}】写入输送线站点数据失败。输送线plc编号={1},站点数据={2}", slave.getId(), JSON.toJSON(staProtocol))); |
| | | log.error("写入输送线站点数据失败。输送线plc编号={},站点数据={}", slave.getId(), JSON.toJSON(staProtocol)); |