|
|
@@ -108,6 +108,15 @@ public class MesClient extends JFrame {
|
|
|
public static Object[] columnNames = { "物料名称", "绑定批次", "剩余次数", "操作" };
|
|
|
public static Object[][] rowData = null;
|
|
|
|
|
|
+ public static JLabel feedinglabel; // 允许MES读码 M190
|
|
|
+ public static JLabel feedingmeslabel; // MES允许检测 M293
|
|
|
+ public static JLabel runlabel; // 检测完成 M192/M193
|
|
|
+ public static JLabel blankingmeslabel; // MES读取结果反馈 M295
|
|
|
+ public static JLabel heartBeatlabel; // PLC心跳 M194
|
|
|
+ public static ImageIcon imageGreen;
|
|
|
+ public static ImageIcon imageGray;
|
|
|
+ public static Timer plcHeartBeatTimer; // 单独刷新 M194,避开与 PLC 1s 同频
|
|
|
+
|
|
|
public static void main(String[] args) {
|
|
|
|
|
|
EventQueue.invokeLater(new Runnable() {
|
|
|
@@ -129,6 +138,7 @@ public class MesClient extends JFrame {
|
|
|
getMaterailData();
|
|
|
|
|
|
process();
|
|
|
+ startPlcHeartBeatTimer();
|
|
|
|
|
|
// startUpdateQualityTimer(); // 开启提交结果的定时任务
|
|
|
|
|
|
@@ -611,10 +621,90 @@ public class MesClient extends JFrame {
|
|
|
finish_ng_bt.setEnabled(false);
|
|
|
indexPanelA.add(finish_ng_bt);
|
|
|
|
|
|
+ imageGreen = new ImageIcon(MesClient.class.getResource("/bg/green_dot.png"));
|
|
|
+ imageGreen.setImage(imageGreen.getImage().getScaledInstance(40, 40, Image.SCALE_SMOOTH));
|
|
|
+ imageGray = new ImageIcon(MesClient.class.getResource("/bg/grey_dot.png"));
|
|
|
+ imageGray.setImage(imageGray.getImage().getScaledInstance(40, 40, Image.SCALE_SMOOTH));
|
|
|
+
|
|
|
+ feedinglabel = new JLabel("允许MES读码");
|
|
|
+ feedinglabel.setHorizontalAlignment(SwingConstants.LEFT);
|
|
|
+ feedinglabel.setIcon(imageGray);
|
|
|
+ feedinglabel.setForeground(Color.BLACK);
|
|
|
+ feedinglabel.setBounds(50, 220, 150, 40);
|
|
|
+ indexPanelA.add(feedinglabel);
|
|
|
+
|
|
|
+ feedingmeslabel = new JLabel("MES允许检测");
|
|
|
+ feedingmeslabel.setHorizontalAlignment(SwingConstants.LEFT);
|
|
|
+ feedingmeslabel.setIcon(imageGray);
|
|
|
+ feedingmeslabel.setForeground(Color.BLACK);
|
|
|
+ feedingmeslabel.setBounds(250, 220, 150, 40);
|
|
|
+ feedingmeslabel.setToolTipText("点击可手动翻转 M293,防止设备卡住");
|
|
|
+ feedingmeslabel.addMouseListener(new MouseAdapter() {
|
|
|
+ public void mouseClicked(MouseEvent e) {
|
|
|
+ try {
|
|
|
+ boolean ret = ModbusUtils.isAllown(modbusTcp);
|
|
|
+ int choice = JOptionPane.showConfirmDialog(mesClientFrame,
|
|
|
+ "确定修改MES允许检测为" + (!ret) + "吗?",
|
|
|
+ "操作确认", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
|
|
|
+ if (choice == JOptionPane.YES_OPTION) {
|
|
|
+ if (!ret) {
|
|
|
+ ModbusUtils.writeAllow(modbusTcp);
|
|
|
+ } else {
|
|
|
+ ModbusUtils.writeAllowDeny(modbusTcp);
|
|
|
+ }
|
|
|
+ feedingmeslabel.setIcon((!ret) ? imageGreen : imageGray);
|
|
|
+ }
|
|
|
+ } catch (Exception ex) {
|
|
|
+ JOptionPane.showMessageDialog(mesClientFrame, "写入失败:" + ex.getMessage(),
|
|
|
+ "提示窗口", JOptionPane.ERROR_MESSAGE);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ indexPanelA.add(feedingmeslabel);
|
|
|
+
|
|
|
+ runlabel = new JLabel("检测完成");
|
|
|
+ runlabel.setHorizontalAlignment(SwingConstants.LEFT);
|
|
|
+ runlabel.setIcon(imageGray);
|
|
|
+ runlabel.setForeground(Color.BLACK);
|
|
|
+ runlabel.setBounds(450, 220, 150, 40);
|
|
|
+ indexPanelA.add(runlabel);
|
|
|
+
|
|
|
+ blankingmeslabel = new JLabel("MES读取结果反馈");
|
|
|
+ blankingmeslabel.setHorizontalAlignment(SwingConstants.LEFT);
|
|
|
+ blankingmeslabel.setIcon(imageGray);
|
|
|
+ blankingmeslabel.setForeground(Color.BLACK);
|
|
|
+ blankingmeslabel.setBounds(650, 220, 180, 40);
|
|
|
+ blankingmeslabel.setToolTipText("点击可手动翻转 M295,防止设备卡住");
|
|
|
+ blankingmeslabel.addMouseListener(new MouseAdapter() {
|
|
|
+ public void mouseClicked(MouseEvent e) {
|
|
|
+ try {
|
|
|
+ boolean ret = ModbusUtils.isGetDate(modbusTcp);
|
|
|
+ int choice = JOptionPane.showConfirmDialog(mesClientFrame,
|
|
|
+ "确定修改MES读取结果反馈为" + (!ret) + "吗?",
|
|
|
+ "操作确认", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
|
|
|
+ if (choice == JOptionPane.YES_OPTION) {
|
|
|
+ if (!ret) {
|
|
|
+ ModbusUtils.yjgetDate(modbusTcp);
|
|
|
+ } else {
|
|
|
+ ModbusUtils.rechargeYjgetDate(modbusTcp);
|
|
|
+ }
|
|
|
+ blankingmeslabel.setIcon((!ret) ? imageGreen : imageGray);
|
|
|
+ }
|
|
|
+ } catch (Exception ex) {
|
|
|
+ JOptionPane.showMessageDialog(mesClientFrame, "写入失败:" + ex.getMessage(),
|
|
|
+ "提示窗口", JOptionPane.ERROR_MESSAGE);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ indexPanelA.add(blankingmeslabel);
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+ heartBeatlabel = new JLabel("心跳");
|
|
|
+ heartBeatlabel.setHorizontalAlignment(SwingConstants.LEFT);
|
|
|
+ heartBeatlabel.setIcon(imageGray);
|
|
|
+ heartBeatlabel.setForeground(Color.BLACK);
|
|
|
+ heartBeatlabel.setBounds(850, 220, 120, 40);
|
|
|
+ heartBeatlabel.setToolTipText("读取 M194,1.3 秒刷新一次显示");
|
|
|
+ indexPanelA.add(heartBeatlabel);
|
|
|
|
|
|
tabbedPane.addTab("工作面板", new ImageIcon(MesClient.class.getResource("/bg/a_side.png")), indexScrollPaneA, null);
|
|
|
tabbedPane.setEnabledAt(0, true);
|
|
|
@@ -794,11 +884,62 @@ public class MesClient extends JFrame {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ // 刷新 PLC 信号指示灯(不含心跳;心跳单独 1.3s 刷新,避免与 PLC 1s 翻转同频)
|
|
|
+ private static void refreshSignalIcons() {
|
|
|
+ try {
|
|
|
+ final boolean retFeeding = ModbusUtils.isReadable(modbusTcp);
|
|
|
+ final boolean retFeedingAllow = ModbusUtils.isAllown(modbusTcp);
|
|
|
+ final boolean ok = ModbusUtils.isQualityOk(modbusTcp);
|
|
|
+ final boolean ng = ModbusUtils.isQualityNG(modbusTcp);
|
|
|
+ final boolean retAllowBlanking = ModbusUtils.isGetDate(modbusTcp);
|
|
|
+ SwingUtilities.invokeLater(() -> {
|
|
|
+ if (feedinglabel != null) {
|
|
|
+ feedinglabel.setIcon(retFeeding ? imageGreen : imageGray);
|
|
|
+ }
|
|
|
+ if (feedingmeslabel != null) {
|
|
|
+ feedingmeslabel.setIcon(retFeedingAllow ? imageGreen : imageGray);
|
|
|
+ }
|
|
|
+ if (runlabel != null) {
|
|
|
+ runlabel.setIcon((ok || ng) ? imageGreen : imageGray);
|
|
|
+ }
|
|
|
+ if (blankingmeslabel != null) {
|
|
|
+ blankingmeslabel.setIcon(retAllowBlanking ? imageGreen : imageGray);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // PLC 心跳 M194:1.3 秒读一次,避免与 PLC 1 秒翻转相位锁死
|
|
|
+ public static void startPlcHeartBeatTimer() {
|
|
|
+ if (plcHeartBeatTimer != null) {
|
|
|
+ plcHeartBeatTimer.cancel();
|
|
|
+ }
|
|
|
+ plcHeartBeatTimer = new Timer();
|
|
|
+ plcHeartBeatTimer.schedule(new TimerTask() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ try {
|
|
|
+ final boolean heartBeat = ModbusUtils.isHeartBeat(modbusTcp);
|
|
|
+ SwingUtilities.invokeLater(() -> {
|
|
|
+ if (heartBeatlabel != null) {
|
|
|
+ heartBeatlabel.setIcon(heartBeat ? imageGreen : imageGray);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }, 1000, 1300);
|
|
|
+ }
|
|
|
+
|
|
|
// 流程
|
|
|
public static void process() {
|
|
|
new Timer().schedule(new TimerTask() {
|
|
|
@Override
|
|
|
public void run() {
|
|
|
+ refreshSignalIcons();
|
|
|
if (MesClient.index == 0){
|
|
|
// 等待允许扫码信号
|
|
|
// 提示栏显示等待扫码
|
|
|
@@ -807,18 +948,26 @@ public class MesClient extends JFrame {
|
|
|
}
|
|
|
MesClient.setMenuStatus("等待扫码",0);
|
|
|
if (ModbusUtils.isReadable(modbusTcp)){
|
|
|
- // 允许扫码,进入下一阶段
|
|
|
+ // 允许扫码,进入下一阶段;新码到来时清加工状态,保证会重新开工
|
|
|
String sn = change(modbusTcp.readString(4100,120).toString());
|
|
|
MesClient.product_sn.setText(sn);
|
|
|
+ MesClient.work_status = 0;
|
|
|
+ MesClient.check_quality_result = false;
|
|
|
+ MesClient.finish_ok_bt.setEnabled(false);
|
|
|
+ MesClient.finish_ng_bt.setEnabled(false);
|
|
|
MesClient.index = 1;
|
|
|
}
|
|
|
}else if (MesClient.index == 1){
|
|
|
- // 查询工件质量
|
|
|
+ // 查询工件质量(只发一次,进入11等待回复)
|
|
|
+ getUser();
|
|
|
Boolean sendret = DataUtil.checkQuality(nettyClient,MesClient.product_sn.getText(),user20);
|
|
|
if(!sendret){
|
|
|
JOptionPane.showMessageDialog(mesClientFrame,"消息发送失败,请重试","提示窗口", JOptionPane.INFORMATION_MESSAGE);
|
|
|
return;
|
|
|
}
|
|
|
+ MesClient.index = 11;
|
|
|
+ }else if (MesClient.index == 11){
|
|
|
+ // 等待AQDW/MKSW回复,由MesRevice推进到index=2或-1
|
|
|
} else if (MesClient.index == 2) {
|
|
|
// 清楚是否可以做件信号
|
|
|
ModbusUtils.rechargeAllow(modbusTcp);
|
|
|
@@ -831,6 +980,7 @@ public class MesClient extends JFrame {
|
|
|
boolean ng = ModbusUtils.isQualityNG(modbusTcp);
|
|
|
//当有一个为ture时
|
|
|
if (ok || ng){
|
|
|
+ getUser();
|
|
|
if (ok){
|
|
|
Boolean sendret = DataUtil.sendQuality(MesClient.product_sn.getText(),"OK",user20);
|
|
|
if(!sendret){
|
|
|
@@ -844,7 +994,11 @@ public class MesClient extends JFrame {
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
+ // 已发送MQDW,等待回复,避免重复提交
|
|
|
+ MesClient.index = 5;
|
|
|
}
|
|
|
+ }else if (MesClient.index == 5){
|
|
|
+ // 等待MQDW回复,由MesRevice.updateResultRevice推进到index=4
|
|
|
} else if (MesClient.index == 4) {
|
|
|
boolean ok = ModbusUtils.isQualityOk(modbusTcp);
|
|
|
boolean ng = ModbusUtils.isQualityNG(modbusTcp);
|