소스 검색

自动线去掉数采相关逻辑

hbx 1 주 전
부모
커밋
c52f427130
5개의 변경된 파일과 1개의 추가작업 그리고 449개의 파일을 삭제
  1. 1 111
      src/com/mes/component/WorkJPanelOP60.java
  2. 0 113
      src/com/mes/component/WorkJPanelOP70.java
  3. 0 29
      src/com/mes/util/JdbcUtils.java
  4. 0 132
      src/com/mes/util/S7Util.java
  5. 0 64
      src/com/mes/util/Test01.java

+ 1 - 111
src/com/mes/component/WorkJPanelOP60.java

@@ -2,19 +2,12 @@ package com.mes.component;
 
 import com.alibaba.fastjson2.JSON;
 import com.alibaba.fastjson2.JSONObject;
-import com.github.s7connector.api.DaveArea;
-import com.github.s7connector.api.S7Connector;
-import com.github.s7connector.api.S7Serializer;
-import com.github.s7connector.api.factory.S7ConnectorFactory;
-import com.github.s7connector.api.factory.S7SerializerFactory;
 import com.github.xingshuangs.iot.protocol.s7.enums.EPlcType;
 import com.github.xingshuangs.iot.protocol.s7.service.S7PLC;
 import com.mes.ui.CacheData;
 import com.mes.ui.DataUtil;
 import com.mes.ui.MesClient;
-import com.mes.util.DateLocalUtils;
 import com.mes.util.JdbcUtils;
-import com.mes.util.S7Util;
 import com.mes.util.TCPClient;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -22,8 +15,6 @@ import org.slf4j.LoggerFactory;
 import javax.swing.*;
 import java.awt.*;
 import java.awt.event.*;
-import java.util.ArrayList;
-import java.util.List;
 import java.util.Timer;
 import java.util.TimerTask;
 import java.util.concurrent.ExecutorService;
