| | |
| | | |
| | | private void read() { |
| | | try { |
| | | if (this.socket == null || !this.socket.isConnected()) { |
| | | //链接断开重新链接 |
| | | this.connect(); |
| | | } |
| | | readStatus(); |
| | | //四向穿梭车空闲、有任务、标记为true、存在任务指令,需要执行任务的下一条指令 |
| | | if (shuttleProtocol.getFree() == ShuttleStatusType.IDLE.id |
| | |
| | | |
| | | //----------读取四向穿梭车状态----------- |
| | | NyShuttleHttpCommand readStatusCommand = NyHttpUtils.getReadStatusCommand(slave.getId()); |
| | | JSONObject result = NyHttpUtils.requestCommand(socket, readStatusCommand); |
| | | if (result == null) { |
| | | JSONObject jsonObject = NyHttpUtils.requestCommand(socket, readStatusCommand); |
| | | if (jsonObject == null) { |
| | | OutputQueue.SHUTTLE.offer(MessageFormat.format("【{0}】四向穿梭车plc状态信息失败 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort())); |
| | | }else { |
| | | JSONObject jsonObject = NyHttpUtils.filterData(result); |
| | | //手动状态/自动状态 |
| | | shuttleProtocol.setWorkingMode(jsonObject.getInteger("workingMode")); |
| | | //允许状态 0:运行中1:空闲 |
| | |
| | | try { |
| | | Socket socket = new Socket(slave.getIp(),slave.getPort()); |
| | | socket.setSoTimeout(60000); |
| | | socket.setKeepAlive(true); |
| | | this.socket = socket; |
| | | } catch (IOException e) { |
| | | OutputQueue.SHUTTLE.offer(MessageFormat.format("【{0}】四向穿梭车Socket链接失败 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort())); |