Browse Source

-- 道闸门业务优化
-- 移库和出库任务无法下发问题解决

star 1 year ago
parent
commit
7f9ab557c6

+ 0 - 10
ruoyi-admin/src/main/java/com/ruoyi/web/controller/warewms/test/ChargingMachineTestController.java

@@ -161,14 +161,4 @@ public class ChargingMachineTestController {
         return  modbusTcpWeigherClient.writeGateClose();
     }
 
-    @ApiOperation("道闸开门状态")
-    @PostMapping("/stateOpenDZ")
-    public Boolean stateOpenDZ() {
-        return  modbusTcpWeigherClient.readGateOpenState();
-    }
-    @ApiOperation("道闸关门状态")
-    @PostMapping("/stateCloseDZ")
-    public Boolean stateCloseDZ() {
-        return  modbusTcpWeigherClient.readGateCloseState();
-    }
 }

+ 19 - 30
warewms-ams/src/main/java/com/ruoyi/ams/agv/ndc/service/impl/StatusUpdateServiceImpl.java

@@ -316,24 +316,20 @@ public class StatusUpdateServiceImpl implements StatusUpdateService {
 
             try {
 
-                //先读 道闸是否已开门  1-开   0-关
-                boolean state = modbusTcpWeigherClient.readGateOpenState();
-                log.info("道闸是否已开门!状态:" + state);
-                if(state){
-
-                    //门已开AGV可通过
+                int state = modbusTcpWeigherClient.redGateState(4);
+                if(state == 1){
+                    log.info("gateOpen允许AGV通过!门号:" + doorNo);
                     feedbackTS(doorNo);
-                }else{
+                }
+                //发送开门信号
+                boolean state2 = modbusTcpWeigherClient.writeGateOpen();
+                log.info("gateOpen发送开门信号!状态:" + state2);
+                Thread.sleep(3000);
 
-                    //发送开门信号
-                    boolean state2 = modbusTcpWeigherClient.writeGateOpen();
-                    log.info("发送开门信号!状态:" + state2);
-                    Thread.sleep(3000);
+                //清除开门信号
+                boolean state3 = modbusTcpWeigherClient.clearOpenStaate();
+                log.info("gateOpen清除开门信号!状态:" + state3);
 
-                    //清除开门信号
-                    boolean state3 = modbusTcpWeigherClient.clearOpenStaate();
-                    log.info("清除开门信号!状态:" + state3);
-                }
             } catch (InterruptedException e) {
 
                 e.printStackTrace();
@@ -342,35 +338,28 @@ public class StatusUpdateServiceImpl implements StatusUpdateService {
                 redisCache.expire("open",12000);
             }
         }
-
     }
 
     @Override
     public void gateClose(Integer doorNo) {
 
-
         if(redisCache.checkIsLock("close")){
 
             try {
 
-                //先读 道闸是否已关门  1-开   0-关
-                boolean state = modbusTcpWeigherClient.readGateCloseState();
-                log.info("道闸是否已关门!状态:" + state);
-                if(!state){
+                //发送关门信号
+                boolean state2 = modbusTcpWeigherClient.writeGateClose();
+                log.info("gateClose发送关门信号!状态:" + state2);
+                Thread.sleep(3000);
 
-                    //发送关门信号
-                    boolean state2 = modbusTcpWeigherClient.writeGateClose();
-                    log.info("发送关门信号!状态:" + state2);
-                    Thread.sleep(3000);
+                //清除关门信号
+                boolean state3 = modbusTcpWeigherClient.clearCloseState();
+                log.info("gateClose清除关门信号!状态:" + state3);
 
-                    //清除关门信号
-                    boolean state3 = modbusTcpWeigherClient.clearCloseState();
-                    log.info("清除关门信号!状态:" + state3);
-                }
             } catch (InterruptedException e) {
 
                 e.printStackTrace();
-            }finally {
+            } finally {
 
                 redisCache.expire("close",12000);
             }

+ 2 - 1
warewms-ams/src/main/java/com/ruoyi/ams/business/BusinessServiceImpl.java

@@ -475,7 +475,8 @@ public class BusinessServiceImpl implements IBusinessService {
             wcsTask.setTaskType(Constant.TASK_TYPE.FORWARD.getValue());
             wcsTask.setExt8(token.toString());
             wcsTask.setExt7(flowConfigHeaderVO.getId().toString());
-            wcsTask.setExt3(agvCallDTO.getExt3());
+            wcsTask.setExt3(agvCallDTO.getExt3() == null || "".equals(agvCallDTO.getExt3())?
+                                "0000": agvCallDTO.getExt3());
             wcsTask.setExtParam(agvCallDTO.getExtParam());
             wcsTaskList.add(wcsTask);
             businessService.addTask(wcsTask);

+ 53 - 0
warewms-hard/src/main/java/com/ruoyi/hard/modbus/tcp/ConvertUtil.java

@@ -0,0 +1,53 @@
+package com.ruoyi.hard.modbus.tcp;
+
+import java.util.Arrays;
+
+/**
+ * @author Jwk
+ * @version 1.0
+ * @date 2023/4/23 16:12
+ */
+public class ConvertUtil {
+
+    public static boolean[] convertToBooleans(Number num) {
+        //转换为bool数组
+        int i = num.intValue();
+        String string = Integer.toBinaryString(i);
+        int StrLength = string.length();
+        if (StrLength < 16) {
+            while (StrLength < 16) {
+                StringBuilder stringBuilder = new StringBuilder();
+                String stringNew = stringBuilder.append("0").append(string).toString();
+                StrLength = stringNew.length();
+                string = stringNew;
+            }
+        }
+        char[] chars = string.toCharArray();
+        boolean[] booleans = new boolean[16];
+        for (int j = 0; j < chars.length; j++) {
+            if (chars[j] == 49) {
+                booleans[j] = true;
+            } else {
+                booleans[j] = false;
+            }
+        }
+        return booleans;
+    }
+
+    public static int convertToInt(boolean[] booleans) {
+        int n = 0;
+        for (boolean b : booleans)
+            n = (n << 1) | (b ? 1 : 0);
+        return n;
+    }
+
+    public static void main(String[] args) {
+        boolean[] booleans = {true, true, true, true, true, true, true, true};
+        System.out.println(ConvertUtil.convertToInt(booleans));
+
+        int num = 23;
+        boolean[] booleans1 = convertToBooleans(num);
+        System.out.println(Arrays.toString(booleans1));
+
+    }
+}

+ 37 - 38
warewms-hard/src/main/java/com/ruoyi/hard/modbus/tcp/ModbusTcpWeigherClient.java

@@ -88,67 +88,66 @@ public class ModbusTcpWeigherClient {
         return modbusMasterUtil.readHoldingRegister(1, 3, DATA_TYPE_WRAPPER.TWO_BYTE_INT_UNSIGNED).intValue();
     }
 
-    /**
-     * 道闸是否开门到位
-     *
-     * @return
-     */
-    public Boolean readGateOpenState() {
-        ModbusMasterUtil modbusMasterUtil = modbusTcpMasterTemplateFirst.getModbusMasterUtil();
-        short i = read(modbusMasterUtil,1, 4, 1);
-        return i == 1;
-    }
 
     /**
-     * 道闸是否关门到位
-     *
-     * @return
+     * 清除开门状态
      */
-    public Boolean readGateCloseState() {
-        ModbusMasterUtil modbusMasterUtil = modbusTcpMasterTemplateFirst.getModbusMasterUtil();
-        short i = read(modbusMasterUtil,1, 5, 1);
-        return i == 1;
+    public Boolean clearOpenStaate() {
+        Number number = read1(1, 4);
+        boolean[] booleans = ConvertUtil.convertToBooleans(number);
+        booleans[15] = false;
+        int i = ConvertUtil.convertToInt(booleans);
+        return write(1, 7, i);
     }
 
     /**
-     * 清除门状态
+     * 清除门状态
      */
-    public Boolean clearOpenStaate() {
-        ModbusMasterUtil modbusMasterUtil = modbusTcpMasterTemplateFirst.getModbusMasterUtil();
-        return write(modbusMasterUtil,1, 7, 0);
+    public Boolean clearCloseState() {
+        Number number = read1(1, 5);
+        boolean[] booleans = ConvertUtil.convertToBooleans(number);
+        booleans[15] = false;
+        int i = ConvertUtil.convertToInt(booleans);
+        return write(1, 6, i);
     }
+
     /**
      * 道闸开门
      */
     public Boolean writeGateOpen() {
-        ModbusMasterUtil modbusMasterUtil = modbusTcpMasterTemplateFirst.getModbusMasterUtil();
-        return write(modbusMasterUtil,1, 7, 1);
+        Number number = read1(1, 4);
+        boolean[] booleans = ConvertUtil.convertToBooleans(number);
+        booleans[15] = true;
+        int i = ConvertUtil.convertToInt(booleans);
+        return write(1, 7, i);
     }
-
     /**
-     * 清除关门状态
+     * 道闸关门
      */
-    public Boolean clearCloseState() {
-        ModbusMasterUtil modbusMasterUtil = modbusTcpMasterTemplateFirst.getModbusMasterUtil();
-        return write(modbusMasterUtil,1, 6, 0);
+    public Boolean writeGateClose() {
+        Number number = read1(1, 5);
+        boolean[] booleans = ConvertUtil.convertToBooleans(number);
+        booleans[15] = true;
+        int i = ConvertUtil.convertToInt(booleans);
+        return write(1, 6, i);
     }
+
     /**
-     * 道闸关门
+     * 获取道闸门状态
      */
-    public Boolean writeGateClose() {
+    public int redGateState(int offset) {
         ModbusMasterUtil modbusMasterUtil = modbusTcpMasterTemplateFirst.getModbusMasterUtil();
-        return write(modbusMasterUtil,1, 6, 1);
+        return modbusMasterUtil.readHoldingRegister(1, offset, DATA_TYPE_WRAPPER.TWO_BYTE_INT_UNSIGNED).intValue();
     }
 
-
-    private short read(ModbusMasterUtil modbusMasterUtil,int slaveId, int offset, int len) {
-        ReadResponse readResponse = modbusMasterUtil.readHoldingRegisters(slaveId, offset, len);
-        short[] shortData = readResponse.getShortData();
-        return shortData[0];
+    private Number read1(int slaveId, int offset) {
+        ModbusMasterUtil modbusMasterUtil = modbusTcpMasterTemplateFirst.getModbusMasterUtil();
+        Number number = modbusMasterUtil.readHoldingRegister(slaveId, offset, DATA_TYPE_WRAPPER.TWO_BYTE_INT_UNSIGNED);
+        return number;
     }
 
-
-    private Boolean write(ModbusMasterUtil modbusMasterUtil,int slaveId, int offset, int value) {
+    private Boolean write(int slaveId, int offset, int value) {
+        ModbusMasterUtil modbusMasterUtil = modbusTcpMasterTemplateFirst.getModbusMasterUtil();
         return modbusMasterUtil.writeHoldingRegisters(slaveId, offset, value);
     }
 }