| | |
| | | config = new Configuration("config.properties"); |
| | | } |
| | | |
| | | |
| | | |
| | | // 创建一个自定义的 S7 控制器消息处理器对象 |
| | | MessageHandler customS7Control = new MessageHandler(); |
| | | |
| | | |
| | | |
| | | |
| | | public static class PLCBooleanConverter { |
| | | |
| | | public static short[] convertListsToBinaryShortArray(List<Boolean>... lists) { |
| | |
| | | } |
| | | if (!sValue.isEmpty()) { |
| | | S7control.getinstance().WriteWord(waddresses1, sValue); |
| | | if (A01readstart != null && !A01readstart.isEmpty()) { |
| | | // 创建一个新的列表用于写入新值 |
| | | List<Boolean> a01startval = new ArrayList<>(); |
| | | // 遍历所有读取到的位值 |
| | | for (Boolean bit : A01readstart) { |
| | | // 取反当前位的值并添加到新的列表中 |
| | | a01startval.add(!bit); |
| | | } |
| | | // 写入新的位值列表 |
| | | S7control.getinstance().WriteBit(A01start, a01startval); |
| | | System.out.println("a01startval " + a01startval + " written to PLC at address " + A01start); |
| | | } |
| | | |
| | | |
| | | System.out.println("Values " + sValue + " written to PLC at address " + waddresses1); |
| | |
| | | } |
| | | if (!sValue2.isEmpty()) { |
| | | S7control.getinstance().WriteWord(waddresses2, sValue2); |
| | | if (A02readstart != null && !A02readstart.isEmpty()) { |
| | | // 创建一个新的列表用于写入新值 |
| | | List<Boolean> a02startval = new ArrayList<>(); |
| | | // 遍历所有读取到的位值 |
| | | for (Boolean bit : A02readstart) { |
| | | // 取反当前位的值并添加到新的列表中 |
| | | a02startval.add(!bit); |
| | | } |
| | | // 写入新的位值列表 |
| | | S7control.getinstance().WriteBit(A02start, a02startval); |
| | | } |
| | | |
| | | |
| | | |
| | | System.out.println("Values " + sValue2 + " written to PLC at address " + waddresses2); |
| | |
| | | } |
| | | if (!sValue2.isEmpty()) { |
| | | S7control.getinstance().WriteWord(waddresses3, sValue2); |
| | | if (B01readstart != null && !B01readstart.isEmpty()) { |
| | | // 创建一个新的列表用于写入新值 |
| | | List<Boolean> b01startval = new ArrayList<>(); |
| | | // 遍历所有读取到的位值 |
| | | for (Boolean bit : B01readstart) { |
| | | // 取反当前位的值并添加到新的列表中 |
| | | b01startval.add(!bit); |
| | | } |
| | | // 写入新的位值列表 |
| | | S7control.getinstance().WriteBit(B01start, b01startval); |
| | | } |
| | | |
| | | System.out.println("Values " + sValue2 + " written to PLC at address " + waddresses3); |
| | | } |
| | | } |
| | |
| | | } |
| | | if (!sValue2.isEmpty()) { |
| | | S7control.getinstance().WriteWord(waddresses4, sValue2); |
| | | if (B02readstart != null && !B02readstart.isEmpty()) { |
| | | // 创建一个新的列表用于写入新值 |
| | | List<Boolean> b02startval = new ArrayList<>(); |
| | | // 遍历所有读取到的位值 |
| | | for (Boolean bit : B02readstart) { |
| | | // 取反当前位的值并添加到新的列表中 |
| | | b02startval.add(!bit); |
| | | } |
| | | // 写入新的位值列表 |
| | | S7control.getinstance().WriteBit(B02start, b02startval); |
| | | System.out.println("Values " + b02startval + " written to PLC at address " + B02start); |
| | | } |
| | | |
| | | System.out.println("Values " + sValue2 + " written to PLC at address " + waddresses4); |
| | | } |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | customS7Control.writeBitToPLC( messageArray, A01start,7); |
| | | customS7Control.writeBitToPLC( messageArray, A02start,8); |
| | | customS7Control.writeBitToPLC( messageArray,B01start,9); |
| | | customS7Control.writeBitToPLC( messageArray, B02start,10); |
| | | |
| | | // 清空消息列表 |
| | | webserver.clearMessages(); |
| | | } |