hzd 2 روز پیش
والد
کامیت
1455a4d306
2فایلهای تغییر یافته به همراه33 افزوده شده و 109 حذف شده
  1. 29 105
      src/com/mes/ui/MesClient.java
  2. 4 4
      src/com/mes/util/Test.java

+ 29 - 105
src/com/mes/ui/MesClient.java

@@ -171,13 +171,8 @@ public class MesClient extends JFrame {
                     //读文件配置
                     readProperty();
 
-//                    S7Util.sendStartSignal(true);
-//                    S7Util.sendMesStatus(true);
-//
-//                    System.out.println(S7Util.getMesStatus());
-//                    System.out.println(S7Util.getDeviceStatus());
-//                    System.out.println(S7Util.getDeviceStart());
-////                    System.out.println(S7Util.getMesStatus());
+                    s7PLC.setConnectTimeout(500);
+                    s7PLC.setReceiveTimeout(500);
 
 
                     // 显示界面
@@ -191,13 +186,6 @@ public class MesClient extends JFrame {
 
                     getMaterailData();
 
-//                    startUpdateQualityTimer();
-
-//                    S7Util.sendStartSignal(true);
-//
-//                    boolean ret = S7Util.getDeviceStart();
-//                    System.out.println(ret);
-
                     monitorDevice();
 
                     fswCheckPoint();
@@ -1089,106 +1077,42 @@ public class MesClient extends JFrame {
         tabbedPane.addTab("绑定物料", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), indexScrollPaneB, null);
     }
 
-    // 开启发送结果定时任务
-    public static void startUpdateQualityTimer(){
-        // 创建异步线程池
-        ExecutorService executorService = Executors.newSingleThreadExecutor();
-        // 提交任务
-        executorService.submit(() -> {
-            log.info("异步任务执行中...");
-            // 模拟耗时操作
-            try {
-                while (true){
-                    try {
-                        // 确保连接已经打开
-                        if (JdbcUtils.conn == null || JdbcUtils.conn.isClosed()) {
-                            JdbcUtils.openConnection();
-                        }
 
-                        Statement statement = JdbcUtils.conn.createStatement();
-                        String selectSql = "SELECT id, bw FROM submit_record\n" +
-                                "WHERE state = 0 ORDER BY id DESC LIMIT 10";
-                        String updateSql = "UPDATE submit_record \n" +
-                                "SET state = '1'\n" +
-                                "WHERE id = ";
-                        ResultSet rs = statement.executeQuery(selectSql);
-                        while(rs.next()){
-                            int id = rs.getInt("id");
-                            String bw = rs.getString("bw");
-                            // 发送请求
-                            String url = "http://"+MesClient.mes_server_ip+":8980/js/a/mes/mesProductRecord/updateQualityByTiming";
-                            log.info("质量:"+bw);
-                            String s = HttpUtils.sendPostRequestJson(url, bw );
-                            log.info("结果:"+s);
-                            Boolean result = JSONObject.parseObject(s).getBoolean("result");
-                            if(result) {
-                                // 更改状态为 1
-                                statement.executeUpdate(updateSql + id);
-                            }
-                        }
-                        rs.close();
-                        statement.close();
-                    } catch (Exception e) {
-                        log.info(e.getMessage());
-                    }
-                    try {
-                        Thread.sleep(2000);
-                    }catch (Exception e){
-                        log.info(e.getMessage());
-                    }
-                }
-            } catch (Exception e) {
-                log.info(e.getMessage());
-            }
-            log.info("异步任务执行完毕");
-        });
-    }
+    public static java.util.Timer monitorDeviceTimer;
 
-    // 开启发送结果定时任务
-    public static void monitorDevice(){
-        // 创建异步线程池
-        ExecutorService executorService = Executors.newSingleThreadExecutor();
-        // 提交任务
-        executorService.submit(() -> {
-            log.info("监控设备异步任务执行中...");
-            // 模拟耗时操作
-            try {
-                while (true){
-                    try{
-                        formatMesStatus();
-                    }catch (Exception e){
-                        e.printStackTrace();
-                    }
+    public static void monitorDevice() {
+        if(monitorDeviceTimer != null) {
+            monitorDeviceTimer.cancel();
+        }
+        monitorDeviceTimer = new java.util.Timer();
+        monitorDeviceTimer.schedule(new TimerTask() {
+            public void run() {
+                try{
+                    formatMesStatus();
+                }catch (Exception e){
+                    e.printStackTrace();
+                }
 
-                    try {
-                        initS7();
-                        if (mes_flag){
-                            S7Util.getDeviceShield();
-                        }else{
-                            if (work_status == 0){
-                                boolean ss = S7Util.getDeviceStart();
-                                if(!ss){
-                                    S7Util.sendStartSignal(true);
-                                }
+                try {
+                    initS7();
+                    if (mes_flag){
+                        S7Util.getDeviceShield();
+                    }else{
+                        if (work_status == 0){
+                            boolean ss = S7Util.getDeviceStart();
+                            if(!ss){
+                                S7Util.sendStartSignal(true);
                             }
-                            S7Util.getDeviceState();
-
                         }
+                        S7Util.getDeviceState();
 
-                    } catch (Exception e) {
-                        log.info(e.getMessage());
-                    }
-                    try {
-                        Thread.sleep(1000);
-                    }catch (Exception e){
-                        log.info(e.getMessage());
                     }
+
+                } catch (Exception e) {
+                    log.info(e.getMessage());
                 }
-            } catch (Exception e) {
-                log.info(e.getMessage());
             }
-            log.info("异步任务执行完毕");
-        });
+        }, 1000, 1000);  // 首次延迟1秒,之后每30秒执行
     }
 
     public static void formatMesStatus(){

+ 4 - 4
src/com/mes/util/Test.java

@@ -24,10 +24,10 @@ public class Test {
 //        writeBit(9000, 3, 2, false);
 //        Map<String, Boolean> stringBooleanMap2 = readBits();
 //        System.out.println(stringBooleanMap2);
-        System.out.println("读取主轴转速:"+S7Util.readActSpindleSpeed(s7PLC));
-        System.out.println("读取进给速度:"+S7Util.readFeedRate(s7PLC));
-        System.out.println("读取X位移:"+S7Util.readXPosition(s7PLC));
-        System.out.println("读取y位移:"+S7Util.readYPosition(s7PLC));
+//        System.out.println("读取主轴转速:"+S7Util.readActSpindleSpeed(s7PLC));
+//        System.out.println("读取进给速度:"+S7Util.readFeedRate(s7PLC));
+//        System.out.println("读取X位移:"+S7Util.readXPosition(s7PLC));
+//        System.out.println("读取y位移:"+S7Util.readYPosition(s7PLC));
 
 
     }