| | |
| | | |
| | | public CrnThread(CrnSlave slave) { |
| | | this.slave = slave; |
| | | this.connect(); |
| | | } |
| | | |
| | | @Override |
| | |
| | | switch (step) { |
| | | // 读数据 |
| | | case 1: |
| | | readStatus(); // 读取状态 |
| | | readStatus(); |
| | | break; |
| | | // 写入数据 |
| | | case 2: |
| | | CrnCommand command = (CrnCommand) task.getData(); |
| | | write((CrnCommand) task.getData()); |
| | | break; |
| | | case 3: |
| | | break; |
| | |
| | | * 读取状态 |
| | | */ |
| | | private void readStatus(){ |
| | | OperateResultExOne<byte[]> result = siemensNet.Read("DB8.18", (short) 10); |
| | | OperateResultExOne<byte[]> result = siemensNet.Read("DB8.18", (short) 46); |
| | | if (result.IsSuccess) { |
| | | if (null == crnProtocol) { |
| | | crnProtocol = new CrnProtocol(); |
| | |
| | | /** |
| | | * 写入数据 |
| | | */ |
| | | private void write(){ |
| | | |
| | | private void write(CrnCommand command){ |
| | | if (null == command) { |
| | | log.error("堆垛机写入命令为空"); |
| | | return; |
| | | } |
| | | command.setCrnNo(slave.getId()); |
| | | short[] array = new short[9]; |
| | | array[0] = command.getAckFinish(); |
| | | array[1] = command.getTaskNo(); |
| | | array[2] = command.getTaskMode(); |
| | | array[3] = command.getSourcePosX(); |
| | | array[4] = command.getSourcePosY(); |
| | | array[5] = command.getSourcePosZ(); |
| | | array[6] = command.getDestinationPosX(); |
| | | array[7] = command.getDestinationPosY(); |
| | | array[8] = command.getDestinationPosZ(); |
| | | OperateResult result = siemensNet.Write("DB8.0", array); |
| | | if (result.IsSuccess) { |
| | | readStatus(); |
| | | } else { |
| | | log.error("写入堆垛机plc数据失败 ===>> [id:{}] [ip:{}] [port:{}] [rack:{}] [slot:{}]", slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot()); |
| | | } |
| | | } |
| | | |
| | | @Override |