wuyouming666
2023-12-19 ea57b412689d6aa808707bc074d662cb0706a13f
springboot-vue3/src/main/java/com/example/springboot/component/S7control.java
@@ -159,8 +159,15 @@
    public List<Short> ReadWord(List<String> address) {
        if (s7PLC==null)
              return null;
        try {
        return s7PLC.readInt16(address);
        } catch (Exception e) {
            System.out.println("读取 " + address + " 失败:" + e.getMessage());
            return null;
    }
    }
@@ -188,8 +195,15 @@
             return null;
        List<String> addresslist = GetAddressList(address, count, 16);
        try {
        return s7PLC.readInt16(addresslist);
        } catch (Exception e) {
            System.out.println("读取 " + address + " 失败:" + e.getMessage());
            return null;
    }
    }
    /**
     * 按指定的地址 读取byte结果集
     * 
@@ -241,34 +255,23 @@
        if (s7PLC == null) {
            return null;
        }
        List<String> result = new ArrayList<>();
        for (String address : addressList) {
        try {
            byte[] bytes = s7PLC.readByte(address, 14);
//            System.out.println(bytes.toString());
          if (bytes != null) {
            String str = new String(bytes, StandardCharsets.UTF_8);
//          System.out.println(str);
//              if(str == null ){
//                   str = "";
//              }
                result.add(str);
            }
//            if ( bytes.toString().contains("@")) {
//                String str = "";
//
//                result.add(str);
//            }else{
//
//                String str = new String(bytes, StandardCharsets.US_ASCII);
//                result.add(str);
//            }
//            System.out.println(bytes.toString());
        } catch (Exception e) {
            System.out.println("读取 " + address + " 失败:" + e.getMessage());
            result.add(null);
        }
        }
        return result;
    }
//不连续地址写入Word
    public void WriteWord(List<String> address, List<Short> datas) {
@@ -304,7 +307,7 @@
        S7control.getinstance().WriteByte(addr, bytes);
    }
//读取不连续word
    public List<Short> readWords(List<String> addresses) {
        if (s7PLC == null) {
            return null;
@@ -351,9 +354,15 @@
        if (s7PLC==null)
            return null;
        List<String> addresslist = GetAddressList(address, count, 1);
        try {
        return s7PLC.readBoolean(addresslist);
        } catch (Exception e) {
            System.out.println("读取 " + address + " 失败:" + e.getMessage());
            return null;
    }
    
    };
    
    private List<String> GetAddressList(String address, int count, int addedbit) {