Browse Source

读称重机上货物重量 - 如果称重机没有连上,返回0

k 1 year ago
parent
commit
e67910f565

+ 3 - 0
warewms-hard/src/main/java/com/ruoyi/hard/modbus/tcp/ModbusTcpWeigherClient.java

@@ -83,6 +83,9 @@ public class ModbusTcpWeigherClient {
      * @return
      */
     public int readWeighing() {
+        if (modbusTcpMasterTemplateFirst == null || modbusTcpMasterTemplateFirst.getModbusMasterUtil() == null) {
+            return 0;
+        }
         ModbusMasterUtil modbusMasterUtil = modbusTcpMasterTemplateFirst.getModbusMasterUtil();
         return modbusMasterUtil.readHoldingRegister(1, 3, DATA_TYPE_WRAPPER.TWO_BYTE_INT_UNSIGNED).intValue();
     }