WorkJPanelOP70.java 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875
  1. package com.mes.component;
  2. import com.alibaba.fastjson2.JSON;
  3. import com.alibaba.fastjson2.JSONObject;
  4. import com.github.xingshuangs.iot.protocol.s7.enums.EPlcType;
  5. import com.github.xingshuangs.iot.protocol.s7.service.S7PLC;
  6. import com.mes.ui.CacheData;
  7. import com.mes.ui.DataUtil;
  8. import com.mes.ui.MesClient;
  9. import com.mes.util.JdbcUtils;
  10. import com.mes.util.TCPClient;
  11. import org.slf4j.Logger;
  12. import org.slf4j.LoggerFactory;
  13. import javax.swing.*;
  14. import java.awt.*;
  15. import java.awt.event.*;
  16. import java.util.Timer;
  17. import java.util.TimerTask;
  18. import java.util.concurrent.ExecutorService;
  19. import java.util.concurrent.Executors;
  20. public class WorkJPanelOP70 extends JPanel {
  21. //70AC,AB同时发送上料请求,导致A无法再次响应码
  22. public static final Logger log = LoggerFactory.getLogger(WorkJPanelOP70.class);
  23. public String oprno = "OP080"; // 原OP070封板反面FSW,产线改造后工位号OP080
  24. public String pos = "A";
  25. public String lastSn = ""; // 最近的码
  26. public String lineSn = "CZ060";
  27. public JLabel feedinglabel;
  28. public JLabel feedingmeslabel;
  29. public JLabel runlabel; //运行反馈,
  30. public JLabel blankinglabel; // 下料反馈
  31. public JLabel blankingmeslabel; // 下料MES反馈
  32. public JLabel feedingtodevicelabel; // 上料到设备
  33. public JLabel feedingtotransferlabel; // 上料到中转车
  34. public JLabel transfertodevicelabel; // 上料到中转车
  35. public JButton scanBtn;
  36. public JTextField productSn;
  37. public JTextField productSnFeeding;
  38. public JButton status_menu;
  39. public JButton resetBtn;
  40. public JButton resetFeedingBtn;
  41. public ImageIcon imageGreen;
  42. public ImageIcon imageGray;
  43. public String plcIp1 = "192.168.90.85"; // plc5 西侧
  44. public String plcIp2 = "192.168.90.86"; // plc6 东侧
  45. public Integer errflag2 = 0;
  46. public S7PLC s7PLC = null;
  47. public Integer workWidth = 470;
  48. public Integer workHeight = 300;
  49. public String plcDb = "";
  50. public String plcDb2 = "DB7010";
  51. public String preSn = ""; // 扫码内容
  52. public Integer tjFeedingFlag = 0; // 上料状态标识
  53. public Integer tjFlag = 0; // 1=可加工 2=设备运行中 3=加工结束
  54. public Integer tjStatus = 0; // 提交标识
  55. public Integer sbtjStatus = 0; // 提交标识
  56. public Boolean toDevice = false;
  57. public Boolean toTransfer = false;
  58. public Boolean transferToDevice = false;
  59. public Boolean plcHeart = false;
  60. public Integer isLocal = 0; // 0=正式 1=本地
  61. public Integer isScan = 1; // 1=西侧 2=东测
  62. public String finallySn = "";
  63. public String fswDeviceName = "";
  64. public JLabel oprnoLabel;
  65. public JLabel oprnoLabel2;
  66. public JButton signalBtn; // 信号监控按钮
  67. public PlcSignalMonitor signalMonitor; // 信号监控组件
  68. public CacheData cacheData = null;
  69. public String cacheName = "";
  70. public WorkJPanelOP70(String position){
  71. this.setLayout(null);
  72. this.setBackground(Color.WHITE);
  73. this.pos = position;
  74. cacheName = "cache_"+oprno+pos;
  75. cacheData = JdbcUtils.getCache(cacheName);
  76. if(cacheData == null){
  77. cacheData = new CacheData();
  78. cacheData.setLastSn("");
  79. cacheData.setSn("");
  80. cacheData.setFeedingSn("");
  81. cacheData.setTjStatus(0);
  82. cacheData.setTjFlag(0);
  83. cacheData.setError(-1);
  84. cacheData.setMsg("");
  85. JdbcUtils.setCache(cacheName,JSON.toJSONString(cacheData));
  86. }
  87. if(MesClient.mes_line_pos.equals("east")){ // 东侧
  88. s7PLC = new S7PLC(EPlcType.S1500, plcIp2);
  89. isScan = 2;
  90. }else{
  91. s7PLC = new S7PLC(EPlcType.S1500, plcIp1);
  92. isScan = 1;
  93. }
  94. s7PLC.setConnectTimeout(1000);
  95. s7PLC.setReceiveTimeout(1000);
  96. // 设备DB对照:反面FSW1=DB7002、反面FSW2=DB7003
  97. // 原3号机、4号机已取消,C/F位不再实例化
  98. if(pos.equals("A")){
  99. plcDb = "DB7002";
  100. fswDeviceName = "西侧1号机";
  101. }else if(pos.equals("B")){
  102. plcDb = "DB7003";
  103. fswDeviceName = "西侧2号机";
  104. }else if(pos.equals("D")){
  105. plcDb = "DB7002";
  106. fswDeviceName = "东侧1号机";
  107. }else if(pos.equals("E")){
  108. plcDb = "DB7003";
  109. fswDeviceName = "东侧2号机";
  110. }
  111. oprnoLabel = new JLabel(oprno+pos);
  112. oprnoLabel.setHorizontalAlignment(SwingConstants.CENTER);
  113. oprnoLabel.setForeground(Color.BLACK);
  114. oprnoLabel.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  115. oprnoLabel.setBounds(0, -10, workWidth/5, 40);
  116. this.add(oprnoLabel);
  117. oprnoLabel2 = new JLabel(fswDeviceName);
  118. oprnoLabel2.setHorizontalAlignment(SwingConstants.CENTER);
  119. oprnoLabel2.setForeground(Color.BLACK);
  120. oprnoLabel2.setFont(new Font("微软雅黑", Font.PLAIN, 14));
  121. oprnoLabel2.setBounds(0, 12, workWidth / 5, 40);
  122. this.add(oprnoLabel2);
  123. status_menu = new JButton("等待请求扫码");
  124. status_menu.setBounds(workWidth/5, 0, workWidth*4/5, 40);
  125. status_menu.setForeground(Color.GREEN);
  126. status_menu.setForeground(Color.GREEN);
  127. status_menu.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  128. status_menu.setBackground(Color.BLACK);
  129. this.add(status_menu);
  130. JLabel oprnoLabelFeeding = new JLabel("上料");
  131. oprnoLabelFeeding.setHorizontalAlignment(SwingConstants.CENTER);
  132. oprnoLabelFeeding.setForeground(Color.BLACK);
  133. oprnoLabelFeeding.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  134. oprnoLabelFeeding.setBounds(0, 50, workWidth/5, 40);
  135. this.add(oprnoLabelFeeding);
  136. productSnFeeding = new JTextField("");
  137. productSnFeeding.setHorizontalAlignment(SwingConstants.CENTER);
  138. productSnFeeding.setForeground(Color.BLACK);
  139. productSnFeeding.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  140. productSnFeeding.setEditable(false);
  141. productSnFeeding.setBounds(workWidth/5, 50, workWidth*3/5, 40);
  142. productSnFeeding.addMouseListener(new MouseAdapter() {
  143. public void mouseClicked(MouseEvent e) {
  144. String sn = productSnFeeding.getText().trim();
  145. if(!sn.isEmpty()){
  146. MesClient.createQRCode(productSnFeeding.getText(),oprno+pos);
  147. }
  148. }
  149. });
  150. this.add(productSnFeeding);
  151. JLabel oprnoLabelWork = new JLabel("加工");
  152. oprnoLabelWork.setHorizontalAlignment(SwingConstants.CENTER);
  153. oprnoLabelWork.setForeground(Color.BLACK);
  154. oprnoLabelWork.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  155. oprnoLabelWork.setBounds(0, 100, workWidth/5, 40);
  156. this.add(oprnoLabelWork);
  157. productSn = new JTextField("");
  158. productSn.setHorizontalAlignment(SwingConstants.CENTER);
  159. productSn.setForeground(Color.BLACK);
  160. productSn.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  161. productSn.setEditable(false);
  162. productSn.setBounds(workWidth/5, 100, workWidth*3/5, 40);
  163. productSn.addMouseListener(new MouseAdapter() {
  164. public void mouseClicked(MouseEvent e) {
  165. String sn = productSn.getText().trim();
  166. if(!sn.isEmpty()){
  167. MesClient.createQRCode(productSn.getText(),oprno+pos);
  168. }
  169. }
  170. });
  171. this.add(productSn);
  172. resetFeedingBtn = new JButton("刷新");
  173. resetFeedingBtn.addActionListener(new ActionListener() {
  174. public void actionPerformed(ActionEvent e) {
  175. int choice = JOptionPane.showConfirmDialog(null, "确定刷新上料工件吗?", "操作确认", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
  176. if (choice == JOptionPane.YES_OPTION) {
  177. resetFeeding();
  178. }
  179. }
  180. });
  181. resetFeedingBtn.setFont(new Font("微软雅黑", Font.PLAIN, 22));
  182. resetFeedingBtn.setBounds(workWidth*4/5 + 10, 50, workWidth/5 - 10, 40);
  183. this.add(resetFeedingBtn);
  184. resetBtn = new JButton("刷新");
  185. resetBtn.addActionListener(new ActionListener() {
  186. public void actionPerformed(ActionEvent e) {
  187. int choice = JOptionPane.showConfirmDialog(null, "确定刷新加工工件吗?", "操作确认", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
  188. if (choice == JOptionPane.YES_OPTION) {
  189. resetBlanking();
  190. }
  191. }
  192. });
  193. resetBtn.setFont(new Font("微软雅黑", Font.PLAIN, 22));
  194. resetBtn.setBounds(workWidth*4/5 + 10, 100, workWidth/5 - 10, 40);
  195. this.add(resetBtn);
  196. imageGreen = new ImageIcon(MesClient.class.getResource("/bg/green_dot.png"));
  197. imageGreen.setImage(imageGreen.getImage().getScaledInstance(20, 20, Image.SCALE_SMOOTH));
  198. imageGray = new ImageIcon(MesClient.class.getResource("/bg/grey_dot.png"));
  199. imageGray.setImage(imageGray.getImage().getScaledInstance(20, 20, Image.SCALE_SMOOTH));
  200. // 信号灯布局:2列×4行,名称后显示PLC点位
  201. feedinglabel = new JLabel(withAddr("请求扫码", plcDb+".0.0"));
  202. feedinglabel.setHorizontalAlignment(SwingConstants.LEFT);
  203. feedinglabel.setIcon(imageGreen);
  204. feedinglabel.setForeground(Color.BLACK);
  205. feedinglabel.setBounds(0, 145, workWidth/2, 27);
  206. this.add(feedinglabel);
  207. feedingmeslabel = new JLabel(withAddr("MES扫码反馈", plcDb+".0.4"));
  208. feedingmeslabel.setHorizontalAlignment(SwingConstants.LEFT);
  209. feedingmeslabel.setIcon(imageGreen);
  210. feedingmeslabel.setForeground(Color.BLACK);
  211. feedingmeslabel.setBounds(workWidth/2, 145, workWidth/2, 27);
  212. feedingmeslabel.addMouseListener(new MouseAdapter() {
  213. public void mouseClicked(MouseEvent e) {
  214. boolean ret = readAllowFeeding();
  215. int choice = JOptionPane.showConfirmDialog(null, "确定修改MES扫码反馈结果为"+(ret?"false":"true")+"吗?", "操作确认", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
  216. if (choice == JOptionPane.YES_OPTION) {
  217. writeAllowFeeding(!ret);
  218. }
  219. }
  220. });
  221. this.add(feedingmeslabel);
  222. runlabel = new JLabel(withAddr("设备运行中", plcDb+".0.2"));
  223. runlabel.setHorizontalAlignment(SwingConstants.LEFT);
  224. runlabel.setIcon(imageGreen);
  225. runlabel.setForeground(Color.BLACK);
  226. runlabel.setBounds(0, 199, workWidth/2, 27);
  227. this.add(runlabel);
  228. blankinglabel = new JLabel(withAddr("下料请求", plcDb+".0.1"));
  229. blankinglabel.setHorizontalAlignment(SwingConstants.LEFT);
  230. blankinglabel.setIcon(imageGreen);
  231. blankinglabel.setForeground(Color.BLACK);
  232. blankinglabel.setBounds(0, 172, workWidth/2, 27);
  233. this.add(blankinglabel);
  234. blankingmeslabel = new JLabel(withAddr("MES下料反馈", plcDb+".0.5"));
  235. blankingmeslabel.setHorizontalAlignment(SwingConstants.LEFT);
  236. blankingmeslabel.setIcon(imageGreen);
  237. blankingmeslabel.setForeground(Color.BLACK);
  238. blankingmeslabel.setBounds(workWidth/2, 172, workWidth/2, 27);
  239. this.add(blankingmeslabel);
  240. blankingmeslabel.addMouseListener(new MouseAdapter() {
  241. public void mouseClicked(MouseEvent e) {
  242. boolean ret = readAllowBlanking();
  243. int choice = JOptionPane.showConfirmDialog(null, "确定修改MES下料反馈结果为"+(ret?"false":"true")+"吗?", "操作确认", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
  244. if (choice == JOptionPane.YES_OPTION) {
  245. writeAllowBlanking(!ret);
  246. }
  247. }
  248. });
  249. feedingtodevicelabel = new JLabel(withAddr("上料到设备", plcDb+".0.7"));
  250. feedingtodevicelabel.setHorizontalAlignment(SwingConstants.LEFT);
  251. feedingtodevicelabel.setIcon(imageGreen);
  252. feedingtodevicelabel.setForeground(Color.BLACK);
  253. feedingtodevicelabel.setBounds(workWidth/2, 199, workWidth/2, 27);
  254. this.add(feedingtodevicelabel);
  255. feedingtotransferlabel = new JLabel(withAddr("上料到中转车", plcDb+".1.0"));
  256. feedingtotransferlabel.setHorizontalAlignment(SwingConstants.LEFT);
  257. feedingtotransferlabel.setIcon(imageGreen);
  258. feedingtotransferlabel.setForeground(Color.BLACK);
  259. feedingtotransferlabel.setBounds(0, 226, workWidth/2, 27);
  260. this.add(feedingtotransferlabel);
  261. transfertodevicelabel = new JLabel(withAddr("中转车上料到设备", plcDb+".1.1"));
  262. transfertodevicelabel.setHorizontalAlignment(SwingConstants.LEFT);
  263. transfertodevicelabel.setIcon(imageGreen);
  264. transfertodevicelabel.setForeground(Color.BLACK);
  265. transfertodevicelabel.setBounds(workWidth/2, 226, workWidth/2, 27);
  266. this.add(transfertodevicelabel);
  267. formatElementUI();
  268. startOprnoTimer();
  269. heartData();
  270. // 信号监控按钮
  271. signalMonitor = new PlcSignalMonitor(s7PLC, plcDb, oprno + pos, MesClient.mesClientFrame);
  272. signalBtn = signalMonitor.createSignalButton();
  273. signalBtn.setBounds(workWidth*2/3 + 63, 255, 90, 26); // 信号灯改为4行后下移
  274. this.add(signalBtn);
  275. // resetScanA();
  276. monitorDeviceStatus();
  277. }
  278. public void formatElementUI(){
  279. cacheData = JdbcUtils.getCache(cacheName);
  280. if(cacheData == null){
  281. return;
  282. }
  283. String msg = cacheData.getMsg();
  284. int error = cacheData.getError();
  285. String sn = cacheData.getSn();
  286. productSn.setText(sn);
  287. String feedingSn = cacheData.getFeedingSn();
  288. productSnFeeding.setText(feedingSn);
  289. tjFlag = cacheData.getTjFlag();
  290. lastSn = cacheData.getLastSn();
  291. setMenuStatus(msg,error);
  292. this.repaint();
  293. }
  294. public void setMenuStatus(String msg,int error){
  295. if(error == 0){
  296. this.status_menu.setForeground(Color.GREEN);
  297. }else{
  298. this.status_menu.setForeground(Color.RED);
  299. }
  300. this.status_menu.setText(msg);
  301. cacheData.setMsg(msg);
  302. cacheData.setError(error);
  303. cacheData.setTjFlag(tjFlag);
  304. cacheData.setTjStatus(tjStatus);
  305. cacheData.setLastSn(lastSn);
  306. cacheData.setSn(productSn.getText());
  307. cacheData.setFeedingSn(productSnFeeding.getText());
  308. JdbcUtils.setCache(cacheName, JSON.toJSONString(cacheData));
  309. }
  310. // 定时任务 -----------------------------------------------------------------------------------------------------
  311. public Timer cjTimerText2;
  312. public void heartData() {
  313. if(cjTimerText2!=null) {
  314. cjTimerText2.cancel();
  315. }
  316. cjTimerText2 = new Timer();
  317. cjTimerText2.schedule(new TimerTask() {
  318. public void run() {
  319. if(MesClient.isLogin == 1 && isLocal == 0){
  320. plcHeart = !plcHeart;
  321. writeBoolean(plcDb+".0.6",plcHeart);
  322. }
  323. }
  324. }, 1000,1000);
  325. }
  326. public Timer cjTimerText3;
  327. public void monitorDeviceStatus() {
  328. if(cjTimerText3!=null) {
  329. cjTimerText3.cancel();
  330. }
  331. cjTimerText3 = new Timer();
  332. cjTimerText3.schedule(new TimerTask() {
  333. public void run() {
  334. if(MesClient.isLogin == 1 && isLocal == 0){
  335. try{
  336. int ret = getAlarm();
  337. if(ret == 0){
  338. errflag2 = 0;
  339. }
  340. if(ret != 0 && errflag2 == 0 ){
  341. String content = oprno+pos;
  342. if(ret == 1){
  343. content += "安全门故障";
  344. }else if(ret == 2){
  345. content += "急停故障";
  346. }else if(ret == 3){
  347. content += "光栅故障";
  348. }else if(ret == 4){
  349. content += "夹紧故障";
  350. }
  351. errflag2 = 1;
  352. DataUtil.deviceAlarm(oprno+pos,productSn.getText(),content,MesClient.user_menu.getText());
  353. }
  354. }catch (Exception e){
  355. }
  356. }
  357. }
  358. }, 1000,1000);
  359. }
  360. public Timer oprnoTimer;
  361. public void startOprnoTimer() {
  362. //心跳显示图标
  363. if(oprnoTimer!=null) {
  364. oprnoTimer.cancel();
  365. }
  366. oprnoTimer = new Timer();
  367. oprnoTimer.schedule(new TimerTask() {
  368. public void run() {
  369. try{
  370. if(MesClient.isLogin == 1){
  371. Boolean retFeeding = readFeeding();
  372. feedinglabel.setIcon(retFeeding?imageGreen:imageGray);
  373. transferToDevice = readFeedingTransferToDevice();
  374. transfertodevicelabel.setIcon(transferToDevice?imageGreen:imageGray);
  375. Boolean retFeedingAllow = readAllowFeeding();
  376. feedingmeslabel.setIcon(retFeedingAllow?imageGreen:imageGray);
  377. if(!retFeeding && retFeedingAllow){
  378. writeAllowFeeding(false);
  379. }
  380. Boolean retBlanking = readBlanking(); //请求下料
  381. blankinglabel.setIcon(retBlanking?imageGreen:imageGray);
  382. Boolean retAllowBlanking = readAllowBlanking(); //MES 允许下料
  383. blankingmeslabel.setIcon(retAllowBlanking?imageGreen:imageGray);
  384. toDevice = readFeedingToDevice(); //目标是否为设备
  385. feedingtodevicelabel.setIcon(toDevice?imageGreen:imageGray);
  386. toTransfer = readFeedingToTransfer(); //目标是否为中转车
  387. feedingtotransferlabel.setIcon(toTransfer?imageGreen:imageGray);
  388. transferToDevice = readFeedingTransferToDevice(); //中专车到设备
  389. transfertodevicelabel.setIcon(transferToDevice?imageGreen:imageGray);
  390. Boolean retRunning = readRunning(); //设备是否运行
  391. runlabel.setIcon(retRunning?imageGreen:imageGray);
  392. /**
  393. * 1.70xh会进行扫码并给反馈
  394. * 2.执行上料,从mesclient中获取全局码,并给上料反馈
  395. * */
  396. //如果允许下料,但未输入条码,则允许下料
  397. if(retBlanking && productSn.getText().isEmpty()){
  398. writeAllowBlanking(true);
  399. resetBlanking();
  400. }
  401. //上料
  402. if(tjFeedingFlag == 0){
  403. if(retFeeding){ //读取上料信号
  404. barCode(); //获取全局码,并给上料反馈
  405. }
  406. if(retRunning){
  407. resetFeeding();
  408. }
  409. }else if(tjFeedingFlag == 1){
  410. // if(toDevice){ // 去设备
  411. if(tjFlag == 0 && retRunning){
  412. tjFlag = 1;
  413. productSn.setText(productSnFeeding.getText());
  414. // resetBtn.setEnabled(false);
  415. resetFeeding();
  416. }
  417. }
  418. if(tjFlag == 0 && !retBlanking){
  419. writeAllowBlanking(false);
  420. }
  421. if(tjFlag == 1){
  422. // if(toDevice){ // 去设备
  423. if(retRunning){
  424. tjFlag = 2;
  425. setMenuStatus("工件加工中", 0);
  426. // 运行中清除下料反馈
  427. writeAllowBlanking(false);
  428. }
  429. // }
  430. }else if(tjFlag == 2){
  431. if(retBlanking){
  432. tjFlag = 3;
  433. setMenuStatus("工件加工结束,结果上传中", 0);
  434. if(sbtjStatus == 0){
  435. sbtjStatus = 1;
  436. log.info("开始上传结果:"+productSn.getText()+" oprno:"+oprno+pos);
  437. JSONObject retObj = DataUtil.sendQuality(productSn.getText(),oprno+pos,"OK",MesClient.user_menu.getText());
  438. if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
  439. resetBlanking();
  440. }else{
  441. if(retObj.get("result")==null){
  442. log.info("结果上传失败result为null:"+productSn.getText()+" oprno:"+oprno+pos);
  443. setMenuStatus("请求失败,请重试",-1);
  444. }else{
  445. if(retObj.get("result").toString().equalsIgnoreCase("false")){
  446. log.info("结果上传失败:"+retObj.getString("message"));
  447. setMenuStatus(retObj.getString("message"),-1);
  448. }
  449. }
  450. }
  451. }
  452. }
  453. }
  454. }
  455. }catch (Exception e) {
  456. log.error(e.getMessage());
  457. }
  458. }
  459. }, 100,1500);
  460. }
  461. public void barCode2(){
  462. String sn = "";
  463. if(isScan == 1){
  464. sn = MesClient.scanQrcode2();
  465. }else{
  466. sn = MesClient.scanQrcode3();
  467. }
  468. preSn = sn.trim();
  469. log.info("preSn:"+preSn);
  470. MesClient.setMenuStatus("工件码:"+sn, 0);
  471. if(sn.length() != WorkJPanel70Xh.SN_LENGTH){
  472. // MesClient.setMenuStatus("扫码结果为空", -1);
  473. }else{
  474. finallySn = sn; //全局码
  475. productSnFeeding.setText(sn);
  476. // writeScanFinish(true);
  477. }
  478. }
  479. public void barCode(){
  480. //如果为空则不进行上料
  481. if(!productSnFeeding.getText().isEmpty()){
  482. return;
  483. }
  484. String sn = readQrcode();
  485. if(sn.equals("")){
  486. if(productSnFeeding.getText().isEmpty()){
  487. productSnFeeding.setText("空结果");
  488. this.setMenuStatus("扫码结果为空", -1);
  489. }
  490. }else{
  491. productSnFeeding.setText(sn);
  492. lastSn = sn;
  493. // 查询工件质量
  494. JSONObject retObj = DataUtil.checkQuality(sn,oprno+pos,MesClient.user_menu.getText());
  495. if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
  496. tjFeedingFlag = 1;//可加工
  497. setMenuStatus("工件可以加工", 0);
  498. writeAllowFeeding(true); //允许上料
  499. // resetFeedingBtn.setEnabled(false);
  500. }else{
  501. writeAllowFeeding(false);
  502. resetFeedingBtn.setEnabled(true);
  503. if(retObj.get("result")==null){
  504. setMenuStatus("请求失败,请重试",-1);
  505. }else{
  506. if(retObj.get("result").toString().equalsIgnoreCase("false")){
  507. setMenuStatus(retObj.getString("message"),-1);
  508. }
  509. }
  510. }
  511. }
  512. }
  513. public void resetBlanking() {
  514. tjFlag = 0;
  515. tjStatus = 0;
  516. sbtjStatus = 0;
  517. productSn.setText("");
  518. setMenuStatus("工件结果已提交,等待下一件",0);
  519. resetBtn.setEnabled(true);
  520. // writeAllowFeeding(false);
  521. // writeAllowBlanking(false);
  522. }
  523. public void resetFeeding() {
  524. productSnFeeding.setText("");
  525. tjFeedingFlag = 0;
  526. setMenuStatus("等待请求扫码",0);
  527. resetFeedingBtn.setEnabled(true);
  528. writeAllowFeeding(false);
  529. }
  530. public void resetScanA() {
  531. tjFeedingFlag = 0;
  532. tjFlag = 0;
  533. tjStatus = 0;
  534. productSn.setText("");
  535. productSnFeeding.setText("");
  536. setMenuStatus("等待请求扫码",0);
  537. resetBtn.setEnabled(true);
  538. resetFeedingBtn.setEnabled(true);
  539. if(isLocal == 0){
  540. writeAllowFeeding(false);
  541. writeAllowBlanking(false);
  542. }
  543. }
  544. //原来的扫码为上料
  545. // 与设备交互-----------------------------------------------------------------------------------------
  546. // 请求扫码
  547. public boolean readScanFeeding(){
  548. if(isLocal == 1){
  549. return false;
  550. }else{
  551. return readBoolean(plcDb2+".0.0"); //7002 扫码
  552. }
  553. }
  554. // 扫码完成
  555. public boolean readScanFinish(){
  556. if(isLocal == 1){
  557. return false;
  558. }else{
  559. return readBoolean(plcDb2+".0.1"); //扫码完成
  560. }
  561. }
  562. // 扫码完成反馈
  563. public boolean writeScanFinish(boolean bt){
  564. if(isLocal == 1){
  565. return false;
  566. }else{
  567. return writeBoolean(plcDb2+".0.1",bt);
  568. }
  569. }
  570. // 请求扫码
  571. public boolean readFeeding(){
  572. if(isLocal == 1){
  573. return false;
  574. }else{
  575. return readBoolean(plcDb+".0.0");
  576. }
  577. }
  578. // 读取上料到设备
  579. public boolean readFeedingToDevice(){
  580. if(isLocal == 1){
  581. return true;
  582. }else{
  583. return readBoolean(plcDb+".0.7");
  584. }
  585. }
  586. // 读取上料到中转车
  587. public boolean readFeedingToTransfer(){
  588. if(isLocal == 1){
  589. return true;
  590. }else{
  591. return readBoolean(plcDb+".1.0");
  592. }
  593. }
  594. // 读取中转车上料到设备
  595. public boolean readFeedingTransferToDevice(){
  596. if(isLocal == 1){
  597. return true;
  598. }else{
  599. return readBoolean(plcDb+".1.1");
  600. }
  601. }
  602. // 读取下料信号
  603. public boolean readBlanking(){
  604. if(isLocal == 1){
  605. return false;
  606. }else{
  607. return readBoolean(plcDb+".0.1");
  608. }
  609. }
  610. // 读取设备运行信号
  611. public boolean readRunning(){
  612. if(isLocal == 1){
  613. return true;
  614. }else{
  615. return readBoolean(plcDb+".0.2");
  616. }
  617. }
  618. // 读取设备通讯状态
  619. public boolean readDeviceStatus(){
  620. if(isLocal == 1){
  621. return true;
  622. }else{
  623. return readBoolean(plcDb+".0.3");
  624. }
  625. }
  626. // 读取MES允许上料信号
  627. public boolean readAllowFeeding(){
  628. if(isLocal == 1){
  629. return false;
  630. }else{
  631. return readBoolean(plcDb+".0.4");
  632. }
  633. }
  634. // 写入MES允许上料信号
  635. public boolean writeAllowFeeding(Boolean b){
  636. if(isLocal == 1){
  637. return true;
  638. }else{
  639. return writeBoolean(plcDb+".0.4",b);
  640. }
  641. }
  642. // 读取MES允许下料信号
  643. public boolean readAllowBlanking(){
  644. if(isLocal == 1){
  645. return true;
  646. }else{
  647. return readBoolean(plcDb+".0.5");
  648. }
  649. }
  650. // 写入MES允许下料信号
  651. public boolean writeAllowBlanking(Boolean b){
  652. if(isLocal == 1){
  653. return true;
  654. }else{
  655. return writeBoolean(plcDb+".0.5",b);
  656. }
  657. }
  658. // 读取中转车号
  659. public int readTransferNo(){
  660. if(isLocal == 1){
  661. return 1;
  662. }else{
  663. return s7PLC.readInt16(plcDb+".2.0");
  664. }
  665. }
  666. // 读取中转车层数
  667. public int readTransferFloor(){
  668. if(isLocal == 1){
  669. return 1;
  670. }else{
  671. return s7PLC.readInt16(plcDb+".4.0");
  672. }
  673. }
  674. // 信号灯文字:名称(点位)
  675. private String withAddr(String name, String addr){
  676. return name + "(" + addr + ")";
  677. }
  678. // 控制扫码枪读取二维码
  679. public String readQrcode(){
  680. // String sn = "5001040043561010006";
  681. String sn = "";
  682. // String sn = finallySn;
  683. if(isLocal == 1){
  684. return "";
  685. }else{
  686. return MesClient.workJPanel70Xh.productSnFeeding.getText().trim();
  687. }
  688. // return sn;
  689. }
  690. public boolean readBoolean(String db){
  691. boolean permit;
  692. try {
  693. permit = s7PLC.readBoolean(db);
  694. // log.info("<"+this.oprno+this.pos+">读取"+db+"-->成功,结果:{}", permit ? "true" : "false");
  695. } catch (Exception e) {
  696. log.error("<"+this.oprno+this.pos+">读取"+db+"-->失败", e);
  697. return false;
  698. }
  699. return permit;
  700. }
  701. public boolean writeBoolean(String db, boolean permit){
  702. try {
  703. s7PLC.writeBoolean(db,permit);
  704. // log.info("<"+this.oprno+this.pos+">写入"+db+"-->成功,写入内容:{}", permit ? "true" : "false");
  705. } catch (Exception e) {
  706. // log.error("<"+this.oprno+this.pos+">写入"+db+"-->失败,写入内容:{}", permit ? "true" : "false");
  707. log.error(e.getMessage(), e);
  708. return false;
  709. }
  710. return true;
  711. }
  712. public int getAlarm(){
  713. boolean ret0 = readBoolean(plcDb+".6.0");
  714. if(ret0){
  715. return 1;
  716. }
  717. boolean ret1 = readBoolean(plcDb+".6.1");
  718. if(ret1){
  719. return 2;
  720. }
  721. boolean ret2 = readBoolean(plcDb+".6.2");
  722. if(ret2){
  723. return 3;
  724. }
  725. boolean ret4 = readBoolean(plcDb+".6.3");
  726. if(ret4){
  727. return 4;
  728. }
  729. return 0;
  730. }
  731. }