pang.jiabao
2024-10-16 ceb33d7020bcc1620d43cdcb9d1ea51a17c81a0d
src/main/java/com/zy/core/thread/SiemensCrnThread.java
@@ -5,6 +5,7 @@
import HslCommunication.Profinet.Siemens.SiemensPLCS;
import HslCommunication.Profinet.Siemens.SiemensS7Net;
import com.alibaba.fastjson.JSON;
import com.core.common.Cools;
import com.core.common.DateUtils;
import com.core.common.SpringUtils;
import com.zy.asrs.entity.BasCrnOpt;
@@ -38,6 +39,10 @@
    private CrnProtocol crnProtocol;
    private boolean resetFlag = false;
    public Long sign = System.currentTimeMillis();
    public boolean isRunning = true;
    /**
     * 堆垛机是否在回原点运动中标记
     */
@@ -51,7 +56,7 @@
    @SuppressWarnings("InfiniteLoopStatement")
    public void run() {
        this.connect();
        while (true) {
        while (isRunning) {
            try {
                int step = 1;
                Task task = MessageQueue.poll(SlaveType.Crn, slave.getId());
@@ -92,7 +97,8 @@
            } catch (Exception e) {
//                e.printStackTrace();
            }
//            System.out.println("第"+slave.getId()+"个堆垛机线程运行一轮:"+(System.currentTimeMillis()-sign));
            sign = System.currentTimeMillis();
        }
    }
@@ -151,6 +157,7 @@
            if (result.IsSuccess) {
                if (null == crnProtocol) {
                    crnProtocol = new CrnProtocol();
                    crnProtocol.setCrnNo(slave.getId());
                }
                crnProtocol.setMode(siemensNet.getByteTransform().TransInt16(result.Content, 0));
                crnProtocol.setTaskNo(siemensNet.getByteTransform().TransInt16(result.Content, 2));
@@ -177,7 +184,9 @@
                OutputQueue.CRN.offer(MessageFormat.format("【{0}】[id:{1}] <<<<< 实时数据更新成功",DateUtils.convert(new Date()), slave.getId()));
                // 复位信号
                if (crnProtocol.getStatusType().equals(CrnStatusType.WAITING)) {
                if (!Cools.isEmpty(crnProtocol.getStatusType()) && crnProtocol.getStatusType().equals(CrnStatusType.WAITING)) {
                    log.error("-------------------------------------------第一步、[堆垛机号:{}, 工作号:{}, 载货台:{}]==>> 状态为10,等待确认!!",
                            slave.getId(),crnProtocol.getTaskNo(), crnProtocol.getLoaded()==1 ? "有物" : "无物");
                    if (resetFlag) {
                        if(crnProtocol.getTaskNo()==9999){
                            backHpFlag = false;
@@ -231,7 +240,7 @@
            log.error("堆垛机写入命令为空");
            return false;
        }
        convertRow(command);
//        convertRow(command);
        command.setCrnNo(slave.getId());
        short[] array = new short[12];
        array[0] = command.getAckFinish();
@@ -248,8 +257,12 @@
        array[11] = command.getCommand();
        OperateResult result = siemensNet.Write("DB100.0", array);
        if (command.getAckFinish() == 0) {
        if(!result.IsSuccess){
            return false;
        }
        if (command.getAckFinish().intValue() == 0) {
            short commandFinish = 1;
            Thread.sleep(100L);
            result = siemensNet.Write("DB100.22", commandFinish);
        }
@@ -263,12 +276,12 @@
                    command.getTaskModeType().toString(),    // 模式
                    command.getSourcePosX().intValue(),    // 源排
                    command.getSourcePosY().intValue(),    // 源列
                    command.getSourcePosZ().intValue(),    // 源层
                    null,    // 源站
                    command.getSourceStaNo().intValue(),    // 源层
                    command.getDestinationPosZ().intValue(),    // 源站
                    command.getDestinationPosX().intValue(),    // 目标排
                    command.getDestinationPosY().intValue(),    // 目标列
                    command.getDestinationPosZ().intValue(),    // 目标层
                    null,    // 目标站
                    command.getDestinationStaNo().intValue(),    // 目标站
                    null,    // 响应结果
                    null,    // 修改时间
                    null    // 修改人员
@@ -410,4 +423,9 @@
    }
    // 提供一个方法来停止线程
    public void requestStop() {
        isRunning = false;
    }
}