|
|
@@ -1,861 +0,0 @@
|
|
|
-package com.mes.component;
|
|
|
-
|
|
|
-import com.alibaba.fastjson2.JSON;
|
|
|
-import com.alibaba.fastjson2.JSONObject;
|
|
|
-import com.github.xingshuangs.iot.protocol.s7.enums.EPlcType;
|
|
|
-import com.github.xingshuangs.iot.protocol.s7.service.S7PLC;
|
|
|
-import com.mes.ui.CacheData;
|
|
|
-import com.mes.ui.DataUtil;
|
|
|
-import com.mes.ui.MesClient;
|
|
|
-import com.mes.util.JdbcUtils;
|
|
|
-import com.mes.util.TCPClient;
|
|
|
-import org.slf4j.Logger;
|
|
|
-import org.slf4j.LoggerFactory;
|
|
|
-
|
|
|
-import javax.swing.*;
|
|
|
-import java.awt.*;
|
|
|
-import java.awt.event.*;
|
|
|
-import java.util.Timer;
|
|
|
-import java.util.TimerTask;
|
|
|
-import java.util.concurrent.ExecutorService;
|
|
|
-import java.util.concurrent.Executors;
|
|
|
-
|
|
|
-public class WorkJPanelOP150 extends JPanel {
|
|
|
-
|
|
|
- public static final Logger log = LoggerFactory.getLogger(WorkJPanelOP150.class);
|
|
|
-
|
|
|
- public String oprno = "OP150";
|
|
|
-
|
|
|
- public String pos = "A";
|
|
|
-
|
|
|
- public String lastSn = ""; // 最近的码
|
|
|
-
|
|
|
- public String lineSn = "CZ060";
|
|
|
-
|
|
|
- public JLabel feedinglabel;
|
|
|
-
|
|
|
- public JLabel feedingmeslabel;
|
|
|
-
|
|
|
- public JLabel runlabel; //运行反馈,
|
|
|
-
|
|
|
- public JLabel blankinglabel; // 下料反馈
|
|
|
-
|
|
|
- public JLabel blankingmeslabel; // 下料MES反馈
|
|
|
-
|
|
|
- public JLabel feedingtodevicelabel; // 上料到设备
|
|
|
-
|
|
|
- public JLabel feedingtotransferlabel; // 上料到中转车
|
|
|
-
|
|
|
- public JLabel transfertodevicelabel; // 上料到中转车
|
|
|
-
|
|
|
- public JButton scanBtn;
|
|
|
-
|
|
|
- public JTextField productSn;
|
|
|
-
|
|
|
- public JTextField productSnFeeding;
|
|
|
-
|
|
|
- public JButton status_menu;
|
|
|
-
|
|
|
- public JButton resetBtn;
|
|
|
-
|
|
|
- public JButton resetFeedingBtn;
|
|
|
-
|
|
|
- public ImageIcon imageGreen;
|
|
|
-
|
|
|
- public ImageIcon imageGray;
|
|
|
-
|
|
|
- public String plcIp12 = "192.168.90.92"; // plc92
|
|
|
- public String plcIp13 = "192.168.90.93"; // plc93
|
|
|
-
|
|
|
- public S7PLC s7PLC = null;
|
|
|
-
|
|
|
- public Integer workWidth = 470;
|
|
|
- public Integer workHeight = 300;
|
|
|
-
|
|
|
- public String plcDb = "";
|
|
|
-
|
|
|
- public Integer tjFeedingFlag = 0; // 上料状态标识
|
|
|
- public Integer tjFlag = 0; // 1=可加工 2=设备运行中 3=加工结束
|
|
|
- public Integer tjStatus = 0; // 提交标识
|
|
|
- public Boolean toDevice = false;
|
|
|
- public Boolean toTransfer = false;
|
|
|
- public Boolean transferToDevice = false;
|
|
|
- public Integer tjScan = 0;
|
|
|
-
|
|
|
- public Boolean plcHeart = false;
|
|
|
-
|
|
|
- public Integer isLocal = 0; // 0=正式 1=本地
|
|
|
-
|
|
|
- public String cncDeviceName = "";
|
|
|
-
|
|
|
- public JLabel oprnoLabel2;
|
|
|
-
|
|
|
- public JButton signalBtn; // 信号监控按钮
|
|
|
-
|
|
|
- public PlcSignalMonitor signalMonitor; // 信号监控组件
|
|
|
-
|
|
|
- public CacheData cacheData = null;
|
|
|
- public String cacheName = "";
|
|
|
-
|
|
|
- public WorkJPanelOP150(String position){
|
|
|
- this.setLayout(null);
|
|
|
- this.setBackground(Color.WHITE);
|
|
|
- this.pos = position;
|
|
|
-
|
|
|
- cacheName = "cache_"+oprno+pos;
|
|
|
- cacheData = JdbcUtils.getCache(cacheName);
|
|
|
- if(cacheData == null){
|
|
|
- cacheData = new CacheData();
|
|
|
- cacheData.setLastSn("");
|
|
|
- cacheData.setSn("");
|
|
|
- cacheData.setFeedingSn("");
|
|
|
- cacheData.setTjStatus(0);
|
|
|
- cacheData.setTjFlag(0);
|
|
|
- cacheData.setError(-1);
|
|
|
- cacheData.setMsg("");
|
|
|
- JdbcUtils.setCache(cacheName, JSON.toJSONString(cacheData));
|
|
|
- }
|
|
|
-
|
|
|
- if(position.equals("A") || position.equals("B") || position.equals("C") || position.equals("D") || position.equals("E")){
|
|
|
- s7PLC = new S7PLC(EPlcType.S1500, plcIp12);
|
|
|
- }else{
|
|
|
- s7PLC = new S7PLC(EPlcType.S1500, plcIp13);
|
|
|
- }
|
|
|
-
|
|
|
- s7PLC.setReceiveTimeout(1000);
|
|
|
- s7PLC.setConnectTimeout(1000);
|
|
|
-
|
|
|
- switch (position){
|
|
|
- case "A":
|
|
|
- plcDb = "DB7000";
|
|
|
- cncDeviceName = "东侧一号机";
|
|
|
- break;
|
|
|
- case "B":
|
|
|
- plcDb = "DB7001";
|
|
|
- cncDeviceName = "东侧二号机";
|
|
|
- break;
|
|
|
- case "C":
|
|
|
- plcDb = "DB7002";
|
|
|
- cncDeviceName = "东侧三号机";
|
|
|
- break;
|
|
|
- case "D":
|
|
|
- plcDb = "DB7003";
|
|
|
- cncDeviceName = "东侧四号机";
|
|
|
- break;
|
|
|
- case "E":
|
|
|
- plcDb = "DB7004";
|
|
|
- cncDeviceName = "东侧五号机";
|
|
|
- break;
|
|
|
- case "F":
|
|
|
- plcDb = "DB7000";
|
|
|
- cncDeviceName = "东侧六号机";
|
|
|
- break;
|
|
|
- case "G":
|
|
|
- plcDb = "DB7001";
|
|
|
- cncDeviceName = "东侧七号机";
|
|
|
- break;
|
|
|
- case "H":
|
|
|
- plcDb = "DB7002";
|
|
|
- cncDeviceName = "东侧八号机";
|
|
|
- break;
|
|
|
- case "I":
|
|
|
- plcDb = "DB7003";
|
|
|
- cncDeviceName = "东侧九号机";
|
|
|
- break;
|
|
|
- case "J":
|
|
|
- plcDb = "DB7004";
|
|
|
- cncDeviceName = "东侧十号机";
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
- JLabel oprnoLabel = new JLabel(oprno+pos);
|
|
|
- oprnoLabel.setHorizontalAlignment(SwingConstants.CENTER);
|
|
|
- oprnoLabel.setForeground(Color.BLACK);
|
|
|
- oprnoLabel.setFont(new Font("微软雅黑", Font.PLAIN, 20));
|
|
|
- oprnoLabel.setBounds(0, 0, workWidth/5, 40);
|
|
|
- this.add(oprnoLabel);
|
|
|
-
|
|
|
- oprnoLabel2 = new JLabel(cncDeviceName);
|
|
|
- oprnoLabel2.setHorizontalAlignment(SwingConstants.CENTER);
|
|
|
- oprnoLabel2.setForeground(Color.BLACK);
|
|
|
- oprnoLabel2.setFont(new Font("微软雅黑", Font.PLAIN, 14));
|
|
|
- oprnoLabel2.setBounds(0, 17, workWidth / 5, 40);
|
|
|
- this.add(oprnoLabel2);
|
|
|
-
|
|
|
- status_menu = new JButton("等待请求扫码");
|
|
|
- status_menu.setBounds(workWidth/5, 0, workWidth*4/5, 40);
|
|
|
- status_menu.setForeground(Color.GREEN);
|
|
|
- status_menu.setForeground(Color.GREEN);
|
|
|
- status_menu.setFont(new Font("微软雅黑", Font.PLAIN, 16));
|
|
|
- status_menu.setBackground(Color.BLACK);
|
|
|
- this.add(status_menu);
|
|
|
-
|
|
|
- JLabel oprnoLabelFeeding = new JLabel("上料");
|
|
|
- oprnoLabelFeeding.setHorizontalAlignment(SwingConstants.CENTER);
|
|
|
- oprnoLabelFeeding.setForeground(Color.BLACK);
|
|
|
- oprnoLabelFeeding.setFont(new Font("微软雅黑", Font.PLAIN, 20));
|
|
|
- oprnoLabelFeeding.setBounds(0, 50, workWidth/5, 40);
|
|
|
- this.add(oprnoLabelFeeding);
|
|
|
-
|
|
|
- productSnFeeding = new JTextField("");
|
|
|
- productSnFeeding.setHorizontalAlignment(SwingConstants.CENTER);
|
|
|
- productSnFeeding.setForeground(Color.BLACK);
|
|
|
- productSnFeeding.setFont(new Font("微软雅黑", Font.PLAIN, 16));
|
|
|
- productSnFeeding.setEditable(false);
|
|
|
- productSnFeeding.setBounds(workWidth/5, 50, workWidth*3/5, 40);
|
|
|
- productSnFeeding.addMouseListener(new MouseAdapter() {
|
|
|
- public void mouseClicked(MouseEvent e) {
|
|
|
- String sn = productSnFeeding.getText().trim();
|
|
|
- if(!sn.isEmpty()){
|
|
|
- MesClient.createQRCode(productSnFeeding.getText(),oprno+pos);
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- this.add(productSnFeeding);
|
|
|
-
|
|
|
- JLabel oprnoLabelWork = new JLabel("加工");
|
|
|
- oprnoLabelWork.setHorizontalAlignment(SwingConstants.CENTER);
|
|
|
- oprnoLabelWork.setForeground(Color.BLACK);
|
|
|
- oprnoLabelWork.setFont(new Font("微软雅黑", Font.PLAIN, 20));
|
|
|
- oprnoLabelWork.setBounds(0, 100, workWidth/5, 40);
|
|
|
- this.add(oprnoLabelWork);
|
|
|
-
|
|
|
- productSn = new JTextField("");
|
|
|
- productSn.setHorizontalAlignment(SwingConstants.CENTER);
|
|
|
- productSn.setForeground(Color.BLACK);
|
|
|
- productSn.setFont(new Font("微软雅黑", Font.PLAIN, 16));
|
|
|
- productSn.setEditable(false);
|
|
|
- productSn.setBounds(workWidth/5, 100, workWidth*3/5, 40);
|
|
|
- productSn.addMouseListener(new MouseAdapter() {
|
|
|
- public void mouseClicked(MouseEvent e) {
|
|
|
- String sn = productSn.getText().trim();
|
|
|
- if(!sn.isEmpty()){
|
|
|
- MesClient.createQRCode(productSn.getText(),oprno+pos);
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- this.add(productSn);
|
|
|
-
|
|
|
-
|
|
|
-// scanBtn = new JButton("扫码");
|
|
|
-// scanBtn.addActionListener(new ActionListener() {
|
|
|
-// public void actionPerformed(ActionEvent e) {
|
|
|
-// log.info("test2:"+productSn.getText());
|
|
|
-// barCode();
|
|
|
-// }
|
|
|
-// });
|
|
|
-// scanBtn.setIcon(new ImageIcon(MesClient.class.getResource("/bg/scan_barcode.png")));
|
|
|
-// scanBtn.setFont(new Font("微软雅黑", Font.PLAIN, 32));
|
|
|
-// scanBtn.setBounds(0, 160, workWidth/2 - 5, 50);
|
|
|
-// this.add(scanBtn);
|
|
|
-
|
|
|
- resetFeedingBtn = new JButton("刷新");
|
|
|
- resetFeedingBtn.addActionListener(new ActionListener() {
|
|
|
- public void actionPerformed(ActionEvent e) {
|
|
|
- resetFeeding();
|
|
|
-// scanQrcode();
|
|
|
-// MesClient.scanQrcode1();
|
|
|
- }
|
|
|
- });
|
|
|
-// resetFeedingBtn.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png")));
|
|
|
- resetFeedingBtn.setFont(new Font("微软雅黑", Font.PLAIN, 22));
|
|
|
- resetFeedingBtn.setBounds(workWidth*4/5 + 10, 50, workWidth/5 - 10, 40);
|
|
|
- this.add(resetFeedingBtn);
|
|
|
-
|
|
|
- resetBtn = new JButton("刷新");
|
|
|
- resetBtn.addActionListener(new ActionListener() {
|
|
|
- public void actionPerformed(ActionEvent e) {
|
|
|
-// log.info("test2:"+productSn.getText());
|
|
|
- resetBlanking();
|
|
|
- }
|
|
|
- });
|
|
|
-// resetBtn.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png")));
|
|
|
- resetBtn.setFont(new Font("微软雅黑", Font.PLAIN, 22));
|
|
|
- resetBtn.setBounds(workWidth*4/5 + 10, 100, workWidth/5 - 10, 40);
|
|
|
- this.add(resetBtn);
|
|
|
-
|
|
|
- imageGreen = new ImageIcon(MesClient.class.getResource("/bg/green_dot.png"));
|
|
|
- imageGreen.setImage(imageGreen.getImage().getScaledInstance(20, 20, Image.SCALE_SMOOTH));
|
|
|
-
|
|
|
- imageGray = new ImageIcon(MesClient.class.getResource("/bg/grey_dot.png"));
|
|
|
- imageGray.setImage(imageGray.getImage().getScaledInstance(20, 20, Image.SCALE_SMOOTH));
|
|
|
-
|
|
|
- feedinglabel = new JLabel("请求扫码");
|
|
|
- feedinglabel.setHorizontalAlignment(SwingConstants.LEFT);
|
|
|
- feedinglabel.setIcon(imageGreen);
|
|
|
- feedinglabel.setForeground(Color.BLACK);
|
|
|
- feedinglabel.setBounds(0, 150, workWidth/3, 30);
|
|
|
- this.add(feedinglabel);
|
|
|
-
|
|
|
- feedingmeslabel = new JLabel("MES扫码反馈");
|
|
|
- feedingmeslabel.setHorizontalAlignment(SwingConstants.LEFT);
|
|
|
- feedingmeslabel.setIcon(imageGreen);
|
|
|
- feedingmeslabel.setForeground(Color.BLACK);
|
|
|
- feedingmeslabel.setBounds(workWidth/3, 150, workWidth/3, 30);
|
|
|
- feedingmeslabel.addMouseListener(new MouseAdapter() {
|
|
|
- public void mouseClicked(MouseEvent e) {
|
|
|
- boolean ret = readAllowFeeding();
|
|
|
- int choice = JOptionPane.showConfirmDialog(null, "确定修改MES扫码反馈结果为"+(ret?"false":"true")+"吗?", "操作确认", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
|
|
|
- if (choice == JOptionPane.YES_OPTION) {
|
|
|
- writeAllowFeeding(!ret);
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- this.add(feedingmeslabel);
|
|
|
-
|
|
|
- runlabel = new JLabel("设备运行中");
|
|
|
- runlabel.setHorizontalAlignment(SwingConstants.LEFT);
|
|
|
- runlabel.setIcon(imageGreen);
|
|
|
- runlabel.setForeground(Color.BLACK);
|
|
|
- runlabel.setBounds(workWidth*2/3, 150, workWidth/3, 30);
|
|
|
- this.add(runlabel);
|
|
|
-
|
|
|
- blankinglabel = new JLabel("下料请求");
|
|
|
- blankinglabel.setHorizontalAlignment(SwingConstants.LEFT);
|
|
|
- blankinglabel.setIcon(imageGreen);
|
|
|
- blankinglabel.setForeground(Color.BLACK);
|
|
|
- blankinglabel.setBounds(0, 190, workWidth/3, 30);
|
|
|
- this.add(blankinglabel);
|
|
|
-
|
|
|
- blankingmeslabel = new JLabel("MES下料反馈");
|
|
|
- blankingmeslabel.setHorizontalAlignment(SwingConstants.LEFT);
|
|
|
- blankingmeslabel.setIcon(imageGreen);
|
|
|
- blankingmeslabel.setForeground(Color.BLACK);
|
|
|
- blankingmeslabel.setBounds(workWidth/3, 190, workWidth/3, 30);
|
|
|
- this.add(blankingmeslabel);
|
|
|
- blankingmeslabel.addMouseListener(new MouseAdapter() {
|
|
|
- public void mouseClicked(MouseEvent e) {
|
|
|
- boolean ret = readAllowBlanking();
|
|
|
- int choice = JOptionPane.showConfirmDialog(null, "确定修改MES下料反馈结果为"+(ret?"false":"true")+"吗?", "操作确认", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
|
|
|
- if (choice == JOptionPane.YES_OPTION) {
|
|
|
- writeAllowBlanking(!ret);
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- feedingtodevicelabel = new JLabel("上料到设备");
|
|
|
- feedingtodevicelabel.setHorizontalAlignment(SwingConstants.LEFT);
|
|
|
- feedingtodevicelabel.setIcon(imageGreen);
|
|
|
- feedingtodevicelabel.setForeground(Color.BLACK);
|
|
|
- feedingtodevicelabel.setBounds(workWidth*2/3, 190, workWidth/3, 30);
|
|
|
- this.add(feedingtodevicelabel);
|
|
|
-
|
|
|
- feedingtotransferlabel = new JLabel("上料到中转车");
|
|
|
- feedingtotransferlabel.setHorizontalAlignment(SwingConstants.LEFT);
|
|
|
- feedingtotransferlabel.setIcon(imageGreen);
|
|
|
- feedingtotransferlabel.setForeground(Color.BLACK);
|
|
|
- feedingtotransferlabel.setBounds(0, 230, workWidth/3, 30);
|
|
|
-// this.add(feedingtotransferlabel);
|
|
|
-
|
|
|
- transfertodevicelabel = new JLabel("中转车上料到设备");
|
|
|
- transfertodevicelabel.setHorizontalAlignment(SwingConstants.LEFT);
|
|
|
- transfertodevicelabel.setIcon(imageGreen);
|
|
|
- transfertodevicelabel.setForeground(Color.BLACK);
|
|
|
- transfertodevicelabel.setBounds(workWidth/3, 230, workWidth/3, 30);
|
|
|
-// this.add(transfertodevicelabel);
|
|
|
-
|
|
|
-
|
|
|
- formatElementUI();
|
|
|
-
|
|
|
- this.startOprnoTimer();
|
|
|
- heartData();
|
|
|
-
|
|
|
-// resetScanA();
|
|
|
-
|
|
|
- // 信号监控按钮
|
|
|
- signalMonitor = new PlcSignalMonitor(s7PLC, plcDb, oprno + pos, MesClient.mesClientFrame);
|
|
|
- signalBtn = signalMonitor.createSignalButton();
|
|
|
- signalBtn.setBounds(workWidth*2/3 + 63, 230, 90, 26);
|
|
|
- this.add(signalBtn);
|
|
|
- }
|
|
|
-
|
|
|
- public void formatElementUI(){
|
|
|
- cacheData = JdbcUtils.getCache(cacheName);
|
|
|
- if(cacheData == null){
|
|
|
- return;
|
|
|
- }
|
|
|
- String msg = cacheData.getMsg();
|
|
|
- int error = cacheData.getError();
|
|
|
- String sn = cacheData.getSn();
|
|
|
- productSn.setText(sn);
|
|
|
-
|
|
|
- String feedingSn = cacheData.getFeedingSn();
|
|
|
- productSnFeeding.setText(feedingSn);
|
|
|
-
|
|
|
- tjFlag = cacheData.getTjFlag();
|
|
|
- lastSn = cacheData.getLastSn();
|
|
|
-
|
|
|
- setMenuStatus(msg,error);
|
|
|
-
|
|
|
- this.repaint();
|
|
|
- }
|
|
|
-
|
|
|
- public void setMenuStatus(String msg,int error){
|
|
|
- if(error == 0){
|
|
|
- this.status_menu.setForeground(Color.GREEN);
|
|
|
- }else{
|
|
|
- this.status_menu.setForeground(Color.RED);
|
|
|
- }
|
|
|
- this.status_menu.setText(msg);
|
|
|
-
|
|
|
- cacheData.setMsg(msg);
|
|
|
- cacheData.setError(error);
|
|
|
- cacheData.setTjFlag(tjFlag);
|
|
|
- cacheData.setTjStatus(tjStatus);
|
|
|
- cacheData.setLastSn(lastSn);
|
|
|
- cacheData.setSn(productSn.getText());
|
|
|
- cacheData.setFeedingSn(productSnFeeding.getText());
|
|
|
- JdbcUtils.setCache(cacheName, JSON.toJSONString(cacheData));
|
|
|
- }
|
|
|
-
|
|
|
- // 定时任务 -----------------------------------------------------------------------------------------------------
|
|
|
-
|
|
|
- public Timer cjTimerText2;
|
|
|
- public void heartData() {
|
|
|
- if(cjTimerText2!=null) {
|
|
|
- cjTimerText2.cancel();
|
|
|
- }
|
|
|
- cjTimerText2 = new Timer();
|
|
|
- cjTimerText2.schedule(new TimerTask() {
|
|
|
- public void run() {
|
|
|
- if(MesClient.isLogin == 1 && isLocal == 0){
|
|
|
- plcHeart = !plcHeart;
|
|
|
- writeBoolean(plcDb+".0.6",plcHeart);
|
|
|
- }
|
|
|
- }
|
|
|
- }, 1000,1000);
|
|
|
- }
|
|
|
-
|
|
|
- public Timer oprnoTimer;
|
|
|
- public void startOprnoTimer() {
|
|
|
-
|
|
|
- //心跳显示图标
|
|
|
- if(oprnoTimer!=null) {
|
|
|
- oprnoTimer.cancel();
|
|
|
- }
|
|
|
- oprnoTimer = new Timer();
|
|
|
- oprnoTimer.schedule(new TimerTask() {
|
|
|
- public void run() {
|
|
|
- try{
|
|
|
-
|
|
|
- if(MesClient.isLogin == 1){
|
|
|
- Boolean retFeeding = readFeeding();
|
|
|
-// Boolean retFeeding = true;
|
|
|
- feedinglabel.setIcon(retFeeding?imageGreen:imageGray);
|
|
|
-
|
|
|
- transferToDevice = readFeedingTransferToDevice();
|
|
|
- transfertodevicelabel.setIcon(transferToDevice?imageGreen:imageGray);
|
|
|
-
|
|
|
- Boolean retFeedingAllow = readAllowFeeding();
|
|
|
- feedingmeslabel.setIcon(retFeedingAllow?imageGreen:imageGray);
|
|
|
-
|
|
|
- if(!retFeeding && retFeedingAllow){
|
|
|
- writeAllowFeeding(false);
|
|
|
- }
|
|
|
-
|
|
|
- Boolean retBlanking = readBlanking();
|
|
|
- blankinglabel.setIcon(retBlanking?imageGreen:imageGray);
|
|
|
-
|
|
|
- Boolean retAllowBlanking = readAllowBlanking();
|
|
|
- blankingmeslabel.setIcon(retAllowBlanking?imageGreen:imageGray);
|
|
|
-
|
|
|
- toDevice = readFeedingToDevice();
|
|
|
- feedingtodevicelabel.setIcon(toDevice?imageGreen:imageGray);
|
|
|
-
|
|
|
- toTransfer = readFeedingToTransfer();
|
|
|
- feedingtotransferlabel.setIcon(toTransfer?imageGreen:imageGray);
|
|
|
-
|
|
|
- Boolean retRunning = readRunning();
|
|
|
- runlabel.setIcon(retRunning?imageGreen:imageGray);
|
|
|
-
|
|
|
- if(retBlanking && productSn.getText().isEmpty()){
|
|
|
- writeAllowBlanking(true);
|
|
|
- }
|
|
|
-
|
|
|
- if(tjFeedingFlag == 0){
|
|
|
- if(retFeeding){
|
|
|
- barCode();
|
|
|
- }
|
|
|
-
|
|
|
- }else if(tjFeedingFlag == 1){
|
|
|
- // 中转车已隐藏:不再走 toTransfer 存码,统一按去设备处理
|
|
|
-// if(toDevice){ // 去设备
|
|
|
- if(tjFlag == 0 && retRunning){
|
|
|
- tjFlag = 1;
|
|
|
- productSn.setText(productSnFeeding.getText());
|
|
|
-// resetBtn.setEnabled(false);
|
|
|
- resetFeeding();
|
|
|
- }
|
|
|
-// }
|
|
|
-// if(toTransfer){ // 去中转台
|
|
|
-// int transferSn = readTransferNo();
|
|
|
-// int transferFloor = readTransferFloor();
|
|
|
-// if(transferSn > 0 && transferFloor > 0){
|
|
|
-// if(tjStatus == 0) {
|
|
|
-// tjStatus = 1;
|
|
|
-// JSONObject retObj = DataUtil.saveSn(oprno+pos,productSnFeeding.getText().trim(),transferSn,transferFloor,MesClient.user_menu.getText());
|
|
|
-// if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
|
|
|
-// resetFeeding();
|
|
|
-// }else{
|
|
|
-// if(retObj.get("result")==null){
|
|
|
-// setMenuStatus("请求失败,请重试",-1);
|
|
|
-// }else{
|
|
|
-// if(retObj.get("result").toString().equalsIgnoreCase("false")){
|
|
|
-// setMenuStatus(retObj.getString("message"),-1);
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
- }
|
|
|
-
|
|
|
- if(tjFlag == 0 && !retBlanking){
|
|
|
- writeAllowBlanking(false);
|
|
|
- }
|
|
|
-
|
|
|
- if(tjFlag == 1){
|
|
|
- // 中转车已隐藏:不再走 toTransfer 存码,统一按去设备处理
|
|
|
-// if(toDevice){ // 去设备
|
|
|
- if(retRunning){
|
|
|
- tjFlag = 2;
|
|
|
- setMenuStatus("工件加工中", 0);
|
|
|
- // 运行中清除下料反馈
|
|
|
- writeAllowBlanking(false);
|
|
|
- }
|
|
|
-// }
|
|
|
-// if(toTransfer){ // 去中转台
|
|
|
-// int transferSn = readTransferNo();
|
|
|
-// int transferFloor = readTransferFloor();
|
|
|
-// if(transferSn > 0 && transferFloor > 0){
|
|
|
-// if(tjStatus == 0) {
|
|
|
-// tjStatus = 1;
|
|
|
-// JSONObject retObj = DataUtil.saveSn(oprno+pos,productSn.getText().trim(),transferSn,transferFloor,MesClient.user_menu.getText());
|
|
|
-// if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
|
|
|
-// resetFeeding();
|
|
|
-// }else{
|
|
|
-// if(retObj.get("result")==null){
|
|
|
-// setMenuStatus("请求失败,请重试",-1);
|
|
|
-// }else{
|
|
|
-// if(retObj.get("result").toString().equalsIgnoreCase("false")){
|
|
|
-// setMenuStatus(retObj.getString("message"),-1);
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
- }else if(tjFlag == 2){
|
|
|
- if(retBlanking){
|
|
|
- tjFlag = 3;
|
|
|
- setMenuStatus("工件加工结束,结果上传中", 0);
|
|
|
-
|
|
|
- if(tjStatus == 0){
|
|
|
- tjStatus = 1;
|
|
|
-
|
|
|
- // 异步执行上传任务,防止阻塞
|
|
|
- ExecutorService executor = Executors.newCachedThreadPool();
|
|
|
- executor.submit(() -> {
|
|
|
- // 你的异步任务代码
|
|
|
- log.info("["+oprno+pos+"]质量上传任务开始");
|
|
|
- try {
|
|
|
- JSONObject retObj = DataUtil.sendQuality(productSn.getText(),oprno+pos,"OK",MesClient.user_menu.getText());
|
|
|
- if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
|
|
|
- resetBlanking();
|
|
|
- }else{
|
|
|
- if(retObj.get("result")==null){
|
|
|
- setMenuStatus("请求失败,请重试",-1);
|
|
|
- }else{
|
|
|
- if(retObj.get("result").toString().equalsIgnoreCase("false")){
|
|
|
- setMenuStatus(retObj.getString("message"),-1);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- Thread.currentThread().interrupt();
|
|
|
- }
|
|
|
- log.info("["+oprno+pos+"]质量上传任务结束");
|
|
|
- });
|
|
|
- // 关闭ExecutorService,不再接受新任务,等待已提交的任务完成
|
|
|
- executor.shutdown();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- }catch (Exception e) {
|
|
|
- log.error(e.getMessage());
|
|
|
- }
|
|
|
- }
|
|
|
- }, 100,3000);
|
|
|
- }
|
|
|
-
|
|
|
- public void barCode(){
|
|
|
- if(!productSnFeeding.getText().isEmpty()){
|
|
|
- return;
|
|
|
- }
|
|
|
- String sn = readQrcode();
|
|
|
- if(sn.equals("")){
|
|
|
- if(productSnFeeding.getText().isEmpty()){
|
|
|
- this.setMenuStatus("扫码结果为空", -1);
|
|
|
- }
|
|
|
- }else{
|
|
|
- productSnFeeding.setText(sn);
|
|
|
- lastSn = sn;
|
|
|
- // 查询工件质量
|
|
|
- JSONObject retObj = DataUtil.checkQuality(sn,oprno+pos,MesClient.user_menu.getText());
|
|
|
- if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
|
|
|
- tjFeedingFlag = 1;//可加工
|
|
|
- setMenuStatus("工件可以加工", 0);
|
|
|
- writeAllowFeeding(true);
|
|
|
-// resetFeedingBtn.setEnabled(false);
|
|
|
- }else{
|
|
|
- writeAllowFeeding(false);
|
|
|
- resetFeedingBtn.setEnabled(true);
|
|
|
- if(retObj.get("result")==null){
|
|
|
- setMenuStatus("请求失败,请重试",-1);
|
|
|
- }else{
|
|
|
- if(retObj.get("result").toString().equalsIgnoreCase("false")){
|
|
|
- setMenuStatus(retObj.getString("message"),-1);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public void resetBlanking() {
|
|
|
- tjFlag = 0;
|
|
|
- tjStatus = 0;
|
|
|
- productSn.setText("");
|
|
|
- setMenuStatus("工件结果已提交,等待下一件",0);
|
|
|
- resetBtn.setEnabled(true);
|
|
|
-// writeAllowFeeding(false);
|
|
|
-// writeAllowBlanking(false);
|
|
|
- }
|
|
|
-
|
|
|
- public void resetFeeding() {
|
|
|
- tjScan = 0;
|
|
|
- productSnFeeding.setText("");
|
|
|
- tjFeedingFlag = 0;
|
|
|
- setMenuStatus("等待请求扫码",0);
|
|
|
- resetFeedingBtn.setEnabled(true);
|
|
|
- writeAllowFeeding(false);
|
|
|
- }
|
|
|
-
|
|
|
- public void resetScanA() {
|
|
|
- tjFeedingFlag = 0;
|
|
|
- tjFlag = 0;
|
|
|
- tjStatus = 0;
|
|
|
- productSn.setText("");
|
|
|
- productSnFeeding.setText("");
|
|
|
- setMenuStatus("等待请求扫码",0);
|
|
|
- resetBtn.setEnabled(true);
|
|
|
- resetFeedingBtn.setEnabled(true);
|
|
|
- writeAllowFeeding(false);
|
|
|
- writeAllowBlanking(false);
|
|
|
- }
|
|
|
- // 与设备交互-----------------------------------------------------------------------------------------
|
|
|
-
|
|
|
- // 请求扫码
|
|
|
- public boolean readFeeding(){
|
|
|
- if(isLocal == 1){
|
|
|
- return false;
|
|
|
- }else{
|
|
|
- return readBoolean(plcDb+".0.0");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 读取上料到设备
|
|
|
- public boolean readFeedingToDevice(){
|
|
|
- if(isLocal == 1){
|
|
|
- return true;
|
|
|
- }else{
|
|
|
- return readBoolean(plcDb+".0.7");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 读取上料到中转车
|
|
|
- public boolean readFeedingToTransfer(){
|
|
|
- if(isLocal == 1){
|
|
|
- return true;
|
|
|
- }else{
|
|
|
- return readBoolean(plcDb+".1.0");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 读取中转车上料到设备
|
|
|
- public boolean readFeedingTransferToDevice(){
|
|
|
- if(isLocal == 1){
|
|
|
- return true;
|
|
|
- }else{
|
|
|
- return readBoolean(plcDb+".1.1");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 读取下料信号
|
|
|
- public boolean readBlanking(){
|
|
|
- if(isLocal == 1){
|
|
|
- return false;
|
|
|
- }else{
|
|
|
- return readBoolean(plcDb+".0.1");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 读取设备运行信号
|
|
|
- public boolean readRunning(){
|
|
|
- if(isLocal == 1){
|
|
|
- return true;
|
|
|
- }else{
|
|
|
- return readBoolean(plcDb+".0.2");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 读取设备通讯状态
|
|
|
- public boolean readDeviceStatus(){
|
|
|
- if(isLocal == 1){
|
|
|
- return true;
|
|
|
- }else{
|
|
|
- return readBoolean(plcDb+".0.3");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 读取MES允许上料信号
|
|
|
- public boolean readAllowFeeding(){
|
|
|
- if(isLocal == 1){
|
|
|
- return false;
|
|
|
- }else{
|
|
|
- return readBoolean(plcDb+".0.4");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 写入MES允许上料信号
|
|
|
- public boolean writeAllowFeeding(Boolean b){
|
|
|
- if(isLocal == 1){
|
|
|
- return true;
|
|
|
- }else{
|
|
|
- return writeBoolean(plcDb+".0.4",b);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 读取MES允许下料信号
|
|
|
- public boolean readAllowBlanking(){
|
|
|
- if(isLocal == 1){
|
|
|
- return true;
|
|
|
- }else{
|
|
|
- return readBoolean(plcDb+".0.5");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 写入MES允许下料信号
|
|
|
- public boolean writeAllowBlanking(Boolean b){
|
|
|
- if(isLocal == 1){
|
|
|
- return true;
|
|
|
- }else{
|
|
|
- return writeBoolean(plcDb+".0.5",b);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 读取中转车号
|
|
|
- public int readTransferNo(){
|
|
|
- if(isLocal == 1){
|
|
|
- return 1;
|
|
|
- }else{
|
|
|
- return s7PLC.readInt16(plcDb+".2.0");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 读取中转车层数
|
|
|
- public int readTransferFloor(){
|
|
|
- if(isLocal == 1){
|
|
|
- return 1;
|
|
|
- }else{
|
|
|
- return s7PLC.readInt16(plcDb+".4.0");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 控制扫码枪读取二维码
|
|
|
- public String readQrcode(){
|
|
|
- String sn = "";
|
|
|
- if(isLocal == 1){
|
|
|
- return "";
|
|
|
- }else{
|
|
|
- try{
|
|
|
- // 中转车已隐藏:不再从中转车取码,统一走扫码枪
|
|
|
-// if(transferToDevice){ // 中转车上料到设备
|
|
|
-// int transferSn = readTransferNo();
|
|
|
-// int transferFloor = readTransferFloor();
|
|
|
-// JSONObject retObj = DataUtil.getSn(oprno+pos,transferSn,transferFloor,MesClient.user_menu.getText());
|
|
|
-// if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
|
|
|
-// sn = retObj.getString("data");
|
|
|
-// }else{
|
|
|
-// writeAllowFeeding(false);
|
|
|
-// if(retObj.get("result")==null){
|
|
|
-// this.setMenuStatus("请求失败,请重试",-1);
|
|
|
-// }else{
|
|
|
-// if(retObj.get("result").toString().equalsIgnoreCase("false")){
|
|
|
-// this.setMenuStatus(retObj.getString("message"),-1);
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }else{
|
|
|
- int transferSn = readTransferNo();
|
|
|
- if(transferSn == 1){
|
|
|
- if(pos.equals("A") || pos.equals("B") || pos.equals("C") || pos.equals("D") || pos.equals("E")){
|
|
|
- sn = MesClient.scanQrcode1();
|
|
|
- }else{
|
|
|
- sn = MesClient.scanQrcode3();
|
|
|
- }
|
|
|
- }else{
|
|
|
- if(pos.equals("A") || pos.equals("B") || pos.equals("C") || pos.equals("D") || pos.equals("E")){
|
|
|
- sn = MesClient.scanQrcode2();
|
|
|
- }else{
|
|
|
- sn = MesClient.scanQrcode4();
|
|
|
- }
|
|
|
- }
|
|
|
-// }
|
|
|
- }catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return sn;
|
|
|
- }
|
|
|
-
|
|
|
- public void scanQrcode(){
|
|
|
- log.info("scanQrcode");
|
|
|
- // 异步执行上传任务,防止阻塞
|
|
|
- ExecutorService executor = Executors.newCachedThreadPool();
|
|
|
- executor.submit(() -> {
|
|
|
- MesClient.scanQrcode4();
|
|
|
- });
|
|
|
- // 关闭ExecutorService,不再接受新任务,等待已提交的任务完成
|
|
|
- executor.shutdown();
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- public boolean readBoolean(String db){
|
|
|
- boolean permit;
|
|
|
- try {
|
|
|
- permit = s7PLC.readBoolean(db);
|
|
|
- log.info("<"+this.oprno+this.pos+">读取"+db+"-->成功,结果:{}", permit ? "true" : "false");
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("<"+this.oprno+this.pos+">读取"+db+"-->失败", e);
|
|
|
- return false;
|
|
|
- }
|
|
|
- return permit;
|
|
|
- }
|
|
|
-
|
|
|
- public boolean writeBoolean(String db, boolean permit){
|
|
|
- try {
|
|
|
- s7PLC.writeBoolean(db,permit);
|
|
|
- // 心跳日志已关闭
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("<"+this.oprno+this.pos+">写入"+db+"-->失败,写入内容:{}", permit ? "true" : "false");
|
|
|
- log.error(e.getMessage(), e);
|
|
|
- return false;
|
|
|
- }
|
|
|
- return true;
|
|
|
- }
|
|
|
-}
|