From c6ac4fcda65f2033dbf4d0cfb57fc32cdd3eee2f Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <t1341870251@163.com>
Date: 星期三, 30 十一月 2022 14:42:09 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/core/thread/SteThread.java |  416 +++++++++++++++++++++++++++++------------------------------
 1 files changed, 206 insertions(+), 210 deletions(-)

diff --git a/src/main/java/com/zy/core/thread/SteThread.java b/src/main/java/com/zy/core/thread/SteThread.java
index c7af558..4adf992 100644
--- a/src/main/java/com/zy/core/thread/SteThread.java
+++ b/src/main/java/com/zy/core/thread/SteThread.java
@@ -5,16 +5,19 @@
 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.core.exception.CoolException;
 import com.zy.asrs.entity.BasSte;
+import com.zy.asrs.entity.BasSteOpt;
 import com.zy.asrs.service.BasSteOptService;
 import com.zy.asrs.service.BasSteService;
 import com.zy.core.ThreadHandler;
 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.model.SteSlave;
 import com.zy.core.model.Task;
 import com.zy.core.model.command.SteCommand;
@@ -39,10 +42,6 @@
     private SteProtocol steProtocol;
     private short heartBeatVal = 1;
     private boolean resetFlag = false;
-
-    private Integer lastRow;
-    private Integer lastBay;
-    private Integer lastLev;
 
     public SteThread(SteSlave slave) {
         this.slave = slave;
@@ -88,23 +87,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((short) 0);
+        steProtocol.setExecute(false);
+        steProtocol.setWaiting(false);
     }
 
     @Override
