PlcUtil.java 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. package com.mes.ui;
  2. import com.github.xingshuangs.iot.protocol.s7.service.S7PLC;
  3. import com.mes.util.JdbcUtils;
  4. import java.awt.*;
  5. import java.text.DecimalFormat;
  6. public class PlcUtil {
  7. public static void getDataA(S7PLC plc){
  8. int cur = plc.readInt32("DB1.184.0");
  9. MesClient.param1.setText(String.valueOf(MesClient.aMax));
  10. if(MesClient.sortA < cur){
  11. MesClient.sortA = cur;
  12. // if (cur == 9){
  13. // plc.writeUInt16("DB1.DBW54",2);
  14. // }
  15. int fout = plc.readInt32("DB1.144.0");
  16. Float sout = plc.readFloat32("DB1.148.0");
  17. int fmin = plc.readInt32("DB1.26.0");
  18. Float smin = plc.readFloat32("DB1.34.0");
  19. int fmax = plc.readInt32("DB1.22.0");
  20. Float smax = plc.readFloat32("DB1.30.0");
  21. String qty = "0";
  22. if(getResultDingA(plc).equals("OK")){
  23. MesClient.aFinish++;
  24. qty = "1";
  25. }
  26. DecimalFormat decimalFormat = new DecimalFormat("#.###");
  27. String soutstr = decimalFormat.format(sout);
  28. String foutstr = fout+"";
  29. String fminstr = fmin+"";
  30. String sminstr = decimalFormat.format(smin);
  31. String fmaxstr = fmax+"";
  32. String smaxstr = decimalFormat.format(smax);
  33. MesClient.param2.setText(cur+"");
  34. MesClient.fout.setText(foutstr);
  35. MesClient.sout.setText(soutstr);
  36. if(qty.equals("1")){
  37. MesClient.fout.setForeground(Color.BLACK);
  38. MesClient.sout.setForeground(Color.BLACK);
  39. }else{
  40. MesClient.fout.setForeground(Color.RED);
  41. MesClient.sout.setForeground(Color.RED);
  42. }
  43. if(!MesClient.product_sn.getText().isEmpty()){
  44. 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());
  45. }
  46. }
  47. upResult();
  48. }
  49. public static void getDataB(S7PLC plc){
  50. int cur = plc.readInt32("DB1.714.0");
  51. MesClient.param3.setText(String.valueOf(MesClient.bMax));
  52. if(MesClient.sortB < cur){
  53. MesClient.sortB = cur;
  54. int fout = plc.readInt32("DB1.674.0");
  55. Float sout = plc.readFloat32("DB1.678.0");
  56. int fmin = plc.readInt32("DB1.556.0");
  57. Float smin = plc.readFloat32("DB1.564.0");
  58. int fmax = plc.readInt32("DB1.552.0");
  59. Float smax = plc.readFloat32("DB1.560.0");
  60. String qty = "0";
  61. if(getResultDingB(plc).equals("OK")){
  62. MesClient.bFinish++;
  63. qty = "1";
  64. }
  65. DecimalFormat decimalFormat = new DecimalFormat("#.###");
  66. String soutstr = decimalFormat.format(sout);
  67. String foutstr = fout+"";
  68. String fminstr = fmin+"";
  69. String sminstr = decimalFormat.format(smin);
  70. String fmaxstr = fmax+"";
  71. String smaxstr = decimalFormat.format(smax);
  72. MesClient.param4.setText(cur+"");
  73. MesClient.foutB.setText(foutstr);
  74. MesClient.soutB.setText(soutstr);
  75. if(qty.equals("1")){
  76. MesClient.foutB.setForeground(Color.BLACK);
  77. MesClient.soutB.setForeground(Color.BLACK);
  78. }else{
  79. MesClient.foutB.setForeground(Color.RED);
  80. MesClient.soutB.setForeground(Color.RED);
  81. }
  82. if(!MesClient.product_sn.getText().isEmpty()){
  83. 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());
  84. }
  85. }
  86. upResult();
  87. }
  88. public static void upResult(){
  89. if(MesClient.product_sn.getText().isEmpty()){
  90. return;
  91. }
  92. boolean torqueDone = (MesClient.cura >= MesClient.maxa); // 20
  93. boolean rivetDoneA = (MesClient.sortA >= MesClient.aMax); // 19
  94. boolean rivetDoneB = (MesClient.sortB >= MesClient.bMax); // 1
  95. boolean allDone = torqueDone && rivetDoneA && rivetDoneB;
  96. if (rivetDoneA && rivetDoneB) {
  97. PlcUtil.setPowerOff(MesClient.plcA);
  98. }
  99. // boolean rivetDone = MesClient.aMax > 0 && MesClient.aMax == MesClient.sortA
  100. // && MesClient.bMax > 0 && MesClient.bMax == MesClient.sortB;
  101. // boolean torqueDone = MesClient.ygslNum == 2
  102. // ? (MesClient.cura >= MesClient.maxa && MesClient.curb >= MesClient.maxb)
  103. // : (MesClient.cura >= MesClient.maxa);
  104. if(!rivetDoneA || !rivetDoneB || !torqueDone){
  105. return;
  106. }
  107. MesClient.finish_ok_bt.setEnabled(true);
  108. MesClient.finish_ng_bt.setEnabled(true);
  109. if(MesClient.tjStatus == 0 && MesClient.check_quality_result){
  110. MesClient.tjStatus = 1;
  111. MesClient.getUser();
  112. String retf = "OK";
  113. if(MesClient.aFinish != MesClient.aMax || MesClient.bFinish != MesClient.bMax){
  114. retf = "NG";
  115. }
  116. Boolean ret = DataUtil.sendQuality(MesClient.nettyClient, MesClient.product_sn.getText(),retf, MesClient.user20);
  117. if(!ret){
  118. MesClient.setMenuStatus(MesClient.tjFlagTextErr,-1);
  119. }
  120. }
  121. }
  122. public static Boolean setPowerOn(S7PLC plc){
  123. Boolean ret = false;
  124. try{
  125. plc.writeBoolean("DB4.DBX0.1",false);
  126. ret = true;
  127. }catch (Exception e){
  128. e.printStackTrace();
  129. ret = false;
  130. }
  131. return ret;
  132. }
  133. public static Boolean setPowerOff(S7PLC plc){
  134. Boolean ret = false;
  135. try{
  136. plc.writeBoolean("DB4.DBX0.1",true);
  137. ret = true;
  138. }catch (Exception e){
  139. e.printStackTrace();
  140. ret = false;
  141. }
  142. return ret;
  143. }
  144. public static void setTask(S7PLC plc,int setNumA,int setNumB){
  145. try{
  146. plc.writeUInt16("DB1.DBW54",1);
  147. plc.writeInt32("DB1.184.0",0);
  148. plc.writeInt32("DB1.714.0",0);
  149. }catch (Exception e){
  150. e.printStackTrace();
  151. }
  152. }
  153. public static String getResultDingA(S7PLC plc){
  154. String ret = "OK";
  155. try{
  156. boolean retang = plc.readBoolean("DB1.314.1");
  157. boolean retang2 = plc.readBoolean("DB1.314.3");
  158. if(retang || retang2){
  159. ret = "NG";
  160. }
  161. }catch (Exception e){
  162. e.printStackTrace();
  163. ret = "NG";
  164. }
  165. return ret;
  166. }
  167. public static String getResultDingB(S7PLC plc){
  168. String ret = "OK";
  169. try{
  170. boolean retbng = plc.readBoolean("DB1.844.1");
  171. boolean retbng2 = plc.readBoolean("DB1.844.3");
  172. if(retbng || retbng2){
  173. ret = "NG";
  174. }
  175. }catch (Exception e){
  176. e.printStackTrace();
  177. ret = "NG";
  178. }
  179. return ret;
  180. }
  181. public static boolean plcReachable(S7PLC plc){
  182. try{
  183. plc.readBoolean("DB4.DBX0.1");
  184. return true;
  185. }catch (Exception e){
  186. return false;
  187. }
  188. }
  189. }