野心家
2025-05-23 d75bdc98e2bc456eecfa4003bf700cb701d52a9b
src/main/java/com/zy/core/thread/RgvThread.java
@@ -12,6 +12,7 @@
import com.zy.asrs.entity.BasRgvOpt;
import com.zy.asrs.service.BasRgvOptService;
import com.zy.asrs.service.BasRgvService;
import com.zy.asrs.service.DeviceErrorService;
import com.zy.asrs.utils.RouteUtils;
import com.zy.asrs.utils.TrackRangeUtils;
import com.zy.core.DevpThread;
@@ -66,6 +67,7 @@
    private boolean resetFlag2 = false;
    private boolean connectRgv = false;
    private boolean delRgvTask = false;
    public RgvThread(RgvSlave slave) {
        this.slave = slave;
@@ -84,17 +86,18 @@
            }
        }
        // 启动读数据线程
        // 启动线程自动重连
        new Thread(this::rgvConnect).start();
        // 启动读数据线程
        new Thread(this::readStatusRgv).start();
        // 启动任务下发线程
        new Thread(this::taskIssued).start();
        // 启动漫游线程
        new Thread(this::taskWalkIssued).start();
        new Thread(this::taskWalkIssued2).start();
//        new Thread(this::taskWalkIssued).start();
//        new Thread(this::taskWalkIssued2).start();
        // 启动任务完成线程
        new Thread(this::taskComplete).start();
