|
|
@@ -14,12 +14,15 @@ import java.util.Arrays;
|
|
|
|
|
|
public class PlcUtil {
|
|
|
|
|
|
- public static void getParamDyDl(S7PLC s7PLC){
|
|
|
- Boolean starta = s7PLC.readBoolean("DB200.0.1"); //进站 A
|
|
|
- Boolean startb = s7PLC.readBoolean("DB200.38.0"); //进站 B
|
|
|
+ /** 焊接状态:0=空闲(MES收到结束后回写) 1=焊接开始 2=焊接结束 */
|
|
|
+ public static final int WELD_IDLE = 0;
|
|
|
+ public static final int WELD_RUNNING = 1;
|
|
|
+ public static final int WELD_FINISH = 2;
|
|
|
|
|
|
+ public static void getParamDyDl(S7PLC s7PLC){
|
|
|
+ // 进站已改作允许启动位,侧别用当前运行面 curFlag
|
|
|
String oprno = MesClient.mes_gw+"A";
|
|
|
- if(startb){
|
|
|
+ if("B".equals(MesClient.curFlag)){
|
|
|
oprno = MesClient.mes_gw+"B";
|
|
|
}
|
|
|
if(MesClient.mes_gwflag != null && MesClient.mes_gwflag.equals("B")){
|
|
|
@@ -74,114 +77,22 @@ public class PlcUtil {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public static void getStatusAOld(S7PLC s7PLC){
|
|
|
- String sna = "";
|
|
|
- if(MesClient.tjFlaga == 1){ // 待运行
|
|
|
- MesClient.checkA = 0;
|
|
|
- Boolean starta = s7PLC.readBoolean("DB1.2.2"); //A启动中
|
|
|
- if(starta){
|
|
|
- MesClient.curFlag = "A";
|
|
|
- MesClient.tjFlaga = 2;
|
|
|
- MesClient.pxstatus1.setText("A:设备运行中");
|
|
|
- PlcUtil.changeEnable(MesClient.s7PLC,false);
|
|
|
- }
|
|
|
- }else if(MesClient.tjFlaga == 2){ // 运行中
|
|
|
- MesClient.batch_scan_1.setEnabled(false);
|
|
|
- Boolean starta = s7PLC.readBoolean("DB1.2.5"); //A焊接完成
|
|
|
- Boolean startb = s7PLC.readBoolean("DB1.2.3"); //B启动中
|
|
|
- if(starta || startb){ // B启动中,A当做完成
|
|
|
- MesClient.tjFlaga = 3;
|
|
|
- MesClient.pxstatus1.setText("A:设备运行结束,提交结果中");
|
|
|
- MesClient.finish_ok_bt.setEnabled(true);
|
|
|
-
|
|
|
- Boolean sendret = DataUtil.sendQuality(MesClient.nettyClient,MesClient.product_sn.getText(),"OK",MesClient.user20,"A");
|
|
|
- if(!sendret){
|
|
|
- MesClient.pxstatus1.setText("A:结果上传MES失败");
|
|
|
- MesClient.tjStatusa = 1;
|
|
|
- }else{
|
|
|
-// MesClient.pxstatus1.setText("A:提交成功");
|
|
|
-// MesClient.status_menu.setText("A件提交成功");
|
|
|
-// MesClient.resetScanA();
|
|
|
- }
|
|
|
- }
|
|
|
-// Boolean sa = s7PLC.readBoolean("DB1.2.2"); //A启动中
|
|
|
-// if(!sa){
|
|
|
-// MesClient.pxstatus1.setText("A:设备运行停止");
|
|
|
-// MesClient.finish_ok_bt.setEnabled(true);
|
|
|
-// }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public static void getStatusBOld(S7PLC s7PLC){
|
|
|
- String snb = "";
|
|
|
- if(MesClient.tjFlagb == 0){ // 未扫码
|
|
|
- snb = s7PLC.readString("DB8.100",50);
|
|
|
- System.out.println("snb:"+snb);
|
|
|
- if(!snb.isEmpty() && !MesClient.curSnb.equals(snb) && snb.length() == 33){
|
|
|
- MesClient.product_sn2.setText(snb);
|
|
|
- }else{
|
|
|
- snb = "";
|
|
|
- }
|
|
|
- if(!MesClient.mesQualityFlagB && !snb.isEmpty() && MesClient.curSnb.isEmpty()){ // 查询工件质量
|
|
|
- if(!MesClient.tcp_connect_flag) {
|
|
|
- MesClient.status_menu.setText("未连接MES服务器");
|
|
|
- }else{
|
|
|
- if(MesClient.checkB == 0) {
|
|
|
- MesClient.checkB = 1;
|
|
|
- MesClient.getUser();
|
|
|
- Boolean sendret = DataUtil.checkQuality(MesClient.nettyClient,snb,MesClient.user20,"B");
|
|
|
- if(!sendret){
|
|
|
- MesClient.pxstatus2.setText("B:查询质量失败");
|
|
|
- MesClient.checkB = 0;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }else if(MesClient.tjFlagb == 1){ // 待运行
|
|
|
- MesClient.checkB = 0;
|
|
|
- Boolean startb = s7PLC.readBoolean("DB1.2.3"); //B启动中
|
|
|
- if(startb){
|
|
|
- MesClient.curFlag = "B";
|
|
|
- MesClient.tjFlagb = 2;
|
|
|
- MesClient.pxstatus2.setText("B:设备运行中");
|
|
|
- PlcUtil.changeEnable(MesClient.s7PLC,false);
|
|
|
- }
|
|
|
- }else if(MesClient.tjFlagb == 2){ // 运行中
|
|
|
- MesClient.batch_scan_2.setEnabled(false);
|
|
|
- Boolean starta = s7PLC.readBoolean("DB1.2.7"); //B焊接完成
|
|
|
- Boolean startb = s7PLC.readBoolean("DB1.2.2"); //A启动中
|
|
|
- if(starta || startb){
|
|
|
- MesClient.tjFlagb = 3;
|
|
|
- MesClient.pxstatus2.setText("B:设备运行结束,提交结果中");
|
|
|
- MesClient.finish_ng_bt.setEnabled(true);
|
|
|
-
|
|
|
- Boolean sendret = DataUtil.sendQuality(MesClient.nettyClient,MesClient.product_sn2.getText(),"OK",MesClient.user20,"B");
|
|
|
- if(!sendret){
|
|
|
- MesClient.pxstatus2.setText("B:结果上传MES失败");
|
|
|
- MesClient.tjStatusb = 1;
|
|
|
- }else{
|
|
|
-// MesClient.pxstatus2.setText("B:提交成功");
|
|
|
-// MesClient.status_menu.setText("B件提交成功");
|
|
|
-// MesClient.resetScanB();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
public static void getStatusA(S7PLC s7PLC){
|
|
|
if(MesClient.tjFlaga == 1){ // 已扫码,设备未运行
|
|
|
- Boolean starta = getAStart(s7PLC); //A启动中
|
|
|
+ Boolean starta = getAStart(s7PLC); //A焊接状态=1 焊接开始
|
|
|
if(starta){
|
|
|
MesClient.curFlag = "A";
|
|
|
MesClient.tjFlaga = 2;
|
|
|
MesClient.pxstatus1.setText("A:设备运行中");
|
|
|
// MesClient.formatScanType(1);
|
|
|
// MesClient.batch_scan_1.setEnabled(false);
|
|
|
- PlcUtil.changeEnable(s7PLC,false);
|
|
|
}
|
|
|
}else if(MesClient.tjFlaga == 2){
|
|
|
- Boolean afinish = getAFinish(s7PLC); //A焊接完成
|
|
|
- if(afinish){ // B启动中,A当做完成
|
|
|
+ Boolean afinish = getAFinish(s7PLC); //A焊接状态=2 焊接结束
|
|
|
+ if(afinish){
|
|
|
+ // 收到结束状态后写回0,并关闭该面允许启动
|
|
|
+ clearAWeldStatus(s7PLC);
|
|
|
+ PlcUtil.changeEnable(s7PLC, "A", false);
|
|
|
MesClient.tjFlaga = 3;
|
|
|
MesClient.pxstatus1.setText("A:设备运行结束,提交结果中");
|
|
|
MesClient.finish_ok_bt.setEnabled(true);
|
|
|
@@ -198,18 +109,20 @@ public class PlcUtil {
|
|
|
|
|
|
public static void getStatusB(S7PLC s7PLC){
|
|
|
if(MesClient.tjFlagb == 1){ // 已扫码,设备未运行
|
|
|
- Boolean startb = getBStart(s7PLC); //B启动中
|
|
|
+ Boolean startb = getBStart(s7PLC); //B焊接状态=1 焊接开始
|
|
|
if(startb){
|
|
|
MesClient.curFlag = "B";
|
|
|
MesClient.tjFlagb = 2;
|
|
|
MesClient.pxstatus2.setText("B:设备运行中");
|
|
|
MesClient.batch_scan_2.setEnabled(false);
|
|
|
MesClient.formatScanType(1);
|
|
|
- PlcUtil.changeEnable(s7PLC,false);
|
|
|
}
|
|
|
}else if(MesClient.tjFlagb == 2){
|
|
|
- Boolean bfinish = getBFinish(s7PLC); //B焊接完成
|
|
|
+ Boolean bfinish = getBFinish(s7PLC); //B焊接状态=2 焊接结束
|
|
|
if(bfinish){
|
|
|
+ // 收到结束状态后写回0,并关闭该面允许启动
|
|
|
+ clearBWeldStatus(s7PLC);
|
|
|
+ PlcUtil.changeEnable(s7PLC, "B", false);
|
|
|
MesClient.tjFlagb = 3;
|
|
|
MesClient.pxstatus2.setText("B:设备运行结束,提交结果中");
|
|
|
MesClient.finish_ng_bt2.setEnabled(true);
|
|
|
@@ -224,56 +137,104 @@ public class PlcUtil {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 获取A启动状态
|
|
|
+ /** 读取A焊接状态 DB200.34.0 */
|
|
|
+ public static int getAWeldStatus(S7PLC s7PLC){
|
|
|
+ try{
|
|
|
+ return s7PLC.readInt16("DB200.34.0");
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 读取B焊接状态 DB200.72.0 */
|
|
|
+ public static int getBWeldStatus(S7PLC s7PLC){
|
|
|
+ try{
|
|
|
+ return s7PLC.readInt16("DB200.72.0");
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 收到A焊接结束后写回0 */
|
|
|
+ public static Boolean clearAWeldStatus(S7PLC s7PLC){
|
|
|
+ try{
|
|
|
+ s7PLC.writeInt16("DB200.34.0", (short) WELD_IDLE);
|
|
|
+ return true;
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 收到B焊接结束后写回0 */
|
|
|
+ public static Boolean clearBWeldStatus(S7PLC s7PLC){
|
|
|
+ try{
|
|
|
+ s7PLC.writeInt16("DB200.72.0", (short) WELD_IDLE);
|
|
|
+ return true;
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // A焊接开始:状态=1
|
|
|
public static Boolean getAStart(S7PLC s7PLC){
|
|
|
try{
|
|
|
- return s7PLC.readBoolean("DB200.0.1"); //进站 A
|
|
|
+ return getAWeldStatus(s7PLC) == WELD_RUNNING;
|
|
|
}catch (Exception e){
|
|
|
e.printStackTrace();
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 获取A的结束状态
|
|
|
+ // A焊接结束:状态=2
|
|
|
public static Boolean getAFinish(S7PLC s7PLC){
|
|
|
try{
|
|
|
- boolean a = s7PLC.readBoolean("DB200.0.2"); //返回 A
|
|
|
- boolean b = s7PLC.readBoolean("DB200.38.0"); //进站 B,A当做完成
|
|
|
- return a || b;
|
|
|
+ return getAWeldStatus(s7PLC) == WELD_FINISH;
|
|
|
}catch (Exception e){
|
|
|
e.printStackTrace();
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 获取B启动状态
|
|
|
+ // B焊接开始:状态=1
|
|
|
public static Boolean getBStart(S7PLC s7PLC){
|
|
|
try{
|
|
|
- return s7PLC.readBoolean("DB200.38.0"); //进站 B
|
|
|
+ return getBWeldStatus(s7PLC) == WELD_RUNNING;
|
|
|
}catch (Exception e){
|
|
|
e.printStackTrace();
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 获取B的结束状态
|
|
|
+ // B焊接结束:状态=2
|
|
|
public static Boolean getBFinish(S7PLC s7PLC){
|
|
|
try{
|
|
|
- boolean a = s7PLC.readBoolean("DB200.38.1"); //返回 B
|
|
|
- boolean b = s7PLC.readBoolean("DB200.0.1"); //进站 A,B当做完成
|
|
|
- return a || b;
|
|
|
+ return getBWeldStatus(s7PLC) == WELD_FINISH;
|
|
|
}catch (Exception e){
|
|
|
e.printStackTrace();
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 修改设备的禁用开关
|
|
|
-// MES 使能 A / MES 使能 B
|
|
|
- public static Boolean changeEnable(S7PLC s7PLC,Boolean result){
|
|
|
+ /**
|
|
|
+ * 进站允许启动控制:1=允许启动,0=不允许启动
|
|
|
+ * 进站A DB200.0.1 / 进站B DB200.38.0
|
|
|
+ * MES使能A DB200.186.1 / MES使能B DB200.186.2
|
|
|
+ * side: "A"/"B" 单面,"ALL" 双面
|
|
|
+ */
|
|
|
+ public static Boolean changeEnable(S7PLC s7PLC, String side, Boolean result){
|
|
|
try{
|
|
|
- s7PLC.writeBoolean("DB200.186.1",result); //MES 使能 A
|
|
|
- s7PLC.writeBoolean("DB200.186.2",result); //MES 使能 B
|
|
|
+ if("A".equals(side) || "ALL".equals(side)){
|
|
|
+ s7PLC.writeBoolean("DB200.0.1", result); // 进站A
|
|
|
+ s7PLC.writeBoolean("DB200.186.1", result); // MES使能A
|
|
|
+ }
|
|
|
+ if("B".equals(side) || "ALL".equals(side)){
|
|
|
+ s7PLC.writeBoolean("DB200.38.0", result); // 进站B
|
|
|
+ s7PLC.writeBoolean("DB200.186.2", result); // MES使能B
|
|
|
+ }
|
|
|
return true;
|
|
|
}catch (Exception e){
|
|
|
e.printStackTrace();
|
|
|
@@ -281,6 +242,11 @@ public class PlcUtil {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /** 双面同时写允许启动 */
|
|
|
+ public static Boolean changeEnable(S7PLC s7PLC, Boolean result){
|
|
|
+ return changeEnable(s7PLC, "ALL", result);
|
|
|
+ }
|
|
|
+
|
|
|
// 获取当前是A面还是B面
|
|
|
public static String getCurAside(S7PLC s7PLC){
|
|
|
String str = "A";
|