zjj
2024-11-25 0f69561e397093b5165c4aac58530721d5c62178
zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/thread/impl/JxgtLiftThread.java
@@ -17,10 +17,12 @@
import com.zy.asrs.wcs.core.model.enums.MotionCtgType;
import com.zy.asrs.wcs.core.service.BasLiftService;
import com.zy.asrs.wcs.core.utils.RedisUtil;
import com.zy.asrs.wcs.core.utils.Utils;
import com.zy.asrs.wcs.rcs.News;
import com.zy.asrs.wcs.rcs.cache.OutputQueue;
import com.zy.asrs.wcs.rcs.entity.Device;
import com.zy.asrs.wcs.rcs.entity.DeviceDataLog;
import com.zy.asrs.wcs.rcs.model.CommandResponse;
import com.zy.asrs.wcs.rcs.model.enums.LiftProtocolStatusType;
import com.zy.asrs.wcs.rcs.model.protocol.LiftProtocol;
import com.zy.asrs.wcs.rcs.service.DeviceDataLogService;
@@ -29,10 +31,7 @@
import lombok.extern.slf4j.Slf4j;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Base64;
import java.util.Date;
import java.util.List;
import java.util.*;
@Slf4j
@SuppressWarnings("all")
@@ -114,8 +113,8 @@
                liftProtocol.setHasCar(siemensS7Net.getByteTransform().TransInt16(result1.Content, 6) == 1);
                //当前楼层
                liftProtocol.setLev((int) siemensS7Net.getByteTransform().TransInt16(result1.Content, 8));
                //工作号
                liftProtocol.setTaskNo(siemensS7Net.getByteTransform().TransInt32(result1.Content, 12));
//                //工作号
//                liftProtocol.setTaskNo(siemensS7Net.getByteTransform().TransInt32(result1.Content, 12));
                //设备故障
                liftProtocol.setError(siemensS7Net.getByteTransform().TransInt16(result1.Content, 16) == 1);
                //故障码