@@ -112,7 +115,13 @@
                    }
                }
            } catch (Exception e) {
                log.error("RGV数据读取线程异常!!!" + e.getMessage());
                log.error("rgv连接失败!!! ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
                try{
                    DeviceErrorService deviceErrorService = SpringUtils.getBean(DeviceErrorService.class);
                    deviceErrorService.addDeviceError("rgv", slave.getId(), "rgv连接失败"+e.getMessage());
                } catch (Exception e2){
                    log.error("e2:"+e2.getMessage());
                }
                initRgv();
//                e.printStackTrace();
            }
@@ -122,12 +131,18 @@
    private void readStatusRgv() {
        while (true) {
            try {
                Thread.sleep(100);
                Thread.sleep(20);
                readStatus();
            } catch (Exception e) {
                log.error("RGV数据读取线程异常!!!" + e.getMessage());
                log.error("RGV数据读取线程异常!!! ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
                try{
                    DeviceErrorService deviceErrorService = SpringUtils.getBean(DeviceErrorService.class);
                    deviceErrorService.addDeviceError("rgv", slave.getId(), "RGV数据读取线程异常"+e.getMessage());
                } catch (Exception e2){
                    log.error("e2:"+e2.getMessage());
                }
                initRgv();
//                e.printStackTrace();
            }
@@ -142,14 +157,25 @@
    private void taskComplete() {
        while (true) {
            try {
                Thread.sleep(100);
                if (delRgvTask){
                    writeDelRgvTask();
                    delRgvTask = false;
                    continue;
                }
                Thread.sleep(40);
                OperateResultExOne<byte[]> result = siemensNet.Read("DB100.12", (short) 1);
                boolean[] status = siemensNet.getByteTransform().TransBool(result.Content, 0, 1);
                if (status[0]){
                    OperateResult result4 = siemensNet.Write("DB100.12.0", false);
                }
            } catch (Exception e) {
                log.error("RGV数据读取线程异常!!!" + e.getMessage());
                log.error("RGV数据任务下发复位线程异常!!! ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
                try{
                    DeviceErrorService deviceErrorService = SpringUtils.getBean(DeviceErrorService.class);
                    deviceErrorService.addDeviceError("rgv", slave.getId(), "RGV数据任务下发复位线程异常"+e.getMessage());
                } catch (Exception e2){
                    log.error("e2:"+e2.getMessage());
                }
                initRgv();
//                e.printStackTrace();
            }
@@ -201,7 +227,6 @@
                            taskProtocolCache.removeTaskProtocol(taskProtocol.getTaskNoDirection());
                            break;
                        } else {
                            Thread.sleep(100);
                            TaskProtocol issued = new TaskProtocol(taskProtocol,true);
                            write(issued);
                            taskProtocolCache.removeTaskProtocol(taskProtocol.getTaskNoDirection());
@@ -210,7 +235,13 @@
                    }
                }
            } catch (Exception e) {
                log.error("RGV取货任务下发线程异常!!!" + e.getMessage());
                log.error("RGV任务下发线程异常!!! ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
                try{
                    DeviceErrorService deviceErrorService = SpringUtils.getBean(DeviceErrorService.class);
                    deviceErrorService.addDeviceError("rgv", slave.getId(), "RGV任务下发线程异常"+e.getMessage());
                } catch (Exception e2){
                    log.error("e2:"+e2.getMessage());
                }
//                e.printStackTrace();
            }
        }
@@ -272,30 +303,56 @@
                    rgvProtocol = RgvStatusCache.getRgvStatus(slave.getId());
                    rgvTaskProtocol = RgvTaskCache.getRgvStatus(slave.getId());
                }
                if (rgvTaskProtocol.getAvoid() != 0) {
                    continue;
                }
                if (!rgvProtocol.getStatusType().equals(RgvStatusType.IDLE)){
                    continue;
                }
                if (rgvProtocol.getLoaded() == -1){
                    continue;
                }
                if (rgvTaskProtocol.getAvoid() != 0) {
                    if (rgvTaskProtocol.getAvoid() == 1) {
                        TaskProtocol issued = new TaskProtocol();
                        issued.setTaskNo(32222L);
                        issued.setTargetPosition(rgvTaskProtocol.getAvoidingTheDestination());
                        issued.setTaskStatus(1);
                        issued.setDirection(true);
                        write(issued);
                        rgvTaskProtocol.setAvoid(0);
                        Thread.sleep(200);
                        RgvTaskCache.updateRgvStatus(rgvTaskProtocol);
                    }
                    continue;
                }
                List<TaskProtocol> allTakeTaskProtocol = taskProtocolCache.getTakeOrPutTaskProtocol(rgvProtocol.getLoaded());
                for (TaskProtocol taskProtocol : allTakeTaskProtocol) {
                    if (taskProtocol.getIsRunning() == 1) {//准备下发
//                        RgvProtocol rgvProtocolOther = RgvStatusCache.getRgvStatus(slave.getOtherId());
                        //双车
                        if (rgvOtherStatusEnable()) {
                            //另一台车是否允许此台车执行
                            if (!otherRgvAvoid(taskProtocol.getTargetPosition())) {
                                continue;
                if (allTakeTaskProtocol.isEmpty()){
                    allTakeTaskProtocol = taskProtocolCache.getAllWalkTaskProtocol();
                    for (TaskProtocol taskProtocol : allTakeTaskProtocol) {
                        if (taskProtocol.getIsRunning() == 1) {//准备下发
                            // 双车
                            if (rgvOtherStatusEnable()) {
                                //另一台车是否允许此台车执行
                                if (!otherRgvAvoid(taskProtocol.getTargetPosition())) {
                                    continue;
                                }
                            }
                            if (taskProtocol.getTargetPosition()<=rgvProtocol.getRgvPos()+50
                                    && taskProtocol.getTargetPosition()>=rgvProtocol.getRgvPos()-50){
                                taskProtocolCache.removeTaskProtocol(taskProtocol.getTaskNoDirection());
                                break;
                            } else {
                                TaskProtocol issued = new TaskProtocol(taskProtocol,true);
                                write(issued);
                                taskProtocolCache.removeTaskProtocol(taskProtocol.getTaskNoDirection());
                                break;
                            }
                        }
                        if (taskProtocol.getTargetPosition()<=rgvProtocol.getRgvPos()+50
                                && taskProtocol.getTargetPosition()>=rgvProtocol.getRgvPos()-50){
                            Thread.sleep(100);
                    }
                } else {
                    for (TaskProtocol taskProtocol : allTakeTaskProtocol) {
                        if (taskProtocol.getIsRunning() == 1) {//准备下发
//                        RgvProtocol rgvProtocolOther = RgvStatusCache.getRgvStatus(slave.getOtherId());
                            if (taskProtocol.getTaskStatus()==3){
                                DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, taskProtocol.getTargetPositionStaNoPlcId());
                                StaProtocol staProtocol = devpThread.getStation().get(taskProtocol.getTargetPositionStaNo());
@@ -306,24 +363,55 @@
                                if (!staProtocol.isAutoing() || staProtocol.isLoading()
                                        || staProtocol.getWorkNo() != 0
                                ){
                                    System.out.println("<放货目标站>" + taskProtocol.getTargetPositionStaNo() + "<非自动或者有物或者存在工作号!!!>");
                                    Thread.sleep(500);
//                                    System.out.println("<放货目标站>" + taskProtocol.getTargetPositionStaNo() + "<非自动或者有物或者存在工作号!!!>");
//                                continue;
                                }
                            }
                            //双车
                            if (rgvOtherStatusEnable()) {
                                //另一台车是否允许此台车执行
                                if (!otherRgvAvoid(taskProtocol.getTargetPosition())) {
                                    continue;
                                }
                            }
                            TaskProtocol issued = new TaskProtocol(taskProtocol);
                            write(issued);
                            taskProtocolCache.removeTaskProtocol(taskProtocol.getTaskNoDirection());
                            break;
                        } else {
                            Thread.sleep(100);
                            TaskProtocol issued = new TaskProtocol(taskProtocol,true);
                            write(issued);
                            break;
                            if (taskProtocol.getTargetPosition()<=rgvProtocol.getRgvPos()+50
                                    && taskProtocol.getTargetPosition()>=rgvProtocol.getRgvPos()-50){
                                if (taskProtocol.getTaskStatus()==3){
                                    DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, taskProtocol.getTargetPositionStaNoPlcId());
                                    StaProtocol staProtocol = devpThread.getStation().get(taskProtocol.getTargetPositionStaNo());
                                    if (staProtocol == null ) {
                                        continue;
                                    }
                                    // 判断是否满足入库条件
                                    if (!staProtocol.isAutoing() || staProtocol.isLoading()
                                            || staProtocol.getWorkNo() != 0
                                    ){
                                        Thread.sleep(500);
//                                    System.out.println("<放货目标站>" + taskProtocol.getTargetPositionStaNo() + "<非自动或者有物或者存在工作号!!!>");
                                        continue;
                                    }
                                }
                                TaskProtocol issued = new TaskProtocol(taskProtocol);
                                write(issued);
                                taskProtocolCache.removeTaskProtocol(taskProtocol.getTaskNoDirection());
                                break;
                            } else {
                                TaskProtocol issued = new TaskProtocol(taskProtocol,true);
                                write(issued);
                                break;
                            }
                        }
                    }
                }
            } catch (Exception e) {
                log.error("RGV取货任务下发线程异常!!!" + e.getMessage());
                log.error("RGV任务下发线程异常!!! ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
                try{
                    DeviceErrorService deviceErrorService = SpringUtils.getBean(DeviceErrorService.class);
                    deviceErrorService.addDeviceError("rgv", slave.getId(), "RGV任务下发线程异常"+e.getMessage());
                } catch (Exception e2){
                    log.error("e2:"+e2.getMessage());
                }
//                e.printStackTrace();
            }
        }
@@ -380,12 +468,18 @@
            if (rgvProtocolOther.getStatusType().equals(RgvStatusType.IDLE)) {
                if ((rgvProtocolOther.getRgvPos() - rgvProtocolOther.getCarBodyJiaoMing())
                        - (targetPosition + rgvProtocol.getCarBodyKunPeng())
                        > avoidDistance) {//无需避让
                        > avoidDistance - 50) {//无需避让
                    return true;
                } else {
                    long avoid = targetPosition + rgvProtocol.getCarBodyKunPeng() + avoidDistance + rgvProtocolOther.getCarBodyJiaoMing();
                    if (!new TrackRangeUtils().avoidRange(avoid, avoidRange[0])) {
                        log.error("行走超出范围!!!任务异常  联系管理员!!!");
                        log.error("RGV行走超出范围!!! ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
                        try{
                            DeviceErrorService deviceErrorService = SpringUtils.getBean(DeviceErrorService.class);
                            deviceErrorService.addDeviceError("rgv", slave.getId(), "RGV行走超出范围");
                        } catch (Exception e2){
                            log.error("e2:"+e2.getMessage());
                        }
                        return false;
                    }
                    long avoidAbs = Math.abs(avoid - rgvProtocolOther.getRgvPos());
@@ -395,17 +489,23 @@
                    rgvTaskProtocolOther.setAvoid(1);
                    rgvTaskProtocolOther.setAvoidingTheDestination(avoid);
                    RgvTaskCache.updateRgvStatus(rgvTaskProtocolOther);
                    return true;
                    return false;
                }
            } else if (rgvProtocolOther.getStatusType().equals(RgvStatusType.ROAM)) {
                if ((rgvProtocolOther.getRgvPosDestination() - rgvProtocolOther.getCarBodyJiaoMing())
                        - (targetPosition + rgvProtocol.getCarBodyKunPeng())
                        > avoidDistance) {//无需避让
                        > avoidDistance - 50) {//无需避让
                    return true;
                } else {
                    long avoid = targetPosition + rgvProtocol.getCarBodyKunPeng() + avoidDistance + rgvProtocolOther.getCarBodyJiaoMing();
                    if (!new TrackRangeUtils().avoidRange(avoid, avoidRange[0])) {
                        log.error("行走超出范围!!!任务异常  联系管理员!!!");
                        log.error("RGV行走超出范围!!! ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
                        try{
                            DeviceErrorService deviceErrorService = SpringUtils.getBean(DeviceErrorService.class);
                            deviceErrorService.addDeviceError("rgv", slave.getId(), "RGV行走超出范围");
                        } catch (Exception e2){
                            log.error("e2:"+e2.getMessage());
                        }
                        return false;
                    }
                    long avoidAbs = Math.abs(avoid - rgvProtocolOther.getRgvPos());
@@ -415,18 +515,24 @@
                    rgvTaskProtocolOther.setAvoid(1);
                    rgvTaskProtocolOther.setAvoidingTheDestination(avoid);
                    RgvTaskCache.updateRgvStatus(rgvTaskProtocolOther);
                    return true;
                    return false;
                }
            } else if (rgvProtocolOther.getStatusType().equals(RgvStatusType.WORKING)) {
                if ((rgvProtocolOther.getRgvPosDestination() - rgvProtocolOther.getCarBodyJiaoMing())
                        - (targetPosition + rgvProtocol.getCarBodyKunPeng())
                        > avoidDistance) {//无需避让
                        > avoidDistance - 50) {//无需避让
                    return true;
                } else {
                    if (rgvProtocolOther.getRgvPosDestination() >= rgvProtocolOther.getRgvPos()-50) {
                        long avoid = rgvProtocolOther.getRgvPos() - rgvProtocolOther.getCarBodyJiaoMing() - avoidDistance - rgvProtocol.getCarBodyKunPeng();
                        if (!new TrackRangeUtils().avoidRange(avoid, avoidRange[1])) {
                            log.error("行走超出范围!!!任务异常  联系管理员!!!");
                            log.error("RGV行走超出范围!!! ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
                            try{
                                DeviceErrorService deviceErrorService = SpringUtils.getBean(DeviceErrorService.class);
                                deviceErrorService.addDeviceError("rgv", slave.getId(), "RGV行走超出范围");
                            } catch (Exception e2){
                                log.error("e2:"+e2.getMessage());
                            }
                            return false;
                        }
                        long avoidAbs = Math.abs(avoid - rgvProtocol.getRgvPos());
@@ -443,7 +549,7 @@
            } else {
                if ((rgvProtocolOther.getRgvPosDestinationOrPos(true) - rgvProtocolOther.getCarBodyJiaoMing())
                        - (targetPosition + rgvProtocol.getCarBodyKunPeng())
                        > avoidDistance) {//无需避让
                        > avoidDistance - 50) {//无需避让
                    return true;
                }
            }
@@ -451,12 +557,18 @@
            if (rgvProtocolOther.getStatusType().equals(RgvStatusType.IDLE)) {
                if ((targetPosition - rgvProtocol.getCarBodyJiaoMing())
                        - (rgvProtocolOther.getRgvPos() + rgvProtocolOther.getCarBodyKunPeng())
                        > avoidDistance) {//无需避让
                        > avoidDistance - 50) {//无需避让
                    return true;
                } else {
                    long avoid = targetPosition - rgvProtocol.getCarBodyJiaoMing() - avoidDistance - rgvProtocolOther.getCarBodyKunPeng();
                    if (!new TrackRangeUtils().avoidRange(avoid, avoidRange[1])) {
                        log.error("行走超出范围!!!任务异常  联系管理员!!!");
                        log.error("RGV行走超出范围!!! ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
                        try{
                            DeviceErrorService deviceErrorService = SpringUtils.getBean(DeviceErrorService.class);
                            deviceErrorService.addDeviceError("rgv", slave.getId(), "RGV行走超出范围");
                        } catch (Exception e2){
                            log.error("e2:"+e2.getMessage());
                        }
                        return false;
                    }
                    long avoidAbs = Math.abs(avoid - rgvProtocolOther.getRgvPos());
@@ -466,17 +578,23 @@
                    rgvTaskProtocolOther.setAvoid(1);
                    rgvTaskProtocolOther.setAvoidingTheDestination(avoid);
                    RgvTaskCache.updateRgvStatus(rgvTaskProtocolOther);
                    return true;
                    return false;
                }
            } else if (rgvProtocolOther.getStatusType().equals(RgvStatusType.ROAM)) {
                if ((targetPosition - rgvProtocol.getCarBodyJiaoMing())
                        - (rgvProtocolOther.getRgvPosDestination() + rgvProtocolOther.getCarBodyKunPeng())
                        > avoidDistance) {//无需避让
                        > avoidDistance - 50) {//无需避让
                    return true;
                } else {
                    long avoid = targetPosition - rgvProtocol.getCarBodyJiaoMing() - avoidDistance - rgvProtocolOther.getCarBodyKunPeng();
                    if (!new TrackRangeUtils().avoidRange(avoid, avoidRange[1])) {
                        log.error("行走超出范围!!!任务异常  联系管理员!!!");
                        log.error("RGV行走超出范围!!! ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
                        try{
                            DeviceErrorService deviceErrorService = SpringUtils.getBean(DeviceErrorService.class);
                            deviceErrorService.addDeviceError("rgv", slave.getId(), "RGV行走超出范围");
                        } catch (Exception e2){
                            log.error("e2:"+e2.getMessage());
                        }
                        return false;
                    }
                    long avoidAbs = Math.abs(avoid - rgvProtocolOther.getRgvPos());
@@ -486,19 +604,25 @@
                    rgvTaskProtocolOther.setAvoid(1);
                    rgvTaskProtocolOther.setAvoidingTheDestination(avoid);
                    RgvTaskCache.updateRgvStatus(rgvTaskProtocolOther);
                    return true;
                    return false;
                }
            } else if (rgvProtocolOther.getStatusType().equals(RgvStatusType.WORKING)) {
                if ((targetPosition - rgvProtocol.getCarBodyJiaoMing())
                        - (rgvProtocolOther.getRgvPosDestination() + rgvProtocolOther.getCarBodyKunPeng())
                        > avoidDistance) {//无需避让
                        > avoidDistance-50) {//无需避让
                    return true;
                } else {
                    if (rgvProtocolOther.getRgvPosDestination() <= rgvProtocolOther.getRgvPos() + 50) {
                        long avoid = rgvProtocolOther.getRgvPos() + rgvProtocolOther.getCarBodyKunPeng() + avoidDistance + rgvProtocol.getCarBodyJiaoMing();
                        if (!new TrackRangeUtils().avoidRange(avoid, avoidRange[0])) {
                            log.error("行走超出范围!!!任务异常  联系管理员!!!");
                            log.error("RGV行走超出范围!!! ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
                            try{
                                DeviceErrorService deviceErrorService = SpringUtils.getBean(DeviceErrorService.class);
                                deviceErrorService.addDeviceError("rgv", slave.getId(), "RGV行走超出范围");
                            } catch (Exception e2){
                                log.error("e2:"+e2.getMessage());
                            }
                            return false;
                        }
                        long avoidAbs = Math.abs(avoid - rgvProtocol.getRgvPos());
@@ -515,7 +639,7 @@
            } else {
                if ((rgvProtocolOther.getRgvPosDestinationOrPos(false) - rgvProtocolOther.getCarBodyJiaoMing())
                        - (targetPosition + rgvProtocol.getCarBodyKunPeng())
                        > avoidDistance) {//无需避让
                        > avoidDistance - 50) {//无需避让
                    return true;
                }
            }
@@ -551,7 +675,13 @@
                rgvProtocol.setStatusEnable(false);
            }
        } catch (Exception e) {
            log.error("RGV异常!!!" + e.getMessage());
            log.error("RGV异常!!! ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
            try{
                DeviceErrorService deviceErrorService = SpringUtils.getBean(DeviceErrorService.class);
                deviceErrorService.addDeviceError("rgv", slave.getId(), "RGV异常"+e.getMessage());
            } catch (Exception e2){
                log.error("e2:"+e2.getMessage());
            }
            rgvProtocol.setStatusEnable(true);
        }
@@ -584,6 +714,12 @@
//            OutputQueue.RGV.offer(MessageFormat.format("【{0}】RGV 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("RGV plc连接失败!!! ===>> [id:{}] [ip:{}] [port:{}] [rack:{}] [slot:{}]", slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot());
            try{
                DeviceErrorService deviceErrorService = SpringUtils.getBean(DeviceErrorService.class);
                deviceErrorService.addDeviceError("rgv", slave.getId(), "RGVplc连接失败");
            } catch (Exception e2){
                log.error("e2:"+e2.getMessage());
            }
        }
        initRgv();
//        siemensNet.ConnectClose();
@@ -595,7 +731,7 @@
     */
    private void readStatus() {
        try {
            OperateResultExOne<byte[]> result = siemensNet.Read("DB101.0", (short) 19);
            OperateResultExOne<byte[]> result = siemensNet.Read("DB101.0", (short) 20);
            if (result.IsSuccess) {
                // 构建设备状态对象
                RgvProtocol rgvProtocol = RgvStatusCache.getRgvStatus(slave.getId());
@@ -622,8 +758,14 @@
//                rgvProtocol.setxDuration(siemensNet.getByteTransform().TransInt16(result.Content, 48));
//                OperateResultExOne<byte[]> result11 = siemensNet.Read("DB100.12", (short) 1);
                boolean[] status = siemensNet.getByteTransform().TransBool(result.Content, 18, 1);
                boolean[] status = siemensNet.getByteTransform().TransBool(result.Content, 18, 2);
                rgvProtocol.setLoaded(status[0]? (short)1:(short)0);
                rgvProtocol.setErr1(status[8]);
                rgvProtocol.setErr2(status[9]);
                rgvProtocol.setErr3(status[10]);
                rgvProtocol.setErr4(status[11]);
                rgvProtocol.setErr5(status[12]);
                rgvProtocol.setErr6(status[13]);
                OutputQueue.RGV.offer(MessageFormat.format("【{0}】[id:{1}] <<<<< 实时数据更新成功", DateUtils.convert(new Date()), slave.getId()));
//                // 工位1复位信号
@@ -652,6 +794,13 @@
                    basRgv.setRgvSts((int) rgvProtocol.getMode());
                    if (!basRgvService.updateById(rgvProtocol.toSqlModel(basRgv))) {
                        log.error("RGV plc数据库更新失败 ===>> [id:{}] [ip:{}] [port:{}] [rack:{}] [slot:{}]", slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot());
                        try{
                            DeviceErrorService deviceErrorService = SpringUtils.getBean(DeviceErrorService.class);
                            deviceErrorService.addDeviceError("rgv", slave.getId(), "RGV plc数据库更新失败");
                        } catch (Exception e2){
                            log.error("e2:"+e2.getMessage());
                        }
                    }
                } catch (Exception ignore) {
@@ -666,11 +815,25 @@
                connectRgv = false;
//                OutputQueue.RGV.offer(MessageFormat.format("【{0}】读取RGV 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("读取RGV plc状态信息失败 ===>> [id:{}] [ip:{}] [port:{}] [rack:{}] [slot:{}]", slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot());
                try{
                    DeviceErrorService deviceErrorService = SpringUtils.getBean(DeviceErrorService.class);
                    deviceErrorService.addDeviceError("rgv", slave.getId(), "读取RGV plc状态信息失败");
                } catch (Exception e2){
                    log.error("e2:"+e2.getMessage());
                }
            }
        } catch (Exception e) {
//            e.printStackTrace();
//            OutputQueue.RGV.offer(MessageFormat.format("【{0}】读取RGV plc状态信息失败 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort()));
            log.error("读取RGV plc状态信息失败 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
            try{
                DeviceErrorService deviceErrorService = SpringUtils.getBean(DeviceErrorService.class);
                deviceErrorService.addDeviceError("rgv", slave.getId(), "读取RGV plc状态信息失败");
            } catch (Exception e2){
                log.error("e2:"+e2.getMessage());
            }
            initRgv();
        }
    }
@@ -680,7 +843,14 @@
     */
    private boolean write(TaskProtocol taskProtocol) throws InterruptedException {
        if (null == taskProtocol) {
            log.error("RGV写入命令为空");
            log.error("RGV写入命令为空 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
            try{
                DeviceErrorService deviceErrorService = SpringUtils.getBean(DeviceErrorService.class);
                deviceErrorService.addDeviceError("rgv", slave.getId(), "RGV写入命令为空");
            } catch (Exception e2){
                log.error("e2:"+e2.getMessage());
            }
            return false;
        }
//        convertRow(command);
@@ -732,6 +902,14 @@
            Thread.sleep(200);
            this.readStatus();
            log.info("RGV 命令下发[id:{}] >>>>> {}", slave.getId(), JSON.toJSON(taskProtocol));
            log.error("RGV 命令下发 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
            try{
                DeviceErrorService deviceErrorService = SpringUtils.getBean(DeviceErrorService.class);
                deviceErrorService.addDeviceError("rgv", slave.getId(), "RGV 命令下发"+JSON.toJSON(taskProtocol));
            } catch (Exception e2){
                log.error("e2:"+e2.getMessage());
            }
            OutputQueue.RGV.offer(MessageFormat.format("【{0}】[id:{1}] >>>>> 命令下发: {2}", DateUtils.convert(new Date()), slave.getId(), JSON.toJSON(taskProtocol)));
            return true;
        } else {
@@ -741,6 +919,53 @@
        }
    }
    private boolean writeDelRgvTask() throws InterruptedException {
//
        OperateResult result = siemensNet.Write("DB100.12.0", false);
        OperateResult result0 = siemensNet.Write("DB100.0", (int) 0);
        OperateResult result1 = siemensNet.Write("DB100.4", (short) 0);
        OperateResult result2 = siemensNet.Write("DB100.6", (int) 0);
        OperateResult result3 = siemensNet.Write("DB100.10", (short) 0); // 执行方向(面朝轨道 定位值左小右大)    true:左   false:右
        try {
            // 日志记录
            BasRgvOptService bean = SpringUtils.getBean(BasRgvOptService.class);
            BasRgvOpt basRgvOpt = new BasRgvOpt(
                    0,
                    0,
                    slave.getId(),
                    new Date(),
                    String.valueOf(0),
                    null,
                    null,
                    null,
                    result.IsSuccess ? 1 : 0,
                    null,
                    new Date(),
                    null
            );
            bean.insert(basRgvOpt);
        } catch (Exception ignore) {
        }
        if (result != null && result.IsSuccess) {
            Thread.sleep(200);
            this.readStatus();
            log.info("RGV 命令下发[id:{}] >>>>> {}", slave.getId(), JSON.toJSON("null"));
            OutputQueue.RGV.offer(MessageFormat.format("【{0}】[id:{1}] >>>>> 命令下发: {2}", DateUtils.convert(new Date()), slave.getId(), JSON.toJSON("null")));
            return true;
        } else {
            OutputQueue.RGV.offer(MessageFormat.format("【{0}】写入RGV plc数据失败 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort()));
            log.error("写入RGV plc数据失败 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
            return false;
        }
    }
    public void setDelRgvTask() {
        delRgvTask = true;
    }
    @Override
    public void close() {
        siemensNet.ConnectClose();