Parcourir la source

按钮盒对接

k il y a 2 ans
Parent
commit
5d0204f5b1

+ 30 - 0
ruoyi-admin/src/main/java/com/ruoyi/web/controller/warewms/test/ModbusTestController.java

@@ -2,6 +2,7 @@ package com.ruoyi.web.controller.warewms.test;
 
 import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.hard.modbus.tcp.AutoDoorClient;
+import com.ruoyi.hard.modbus.tcp.ButtonBoxClient;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -22,6 +23,8 @@ public class ModbusTestController {
 
     @Autowired
     private AutoDoorClient autoDoorClient;
+    @Autowired
+    private ButtonBoxClient buttonBoxClient;
 
     /**
      * 写保持寄存器 开门
@@ -88,4 +91,31 @@ public class ModbusTestController {
     public Boolean sendCloseClear(Boolean con) {
         return autoDoorClient.sendCloseClear(con);
     }
+
+    /**
+     * 读按钮盒
+     */
+    @ApiOperation("读按钮盒")
+    @PostMapping("/btnR")
+    public void btnR(int slaveId, int offset, int len) {
+        buttonBoxClient.read(slaveId, offset, len);
+    }
+
+    /**
+     * 读按钮盒Num
+     */
+    @ApiOperation("读按钮盒Num")
+    @PostMapping("/btnRNum")
+    public void btnRNum(int slaveId, int offset) {
+        buttonBoxClient.readNum(slaveId, offset);
+    }
+
+    /**
+     * 写按钮盒
+     */
+    @ApiOperation("写按钮盒")
+    @PostMapping("/btnW")
+    public Boolean btnW(int slaveId, int offset, int value) {
+        return buttonBoxClient.write(slaveId, offset, value);
+    }
 }

+ 12 - 2
ruoyi-admin/src/main/resources/application-dev.yml

@@ -76,10 +76,14 @@ modbus:
             open: false
             host: 192.168.42.201
             port: 9000
-        second: # 自动门
+        second: # 自动门(靠里面)
             open: false
             host: 192.168.42.202
             port: 9000
+        third: # 按钮盒
+            open: true
+            host: 192.168.0.7
+            port: 9000
 
 # 注意:这玩意只能跑在window上
 rfid:
@@ -87,6 +91,12 @@ rfid:
       open: false
       host: 169.254.199.221
       port: 5084
-      number-of-tags: 3
+      number-of-tags: 3 # 一次读取标签的数量
+      timeout-milliseconds: 5000
+  second: # 靠里面
+      open: false
+      host: 192.168.42.204
+      port: 5084
+      number-of-tags: 3 # 一次读取标签的数量
       timeout-milliseconds: 5000
 

+ 15 - 4
ruoyi-admin/src/main/resources/application-prod.yml

@@ -75,15 +75,26 @@ modbus:
             open: true
             host: 192.168.42.201
             port: 9000
-        second: # 自动门
+        second: # 自动门(靠里面)
             open: true
             host: 192.168.42.202
             port: 9000
+        third: # 按钮盒
+            open: true
+            host: 192.168.42.205
+            port: 9000
 
 rfid:
-    first:
+    first: # 靠马路
+        open: true
+        host: 192.168.42.203
+        port: 5084
+        number-of-tags: 3 # 一次读取标签的数量
+        timeout-milliseconds: 5000
+    second: # 靠里面
         open: true
-        host: 169.254.199.221
+        host: 192.168.42.204
         port: 5084
-        number-of-tags: 3
+        number-of-tags: 3 # 一次读取标签的数量
         timeout-milliseconds: 5000
+

+ 133 - 0
warewms-hard/src/main/java/com/ruoyi/hard/modbus/tcp/ButtonBoxClient.java

