whycq
2022-03-16 2a66c437952971e9065dff5c48d76c6ae50b6c5d
src/main/java/com/zy/core/thread/SteThread.java
@@ -16,6 +16,8 @@
import com.zy.core.cache.MessageQueue;
import com.zy.core.cache.OutputQueue;
import com.zy.core.enums.SlaveType;
import com.zy.core.enums.SteStatusType;
import com.zy.core.enums.SteTaskModeType;
import com.zy.core.model.SteSlave;
import com.zy.core.model.Task;
import com.zy.core.model.command.SteCommand;
@@ -25,6 +27,7 @@
import java.text.MessageFormat;
import java.util.Date;
import java.util.Random;
/**
 * shuttle 穿梭车线程
@@ -89,23 +92,12 @@
        if (null == steProtocol) {
            steProtocol = new SteProtocol();
        }
//        steProtocol.setMode((short) -1);
//        steProtocol.setTaskNo((short)0);
//        steProtocol.setStatus((short)-1);
//        steProtocol.setBay((short)0);
//        steProtocol.setLevel((short)0);
//        steProtocol.setForkPos((short) -1);
//        steProtocol.setLiftPos((short) -1);
//        steProtocol.setWalkPos((short)0);
//        steProtocol.setLoaded((short)0);
//        steProtocol.setAlarm((short)0);
//        steProtocol.setXSpeed(0F);
//        steProtocol.setYSpeed(0F);
//        steProtocol.setZSpeed(0F);
//        steProtocol.setXDistance(0F);
//        steProtocol.setYDistance(0F);
//        steProtocol.setXDuration(0F);
//        steProtocol.setYDuration(0F);
        steProtocol.setSteNo(slave.getId().shortValue());
        steProtocol.setMode((short) 0);
        steProtocol.setStatus(SteStatusType.OFF_LINE);
        steProtocol.setTaskNo(0);
        steProtocol.setExecute(false);
        steProtocol.setWaiting(false);
    }
    @Override
@@ -226,11 +218,9 @@
            // 作业
            if (command.getTaskMode() != 0) {
                // 1.任务号
                OperateResult result0 = siemensS7Net.Write("DB3", command.getTaskNo());
                OperateResult result0 = siemensS7Net.Write("DB3.0", command.getTaskNo());
                // 2.作业
                short[] array = new short[10];
                array[0] = command.getTaskMode();
                OperateResult result1 = siemensS7Net.Write("D0", array);
                OperateResult result1 = siemensS7Net.Write("DB3.4", command.getTaskMode());
                // 3.确认开始任务
                if (result0.IsSuccess && result1.IsSuccess) {
                    result = siemensS7Net.Write("D0", true);
@@ -363,101 +353,42 @@
    /**************************************** 测试专用 *****************************************/
    /*****************************************************************************************/
    public static void main(String[] args) throws InterruptedException {
//        CrnSlave slave = new CrnSlave();
//        slave.setId(1);
//        slave.setIp("192.168.3.39");
//        slave.setPort(5015);
//        slave.setRack(0);
//        slave.setSlot(0);
//        SteThread melsecCrnThread = new SteThread(slave);
//        melsecCrnThread.connect();
//        melsecCrnThread.readStatus();
//        System.out.println(JSON.toJSONString(melsecCrnThread.crnProtocol));
        SteSlave slave = new SteSlave();
        slave.setId(1);
        slave.setIp("192.168.3.39");
        slave.setPort(5015);
        SteThread thread = new SteThread(slave);
        thread.connect();
        thread.readStatus();
        System.out.println(JSON.toJSONString(thread.steProtocol));
        // 1.入库 源和目标都发
//        CrnCommand command = new CrnCommand();
//        command.setCrnNo(1); // 堆垛机编号
//        command.setTaskNo((short) 0); // 工作号
//        command.setAckFinish((short) 0);  // 任务完成确认位
//        command.setTaskMode(CrnTaskModeType.PAKIN); // 任务模式
//        command.setSourcePosX((short) 1);     // 源库位排
//        command.setSourcePosY((short) 0);     // 源库位列
//        command.setSourcePosZ((short) 1);     // 源库位层
//        command.setDestinationPosX((short) 2);     // 目标库位排
//        command.setDestinationPosY((short) 3);     // 目标库位列
//        command.setDestinationPosZ((short) 1);     // 目标库位层
//        crnThread.write(command);
        // 任务作业
        SteCommand command = new SteCommand();
        command.setSteNo(1); // 堆垛机编号
        command.setTaskNo(new Random().nextInt(9000)); // 工作号
        command.setTaskMode(SteTaskModeType.IN_LEFT); // 任务模式
        thread.write(command);
        // 2.出库 源和目标都发
//        CrnCommand command = new CrnCommand();
//        command.setCrnNo(1); // 堆垛机编号
//        command.setTaskNo((short) 0); // 工作号
//        command.setAckFinish((short) 0);  // 任务完成确认位
//        command.setTaskMode(CrnTaskModeType.PAKOUT); // 任务模式
//        command.setSourcePosX((short) 2);     // 源库位排
//        command.setSourcePosY((short) 4);     // 源库位列
//        command.setSourcePosZ((short) 3);     // 源库位层
//        command.setDestinationPosX((short) 1);     // 目标库位排
//        command.setDestinationPosY((short) 0);     // 目标库位列
//        command.setDestinationPosZ((short) 1);     // 目标库位层
//        crnThread.write(command);
        // 任务完成
//        SteCommand command = new SteCommand();
//        command.setSteNo(1); // 堆垛机编号
//        command.setComplete(Boolean.TRUE); // 任务模式
//        thread.write(command);
        // 控制模式
//        SteCommand command = new SteCommand();
//        command.setControlMode((short) 1);
//        thread.write(command);
//        // 3.库位移转   源和目标都发 pass
//        CrnCommand command = new CrnCommand();
//        command.setCrnNo(slave.getId()); // 堆垛机编号
//        command.setTaskNo((short) 0); // 工作号
//        command.setAckFinish((short) 0);  // 任务完成确认位
//        command.setTaskMode(CrnTaskModeType.LOC_MOVE); // 任务模式:  库位移转
//        command.setSourcePosX((short)2);     // 源库位排
//        command.setSourcePosY((short)2);     // 源库位列
//        command.setSourcePosZ((short)3);     // 源库位层
//        command.setDestinationPosX((short)2);     // 目标库位排
//        command.setDestinationPosY((short)4);     // 目标库位列
//        command.setDestinationPosZ((short)4);     // 目标库位层
//        crnThread.write(command);
        // 复位信号
//        SteCommand command = new SteCommand();
//        command.setReset((short) 1);
//        thread.write(command);
        // 4.站位移转   源和目标都发
//        CrnCommand command = new CrnCommand();
//        command.setCrnNo(slave.getId()); // 堆垛机编号
//        command.setTaskNo((short) 0); // 工作号
//        command.setAckFinish((short) 0);  // 任务完成确认位
//        command.setTaskMode(CrnTaskModeType.SITE_MOVE); // 任务模式:  库位移转
//        command.setSourcePosX((short)1);     // 源库位排
//        command.setSourcePosY((short)0);     // 源库位列
//        command.setSourcePosZ((short)1);     // 源库位层
//        command.setDestinationPosX((short)2);     // 目标库位排
//        command.setDestinationPosY((short)0);     // 目标库位列
//        command.setDestinationPosZ((short)1);     // 目标库位层
//        crnThread.write(command);
//        // 5.回原点  不用发   pass
//        CrnCommand command = new CrnCommand();
//        command.setCrnNo(1); // 堆垛机编号
//        command.setTaskNo((short) 0); // 工作号
//        command.setAckFinish((short) 0);  // 任务完成确认位
//        command.setTaskMode(CrnTaskModeType.GO_ORIGIN); // 任务模式
//        command.setSourcePosX((short) 0);     // 源库位排
//        command.setSourcePosY((short) 0);     // 源库位列
//        command.setSourcePosZ((short) 0);     // 源库位层
//        command.setDestinationPosX((short) 0);     // 目标库位排
//        command.setDestinationPosY((short) 0);     // 目标库位列
//        command.setDestinationPosZ((short) 0);     // 目标库位层
//        crnThread.write(command);
        // 只有出现指定异常才进行复位
//        if (crnThread.crnProtocol.getCrnError2().leftTakeNoneErr
//                || crnThread.crnProtocol.getCrnError2().rightTakeNoneErr
//                || crnThread.crnProtocol.getCrnError2().leftPutLoadErr
//                || crnThread.crnProtocol.getCrnError2().rightPutLoadErr) {
//            CrnCommand command = new CrnCommand();
//            command.setCrnNo(1); // 堆垛机编号
//            command.setAckFinish((short) 1);  // 任务完成确认位
//            command.setTaskMode(CrnTaskModeType.NONE); // 任务模式
//            Thread.sleep(3000L);
//            crnThread.write(command);
//        }
        // 删除指令
//        SteCommand command = new SteCommand();
//        command.setDelete((short) 1);
//        thread.write(command);
    }