@@ -126,6 +125,12 @@
                //锁定
                liftExtend.setLock(siemensS7Net.getByteTransform().TransInt16(result1.Content, 10) == 1);
                liftProtocol.setExtend(liftExtend);
                boolean ready = true;
                if (!liftProtocol.getModel() || liftProtocol.getRun()) {
                    ready = false;
                }
                liftProtocol.setReady(ready);//就绪状态
            }else {
@@ -191,53 +196,70 @@
    }
    @Override
    public boolean move(LiftCommand command) {
    public CommandResponse move(LiftCommand command) {
        return write(command);
    }
    @Override
    public boolean palletInOut(LiftCommand command) {
    public CommandResponse palletInOut(LiftCommand command) {
        return write(command);
    }
    private boolean write(LiftCommand command) {
    private CommandResponse write(LiftCommand command) {
        CommandResponse response = new CommandResponse(false);
        if (null == command) {
            News.error("提升机写入命令为空");
            return false;
            response.setMessage("提升机写入命令为空");
            return response;
        }
        List<Short> shorts = JSON.parseArray(command.getBody(), Short.class);
        short[] array = new short[shorts.size()];//获取命令报文
        for (int i = 0; i < shorts.size(); i++) {
            array[i] = shorts.get(i);
        List<Integer> list = JSON.parseArray(command.getBody(), Integer.class);
        int[] array = new int[list.size()];//获取命令报文
        for (int i = 0; i < list.size(); i++) {
            array[i] = list.get(i);
        }
        OperateResult result = siemensS7Net.Write("DB83.0", array);
        OperateResult result = null;
        if (command.getMode() == LiftCommandModeType.MOVE.id) {
            //移动
            result = siemensS7Net.Write("DB101.2", (short) array[0]);
            result = siemensS7Net.Write("DB101.4", (int) array[1]);
        } else if (command.getMode() == LiftCommandModeType.PALLET_INOUT.id) {
            //托盘出入
            result = siemensS7Net.Write("DB101.8", array);
        } else if (command.getMode() == LiftCommandModeType.LOCK.id || command.getMode() == LiftCommandModeType.UNLOCK.id) {
            //提升机锁定/解锁
            result = siemensS7Net.Write("DB101.0", (short) array[0]);
        }
        if (result != null && result.IsSuccess) {
            liftProtocol.setSendTime(System.currentTimeMillis());//指令下发时间
            News.info("提升机命令下发[id:{}] >>>>> {}", device.getId(), JSON.toJSON(command));
            OutputQueue.LIFT.offer(MessageFormat.format("【{0}】[id:{1}] >>>>> 命令下发: {2}", DateUtils.convert(new Date()), device.getId(), JSON.toJSON(command)));
            return true;
            response.setMessage(MessageFormat.format("【{0}】[id:{1}] >>>>> 命令下发: {2}", DateUtils.convert(new Date()), device.getId(), JSON.toJSON(command)));
            response.setResult(true);
            return response;
        } else {
            OutputQueue.LIFT.offer(MessageFormat.format("【{0}】写入提升机plc数据失败 ===>> [id:{1}] [ip:{2}] [port:{3}],次数:{}", DateUtils.convert(new Date()), device.getId(), device.getIp(), device.getPort()));
            OutputQueue.LIFT.offer(MessageFormat.format("【{0}】写入提升机plc数据失败 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), device.getId(), device.getIp(), device.getPort()));
            News.error("写入提升机plc数据失败 ===>> [id:{}] [ip:{}] [port:{}]", device.getId(), device.getIp(), device.getPort());
            return false;
            response.setMessage(MessageFormat.format("【{0}】写入提升机plc数据失败 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), device.getId(), device.getIp(), device.getPort()));
            return response;
        }
    }
    @Override
    public boolean lock(LiftCommand command) {
        return true;
    public CommandResponse lock(LiftCommand command) {
        return write(command);
    }
    @Override
    public boolean unlock(LiftCommand command) {
        return true;
    public CommandResponse unlock(LiftCommand command) {
        return write(command);
    }
    @Override
    public boolean reset(LiftCommand command) {
        return false;
    public CommandResponse reset(LiftCommand command) {
        return new CommandResponse(true);
    }
    @Override
@@ -302,37 +324,31 @@
    @Override
    public boolean isLock(ExecuteSupport support) {
        if (support != null) {
            return support.judgement();
        InnerLiftExtend extend = (InnerLiftExtend) this.liftProtocol.getExtend();
        return extend.getLock();
    }
    @Override
    public int generateDeviceTaskNo(int taskNo, MotionCtgType motionCtgType) {
        int deviceTaskNo = taskNo;
        try {
            deviceTaskNo = Utils.getTaskNo("LIFT_TASK_NO");
        } catch (Exception e) {
            return taskNo;
        }
        return true;
        return deviceTaskNo;
    }
    @Override
    public List<LiftCommand> getMoveCommand(Integer taskNo, Integer sourceLev, Integer targetLev, LiftCommandModeType mode) {
        /**
         * 任务类型
         * 1=移托盘;升降机将源站台托盘移到目标站台
         * 2=移小车,升降机移到目标层,等待
         */
        short taskMode = 2;
        if (mode.equals(LiftCommandModeType.PALLET_INOUT)) {
            taskMode = 1;
        }
        // 开始任务
        short[] array = new short[4];
        //任务类型
        array[0] = taskMode;
        //源站台编号
        array[1] = sourceLev.shortValue();
        //目标站台编号
        array[2] = targetLev.shortValue();
        //任务号
        array[3] = taskNo.shortValue();
        short[] array = new short[2];
        array[0] = targetLev.shortValue();//目标层
        array[1] = taskNo.shortValue();//工作号
        LiftCommand command = new LiftCommand();
        command.setLiftNo(Integer.valueOf(this.device.getDeviceNo()));
        command.setTaskNo(taskNo);
        command.setBody(JSON.toJSONString(array));
        command.setMode(LiftCommandModeType.MOVE.id);
        command.setOriginLev(sourceLev);
@@ -350,12 +366,40 @@
    @Override
    public List<LiftCommand> getPalletInOutCommand(Integer taskNo, Integer sourceLev, Integer targetLev, Integer originSta, Integer targetSta, LiftCommandModeType mode) {
        return getMoveCommand(taskNo, sourceLev, targetLev, mode);
        // 开始任务
        short[] array = new short[3];
        array[0] = originSta.shortValue();//起始站
        array[1] = targetSta.shortValue();//目标站
        array[2] = taskNo.shortValue();//工作号
        LiftCommand command = new LiftCommand();
        command.setLiftNo(Integer.valueOf(this.device.getDeviceNo()));
        command.setTaskNo(taskNo);
        command.setBody(JSON.toJSONString(array));
        command.setMode(LiftCommandModeType.PALLET_INOUT.id);
        command.setOriginLev(sourceLev);
        command.setTargetLev(targetLev);
        ArrayList<LiftCommand> list = new ArrayList<>();
        list.add(command);
        return list;
    }
    @Override
    public List<LiftCommand> getLockCommand(Integer taskNo, Boolean lock) {
        return null;
        // 开始任务
        short[] array = new short[2];
        array[0] = lock ? (short) 1 : (short) 0;
        LiftCommand command = new LiftCommand();
        command.setLiftNo(Integer.valueOf(this.device.getDeviceNo()));
        command.setTaskNo(taskNo);
        command.setBody(JSON.toJSONString(array));
        command.setMode(lock ? LiftCommandModeType.LOCK.id : LiftCommandModeType.UNLOCK.id);
        ArrayList<LiftCommand> list = new ArrayList<>();
        list.add(command);
        return list;
    }
    @Override
@@ -367,7 +411,7 @@
    public boolean connect() {
        boolean result = false;
        //-------------------------提升机连接方法------------------------//
        siemensS7Net = new SiemensS7Net(SiemensPLCS.S1200, device.getIp());
        siemensS7Net = new SiemensS7Net(SiemensPLCS.S1500, device.getIp());
        OperateResult connect = siemensS7Net.ConnectServer();
        if(connect.IsSuccess){
            result = true;