自动化立体仓库 - WCS系统
*
lsh
2025-01-15 a25037d44427756e6ab9dd0ed1360425d660362a
src/main/java/com/zy/core/thread/RgvThread.java
@@ -11,6 +11,7 @@
import com.zy.asrs.entity.BasRgvOpt;
import com.zy.asrs.service.BasRgvOptService;
import com.zy.asrs.service.BasRgvService;
import com.zy.asrs.utils.NumUtils;
import com.zy.asrs.utils.RouteUtils;
import com.zy.core.ThreadHandler;
import com.zy.core.cache.MessageQueue;
@@ -72,6 +73,20 @@
                    case 2:
                        write((RgvCommand) task.getData());
                        break;
                    // 复位
                    case 3:
                        RgvCommand command = (RgvCommand) task.getData();
                        if (null == command) {
                            command = new RgvCommand();
                        }
                        command.setRgvNo(slave.getId()); // RGV编号
                        command.setTaskNo1((short) 0); // 工作号
                        command.setAckFinish1((short) 1);  // 任务完成确认位
                        command.setTaskMode1(RgvTaskModeType.NONE); // 任务模式
                        command.setSourceStaNo1((short)0);     // 源站
                        command.setDestinationStaNo1((short)0);     // 目标站
                        write3(command);
                        break;
                    default:
                        break;
                }
@@ -90,6 +105,7 @@
        if (null == rgvProtocol) {
            rgvProtocol = new RgvProtocol();
        }
        rgvProtocol.setRgvNo(slave.getId());
        rgvProtocol.setMode((short) -1);
        rgvProtocol.setStatus((short)-1);
        rgvProtocol.setTaskNo1((short)0);
