|
@@ -12,13 +12,21 @@ import javax.swing.border.TitledBorder;
|
|
|
import java.awt.*;
|
|
import java.awt.*;
|
|
|
import java.awt.event.ActionEvent;
|
|
import java.awt.event.ActionEvent;
|
|
|
import java.awt.event.ActionListener;
|
|
import java.awt.event.ActionListener;
|
|
|
|
|
+import java.awt.event.MouseAdapter;
|
|
|
|
|
+import java.awt.event.MouseEvent;
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
|
|
+import java.util.LinkedHashMap;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
+import java.util.Map;
|
|
|
import java.util.Timer;
|
|
import java.util.Timer;
|
|
|
import java.util.TimerTask;
|
|
import java.util.TimerTask;
|
|
|
|
|
|
|
|
public class WorkStationPanel extends JPanel {
|
|
public class WorkStationPanel extends JPanel {
|
|
|
private static final Logger log = LoggerFactory.getLogger(WorkStationPanel.class);
|
|
private static final Logger log = LoggerFactory.getLogger(WorkStationPanel.class);
|
|
|
|
|
+ private static final long PLC_STATUS_REFRESH_INTERVAL_MS = 3000L;
|
|
|
|
|
+ private static final long PLC_STATUS_RETRY_BACKOFF_MS = 10000L;
|
|
|
|
|
+ private static final long PLC_STATUS_WARN_INTERVAL_MS = 30000L;
|
|
|
|
|
+ private static final long PLC_WORKFLOW_WARN_INTERVAL_MS = 30000L;
|
|
|
private String gw;
|
|
private String gw;
|
|
|
private String gwDes;
|
|
private String gwDes;
|
|
|
private String lineSn;
|
|
private String lineSn;
|
|
@@ -45,10 +53,18 @@ public class WorkStationPanel extends JPanel {
|
|
|
private JLabel statusLabel;
|
|
private JLabel statusLabel;
|
|
|
private JLabel heartBeatLabel;
|
|
private JLabel heartBeatLabel;
|
|
|
private JLabel fxLabel;
|
|
private JLabel fxLabel;
|
|
|
|
|
+ private final Map<String, JLabel> plcStatusDots = new LinkedHashMap<>();
|
|
|
|
|
+ private final Map<String, Boolean> plcStatusValues = new LinkedHashMap<>();
|
|
|
public static Object[][] rowData = null;
|
|
public static Object[][] rowData = null;
|
|
|
|
|
|
|
|
private Timer heartBeatTimer;
|
|
private Timer heartBeatTimer;
|
|
|
private Timer getSnBeatTimer;
|
|
private Timer getSnBeatTimer;
|
|
|
|
|
+ private Timer plcStatusTimer;
|
|
|
|
|
+ private int plcStatusReadFailCount = 0;
|
|
|
|
|
+ private long nextPlcStatusReadTime = 0L;
|
|
|
|
|
+ private long lastPlcStatusWarnTime = 0L;
|
|
|
|
|
+ private int plcWorkflowFailCount = 0;
|
|
|
|
|
+ private long lastPlcWorkflowWarnTime = 0L;
|
|
|
|
|
|
|
|
private boolean iconREDFlag = true;
|
|
private boolean iconREDFlag = true;
|
|
|
|
|
|
|
@@ -63,6 +79,7 @@ public class WorkStationPanel extends JPanel {
|
|
|
this.stopMethod = stopMethod;
|
|
this.stopMethod = stopMethod;
|
|
|
initUI();
|
|
initUI();
|
|
|
startHeartBeatTimer();
|
|
startHeartBeatTimer();
|
|
|
|
|
+ startPlcStatusTimer();
|
|
|
startGetCurSn();
|
|
startGetCurSn();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -78,6 +95,7 @@ public class WorkStationPanel extends JPanel {
|
|
|
this.stationConfig = stationConfig;
|
|
this.stationConfig = stationConfig;
|
|
|
initUI();
|
|
initUI();
|
|
|
startHeartBeatTimer();
|
|
startHeartBeatTimer();
|
|
|
|
|
+ startPlcStatusTimer();
|
|
|
startGetCurSn();
|
|
startGetCurSn();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -203,6 +221,10 @@ public class WorkStationPanel extends JPanel {
|
|
|
buttonPanel.add(finishNgButton);
|
|
buttonPanel.add(finishNgButton);
|
|
|
|
|
|
|
|
centerPanel.add(buttonPanel);
|
|
centerPanel.add(buttonPanel);
|
|
|
|
|
+
|
|
|
|
|
+ JPanel plcStatusPanel = createPlcStatusPanel();
|
|
|
|
|
+ centerPanel.add(plcStatusPanel);
|
|
|
|
|
+
|
|
|
add(centerPanel, BorderLayout.CENTER);
|
|
add(centerPanel, BorderLayout.CENTER);
|
|
|
|
|
|
|
|
JPanel bottomPanel = new JPanel(new BorderLayout());
|
|
JPanel bottomPanel = new JPanel(new BorderLayout());
|
|
@@ -242,19 +264,129 @@ public class WorkStationPanel extends JPanel {
|
|
|
add(bottomPanel, BorderLayout.SOUTH);
|
|
add(bottomPanel, BorderLayout.SOUTH);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private void scanBarcode() {
|
|
|
|
|
- if (workStatus == 1) {
|
|
|
|
|
- JOptionPane.showMessageDialog(this, "[" + gw + "] 工作中,勿扫码", "提示", JOptionPane.INFORMATION_MESSAGE);
|
|
|
|
|
|
|
+ private JPanel createPlcStatusPanel() {
|
|
|
|
|
+ JPanel plcStatusPanel = new JPanel(new GridLayout(3, 1, 0, 3));
|
|
|
|
|
+ plcStatusPanel.setBackground(Color.WHITE);
|
|
|
|
|
+ plcStatusPanel.setBorder(BorderFactory.createEmptyBorder(0, 20, 0, 20));
|
|
|
|
|
+
|
|
|
|
|
+ JPanel firstLine = createPlcStatusLine();
|
|
|
|
|
+ addPlcStatusItem(firstLine, "allowStart", "允许启动", true);
|
|
|
|
|
+ addPlcStatusItem(firstLine, "allowDown", "允许下料", true);
|
|
|
|
|
+ plcStatusPanel.add(firstLine);
|
|
|
|
|
+
|
|
|
|
|
+ JPanel secondLine = createPlcStatusLine();
|
|
|
|
|
+ addPlcStatusItem(secondLine, "start", "开始加工", false);
|
|
|
|
|
+ addPlcStatusItem(secondLine, "finish", "加工结束", false);
|
|
|
|
|
+ plcStatusPanel.add(secondLine);
|
|
|
|
|
+
|
|
|
|
|
+ JPanel thirdLine = createPlcStatusLine();
|
|
|
|
|
+ addPlcStatusItem(thirdLine, "fault", "故障", false);
|
|
|
|
|
+ plcStatusPanel.add(thirdLine);
|
|
|
|
|
+ return plcStatusPanel;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private JPanel createPlcStatusLine() {
|
|
|
|
|
+ JPanel linePanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 14, 0));
|
|
|
|
|
+ linePanel.setBackground(Color.WHITE);
|
|
|
|
|
+ return linePanel;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void addPlcStatusItem(JPanel parent, final String key, String title, boolean clickable) {
|
|
|
|
|
+ JPanel itemPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 4, 0));
|
|
|
|
|
+ itemPanel.setBackground(Color.WHITE);
|
|
|
|
|
+
|
|
|
|
|
+ JLabel titleLabel = new JLabel(title);
|
|
|
|
|
+ titleLabel.setFont(new Font("微软雅黑", Font.PLAIN, 14));
|
|
|
|
|
+ titleLabel.setPreferredSize(new Dimension(62, 20));
|
|
|
|
|
+ titleLabel.setHorizontalAlignment(SwingConstants.RIGHT);
|
|
|
|
|
+ itemPanel.add(titleLabel);
|
|
|
|
|
+
|
|
|
|
|
+ JLabel dotLabel = new JLabel(greyDotIcon());
|
|
|
|
|
+ dotLabel.setPreferredSize(new Dimension(20, 20));
|
|
|
|
|
+ if (clickable) {
|
|
|
|
|
+ dotLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
|
|
|
|
+ titleLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
|
|
|
|
+ MouseAdapter adapter = new MouseAdapter() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void mouseClicked(MouseEvent e) {
|
|
|
|
|
+ toggleWritablePlcStatus(key);
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+ dotLabel.addMouseListener(adapter);
|
|
|
|
|
+ titleLabel.addMouseListener(adapter);
|
|
|
|
|
+ }
|
|
|
|
|
+ itemPanel.add(dotLabel);
|
|
|
|
|
+
|
|
|
|
|
+ plcStatusDots.put(key, dotLabel);
|
|
|
|
|
+ plcStatusValues.put(key, false);
|
|
|
|
|
+ parent.add(itemPanel);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private ImageIcon greenDotIcon() {
|
|
|
|
|
+ return new ImageIcon(getClass().getResource("/bg/green_dot.png"));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private ImageIcon greyDotIcon() {
|
|
|
|
|
+ return new ImageIcon(getClass().getResource("/bg/grey_dot.png"));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void toggleWritablePlcStatus(final String key) {
|
|
|
|
|
+ if (stationConfig == null) {
|
|
|
|
|
+ JOptionPane.showMessageDialog(this, "未加载PLC工位配置,无法切换状态", "提示", JOptionPane.WARNING_MESSAGE);
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- String scanBarcode = JOptionPane.showInputDialog(null, "[" + gw + "] 请扫工件码");
|
|
|
|
|
- if (scanBarcode != null && !scanBarcode.isEmpty()) {
|
|
|
|
|
- productSnField.setText(scanBarcode);
|
|
|
|
|
- checkQuality(scanBarcode);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ final boolean newValue = !Boolean.TRUE.equals(plcStatusValues.get(key));
|
|
|
|
|
+ String statusName = "allowStart".equals(key) ? "允许启动" : "允许下料";
|
|
|
|
|
+ String actionName = newValue ? "开启" : "关闭";
|
|
|
|
|
+ int confirm = JOptionPane.showConfirmDialog(
|
|
|
|
|
+ this,
|
|
|
|
|
+ "确定要" + actionName + "【" + statusName + "】吗?",
|
|
|
|
|
+ "确认更改",
|
|
|
|
|
+ JOptionPane.YES_NO_OPTION,
|
|
|
|
|
+ JOptionPane.QUESTION_MESSAGE);
|
|
|
|
|
+ if (confirm != JOptionPane.YES_OPTION) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ setPlcStatusDot(key, newValue);
|
|
|
|
|
+
|
|
|
|
|
+ SwingWorker<Boolean, Void> worker = new SwingWorker<Boolean, Void>() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ protected Boolean doInBackground() {
|
|
|
|
|
+ if ("allowStart".equals(key)) {
|
|
|
|
|
+ return PLCUtils.writeAllowStart(stationConfig, newValue);
|
|
|
|
|
+ }
|
|
|
|
|
+ if ("allowDown".equals(key)) {
|
|
|
|
|
+ return PLCUtils.writeAllowDown(stationConfig, newValue);
|
|
|
|
|
+ }
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ protected void done() {
|
|
|
|
|
+ try {
|
|
|
|
|
+ if (!get()) {
|
|
|
|
|
+ setPlcStatusDot(key, !newValue);
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception ex) {
|
|
|
|
|
+ setPlcStatusDot(key, !newValue);
|
|
|
|
|
+ JOptionPane.showMessageDialog(WorkStationPanel.this, "PLC状态切换失败:" + ex.getMessage(), "错误", JOptionPane.ERROR_MESSAGE);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+ worker.execute();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void setPlcStatusDot(String key, boolean value) {
|
|
|
|
|
+ plcStatusValues.put(key, value);
|
|
|
|
|
+ JLabel dot = plcStatusDots.get(key);
|
|
|
|
|
+ if (dot != null) {
|
|
|
|
|
+ dot.setIcon(value ? greenDotIcon() : greyDotIcon());
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
private void checkQuality(String sn) {
|
|
private void checkQuality(String sn) {
|
|
|
JSONObject retObj = DataUtil.checkQuality(sn, currentUser, gw, lineSn, serverIp);
|
|
JSONObject retObj = DataUtil.checkQuality(sn, currentUser, gw, lineSn, serverIp);
|
|
|
if (retObj != null && "true".equalsIgnoreCase(retObj.getString("result"))) {
|
|
if (retObj != null && "true".equalsIgnoreCase(retObj.getString("result"))) {
|
|
@@ -380,6 +512,52 @@ public class WorkStationPanel extends JPanel {
|
|
|
}, 100, 1000);
|
|
}, 100, 1000);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private void startPlcStatusTimer() {
|
|
|
|
|
+ if (plcStatusTimer != null) {
|
|
|
|
|
+ plcStatusTimer.cancel();
|
|
|
|
|
+ }
|
|
|
|
|
+ plcStatusTimer = new Timer();
|
|
|
|
|
+ long initialDelay = 500L + Math.abs(gw == null ? 0 : gw.hashCode() % 2000);
|
|
|
|
|
+ plcStatusTimer.schedule(new TimerTask() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void run() {
|
|
|
|
|
+ refreshPlcStatus();
|
|
|
|
|
+ }
|
|
|
|
|
+ }, initialDelay, PLC_STATUS_REFRESH_INTERVAL_MS);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void refreshPlcStatus() {
|
|
|
|
|
+ if (stationConfig == null) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ long now = System.currentTimeMillis();
|
|
|
|
|
+ if (now < nextPlcStatusReadTime) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ try {
|
|
|
|
|
+ final PLCUtils.StationStatus status = PLCUtils.readStationStatus(stationConfig);
|
|
|
|
|
+ plcStatusReadFailCount = 0;
|
|
|
|
|
+ nextPlcStatusReadTime = 0L;
|
|
|
|
|
+ SwingUtilities.invokeLater(new Runnable() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void run() {
|
|
|
|
|
+ setPlcStatusDot("allowStart", status.isAllowStart());
|
|
|
|
|
+ setPlcStatusDot("allowDown", status.isAllowDown());
|
|
|
|
|
+ setPlcStatusDot("start", status.isStart());
|
|
|
|
|
+ setPlcStatusDot("finish", status.isFinish());
|
|
|
|
|
+ setPlcStatusDot("fault", status.isFault());
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ plcStatusReadFailCount++;
|
|
|
|
|
+ nextPlcStatusReadTime = now + PLC_STATUS_RETRY_BACKOFF_MS;
|
|
|
|
|
+ if (now - lastPlcStatusWarnTime >= PLC_STATUS_WARN_INTERVAL_MS) {
|
|
|
|
|
+ lastPlcStatusWarnTime = now;
|
|
|
|
|
+ log.warn("读取PLC状态失败,工位={},连续失败{}次,{}ms后重试", gw, plcStatusReadFailCount, PLC_STATUS_RETRY_BACKOFF_MS, e);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
private void startGetCurSn(){
|
|
private void startGetCurSn(){
|
|
|
if (getSnBeatTimer != null) {
|
|
if (getSnBeatTimer != null) {
|
|
|
getSnBeatTimer.cancel();
|
|
getSnBeatTimer.cancel();
|
|
@@ -388,104 +566,122 @@ public class WorkStationPanel extends JPanel {
|
|
|
getSnBeatTimer.schedule(new TimerTask() {
|
|
getSnBeatTimer.schedule(new TimerTask() {
|
|
|
@Override
|
|
@Override
|
|
|
public void run() {
|
|
public void run() {
|
|
|
- if (workStatus == 1) {
|
|
|
|
|
- // TODO
|
|
|
|
|
- // 加入工作流程
|
|
|
|
|
- if (plcStatus == 0){
|
|
|
|
|
- // 等待扫码
|
|
|
|
|
- String sn = productSnField.getText().trim();
|
|
|
|
|
- if (!sn.isEmpty()) {
|
|
|
|
|
- plcStatus = 1;
|
|
|
|
|
- }
|
|
|
|
|
- } else if (plcStatus == 1) {
|
|
|
|
|
- // 发送允许启动信号
|
|
|
|
|
- Boolean ret = PLCUtils.writeStartMethod(stationConfig);
|
|
|
|
|
- if (ret) {
|
|
|
|
|
- plcStatus = 2;
|
|
|
|
|
- }
|
|
|
|
|
- } else if (plcStatus == 2) {
|
|
|
|
|
- // 等待开始加工信号
|
|
|
|
|
- Boolean ret = PLCUtils.readStartMethod(stationConfig);
|
|
|
|
|
- if (ret){
|
|
|
|
|
- // 将允许启动置空
|
|
|
|
|
- boolean ret2 = PLCUtils.writeStopMethod(stationConfig);
|
|
|
|
|
- if (ret2){
|
|
|
|
|
- plcStatus = 3;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- } else if (plcStatus ==3) {
|
|
|
|
|
- // 等待加工结束信号
|
|
|
|
|
- Boolean ret = PLCUtils.readStopMethod(stationConfig);
|
|
|
|
|
- if (ret){
|
|
|
|
|
- // 发送结果
|
|
|
|
|
- String sn = productSnField.getText().trim();
|
|
|
|
|
- if (lastWeldingParamContent == null || lastWeldingParamContent.trim().isEmpty()) {
|
|
|
|
|
- lastWeldingParamContent = PLCUtils.getWeldingParamContent(stationConfig);
|
|
|
|
|
- }
|
|
|
|
|
- JSONObject retObj = DataUtil.sendQuality( sn,"OK", currentUser, gw, lineSn, serverIp);
|
|
|
|
|
- if (retObj != null && "true".equalsIgnoreCase(retObj.getString("result"))) {
|
|
|
|
|
- if (lastWeldingParamContent != null && !lastWeldingParamContent.trim().isEmpty()) {
|
|
|
|
|
- JSONObject saveParamRet = DataUtil.saveWeldingParams(sn, gw, lineSn, serverIp, lastWeldingParamContent);
|
|
|
|
|
- if (saveParamRet == null || !"true".equalsIgnoreCase(saveParamRet.getString("result"))) {
|
|
|
|
|
- log.warn("焊接参数上传失败,工位={}, 工件码={}", gw, sn);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- // 发送允许下料
|
|
|
|
|
- PLCUtils.writeDownMethod(stationConfig);
|
|
|
|
|
- statusLabel.setForeground(Color.GREEN);
|
|
|
|
|
- statusLabel.setText("结果提交成功,请扫下一件");
|
|
|
|
|
- finishNgButton.setEnabled(false);
|
|
|
|
|
- plcStatus = 4;
|
|
|
|
|
- } else {
|
|
|
|
|
- statusLabel.setForeground(Color.RED);
|
|
|
|
|
- String msg = (retObj != null && retObj.containsKey("message")) ? retObj.getString("message") : "提交失败";
|
|
|
|
|
- statusLabel.setText(msg);
|
|
|
|
|
- }
|
|
|
|
|
- }else {
|
|
|
|
|
- // 获取参数
|
|
|
|
|
- lastWeldingParamContent = PLCUtils.getWeldingParamContent(stationConfig);
|
|
|
|
|
- hjparams = new ArrayList<>();
|
|
|
|
|
- if (lastWeldingParamContent != null && !lastWeldingParamContent.trim().isEmpty()) {
|
|
|
|
|
- hjparams.add(lastWeldingParamContent);
|
|
|
|
|
|
|
+ runWorkFlowSafely();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }, 100, 1000);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void runWorkFlowSafely() {
|
|
|
|
|
+ try {
|
|
|
|
|
+ runWorkFlow();
|
|
|
|
|
+ plcWorkflowFailCount = 0;
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ handleWorkflowException(e);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void runWorkFlow() {
|
|
|
|
|
+ if (workStatus == 1) {
|
|
|
|
|
+ if (plcStatus == 0){
|
|
|
|
|
+ // 等待扫码
|
|
|
|
|
+ String sn = productSnField.getText().trim();
|
|
|
|
|
+ if (!sn.isEmpty()) {
|
|
|
|
|
+ plcStatus = 1;
|
|
|
|
|
+ }
|
|
|
|
|
+ } else if (plcStatus == 1) {
|
|
|
|
|
+ // 质量检查合格后,发送允许启动信号。
|
|
|
|
|
+ Boolean ret = PLCUtils.writeStartMethod(stationConfig);
|
|
|
|
|
+ if (ret) {
|
|
|
|
|
+ statusLabel.setForeground(Color.GREEN);
|
|
|
|
|
+ statusLabel.setText("已允许启动,等待开始加工");
|
|
|
|
|
+ plcStatus = 2;
|
|
|
|
|
+ }
|
|
|
|
|
+ } else if (plcStatus == 2) {
|
|
|
|
|
+ // 等待开始加工信号为 true,收到后将允许启动置为 false。
|
|
|
|
|
+ Boolean ret = PLCUtils.readStartMethod(stationConfig);
|
|
|
|
|
+ System.out.println("开始加工信号"+stationConfig.getGw()+ret);
|
|
|
|
|
+ if (ret){
|
|
|
|
|
+ boolean ret2 = PLCUtils.writeStopMethod(stationConfig);
|
|
|
|
|
+ if (ret2) {
|
|
|
|
|
+ statusLabel.setForeground(Color.GREEN);
|
|
|
|
|
+ statusLabel.setText("加工中,等待加工结束");
|
|
|
|
|
+ plcStatus = 3;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ } else if (plcStatus ==3) {
|
|
|
|
|
+ // 等待加工结束信号为 true,提交结果后发送允许下料信号。
|
|
|
|
|
+ Boolean ret = PLCUtils.readStopMethod(stationConfig);
|
|
|
|
|
+ if (ret){
|
|
|
|
|
+ // 发送结果
|
|
|
|
|
+ String sn = productSnField.getText().trim();
|
|
|
|
|
+ if (lastWeldingParamContent == null || lastWeldingParamContent.trim().isEmpty()) {
|
|
|
|
|
+ lastWeldingParamContent = PLCUtils.getWeldingParamContent(stationConfig);
|
|
|
|
|
+ log.info("PLC中读取"+lastWeldingParamContent);
|
|
|
|
|
+ }
|
|
|
|
|
+ JSONObject retObj = DataUtil.sendQuality( sn,"OK", currentUser, gw, lineSn, serverIp);
|
|
|
|
|
+ if (retObj != null && "true".equalsIgnoreCase(retObj.getString("result"))) {
|
|
|
|
|
+ if (lastWeldingParamContent != null && !lastWeldingParamContent.trim().isEmpty()) {
|
|
|
|
|
+ JSONObject saveParamRet = DataUtil.saveWeldingParams(sn, gw, lineSn, serverIp, lastWeldingParamContent);
|
|
|
|
|
+ if (saveParamRet == null || !"true".equalsIgnoreCase(saveParamRet.getString("result"))) {
|
|
|
|
|
+ log.warn("焊接参数上传失败,工位={}, 工件码={}", gw, sn);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- }else if (plcStatus == 4){
|
|
|
|
|
- // 等待加工结束为空
|
|
|
|
|
- Boolean ret = PLCUtils.readStopMethod(stationConfig);
|
|
|
|
|
- if (!ret){
|
|
|
|
|
- PLCUtils.writeDownStopMethod(stationConfig);
|
|
|
|
|
- resetState();
|
|
|
|
|
|
|
+ Boolean downRet = PLCUtils.writeDownMethod(stationConfig);
|
|
|
|
|
+ if (downRet) {
|
|
|
|
|
+ statusLabel.setForeground(Color.GREEN);
|
|
|
|
|
+ statusLabel.setText("已允许下料,等待加工结束信号复位");
|
|
|
|
|
+ finishOkButton.setEnabled(false);
|
|
|
|
|
+ finishNgButton.setEnabled(false);
|
|
|
|
|
+ plcStatus = 4;
|
|
|
}
|
|
}
|
|
|
|
|
+ } else {
|
|
|
|
|
+ statusLabel.setForeground(Color.RED);
|
|
|
|
|
+ String msg = (retObj != null && retObj.containsKey("message")) ? retObj.getString("message") : "提交失败";
|
|
|
|
|
+ statusLabel.setText(msg);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- return;
|
|
|
|
|
- } else if (workStatus == 0) {
|
|
|
|
|
- JSONObject result = DataUtil.getCurSn(gw, serverIp, lineSn);
|
|
|
|
|
- // 正常处理结果
|
|
|
|
|
- if (result.containsKey("data")) {
|
|
|
|
|
- String data = result.getString("data");
|
|
|
|
|
- if (data != null && !data.isEmpty()) {
|
|
|
|
|
- productSnField.setText(data);
|
|
|
|
|
- checkQuality(data);
|
|
|
|
|
- } else {
|
|
|
|
|
- JOptionPane.showMessageDialog(WorkStationPanel.this, "获取工件码为空", "提示", JOptionPane.INFORMATION_MESSAGE);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ }else {
|
|
|
|
|
+ // 获取参数
|
|
|
|
|
+ lastWeldingParamContent = PLCUtils.getWeldingParamContent(stationConfig);
|
|
|
|
|
+ hjparams = new ArrayList<>();
|
|
|
|
|
+ if (lastWeldingParamContent != null && !lastWeldingParamContent.trim().isEmpty()) {
|
|
|
|
|
+ hjparams.add(lastWeldingParamContent);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ }else if (plcStatus == 4){
|
|
|
|
|
+ // 等待加工结束信号为 false,收到后将允许下料置为 false。
|
|
|
|
|
+ Boolean ret = PLCUtils.readStopMethod(stationConfig);
|
|
|
|
|
+ if (!ret){
|
|
|
|
|
+ PLCUtils.writeDownStopMethod(stationConfig);
|
|
|
|
|
+ resetState();
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- }, 100, 1000);
|
|
|
|
|
|
|
+ return;
|
|
|
|
|
+ } else if (workStatus == 0) {
|
|
|
|
|
+ JSONObject result = DataUtil.getCurSn(gw, serverIp, lineSn);
|
|
|
|
|
+ // 正常处理结果
|
|
|
|
|
+ if (result.containsKey("data")) {
|
|
|
|
|
+ String data = result.getString("data");
|
|
|
|
|
+ if (data != null && !data.isEmpty()) {
|
|
|
|
|
+ productSnField.setText(data);
|
|
|
|
|
+ checkQuality(data);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ JOptionPane.showMessageDialog(WorkStationPanel.this, "获取工件码为空", "提示", JOptionPane.INFORMATION_MESSAGE);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public void stopHeartBeat() {
|
|
|
|
|
- if (heartBeatTimer != null) {
|
|
|
|
|
- heartBeatTimer.cancel();
|
|
|
|
|
|
|
+ private void handleWorkflowException(Exception e) {
|
|
|
|
|
+ plcWorkflowFailCount++;
|
|
|
|
|
+ long now = System.currentTimeMillis();
|
|
|
|
|
+ if (now - lastPlcWorkflowWarnTime >= PLC_WORKFLOW_WARN_INTERVAL_MS) {
|
|
|
|
|
+ lastPlcWorkflowWarnTime = now;
|
|
|
|
|
+ log.warn("PLC自动流程执行失败,工位={},流程状态={},连续失败{}次,下次继续等待", gw, plcStatus, plcWorkflowFailCount, e);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public String getGw() {
|
|
|
|
|
- return gw;
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
public void setCurrentUser(String user) {
|
|
public void setCurrentUser(String user) {
|
|
|
this.currentUser = user;
|
|
this.currentUser = user;
|