hzd hace 3 días
padre
commit
a6122fdfb7
Se han modificado 2 ficheros con 139 adiciones y 74 borrados
  1. 136 71
      src/com/mes/component/WorkJPanelDevice.java
  2. 3 3
      src/resources/config/config.properties

+ 136 - 71
src/com/mes/component/WorkJPanelDevice.java

@@ -7,6 +7,7 @@ import com.github.s7connector.api.S7Connector;
 import com.github.s7connector.api.S7Serializer;
 import com.github.s7connector.api.factory.S7ConnectorFactory;
 import com.github.s7connector.api.factory.S7SerializerFactory;
+import com.github.xingshuangs.iot.protocol.common.buff.EByteBuffFormat;
 import com.github.xingshuangs.iot.protocol.modbus.service.ModbusTcp;
 import com.github.xingshuangs.iot.protocol.s7.enums.EPlcType;
 import com.github.xingshuangs.iot.protocol.s7.service.S7PLC;
@@ -117,15 +118,21 @@ public class WorkJPanelDevice extends JPanel {
 
     public  JLabel oprnoLabel;
 
-    // OP170
+    // OP110
 //    public int[] toolNums = { 1,2,3,4,5};
 //    public String[] toolTitle = { "高速端铣刀", "合金铣刀", "合金台阶钻", "合金台阶钻", "合金钻头" };
 //    public String[] toolLife = { "", "", "", "", "" };
 
-    // OP160
-    public int[] toolNums = { 1,2,3,4,5};
-    public String[] toolTitle = { "合金铣刀", "插孔铣刀", "合金台阶钻", "铝用合金钻头", "切削丝锥" };
-    public String[] toolLife = { "", "", "", "", "" };
+//    // OP170
+//    public int[] toolNums = { 1,2,3,4,5};
+//    public String[] toolTitle = { "合金铣刀", "插孔铣刀", "合金台阶钻", "铝用合金钻头", "切削丝锥" };
+//    public String[] toolLife = { "", "", "", "", "" };
+    // OP180
+    public int[] toolNums = new int[10];
+    public String[] toolTitle = new String[10];
+    public String[] toolLife = new String[10];
+
+    public int toolNm = 6;
 
 
     // 缓存上一次的信号值,用于检测变化(key=地址, value=上次值)
@@ -141,75 +148,90 @@ public class WorkJPanelDevice extends JPanel {
         // 对于 OP140 和 OP150,增大窗口尺寸以占满主界面
         int yScale = 1;
 
-
-        s7PLC = new S7PLC(EPlcType.S1500, plcIp);
-        s7PLC.setConnectTimeout(500);
-        s7PLC.setReceiveTimeout(500);
-
         log.info("deviceIp:"+deviceIp);
         fswDeviceName = OprnoUtil.getGwDes(lineSn, oprno);
 
-        if(oprno.equals("OP110")){
+        if(oprno.equals("OP110")){ // 框架反面CNC
+            plcIp = "10.85.10.6";
             if(position.equals("A")){
                 plcDb = "DB4003";
-                deviceIp = "10.85.10.6";
+                deviceIp = "10.85.10.80";
             }else if(position.equals("B")){
                 plcDb = "DB4004";
-                deviceIp = "10.85.10.6";
+                deviceIp = "10.85.10.81";
             } else if (position.equals("C")) {
                 plcDb = "DB4005";
-                deviceIp = "10.85.10.6";
+                deviceIp = "10.85.10.82";
+            }
+        }else if(oprno.equals("OP140")){
+            plcIp = "10.85.10.2";
+            if(position.equals("A")){
+                plcDb = "DB4008";
+                deviceIp = "";
+            }
+        }else if(oprno.equals("OP150")){
+            plcIp = "10.85.10.2";
+            if(position.equals("A")){
+                plcDb = "DB4009";
+                deviceIp = "10.85.10.160";
+            }else if(position.equals("B")){
+                plcDb = "DB4010";
+                deviceIp = "10.85.10.161";
             }
         }else if(oprno.equals("OP170")){
+            plcIp = "10.85.10.3";
             if(position.equals("A")){
                 plcDb = "DB4012";
-                deviceIp = "10.85.10.3";
+                deviceIp = "10.85.10.83";
             }else if(position.equals("B")){
                 plcDb = "DB4013";
-                deviceIp = "10.85.10.3";
+                deviceIp = "10.85.10.84";
             }else if (position.equals("C")) {
                 plcDb = "DB4014";
-                deviceIp = "10.85.10.3";
+                deviceIp = "10.85.10.85";
             }else if (position.equals("D")) {
                 plcDb = "DB4015";
-                deviceIp = "10.85.10.3";
+                deviceIp = "10.85.10.86";
             }
         }else if(oprno.equals("OP180")){
+            plcIp = "10.85.10.4";
             if(position.equals("A")){
                 plcDb = "DB4017";
-                deviceIp = "10.85.10.4";
+                deviceIp = "10.85.10.86";
             }else if(position.equals("B")){
                 plcDb = "DB4018";
-                deviceIp = "10.85.10.4";
+                deviceIp = "10.85.10.87";
             } else if (position.equals("C")) {
                 plcDb = "DB4019";
-                deviceIp = "10.85.10.4";
-            }
-        }else if(oprno.equals("OP220")){
-            if(position.equals("A")){
-                plcDb = "DB3011";
+                deviceIp = "10.85.10.88";
             }
-        }else if(oprno.equals("OP140")){
-            if(position.equals("A")){
-//                workWidth = 940;
-//                workHeight = 600;
-//                yScale = 2;
-                plcDb = "DB4008";
-                deviceIp = "10.85.10.2";
+        }
+
+        s7PLC = new S7PLC(EPlcType.S1500, plcIp);
+        s7PLC.setConnectTimeout(800);
+        s7PLC.setReceiveTimeout(800);
+
+        if(oprno.equals("OP110")||oprno.equals("OP170")||oprno.equals("OP180")){
+            modbusTcp = new ModbusTcp(1, deviceIp);
+            modbusTcp.setConnectTimeout(500);
+            modbusTcp.setReceiveTimeout(500);
+            if(oprno.equals("OP170")){
+                toolNm = 9;
+            }else if(oprno.equals("OP180")){
+                toolNm = 5;
             }
-        }else if(oprno.equals("OP150")){
-            if(position.equals("A")){
-                plcDb = "DB4009";
-                deviceIp = "10.85.10.2";
-            }else if(position.equals("B")){
-                plcDb = "DB4010";
-                deviceIp = "10.85.10.2";
+            for(int i=0; i<toolNm; i++){
+                toolNums[i] = i+1;
+                toolTitle[i] = "T"+(i+1);
+                toolLife[i] = "";
             }
         }
 
-        modbusTcp = new ModbusTcp(1, deviceIp);
-        modbusTcp.setConnectTimeout(500);
-        modbusTcp.setReceiveTimeout(500);
+        if(oprno.equals("OP150")){
+            s7PLCFSW = new S7PLC(EPlcType.SINUMERIK_828D, deviceIp);
+            s7PLCFSW.setReceiveTimeout(500);
+            s7PLCFSW.setConnectTimeout(500);
+        }
 
         oprnoLabel = new JLabel(oprno+pos);
         oprnoLabel.setHorizontalAlignment(SwingConstants.CENTER);
@@ -330,7 +352,7 @@ public class WorkJPanelDevice extends JPanel {
         historyBtn.setBounds(workWidth*3/4, 220*yScale, workWidth/4, 35);
         this.add(historyBtn);
 
-        if(oprno.equals("OP160") || oprno.equals("OP170")){
+        if(oprno.equals("OP110") || oprno.equals("OP170")|| oprno.equals("OP180")){
             toolBtn = new JButton("刀具寿命");
             toolBtn.addActionListener(new ActionListener() {
                 public void actionPerformed(ActionEvent e) {
@@ -406,7 +428,10 @@ public class WorkJPanelDevice extends JPanel {
 
         startOprnoTimer();
 
-        //monitorDeviceStatus();
+        if(oprno.equals("OP150")){
+            monitorDevice();
+        }
+
 
         resetScanA();
 
@@ -443,24 +468,24 @@ public class WorkJPanelDevice extends JPanel {
         cjTimerText2.schedule(new TimerTask() {
             public void run() {
                 if(MesClient.isLogin == 1 && isLocal == 0){
-                    if(oprno.equals("OP160") && pos.equals("A")){
+                    if(oprno.equals("OP110") && pos.equals("A")){
                         try{ // 心跳
                             sendHeart("DB3000",s7PLC);
                         }catch (Exception e){
                             e.printStackTrace();
                         }
 
-                        try{ // CNC上线
-                            ReplyPlc("DB3000",s7PLC);
-                        }catch (Exception e){
-                            e.printStackTrace();
-                        }
-
-                        try{ // 涂胶上线
-                            ReplyPlc("DB3010",s7PLC);
-                        }catch (Exception e){
-                            e.printStackTrace();
-                        }
+//                        try{ // CNC上线
+//                            ReplyPlc("DB3000",s7PLC);
+//                        }catch (Exception e){
+//                            e.printStackTrace();
+//                        }
+//
+//                        try{ // 涂胶上线
+//                            ReplyPlc("DB3010",s7PLC);
+//                        }catch (Exception e){
+//                            e.printStackTrace();
+//                        }
                     }
                 }
             }
@@ -620,7 +645,7 @@ public class WorkJPanelDevice extends JPanel {
                                 resetFeeding();
                                 setMenuStatus("工件加工中", 0);
 
-//                                getToolLife();
+                                getToolLife();
 
                             }else{
                                 if(!retFeedingAllow){
@@ -634,11 +659,12 @@ public class WorkJPanelDevice extends JPanel {
                                 writeAllowBlanking(true);
                                 if(tjStatus == 0){
                                     tjStatus = 1;
-                                    String result = readResult();
+//                                    String result = readResult();
+                                    String result = "OK";
                                     result = result.equals("OK")?"OK":"NG";
-                                    if(oprno.equals("OP220")||oprno.equals("OP230")){
-                                        result = "OK";
-                                    }
+//                                    if(oprno.equals("OP110")||oprno.equals("OP170")||oprno.equals("OP180")){
+//                                        result = "OK";
+//                                    }
                                     JSONObject retObj = DataUtil.sendQuality(productSnFeeding.getText(),oprno+pos,result,MesClient.user_menu.getText());
                                     if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
                                         resetBlanking();
@@ -863,10 +889,12 @@ public class WorkJPanelDevice extends JPanel {
             int i=0;
             List<String> ps = new ArrayList<>();
             for(Integer toolNum : toolNums){
-                String life = String.valueOf(getLife(modbusTcp,toolNum));
-                toolLife[i] = life;
-                ps.add(toolNum+"_"+life);
-                i++;
+                if(i < toolNm){
+                    String life = String.valueOf(getLife(modbusTcp,toolNum));
+                    toolLife[i] = life;
+                    ps.add(toolNum+"_"+life);
+                    i++;
+                }
             }
             if(!toolLife[i].isEmpty()){
                 DataUtil.saveLife(lineSn,oprno,productSnFeeding.getText(),MesClient.user_menu.getText(),String.join("\\|",ps));
@@ -882,12 +910,12 @@ public class WorkJPanelDevice extends JPanel {
             if(isLocal == 1){
                 return 0;
             }else{
-                short max1 = modbusTcp.readInt16((2103+(i*10))*2+3);
-                short cur1 = modbusTcp.readInt16((2103+(i*10))*2+1);
-                return max1 - cur1;
-//            Integer st = 150; // 宏变量对应R变量   @551=>R151
-//            Integer max1 = modbusTcp.readInt32((st + i)*2,EByteBuffFormat.DC_BA);
-//            return max1;
+//                short max1 = modbusTcp.readInt16((2103+(i*10))*2+3);
+//                short cur1 = modbusTcp.readInt16((2103+(i*10))*2+1);
+//                return max1 - cur1;
+                Integer st = 500; // 宏变量对应R变量  901 - 551  @551=>R151   @901=>R501
+                Integer max1 = modbusTcp.readInt32((st + i)*2, EByteBuffFormat.DC_BA);
+                return max1;
             }
         }catch (Exception e){
             e.printStackTrace();
@@ -923,7 +951,44 @@ public class WorkJPanelDevice extends JPanel {
         }
     }
 
+    public Timer cjTimerText33;
     public void monitorDevice(){
+
+        if(cjTimerText33!=null) {
+            cjTimerText33.cancel();
+        }
+        cjTimerText33 = new Timer();
+        cjTimerText33.schedule(new TimerTask() {
+            public void run() {
+                log.info("monitorDevice");
+                if(oprno.equals("OP150")){
+                    if(tjFeedingFlag == 2 && !productSnFeeding.getText().isEmpty()){
+                        try{
+                            String zzzs = String.valueOf(s7PLCFSW.readSpindleRate());
+                            String jgsd = String.valueOf(s7PLCFSW.readFeedRate());
+                            String record_time = DateLocalUtils.getCurrentTime();
+                            hjparams.add(zzzs+"|"+jgsd+"|"+record_time);
+                            if (hjparams.size() == 60  && productSn.getText() != null && !productSnFeeding.getText().trim().isEmpty() ) {
+                                JdbcUtils.insertParamData(oprno+pos,MesClient.mes_line_sn,productSn.getText(), JSON.toJSONString(hjparams));
+                                hjparams = new ArrayList<>();
+                            }
+                        }catch (Exception e){
+                            e.printStackTrace();
+                        }
+                        log.info("monitorDevice:"+JSON.toJSONString(hjparams));
+                    }else{
+                        if(hjparams.size() > 0){
+                            JdbcUtils.insertParamData(oprno+pos,MesClient.mes_line_sn,lastSn, JSON.toJSONString(hjparams));
+                            hjparams = new ArrayList<>();
+                        }
+                    }
+                }
+            }
+        }, 1000,1000);
+
+    }
+
+    public void monitorDeviceOld(){
         log.info("monitorDevice");
         if(tjFlag == 2){
             try{

+ 3 - 3
src/resources/config/config.properties

@@ -1,5 +1,5 @@
-mes.server_ip=127.0.0.1
-#mes.server_ip=192.168.14.99
+#mes.server_ip=127.0.0.1
+mes.server_ip=192.168.14.99
 mes.line_sn=XT
-mes.gw=OP110
+mes.gw=OP170
 mes.line_pos=west