wu
2023-12-18 37f7f87968cfd2c400283fbf83851c39c2c4d456
springboot-vue3/src/main/java/com/example/springboot/component/PlcPositioning1.java
@@ -17,53 +17,7 @@
import org.apache.commons.io.FileUtils;
public class PlcPositioning1 extends Thread {
    String name = "";
    Integer count = 0;
    public static String readFileToString(String filePath) throws IOException {
        File file = new File(filePath);
        return FileUtils.readFileToString(file, "UTF-8");
    }
    public void readValue() {
        String str = "";
        BufferedReader bufferedReader = null;
        FileInputStream fileInputStream;
        try {
            // 从文件中读取字节数据存入 fileInputStream
            fileInputStream = new FileInputStream("CanadaMes-ui/src/configuration/address.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("Positioning1");
            for (int i = 0; i < address.size(); i++) {
                JSONObject ress = (JSONObject) address.get(i);
                this.name = ress.getStr("name");
                this.count = ress.getInt("count");
                System.out.println("messageValues:" + this.name);
                System.out.println("messageValues:" + this.count);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    @Override
    public void run() {
@@ -74,21 +28,15 @@
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
//        this.readValue();
//            String PlcAddress = this.name;
//            Integer Plccount = this.count;
            // System.out.println(stt);
            //存片格  出片格读取
  List<Short> arraylist = S7control.getinstance().ReadWord("DB100.42", 23);
          List<Short> arraylist = S7control.getinstance().ReadWord("DB100.42", 33);
//            System.out.println(arraylist);
//            Short[] 存片 = { 1 };
//            List<Short> 存片1 = new ArrayList<>(Arrays.asList(存片));
//            Short[] 接片 = { 1 };
//            List<Short> 接片1 = new ArrayList<>(Arrays.asList(接片));
//            Short[] 间距 = { 1 };
//            List<Short> 间距1 = new ArrayList<>(Arrays.asList(间距));
//            Short[] values1 = {1,1,1, 1,2, 3, 4, 5, 6, 7, 8, 9, 10,11, 12,13,14,15,16,17,18,19,20 };
//            Short[] values1 = {1,1,1, 1,2, 3, 4, 5, 6, 7, 8, 9, 10,11, 12,13,14,15,16,17,18,19,20,11, 12,13,14,15,16,17,18,19,20 };
//            List<Short> arraylist = new ArrayList<>(Arrays.asList(values1));
@@ -122,7 +70,7 @@
                            // 整合第 1 到 3 个数组并去掉 null 元素
                            List<Short> mergedList = new ArrayList<>();
                            for (int i = 0; i < 5; i++) {
                            for (int i = 0; i < 7; i++) {
                                JSONArray sublist = messageArray.getJSONArray(i);
                                for (int j = 0; j < sublist.size(); j++) {
                                    Object value = sublist.get(j);