|
|
@@ -54,6 +54,7 @@ public class MesClient extends JFrame {
|
|
|
public static int mes_heart_beat_cycle = 10; // 心跳周期
|
|
|
public static int mes_heart_icon_cycle = 1;
|
|
|
public static String mes_line_sn = ""; // 产线编号
|
|
|
+ public static String lastSn = "";
|
|
|
|
|
|
//TCP连接
|
|
|
public static NettyClient nettyClient;
|
|
|
@@ -103,11 +104,24 @@ public class MesClient extends JFrame {
|
|
|
public static int index = 0;
|
|
|
|
|
|
public static ModbusTcp modbusTcp = new ModbusTcp("192.168.1.20");
|
|
|
-
|
|
|
public static JTable table;
|
|
|
public static Object[] columnNames = { "物料名称", "绑定批次", "剩余次数", "操作" };
|
|
|
public static Object[][] rowData = null;
|
|
|
|
|
|
+ public static JLabel feedinglabel;
|
|
|
+
|
|
|
+ public static JLabel feedingmeslabel;
|
|
|
+
|
|
|
+ public static JLabel runlabel; //运行反馈,
|
|
|
+
|
|
|
+ public static JLabel blankinglabel; // 下料反馈
|
|
|
+
|
|
|
+ public static JLabel blankingmeslabel; // 下料MES反馈
|
|
|
+
|
|
|
+ public static ImageIcon imageGreen;
|
|
|
+
|
|
|
+ public static ImageIcon imageGray;
|
|
|
+
|
|
|
public static void main(String[] args) {
|
|
|
|
|
|
EventQueue.invokeLater(new Runnable() {
|
|
|
@@ -123,10 +137,11 @@ public class MesClient extends JFrame {
|
|
|
|
|
|
JdbcUtils.getConn();
|
|
|
|
|
|
+// System.out.println("sn:"+change(modbusTcp.readString(100,120).toString()));
|
|
|
welcomeWin = new LoginFarme();
|
|
|
welcomeWin.setVisible(true);
|
|
|
|
|
|
- getMaterailData();
|
|
|
+// getMaterailData();
|
|
|
|
|
|
process();
|
|
|
|
|
|
@@ -275,7 +290,10 @@ public class MesClient extends JFrame {
|
|
|
MesClient.f_scan_data_bt_1.setEnabled(true);
|
|
|
MesClient.setMenuStatus("请扫工件码",0);
|
|
|
MesClient.index = 0;
|
|
|
- updateMaterailData();
|
|
|
+ lastSn = "";
|
|
|
+// updateMaterailData();
|
|
|
+ // 清楚是否可以做件信号
|
|
|
+ ModbusUtils.rechargeAllow(modbusTcp);
|
|
|
// shiftUserCheck();
|
|
|
}
|
|
|
|
|
|
@@ -612,6 +630,66 @@ public class MesClient extends JFrame {
|
|
|
// 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(imageGreen);
|
|
|
+ feedinglabel.setForeground(Color.BLACK);
|
|
|
+ feedinglabel.setBounds(50, 220, 150, 40);
|
|
|
+ indexPanelA.add(feedinglabel);
|
|
|
+
|
|
|
+ feedingmeslabel = new JLabel("MES允许上料");
|
|
|
+ feedingmeslabel.setHorizontalAlignment(SwingConstants.LEFT);
|
|
|
+ feedingmeslabel.setIcon(imageGreen);
|
|
|
+ feedingmeslabel.setForeground(Color.BLACK);
|
|
|
+ feedingmeslabel.setBounds(250, 220, 150, 40);
|
|
|
+ feedingmeslabel.addMouseListener(new MouseAdapter() {
|
|
|
+ public void mouseClicked(MouseEvent e) {
|
|
|
+ boolean ret = ModbusUtils.isAllown(modbusTcp);
|
|
|
+ int choice = JOptionPane.showConfirmDialog(null, "确定修改MES允许上料结果为"+(ret?"false":"true")+"吗?", "操作确认", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
|
|
|
+ if (choice == JOptionPane.YES_OPTION) {
|
|
|
+ if(!ret){
|
|
|
+ ModbusUtils.writeAllow(modbusTcp);
|
|
|
+ }else{
|
|
|
+ ModbusUtils.writeAllowDeny(modbusTcp);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ indexPanelA.add(feedingmeslabel);
|
|
|
+
|
|
|
+ runlabel = new JLabel("检测完成");
|
|
|
+ runlabel.setHorizontalAlignment(SwingConstants.LEFT);
|
|
|
+ runlabel.setIcon(imageGreen);
|
|
|
+ runlabel.setForeground(Color.BLACK);
|
|
|
+ runlabel.setBounds(450, 220, 150, 40);
|
|
|
+ indexPanelA.add(runlabel);
|
|
|
+
|
|
|
+ blankingmeslabel = new JLabel("MES读取结果反馈");
|
|
|
+ blankingmeslabel.setHorizontalAlignment(SwingConstants.LEFT);
|
|
|
+ blankingmeslabel.setIcon(imageGreen);
|
|
|
+ blankingmeslabel.setForeground(Color.BLACK);
|
|
|
+ blankingmeslabel.setBounds(650, 220, 150, 40);
|
|
|
+ indexPanelA.add(blankingmeslabel);
|
|
|
+ blankingmeslabel.addMouseListener(new MouseAdapter() {
|
|
|
+ public void mouseClicked(MouseEvent e) {
|
|
|
+ boolean ret = ModbusUtils.isGetDate(modbusTcp);
|
|
|
+ int choice = JOptionPane.showConfirmDialog(null, "确定修改MES读取结果反馈结果为"+(ret?"false":"true")+"吗?", "操作确认", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
|
|
|
+ if (choice == JOptionPane.YES_OPTION) {
|
|
|
+ if(!ret){
|
|
|
+ ModbusUtils.yjgetDate(modbusTcp);
|
|
|
+ }else{
|
|
|
+ ModbusUtils.rechargeYjgetDate(modbusTcp);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
|
|
|
|
|
|
|
|
|
@@ -799,68 +877,90 @@ public class MesClient extends JFrame {
|
|
|
new Timer().schedule(new TimerTask() {
|
|
|
@Override
|
|
|
public void run() {
|
|
|
- if (MesClient.index == 0){
|
|
|
- // 等待允许扫码信号
|
|
|
- // 提示栏显示等待扫码
|
|
|
- if (ModbusUtils.isGetDate(modbusTcp)){
|
|
|
- ModbusUtils.rechargeYjgetDate(modbusTcp);
|
|
|
- }
|
|
|
- MesClient.setMenuStatus("等待扫码",0);
|
|
|
- System.out.println("是否允许读码"+ModbusUtils.isReadable(modbusTcp));
|
|
|
- if (ModbusUtils.isReadable(modbusTcp)){
|
|
|
- // 允许扫码,进入下一阶段
|
|
|
- String sn = change(modbusTcp.readString(4100,120).toString());
|
|
|
- System.out.println("已读二维码:"+change(modbusTcp.readString(4100,120).toString()));
|
|
|
- MesClient.product_sn.setText(sn);
|
|
|
- MesClient.index = 1;
|
|
|
- }
|
|
|
- }else if (MesClient.index == 1){
|
|
|
- // 查询工件质量
|
|
|
- Boolean sendret = DataUtil.checkQuality(nettyClient,MesClient.product_sn.getText(),user20);
|
|
|
- if(!sendret){
|
|
|
- JOptionPane.showMessageDialog(mesClientFrame,"消息发送失败,请重试","提示窗口", JOptionPane.INFORMATION_MESSAGE);
|
|
|
- return;
|
|
|
- }
|
|
|
- } else if (MesClient.index == 2) {
|
|
|
- // 清楚是否可以做件信号
|
|
|
- ModbusUtils.rechargeAllow(modbusTcp);
|
|
|
- MesClient.index = 3;
|
|
|
- }else if (MesClient.index == 3) {
|
|
|
- // 提示栏显示等待加工
|
|
|
- MesClient.setMenuStatus("加工中",0);
|
|
|
- //等待产品是否合格
|
|
|
- boolean ok = ModbusUtils.isQualityOk(modbusTcp);
|
|
|
- boolean ng = ModbusUtils.isQualityNG(modbusTcp);
|
|
|
- //当有一个为ture时
|
|
|
- if (ok || ng){
|
|
|
- if (ok){
|
|
|
- Boolean sendret = DataUtil.sendQuality(MesClient.product_sn.getText(),"OK",user20);
|
|
|
- if(!sendret){
|
|
|
- JOptionPane.showMessageDialog(mesClientFrame,"消息发送失败,请重试","提示窗口", JOptionPane.INFORMATION_MESSAGE);
|
|
|
- return;
|
|
|
- }
|
|
|
- }else {
|
|
|
- Boolean sendret = DataUtil.sendQuality(MesClient.product_sn.getText(),"NG",user20);
|
|
|
- if(!sendret){
|
|
|
- JOptionPane.showMessageDialog(mesClientFrame,"消息发送失败,请重试","提示窗口", JOptionPane.INFORMATION_MESSAGE);
|
|
|
- return;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- } else if (MesClient.index == 4) {
|
|
|
- boolean ok = ModbusUtils.isQualityOk(modbusTcp);
|
|
|
- boolean ng = ModbusUtils.isQualityNG(modbusTcp);
|
|
|
- work_status = 0;
|
|
|
- check_quality_result = false;
|
|
|
- MesClient.finish_ok_bt.setEnabled(false);
|
|
|
- MesClient.finish_ng_bt.setEnabled(false);
|
|
|
- product_sn.setText("");
|
|
|
- // 当两个都为false时
|
|
|
- if (!ok && !ng){
|
|
|
- ModbusUtils.rechargeYjgetDate(modbusTcp);
|
|
|
- MesClient.index = 0;
|
|
|
- }
|
|
|
- }
|
|
|
+ if(!MesClient.sessionid.isEmpty()){
|
|
|
+
|
|
|
+ //请求扫码
|
|
|
+ Boolean retFeeding = ModbusUtils.isReadable(modbusTcp);
|
|
|
+ feedinglabel.setIcon(retFeeding?imageGreen:imageGray);
|
|
|
+
|
|
|
+ // 读取MES允许上料信号
|
|
|
+ Boolean retFeedingAllow = ModbusUtils.isAllown(modbusTcp);
|
|
|
+ feedingmeslabel.setIcon(retFeedingAllow?imageGreen:imageGray);
|
|
|
+
|
|
|
+ boolean ok = ModbusUtils.isQualityOk(modbusTcp);
|
|
|
+ boolean ng = ModbusUtils.isQualityNG(modbusTcp);
|
|
|
+ // 读取下料信号
|
|
|
+ Boolean retBlanking = ok || ng;
|
|
|
+ runlabel.setIcon(retBlanking?imageGreen:imageGray);
|
|
|
+
|
|
|
+ // 读取MES允许下料信号
|
|
|
+ Boolean retAllowBlanking = ModbusUtils.isGetDate(modbusTcp);
|
|
|
+ blankingmeslabel.setIcon(retAllowBlanking?imageGreen:imageGray);
|
|
|
+
|
|
|
+
|
|
|
+ if (MesClient.index == 0){
|
|
|
+ // 等待允许扫码信号
|
|
|
+ // 提示栏显示等待扫码
|
|
|
+
|
|
|
+ MesClient.setMenuStatus("等待扫码",0);
|
|
|
+ String sn = change(modbusTcp.readString(100,120).toString());
|
|
|
+ System.out.println("已读二维码1:"+sn);
|
|
|
+ System.out.println("是否允许读码"+ModbusUtils.isReadable(modbusTcp));
|
|
|
+// String sn2 = product_sn.getText().trim();
|
|
|
+ if(!lastSn.equals(sn) && !sn.isEmpty()){
|
|
|
+ product_sn.setText(sn);
|
|
|
+ lastSn = sn;
|
|
|
+ MesClient.index = 1;
|
|
|
+ }
|
|
|
+ }else if (MesClient.index == 1){
|
|
|
+ if (retAllowBlanking){
|
|
|
+ ModbusUtils.rechargeYjgetDate(modbusTcp);
|
|
|
+ }
|
|
|
+ System.out.println("已读二维码2:"+product_sn.getText());
|
|
|
+ // 查询工件质量
|
|
|
+ Boolean sendret = DataUtil.checkQuality(nettyClient,MesClient.product_sn.getText(),user20);
|
|
|
+ if(!sendret){
|
|
|
+ JOptionPane.showMessageDialog(mesClientFrame,"消息发送失败,请重试","提示窗口", JOptionPane.INFORMATION_MESSAGE);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ } else if (MesClient.index == 2) {
|
|
|
+ if(ModbusUtils.isAllown(modbusTcp)){
|
|
|
+ MesClient.index = 3;
|
|
|
+ }
|
|
|
+ }else if (MesClient.index == 3) {
|
|
|
+ // 提示栏显示等待加工
|
|
|
+ MesClient.setMenuStatus("加工中",0);
|
|
|
+ //等待产品是否合格
|
|
|
+ //当有一个为ture时
|
|
|
+ if (ok || ng){
|
|
|
+ if (ok){
|
|
|
+ Boolean sendret = DataUtil.sendQuality(MesClient.product_sn.getText(),"OK",user20);
|
|
|
+ if(!sendret){
|
|
|
+ JOptionPane.showMessageDialog(mesClientFrame,"消息发送失败,请重试","提示窗口", JOptionPane.INFORMATION_MESSAGE);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ Boolean sendret = DataUtil.sendQuality(MesClient.product_sn.getText(),"NG",user20);
|
|
|
+ if(!sendret){
|
|
|
+ JOptionPane.showMessageDialog(mesClientFrame,"消息发送失败,请重试","提示窗口", JOptionPane.INFORMATION_MESSAGE);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if (MesClient.index == 4) {
|
|
|
+ work_status = 0;
|
|
|
+ check_quality_result = false;
|
|
|
+ MesClient.finish_ok_bt.setEnabled(false);
|
|
|
+ MesClient.finish_ng_bt.setEnabled(false);
|
|
|
+ product_sn.setText("");
|
|
|
+ // 当两个都为false时
|
|
|
+ if (!ok && !ng){
|
|
|
+ ModbusUtils.rechargeYjgetDate(modbusTcp);
|
|
|
+ MesClient.index = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
// 1秒执行一次循环
|
|
|
}, 1000, 1000);
|