@@ -117,10 +105,10 @@
         OperateResult connect = siemensS7Net.ConnectServer();
         if(connect.IsSuccess){
             result = true;
-            OutputQueue.CRN.offer(MessageFormat.format( "銆恵0}銆戠┛姊溅plc杩炴帴鎴愬姛 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort()));
+            OutputQueue.STE.offer(MessageFormat.format( "銆恵0}銆戠┛姊溅plc杩炴帴鎴愬姛 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort()));
             log.info("绌挎杞lc杩炴帴鎴愬姛 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
         } else {
-            OutputQueue.CRN.offer(MessageFormat.format("銆恵0}銆戠┛姊溅plc杩炴帴澶辫触锛侊紒锛� ===>> [id:{1}] [ip:{2}] [port:{3}] ", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort()));
+            OutputQueue.STE.offer(MessageFormat.format("銆恵0}銆戠┛姊溅plc杩炴帴澶辫触锛侊紒锛� ===>> [id:{1}] [ip:{2}] [port:{3}] ", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort()));
             log.error("绌挎杞lc杩炴帴澶辫触锛侊紒锛� ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
             initSte();
         }
@@ -133,46 +121,62 @@
      */
     private void readStatus(){
         try {
-            OperateResultExOne<byte[]> result = siemensS7Net.Read("DB4", (short) 70);
+            OperateResultExOne<byte[]> result = siemensS7Net.Read("V800", (short) 70);
             if (result.IsSuccess) {
                 if (null == steProtocol) {
                     steProtocol = new SteProtocol();
+                    steProtocol.setSteNo(slave.getId().shortValue());
                 }
-                steProtocol.setSteNo(siemensS7Net.getByteTransform().TransInt16(result.Content, 0));
+//                steProtocol.setSteNo(siemensS7Net.getByteTransform().TransInt16(result.Content, 0));
                 steProtocol.setMode(siemensS7Net.getByteTransform().TransInt16(result.Content, 2));
                 steProtocol.setStatus(siemensS7Net.getByteTransform().TransInt16(result.Content, 4));
-//                steProtocol.setExecute();
-//                steProtocol.setWaiting();
-                steProtocol.setAlarm(siemensS7Net.getByteTransform().TransInt32(result.Content, 6));
-                steProtocol.setAlarm0(siemensS7Net.getByteTransform().TransInt32(result.Content, 10));
-                steProtocol.setCharge(siemensS7Net.getByteTransform().TransInt16(result.Content, 14));
+                OperateResultExOne<Boolean> executeRes = siemensS7Net.ReadBool("V2001.0");
+                if (executeRes.IsSuccess) {
+                    steProtocol.setExecute(executeRes.Content);
+                }
+                OperateResultExOne<Boolean> waitingRes = siemensS7Net.ReadBool("V2001.1");
+                if (waitingRes.IsSuccess) {
+                    steProtocol.setWaiting(waitingRes.Content);
+                }
+                OperateResultExOne<Boolean> inEmptyRes = siemensS7Net.ReadBool("V2001.2");
+                if (inEmptyRes.IsSuccess) {
+                    steProtocol.setInEmpty(inEmptyRes.Content);
+                }
+                OperateResultExOne<Boolean> outEmptyRes = siemensS7Net.ReadBool("V2001.3");
+                if (outEmptyRes.IsSuccess) {
+                    steProtocol.setOutEmpty(outEmptyRes.Content);
+                }
+                steProtocol.setAlarm(siemensS7Net.getByteTransform().TransInt16(result.Content, 6));
+                steProtocol.setAlarm0(siemensS7Net.getByteTransform().TransInt16(result.Content, 8));
+                steProtocol.setCharge(siemensS7Net.getByteTransform().TransSingle(result.Content, 10));
 //                steProtocol.setFullCharge();
 //                steProtocol.setLowCharge();
-                steProtocol.setFeed(siemensS7Net.getByteTransform().TransInt16(result.Content, 16));
-                steProtocol.setLoca(siemensS7Net.getByteTransform().TransInt16(result.Content, 18));
+                steProtocol.setFeed(siemensS7Net.getByteTransform().TransInt16(result.Content, 14));
+                steProtocol.setLoca(siemensS7Net.getByteTransform().TransInt16(result.Content, 16));
 //                steProtocol.setCloser();
 //                steProtocol.setSpeed();
-                steProtocol.setPos(siemensS7Net.getByteTransform().TransInt16(result.Content, 28));
-                steProtocol.setLoad(siemensS7Net.getByteTransform().TransInt16(result.Content, 30));
-                steProtocol.setTrack(siemensS7Net.getByteTransform().TransInt16(result.Content, 32));
-                steProtocol.setTaskNo(siemensS7Net.getByteTransform().TransInt32(result.Content, 38));
-                steProtocol.setTaskType(siemensS7Net.getByteTransform().TransInt16(result.Content, 42));
-                steProtocol.setRow(siemensS7Net.getByteTransform().TransInt16(result.Content, 44));
-                steProtocol.setBay(siemensS7Net.getByteTransform().TransInt16(result.Content, 46));
-                steProtocol.setLev(siemensS7Net.getByteTransform().TransInt16(result.Content, 48));
+                steProtocol.setPos(siemensS7Net.getByteTransform().TransInt16(result.Content, 18));
+                steProtocol.setLoad(siemensS7Net.getByteTransform().TransInt16(result.Content, 20));
+                steProtocol.setTrack(siemensS7Net.getByteTransform().TransInt16(result.Content, 22));
+                steProtocol.setTaskNo(siemensS7Net.getByteTransform().TransInt16(result.Content, 24));
+                steProtocol.setTaskType(siemensS7Net.getByteTransform().TransInt16(result.Content, 28));
+                steProtocol.setRow(siemensS7Net.getByteTransform().TransInt16(result.Content, 30));
+                steProtocol.setBay(siemensS7Net.getByteTransform().TransInt16(result.Content, 32));
+                steProtocol.setLev(siemensS7Net.getByteTransform().TransInt16(result.Content, 34));
 
-                steProtocol.setHisTaskNo(siemensS7Net.getByteTransform().TransInt32(result.Content, 58));
-                steProtocol.setHisTaskStatus(siemensS7Net.getByteTransform().TransInt16(result.Content, 62));
-                steProtocol.setCheckQty(siemensS7Net.getByteTransform().TransInt16(result.Content, 64));
-                steProtocol.setReady(siemensS7Net.getByteTransform().TransInt16(result.Content, 66));
-                steProtocol.setChargeNo(siemensS7Net.getByteTransform().TransInt16(result.Content, 68));
+//                steProtocol.setHisTaskNo(siemensS7Net.getByteTransform().TransInt32(result.Content, 58));
+//                steProtocol.setHisTaskStatus(siemensS7Net.getByteTransform().TransInt16(result.Content, 62));
+//                steProtocol.setCheckQty(siemensS7Net.getByteTransform().TransInt16(result.Content, 64));
+                steProtocol.setReady(siemensS7Net.getByteTransform().TransInt16(result.Content, 36));
+//                steProtocol.setChargeNo(siemensS7Net.getByteTransform().TransInt16(result.Content, 68));
 
-                steProtocol.setHeart(siemensS7Net.getByteTransform().TransInt16(result.Content, 72));
-                steProtocol.setCrnStopRun(siemensS7Net.getByteTransform().TransInt16(result.Content, 74));
-                steProtocol.setCrnStopFork(siemensS7Net.getByteTransform().TransInt16(result.Content, 76));
-                steProtocol.setCrnAllowRun(siemensS7Net.getByteTransform().TransInt16(result.Content, 78));
+//                steProtocol.setHeart(siemensS7Net.getByteTransform().TransInt16(result.Content, 72));
+                steProtocol.setCrnStopRun(siemensS7Net.getByteTransform().TransInt16(result.Content, 38));
+                steProtocol.setCrnStopFork(siemensS7Net.getByteTransform().TransInt16(result.Content, 40));
+                steProtocol.setCrnAllowRun(siemensS7Net.getByteTransform().TransInt16(result.Content, 42));
+                steProtocol.setChargeStatus(siemensS7Net.getByteTransform().TransInt16(result.Content, 44));
 
-                OutputQueue.CRN.offer(MessageFormat.format("銆恵0}銆慬id:{1}] <<<<< 瀹炴椂鏁版嵁鏇存柊鎴愬姛",DateUtils.convert(new Date()), slave.getId()));
+                OutputQueue.STE.offer(MessageFormat.format("銆恵0}銆慬id:{1}] <<<<< 瀹炴椂鏁版嵁鏇存柊鎴愬姛",DateUtils.convert(new Date()), slave.getId()));
 
                 // 澶嶄綅淇″彿
                 if (steProtocol.getWaiting()) {
@@ -189,6 +193,12 @@
                 // 鏍规嵁瀹炴椂淇℃伅鏇存柊鏁版嵁搴�
                 BasSteService service = SpringUtils.getBean(BasSteService.class);
                 if (null != service) {
+                    // 鍚屾pakMk
+                    BasSte one = service.selectById(slave.getId());
+                    if (one != null) {
+                        steProtocol.setPakMk(one.getPakMk());
+                    }
+
                     BasSte basSte = new BasSte();
                     basSte.setSteNo(slave.getId());
                     if (!service.updateById(steProtocol.toSqlModel(basSte))){
@@ -197,13 +207,13 @@
 
                 }
             } else {
-                OutputQueue.CRN.offer(MessageFormat.format("銆恵0}銆憑1}绌挎杞lc鐘舵�佷俊鎭け璐�",DateUtils.convert(new Date()), slave.getId()));
+                OutputQueue.STE.offer(MessageFormat.format("銆恵0}銆憑1}绌挎杞lc鐘舵�佷俊鎭け璐�",DateUtils.convert(new Date()), slave.getId()));
                 throw new CoolException(MessageFormat.format( "绌挎杞lc鐘舵�佷俊鎭け璐� ===>> [id:{0}] [ip:{1}] [port:{2}]", slave.getId(), slave.getIp(), slave.getPort()));
             }
         } catch (Exception e) {
-            e.printStackTrace();
-            OutputQueue.CRN.offer(MessageFormat.format("銆恵0}銆戣鍙栫┛姊溅plc鐘舵�佷俊鎭け璐� ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort()));
-            log.error("璇诲彇绌挎杞lc鐘舵�佷俊鎭け璐� ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
+//            e.printStackTrace();
+            OutputQueue.STE.offer(MessageFormat.format("銆恵0}銆戣鍙栫┛姊溅plc鐘舵�佷俊鎭け璐� ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort()));
+//            log.error("璇诲彇绌挎杞lc鐘舵�佷俊鎭け璐� ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
             initSte();
         }
 
@@ -221,103 +231,135 @@
         OperateResult result = null;
         // 寮�濮嬩换鍔�
         if (!command.getComplete()) {
-            OperateResult result0 = siemensS7Net.Write("D0", command.getTaskNo());
-            short[] array = new short[10];
-            array[0] = command.getTaskMode();
-//            array[1] = command.getTaskNo();
-//            array[2] = command.getTaskMode();
-//            array[3] = command.getSourcePosX();
-//        array[4] = command.getSourcePosY();
-//        array[5] = command.getSourcePosZ();
-//        array[6] = command.getDestinationPosX();
-//        array[7] = command.getDestinationPosY();
-//        array[8] = command.getDestinationPosZ();
-//        array[9] = command.getCommand();
-            OperateResult result1 = siemensS7Net.Write("D0", array);
-            // 纭寮�濮嬩换鍔�
-            if (result0.IsSuccess) {
-                result = siemensS7Net.Write("D0", true);
+            // 1.浠诲姟鍙�
+            OperateResult result0 = siemensS7Net.Write("V998", command.getTaskNo().shortValue());
+            try {
+                Thread.sleep(200);
+            } catch (InterruptedException e) {
+                e.printStackTrace();
             }
+            // 浣滀笟
+            if (command.getTaskMode() != 0) {
+                // 2.浣滀笟
+                OperateResult result1 = siemensS7Net.Write("V1000", command.getTaskMode());
+                // 3.纭寮�濮嬩换鍔�
+                if (result0.IsSuccess && result1.IsSuccess) {
+                    result = siemensS7Net.Write("V2000.0", true);
+                }
+
+            // 鍏朵粬鎸囦护
+            } else {
+                // 鎺у埗妯″紡
+                if (command.getControlMode() != null) {
+                    result =  siemensS7Net.Write("V1010", command.getControlMode());
+                // 澶嶄綅淇″彿
+                } else if (command.getReset() != null) {
+                    result =  siemensS7Net.Write("V2000.2", command.getReset());
+                // 鍒犻櫎鎸囦护
+                } else if (command.getDelete() != null) {
+                    result =  siemensS7Net.Write("V2000.3", command.getDelete());
+                // 鏃犳晥鎸囦护
+                } else if (command.getRun() != null) {
+                    result =  siemensS7Net.Write("V1016", command.getRun());
+                    // 鏃犳晥鎸囦护
+                }else {
+                    return false;
+                }
+            }
+
         // 浠诲姟瀹屾垚
         } else {
-            result = siemensS7Net.Write("D0", true);
+            siemensS7Net.Write("V998", (short) 0);
+            siemensS7Net.Write("V1000", (short) 0);
+            result = siemensS7Net.Write("V2000.1", true);
         }
 
         try {
             // 鏃ュ織璁板綍
-            BasSteOptService bean = SpringUtils.getBean(BasSteOptService.class);
-//            BasSteOpt basSteOpt = new BasSteOpt(
-//                    command.getTaskNo(),    // 浠诲姟鍙�
-//                    command.getSteNo(),    // 绌挎杞闈炵┖]
-//                    new Date(),    // 涓嬪彂鏃堕棿
-//                    command.getTaskModeType().desc,    // 妯″紡
-//                    command.getSourcePosX().intValue(),    // 婧愭帓
-//                    command.getSourcePosY().intValue(),    // 婧愬垪
-//                    command.getSourcePosZ().intValue(),    // 婧愬眰
-//                    null,    // 婧愮珯
-//                    command.getDestinationPosX().intValue(),    // 鐩爣鎺�
-//                    command.getDestinationPosY().intValue(),    // 鐩爣鍒�
-//                    command.getDestinationPosZ().intValue(),    // 鐩爣灞�
-//                    null,    // 鐩爣绔�
-//                    null,    // 鍝嶅簲缁撴灉
-//                    null,    // 淇敼鏃堕棿
-//                    null    // 淇敼浜哄憳
-//            );
-//            bean.insert(basSteOpt);
+            if (!command.getComplete() && command.getTaskMode() != 0) {
+                BasSteOptService bean = SpringUtils.getBean(BasSteOptService.class);
+                if (null != bean) {
+                    BasSteOpt basSteOpt = new BasSteOpt(
+                            command.getTaskNo(),    // 浠诲姟鍙�
+                            command.getSteNo(),    // 绌挎杞�
+                            new Date(),    // 涓嬪彂鏃堕棿
+                            command.getTaskModeType().desc,    // 浣滀笟
+                            null,    // 婧愭帓
+                            null,    // 婧愬垪
+                            null,    // 婧愬眰
+                            null,    // 婧愮珯
+                            null,    // 鐩爣鎺�
+                            null,    // 鐩爣鍒�
+                            null,    // 鐩爣灞�
+                            null,    // 鐩爣绔�
+                            null,    // 鍝嶅簲缁撴灉
+                            null,    // 淇敼鏃堕棿
+                            null,    // 淇敼浜哄憳
+                            null    // 澶囨敞
+                    );
+                    bean.insert(basSteOpt);
+                }
+            }
+
         } catch (Exception ignore) {}
 
         if (result != null && result.IsSuccess) {
             // 缁存姢鏁版嵁搴撴帓鍒楀眰
             if (!steProtocol.getWaiting()) {
-                this.lastRow = command.getRow().intValue();
-                this.lastBay = command.getBay().intValue();
-                this.lastLev = command.getLev().intValue();
+                if (!Cools.isEmpty(command.getRow(), command.getBay(), command.getLev())) {
+                    this.modifyPos(command.getRow().intValue(), command.getBay().intValue(), command.getLev().intValue());
+                }
             }
 
-
             log.info("绌挎杞﹀懡浠や笅鍙慬id:{}] >>>>> {}", slave.getId(), JSON.toJSON(command));
-            OutputQueue.CRN.offer(MessageFormat.format("銆恵0}銆慬id:{1}] >>>>> 鍛戒护涓嬪彂锛� {2}", DateUtils.convert(new Date()), slave.getId(), JSON.toJSON(command)));
+            OutputQueue.STE.offer(MessageFormat.format("銆恵0}銆慬id:{1}] >>>>> 鍛戒护涓嬪彂锛� {2}", DateUtils.convert(new Date()), slave.getId(), JSON.toJSON(command)));
             return true;
         } else {
-            OutputQueue.CRN.offer(MessageFormat.format("銆恵0}銆戝啓鍏ョ┛姊溅plc鏁版嵁澶辫触 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort()));
+            OutputQueue.STE.offer(MessageFormat.format("銆恵0}銆戝啓鍏ョ┛姊溅plc鏁版嵁澶辫触 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort()));
             log.error("鍐欏叆绌挎杞lc鏁版嵁澶辫触 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
             return false;
         }
     }
 
     public void modifyPos(Integer row, Integer bay, Integer lev) {
-        this.lastRow = row;
-        this.lastBay = bay;
-        this.lastLev = lev;
+        BasSteService service = SpringUtils.getBean(BasSteService.class);
+        if (!service.updatePos(this.slave.getId(), row, bay, lev)) {
+            log.error("鏇存柊{}鍙风┛姊溅瀹氫綅澶辫触 ===>> 鎺掞細銆恵}銆�, 鍒楋細銆恵}銆戯紝灞傦細銆恵}銆�", this.slave.getId(), row, bay, lev);
+        }
     }
 
     public boolean confirmPos() {
-        if (this.lastRow != null && this.lastRow != 0) {
-            if (this.lastBay != null && this.lastBay != 0) {
-                if (this.lastLev != null && this.lastLev != 0) {
-                    BasSteService service = SpringUtils.getBean(BasSteService.class);
-                    BasSte basSte = service.selectById(slave.getId());
-                    if (basSte != null) {
-                        // 鏇存柊plc鏁版嵁鍧�
-                        short[] arr = new short[] {this.lastRow.shortValue(), this.lastBay.shortValue(), this.lastLev.shortValue()};
-                        OperateResult result = siemensS7Net.Write("D0", arr);
-                        if (result.IsSuccess) {
-                            // 鏇存柊鏁版嵁搴�
-                            if (service.updatePos(this.lastRow, this.lastBay, this.lastLev) > 0) {
-                                this.lastRow = null;
-                                this.lastBay = null;
-                                this.lastLev = null;
-                                return true;
-                            } else {
-                                log.error("{}鍙风┛姊溅淇敼鏁版嵁搴撳畾浣嶅け璐ワ紒锛侊紒", slave.getId());
-                            }
-                        }
-                    }
-
+        BasSteService service = SpringUtils.getBean(BasSteService.class);
+        BasSte basSte = service.selectById(slave.getId());
+        if (basSte != null) {
+            // 鏇存柊plc鏁版嵁鍧�
+            short[] arr = new short[] {basSte.getRow().shortValue(), basSte.getBay().shortValue(), basSte.getLev().shortValue()};
+            OperateResult result = siemensS7Net.Write("V1002", arr);
+            if (result.IsSuccess) {
+                // 鏇存柊鏁版嵁搴�
+                if (service.updatePakMk(this.slave.getId(), "N")) {
+                    return true;
+                } else {
+                    log.error("{}鍙风┛姊溅淇敼鏁版嵁搴撳畾浣嶅け璐ワ紒锛侊紒", slave.getId());
                 }
             }
         }
         return false;
+    }
+
+    public boolean modifyPosHandle(Integer row, Integer bay, Integer lev) {
+        short[] arr = new short[] {row.shortValue(), bay.shortValue(), lev.shortValue()};
+        OperateResult result = siemensS7Net.Write("V1002", arr);
+        if (!result.IsSuccess) {
+            log.error("鏇存柊{}鍙风┛姊溅瀹氫綅澶辫触 ===>> 鎺掞細銆恵}銆�, 鍒楋細銆恵}銆戯紝灞傦細銆恵}銆�", this.slave.getId(), row, bay, lev);
+            return false;
+        }
+        BasSteService service = SpringUtils.getBean(BasSteService.class);
+        if (!service.updatePos(this.slave.getId(), row, bay, lev)) {
+            log.error("鏇存柊{}鍙风┛姊溅瀹氫綅澶辫触 ===>> 鎺掞細銆恵}銆�, 鍒楋細銆恵}銆戯紝灞傦細銆恵}銆�", this.slave.getId(), row, bay, lev);
+            return false;
+        }
+        return true;
     }
 
     @Override
@@ -340,106 +382,60 @@
         }
     }
 
+//    public void modifyPos(int wrkNo, int row, int bay, int lev) {
+//        BasSteService service = SpringUtils.getBean(BasSteService.class);
+//        if (!service.updatePos(wrkNo,this.slave.getId(), row, bay, lev)) {
+//            log.error("鏇存柊{}鍙风┛姊溅瀹氫綅澶辫触 ===>> 鎺掞細銆恵}銆�, 鍒楋細銆恵}銆戯紝灞傦細銆恵}銆�", this.slave.getId(), row, bay, lev);
+//        }
+//    }
 
     /******************************************************************************************/
     /**************************************** 娴嬭瘯涓撶敤 *****************************************/
     /*****************************************************************************************/
     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.2.1");
+        slave.setPort(502);
+        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); // 鍫嗗灈鏈虹紪鍙�
+//        Random random = new Random();
+//        int taskNo = random.nextInt(9090);
+//        command.setTaskNo(taskNo); // 宸ヤ綔鍙�
+//        command.setTaskMode(SteTaskModeType.MOVE_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(Boolean.TRUE);
+//        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);
+        // 鍒犻櫎鎸囦护
+//        SteCommand command = new SteCommand();
+//        command.setDelete(Boolean.TRUE);
+//        thread.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.setRun((short)0);
+        thread.write(command);
 
     }
 

--
Gitblit v1.9.1