| | |
| | | }
|
| | | }
|
| | |
|
| | | //写入Word
|
| | | //不连续地址 写入Word
|
| | | public void WriteWordToPLC(JSONArray messageArray, List<String> addresses, int index) {
|
| | | try {
|
| | | if (messageArray.getJSONArray(index).size() > 0) {
|
| | |
| | | }
|
| | | }
|
| | |
|
| | |
|
| | |
|
| | | public void WriteWordsToPLC(JSONArray jsonArray, String address,int index) {
|
| | | if (jsonArray.getJSONArray(index).size() > 0) {
|
| | | Object value = jsonArray.getJSONArray(index).get(0);
|
| | | if (value != null && !value.toString().equals("null")) {
|
| | | try {
|
| | | String cleanedValue = value.toString().replaceAll("[^0-9-]", "");
|
| | | short sValue = Short.parseShort(cleanedValue.trim());
|
| | | S7control.getinstance().WriteWord(address, Arrays.asList(sValue));
|
| | | System.out.println("messageValue:" + Arrays.asList(sValue) + " written to PLC at address " + address);
|
| | | } catch (NumberFormatException e) {
|
| | | // 如果无法解析为 short 类型,则忽略该部分
|
| | | System.err.println("Could not parse value: " + value);
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | |
|
| | | //写入String
|
| | | public void writeStringToPLC(JSONArray messageArray, String addresses, int index) {
|
| | | try {
|