|
@@ -171,13 +171,8 @@ public class MesClient extends JFrame {
|
|
|
//读文件配置
|
|
//读文件配置
|
|
|
readProperty();
|
|
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();
|
|
getMaterailData();
|
|
|
|
|
|
|
|
-// startUpdateQualityTimer();
|
|
|
|
|
-
|
|
|
|
|
-// S7Util.sendStartSignal(true);
|
|
|
|
|
-//
|
|
|
|
|
-// boolean ret = S7Util.getDeviceStart();
|
|
|
|
|
-// System.out.println(ret);
|
|
|
|
|
-
|
|
|
|
|
monitorDevice();
|
|
monitorDevice();
|
|
|
|
|
|
|
|
fswCheckPoint();
|
|
fswCheckPoint();
|
|
@@ -1089,106 +1077,42 @@ public class MesClient extends JFrame {
|
|
|
tabbedPane.addTab("绑定物料", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), indexScrollPaneB, null);
|
|
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(){
|
|
public static void formatMesStatus(){
|