|
|
@@ -5,6 +5,7 @@ import com.github.xingshuangs.iot.protocol.s7.enums.EPlcType;
|
|
|
import com.github.xingshuangs.iot.protocol.s7.service.S7PLC;
|
|
|
import com.mes.component.MesRadio;
|
|
|
import com.mes.component.MesWebView;
|
|
|
+import com.mes.device.DeviceStateReporter;
|
|
|
import com.mes.util.*;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
@@ -34,6 +35,7 @@ public class MesClient extends JFrame {
|
|
|
public static String mes_server_ip = ""; // 服务器IP地址
|
|
|
public static int mes_heart_icon_cycle = 1;
|
|
|
public static String mes_line_sn = ""; // 产线编号
|
|
|
+ public static int mes_device_heartbeat_minutes = 5; // 设备状态上报间隔(分钟)
|
|
|
public static String csyq = "";
|
|
|
|
|
|
//session
|
|
|
@@ -128,12 +130,22 @@ public class MesClient extends JFrame {
|
|
|
mes_line_sn = pro.getProperty("mes.line_sn");
|
|
|
csyq = pro.getProperty("mes.csyq");
|
|
|
mes_gw_des = OprnoUtil.getGwDes(mes_line_sn,mes_gw);
|
|
|
+ try {
|
|
|
+ mes_device_heartbeat_minutes = Integer.parseInt(pro.getProperty("mes.device.heartbeat.minutes", "5").trim());
|
|
|
+ } catch (Exception e) {
|
|
|
+ mes_device_heartbeat_minutes = 5;
|
|
|
+ }
|
|
|
+ if (mes_device_heartbeat_minutes <= 0) {
|
|
|
+ mes_device_heartbeat_minutes = 5;
|
|
|
+ }
|
|
|
log.info(mes_gw + ";" + mes_gw_des + ";" + mes_server_ip + ";");
|
|
|
}
|
|
|
|
|
|
//启动心跳包程序
|
|
|
public static java.util.Timer heartBeatTimer;
|
|
|
public static java.util.Timer heartBeatIconTimer;
|
|
|
+ // 设备状态定时上报
|
|
|
+ public static java.util.Timer deviceReportTimer;
|
|
|
public static boolean iconREDFlag = true;
|
|
|
public static void startHeartBeatTimer() {
|
|
|
if(heartBeatTimer!=null) {
|
|
|
@@ -160,6 +172,49 @@ public class MesClient extends JFrame {
|
|
|
}, 100,mes_heart_icon_cycle*1000);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 启动设备状态定时上报
|
|
|
+ */
|
|
|
+ public static void startDeviceReportTimer() {
|
|
|
+ stopDeviceReportTimer();
|
|
|
+ long intervalMs = mes_device_heartbeat_minutes * 60L * 1000L;
|
|
|
+ deviceReportTimer = new Timer("device-report-timer", true);
|
|
|
+ deviceReportTimer.schedule(new TimerTask() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ DeviceStateReporter.getInstance().reportAsync(DeviceStateReporter.STATE_RUNNING, "运行心跳");
|
|
|
+ }
|
|
|
+ }, intervalMs, intervalMs);
|
|
|
+ log.info("设备状态定时上报已启动,间隔 {} 分钟", mes_device_heartbeat_minutes);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 停止设备状态定时上报
|
|
|
+ */
|
|
|
+ public static void stopDeviceReportTimer() {
|
|
|
+ if (deviceReportTimer != null) {
|
|
|
+ deviceReportTimer.cancel();
|
|
|
+ deviceReportTimer = null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 登录成功后上报设备开机状态
|
|
|
+ */
|
|
|
+ public static void reportDeviceRunning() {
|
|
|
+ DeviceStateReporter.getInstance().init(mes_server_ip, mes_gw, mes_line_sn);
|
|
|
+ DeviceStateReporter.getInstance().reportAsync(DeviceStateReporter.STATE_RUNNING, "工位登录,设备开机");
|
|
|
+ startDeviceReportTimer();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 退出或关闭时上报设备停机状态
|
|
|
+ */
|
|
|
+ public static void reportDeviceStopped() {
|
|
|
+ stopDeviceReportTimer();
|
|
|
+ DeviceStateReporter.getInstance().reportSync(DeviceStateReporter.STATE_STOP, "工位退出,设备停机");
|
|
|
+ }
|
|
|
+
|
|
|
//设置tcp连接状态显示
|
|
|
public static void setTcpStatus() {
|
|
|
status_menu.setText("已连接MES服务器");
|
|
|
@@ -172,7 +227,9 @@ public class MesClient extends JFrame {
|
|
|
}
|
|
|
|
|
|
public static void resetScanA() {
|
|
|
- work_status = 0;
|
|
|
+ JSONObject retObj = DataUtil.delCurSn(MesClient.mes_gw, mes_server_ip, mes_line_sn);
|
|
|
+ if (retObj.get("result")!=null && retObj.get("result").toString().equalsIgnoreCase("true")) {
|
|
|
+ work_status = 0;
|
|
|
check_quality_result = false;
|
|
|
MesClient.finish_ok_bt.setEnabled(false);
|
|
|
MesClient.finish_ng_bt.setEnabled(false);
|
|
|
@@ -185,6 +242,9 @@ public class MesClient extends JFrame {
|
|
|
|
|
|
updateMaterailData();
|
|
|
// shiftUserCheck();
|
|
|
+ } else {
|
|
|
+ MesClient.setMenuStatus("刷新失败",0);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public static int userLoginHours;//用户登录所处小时
|
|
|
@@ -297,6 +357,11 @@ public class MesClient extends JFrame {
|
|
|
}
|
|
|
|
|
|
public static void logoff() {
|
|
|
+ reportDeviceStopped();
|
|
|
+ if (getSnBeatTimer != null) {
|
|
|
+ getSnBeatTimer.cancel();
|
|
|
+ getSnBeatTimer = null;
|
|
|
+ }
|
|
|
welcomeWin.setVisible(true);
|
|
|
mesClientFrame.setVisible(false);
|
|
|
}
|
|
|
@@ -314,8 +379,8 @@ public class MesClient extends JFrame {
|
|
|
public void windowClosing(WindowEvent e) {
|
|
|
int choice = JOptionPane.showConfirmDialog(null, "确定要关闭窗口吗?", "关闭确认", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
|
|
|
if (choice == JOptionPane.YES_OPTION) {
|
|
|
- // 如果用户点击“是”,则关闭窗口
|
|
|
- dispose(); // 释放窗口资源并关闭窗口
|
|
|
+ reportDeviceStopped();
|
|
|
+ dispose();
|
|
|
System.exit(0);
|
|
|
}
|
|
|
}
|
|
|
@@ -713,8 +778,6 @@ public class MesClient extends JFrame {
|
|
|
}
|
|
|
}
|
|
|
} else if (work_status == 0) {
|
|
|
- String abc = PLCUtils.getResult(plc);
|
|
|
- System.out.println(abc);
|
|
|
JSONObject result = DataUtil.getCurSn(mes_gw, mes_server_ip, mes_line_sn);
|
|
|
// 正常处理结果
|
|
|
if (result.containsKey("data")) {
|
|
|
@@ -737,6 +800,9 @@ public class MesClient extends JFrame {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ String abc = PLCUtils.getResult(plc);
|
|
|
+ System.out.println(abc);
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
|