自动化立体仓库 - WCS系统
#
LSH
2023-11-21 67a8ef2767b1980487091e1bfcd3bd17502140e6
src/main/java/com/zy/core/thread/SiemensCrnThread.java
@@ -7,10 +7,7 @@
import com.alibaba.fastjson.JSON;
import com.core.common.DateUtils;
import com.core.common.SpringUtils;
import com.zy.asrs.entity.BasCrnOpt;
import com.zy.asrs.entity.BasCrnp;
import com.zy.asrs.entity.CommandInfo;
import com.zy.asrs.entity.TaskWrk;
import com.zy.asrs.entity.*;
import com.zy.asrs.service.*;
import com.zy.core.CrnThread;
import com.zy.core.cache.MessageQueue;
@@ -25,6 +22,7 @@
import lombok.extern.slf4j.Slf4j;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@@ -40,6 +38,19 @@
    private CrnSlave slave;
    private CrnProtocol crnProtocol;
    private boolean resetFlag = false;
    public static final List<Short> rowOne = new ArrayList<Short>() {{
        add((short) 1);add((short) 5);add((short) 7);add((short) 11);add((short) 15);add((short) 19);
    }};
    public static final List<Short> rowTwo = new ArrayList<Short>() {{
        add((short) 2);add((short) 6);add((short) 8);add((short) 12);add((short) 16);add((short) 20);
    }};
    public static final List<Short> rowThree = new ArrayList<Short>() {{
        add((short) 3);add((short) 9);add((short) 13);add((short) 17);add((short) 21);
    }};
    public static final List<Short> rowFour = new ArrayList<Short>() {{
        add((short) 4);add((short) 10);add((short) 14);add((short) 18);
    }};
    public SiemensCrnThread(CrnSlave slave) {
        this.slave = slave;
@@ -137,21 +148,33 @@
     * 读取状态
     */
    private void readStatus(){
        OperateResultExOne<byte[]> result = siemensNet.Read("DB11.2", (short) 104);
        OperateResultExOne<byte[]> result = siemensNet.Read("DB101.0", (short) 56);
        if (result.IsSuccess) {
            if (null == crnProtocol) {
                crnProtocol = new CrnProtocol();
            }
            crnProtocol.setMode(siemensNet.getByteTransform().TransInt16(result.Content, 0));   // 2
            crnProtocol.setStatus(siemensNet.getByteTransform().TransInt16(result.Content, 2)); // 4
            crnProtocol.setTaskNo(siemensNet.getByteTransform().TransInt16(result.Content, 4)); // 6
            crnProtocol.setTaskFinish(siemensNet.getByteTransform().TransInt16(result.Content, 6)); // 8
            crnProtocol.setValid(siemensNet.getByteTransform().TransInt16(result.Content, 8));  // 10
            crnProtocol.setLevel(siemensNet.getByteTransform().TransInt16(result.Content, 14)); // 16
            crnProtocol.setBay(siemensNet.getByteTransform().TransInt16(result.Content, 16));   // 18
            crnProtocol.setRow(siemensNet.getByteTransform().TransInt16(result.Content, 18));   // 20
            crnProtocol.setLane(siemensNet.getByteTransform().TransInt16(result.Content, 20));  // 22
            crnProtocol.setMode(siemensNet.getByteTransform().TransInt16(result.Content, 0));
            crnProtocol.setTaskNo(siemensNet.getByteTransform().TransInt16(result.Content, 2));
            crnProtocol.setStatus(siemensNet.getByteTransform().TransInt16(result.Content, 4));
            crnProtocol.setBay(siemensNet.getByteTransform().TransInt16(result.Content, 6));
            crnProtocol.setLevel(siemensNet.getByteTransform().TransInt16(result.Content, 8));
            crnProtocol.setForkPos(siemensNet.getByteTransform().TransInt16(result.Content, 10));
            crnProtocol.setLiftPos(siemensNet.getByteTransform().TransInt16(result.Content, 12));
            crnProtocol.setWalkPos(siemensNet.getByteTransform().TransInt16(result.Content, 14));
            crnProtocol.setLoaded(siemensNet.getByteTransform().TransInt16(result.Content, 16));
//            crnProtocol.setAlarm(siemensNet.getByteTransform().TransInt16(result.Content, 18));
//            crnProtocol.setTemp1(siemensNet.getByteTransform().TransInt16(result.Content, 20));
//            crnProtocol.setTemp2(siemensNet.getByteTransform().TransInt16(result.Content, 22));
//            crnProtocol.setTemp3(siemensNet.getByteTransform().TransInt16(result.Content, 24));
//            crnProtocol.setTemp4(siemensNet.getByteTransform().TransInt16(result.Content, 26));
            crnProtocol.setXSpeed(siemensNet.getByteTransform().TransSingle(result.Content, 28));
            crnProtocol.setYSpeed(siemensNet.getByteTransform().TransSingle(result.Content, 32));
            crnProtocol.setZSpeed(siemensNet.getByteTransform().TransSingle(result.Content, 36));
            crnProtocol.setXDistance(siemensNet.getByteTransform().TransSingle(result.Content, 40));
            crnProtocol.setYDistance(siemensNet.getByteTransform().TransSingle(result.Content, 44));
            crnProtocol.setXDuration(siemensNet.getByteTransform().TransSingle(result.Content, 48));
            crnProtocol.setYDuration(siemensNet.getByteTransform().TransSingle(result.Content, 52));
            // 异常
            crnProtocol.setAlarm1(0);
@@ -371,60 +394,40 @@
        } else {
            array[0] = 0;
        }
        array[1] = command.getSourcePosZ();
        array[2] = command.getSourcePosY();
        if (command.getSourcePosZ()==(short)1 && command.getSourcePosY()==(short)1){
            array[1] = (short)0;
            array[2] = (short)0;
        }else if (command.getSourcePosZ()==(short)1 && command.getSourcePosY()==(short)41){
            array[1] = (short)0;
            array[2] = (short)42;
        }else {
            array[1] = command.getSourcePosZ();
            array[2] = command.getSourcePosY();
        }
        if (command.getSourcePosX()==(short)3){
        if (rowOne.contains(command.getSourcePosX())){
            array[3] = (short)1;
        }else if (command.getSourcePosX()==(short)4){
        }else if (rowTwo.contains(command.getSourcePosX())){
            array[3] = (short)2;
        }else if (rowThree.contains(command.getSourcePosX())){
            array[3] = (short)3;
        }else if (rowFour.contains(command.getSourcePosX())){
            array[3] = (short)4;
        }else {
            array[3] = command.getSourcePosX();
        }
        array[4] = command.getDestinationPosZ();
        array[5] = command.getDestinationPosY();
        if (command.getDestinationPosZ()==(short)1 && command.getDestinationPosY()==(short)1){
            array[4] = (short)0;
            array[5] = (short)0;
        }else if (command.getDestinationPosZ()==(short)1 && command.getDestinationPosY()==(short)41){
            array[4] = (short)0;
            array[5] = (short)42;
        }else {
            array[4] = command.getDestinationPosZ();
            array[5] = command.getDestinationPosY();
        }
        if (command.getDestinationPosX()==(short)3){
        if (rowOne.contains(command.getDestinationPosX())){
            array[6] = (short)1;
        }else if (command.getDestinationPosX()==(short)4){
        }else if (rowTwo.contains(command.getDestinationPosX())){
            array[6] = (short)2;
        }else if (rowThree.contains(command.getDestinationPosX())){
            array[6] = (short)3;
        }else if (rowFour.contains(command.getDestinationPosX())){
            array[6] = (short)4;
        }else {
            array[6] = command.getDestinationPosX();
        }
        if ((array[1]==(short)0 && array[2] == (short)0) || (array[1]==(short)0 && array[2] == (short)42)){
            array[7]=(short)1;
        }else {
            array[7]=(short)0;
        }
//        array[7] = command.getSourceStaNo();
        if ((array[4]==(short)0 && array[5] == (short)0) || (array[4]==(short)0 && array[5] == (short)42)){
            array[8]=(short)1;
        }else {
            array[8]=(short)0;
        }
//        array[8] = command.getDestinationStaNo();
        array[7] = command.getSourceStaNo();
        array[8] = command.getDestinationStaNo();
        // 作业信息
        OperateResult result = siemensNet.Write("DB10.0", array);
        OperateResult result = siemensNet.Write("DB100.0", array);
        // 任务号 + 完成位
        short[] array2 = new short[2];
        array2[0] = command.getTaskNo();
@@ -461,9 +464,20 @@
            }
        } catch (Exception ignore) {}
        //更新命令日志
        CommandInfoLogService commandInfoLogService = SpringUtils.getBean(CommandInfoLogService.class);
        CommandInfoService commandInfoService = SpringUtils.getBean(CommandInfoService.class);
        CommandInfo commandInfo = commandInfoService.selectById(command.getCommandId());
        CommandInfoLog commandInfoLog = JSON.parseObject(JSON.toJSONString(commandInfo), CommandInfoLog.class);
        commandInfoLog.setId(null);
        if (result.IsSuccess && result1.IsSuccess) {
            log.warn("堆垛机命令下发[id:{},时间:{}] >>>>> {}", slave.getId(), DateUtils.convert(new Date(), DateUtils.yyyyMMddHHmmsssss_F), JSON.toJSON(command));
            OutputQueue.CRN.offer(MessageFormat.format("【{0}】[id:{1}] >>>>> 命令下发: {2}", DateUtils.convert(new Date()), slave.getId(), JSON.toJSON(command)));
            //更新指令日志
            commandInfoLog.setDeviceLog("指令下发成功");
            commandInfoLogService.insert(commandInfoLog);
            //更新任务步序
            TaskWrkService taskWrkService = SpringUtils.getBean(TaskWrkService.class);
@@ -477,6 +491,10 @@
        } else {
            OutputQueue.CRN.offer(MessageFormat.format("【{0}】写入堆垛机plc数据失败 ===>> [id:{1}] [ip:{2}] [port:{3}] [rack:{4}] [slot:{5}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot()));
            log.error("写入堆垛机plc数据失败 ===>> [id:{}] [ip:{}] [port:{}] [rack:{}] [slot:{}]", slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot());
            //更新指令日志
            commandInfoLog.setDeviceLog("指令下发失败");
            commandInfoLogService.insert(commandInfoLog);
            return false;
        }
    }