|
|
@@ -2,308 +2,356 @@ package com.mes.ui;
|
|
|
|
|
|
import com.alibaba.fastjson2.JSON;
|
|
|
import com.github.xingshuangs.iot.protocol.s7.service.S7PLC;
|
|
|
-import com.mes.util.CommonUtils;
|
|
|
import com.mes.util.DateLocalUtils;
|
|
|
import com.mes.util.JdbcUtils;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
|
|
|
public class PlcUtil {
|
|
|
|
|
|
- public static void getParamDyDl(S7PLC s7PLC){
|
|
|
- Boolean starta = getAStart(s7PLC); //A启动中
|
|
|
- Boolean startb = getBStart(s7PLC); //B启动中
|
|
|
-
|
|
|
- if(MesClient.tjFlaga == 2 || MesClient.tjFlagb == 2){ //运行中
|
|
|
- Float dya = s7PLC.readFloat32("DB1010.2");
|
|
|
- Float dla = s7PLC.readFloat32("DB1010.8");
|
|
|
- Float ssa = s7PLC.readFloat32("DB1010.14");
|
|
|
- Short cwa = s7PLC.readInt16("DB1010.18");
|
|
|
- Short joba = s7PLC.readInt16("DB1010.20");
|
|
|
-
|
|
|
- MesClient.param1.setText(dya+"");
|
|
|
- MesClient.param2.setText(dla+"");
|
|
|
- MesClient.param3.setText(ssa+"");
|
|
|
- MesClient.param4.setText(cwa+"");
|
|
|
- MesClient.param5.setText(joba+"");
|
|
|
-
|
|
|
- Float dyb = s7PLC.readFloat32("DB1010.26");
|
|
|
- Float dlb = s7PLC.readFloat32("DB1010.34");
|
|
|
- Float ssb = s7PLC.readFloat32("DB1010.42");
|
|
|
- Short cwb = s7PLC.readInt16("DB1010.46");
|
|
|
- Short jobb = s7PLC.readInt16("DB1010.48");
|
|
|
-
|
|
|
- MesClient.param21.setText(dyb+"");
|
|
|
- MesClient.param22.setText(dlb+"");
|
|
|
- MesClient.param23.setText(ssb+"");
|
|
|
- MesClient.param24.setText(cwb+"");
|
|
|
- MesClient.param25.setText(jobb+"");
|
|
|
-
|
|
|
- String record_time = DateLocalUtils.getCurrentTime();
|
|
|
- MesClient.hjparams.add(dya+"|"+dla+"|"+ssa+"|"+cwa+"|"+joba+"|"+dyb+"|"+dlb+"|"+ssb+"|"+cwb+"|"+jobb+"|"+record_time);
|
|
|
- System.out.println("cmt:"+dya+"|"+dla+"|"+ssa+"|"+cwa+"|"+joba+"|"+dyb+"|"+dlb+"|"+ssb+"|"+cwb+"|"+jobb+"|"+record_time);
|
|
|
-
|
|
|
- if(MesClient.hjparams.size() == 60){
|
|
|
- try{
|
|
|
- // 根据curFlag确定工位号和工件码
|
|
|
- String oprno = MesClient.mes_gw+"A";
|
|
|
- String sn = MesClient.curSna;
|
|
|
- if(MesClient.curFlag.equals("B")){
|
|
|
- oprno = MesClient.mes_gw+"B";
|
|
|
- sn = MesClient.curSnb;
|
|
|
- }
|
|
|
- if(MesClient.mes_gwflag.equals("B")){
|
|
|
- if(MesClient.curFlag.equals("A")){
|
|
|
- oprno = MesClient.mes_gw+"C";
|
|
|
- }else{
|
|
|
- oprno = MesClient.mes_gw+"D";
|
|
|
- }
|
|
|
- }
|
|
|
- // 检查工件码是否为空,为空则不上传
|
|
|
- if(sn != null && !sn.trim().isEmpty()){
|
|
|
- JdbcUtils.insertCmtData(oprno,MesClient.mes_line_sn,sn, JSON.toJSONString(MesClient.hjparams));
|
|
|
- System.out.println("cmt:"+MesClient.curFlag+" sn:"+sn);
|
|
|
- }else{
|
|
|
- System.out.println("工件码为空,跳过保存数据");
|
|
|
- }
|
|
|
- MesClient.hjparams = new ArrayList<>();
|
|
|
- }catch (Exception e){
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
+ private static final String DB = "DB200";
|
|
|
+ private static final String A_ENABLE = DB + ".0.1";
|
|
|
+ private static final String B_ENABLE = DB + ".38.0";
|
|
|
+ private static final String A_STATUS = DB + ".34";
|
|
|
+ private static final String B_STATUS = DB + ".72";
|
|
|
+ private static final String A_POSITION = DB + ".156.3";
|
|
|
+ private static final String B_POSITION = DB + ".156.4";
|
|
|
+
|
|
|
+ private static final WeldPoint[] WELD_POINTS = new WeldPoint[]{
|
|
|
+ new WeldPoint("R1", 76.1, 78, 80, 84, 88, 92),
|
|
|
+ new WeldPoint("R2", 96.2, 98, 100, 104, 108, 112),
|
|
|
+ new WeldPoint("R3", 116.2, 118, 120, 124, 128, 132),
|
|
|
+ new WeldPoint("R4", 136.2, 138, 140, 144, 148, 152)
|
|
|
+ };
|
|
|
+
|
|
|
+ public static void getParamDyDl(S7PLC s7PLC) {
|
|
|
+ if (MesClient.tjFlaga == 2 || MesClient.tjFlagb == 2) {
|
|
|
+ List<String> values = readWeldParams(s7PLC);
|
|
|
+ String recordTime = DateLocalUtils.getCurrentTime();
|
|
|
+ values.add("time=" + recordTime);
|
|
|
+ MesClient.hjparams.add(String.join("|", values));
|
|
|
+ refreshParamText(values);
|
|
|
+ System.out.println("cmt:" + String.join("|", values));
|
|
|
+
|
|
|
+ if (MesClient.hjparams.size() == 60) {
|
|
|
+ saveCurrentParams();
|
|
|
}
|
|
|
- }else{
|
|
|
- if(MesClient.hjparams.size() != 60 && MesClient.hjparams.size() > 0){
|
|
|
- try{
|
|
|
- // 根据curFlag确定工位号和工件码
|
|
|
- String oprno = MesClient.mes_gw+"A";
|
|
|
- String sn = MesClient.curSna;
|
|
|
- if(MesClient.curFlag.equals("B")){
|
|
|
- oprno = MesClient.mes_gw+"B";
|
|
|
- sn = MesClient.curSnb;
|
|
|
- }
|
|
|
- if(MesClient.mes_gwflag.equals("B")){
|
|
|
- if(MesClient.curFlag.equals("A")){
|
|
|
- oprno = MesClient.mes_gw+"C";
|
|
|
- }else{
|
|
|
- oprno = MesClient.mes_gw+"D";
|
|
|
- }
|
|
|
- }
|
|
|
- // 检查工件码是否为空,为空则不上传
|
|
|
- if(sn != null && !sn.trim().isEmpty()){
|
|
|
- JdbcUtils.insertCmtData(oprno,MesClient.mes_line_sn,sn, JSON.toJSONString(MesClient.hjparams));
|
|
|
- System.out.println("cmt:"+MesClient.curFlag+" sn:"+sn);
|
|
|
- }else{
|
|
|
- System.out.println("工件码为空,跳过保存剩余数据");
|
|
|
- }
|
|
|
- MesClient.hjparams = new ArrayList<>();
|
|
|
- }catch (Exception e){
|
|
|
- e.printStackTrace();
|
|
|
+ } else if (MesClient.hjparams.size() > 0) {
|
|
|
+ saveCurrentParams();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static List<String> readWeldParams(S7PLC s7PLC) {
|
|
|
+ List<String> values = new ArrayList<>();
|
|
|
+ for (WeldPoint point : WELD_POINTS) {
|
|
|
+ boolean finished = readBoolean(s7PLC, point.finishAddress());
|
|
|
+ int seq = readInt16(s7PLC, point.seqAddress());
|
|
|
+ float current = readFloat32(s7PLC, point.currentAddress());
|
|
|
+ float voltage = readFloat32(s7PLC, point.voltageAddress());
|
|
|
+ float wireSpeed = readFloat32(s7PLC, point.wireSpeedAddress());
|
|
|
+ float weldSpeed = readFloat32(s7PLC, point.weldSpeedAddress());
|
|
|
+ values.add(point.name + ":finish=" + finished);
|
|
|
+ values.add(point.name + ":seq=" + seq);
|
|
|
+ values.add(point.name + ":current=" + current);
|
|
|
+ values.add(point.name + ":voltage=" + voltage);
|
|
|
+ values.add(point.name + ":wireSpeed=" + wireSpeed);
|
|
|
+ values.add(point.name + ":weldSpeed=" + weldSpeed);
|
|
|
+ }
|
|
|
+ return values;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void refreshParamText(List<String> values) {
|
|
|
+ float r1Current = valueOf(values, "R1:current=");
|
|
|
+ float r1Voltage = valueOf(values, "R1:voltage=");
|
|
|
+ float r1WireSpeed = valueOf(values, "R1:wireSpeed=");
|
|
|
+ float r1WeldSpeed = valueOf(values, "R1:weldSpeed=");
|
|
|
+ int r1Seq = (int) valueOf(values, "R1:seq=");
|
|
|
+
|
|
|
+ if ("B".equals(MesClient.curFlag)) {
|
|
|
+ MesClient.param21.setText(String.valueOf(r1Voltage));
|
|
|
+ MesClient.param22.setText(String.valueOf(r1Current));
|
|
|
+ MesClient.param23.setText(String.valueOf(r1WireSpeed));
|
|
|
+ MesClient.param24.setText(String.valueOf(r1Seq));
|
|
|
+ MesClient.param25.setText(String.valueOf(r1WeldSpeed));
|
|
|
+ } else {
|
|
|
+ MesClient.param1.setText(String.valueOf(r1Voltage));
|
|
|
+ MesClient.param2.setText(String.valueOf(r1Current));
|
|
|
+ MesClient.param3.setText(String.valueOf(r1WireSpeed));
|
|
|
+ MesClient.param4.setText(String.valueOf(r1Seq));
|
|
|
+ MesClient.param5.setText(String.valueOf(r1WeldSpeed));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static float valueOf(List<String> values, String prefix) {
|
|
|
+ for (String value : values) {
|
|
|
+ if (value.startsWith(prefix)) {
|
|
|
+ try {
|
|
|
+ return Float.parseFloat(value.substring(prefix.length()));
|
|
|
+ } catch (Exception ignored) {
|
|
|
+ return 0;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ return 0;
|
|
|
}
|
|
|
|
|
|
+ private static void saveCurrentParams() {
|
|
|
+ try {
|
|
|
+ String oprno = MesClient.mes_gw + "A";
|
|
|
+ String sn = MesClient.curSna;
|
|
|
+ if ("B".equals(MesClient.curFlag)) {
|
|
|
+ oprno = MesClient.mes_gw + "B";
|
|
|
+ sn = MesClient.curSnb;
|
|
|
+ }
|
|
|
|
|
|
- // 获取A启动状态
|
|
|
- public static Boolean getAStart(S7PLC s7PLC){
|
|
|
- try{
|
|
|
- return s7PLC.readBoolean("DB1.2.2");
|
|
|
- }catch (Exception e){
|
|
|
+ if (sn != null && !sn.trim().isEmpty()) {
|
|
|
+ JdbcUtils.insertCmtData(oprno, MesClient.mes_line_sn, sn, JSON.toJSONString(MesClient.hjparams));
|
|
|
+ System.out.println("cmt:" + MesClient.curFlag + " sn:" + sn);
|
|
|
+ } else {
|
|
|
+ System.out.println("workpiece sn is empty, skip cmt params save");
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
- return false;
|
|
|
+ } finally {
|
|
|
+ MesClient.hjparams = new ArrayList<>();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 获取A的结束状态
|
|
|
- public static Boolean getAFinish(S7PLC s7PLC){
|
|
|
- try{
|
|
|
- boolean a = s7PLC.readBoolean("DB1.2.5");
|
|
|
- boolean b = s7PLC.readBoolean("DB1.2.3");
|
|
|
-// Boolean ret = s7PLC.readBoolean("DB1.2.0");
|
|
|
+ public static Boolean getAStart(S7PLC s7PLC) {
|
|
|
+ return getWeldStatus(s7PLC, "A") == 1;
|
|
|
+ }
|
|
|
|
|
|
- return a || b;
|
|
|
- }catch (Exception e){
|
|
|
- e.printStackTrace();
|
|
|
- return false;
|
|
|
- }
|
|
|
+ public static Boolean getAFinish(S7PLC s7PLC) {
|
|
|
+ return getWeldStatus(s7PLC, "A") == 2;
|
|
|
}
|
|
|
|
|
|
- public static void getStatusA(S7PLC s7PLC){
|
|
|
- if(MesClient.tjFlaga == 1){ // 已扫码,设备未运行
|
|
|
- Boolean starta = getAStart(s7PLC); //A启动中
|
|
|
- if(starta){
|
|
|
+ public static void getStatusA(S7PLC s7PLC) {
|
|
|
+ int status = getWeldStatus(s7PLC, "A");
|
|
|
+ if (MesClient.tjFlaga == 1) {
|
|
|
+ if (status == 1) {
|
|
|
MesClient.curFlag = "A";
|
|
|
MesClient.tjFlaga = 2;
|
|
|
- MesClient.pxstatus1.setText("A:设备运行中");
|
|
|
- // 更新curSna为当前文本框中的工件码
|
|
|
- if(MesClient.curSna == null || MesClient.curSna.isEmpty()){
|
|
|
+ MesClient.pxstatus1.setText("A:\u8bbe\u5907\u8fd0\u884c\u4e2d");
|
|
|
+ if (MesClient.curSna == null || MesClient.curSna.isEmpty()) {
|
|
|
MesClient.curSna = MesClient.product_sn.getText();
|
|
|
}
|
|
|
- if(MesClient.lastpage == 0){
|
|
|
- MesClient.lastpage = 1;
|
|
|
- PlcUtil.changeEnable(s7PLC,false);
|
|
|
- }
|
|
|
- }else{
|
|
|
- // 程序号防错功能已注释 - 直接允许启动
|
|
|
- // if(CommonUtils.checkProgramNoSn(MesClient.product_sn.getText(),MesClient.programNoA)){
|
|
|
- Boolean reta = getEnable(s7PLC);
|
|
|
- if(!reta){
|
|
|
- PlcUtil.changeEnable(MesClient.s7PLC,true);
|
|
|
- }
|
|
|
- // }
|
|
|
- }
|
|
|
- }else if(MesClient.tjFlaga == 2){
|
|
|
- Boolean afinish = getAFinish(s7PLC); //A焊接完成
|
|
|
- if(afinish){ // 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");
|
|
|
-// Boolean sendret = DataUtil.sendQuality(MesClient.product_sn.getText(),"OK",MesClient.user20,"A");
|
|
|
- if(!sendret){
|
|
|
- MesClient.pxstatus1.setText("A:结果上传MES失败");
|
|
|
- MesClient.tjStatusa = 1;
|
|
|
- }else{
|
|
|
-// MesClient.pxstatus1.setText("A:提交成功");
|
|
|
-// MesClient.resetScanA();
|
|
|
- }
|
|
|
+ changeEnable(s7PLC, false, "A");
|
|
|
+ } else if (!getEnable(s7PLC, "A")) {
|
|
|
+ changeEnable(s7PLC, true, "A");
|
|
|
}
|
|
|
+ } else if (MesClient.tjFlaga == 2 && status == 2) {
|
|
|
+ finishA(s7PLC);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 获取B启动状态
|
|
|
- public static Boolean getBStart(S7PLC s7PLC){
|
|
|
- try{
|
|
|
- return s7PLC.readBoolean("DB1.2.3");
|
|
|
- }catch (Exception e){
|
|
|
- e.printStackTrace();
|
|
|
- return false;
|
|
|
+ private static void finishA(S7PLC s7PLC) {
|
|
|
+ MesClient.tjFlaga = 3;
|
|
|
+ MesClient.pxstatus1.setText("A:\u8bbe\u5907\u8fd0\u884c\u7ed3\u675f,\u63d0\u4ea4\u7ed3\u679c\u4e2d");
|
|
|
+ MesClient.finish_ok_bt.setEnabled(true);
|
|
|
+ changeEnable(s7PLC, false, "A");
|
|
|
+ ackWeldStatus(s7PLC, "A");
|
|
|
+ saveCurrentParams();
|
|
|
+
|
|
|
+ Boolean sendret = DataUtil.sendQuality(MesClient.nettyClient, MesClient.product_sn.getText(), "OK", MesClient.user20, "A");
|
|
|
+ if (!sendret) {
|
|
|
+ MesClient.pxstatus1.setText("A:\u7ed3\u679c\u4e0a\u4f20MES\u5931\u8d25");
|
|
|
+ MesClient.tjStatusa = 1;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 获取B的结束状态
|
|
|
- public static Boolean getBFinish(S7PLC s7PLC){
|
|
|
- try{
|
|
|
- boolean a = s7PLC.readBoolean("DB1.2.7");
|
|
|
- boolean b = s7PLC.readBoolean("DB1.2.2");
|
|
|
-// Boolean ret = s7PLC.readBoolean("DB1.2.1");
|
|
|
- return a || b;
|
|
|
- }catch (Exception e){
|
|
|
- e.printStackTrace();
|
|
|
- return false;
|
|
|
- }
|
|
|
+ public static Boolean getBStart(S7PLC s7PLC) {
|
|
|
+ return getWeldStatus(s7PLC, "B") == 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Boolean getBFinish(S7PLC s7PLC) {
|
|
|
+ return getWeldStatus(s7PLC, "B") == 2;
|
|
|
}
|
|
|
|
|
|
- public static void getStatusB(S7PLC s7PLC){
|
|
|
- if(MesClient.tjFlagb == 1){ // 已扫码,设备未运行
|
|
|
- Boolean startb = getBStart(s7PLC); //B启动中
|
|
|
- if(startb){
|
|
|
+ public static void getStatusB(S7PLC s7PLC) {
|
|
|
+ int status = getWeldStatus(s7PLC, "B");
|
|
|
+ if (MesClient.tjFlagb == 1) {
|
|
|
+ if (status == 1) {
|
|
|
MesClient.curFlag = "B";
|
|
|
MesClient.tjFlagb = 2;
|
|
|
- MesClient.pxstatus2.setText("B:设备运行中");
|
|
|
- // 更新curSnb为当前文本框中的工件码
|
|
|
- if(MesClient.curSnb == null || MesClient.curSnb.isEmpty()){
|
|
|
+ MesClient.pxstatus2.setText("B:\u8bbe\u5907\u8fd0\u884c\u4e2d");
|
|
|
+ if (MesClient.curSnb == null || MesClient.curSnb.isEmpty()) {
|
|
|
MesClient.curSnb = MesClient.product_sn2.getText();
|
|
|
}
|
|
|
- if(MesClient.lastpage == 0){
|
|
|
- MesClient.lastpage = 1;
|
|
|
- PlcUtil.changeEnable(s7PLC,false);
|
|
|
- }
|
|
|
- }else{
|
|
|
- // 程序号防错功能已注释 - 直接允许启动
|
|
|
- // if(CommonUtils.checkProgramNoSn(MesClient.product_sn2.getText(),MesClient.programNoB)){
|
|
|
- Boolean reta = getEnable(s7PLC);
|
|
|
- if(!reta){
|
|
|
- PlcUtil.changeEnable(MesClient.s7PLC,true);
|
|
|
- }
|
|
|
- // }
|
|
|
- }
|
|
|
- }else if(MesClient.tjFlagb == 2){
|
|
|
- Boolean bfinish = getBFinish(s7PLC); //B焊接完成
|
|
|
- if(bfinish){
|
|
|
- MesClient.tjFlagb = 3;
|
|
|
- MesClient.pxstatus2.setText("B:设备运行结束,提交结果中");
|
|
|
- MesClient.finish_ng_bt.setEnabled(true);
|
|
|
-
|
|
|
-// Boolean sendret = DataUtil.sendQuality(MesClient.product_sn2.getText(),"OK",MesClient.user20,"B");
|
|
|
- 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.resetScanB();
|
|
|
- }
|
|
|
+ changeEnable(s7PLC, false, "B");
|
|
|
+ } else if (!getEnable(s7PLC, "B")) {
|
|
|
+ changeEnable(s7PLC, true, "B");
|
|
|
}
|
|
|
+ } else if (MesClient.tjFlagb == 2 && status == 2) {
|
|
|
+ finishB(s7PLC);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ private static void finishB(S7PLC s7PLC) {
|
|
|
+ MesClient.tjFlagb = 3;
|
|
|
+ MesClient.pxstatus2.setText("B:\u8bbe\u5907\u8fd0\u884c\u7ed3\u675f,\u63d0\u4ea4\u7ed3\u679c\u4e2d");
|
|
|
+ MesClient.finish_ng_bt.setEnabled(true);
|
|
|
+ changeEnable(s7PLC, false, "B");
|
|
|
+ ackWeldStatus(s7PLC, "B");
|
|
|
+ saveCurrentParams();
|
|
|
+
|
|
|
+ Boolean sendret = DataUtil.sendQuality(MesClient.nettyClient, MesClient.product_sn2.getText(), "OK", MesClient.user20, "B");
|
|
|
+ if (!sendret) {
|
|
|
+ MesClient.pxstatus2.setText("B:\u7ed3\u679c\u4e0a\u4f20MES\u5931\u8d25");
|
|
|
+ MesClient.tjStatusb = 1;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public static Boolean changeEnable(S7PLC s7PLC, Boolean result) {
|
|
|
+ return changeEnable(s7PLC, result, getCurAside(s7PLC));
|
|
|
+ }
|
|
|
|
|
|
- // 修改设备的禁用开关
|
|
|
- public static Boolean changeEnable(S7PLC s7PLC,Boolean result){
|
|
|
- try{
|
|
|
- s7PLC.writeBoolean("DB9.18.1",result); // AB
|
|
|
+ public static Boolean changeEnable(S7PLC s7PLC, Boolean result, String side) {
|
|
|
+ try {
|
|
|
+ s7PLC.writeBoolean(enableAddress(side), result);
|
|
|
return true;
|
|
|
- }catch (Exception e){
|
|
|
+ } catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 获取MES允许的值
|
|
|
- public static Boolean getEnable(S7PLC s7PLC){
|
|
|
- Boolean ret = false;
|
|
|
- try{
|
|
|
- ret = s7PLC.readBoolean("DB9.18.1");
|
|
|
- }catch (Exception e){
|
|
|
+ public static Boolean getEnable(S7PLC s7PLC) {
|
|
|
+ return getEnable(s7PLC, getCurAside(s7PLC));
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Boolean getEnable(S7PLC s7PLC, String side) {
|
|
|
+ return readBoolean(s7PLC, enableAddress(side));
|
|
|
+ }
|
|
|
+
|
|
|
+ public static String getReserveSide(S7PLC s7PLC) {
|
|
|
+ int aStatus = getWeldStatus(s7PLC, "A");
|
|
|
+ int bStatus = getWeldStatus(s7PLC, "B");
|
|
|
+ if (aStatus == 1 || MesClient.tjFlaga == 2) {
|
|
|
+ return "B";
|
|
|
+ }
|
|
|
+ if (bStatus == 1 || MesClient.tjFlagb == 2) {
|
|
|
+ return "A";
|
|
|
+ }
|
|
|
+ return getCurAside(s7PLC);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static String getCurAside(S7PLC s7PLC) {
|
|
|
+ try {
|
|
|
+ boolean aPosition = s7PLC.readBoolean(A_POSITION);
|
|
|
+ boolean bPosition = s7PLC.readBoolean(B_POSITION);
|
|
|
+ if (aPosition) {
|
|
|
+ return "A";
|
|
|
+ }
|
|
|
+ if (bPosition) {
|
|
|
+ return "B";
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
- return ret;
|
|
|
+ if (MesClient.lastDetectedPage != null && !MesClient.lastDetectedPage.isEmpty()) {
|
|
|
+ return MesClient.lastDetectedPage;
|
|
|
+ }
|
|
|
+ return "A";
|
|
|
}
|
|
|
|
|
|
+ public static int getProgranNoA(S7PLC s7PLC) {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
|
|
|
+ public static int getProgranNoB(S7PLC s7PLC) {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
|
|
|
- // 获取当前是A面还是B面
|
|
|
- public static String getCurAside(S7PLC s7PLC){
|
|
|
- String str = "A";
|
|
|
- try{
|
|
|
- Boolean ret = s7PLC.readBoolean("DB1.2.0"); // 当前A面
|
|
|
- if(!ret){
|
|
|
- str = "B";
|
|
|
- }
|
|
|
+ private static int getWeldStatus(S7PLC s7PLC, String side) {
|
|
|
+ return readInt16(s7PLC, statusAddress(side));
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void ackWeldStatus(S7PLC s7PLC, String side) {
|
|
|
+ try {
|
|
|
+ s7PLC.writeInt16(statusAddress(side), (short) 0);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- }catch (Exception e){
|
|
|
+ private static String enableAddress(String side) {
|
|
|
+ return "B".equals(side) ? B_ENABLE : A_ENABLE;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static String statusAddress(String side) {
|
|
|
+ return "B".equals(side) ? B_STATUS : A_STATUS;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static boolean readBoolean(S7PLC s7PLC, String address) {
|
|
|
+ try {
|
|
|
+ return s7PLC.readBoolean(address);
|
|
|
+ } catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
+ return false;
|
|
|
}
|
|
|
- return str;
|
|
|
}
|
|
|
|
|
|
- // 获取程序号A
|
|
|
- public static int getProgranNoA(S7PLC s7PLC){
|
|
|
- int str = 0;
|
|
|
- try{
|
|
|
- int ret = Integer.valueOf(s7PLC.readByte("DB8.3")); // AB
|
|
|
- return ret;
|
|
|
- }catch (Exception e){
|
|
|
+ private static int readInt16(S7PLC s7PLC, String address) {
|
|
|
+ try {
|
|
|
+ return s7PLC.readInt16(address);
|
|
|
+ } catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
+ return 0;
|
|
|
}
|
|
|
- return str;
|
|
|
}
|
|
|
|
|
|
- // 获取程序号B
|
|
|
- public static int getProgranNoB(S7PLC s7PLC){
|
|
|
- int str = 0;
|
|
|
- try{
|
|
|
- int ret = Integer.valueOf(s7PLC.readByte("DB8.4")); // AB
|
|
|
- return ret;
|
|
|
- }catch (Exception e){
|
|
|
+ private static float readFloat32(S7PLC s7PLC, String address) {
|
|
|
+ try {
|
|
|
+ return s7PLC.readFloat32(address);
|
|
|
+ } catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
+ return 0;
|
|
|
}
|
|
|
- return str;
|
|
|
}
|
|
|
|
|
|
+ private static class WeldPoint {
|
|
|
+ private final String name;
|
|
|
+ private final double finishOffset;
|
|
|
+ private final int seqOffset;
|
|
|
+ private final int currentOffset;
|
|
|
+ private final int voltageOffset;
|
|
|
+ private final int wireSpeedOffset;
|
|
|
+ private final int weldSpeedOffset;
|
|
|
+
|
|
|
+ private WeldPoint(String name, double finishOffset, int seqOffset, int currentOffset, int voltageOffset,
|
|
|
+ int wireSpeedOffset, int weldSpeedOffset) {
|
|
|
+ this.name = name;
|
|
|
+ this.finishOffset = finishOffset;
|
|
|
+ this.seqOffset = seqOffset;
|
|
|
+ this.currentOffset = currentOffset;
|
|
|
+ this.voltageOffset = voltageOffset;
|
|
|
+ this.wireSpeedOffset = wireSpeedOffset;
|
|
|
+ this.weldSpeedOffset = weldSpeedOffset;
|
|
|
+ }
|
|
|
+
|
|
|
+ private String finishAddress() {
|
|
|
+ return DB + "." + String.valueOf(finishOffset);
|
|
|
+ }
|
|
|
|
|
|
+ private String seqAddress() {
|
|
|
+ return DB + "." + seqOffset;
|
|
|
+ }
|
|
|
|
|
|
+ private String currentAddress() {
|
|
|
+ return DB + "." + currentOffset;
|
|
|
+ }
|
|
|
+
|
|
|
+ private String voltageAddress() {
|
|
|
+ return DB + "." + voltageOffset;
|
|
|
+ }
|
|
|
+
|
|
|
+ private String wireSpeedAddress() {
|
|
|
+ return DB + "." + wireSpeedOffset;
|
|
|
+ }
|
|
|
+
|
|
|
+ private String weldSpeedAddress() {
|
|
|
+ return DB + "." + weldSpeedOffset;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|