WorkJPanelOP60Transfer.java 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742
  1. package com.mes.component;
  2. import com.alibaba.fastjson2.JSONObject;
  3. import com.github.xingshuangs.iot.protocol.s7.enums.EPlcType;
  4. import com.github.xingshuangs.iot.protocol.s7.service.S7PLC;
  5. import com.mes.ui.DataUtil;
  6. import com.mes.ui.MesClient;
  7. import org.slf4j.Logger;
  8. import org.slf4j.LoggerFactory;
  9. import javax.swing.*;
  10. import java.awt.*;
  11. import java.awt.event.ActionEvent;
  12. import java.awt.event.ActionListener;
  13. import java.awt.event.MouseAdapter;
  14. import java.awt.event.MouseEvent;
  15. import java.util.Timer;
  16. import java.util.TimerTask;
  17. import java.util.concurrent.ExecutorService;
  18. import java.util.concurrent.Executors;
  19. public class WorkJPanelOP60Transfer extends JPanel {
  20. public static final Logger log = LoggerFactory.getLogger(WorkJPanelOP60Transfer.class);
  21. public String oprno = "OP070"; // 原OP060中转车,产线改造后工位号OP070
  22. public String pos = "A";
  23. public String lastSn = ""; // 最近的码
  24. public String lineSn = "XT";
  25. public JLabel feedinglabel;
  26. public JLabel feedingmeslabel;
  27. public JLabel runlabel; //运行反馈,
  28. public JLabel blankinglabel; // 下料反馈
  29. public JLabel blankingmeslabel; // 下料MES反馈
  30. public JLabel feedingtodevicelabel; // 上料到设备
  31. public JLabel feedingtotransferlabel; // 上料到中转车
  32. public JLabel transfertodevicelabel; // 上料到中转车
  33. public JButton scanBtn;
  34. public JTextField productSn;
  35. public JTextField productSnFeeding;
  36. public JButton status_menu;
  37. public JButton resetBtn;
  38. public JButton resetFeedingBtn;
  39. public ImageIcon imageGreen;
  40. public ImageIcon imageGray;
  41. public String plcIp1 = "192.168.90.85"; // plc5 西侧
  42. public String plcIp2 = "192.168.90.86"; // plc6 东侧
  43. public S7PLC s7PLC = null;
  44. public Integer workWidth = 470;
  45. public Integer workHeight = 300;
  46. public String plcDb = "";
  47. public Integer tjFeedingFlag = 0; // 上料状态标识
  48. public Integer tjFlag = 0; // 1=可加工 2=设备运行中 3=加工结束
  49. public Integer tjStatus = 0; // 提交标识
  50. public Boolean toDevice = false;
  51. public Boolean toTransfer = false;
  52. public Boolean transferToDevice = false;
  53. public Boolean plcHeart = false;
  54. public Integer isLocal = 0; // 0=正式 1=本地
  55. public Integer isScan = 2; // 1=西侧 2=东测
  56. public int transferSn = 0;
  57. public int transferFloor = 0;
  58. public JButton signalBtn; // 信号监控按钮
  59. public PlcSignalMonitor signalMonitor; // 信号监控组件
  60. public WorkJPanelOP60Transfer(String position){
  61. this.setLayout(null);
  62. this.setBackground(Color.WHITE);
  63. this.pos = position;
  64. if(MesClient.mes_line_pos.equals("east")){ // 东侧
  65. s7PLC = new S7PLC(EPlcType.S1500, plcIp2);
  66. isScan = 2;
  67. }else{
  68. s7PLC = new S7PLC(EPlcType.S1500, plcIp1);
  69. isScan = 1;
  70. }
  71. plcDb = "DB7001";
  72. JLabel oprnoLabel = new JLabel("OP70中转车");
  73. oprnoLabel.setHorizontalAlignment(SwingConstants.CENTER);
  74. oprnoLabel.setForeground(Color.BLACK);
  75. oprnoLabel.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  76. oprnoLabel.setBounds(0, 0, workWidth/5, 40);
  77. this.add(oprnoLabel);
  78. status_menu = new JButton("等待请求扫码");
  79. status_menu.setBounds(workWidth/5, 0, workWidth*4/5, 40);
  80. status_menu.setForeground(Color.GREEN);
  81. status_menu.setForeground(Color.GREEN);
  82. status_menu.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  83. status_menu.setBackground(Color.BLACK);
  84. this.add(status_menu);
  85. JLabel oprnoLabelFeeding = new JLabel("上料");
  86. oprnoLabelFeeding.setHorizontalAlignment(SwingConstants.CENTER);
  87. oprnoLabelFeeding.setForeground(Color.BLACK);
  88. oprnoLabelFeeding.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  89. oprnoLabelFeeding.setBounds(0, 50, workWidth/5, 40);
  90. this.add(oprnoLabelFeeding);
  91. productSnFeeding = new JTextField("");
  92. productSnFeeding.setHorizontalAlignment(SwingConstants.CENTER);
  93. productSnFeeding.setForeground(Color.BLACK);
  94. productSnFeeding.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  95. productSnFeeding.setEditable(false);
  96. productSnFeeding.setBounds(workWidth/5, 50, workWidth*3/5, 40);
  97. productSnFeeding.addMouseListener(new MouseAdapter() {
  98. public void mouseClicked(MouseEvent e) {
  99. String sn = productSnFeeding.getText().trim();
  100. if(!sn.isEmpty()){
  101. MesClient.createQRCode(productSnFeeding.getText(),oprno+pos);
  102. }
  103. }
  104. });
  105. this.add(productSnFeeding);
  106. JLabel oprnoLabelWork = new JLabel("加工");
  107. oprnoLabelWork.setHorizontalAlignment(SwingConstants.CENTER);
  108. oprnoLabelWork.setForeground(Color.BLACK);
  109. oprnoLabelWork.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  110. oprnoLabelWork.setBounds(0, 100, workWidth/5, 40);
  111. this.add(oprnoLabelWork);
  112. productSn = new JTextField("");
  113. productSn.setHorizontalAlignment(SwingConstants.CENTER);
  114. productSn.setForeground(Color.BLACK);
  115. productSn.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  116. productSn.setEditable(false);
  117. productSn.setBounds(workWidth/5, 100, workWidth*3/5, 40);
  118. productSn.addMouseListener(new MouseAdapter() {
  119. public void mouseClicked(MouseEvent e) {
  120. String sn = productSn.getText().trim();
  121. if(!sn.isEmpty()){
  122. MesClient.createQRCode(productSn.getText(),oprno+pos);
  123. }
  124. }
  125. });
  126. this.add(productSn);
  127. resetFeedingBtn = new JButton("刷新");
  128. resetFeedingBtn.addActionListener(new ActionListener() {
  129. public void actionPerformed(ActionEvent e) {
  130. int choice = JOptionPane.showConfirmDialog(null, "确定刷新上料工件吗?", "操作确认", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
  131. if (choice == JOptionPane.YES_OPTION) {
  132. resetFeeding();
  133. }
  134. }
  135. });
  136. resetFeedingBtn.setFont(new Font("微软雅黑", Font.PLAIN, 22));
  137. resetFeedingBtn.setBounds(workWidth*4/5 + 10, 50, workWidth/5 - 10, 40);
  138. this.add(resetFeedingBtn);
  139. resetBtn = new JButton("刷新");
  140. resetBtn.addActionListener(new ActionListener() {
  141. public void actionPerformed(ActionEvent e) {
  142. int choice = JOptionPane.showConfirmDialog(null, "确定刷新加工工件吗?", "操作确认", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
  143. if (choice == JOptionPane.YES_OPTION) {
  144. resetBlanking();
  145. }
  146. }
  147. });
  148. resetBtn.setFont(new Font("微软雅黑", Font.PLAIN, 22));
  149. resetBtn.setBounds(workWidth*4/5 + 10, 100, workWidth/5 - 10, 40);
  150. this.add(resetBtn);
  151. imageGreen = new ImageIcon(MesClient.class.getResource("/bg/green_dot.png"));
  152. imageGreen.setImage(imageGreen.getImage().getScaledInstance(20, 20, Image.SCALE_SMOOTH));
  153. imageGray = new ImageIcon(MesClient.class.getResource("/bg/grey_dot.png"));
  154. imageGray.setImage(imageGray.getImage().getScaledInstance(20, 20, Image.SCALE_SMOOTH));
  155. feedinglabel = new JLabel("请求扫码");
  156. feedinglabel.setHorizontalAlignment(SwingConstants.LEFT);
  157. feedinglabel.setIcon(imageGreen);
  158. feedinglabel.setForeground(Color.BLACK);
  159. feedinglabel.setBounds(0, 150, workWidth/3, 30);
  160. this.add(feedinglabel);
  161. feedingmeslabel = new JLabel("MES扫码反馈");
  162. feedingmeslabel.setHorizontalAlignment(SwingConstants.LEFT);
  163. feedingmeslabel.setIcon(imageGreen);
  164. feedingmeslabel.setForeground(Color.BLACK);
  165. feedingmeslabel.setBounds(workWidth/3, 150, workWidth/3, 30);
  166. feedingmeslabel.addMouseListener(new MouseAdapter() {
  167. public void mouseClicked(MouseEvent e) {
  168. boolean ret = readAllowFeeding();
  169. int choice = JOptionPane.showConfirmDialog(null, "确定修改MES扫码反馈结果为"+(ret?"false":"true")+"吗?", "操作确认", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
  170. if (choice == JOptionPane.YES_OPTION) {
  171. writeAllowFeeding(!ret);
  172. }
  173. }
  174. });
  175. this.add(feedingmeslabel);
  176. runlabel = new JLabel("设备运行中");
  177. runlabel.setHorizontalAlignment(SwingConstants.LEFT);
  178. runlabel.setIcon(imageGreen);
  179. runlabel.setForeground(Color.BLACK);
  180. runlabel.setBounds(workWidth*2/3, 150, workWidth/3, 30);
  181. this.add(runlabel);
  182. blankinglabel = new JLabel("下料请求");
  183. blankinglabel.setHorizontalAlignment(SwingConstants.LEFT);
  184. blankinglabel.setIcon(imageGreen);
  185. blankinglabel.setForeground(Color.BLACK);
  186. blankinglabel.setBounds(0, 190, workWidth/3, 30);
  187. this.add(blankinglabel);
  188. blankingmeslabel = new JLabel("MES下料反馈");
  189. blankingmeslabel.setHorizontalAlignment(SwingConstants.LEFT);
  190. blankingmeslabel.setIcon(imageGreen);
  191. blankingmeslabel.setForeground(Color.BLACK);
  192. blankingmeslabel.setBounds(workWidth/3, 190, workWidth/3, 30);
  193. this.add(blankingmeslabel);
  194. blankingmeslabel.addMouseListener(new MouseAdapter() {
  195. public void mouseClicked(MouseEvent e) {
  196. boolean ret = readAllowBlanking();
  197. int choice = JOptionPane.showConfirmDialog(null, "确定修改MES下料反馈结果为"+(ret?"false":"true")+"吗?", "操作确认", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
  198. if (choice == JOptionPane.YES_OPTION) {
  199. writeAllowBlanking(!ret);
  200. }
  201. }
  202. });
  203. feedingtodevicelabel = new JLabel("上料到设备");
  204. feedingtodevicelabel.setHorizontalAlignment(SwingConstants.LEFT);
  205. feedingtodevicelabel.setIcon(imageGreen);
  206. feedingtodevicelabel.setForeground(Color.BLACK);
  207. feedingtodevicelabel.setBounds(workWidth*2/3, 190, workWidth/3, 30);
  208. this.add(feedingtodevicelabel);
  209. feedingtotransferlabel = new JLabel("上料到中转车");
  210. feedingtotransferlabel.setHorizontalAlignment(SwingConstants.LEFT);
  211. feedingtotransferlabel.setIcon(imageGreen);
  212. feedingtotransferlabel.setForeground(Color.BLACK);
  213. feedingtotransferlabel.setBounds(0, 230, workWidth/3, 30);
  214. this.add(feedingtotransferlabel);
  215. transfertodevicelabel = new JLabel("中转车上料到设备");
  216. transfertodevicelabel.setHorizontalAlignment(SwingConstants.LEFT);
  217. transfertodevicelabel.setIcon(imageGreen);
  218. transfertodevicelabel.setForeground(Color.BLACK);
  219. transfertodevicelabel.setBounds(workWidth/3, 230, workWidth/3, 30);
  220. this.add(transfertodevicelabel);
  221. startOprnoTimer();
  222. heartData();
  223. // 信号监控按钮
  224. signalMonitor = new PlcSignalMonitor(s7PLC, plcDb, oprno + pos, MesClient.mesClientFrame);
  225. signalBtn = signalMonitor.createSignalButton();
  226. signalBtn.setBounds(workWidth*2/3 + 63, 230, 90, 26);
  227. this.add(signalBtn);
  228. resetScanA();
  229. }
  230. public void setMenuStatus(String msg,int error){
  231. if(error == 0){
  232. this.status_menu.setForeground(Color.GREEN);
  233. }else{
  234. this.status_menu.setForeground(Color.RED);
  235. }
  236. this.status_menu.setText(msg);
  237. }
  238. // 定时任务 -----------------------------------------------------------------------------------------------------
  239. public Timer cjTimerText2;
  240. public void heartData() {
  241. if(cjTimerText2!=null) {
  242. cjTimerText2.cancel();
  243. }
  244. cjTimerText2 = new Timer();
  245. cjTimerText2.schedule(new TimerTask() {
  246. public void run() {
  247. if(MesClient.isLogin == 1 && isLocal == 0){
  248. plcHeart = !plcHeart;
  249. writeBoolean(plcDb+".0.6",plcHeart);
  250. }
  251. }
  252. }, 1000,1000);
  253. }
  254. public Timer oprnoTimer;
  255. public void startOprnoTimer() {
  256. //心跳显示图标
  257. if(oprnoTimer!=null) {
  258. oprnoTimer.cancel();
  259. }
  260. oprnoTimer = new Timer();
  261. oprnoTimer.schedule(new TimerTask() {
  262. public void run() {
  263. try{
  264. if(MesClient.isLogin == 1){
  265. Boolean retFeeding = readFeeding();
  266. feedinglabel.setIcon(retFeeding?imageGreen:imageGray);
  267. transferToDevice = readFeedingTransferToDevice();
  268. transfertodevicelabel.setIcon(transferToDevice?imageGreen:imageGray);
  269. Boolean retFeedingAllow = readAllowFeeding();
  270. feedingmeslabel.setIcon(retFeedingAllow?imageGreen:imageGray);
  271. if(!retFeeding && retFeedingAllow){
  272. writeAllowFeeding(false);
  273. }
  274. Boolean retBlanking = readBlanking();
  275. blankinglabel.setIcon(retBlanking?imageGreen:imageGray);
  276. Boolean retAllowBlanking = readAllowBlanking();
  277. blankingmeslabel.setIcon(retAllowBlanking?imageGreen:imageGray);
  278. toDevice = readFeedingToDevice();
  279. feedingtodevicelabel.setIcon(toDevice?imageGreen:imageGray);
  280. toTransfer = readFeedingToTransfer();
  281. feedingtotransferlabel.setIcon(toTransfer?imageGreen:imageGray);
  282. transferToDevice = readFeedingTransferToDevice();
  283. transfertodevicelabel.setIcon(transferToDevice?imageGreen:imageGray);
  284. Boolean retRunning = readRunning();
  285. runlabel.setIcon(retRunning?imageGreen:imageGray);
  286. if(retBlanking && productSn.getText().isEmpty()){
  287. writeAllowBlanking(true);
  288. }
  289. if(tjFeedingFlag == 0){
  290. if(retFeeding){
  291. barCode();
  292. transferSn = readTransferNo();
  293. transferFloor = readTransferFloor();
  294. }
  295. }else if(tjFeedingFlag == 1){
  296. // if(toDevice){ // 去设备
  297. if(tjFlag == 0 && retRunning){
  298. tjFlag = 1;
  299. productSn.setText(productSnFeeding.getText());
  300. resetBtn.setEnabled(false);
  301. resetFeeding();
  302. }
  303. // }
  304. // if(toTransfer){ // 去中转台
  305. if(transferSn > 0 && transferFloor > 0 && !retFeeding){
  306. if(tjStatus == 0) {
  307. tjStatus = 1;
  308. log.info("60中转车存码"+transferSn+"号车"+transferFloor+"层"+"工件码"+productSnFeeding.getText().trim()+"工位号"+oprno+pos);
  309. JSONObject retObj = DataUtil.saveSn(oprno+pos,productSnFeeding.getText().trim(),transferSn,transferFloor,MesClient.user_menu.getText());
  310. if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
  311. writeAllowFeeding(true);
  312. resetFeeding();
  313. }else{
  314. if(retObj.get("result")==null){
  315. setMenuStatus("请求失败,请重试",-1);
  316. }else{
  317. if(retObj.get("result").toString().equalsIgnoreCase("false")){
  318. setMenuStatus(retObj.getString("message"),-1);
  319. }
  320. }
  321. }
  322. }
  323. }else{
  324. writeAllowFeeding(false);
  325. }
  326. // }
  327. }
  328. if(tjFlag == 0 && !retBlanking){
  329. writeAllowBlanking(false);
  330. }
  331. if(tjFlag == 1){
  332. // if(toDevice){ // 去设备
  333. if(retRunning){
  334. tjFlag = 2;
  335. setMenuStatus("工件加工中", 0);
  336. // 运行中清除下料反馈
  337. writeAllowBlanking(false);
  338. }
  339. // }
  340. }else if(tjFlag == 2){
  341. if(retBlanking){
  342. tjFlag = 3;
  343. setMenuStatus("工件加工结束,结果上传中", 0);
  344. if(tjStatus == 0){
  345. tjStatus = 1;
  346. // 异步执行上传任务,防止阻塞
  347. // ExecutorService executor = Executors.newCachedThreadPool();
  348. // executor.submit(() -> {
  349. // 你的异步任务代码
  350. log.info("["+oprno+pos+"]质量上传任务开始");
  351. try {
  352. JSONObject retObj = DataUtil.sendQuality(productSn.getText(),oprno+pos,"OK",MesClient.user_menu.getText());
  353. if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
  354. resetBlanking();
  355. }else{
  356. if(retObj.get("result")==null){
  357. setMenuStatus("请求失败,请重试",-1);
  358. }else{
  359. if(retObj.get("result").toString().equalsIgnoreCase("false")){
  360. setMenuStatus(retObj.getString("message"),-1);
  361. }
  362. }
  363. }
  364. } catch (Exception e) {
  365. Thread.currentThread().interrupt();
  366. }
  367. log.info("["+oprno+pos+"]质量上传任务结束");
  368. // });
  369. // 关闭ExecutorService,不再接受新任务,等待已提交的任务完成
  370. // executor.shutdown();
  371. }
  372. }
  373. }
  374. }
  375. }catch (Exception e) {
  376. log.error(e.getMessage());
  377. }
  378. }
  379. }, 100,2000);
  380. }
  381. public void barCode(){
  382. if(!productSnFeeding.getText().isEmpty()){
  383. return;
  384. }
  385. String sn = readQrcode();
  386. if(sn.equals("")){
  387. if(productSnFeeding.getText().isEmpty()){
  388. productSnFeeding.setText("空结果");
  389. this.setMenuStatus("扫码结果为空", -1);
  390. }
  391. }else{
  392. productSnFeeding.setText(sn);
  393. lastSn = sn;
  394. // 查询工件质量
  395. JSONObject retObj = DataUtil.checkQuality(sn,oprno+pos,MesClient.user_menu.getText());
  396. log.info("工件质量结果"+retObj.get("result"));
  397. if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
  398. tjFeedingFlag = 1;//可加工
  399. setMenuStatus("工件可以加工", 0);
  400. writeAllowFeeding(true);
  401. // writeScanFinish(true);
  402. // resetFeedingBtn.setEnabled(false);
  403. }else{
  404. writeAllowFeeding(false);
  405. resetFeedingBtn.setEnabled(true);
  406. writeScanFinish(false);
  407. if(retObj.get("result")==null){
  408. setMenuStatus("请求失败,请重试",-1);
  409. }else{
  410. if(retObj.get("result").toString().equalsIgnoreCase("false")){
  411. setMenuStatus(retObj.getString("message"),-1);
  412. }
  413. }
  414. }
  415. }
  416. }
  417. public void resetBlanking() {
  418. tjFlag = 0;
  419. tjStatus = 0;
  420. productSn.setText("");
  421. setMenuStatus("工件结果已提交,等待下一件",0);
  422. resetBtn.setEnabled(true);
  423. // writeAllowFeeding(false);
  424. // writeAllowBlanking(false);
  425. }
  426. public void resetFeeding() {
  427. productSnFeeding.setText("");
  428. tjFeedingFlag = 0;
  429. tjStatus = 0;
  430. setMenuStatus("等待请求扫码",0);
  431. resetFeedingBtn.setEnabled(true);
  432. // writeAllowFeeding(false);
  433. writeScanFinish(false);
  434. }
  435. public void resetScanA() {
  436. tjFeedingFlag = 0;
  437. tjFlag = 0;
  438. tjStatus = 0;
  439. productSn.setText("");
  440. productSnFeeding.setText("");
  441. setMenuStatus("等待请求扫码",0);
  442. resetBtn.setEnabled(true);
  443. resetFeedingBtn.setEnabled(true);
  444. if(isLocal == 0){
  445. writeAllowFeeding(false);
  446. writeAllowBlanking(false);
  447. }
  448. }
  449. // 与设备交互-----------------------------------------------------------------------------------------
  450. // 请求扫码
  451. public boolean readFeeding(){
  452. if(isLocal == 1){
  453. return false;
  454. }else{
  455. return readBoolean(plcDb+".0.0");
  456. }
  457. }
  458. // 读取上料到设备
  459. public boolean readFeedingToDevice(){
  460. if(isLocal == 1){
  461. return true;
  462. }else{
  463. return readBoolean(plcDb+".0.7");
  464. }
  465. }
  466. // 读取上料到中转车
  467. public boolean readFeedingToTransfer(){
  468. if(isLocal == 1){
  469. return true;
  470. }else{
  471. return readBoolean(plcDb+".1.0");
  472. }
  473. }
  474. // 读取中转车上料到设备
  475. public boolean readFeedingTransferToDevice(){
  476. if(isLocal == 1){
  477. return true;
  478. }else{
  479. return readBoolean(plcDb+".1.1");
  480. }
  481. }
  482. // 读取下料信号
  483. public boolean readBlanking(){
  484. if(isLocal == 1){
  485. return false;
  486. }else{
  487. return readBoolean(plcDb+".0.1");
  488. }
  489. }
  490. // 读取设备运行信号
  491. public boolean readRunning(){
  492. if(isLocal == 1){
  493. return true;
  494. }else{
  495. return readBoolean(plcDb+".0.2");
  496. }
  497. }
  498. // 读取设备通讯状态
  499. public boolean readDeviceStatus(){
  500. if(isLocal == 1){
  501. return true;
  502. }else{
  503. return readBoolean(plcDb+".0.3");
  504. }
  505. }
  506. // 读取MES允许上料信号
  507. public boolean readAllowFeeding(){
  508. if(isLocal == 1){
  509. return false;
  510. }else{
  511. return readBoolean(plcDb+".0.4");
  512. }
  513. }
  514. // 读取s扫码完成信号
  515. public boolean readScanFinish(){
  516. if(isLocal == 1){
  517. return false;
  518. }else{
  519. return readBoolean(plcDb+".6.4");
  520. }
  521. }
  522. public boolean writeScanFinish(Boolean b){
  523. if(isLocal == 1){
  524. return true;
  525. }else{
  526. return writeBoolean(plcDb+".6.4",b);
  527. }
  528. }
  529. // 写入MES允许上料信号
  530. public boolean writeAllowFeeding(Boolean b){
  531. if(isLocal == 1){
  532. return true;
  533. }else{
  534. return writeBoolean(plcDb+".0.4",b);
  535. }
  536. }
  537. // 读取MES允许下料信号
  538. public boolean readAllowBlanking(){
  539. if(isLocal == 1){
  540. return true;
  541. }else{
  542. return readBoolean(plcDb+".0.5");
  543. }
  544. }
  545. // 写入MES允许下料信号
  546. public boolean writeAllowBlanking(Boolean b){
  547. if(isLocal == 1){
  548. return true;
  549. }else{
  550. return writeBoolean(plcDb+".0.5",b);
  551. }
  552. }
  553. // 读取中转车号
  554. public int readTransferNo(){
  555. if(isLocal == 1){
  556. return 1;
  557. }else{
  558. return s7PLC.readInt16(plcDb+".2.0");
  559. }
  560. }
  561. // 读取中转车层数
  562. public int readTransferFloor(){
  563. if(isLocal == 1){
  564. return 1;
  565. }else{
  566. return s7PLC.readInt16(plcDb+".4.0");
  567. }
  568. }
  569. // 控制扫码枪读取二维码
  570. public String readQrcode(){
  571. // String sn = "5001040043561010006";
  572. String sn = "";
  573. if(isLocal == 1){
  574. return "";
  575. }else{
  576. try{
  577. if(transferToDevice){ // 中转车上料到设备
  578. int transferSn = readTransferNo();
  579. int transferFloor = readTransferFloor();
  580. log.info("60中转车开始执行取码"+transferSn+"号车"+transferFloor+"层"+"工位号"+oprno+pos);
  581. JSONObject retObj = DataUtil.getSn(oprno+pos,transferSn,transferFloor,MesClient.user_menu.getText());
  582. if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
  583. sn = retObj.getString("data");
  584. this.setMenuStatus("允许工件加工",0);
  585. log.info("60中转车取码成功"+transferSn+"号车"+transferFloor+"层"+"工件码:"+sn+"工位号"+oprno+pos);
  586. // writeAllowFeeding(true);
  587. }else{
  588. writeAllowFeeding(false);
  589. if(retObj.get("result")==null){
  590. this.setMenuStatus("请求失败,请重试",-1);
  591. }else{
  592. if(retObj.get("result").toString().equalsIgnoreCase("false")){
  593. this.setMenuStatus(retObj.getString("message"),-1);
  594. }
  595. }
  596. }
  597. }else{
  598. if(isScan == 1){
  599. sn = MesClient.scanQrcode1();
  600. }else{
  601. sn = MesClient.scanQrcode3();
  602. }
  603. }
  604. }catch (Exception e) {
  605. e.printStackTrace();
  606. }
  607. }
  608. return sn;
  609. }
  610. public boolean readBoolean(String db){
  611. boolean permit;
  612. try {
  613. permit = s7PLC.readBoolean(db);
  614. // log.info("<"+this.oprno+this.pos+">读取"+db+"-->成功,结果:{}", permit ? "true" : "false");
  615. } catch (Exception e) {
  616. log.error("<"+this.oprno+this.pos+">读取"+db+"-->失败", e);
  617. return false;
  618. }
  619. return permit;
  620. }
  621. public boolean writeBoolean(String db, boolean permit){
  622. try {
  623. s7PLC.writeBoolean(db,permit);
  624. // log.info("<"+this.oprno+this.pos+">写入"+db+"-->成功,写入内容:{}", permit ? "true" : "false");
  625. } catch (Exception e) {
  626. log.error("<"+this.oprno+this.pos+">写入"+db+"-->失败,写入内容:{}", permit ? "true" : "false");
  627. log.error(e.getMessage(), e);
  628. return false;
  629. }
  630. return true;
  631. }
  632. }