From 11b41b18f1608704bc9e92814178b326dad80d60 Mon Sep 17 00:00:00 2001 From: caixiang <939387484@qq.com> Date: Thu, 26 Oct 2023 09:11:22 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E1=E7=BA=BF=EF=BC=8C=E6=98=AF?= =?UTF-8?q?=E4=BB=8E2=E7=BA=BF=E5=B9=B3=E7=A7=BB=E8=BF=87=E5=8E=BB?= =?UTF-8?q?=E7=9A=84=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dispatch/line2/KukaEvent2ThreadLine2.java | 16 +++++----- .../dispatch/line2/KukaEvent3ThreadLine2.java | 14 ++++----- .../packing/controller/TestController.java | 31 +++++++++++++++++++ .../cnbm/s7/s7connector/enmuc/S7Client.java | 7 +++-- 4 files changed, 50 insertions(+), 18 deletions(-) diff --git a/ym-packing/src/main/java/com/cnbm/dispatch/line2/KukaEvent2ThreadLine2.java b/ym-packing/src/main/java/com/cnbm/dispatch/line2/KukaEvent2ThreadLine2.java index 7070f45..7db852a 100644 --- a/ym-packing/src/main/java/com/cnbm/dispatch/line2/KukaEvent2ThreadLine2.java +++ b/ym-packing/src/main/java/com/cnbm/dispatch/line2/KukaEvent2ThreadLine2.java @@ -224,8 +224,8 @@ public class KukaEvent2ThreadLine2 implements ApplicationRunner { } //一. 从plc 中获取 subIdList 和 lineNum - String[] subIdList = (String[])read(S7Client.S7_DDJ1,Step2Plc2MesVar.SubIdList); - Integer listSize = (Integer)read(S7Client.S7_DDJ1,Step2Plc2MesVar.PackageNumberSet)-1; + String[] subIdList = (String[])read(S7Client.S7_DDJ2,Step2Plc2MesVar.SubIdList); + Integer listSize = (Integer)read(S7Client.S7_DDJ2,Step2Plc2MesVar.PackageNumberSet)-1; //二. MES 业务 @@ -301,11 +301,11 @@ public class KukaEvent2ThreadLine2 implements ApplicationRunner { //=============== MES 业务 结束 ================= //三. 把生成的BoxId 告诉kuka - write(S7Client.S7_DDJ1,Step2Mes2PlcVar.BoxId,boxId); + write(S7Client.S7_DDJ2,Step2Mes2PlcVar.BoxId,boxId); logger.info("BOXID生成Event-------boxId :"+ boxId+"传给PLC 成功"); //四. 当MES完成任务后,把MesToPlc.ShelfIsFullFinish变量置为true,告诉plc,我操作完成了 - write(S7Client.S7_DDJ1,Step2Mes2PlcVar.ShelfIsFullFinish,true); + write(S7Client.S7_DDJ2,Step2Mes2PlcVar.ShelfIsFullFinish,true); logger.info("BOXID生成Event-------boxId :"+ boxId+"ShelfIsFullFinish 置为true 成功"); //四. mes 监控 到PlcToMes.SubArrived==false,就把MesToPlc.SubArrivedFinish置为false Integer subArrived2 = waitingForTarget(Step2Plc2MesVar.ShelfIsFull, false); @@ -314,7 +314,7 @@ public class KukaEvent2ThreadLine2 implements ApplicationRunner { }else if(subArrived2 == 2){ throw new Exception("MES 监听值出现异常。"); } - write(S7Client.S7_DDJ1,Step2Mes2PlcVar.ShelfIsFullFinish,false); + write(S7Client.S7_DDJ2,Step2Mes2PlcVar.ShelfIsFullFinish,false); logger.info("BOXID生成Event-------boxId :"+ boxId+"ShelfIsFullFinish 置为false 成功,Event2 成功结束"); logger.info("================================== 现在开始执行 过程二 任务( 结束 ) ==================================="); logger.info(""); @@ -342,7 +342,7 @@ public class KukaEvent2ThreadLine2 implements ApplicationRunner { while (true){ try { - Boolean now = (Boolean) read(S7Client.S7_DDJ1,var); + Boolean now = (Boolean) read(S7Client.S7_DDJ2,var); //注意:即使now为null ,这里也不会抛出异常,这里很容易产生 空轮询。 if(now == null){ throw new Exception(""); @@ -373,7 +373,7 @@ public class KukaEvent2ThreadLine2 implements ApplicationRunner { Integer res = 0; while (true){ try { - Boolean now = (Boolean) read(S7Client.S7_DDJ1,var); + Boolean now = (Boolean) read(S7Client.S7_DDJ2,var); if(now == null){ throw new Exception(""); } @@ -403,7 +403,7 @@ public class KukaEvent2ThreadLine2 implements ApplicationRunner { Integer res = 0; while (true){ try { - Boolean now = (Boolean) read(S7Client.S7_DDJ1,var); + Boolean now = (Boolean) read(S7Client.S7_DDJ2,var); if(now == null){ throw new Exception(""); } diff --git a/ym-packing/src/main/java/com/cnbm/dispatch/line2/KukaEvent3ThreadLine2.java b/ym-packing/src/main/java/com/cnbm/dispatch/line2/KukaEvent3ThreadLine2.java index 3f8f5a3..049f413 100644 --- a/ym-packing/src/main/java/com/cnbm/dispatch/line2/KukaEvent3ThreadLine2.java +++ b/ym-packing/src/main/java/com/cnbm/dispatch/line2/KukaEvent3ThreadLine2.java @@ -216,8 +216,8 @@ public class KukaEvent3ThreadLine2 implements ApplicationRunner { } //一. 从plc 中获取 subIdList 和 lineNum - String boxId = (String)read(S7Client.S7_DDJ1,Step3Plc2MesVar.BoxId); - Integer lineNum = (Integer) read(S7Client.S7_DDJ1,Step3Plc2MesVar.LineNum); + String boxId = (String)read(S7Client.S7_DDJ2,Step3Plc2MesVar.BoxId); + Integer lineNum = (Integer) read(S7Client.S7_DDJ2,Step3Plc2MesVar.LineNum); if(boxId == null){ logger.info("装箱单打印Event-------失败"+" --- "+"从plc里面获取到的boxId 为null"); throw new Exception("装箱单打印Event-------boxId 为null"); @@ -233,7 +233,7 @@ public class KukaEvent3ThreadLine2 implements ApplicationRunner { //四. 当MES完成任务后,把MesToPlc.ShelfIsFullArrivedFinish变量置为true,告诉plc,我操作完成了 - write(S7Client.S7_DDJ1,Step3Mes2PlcVar.ShelfIsFullArrivedFinish,true); + write(S7Client.S7_DDJ2,Step3Mes2PlcVar.ShelfIsFullArrivedFinish,true); logger.info("装箱单打印Event------boxId :"+boxId+", ShelfIsFullArrivedFinish置为true 成功"); //四. mes 监控 到PlcToMes.SubArrived==false,就把MesToPlc.SubArrivedFinish置为false Integer subArrived2 = waitingForTarget(Step3Plc2MesVar.ShelfIsFullArrived, false); @@ -243,7 +243,7 @@ public class KukaEvent3ThreadLine2 implements ApplicationRunner { throw new Exception("MES 监听值出现异常。"); } logger.info("装箱单打印Event------boxId :"+boxId+", 监听到subArrived=false 成功"); - write(S7Client.S7_DDJ1,Step3Mes2PlcVar.ShelfIsFullArrivedFinish,false); + write(S7Client.S7_DDJ2,Step3Mes2PlcVar.ShelfIsFullArrivedFinish,false); logger.info("装箱单打印Event------boxId :"+boxId+", Even3 成功"); logger.info("================================== 现在开始执行 过程三 任务( 结束 ) ==================================="); @@ -273,7 +273,7 @@ public class KukaEvent3ThreadLine2 implements ApplicationRunner { while (true){ try { - Boolean now = (Boolean) read(S7Client.S7_DDJ1,var); + Boolean now = (Boolean) read(S7Client.S7_DDJ2,var); //注意:即使now为null ,这里也不会抛出异常,这里很容易产生 空轮询。 if(now == null){ throw new Exception(""); @@ -304,7 +304,7 @@ public class KukaEvent3ThreadLine2 implements ApplicationRunner { Integer res = 0; while (true){ try { - Boolean now = (Boolean) read(S7Client.S7_DDJ1,var); + Boolean now = (Boolean) read(S7Client.S7_DDJ2,var); if(now == null){ throw new Exception(""); } @@ -334,7 +334,7 @@ public class KukaEvent3ThreadLine2 implements ApplicationRunner { Integer res = 0; while (true){ try { - Boolean now = (Boolean) read(S7Client.S7_DDJ1,var); + Boolean now = (Boolean) read(S7Client.S7_DDJ2,var); if(now == null){ throw new Exception(""); } diff --git a/ym-packing/src/main/java/com/cnbm/packing/controller/TestController.java b/ym-packing/src/main/java/com/cnbm/packing/controller/TestController.java index 24cab80..835a033 100644 --- a/ym-packing/src/main/java/com/cnbm/packing/controller/TestController.java +++ b/ym-packing/src/main/java/com/cnbm/packing/controller/TestController.java @@ -265,6 +265,37 @@ public class TestController { return R.ok(); } + @PostMapping("/testReadAll2") + public R testReadAll2() throws UnsupportedEncodingException, ParseException { + for(Step1Plc2MesVar actual:Step1Plc2MesVar.values()){ + logger.info(read(S7Client.S7_DDJ2,actual).toString()); + System.out.println(actual.getName().toString()+" : "+read(S7Client.S7_DDJ2,actual).toString()); + } + for(Step1Mes2PlcVar actual:Step1Mes2PlcVar.values()){ + logger.info(read(S7Client.S7_DDJ2,actual).toString()); + System.out.println(actual.getName().toString()+" : "+read(S7Client.S7_DDJ2,actual).toString()); + } + + for(Step2Plc2MesVar actual:Step2Plc2MesVar.values()){ + logger.info(read(S7Client.S7_DDJ2,actual).toString()); + System.out.println(actual.getName().toString()+" : "+read(S7Client.S7_DDJ2,actual).toString()); + } + for(Step2Mes2PlcVar actual:Step2Mes2PlcVar.values()){ + logger.info(read(S7Client.S7_DDJ2,actual).toString()); + System.out.println(actual.getName().toString()+" : "+read(S7Client.S7_DDJ2,actual).toString()); + } + + for(Step3Plc2MesVar actual:Step3Plc2MesVar.values()){ + logger.info(read(S7Client.S7_DDJ2,actual).toString()); + System.out.println(actual.getName().toString()+" : "+read(S7Client.S7_DDJ2,actual).toString()); + } + for(Step3Mes2PlcVar actual:Step3Mes2PlcVar.values()){ + logger.info(read(S7Client.S7_DDJ2,actual).toString()); + System.out.println(actual.getName().toString()+" : "+read(S7Client.S7_DDJ2,actual).toString()); + } + return R.ok(); + } + public static void main(String[] args) { BigDecimal voc = new BigDecimal(59.799); System.out.println(Float.valueOf(voc.toString())); diff --git a/ym-s7/src/main/java/com/cnbm/s7/s7connector/enmuc/S7Client.java b/ym-s7/src/main/java/com/cnbm/s7/s7connector/enmuc/S7Client.java index e43cbf1..f669d14 100644 --- a/ym-s7/src/main/java/com/cnbm/s7/s7connector/enmuc/S7Client.java +++ b/ym-s7/src/main/java/com/cnbm/s7/s7connector/enmuc/S7Client.java @@ -29,12 +29,13 @@ public enum S7Client { // S7_1500("192.168.0.51",0,1,1), //1线 - S7_DDJ1("10.10.3.158",0,1,2), - + //S7_DDJ1("10.10.3.152",0,1,2), + S7_DDJ1("10.10.3.152",0,1,2), //2线 S7_DDJ2("10.10.3.158",0,1,2), - //1500 机架-0 插槽-1 + +//1500 机架-0 插槽-1 //后续 在这里扩展 多PLC应用。 ; private String host;