|
|
@@ -1,5 +1,6 @@
|
|
|
package com.mes.ui;
|
|
|
|
|
|
+import com.alibaba.fastjson2.JSON;
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
import com.github.s7connector.api.S7Connector;
|
|
|
import com.github.s7connector.api.S7Serializer;
|
|
|
@@ -35,6 +36,8 @@ import java.sql.SQLException;
|
|
|
import java.sql.Statement;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.Properties;
|
|
|
import java.util.Timer;
|
|
|
import java.util.TimerTask;
|
|
|
@@ -100,9 +103,9 @@ public class MesClient extends JFrame {
|
|
|
|
|
|
public static JLabel fxlabel;
|
|
|
|
|
|
- public static String plcUrl = "192.168.88.89"; // 180AF
|
|
|
+// public static String plcUrl = "192.168.88.89"; // 180AF
|
|
|
|
|
|
-// public static String plcUrl = "192.168.88.99"; // 180BE 280AB
|
|
|
+ public static String plcUrl = "192.168.88.99"; // 180BE 280AB
|
|
|
|
|
|
public static S7PLC s7PLC = new S7PLC(EPlcType.SINUMERIK_828D, plcUrl);
|
|
|
|
|
|
@@ -135,6 +138,18 @@ public class MesClient extends JFrame {
|
|
|
|
|
|
public static String programNo = "";
|
|
|
|
|
|
+
|
|
|
+ // 设备实时参数
|
|
|
+ public static double actSpindleSpeed = 0; // 主轴转速
|
|
|
+ public static double feedRate = 0; // 进给速度
|
|
|
+
|
|
|
+ // 数据缓存
|
|
|
+ public static List<String> deviceParams = new ArrayList<>();
|
|
|
+
|
|
|
+ // 显示组件
|
|
|
+ public static JLabel spindleSpeedLabel;
|
|
|
+ public static JLabel feedRateLabel;
|
|
|
+
|
|
|
public static void main(String[] args) {
|
|
|
if (LockUtil.getInstance().isAppActive() == true){
|
|
|
// JOptionPane.showMessageDialog(null, "已有一个程序在运行,程序退出");
|
|
|
@@ -280,6 +295,81 @@ public class MesClient extends JFrame {
|
|
|
}, 100,mes_heart_icon_cycle*1000);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ // 设备参数读取定时器
|
|
|
+ public static java.util.Timer deviceParamTimer;
|
|
|
+
|
|
|
+ public static void startDeviceParamTimer() {
|
|
|
+ if(deviceParamTimer != null) {
|
|
|
+ deviceParamTimer.cancel();
|
|
|
+ }
|
|
|
+ deviceParamTimer = new java.util.Timer();
|
|
|
+ deviceParamTimer.schedule(new TimerTask() {
|
|
|
+ public void run() {
|
|
|
+ try {
|
|
|
+ if (work_status == 1){
|
|
|
+ // 读取转速和进给
|
|
|
+ actSpindleSpeed = S7Util.readActSpindleSpeed(s7PLC);
|
|
|
+ feedRate = S7Util.readFeedRate(s7PLC);
|
|
|
+ // 更新UI
|
|
|
+ final double spindle = actSpindleSpeed;
|
|
|
+ final double feed = feedRate;
|
|
|
+ SwingUtilities.invokeLater(() -> {
|
|
|
+ spindleSpeedLabel.setText(String.format("转速: %.1f rpm", spindle));
|
|
|
+ feedRateLabel.setText(String.format("进给: %.1f mm/min", feed));
|
|
|
+ });
|
|
|
+ // 存储数据
|
|
|
+ final String currentSn = product_sn.getText();
|
|
|
+ if(currentSn != null && !currentSn.isEmpty()) {
|
|
|
+ String record_time = DateLocalUtils.getCurrentTime();
|
|
|
+ deviceParams.add(actSpindleSpeed + "|" + feedRate + "|" + record_time);
|
|
|
+ if(deviceParams.size() == 60) {
|
|
|
+ try {
|
|
|
+ JdbcUtils.insertDeviceParamData(mes_gw, mes_line_sn, currentSn, JSON.toJSONString(deviceParams));
|
|
|
+ log.info("设备参数数据已存储: " + currentSn);
|
|
|
+ deviceParams = new ArrayList<>();
|
|
|
+ }catch (Exception e) {
|
|
|
+ log.info("存储设备参数异常: " + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.info("读取设备参数异常: " + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }, 100, 500); // 首次延迟100ms,之后每500ms执行
|
|
|
+ }
|
|
|
+
|
|
|
+ // 设备参数上传定时器
|
|
|
+ public static java.util.Timer upDeviceParamsTimer;
|
|
|
+
|
|
|
+ public static void startUpDeviceParamsTimer() {
|
|
|
+ if(upDeviceParamsTimer != null) {
|
|
|
+ upDeviceParamsTimer.cancel();
|
|
|
+ }
|
|
|
+ upDeviceParamsTimer = new java.util.Timer();
|
|
|
+ upDeviceParamsTimer.schedule(new TimerTask() {
|
|
|
+ public void run() {
|
|
|
+ try{
|
|
|
+ List<Map<String, Object>> prods = JdbcUtils.getDeviceParams();
|
|
|
+ System.out.println("prods:"+ JSON.toJSONString(prods));
|
|
|
+ if(prods.size() > 0){
|
|
|
+ JSONObject retObj = DataUtil.upDeviceParams(JSON.toJSONString(prods));
|
|
|
+ if(retObj != null && retObj.get("result") != null && retObj.get("result").toString().equalsIgnoreCase("true")) {
|
|
|
+ for(Map<String, Object> prodReq : prods) {
|
|
|
+ JdbcUtils.updateDeviceParamSync(Integer.valueOf(prodReq.get("id").toString()), 1);
|
|
|
+ }
|
|
|
+ log.info("设备参数数据上传成功,数量: " + prods.size());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+ log.info("上传设备参数异常: " + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }, 1000, 30*1000); // 首次延迟1秒,之后每30秒执行
|
|
|
+ }
|
|
|
+
|
|
|
//设置tcp连接状态显示
|
|
|
public static void setTcpStatus() {
|
|
|
if(tcp_connect_flag) {
|
|
|
@@ -404,6 +494,13 @@ public class MesClient extends JFrame {
|
|
|
// JOptionPane.showMessageDialog(mesClientFrame,"设备未连接Mes服务器","提示窗口", JOptionPane.INFORMATION_MESSAGE);
|
|
|
return;
|
|
|
}
|
|
|
+ //弹框扫码,如果和规定的工装编号一致才可以继续
|
|
|
+ String scanBarcode1 = JOptionPane.showInputDialog(null, "请扫工装二维码");
|
|
|
+ if (!scanBarcode1.equalsIgnoreCase("OP280A")){
|
|
|
+ //菜单栏给出提示信息
|
|
|
+ MesClient.setMenuStatus("请扫正确的工装二维码",-1);
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
// 查询工件质量
|
|
|
Boolean sendret = DataUtil.checkQuality(nettyClient,barcode36,user20);
|
|
|
@@ -722,6 +819,18 @@ public class MesClient extends JFrame {
|
|
|
searchScrollPaneDj = new JScrollPane(indexPanelC);
|
|
|
indexPanelC.setLayout(null);
|
|
|
|
|
|
+ // 转速显示
|
|
|
+ spindleSpeedLabel = new JLabel("转速: 0 rpm");
|
|
|
+ spindleSpeedLabel.setBounds(81, 240, 400, 40);
|
|
|
+ spindleSpeedLabel.setFont(new Font("微软雅黑", Font.PLAIN, 20));
|
|
|
+ indexPanelA.add(spindleSpeedLabel);
|
|
|
+
|
|
|
+ // 进给显示
|
|
|
+ feedRateLabel = new JLabel("进给: 0 mm/min");
|
|
|
+ feedRateLabel.setBounds(500, 240, 400, 40);
|
|
|
+ feedRateLabel.setFont(new Font("微软雅黑", Font.PLAIN, 20));
|
|
|
+ indexPanelA.add(feedRateLabel);
|
|
|
+
|
|
|
tabbedPane.addTab("开班点检", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), searchScrollPaneDj, null);
|
|
|
|
|
|
|