WorkJPanelOP20Old.java 27 KB

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