wuyouming666
2023-11-30 f35b7028fc2c980f1ad1afefa17e9adf55b7a1d0
springboot-vue3/src/main/java/com/example/springboot/component/Plcstate.java
@@ -1,12 +1,61 @@
package com.example.springboot.component;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
import java.util.Arrays;
public class Plcstate extends Thread {
  String name = "";
  Integer count = 0;
  public void readValue() {
    String str = "";
    BufferedReader bufferedReader = null;
    FileInputStream fileInputStream;
    try {
      // 从文件中读取字节数据存入 fileInputStream
      fileInputStream = new FileInputStream("CanadaMes-ui/src/configuration/State.json");
      // 读取 fileInputStream 中字节并将其解码为字符
      InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream, "utf-8");
      // 提高读取效率,在 BufferedReader 内包装 InputStreamReader
      bufferedReader = new BufferedReader(inputStreamReader);
      String line = null;
      // 将 bufferedReader 内容一行一行赋值给str
      while ((line = bufferedReader.readLine()) != null) {
        str += line;
      }
      // 将str字符串格式转为json
      JSONObject jsonObject = new JSONObject(str);
      // 获取json中的值
      JSONArray address = jsonObject.getJSONArray("address");
      for (int i = 0; i < address.size(); i++) {
        JSONObject ress = (JSONObject) address.get(i);
        this.name = ress.getStr("name");
        this.count = ress.getInt("count");
      }
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (UnsupportedEncodingException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
  @Override
  public void run() {
    while (this != null) {
@@ -16,10 +65,15 @@
        e.printStackTrace();
      }
      List<Short> plclist = S7control.getinstance().ReadWord("DB103.0", 10);
      // Short[] values = { 0, 1, 1, 0, 1, 0, 1, 0,
      // 1, 0, };
      // List<Short> plclist = new ArrayList<>(Arrays.asList(values));
//      this.readValue();
//      String PlcAddress = this.name;
//      Integer Plccount = this.count;
      // System.out.println(PlcAddress);
List<Short> plclist = S7control.getinstance().ReadWord("DB103.0", 44);
//      Short[] values = { 0, 1, 1, 0, 1, 0, 1, 0,
//          1, 0, };
//      List<Short> plclist = new ArrayList<>(Arrays.asList(values));
      if (plclist != null) {
        List<String> Intlist = new ArrayList<>();