严智鑫
2024-05-10 211cd083bc9fc1871779802650dfe0e607d8ca77
hangzhoumesParent/common/servicebase/src/main/java/com/mes/tools/S7control.java
@@ -273,21 +273,18 @@
        return result;
    }
    //读取字符串
    public String readString(String address) {
        if (s7PLC == null) {
            return null;
        }
        try {
            byte[] bytes = s7PLC.readByte(address, 14);
            if (bytes != null) {
                return new String(bytes, StandardCharsets.UTF_8);
            }
            return s7PLC.readString(address);
        } catch (Exception e) {
            System.out.println("读取 " + address + " 失败:" + e.getMessage());
            return null;
        }
        return null;
    }
@@ -346,6 +343,21 @@
        return data;
    }
    //读取单个word
    public Short readWord(String address) {
        if (s7PLC == null) {
            return null;
        }
        try {
            // 单个地址
            return s7PLC.readInt16(address);
        } catch (Exception e) {
            System.out.println("读取 " + address + " 失败:" + e.getMessage());
        }
        return -1;
    }
    //读取时间
    public Long readtime(String address) {
        if (s7PLC == null) {