@@ -131,34 +147,27 @@
     */
    private void readStatus(){
        try {
            OperateResultExOne<byte[]> result = siemensNet.Read("DB100.0", (short) 18);
            OperateResultExOne<byte[]> result = siemensNet.Read("DB100.0", (short) 20);
            OperateResultExOne<byte[]> resultV = siemensNet.Read("DB20.16", (short) 2);
            OperateResultExOne<byte[]> resultE = siemensNet.Read("DB20.26", (short) 2);
            if (result.IsSuccess) {
                if (null == rgvProtocol) {
                    rgvProtocol = new RgvProtocol();
                    rgvProtocol.setRgvNo(slave.getId());
                }
                rgvProtocol.setMode(siemensNet.getByteTransform().TransInt16(result.Content, 0));
                rgvProtocol.setStartSta(siemensNet.getByteTransform().TransInt16(result.Content, 2));
                rgvProtocol.setEndSta(siemensNet.getByteTransform().TransInt16(result.Content, 4));
                rgvProtocol.setTaskNo1(siemensNet.getByteTransform().TransInt16(result.Content, 6));
                rgvProtocol.setAlarm(siemensNet.getByteTransform().TransInt16(result.Content, 8));
                rgvProtocol.setStatus(siemensNet.getByteTransform().TransInt16(result.Content, 10));
                rgvProtocol.setxSpeed(siemensNet.getByteTransform().TransInt16(result.Content, 12));
                rgvProtocol.setRgvPos(siemensNet.getByteTransform().TransUInt32(result.Content, 14));
                rgvProtocol.setRgvPos(slave.getId().longValue()*100000);
                rgvProtocol.setRgvNo(slave.getId());
                rgvProtocol.setMode(siemensNet.getByteTransform().TransInt16(result.Content, 2));
                rgvProtocol.setStartSta(siemensNet.getByteTransform().TransInt16(result.Content, 4));
                rgvProtocol.setEndSta(siemensNet.getByteTransform().TransInt16(result.Content, 6));
                rgvProtocol.setTaskNo1(siemensNet.getByteTransform().TransInt16(result.Content, 8));
                rgvProtocol.setAlarm(siemensNet.getByteTransform().TransInt16(result.Content, 10));
                rgvProtocol.setStatus(siemensNet.getByteTransform().TransInt16(result.Content, 12));
                rgvProtocol.setxSpeed(siemensNet.getByteTransform().TransInt16(result.Content, 14));
                rgvProtocol.setRgvPos(siemensNet.getByteTransform().TransUInt32(result.Content, 16));
                rgvProtocol.setInstantaneousSpeed(Double.valueOf(siemensNet.getByteTransform().TransInt16(resultV.Content, 0)));
                rgvProtocol.setEndStaM(siemensNet.getByteTransform().TransInt16(resultE.Content, 0));
//                rgvProtocol.setRgvPos((long)NumUtils.GetRandomIntInRange(1737000));
                OutputQueue.RGV.offer(MessageFormat.format("【{0}】[id:{1}] <<<<< 实时数据更新成功",DateUtils.convert(new Date()), slave.getId()));
                // 工位1复位信号
                if (rgvProtocol.getStatusType1().equals(RgvStatusType.WAITING)
                        || rgvProtocol.getStatusType1().equals(RgvStatusType.FETCHWAITING)) {
                    if (resetFlag1) {
                        RgvCommand rgvCommand = new RgvCommand();
                        rgvCommand.setAckFinish1((short)1);
                        if (write(rgvCommand)) {
                            resetFlag1 = false;
                        }
                    }
                }
                try {
                    // 根据实时信息更新数据库
@@ -196,23 +205,82 @@
            return false;
        }
//        siemensNet.Write("DB100.20", command.getCommand());
        siemensNet.Write("DB24.10.0", false);
        siemensNet.Write("DB24.10.1", false);
        command.setRgvNo(slave.getId());
        short[] array = new short[5];
        array[0] = command.getAckFinish1();
        array[1] = command.getTaskNo1();
        array[2] = command.getTaskMode1();//任务模式
        array[3] = command.getSourceStaNo1();
        array[4] = command.getDestinationStaNo1();
//        siemensNet.Write("DB100.20", 0);
        array[0] = command.getRgvNo().shortValue();
        array[1] = command.getSourceStaNo1();
        array[2] = command.getDestinationStaNo1();
        array[3] = command.getTaskMode1();//任务模式
        array[4] = command.getTaskNo1();
        OperateResult result = siemensNet.Write("DB100.0", array);
        OperateResult result = siemensNet.Write("DB24.0", array);
        if (command.getAckFinish1() == 0) {
            short commandFinish = 1;  //工位1任务写入
        if (command.getAckFinish1().equals((short)0)) {
            Thread.sleep(100L);
            result = siemensNet.Write("DB100.20", commandFinish);
            result = siemensNet.Write("DB24.10.0", true);
        } else {
            siemensNet.Write("DB24.10.1", true);
        }
        try {
            // 日志记录
            BasRgvOptService bean = SpringUtils.getBean(BasRgvOptService.class);
            BasRgvOpt basRgvOpt = new BasRgvOpt(
                    command.getTaskNo1().intValue(),
                    command.getTaskNo2().intValue(),
                    command.getRgvNo(),
                    new Date(),
                    command.getTaskModeType1().toString(),
                    command.getSourceStaNo1().intValue(),
                    command.getDestinationStaNo1().intValue(),
                    command.getSourceStaNo2().intValue(),
                    command.getDestinationStaNo2().intValue(),
                    null,
                    new Date(),
                    null
            );
            bean.insert(basRgvOpt);
        } catch (Exception ignore) {}
        if (result != null && result.IsSuccess) {
            Thread.sleep(200);
            this.readStatus();
            log.info("RGV 工位1命令下发[id:{}] >>>>> {}", slave.getId(), JSON.toJSONString(command));
            OutputQueue.RGV.offer(MessageFormat.format("【{0}】[id:{1}] >>>>> 工位1命令下发: {2}", DateUtils.convert(new Date()), slave.getId(), JSON.toJSONString(command)));
            return true;
        } else {
            OutputQueue.RGV.offer(MessageFormat.format("【{0}】写入RGV plc工位1数据失败 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort()));
            log.error("写入RGV plc工位1数据失败 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
            return false;
        }
    }
    private boolean write3(RgvCommand command) throws InterruptedException {
        if (null == command) {
            log.error("RGV写入命令为空");
            return false;
        }
        siemensNet.Write("DB24.10.0", false);
        siemensNet.Write("DB24.10.1", false);
        command.setRgvNo(slave.getId());
        short[] array = new short[5];
        array[0] = command.getRgvNo().shortValue();
        array[1] = command.getSourceStaNo1();
        array[2] = command.getDestinationStaNo1();
        array[3] = command.getTaskMode1();//任务模式
        array[4] = command.getTaskNo1();
//        OperateResult result = siemensNet.Write("DB24.0", array);
        OperateResult result = null;
        if (command.getAckFinish1().equals((short)0)) {
            Thread.sleep(100L);
            result = siemensNet.Write("DB24.10.0", true);
        } else {
            siemensNet.Write("DB24.10.1", true);
        }
        try {