| | |
| | | import com.core.common.DateUtils; |
| | | import com.core.common.RadixTools; |
| | | import com.core.exception.CoolException; |
| | | import com.zy.common.utils.CommonUtils; |
| | | import com.zy.core.News; |
| | | import com.zy.core.ThreadHandler; |
| | | import com.zy.core.cache.MessageQueue; |
| | |
| | | |
| | | import java.text.MessageFormat; |
| | | import java.util.Date; |
| | | import java.util.Random; |
| | | |
| | | /** |
| | | * 四向穿梭车线程 |
| | |
| | | |
| | | private void readStatus() { |
| | | try { |
| | | OperateResultExOne<byte[]> result = modbusTcpNet.Read("0", (short) 17); |
| | | OperateResultExOne<byte[]> result = modbusTcpNet.Read("200", (short) 17); |
| | | if (result.IsSuccess) { |
| | | if (null == shuttleProtocol) { |
| | | shuttleProtocol = new ShuttleProtocol(); |
| | | shuttleProtocol.setShuttleNo(slave.getId().shortValue()); |
| | | } |
| | | |
| | | //----------设置四向穿梭车状态----------- |
| | | //----------读取四向穿梭车状态----------- |
| | | //获取数据 |
| | | byte[] content = result.Content; |
| | | //小车忙状态位 |
| | | shuttleProtocol.setBusyStatus(modbusTcpNet.getByteTransform().TransInt16(content,0)); |
| | | //当前二维码 |
| | | shuttleProtocol.setCurrentCode(modbusTcpNet.getByteTransform().TransInt16(content,2)); |
| | | //电池电量百分比 |
| | | shuttleProtocol.setBatteryPower(modbusTcpNet.getByteTransform().TransInt16(content,4)); |
| | | //电池温度 |
| | | shuttleProtocol.setBatteryTemp(modbusTcpNet.getByteTransform().TransInt16(content,6)); |
| | | //错误编号 |
| | | shuttleProtocol.setErrorCode(modbusTcpNet.getByteTransform().TransInt16(content,8)); |
| | | //Plc输出状态IO |
| | | shuttleProtocol.setPlcOutputStatusIO(modbusTcpNet.getByteTransform().TransInt16(content,10)); |
| | | //错误信息码 |
| | | shuttleProtocol.setStatusErrorCode(modbusTcpNet.getByteTransform().TransInt16(content,12)); |
| | | //PLC输入状态 |
| | | shuttleProtocol.setPlcInputStatus(modbusTcpNet.getByteTransform().TransInt16(content,14)); |
| | | //当前或者之前读到的二维码值 |
| | | shuttleProtocol.setCurrentOrBeforeCode(modbusTcpNet.getByteTransform().TransInt16(content,16)); |
| | | //读到的二维码X方向偏移量 |
| | | shuttleProtocol.setCodeOffsetX(modbusTcpNet.getByteTransform().TransInt16(content,18)); |
| | | //读到的二维码Y方向偏移量 |
| | | shuttleProtocol.setCodeOffsetY(modbusTcpNet.getByteTransform().TransInt16(content,20)); |
| | | //当前的电压值 |
| | | shuttleProtocol.setCurrentVoltage(modbusTcpNet.getByteTransform().TransInt16(content,22)); |
| | | //当前的模拟量值 |
| | | shuttleProtocol.setCurrentAnalogValue(modbusTcpNet.getByteTransform().TransInt16(content,24)); |
| | | //当前的升降伺服速度 |
| | | shuttleProtocol.setCurrentLiftServoSpeed(modbusTcpNet.getByteTransform().TransInt16(content,26)); |
| | | //当前的行走伺服速度 |
| | | shuttleProtocol.setCurrentMoveServoSpeed(modbusTcpNet.getByteTransform().TransInt16(content,28)); |
| | | //当前的升降伺服负载率 |
| | | shuttleProtocol.setCurrentLiftServoLoad(modbusTcpNet.getByteTransform().TransInt16(content,30)); |
| | | //当前的行走伺服负载率 |
| | | shuttleProtocol.setCurrentMoveServoLoad(modbusTcpNet.getByteTransform().TransInt16(content,32)); |
| | | |
| | | //--------控制字-------- |
| | | //控制指令字 |
| | | shuttleProtocol.setCommandWord(modbusTcpNet.getByteTransform().TransUInt16(content, 0)); |
| | | //启始二维编号 |
| | | shuttleProtocol.setStartCodeNum(modbusTcpNet.getByteTransform().TransUInt16(content, 2)); |
| | | //中间二维编号 |
| | | shuttleProtocol.setMiddleCodeNum(modbusTcpNet.getByteTransform().TransUInt16(content, 4)); |
| | | //目标二维编号 |
| | | shuttleProtocol.setDistCodeNum(modbusTcpNet.getByteTransform().TransUInt16(content, 6)); |
| | | //起点到目标点的距离长度 |
| | | shuttleProtocol.setStartToDistDistance(modbusTcpNet.getByteTransform().TransInt32(content, 8)); |
| | | //中间点到目标点的距离长度 |
| | | shuttleProtocol.setMiddleToDistDistance(modbusTcpNet.getByteTransform().TransInt32(content, 12)); |
| | | //小车运行方向 |
| | | shuttleProtocol.setRunDirection(modbusTcpNet.getByteTransform().TransUInt16(content, 16)); |
| | | //托盘顶升 |
| | | shuttleProtocol.setPalletLift(modbusTcpNet.getByteTransform().TransUInt16(content,18)); |
| | | //小车强制移动距离 |
| | | shuttleProtocol.setForceMoveDistance(modbusTcpNet.getByteTransform().TransInt32(content, 20)); |
| | | //充电开关 |
| | | shuttleProtocol.setChargeSwitch(modbusTcpNet.getByteTransform().TransUInt16(content,24)); |
| | | //小车IO控制 |
| | | shuttleProtocol.setIOControl(modbusTcpNet.getByteTransform().TransUInt16(content,26)); |
| | | //小车运行速度 |
| | | shuttleProtocol.setRunSpeed(modbusTcpNet.getByteTransform().TransUInt16(content,28)); |
| | | //小车雷达备用 |
| | | shuttleProtocol.setRadarTmp(modbusTcpNet.getByteTransform().TransUInt16(content,30)); |
| | | //指令结束位 |
| | | shuttleProtocol.setCommandEnd(modbusTcpNet.getByteTransform().TransUInt16(content,32)); |
| | | ///读取四向穿梭车状态-end |
| | | |
| | | |
| | | //---------状态字--------- |
| | | // shuttleProtocol.setBusyStatus(modbusTcpNet.getByteTransform().TransUInt16(content,32)); |
| | | |
| | | ///设置四向穿梭车状态-end |
| | | OutputQueue.SHUTTLE.offer(MessageFormat.format("【{0}】[id:{1}] <<<<< 实时数据更新成功",DateUtils.convert(new Date()), slave.getId())); |
| | | //读取四向穿梭车设备信息,提供查询 |
| | | //..... |
| | | |
| | | log.info(MessageFormat.format("【{0}】[id:{1}] <<<<< 实时数据更新成功",DateUtils.convert(new Date()), slave.getId())); |
| | | |
| | | // 根据实时信息更新数据库 |
| | | //..... |
| | | |
| | | |
| | | }else { |
| | | OutputQueue.SHUTTLE.offer(MessageFormat.format("【{0}】{1}四向穿梭车plc状态信息失败", DateUtils.convert(new Date()), slave.getId())); |
| | |
| | | return false; |
| | | } |
| | | |
| | | //判断小车是否在充电 |
| | | SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, 1); |
| | | if (devpThread.charge1){ |
| | | |
| | | } |
| | | |
| | | command.setShuttleNo(slave.getId()); |
| | | OperateResult result = null; |
| | | // 开始任务 |
| | | //... |
| | | short[] array = new short[17]; |
| | | //控制指令字 |
| | | array[0] = command.getCommandWord(); |
| | | //启始二维编号 |
| | | array[1] = command.getStartCodeNum(); |
| | | //中间二维编号 |
| | | array[2] = command.getMiddleCodeNum(); |
| | | //目标二维编号 |
| | | array[3] = command.getDistCodeNum(); |
| | | |
| | | //起点到目标点的距离长度,先将int转为byte数组,再将byte数组转成两个short,分别占用4和5空间 |
| | | short[] startToDistDistances = CommonUtils.intToShorts(command.getStartToDistDistance()); |
| | | array[4] = startToDistDistances[0]; |
| | | array[5] = startToDistDistances[1]; |
| | | |
| | | try { |
| | | // 日志记录 |
| | | if (!command.getComplete() && command.getTaskMode() != 0) { |
| | | //日志记录保存到数据库中 |
| | | //..... |
| | | } |
| | | } catch (Exception ignore) {} |
| | | //中间点到目标点的距离长度,先将int转为byte数组,再将byte数组转成两个short,分别占用4和5空间 |
| | | short[] middleToDistDistances = CommonUtils.intToShorts(command.getMiddleToDistDistance()); |
| | | array[6] = middleToDistDistances[0]; |
| | | array[7] = middleToDistDistances[1]; |
| | | |
| | | //小车运行方向 |
| | | array[8] = command.getRunDirection(); |
| | | //托盘顶升 |
| | | array[9] = command.getPalletLift(); |
| | | |
| | | //小车强制移动距离,先将int转为byte数组,再将byte数组转成两个short,分别占用4和5空间 |
| | | short[] forceMoveDistances = CommonUtils.intToShorts(command.getForceMoveDistance()); |
| | | array[10] = forceMoveDistances[0]; |
| | | array[11] = forceMoveDistances[1]; |
| | | |
| | | //充电开关 |
| | | array[12] = command.getChargeSwitch(); |
| | | //小车IO控制 |
| | | array[13] = command.getIOControl(); |
| | | //小车运行速度 |
| | | array[14] = command.getRunSpeed(); |
| | | //小车雷达备用 |
| | | array[15] = command.getRadarTmp(); |
| | | //指令结束位 |
| | | array[16] = command.getCommandEnd(); |
| | | |
| | | OperateResult result = modbusTcpNet.Write("0", array);; |
| | | if (result != null && result.IsSuccess) { |
| | | // 维护数据库排列层 |
| | | // if (!steProtocol.getWaiting()) { |
| | | // if (!Cools.isEmpty(command.getRow(), command.getBay(), command.getLev())) { |
| | | // this.modifyPos(command.getRow().intValue(), command.getBay().intValue(), command.getLev().intValue()); |
| | | // } |
| | | // } |
| | | |
| | | News.info("四向穿梭车命令下发[id:{}] >>>>> {}", slave.getId(), JSON.toJSON(command)); |
| | | OutputQueue.SHUTTLE.offer(MessageFormat.format("【{0}】[id:{1}] >>>>> 命令下发: {2}", DateUtils.convert(new Date()), slave.getId(), JSON.toJSON(command))); |
| | | return true; |
| | |
| | | if (null == shuttleProtocol) { |
| | | shuttleProtocol = new ShuttleProtocol(); |
| | | } |
| | | shuttleProtocol.setShuttleNo(slave.getId().shortValue()); |
| | | shuttleProtocol.setBusyStatus(ShuttleStatusType.BUSY); |
| | | shuttleProtocol.setCurrentCode("0"); |
| | | // shuttleProtocol.setShuttleNo(slave.getId().shortValue()); |
| | | // shuttleProtocol.setBusyStatus(ShuttleStatusType.BUSY); |
| | | // shuttleProtocol.setCurrentCode("0"); |
| | | } |
| | | |
| | | /******************************************************************************************/ |
| | |
| | | ShuttleThread thread = new ShuttleThread(slave); |
| | | thread.connect(); |
| | | thread.readStatus(); |
| | | System.out.println(JSON.toJSONString(thread.shuttleProtocol)); |
| | | |
| | | // 任务作业 |
| | | // SteCommand command = new SteCommand(); |
| | | // command.setSteNo(1); // 堆垛机编号 |
| | | // Random random = new Random(); |
| | | // int taskNo = random.nextInt(9090); |
| | | // command.setTaskNo(taskNo); // 工作号 |
| | | // command.setTaskMode(SteTaskModeType.MOVE_LEFT); // 任务模式 |
| | | // thread.write(command); |
| | | |
| | | // 任务完成 |
| | | // SteCommand command = new SteCommand(); |
| | | // command.setSteNo(1); // 堆垛机编号 |
| | | // command.setComplete(Boolean.TRUE); // 任务模式 |
| | | // thread.write(command); |
| | | |
| | | // 控制模式 |
| | | // SteCommand command = new SteCommand(); |
| | | // command.setControlMode((short) 1); |
| | | // thread.write(command); |
| | | |
| | | // 复位信号 |
| | | // SteCommand command = new SteCommand(); |
| | | // command.setReset(Boolean.TRUE); |
| | | // thread.write(command); |
| | | |
| | | // 删除指令 |
| | | // SteCommand command = new SteCommand(); |
| | | // command.setDelete(Boolean.TRUE); |
| | | // thread.write(command); |
| | | |
| | | // 穿梭车运行禁止 |
| | | // SteCommand command = new SteCommand(); |
| | | // command.setRun((short)0); |
| | | // thread.write(command); |
| | | ShuttleCommand command = new ShuttleCommand(); |
| | | command.setCommandWord((short) 0); |
| | | command.setStartCodeNum((short) 12323); |
| | | command.setMiddleCodeNum((short) 22323); |
| | | command.setDistCodeNum((short) 29999); |
| | | command.setStartToDistDistance(109999); |
| | | command.setMiddleToDistDistance(5000); |
| | | command.setRunDirection((short) 1); |
| | | command.setPalletLift((short) 2); |
| | | command.setForceMoveDistance(3000); |
| | | command.setChargeSwitch((short) 2); |
| | | command.setIOControl((short) 0); |
| | | command.setRunSpeed((short) 0); |
| | | command.setRadarTmp((short) 0); |
| | | command.setCommandEnd((short) 1); |
| | | thread.write(command); |
| | | |
| | | } |
| | | } |