jingbo пре 2 дана
родитељ
комит
6e3428b40f
3 измењених фајлова са 125 додато и 30 уклоњено
  1. 67 25
      src/com/mes/ui/MesClient.java
  2. 5 5
      src/com/mes/util/PLCUtils.java
  3. 53 0
      src/com/mes/util/test.java

+ 67 - 25
src/com/mes/ui/MesClient.java

@@ -623,27 +623,59 @@ public class MesClient extends JFrame {
             @Override
             @Override
             public void run() {
             public void run() {
                 if (work_status == 1) {
                 if (work_status == 1) {
-                    // TODO
-                    //  加入工作流程
-                    if (plc_status == 0){
-                        // 等待扫码
-                        String sn = product_sn.getText().trim();
-                        if (sn.isEmpty()) {
-                            plc_status = 1;
-                        }
-                    } else if (plc_status == 1) {
-                        // 发送允许启动信号
-                        Boolean ret = PLCUtils.writeStartMethod(plc);
-                        if (ret) {
-                            plc_status = 2;
-                        }
-                    } else if (plc_status == 2) {
-                        // 等待加工结束信号
-                        Boolean ret = PLCUtils.readStopMethod(plc);
-                        if (ret){
-                            // 将允许启动置空
-                            PLCUtils.writeStopMethod(plc);
-                            // 获取参数
+
+//                    if (plc_status == 0){
+//                        // 等待扫码
+//                        String sn = product_sn.getText().trim();
+//                        if (sn.isEmpty()) {
+//                            plc_status = 1;
+//                        }
+//                    } else if (plc_status == 1) {
+//                        // 发送允许启动信号
+//                        Boolean ret = PLCUtils.writeStartMethod(plc);
+//                        if (ret) {
+//                            plc_status = 2;
+//                        }
+//                    } else if (plc_status == 2) {
+//                        // 等待加工结束信号
+//                        Boolean ret = PLCUtils.readStopMethod(plc);
+//                        if (ret){
+//                            // 将允许启动置空
+//                            PLCUtils.writeStopMethod(plc);
+//                            // 获取参数
+//                            QmParam qmParam = PLCUtils.getParameter(plc);
+//                            // 发送参数
+//                            JSONObject retObj1 = DataUtil.sendQualityParam( user20, product_sn.getText().trim(), MesClient.mes_gw, MesClient.mes_line_sn,qmParam);
+//                            if(retObj1 != null && retObj1.get("result") != null && retObj1.get("result").toString().equalsIgnoreCase("true")) {
+//                                MesClient.resetScanA();
+//                                MesClient.setMenuStatus("测试结果上传成功,请扫下一件",0);
+//                            }else{
+//                                MesClient.setMenuStatus("测试结果上传失败,请重试",-1);
+//                                return;
+//                            }
+//                            // 获取结果
+//                            String result = PLCUtils.getResult(plc);
+//                            // 发送结果
+//                            String sn = product_sn.getText().trim();
+//                            JSONObject retObj = DataUtil.sendQuality( sn,result,user20);
+//                            if (retObj != null && "true".equalsIgnoreCase(retObj.getString("result"))) {
+//                                resetState();
+//                                status_menu.setForeground(Color.GREEN);
+//                                status_menu.setText("结果提交成功,请扫下一件");
+//                                finish_ng_bt.setEnabled(false);
+//                            } else {
+//                                status_menu.setForeground(Color.RED);
+//                                String msg = (retObj != null && retObj.containsKey("message")) ? retObj.getString("message") : "提交失败";
+//                                status_menu.setText(msg);
+//                            }
+//                        }
+//                    }
+
+                    // 获取结果
+                    String result = PLCUtils.getResult(plc);
+                    // 如果等于OK或者NG的时候才处理结果
+                    if("OK".equals(result)){
+                        // 获取参数
                             QmParam qmParam = PLCUtils.getParameter(plc);
                             QmParam qmParam = PLCUtils.getParameter(plc);
                             // 发送参数
                             // 发送参数
                             JSONObject retObj1 = DataUtil.sendQualityParam( user20, product_sn.getText().trim(), MesClient.mes_gw, MesClient.mes_line_sn,qmParam);
                             JSONObject retObj1 = DataUtil.sendQualityParam( user20, product_sn.getText().trim(), MesClient.mes_gw, MesClient.mes_line_sn,qmParam);
@@ -652,11 +684,7 @@ public class MesClient extends JFrame {
                                 MesClient.setMenuStatus("测试结果上传成功,请扫下一件",0);
                                 MesClient.setMenuStatus("测试结果上传成功,请扫下一件",0);
                             }else{
                             }else{
                                 MesClient.setMenuStatus("测试结果上传失败,请重试",-1);
                                 MesClient.setMenuStatus("测试结果上传失败,请重试",-1);
-                                return;
                             }
                             }
-                            // 获取结果
-                            String result = PLCUtils.getResult(plc);
-                            // 发送结果
                             String sn = product_sn.getText().trim();
                             String sn = product_sn.getText().trim();
                             JSONObject retObj = DataUtil.sendQuality( sn,result,user20);
                             JSONObject retObj = DataUtil.sendQuality( sn,result,user20);
                             if (retObj != null && "true".equalsIgnoreCase(retObj.getString("result"))) {
                             if (retObj != null && "true".equalsIgnoreCase(retObj.getString("result"))) {
@@ -669,8 +697,22 @@ public class MesClient extends JFrame {
                                 String msg = (retObj != null && retObj.containsKey("message")) ? retObj.getString("message") : "提交失败";
                                 String msg = (retObj != null && retObj.containsKey("message")) ? retObj.getString("message") : "提交失败";
                                 status_menu.setText(msg);
                                 status_menu.setText(msg);
                             }
                             }
+                    } else if ("NG".equals(result)) {
+                        String sn = product_sn.getText().trim();
+                        JSONObject retObj = DataUtil.sendQuality( sn,result,user20);
+                        if (retObj != null && "true".equalsIgnoreCase(retObj.getString("result"))) {
+                            resetState();
+                            status_menu.setForeground(Color.GREEN);
+                            status_menu.setText("结果提交成功,请扫下一件");
+                            finish_ng_bt.setEnabled(false);
+                        } else {
+                            status_menu.setForeground(Color.RED);
+                            String msg = (retObj != null && retObj.containsKey("message")) ? retObj.getString("message") : "提交失败";
+                            status_menu.setText(msg);
                         }
                         }
                     }
                     }
+
+
                 } else if (work_status == 0) {
                 } else if (work_status == 0) {
                     JSONObject result = DataUtil.getCurSn(mes_gw, mes_server_ip, mes_line_sn);
                     JSONObject result = DataUtil.getCurSn(mes_gw, mes_server_ip, mes_line_sn);
                     // 正常处理结果
                     // 正常处理结果

+ 5 - 5
src/com/mes/util/PLCUtils.java

@@ -31,7 +31,7 @@ public class PLCUtils {
         // 泄露值
         // 泄露值
         String leakageValue = "0.0";
         String leakageValue = "0.0";
         if ("comso".equals(MesClient.csyq)){
         if ("comso".equals(MesClient.csyq)){
-            leakageValue = plc.readString("VB306", 8);
+            leakageValue = plc.readString("VB307", 7);
         }else if ("ATEQ".equals(MesClient.csyq)){
         }else if ("ATEQ".equals(MesClient.csyq)){
             leakageValue = plc.readFloat32("VD800")+"";
             leakageValue = plc.readFloat32("VD800")+"";
         }
         }
@@ -42,13 +42,13 @@ public class PLCUtils {
         // 预充时间
         // 预充时间
         String preChargeTime = plc.readInt16("VW2048")+"";
         String preChargeTime = plc.readInt16("VW2048")+"";
         // 充气时间
         // 充气时间
-        String chargeTime = plc.readInt16("VW504")+"";
+        String chargeTime = Math.round(plc.readInt16("VW504") / 10.0) + "";
         // 平衡时间
         // 平衡时间
-        String balanceTime = plc.readInt16("VW506")+"";
+        String balanceTime = Math.round(plc.readInt16("VW506") / 10.0) + "";
         // 检测时间
         // 检测时间
-        String detectTime = plc.readInt16("VW508")+"";
+        String detectTime = Math.round(plc.readInt16("VW508") / 10.0) + "";
         //循环时间
         //循环时间
-        String loopTime = plc.readInt16("VW850")+"";
+        String loopTime = Math.round(plc.readInt16("VW850") / 10.0) + "";
 
 
         QmParam qmParam = new QmParam();
         QmParam qmParam = new QmParam();
         qmParam.setLeakVal(leakageValue);
         qmParam.setLeakVal(leakageValue);

+ 53 - 0
src/com/mes/util/test.java

@@ -0,0 +1,53 @@
+package com.mes.util;
+
+import com.github.xingshuangs.iot.protocol.s7.enums.EPlcType;
+import com.github.xingshuangs.iot.protocol.s7.service.S7PLC;
+
+public class test {
+
+
+    public static S7PLC plc = new S7PLC(EPlcType.S1200,"192.168.2.1");
+
+    public static void main(String[] args) {
+        // 结果
+        String result = getResult(plc);
+        // 检测压
+        String pressure = plc.readFloat32("VD852")+"";
+        // 预充时间
+        String preChargeTime = Math.round(plc.readInt16("VW2048") / 10.0) + "";
+        // 充气时间
+        String chargeTime = Math.round(plc.readInt16("VW504") / 10.0) + "";
+        // 平衡时间
+        String balanceTime = Math.round(plc.readInt16("VW506") / 10.0) + "";
+        // 检测时间
+        String detectTime = Math.round(plc.readInt16("VW508") / 10.0) + "";
+        //循环时间
+        String loopTime = Math.round(plc.readInt16("VW850") / 10.0) + "";
+        // 泄露值
+        String leakageValue = plc.readString("VB307", 7);
+        // 加工结束
+        boolean istime =  plc.readBoolean("M4.0");
+        System.out.println("结果"+ result);
+        System.out.println("检测压"+ pressure);
+        System.out.println("预充时间"+ preChargeTime);
+        System.out.println("充气时间"+ chargeTime);
+        System.out.println("平衡时间"+ balanceTime);
+        System.out.println("检测时间"+ detectTime);
+        System.out.println("循环时间"+ loopTime);
+        System.out.println("泄露值"+ leakageValue);
+        System.out.println("加工结束"+ istime);
+
+    }
+
+    public static String getResult(S7PLC plc){
+        byte data = plc.readByte("VB503");
+        switch (data) {
+            case 2:
+                return "OK";
+            case 3:
+                return "NG";
+            default:
+                return "未知状态";
+        }
+    }
+}