hzd 1 viikko sitten
vanhempi
commit
7c451f513b
3 muutettua tiedostoa jossa 182 lisäystä ja 9 poistoa
  1. 26 0
      src/com/mes/ui/DataUtil.java
  2. 126 5
      src/com/mes/ui/MesClient.java
  3. 30 4
      src/com/mes/ui/S7Util.java

+ 26 - 0
src/com/mes/ui/DataUtil.java

@@ -245,6 +245,32 @@ public class DataUtil {
         }
     }
 
+    public static JSONObject saveFswPoint(String sn,String point1,String point2,String point3,String point4) {
+        try{
+            String enconding = "UTF-8";
+            InputStream is = ClassLoader.getSystemResourceAsStream("config/config.properties");
+            Properties pro = new Properties();
+            BufferedReader br = new BufferedReader(new InputStreamReader(is, enconding));
+            pro.load(br);
+            String mes_server_ip = pro.getProperty("mes.server_ip");
+            String oprno = pro.getProperty("mes.gw").trim();
+            String lineSn = pro.getProperty("mes.line_sn").trim();
+            String url = "http://"+mes_server_ip+":8980/js/a/mes/mesMaterialPrebind/bind";
+            String params = "__ajax=json&oprno="+oprno+"&lineSn="+lineSn+"&sn="+sn+"&point1="+point1+"&point2="+point2+"&point3="+point3+"&point4="+point4+"&point4="+point4;
+            System.out.println("params="+params);
+            String result = doPost(url,params);
+            System.out.println("result="+result);
+
+            if(result.equalsIgnoreCase("false")) {
+                return null;
+            }else {
+                return JSONObject.parseObject(result);
+            }
+        }catch (Exception e){
+            return null;
+        }
+    }
+
     public static String doPost(String httpUrl, String param) {
         HttpURLConnection connection = null;
         InputStream is = null;

+ 126 - 5
src/com/mes/ui/MesClient.java

@@ -103,6 +103,10 @@ public class MesClient extends JFrame {
 
     public static JLabel fxlabel;
 
+    public static JLabel fxlabel2;
+
+    public static Integer fxlabel2Flag = 0;
+
 //    public static String plcUrl = "192.168.88.89"; // 180AF
 
     public static String plcUrl = "192.168.88.99"; // 180BE  280AB
@@ -149,6 +153,11 @@ public class MesClient extends JFrame {
     // 显示组件
     public static JLabel spindleSpeedLabel;
     public static JLabel feedRateLabel;
+    public static JLabel torqueLabel;
+
+    public static Integer curPoint = 0;
+    public static List<String> curPointX = new ArrayList<>();
+    public static List<String> curPointY = new ArrayList<>();
 
     public static void main(String[] args) {
         if (LockUtil.getInstance().isAppActive() == true){
@@ -191,6 +200,8 @@ public class MesClient extends JFrame {
 
                     monitorDevice();
 
+                    fswCheckPoint();
+
                 }catch (Exception e){
                     e.printStackTrace();
                 }
@@ -311,12 +322,14 @@ public class MesClient extends JFrame {
                         // 读取转速和进给
                         actSpindleSpeed = S7Util.readActSpindleSpeed(s7PLC);
                         feedRate = S7Util.readFeedRate(s7PLC);
+                        final double torque = S7Util.readTorque(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));
+                            torqueLabel.setText(String.format("扭矩: %.1f ", torque));
                         });
                         // 存储数据
                         final String currentSn = product_sn.getText();
@@ -370,6 +383,78 @@ public class MesClient extends JFrame {
         }, 1000, 30*1000);  // 首次延迟1秒,之后每30秒执行
     }
 
+    public static java.util.Timer fswCheckPointTimer;
+
+    public static void fswCheckPoint() {
+        if(fswCheckPointTimer != null) {
+            fswCheckPointTimer.cancel();
+        }
+        fswCheckPointTimer = new java.util.Timer();
+        fswCheckPointTimer.schedule(new TimerTask() {
+            public void run() {
+                try{
+                    if(work_status == 1 && fxlabel2Flag == 1){ // 获取点位
+                        boolean ret = S7Util.getParamFlag();
+                        if(ret){
+                            curPoint += 1;
+                            curPointX.add(String.valueOf(S7Util.readXPosition()));
+                            curPointY.add(String.valueOf(S7Util.readYPosition()));
+                        }
+
+                        if(curPoint == 4){
+                            String pointx1 = "";
+                            String pointx2 = "";
+                            String pointx3 = "";
+                            String pointx4 = "";
+                            String pointy1 = "";
+                            String pointy2 = "";
+                            String pointy3 = "";
+                            String pointy4 = "";
+                            int i = 0;
+                            for(String str : curPointX){
+                                if(i == 0){
+                                    pointx1 = str;
+                                }else if(i == 1){
+                                    pointx2 = str;
+                                }else if(i == 2){
+                                    pointx3 = str;
+                                }else if(i == 3){
+                                    pointx4 = str;
+                                }
+                                i++;
+                            }
+
+                            int j = 0;
+                            for(String str : curPointX){
+                                if(i == 0){
+                                    pointy1 = str;
+                                }else if(i == 1){
+                                    pointy2 = str;
+                                }else if(i == 2){
+                                    pointy3 = str;
+                                }else if(i == 3){
+                                    pointy4 = str;
+                                }
+                                j++;
+                            }
+
+                            JSONObject retObj = DataUtil.saveFswPoint(product_sn.getText(),pointx1+"_"+pointy1,pointx2+"_"+pointy2,pointx3+"_"+pointy3,pointx4+"_"+pointy4);
+                            if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
+                                MesClient.curPointX.clear();
+                                MesClient.curPointY.clear();
+                                MesClient.curPoint = 0;
+                            }
+
+                        }
+                    }
+
+                }catch (Exception e){
+                    log.info("异常: " + e.getMessage());
+                }
+            }
+        }, 1000, 500);  // 首次延迟1秒,之后每30秒执行
+    }
+
     //设置tcp连接状态显示
     public static void setTcpStatus() {
         if(tcp_connect_flag) {
@@ -404,8 +489,12 @@ public class MesClient extends JFrame {
         MesClient.status_menu.setText("请扫工件码");
         S7Util.sendStartSignal(true);
 
+        MesClient.curPointX.clear();
+        MesClient.curPointY.clear();
+        MesClient.curPoint = 0;
+
         updateMaterailData();
-        shiftUserCheck();
+//        shiftUserCheck();
     }
 
     public static int userLoginHours;//用户登录所处小时
@@ -615,6 +704,25 @@ public class MesClient extends JFrame {
         });
         settingMenu.add(mes_block_menu);
 
+        JMenuItem resetTcpMenu_2 = new JMenuItem("程序点检");
+        resetTcpMenu_2.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png")));
+        resetTcpMenu_2.setFont(new Font("微软雅黑", Font.PLAIN, 20));
+        resetTcpMenu_2.addMouseListener(new MouseAdapter() {
+            @Override
+            public void mousePressed(MouseEvent e) {
+                super.mouseClicked(e);
+//                resetScanA();
+                boolean ret = fxlabel2Flag == 1?false:true;
+                if(fxlabel2Flag == 1){
+                    fxlabel2Flag = 0;
+                }else{
+                    fxlabel2Flag = 1;
+                }
+                fxlabel2.setVisible(ret);
+            }
+        });
+        settingMenu.add(resetTcpMenu_2);
+
         contentPane = new JPanel();
         contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
         setContentPane(contentPane);
@@ -718,6 +826,14 @@ public class MesClient extends JFrame {
         indexScrollPaneA = new JScrollPane(indexPanelA);
         indexPanelA.setLayout(null);
 
+        fxlabel2 = new JLabel("程序点检中");
+        fxlabel2.setFont(new Font("微软雅黑", Font.PLAIN, 24));
+        fxlabel2.setBounds(81, 0, 810, 70);
+        fxlabel2.setForeground(Color.RED);
+        fxlabel2.setHorizontalAlignment(SwingConstants.CENTER);
+        fxlabel2.setVisible(false);
+        indexPanelA.add(fxlabel2);
+
         product_sn = new JTextField();
         product_sn.setHorizontalAlignment(SwingConstants.CENTER);
         product_sn.setEditable(false);
@@ -821,18 +937,23 @@ public class MesClient extends JFrame {
 
         // 转速显示
         spindleSpeedLabel = new JLabel("转速: 0 rpm");
-        spindleSpeedLabel.setBounds(81, 240, 400, 40);
+        spindleSpeedLabel.setBounds(81, 200, 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.setBounds(320, 200, 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);
+        // 扭矩显示
+        torqueLabel = new JLabel("扭矩: 0");
+        torqueLabel.setBounds(600, 200, 400, 40);
+        torqueLabel.setFont(new Font("微软雅黑", Font.PLAIN, 20));
+        indexPanelA.add(torqueLabel);
 
+        tabbedPane.addTab("开班点检", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), searchScrollPaneDj, null);
 
         indexPanelB = new JPanel();
         searchScrollPane = new JScrollPane(indexPanelB);
@@ -1092,7 +1213,7 @@ public class MesClient extends JFrame {
 //				int port = 102;
                 int rack=0;
                 int slot=3;
-                int timeout=5000;
+                int timeout=1000;
                 s7Connector=
                         S7ConnectorFactory
                                 .buildTCPConnector()

+ 30 - 4
src/com/mes/ui/S7Util.java

@@ -398,11 +398,37 @@ public class S7Util {
         }
     }
 
+    // 读取扭矩值 - DB4900.DBD364 (4字节浮点数)
+    public static double readTorque(S7PLC s7PLC){
+        try {
+            MesClient.initS7();
+            byte[] data = MesClient.s7Connector.read(DaveArea.DB, 4900, 4, 364);
+            return formatS7Float(data);
+        } catch (Exception e) {
+            return 0;
+        }
+    }
+
+    // DB9043.DBX120.0
+    public static Boolean getParamFlag() {
+        try {
+            MesClient.initS7();
+            // 读取 DB9043.DBB0(1字节,包含 DBX0.0~DBX0.7)        1个字节,从第0个字节开始
+            byte[] data9015 = MesClient.s7Connector.read(DaveArea.DB, S7Util.db, 1, 120);
+            byte b9015 = data9015[0];
+            Boolean result = (b9015 & (1 << 0)) != 0;
+            return result;
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return false;
+    }
+
     // 读取X位移 - DB5700.DBD0 (4字节浮点数)
-    public static double readXPosition(S7PLC s7PLC){
+    public static double readXPosition(){
         try {
             MesClient.initS7();
-            byte[] data = MesClient.s7Connector.read(DaveArea.DB, 5700, 4, 32);
+            byte[] data = MesClient.s7Connector.read(DaveArea.DB, 5700, 4, 0);
             return formatS7Float(data);
         } catch (Exception e) {
             return 0;
@@ -410,10 +436,10 @@ public class S7Util {
     }
 
     // 读取Y位移 - DB5701.DBD0 (4字节浮点数)
-    public static double readYPosition(S7PLC s7PLC){
+    public static double readYPosition(){
         try {
             MesClient.initS7();
-            byte[] data = MesClient.s7Connector.read(DaveArea.DB, 5701, 4, 32);
+            byte[] data = MesClient.s7Connector.read(DaveArea.DB, 5701, 4, 0);
             return formatS7Float(data);
         } catch (Exception e) {
             return 0;