@@ -75,13 +66,9 @@ public class WorkJPanelOP60 extends JPanel {
 
     public String plcIp1 = "192.168.90.85"; // plc5 西侧
     public String plcIp2 = "192.168.90.86"; // plc6 东侧
-    public String deviceIp = "";   //摩擦焊ip
 
-    public Integer errflag = 0; // 1=报警 0=正常
     public Integer errflag2 = 0;
 
-    public S7Connector s7Connector;
-
     public S7PLC s7PLC = null;
 
     public Integer workWidth = 470;
@@ -104,13 +91,11 @@ public class WorkJPanelOP60 extends JPanel {
 
     public Integer isScan = 1; // 1=西侧 2=东测
 
-    public static List<String> hjparams = new ArrayList<>();
     public int transferSn = 0;
     public int transferFloor = 0;
     public JLabel oprnoLabel;
     public JLabel oprnoLabel2;
     public String fswDeviceName = ""; // 设备名:1号机/2号机
-    public Boolean fswOnline = true;
 
     public JButton signalBtn; // 信号监控按钮
 
@@ -141,11 +126,9 @@ public class WorkJPanelOP60 extends JPanel {
 
         if(MesClient.mes_line_pos.equals("east")){ // 东侧
             s7PLC = new S7PLC(EPlcType.S1500, plcIp2);
-            deviceIp = "80.25.10.42";
             isScan = 2;
         }else{
             s7PLC = new S7PLC(EPlcType.S1500, plcIp1);
-            deviceIp = "80.24.10.42";
             isScan = 1;
         }
 
@@ -153,7 +136,6 @@ public class WorkJPanelOP60 extends JPanel {
         // pos: A=西侧1号机 B=东侧1号机(默认DB7000);C=西侧2号机 D=东侧2号机(DB7004,新增设备)
         if(pos.equals("C") || pos.equals("D")){
             plcDb = "DB7004";
-            deviceIp = ""; // TODO 封板正面FSW2设备IP待现场确认后修改,未确认前参数采集不可用
             fswDeviceName = pos.equals("C") ? "西侧2号机" : "东侧2号机";
         }else{
             fswDeviceName = MesClient.mes_line_pos.equals("east") ? "东侧1号机" : "西侧1号机";
@@ -351,7 +333,7 @@ public class WorkJPanelOP60 extends JPanel {
 
 
 //        resetScanA();
-        monitorDeviceStatus();   //获取摩擦焊参
+        monitorDeviceStatus();   //设备报警监控
 
 
 
@@ -424,31 +406,6 @@ public class WorkJPanelOP60 extends JPanel {
             public void run() {
                 if(MesClient.isLogin == 1 && isLocal == 0){
                     try{
-                        initS7();
-                        monitorDevice();
-                        boolean ret = S7Util.getFswAlarm(s7Connector);
-                        if(ret){
-                            errflag = 0;
-                        }
-                        if(!ret && errflag == 0 ){
-                            errflag = 1;
-                            DataUtil.deviceAlarm(oprno+pos,productSn.getText(),oprno+pos+"随动夹具报警",MesClient.user_menu.getText());
-                        }
-                        fswOnline = true;
-                    }catch (Exception e){
-                        log.info(e.getMessage());
-                        fswOnline = false;
-                    }
-
-                    if(fswOnline){
-                        oprnoLabel.setForeground(Color.BLACK);
-                        oprnoLabel2.setForeground(Color.BLACK);
-                    }else{
-                        oprnoLabel.setForeground(Color.RED);
-                        oprnoLabel2.setForeground(Color.RED);
-                    }
-
-                    try{
                         int ret = getAlarm();
                         if(ret == 0){
                             errflag2 = 0;
@@ -633,13 +590,6 @@ public class WorkJPanelOP60 extends JPanel {
             productSnFeeding.setText(sn);
             lastSn = sn;
 
-            //判断刀具寿命
-//            Integer hjjs =  S7Util.formatS7Int(s7Connector.read(DaveArea.DB, 9051, 2, 26));
-//            if(hjjs > 1230){
-//                setMenuStatus("搅拌头达到使用寿命,请换搅拌头",-1);
-//                return;
-//            }
-
             // 查询工件质量
             JSONObject retObj = DataUtil.checkQuality(sn,oprno+pos,MesClient.user_menu.getText());
             if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
@@ -850,66 +800,6 @@ public class WorkJPanelOP60 extends JPanel {
         return true;
     }
 
-    public void initS7(){
-        try {
-            if(s7Connector == null) {
-                //PLC地址
-                String ipAddress = deviceIp;
-                //默认端口
-                int port = 102;
-                int rack=0;
-                int slot=3;
-                int timeout=5000;
-                s7Connector=
-                        S7ConnectorFactory
-                                .buildTCPConnector()
-                                .withHost(ipAddress)
-                                .withPort(port) //optional
-//								.withRack(rack) //optional
-//								.withSlot(slot) //optional
-                                .withTimeout(timeout) //连接超时时间
-                                .build();
-                S7Serializer s7Serializer2L = S7SerializerFactory.buildSerializer(s7Connector);
-            }
-        } catch (Exception e) { // 如果连接失败保存失败再次尝试连接一次
-            s7Connector = null;
-            e.printStackTrace();
-        }
-    }
-
-    public void monitorDevice(){
-        //工件加工状态开始上传摩擦焊参数
-        if(tjFlag == 2){
-            try{
-                String zzzs = S7Util.formatS7Val(s7Connector.read(DaveArea.DB, 9051, 4, 0));
-                String jgsd = S7Util.formatS7Val(s7Connector.read(DaveArea.DB, 9051, 4, 4));
-                String zzzb = S7Util.formatS7Val(s7Connector.read(DaveArea.DB, 9051, 4, 8));
-                String ylz = S7Util.formatS7Val(s7Connector.read(DaveArea.DB, 9051, 4, 12));
-                Integer hjjs = S7Util.formatS7Int(s7Connector.read(DaveArea.DB, 9051, 2, 26));
-                String hjcd = S7Util.formatS7Val(s7Connector.read(DaveArea.DB, 9051, 4, 28));
-                String hjms = S7Util.formatS7Val(s7Connector.read(DaveArea.DB, 9051, 4, 32));
-                String record_time = DateLocalUtils.getCurrentTime();
-//                log.info(oprno+pos+"摩擦焊参数采集 -> 时间: {}, 转速: {}, 速度: {}, Z轴: {}, 压力: {}, 计数: {}, 长度: {}, 耗时: {}", record_time, zzzs, jgsd, zzzb, ylz, hjjs, hjcd, hjms);
-                hjparams.add(zzzs+"|"+jgsd+"|"+zzzb+"|"+ylz+"|"+hjjs+"|"+hjcd+"|"+hjms+"|"+record_time);
-                if (hjparams.size() == 60  && productSn.getText() != null && !productSn.getText().trim().isEmpty() ) {
-                    JdbcUtils.insertParamData(oprno+pos,MesClient.mes_line_sn,productSn.getText(), JSON.toJSONString(hjparams));
-                    hjparams = new ArrayList<>();
-                }else{
-//                    log.info("未执行插入");
-                }
-            }catch (Exception e){
-                e.printStackTrace();
-                s7Connector = null;
-            }
-        }else{
-            if(hjparams.size() > 0){
-                JdbcUtils.insertParamData(oprno+pos,MesClient.mes_line_sn,productSn.getText(), JSON.toJSONString(hjparams));
-                hjparams = new ArrayList<>();
-            }
-        }
-
-    }
-
     public int getAlarm(){
         boolean ret0 = readBoolean(plcDb+".6.0");
         if(ret0){

+ 0 - 113
src/com/mes/component/WorkJPanelOP70.java

@@ -2,19 +2,12 @@ package com.mes.component;
 
 import com.alibaba.fastjson2.JSON;
 import com.alibaba.fastjson2.JSONObject;
-import com.github.s7connector.api.DaveArea;
-import com.github.s7connector.api.S7Connector;
-import com.github.s7connector.api.S7Serializer;
-import com.github.s7connector.api.factory.S7ConnectorFactory;
-import com.github.s7connector.api.factory.S7SerializerFactory;
 import com.github.xingshuangs.iot.protocol.s7.enums.EPlcType;
 import com.github.xingshuangs.iot.protocol.s7.service.S7PLC;
 import com.mes.ui.CacheData;
 import com.mes.ui.DataUtil;
 import com.mes.ui.MesClient;
-import com.mes.util.DateLocalUtils;
 import com.mes.util.JdbcUtils;
-import com.mes.util.S7Util;
 import com.mes.util.TCPClient;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -22,8 +15,6 @@ import org.slf4j.LoggerFactory;
 import javax.swing.*;
 import java.awt.*;
 import java.awt.event.*;
-import java.util.ArrayList;
-import java.util.List;
 import java.util.Timer;
 import java.util.TimerTask;
 import java.util.concurrent.ExecutorService;
@@ -77,11 +68,8 @@ public class WorkJPanelOP70 extends JPanel {
     public String plcIp2 = "192.168.90.86"; // plc6 东侧
 
 
-    public String deviceIp = "";   //摩擦焊ip
-    public Integer errflag = 0; // 1=报警 0=正常
     public Integer errflag2 = 0;
 
-    public S7Connector s7Connector;
     public S7PLC s7PLC = null;
 
     public Integer workWidth = 470;
@@ -109,16 +97,12 @@ public class WorkJPanelOP70 extends JPanel {
 
     public String finallySn = "";
 
-    public static List<String> hjparams = new ArrayList<>();
-
     public String fswDeviceName = "";
 
     public JLabel oprnoLabel;
 
     public JLabel oprnoLabel2;
 
-    public Boolean fswOnline = true;
-
     public JButton signalBtn; // 信号监控按钮
 
     public PlcSignalMonitor signalMonitor; // 信号监控组件
@@ -149,11 +133,9 @@ public class WorkJPanelOP70 extends JPanel {
 
         if(MesClient.mes_line_pos.equals("east")){ // 东侧
             s7PLC = new S7PLC(EPlcType.S1500, plcIp2);
-            deviceIp = "80.25.10."; //摩擦焊前缀ip
             isScan = 2;
         }else{
             s7PLC = new S7PLC(EPlcType.S1500, plcIp1);
-            deviceIp = "80.24.10.";
             isScan = 1;
         }
 
@@ -164,19 +146,15 @@ public class WorkJPanelOP70 extends JPanel {
         // 原西侧/东侧3号机(DB7003)、4号机(DB7004)已取消,C/F位不再实例化
         if(pos.equals("A")){
             plcDb = "DB7001";
-            deviceIp = deviceIp + "43";
             fswDeviceName = "西侧1号机";
         }else if(pos.equals("B")){
             plcDb = "DB7002";
-            deviceIp = deviceIp + "44";
             fswDeviceName = "西侧2号机";
         }else if(pos.equals("D")){
             plcDb = "DB7001";
-            deviceIp = deviceIp + "43";
             fswDeviceName = "东侧1号机";
         }else if(pos.equals("E")){
             plcDb = "DB7002";
-            deviceIp = deviceIp + "44";
             fswDeviceName = "东侧2号机";
         }
 
@@ -439,31 +417,6 @@ public class WorkJPanelOP70 extends JPanel {
             public void run() {
                 if(MesClient.isLogin == 1 && isLocal == 0){
                     try{
-                        initS7();
-                        monitorDevice();
-                        boolean ret = S7Util.getFswAlarm(s7Connector);
-                        if(ret){
-                            errflag = 0;
-                        }
-                        if(!ret && errflag == 0 ){
-                            errflag = 1;
-                            DataUtil.deviceAlarm(oprno+pos,productSn.getText(),oprno+pos+"随动夹具报警",MesClient.user_menu.getText());
-                        }
-                        fswOnline = true;
-                    }catch (Exception e){
-                        log.info(e.getMessage());
-                        fswOnline = false;
-                    }
-
-                    if(fswOnline){
-                        oprnoLabel.setForeground(Color.BLACK);
-                        oprnoLabel2.setForeground(Color.BLACK);
-                    }else{
-                        oprnoLabel.setForeground(Color.RED);
-                        oprnoLabel2.setForeground(Color.RED);
-                    }
-
-                    try{
                         int ret = getAlarm();
                         if(ret == 0){
                             errflag2 = 0;
@@ -649,13 +602,6 @@ public class WorkJPanelOP70 extends JPanel {
             productSnFeeding.setText(sn);
             lastSn = sn;
 
-            //判断刀具寿命
-//            Integer hjjs =  S7Util.formatS7Int(s7Connector.read(DaveArea.DB, 9051, 2, 26));
-//            if(hjjs > 620){
-//                setMenuStatus("搅拌头达到使用寿命,请换搅拌头",-1);
-//                return;
-//            }
-
             // 查询工件质量
             JSONObject retObj = DataUtil.checkQuality(sn,oprno+pos,MesClient.user_menu.getText());
             if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
@@ -899,65 +845,6 @@ public class WorkJPanelOP70 extends JPanel {
         return true;
     }
 
-    public void initS7(){
-        try {
-            if(s7Connector == null) {
-                //PLC地址
-                String ipAddress = deviceIp;
-                //默认端口
-                int port = 102;
-                int rack=0;
-                int slot=3;
-                int timeout=5000;
-                s7Connector=
-                        S7ConnectorFactory
-                                .buildTCPConnector()
-                                .withHost(ipAddress)
-                                .withPort(port) //optional
-//								.withRack(rack) //optional
-//								.withSlot(slot) //optional
-                                .withTimeout(timeout) //连接超时时间
-                                .build();
-                S7Serializer s7Serializer2L = S7SerializerFactory.buildSerializer(s7Connector);
-            }
-        } catch (Exception e) { // 如果连接失败保存失败再次尝试连接一次
-            s7Connector = null;
-            e.printStackTrace();
-        }
-    }
-
-    public void monitorDevice() {
-//        log.info("monitorDevice");
-        if (tjFlag == 2) {
-            try {
-                String zzzs = S7Util.formatS7Val(s7Connector.read(DaveArea.DB, 9051, 4, 0)); //主轴转速
-                String jgsd = S7Util.formatS7Val(s7Connector.read(DaveArea.DB, 9051, 4, 4));  //进给速度
-                String zzzb = S7Util.formatS7Val(s7Connector.read(DaveArea.DB, 9051, 4, 8));  //Z轴坐标
-                String ylz = S7Util.formatS7Val(s7Connector.read(DaveArea.DB, 9051, 4, 12));  //压力值
-                Integer hjjs = S7Util.formatS7Int(s7Connector.read(DaveArea.DB, 9051, 2, 26));  //焊接件数
-                String hjcd = S7Util.formatS7Val(s7Connector.read(DaveArea.DB, 9051, 4, 28));    //焊接长度
-                String hjms = S7Util.formatS7Val(s7Connector.read(DaveArea.DB, 9051, 4, 32));    //焊接磨损
-                String record_time = DateLocalUtils.getCurrentTime();
-//                log.info(oprno + pos + "摩擦焊参数采集 ->   主轴转速: {}, 进给速度: {}, Z轴坐标: {}, 压力值: {}, 焊接件数: {}, 焊接长度: {}, 耗时: {}", zzzs, jgsd, zzzb, ylz, hjjs, hjcd, hjms,record_time );
-                hjparams.add(zzzs + "|" + jgsd + "|" + zzzb + "|" + ylz + "|" + hjjs + "|" + hjcd + "|" + hjms + "|" + record_time);
-                if (hjparams.size() == 60  && productSn.getText() != null && !productSn.getText().trim().isEmpty() ) {
-                    JdbcUtils.insertParamData(oprno+pos,MesClient.mes_line_sn,productSn.getText(), JSON.toJSONString(hjparams));
-                    hjparams = new ArrayList<>();
-                }else {
-//                    log.info("未执行插入");
-                }
-            } catch (Exception e) {
-                e.printStackTrace();
-                s7Connector = null;
-            }
-        } else {
-            if (hjparams.size() > 0 && !productSn.getText().trim().isEmpty() && productSn.getText().trim() != null ) {
-                JdbcUtils.insertParamData(oprno+pos,MesClient.mes_line_sn,productSn.getText(), JSON.toJSONString(hjparams));
-                hjparams = new ArrayList<>();
-            }
-        }
-    }
-
     public int getAlarm(){
         boolean ret0 = readBoolean(plcDb+".6.0");
         if(ret0){

+ 0 - 29
src/com/mes/util/JdbcUtils.java

@@ -162,35 +162,6 @@ public class JdbcUtils {
 		return true;
 	}
 
-	//插入数据
-	public static boolean insertParamData(String oprno, String line_sn, String sn,String content) {
-		if (sn == null || sn.trim().isEmpty()) {
-			return false;
-		}
-//		log.info("插入数据执行");
-		JdbcUtils.getConn();
-		boolean ret = false;
-		String record_time = DateLocalUtils.getCurrentTime();
-		try {
-			// 确保连接已经打开
-			if (JdbcUtils.conn == null || JdbcUtils.conn.isClosed()) {
-				JdbcUtils.openConnection();
-			}
-			//创建连接对象,是Java的一个操作数据库的重要接口
-			Statement statement=conn.createStatement();
-			statement.executeUpdate("INSERT INTO bw_params (oprno,line_sn,sn,content,create_time) VALUES"
-					+ " ('"+oprno+"', '"+line_sn+"', '"+sn+"', '"+content+"','"+record_time+"')");//向数据库中插入数据
-			statement.close();
-			ret = true;
-		} catch (SQLException e) {
-			// TODO Auto-generated catch block
-			//e.printStackTrace();
-			ret = false;
-		}
-
-		return ret;
-	}
-
 	public static void updateProdSync(Integer id,Integer sync) throws SQLException {
 		Connection conn = JdbcUtils.getConn();
 		Statement statement=conn.createStatement();   //创建连接对象,是Java的一个操作数据库的重要接口

+ 0 - 132
src/com/mes/util/S7Util.java

@@ -1,132 +0,0 @@
-package com.mes.util;
-
-import com.github.s7connector.api.DaveArea;
-import com.github.s7connector.api.S7Connector;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.math.BigInteger;
-import java.text.DecimalFormat;
-
-public class S7Util {
-    public static final Logger log =  LoggerFactory.getLogger(S7Util.class);
-
-    public static Boolean getFswAlarm(S7Connector s7Connector){
-        byte[] bytes1 = s7Connector.read(DaveArea.DB, 9051, 1, 24);
-        int alarm242 = getBit(bytes1[0],5);
-        if(alarm242 == 1){
-            return false;
-        }
-        int alarm243 = getBit(bytes1[0],4);
-        if(alarm243 == 1){
-            return false;
-        }
-        int alarm244 = getBit(bytes1[0],3);
-        if(alarm244 == 1){
-            return false;
-        }
-        int alarm245 = getBit(bytes1[0],2);
-        if(alarm245 == 1){
-            return false;
-        }
-        int alarm246 = getBit(bytes1[0],1);
-        if(alarm246 == 1){
-            return false;
-        }
-        int alarm247 = getBit(bytes1[0],0);
-        if(alarm247 == 1){
-            return false;
-        }
-
-        byte[] bytes2 = s7Connector.read(DaveArea.DB, 9051, 1, 25);
-        int alarm250 = getBit(bytes2[0],7);
-        if(alarm250 == 1){
-            return false;
-        }
-
-        int alarm251 = getBit(bytes2[0],6);
-        if(alarm251 == 1){
-            return false;
-        }
-
-        int alarm252 = getBit(bytes2[0],5);
-        if(alarm252 == 1){
-            return false;
-        }
-
-        int alarm253 = getBit(bytes2[0],4);
-        if(alarm253 == 1){
-            return false;
-        }
-
-        int alarm254 = getBit(bytes2[0],3);
-        if(alarm254 == 1){
-            return false;
-        }
-
-        int alarm255 = getBit(bytes2[0],2);
-        if(alarm255 == 1){
-            return false;
-        }
-
-        int alarm256 = getBit(bytes2[0],1);
-        if(alarm256 == 1){
-            return false;
-        }
-
-        return true;
-
-    }
-
-    // 格式化s7取出的值
-    public static String formatS7Val(byte[] val){
-        int intValue = new BigInteger(xtob(val)).intValue();
-        float floatValue = Float.intBitsToFloat(intValue);
-
-        // 保留1位小数
-        DecimalFormat df = new DecimalFormat("#.#");
-        df.setMaximumFractionDigits(1);
-        String result = df.format(floatValue);
-        float roundedNum = Float.parseFloat(result);
-
-        return roundedNum+"";
-    }
-
-    // 转大端排序
-    private static byte[] xtob( byte[] bytes){
-        return bytes;
-//        // 创建新的byte数组并复制原始数据
-//        byte[] reversedBytes = new byte[bytes.length];
-//        System.arraycopy(bytes, 0, reversedBytes, 0, bytes.length);
-//
-//        // 反转byte数组元素的位置
-//        for (int i = 0; i < bytes.length / 2; i++) {
-//            byte temp = reversedBytes[i];
-//            reversedBytes[i] = reversedBytes[reversedBytes.length - 1 - i];
-//            reversedBytes[reversedBytes.length - 1 - i] = temp;
-//        }
-//        return reversedBytes;
-    }
-
-    private static String byteToBinaryString(byte[] byteArray) {
-        StringBuilder binaryString = new StringBuilder();
-        for (byte b : byteArray) {
-            binaryString.append(String.format("%8s", Integer.toBinaryString(b & 0xFF)).replace(' ', '0'));
-        }
-        return binaryString.toString();
-    }
-
-    public static int getBit(byte b, int n) {
-        // 将byte转换为二进制字符串
-        String binaryString = Integer.toBinaryString(b & 0xFF);
-        // 补足位数到8位
-        binaryString = String.format("%8s", binaryString).replace(' ', '0');
-        // 获取第n位的字符,然后转换为整数
-        return binaryString.charAt(n) == '1' ? 1 : 0;
-    }
-
-    public static Integer formatS7Int(byte[] val){
-        return new BigInteger(xtob(val)).intValue();
-    }
-
-}

+ 0 - 64
src/com/mes/util/Test01.java

@@ -1,64 +0,0 @@
-package com.mes.util;
-
-import com.github.s7connector.api.DaveArea;
-import com.github.s7connector.api.S7Connector;
-import com.github.s7connector.api.factory.S7ConnectorFactory;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class Test01 {
-    private static final Logger log = LoggerFactory.getLogger(Test01.class);
-
-    private final String ipAddress;
-    private final int port;
-    private final int timeout;
-    private S7Connector s7Connector;
-
-    // 1. 构造函数注入:允许在测试时传入不同的配置
-    public Test01(String ipAddress, int port, int timeout) {
-        this.ipAddress = ipAddress;
-        this.port = port;
-        this.timeout = timeout;
-    }
-
-    // 2. 默认构造函数:保留原有的生产逻辑
-    public Test01() {
-        this("80.24.10.42", 102, 5000);
-    }
-
-    // 3. 允许外部设置连接器:这对使用 Mock 对象(模拟对象)进行单元测试至关重要
-    public void setS7Connector(S7Connector s7Connector) {
-        this.s7Connector = s7Connector;
-    }
-
-    public void initS7() {
-        if (this.s7Connector != null) {
-            return; // 如果已经注入了模拟连接器,则不再创建真实连接
-        }
-
-        try {
-            log.info("正在尝试连接 PLC: {}:{}", ipAddress, port);
-            this.s7Connector = S7ConnectorFactory
-                    .buildTCPConnector()
-                    .withHost(ipAddress)
-                    .withPort(port)
-                    .withTimeout(timeout)
-                    .build();
-
-            Integer hjjs =  S7Util.formatS7Int(s7Connector.read(DaveArea.DB, 9051, 2, 26));
-            System.out.println("寿命值"+hjjs);
-        } catch (Exception e) {
-            log.error("PLC 连接初始化失败: {}", e.getMessage());
-            throw new RuntimeException("无法连接到 PLC", e);
-        }
-    }
-
-    public S7Connector getS7Connector() {
-        return s7Connector;
-    }
-
-    public static void main(String[] args) {
-        Test01 service = new Test01(); // 生产环境使用
-        service.initS7();
-    }
-}