| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227 |
- package com.mes.ui;
- import com.github.xingshuangs.iot.protocol.s7.service.S7PLC;
- import com.mes.util.JdbcUtils;
- import java.awt.*;
- import java.text.DecimalFormat;
- public class PlcUtil {
- public static void getDataA(S7PLC plc){
- int cur = plc.readInt32("DB1.184.0");
- MesClient.param1.setText(String.valueOf(MesClient.aMax));
- if(MesClient.sortA < cur){
- MesClient.sortA = cur;
- // if (cur == 9){
- // plc.writeUInt16("DB1.DBW54",2);
- // }
- int fout = plc.readInt32("DB1.144.0");
- Float sout = plc.readFloat32("DB1.148.0");
- int fmin = plc.readInt32("DB1.26.0");
- Float smin = plc.readFloat32("DB1.34.0");
- int fmax = plc.readInt32("DB1.22.0");
- Float smax = plc.readFloat32("DB1.30.0");
- String qty = "0";
- if(getResultDingA(plc).equals("OK")){
- MesClient.aFinish++;
- qty = "1";
- }
- DecimalFormat decimalFormat = new DecimalFormat("#.###");
- String soutstr = decimalFormat.format(sout);
- String foutstr = fout+"";
- String fminstr = fmin+"";
- String sminstr = decimalFormat.format(smin);
- String fmaxstr = fmax+"";
- String smaxstr = decimalFormat.format(smax);
- MesClient.param2.setText(cur+"");
- MesClient.fout.setText(foutstr);
- MesClient.sout.setText(soutstr);
- if(qty.equals("1")){
- MesClient.fout.setForeground(Color.BLACK);
- MesClient.sout.setForeground(Color.BLACK);
- }else{
- MesClient.fout.setForeground(Color.RED);
- MesClient.sout.setForeground(Color.RED);
- }
- if(!MesClient.product_sn.getText().isEmpty()){
- JdbcUtils.insertProdData(MesClient.mes_gw, MesClient.mes_line_sn, MesClient.product_sn.getText(),"A",foutstr,soutstr,fminstr,sminstr,fmaxstr,smaxstr,qty,cur+"", MesClient.user_menu.getText());
- }
- }
- upResult();
- }
- public static void getDataB(S7PLC plc){
- int cur = plc.readInt32("DB1.714.0");
- MesClient.param3.setText(String.valueOf(MesClient.bMax));
- if(MesClient.sortB < cur){
- MesClient.sortB = cur;
- int fout = plc.readInt32("DB1.674.0");
- Float sout = plc.readFloat32("DB1.678.0");
- int fmin = plc.readInt32("DB1.556.0");
- Float smin = plc.readFloat32("DB1.564.0");
- int fmax = plc.readInt32("DB1.552.0");
- Float smax = plc.readFloat32("DB1.560.0");
- String qty = "0";
- if(getResultDingB(plc).equals("OK")){
- MesClient.bFinish++;
- qty = "1";
- }
- DecimalFormat decimalFormat = new DecimalFormat("#.###");
- String soutstr = decimalFormat.format(sout);
- String foutstr = fout+"";
- String fminstr = fmin+"";
- String sminstr = decimalFormat.format(smin);
- String fmaxstr = fmax+"";
- String smaxstr = decimalFormat.format(smax);
- MesClient.param4.setText(cur+"");
- MesClient.foutB.setText(foutstr);
- MesClient.soutB.setText(soutstr);
- if(qty.equals("1")){
- MesClient.foutB.setForeground(Color.BLACK);
- MesClient.soutB.setForeground(Color.BLACK);
- }else{
- MesClient.foutB.setForeground(Color.RED);
- MesClient.soutB.setForeground(Color.RED);
- }
- if(!MesClient.product_sn.getText().isEmpty()){
- JdbcUtils.insertProdData(MesClient.mes_gw, MesClient.mes_line_sn, MesClient.product_sn.getText(),"B",foutstr,soutstr,fminstr,sminstr,fmaxstr,smaxstr,qty,cur+"", MesClient.user_menu.getText());
- }
- }
- upResult();
- }
- public static void upResult(){
- if(MesClient.product_sn.getText().isEmpty()){
- return;
- }
- boolean torqueDone = (MesClient.cura >= MesClient.maxa); // 20
- boolean rivetDoneA = (MesClient.sortA >= MesClient.aMax); // 19
- boolean rivetDoneB = (MesClient.sortB >= MesClient.bMax); // 1
- boolean allDone = torqueDone && rivetDoneA && rivetDoneB;
- if (rivetDoneA && rivetDoneB) {
- PlcUtil.setPowerOff(MesClient.plcA);
- }
- // boolean rivetDone = MesClient.aMax > 0 && MesClient.aMax == MesClient.sortA
- // && MesClient.bMax > 0 && MesClient.bMax == MesClient.sortB;
- // boolean torqueDone = MesClient.ygslNum == 2
- // ? (MesClient.cura >= MesClient.maxa && MesClient.curb >= MesClient.maxb)
- // : (MesClient.cura >= MesClient.maxa);
- if(!rivetDoneA || !rivetDoneB || !torqueDone){
- return;
- }
- MesClient.finish_ok_bt.setEnabled(true);
- MesClient.finish_ng_bt.setEnabled(true);
- if(MesClient.tjStatus == 0 && MesClient.check_quality_result){
- MesClient.tjStatus = 1;
- MesClient.getUser();
- String retf = "OK";
- if(MesClient.aFinish != MesClient.aMax || MesClient.bFinish != MesClient.bMax){
- retf = "NG";
- }
- Boolean ret = DataUtil.sendQuality(MesClient.nettyClient, MesClient.product_sn.getText(),retf, MesClient.user20);
- if(!ret){
- MesClient.setMenuStatus(MesClient.tjFlagTextErr,-1);
- }
- }
- }
- public static Boolean setPowerOn(S7PLC plc){
- Boolean ret = false;
- try{
- plc.writeBoolean("DB4.DBX0.1",false);
- ret = true;
- }catch (Exception e){
- e.printStackTrace();
- ret = false;
- }
- return ret;
- }
- public static Boolean setPowerOff(S7PLC plc){
- Boolean ret = false;
- try{
- plc.writeBoolean("DB4.DBX0.1",true);
- ret = true;
- }catch (Exception e){
- e.printStackTrace();
- ret = false;
- }
- return ret;
- }
- public static void setTask(S7PLC plc,int setNumA,int setNumB){
- try{
- plc.writeUInt16("DB1.DBW54",1);
- plc.writeInt32("DB1.184.0",0);
- plc.writeInt32("DB1.714.0",0);
- }catch (Exception e){
- e.printStackTrace();
- }
- }
- public static String getResultDingA(S7PLC plc){
- String ret = "OK";
- try{
- boolean retang = plc.readBoolean("DB1.314.1");
- boolean retang2 = plc.readBoolean("DB1.314.3");
- if(retang || retang2){
- ret = "NG";
- }
- }catch (Exception e){
- e.printStackTrace();
- ret = "NG";
- }
- return ret;
- }
- public static String getResultDingB(S7PLC plc){
- String ret = "OK";
- try{
- boolean retbng = plc.readBoolean("DB1.844.1");
- boolean retbng2 = plc.readBoolean("DB1.844.3");
- if(retbng || retbng2){
- ret = "NG";
- }
- }catch (Exception e){
- e.printStackTrace();
- ret = "NG";
- }
- return ret;
- }
- public static boolean plcReachable(S7PLC plc){
- try{
- plc.readBoolean("DB4.DBX0.1");
- return true;
- }catch (Exception e){
- return false;
- }
- }
- }
|