| | |
| | | |
| | | 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; |
| | | } |
| | | |
| | | |
| | |
| | | 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) { |