@@ -0,0 +1,133 @@
+package com.ruoyi.hard.modbus.tcp;
+
+import com.jwk.spring.boot.autoconfigure.ModbusTcpMasterTemplate;
+import com.jwk.spring.boot.constant.DATA_TYPE_WRAPPER;
+import com.jwk.spring.boot.modbus4j.ModbusMasterUtil;
+import com.serotonin.modbus4j.msg.ReadResponse;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+
+/**
+ * 按钮盒对接
+ *
+ * @author JWK
+ * @version 1.0
+ * @date 2022/12/21 21:04
+ */
+@Service
+public class ButtonBoxClient {
+
+    /**
+     * 按钮盒
+     */
+    @Autowired(required = false)
+    private ModbusTcpMasterTemplate modbusTcpMasterTemplateThird;
+
+    /**
+     * 按钮盒命令
+     */
+    public enum BUTTON_BOX_CODE {
+        /**
+         * 1号按钮状态 value代表读的长度(读到1代表按钮被按过) value1代表清除按下标记
+         */
+        BTN_STS_01(1, 1, 1, 0, 0, 0, 0),
+        /**
+         * 1号按钮状态 value代表读的长度(读到1代表按钮被按过) value1代表清除按下标记
+         */
+        BTN_STS_02(1, 2, 1, 0, 0, 0, 0),
+        /**
+         * 1号灯状态 value代表读的长度(0:灭 1:亮 2:快闪 3慢闪) value1-4代表写(0:灭 1:亮 2:快闪 3慢闪)
+         */
+        LAMP_STS_01(1, 5, 1, 0, 1, 2, 3),
+        /**
+         * 1号灯状态 value代表读的长度(0:灭 1:亮 2:快闪 3慢闪) value1-4代表写(0:灭 1:亮 2:快闪 3慢闪)
+         */
+        LAMP_STS_02(1, 6, 1, 0, 1, 2, 3);
+
+
+        /**
+         * 从节点id
+         */
+        private int slaveId;
+        /**
+         * 地址
+         */
+        private int offset;
+        /**
+         * 读的长度
+         */
+        private int value;
+        /**
+         * 写的值
+         */
+        private int value1;
+        private int value2;
+        private int value3;
+        private int value4;
+
+        BUTTON_BOX_CODE(int slaveId, int offset, int value, int value1, int value2, int value3, int value4) {
+            this.slaveId = slaveId;
+            this.offset = offset;
+            this.value = value;
+            this.value1 = value1;
+            this.value2 = value2;
+            this.value3 = value3;
+            this.value4 = value4;
+        }
+
+        public int getSlaveId() {
+            return slaveId;
+        }
+
+        public int getOffset() {
+            return offset;
+        }
+
+        public int getValue() {
+            return value;
+        }
+
+        public int getValue1() {
+            return value1;
+        }
+
+        public int getValue2() {
+            return value2;
+        }
+
+        public int getValue3() {
+            return value3;
+        }
+
+        public int getValue4() {
+            return value4;
+        }
+    }
+
+
+    /**
+     *
+     */
+    public void readBtn01() {
+
+    }
+
+    public void read(int slaveId, int offset, int len) {
+        ModbusMasterUtil modbusMasterUtil = modbusTcpMasterTemplateThird.getModbusMasterUtil();
+        ReadResponse readResponse = modbusMasterUtil.readHoldingRegisters(slaveId, offset, len);
+        short[] shortData = readResponse.getShortData();
+    }
+
+    public void readNum(int slaveId, int offset) {
+        ModbusMasterUtil modbusMasterUtil = modbusTcpMasterTemplateThird.getModbusMasterUtil();
+        Number number = modbusMasterUtil.readHoldingRegister(slaveId, offset, DATA_TYPE_WRAPPER.EIGHT_BYTE_INT_SIGNED);
+
+    }
+
+    public Boolean write(int slaveId, int offset, int value) {
+        ModbusMasterUtil modbusMasterUtil = modbusTcpMasterTemplateThird.getModbusMasterUtil();
+        return modbusMasterUtil.writeHoldingRegisters(slaveId, offset, value);
+    }
+
+}