package com.mes.ui; import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSONObject; import com.github.xingshuangs.iot.protocol.s7.service.S7PLC; import com.mes.util.DateLocalUtils; import com.mes.util.JdbcUtils; import org.slf4j.LoggerFactory; import java.util.ArrayList; public class PlcUtil { private static final org.slf4j.Logger log = LoggerFactory.getLogger(PlcUtil.class); // 获取并提交所有焊机参数 public static void getParamDyDl(S7PLC s7PLC){ // 直接使用统一转换好的工位代号 String op = MesClient.getCalculatedOp(); String oprno = MesClient.mes_gw + op; Boolean ret1 = s7PLC.readBoolean("DB5000.584.2"); // 焊机1运行状态 Boolean ret2 = s7PLC.readBoolean("DB5000.588.2"); // 焊机2运行状态 Boolean ret3 = s7PLC.readBoolean("DB5000.592.2"); // 焊机3运行状态 if(ret1 || ret2 || ret3){ // 焊机1 Short dya = s7PLC.readInt16("DB5000.536"); Short dla = s7PLC.readInt16("DB5000.538"); Short ssa = s7PLC.readInt16("DB5000.540"); Short cwa = s7PLC.readInt16("DB5000.542"); Short joba = s7PLC.readInt16("DB5000.544"); MesClient.param1.setText(dya+""); MesClient.param2.setText(dla+""); MesClient.param3.setText(ssa+""); MesClient.param4.setText(cwa+""); MesClient.param5.setText(joba+""); // 焊机2 Short dyb = s7PLC.readInt16("DB5000.552"); Short dlb = s7PLC.readInt16("DB5000.554"); Short ssb = s7PLC.readInt16("DB5000.556"); Short cwb = s7PLC.readInt16("DB5000.558"); Short jobb = s7PLC.readInt16("DB5000.560"); MesClient.param21.setText(dyb+""); MesClient.param22.setText(dlb+""); MesClient.param23.setText(ssb+""); MesClient.param24.setText(cwb+""); MesClient.param25.setText(jobb+""); // 焊机3 Short dyc = s7PLC.readInt16("DB5000.568"); Short dlc = s7PLC.readInt16("DB5000.570"); Short ssc = s7PLC.readInt16("DB5000.572"); Short cwc = s7PLC.readInt16("DB5000.574"); Short jobc = s7PLC.readInt16("DB5000.576"); MesClient.param31.setText(dyc+""); MesClient.param32.setText(dlc+""); MesClient.param33.setText(ssc+""); MesClient.param34.setText(cwc+""); MesClient.param35.setText(jobc+""); String record_time = DateLocalUtils.getCurrentTime(); MesClient.hjparams.add(dya+"|"+dla+"|"+ssa+"|"+cwa+"|"+joba+"|"+dyb+"|"+dlb+"|"+ssb+"|"+cwb+"|"+jobb+"|"+dyc+"|"+dlc+"|"+ssc+"|"+cwc+"|"+jobc+"|"+record_time); if(MesClient.hjparams.size() == 60){ try{ if(!MesClient.product_sn.getText().isEmpty()){ JdbcUtils.insertCmtData(oprno, MesClient.mes_line_sn, MesClient.product_sn.getText(), JSON.toJSONString(MesClient.hjparams)); } MesClient.hjparams = new ArrayList<>(); }catch (Exception e){ e.printStackTrace(); } } }else{ if(MesClient.hjparams.size() != 60 && MesClient.hjparams.size() > 0){ try{ if(!MesClient.product_sn.getText().isEmpty()){ JdbcUtils.insertCmtData(oprno, MesClient.mes_line_sn, MesClient.product_sn.getText(), JSON.toJSONString(MesClient.hjparams)); } MesClient.hjparams = new ArrayList<>(); }catch (Exception e){ e.printStackTrace(); } } } } // 统一设备状态与质量提交流程 public static void getStatus(S7PLC s7PLC){ if(MesClient.tjFlag == 1){ // 已扫码,设备未运行 Boolean feeding = getFeeding(s7PLC); if(feeding){ PlcUtil.changeEnable(s7PLC,true); } Boolean start = getStart(s7PLC); if(start){ MesClient.tjFlag = 2; MesClient.status_menu.setText("设备运行中"); } }else if(MesClient.tjFlag == 2){ Boolean finish = getFinish(s7PLC); if(finish){ MesClient.tjFlag = 3; MesClient.status_menu.setText("设备运行结束,提交结果中"); // 直接使用统一转换好的工位代号进行质量上传 String op = MesClient.getCalculatedOp(); JSONObject retObj = DataUtil.sendQuality(MesClient.product_sn.getText(), "OK", MesClient.user_menu.getText(), op); if(retObj.get("result")!=null && retObj.get("result").toString().equalsIgnoreCase("true")) { MesClient.status_menu.setText("提交成功"); MesClient.resetScan(); }else{ if(retObj.get("result")==null){ MesClient.status_menu.setText("请求失败,请重试"); }else{ if(retObj.get("result").toString().equalsIgnoreCase("false")){ MesClient.status_menu.setText(retObj.getString("message")); } } } } } } public static Boolean getFeeding(S7PLC s7PLC){ try{ return s7PLC.readBoolean(MesClient.addr_feeding); }catch (Exception e){ return false; } } public static Boolean getStart(S7PLC s7PLC){ try{ return s7PLC.readBoolean(MesClient.addr_start); }catch (Exception e){ return false; } } public static Boolean getFinish(S7PLC s7PLC){ try{ return s7PLC.readBoolean(MesClient.addr_finish); }catch (Exception e){ return false; } } public static Boolean changeEnable(S7PLC s7PLC,Boolean result){ try{ s7PLC.writeBoolean(MesClient.addr_enable, result); return true; }catch (Exception e){ return false; } } public static Boolean getEnable(S7PLC s7PLC){ try{ return s7PLC.readBoolean(MesClient.addr_enable); }catch (Exception e){ return false; } } }