自动化立体仓库 - WCS系统
*
lsh
2025-01-15 1776f84639c7b6d747de68e6a34c36e1169cdec0
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;
@@ -84,7 +85,7 @@
                        command.setTaskMode1(RgvTaskModeType.NONE); // 任务模式
                        command.setSourceStaNo1((short)0);     // 源站
                        command.setDestinationStaNo1((short)0);     // 目标站
                        write(command);
                        write3(command);
                        break;
                    default:
                        break;
@@ -104,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);
@@ -146,11 +148,14 @@
    private void readStatus(){
        try {
            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.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));
@@ -159,7 +164,9 @@
                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.setRgvPos(slave.getId().longValue()*100000);
                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()));
                try {
@@ -202,13 +209,14 @@
        siemensNet.Write("DB24.10.1", false);
        command.setRgvNo(slave.getId());
        short[] array = new short[4];
        array[0] = command.getSourceStaNo1();
        array[1] = command.getDestinationStaNo1();
        array[2] = command.getTaskMode1();//任务模式
        array[3] = command.getTaskNo1();
        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.2", array);
        OperateResult result = siemensNet.Write("DB24.0", array);
        if (command.getAckFinish1().equals((short)0)) {
            Thread.sleep(100L);
@@ -249,6 +257,64 @@
            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 {
            // 日志记录
            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;
        }
    }
    @Override
    public void close() {