|
|
@@ -1,12 +1,14 @@
|
|
|
package com.mes.ui;
|
|
|
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
+import com.github.xingshuangs.iot.protocol.modbus.service.ModbusTcp;
|
|
|
import com.mes.component.MesRadio;
|
|
|
import com.mes.component.MesWebView;
|
|
|
import com.mes.netty.NettyClient;
|
|
|
import com.mes.util.DateLocalUtils;
|
|
|
import com.mes.util.HttpUtils;
|
|
|
import com.mes.util.JdbcUtils;
|
|
|
+import com.mes.util.ModbusUtils;
|
|
|
import javafx.embed.swing.JFXPanel;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
@@ -97,8 +99,10 @@ public class MesClient extends JFrame {
|
|
|
public static MesWebView jfxPanel3 = null;
|
|
|
public static MesRadio mesRadioHj;
|
|
|
|
|
|
- public static JLabel timer_label; // 倒计时显示
|
|
|
- public static String time = "";
|
|
|
+ // 流程步骤
|
|
|
+ public static int index = 0;
|
|
|
+
|
|
|
+ public static ModbusTcp modbusTcp = new ModbusTcp("192.168.1.20");
|
|
|
|
|
|
public static JTable table;
|
|
|
public static Object[] columnNames = { "物料名称", "绑定批次", "剩余次数", "操作" };
|
|
|
@@ -123,7 +127,8 @@ public class MesClient extends JFrame {
|
|
|
welcomeWin.setVisible(true);
|
|
|
|
|
|
getMaterailData();
|
|
|
- startTimeTimer();
|
|
|
+
|
|
|
+ process();
|
|
|
|
|
|
// startUpdateQualityTimer(); // 开启提交结果的定时任务
|
|
|
|
|
|
@@ -245,32 +250,6 @@ public class MesClient extends JFrame {
|
|
|
// 时间显示定时任务
|
|
|
public static java.util.Timer timeTimer;
|
|
|
|
|
|
- public static void startTimeTimer() {
|
|
|
- if(timeTimer!=null) {
|
|
|
- timeTimer.cancel();
|
|
|
- }
|
|
|
- timeTimer = new Timer();
|
|
|
- timeTimer.schedule(new TimerTask() {
|
|
|
- @Override
|
|
|
- public void run() {
|
|
|
- if (!"".equals(time)){
|
|
|
- // 获取当前时间
|
|
|
- String nowTime = DateLocalUtils.getCurrentTime();
|
|
|
- // 当前时间减去完成时间得出超过的分秒
|
|
|
- try {
|
|
|
- long time = DateLocalUtils.DATA_FORMAT.parse(nowTime).getTime() - DateLocalUtils.DATA_FORMAT.parse(MesClient.time).getTime();
|
|
|
- long minutes = time / 1000 / 60;
|
|
|
- long seconds = time / 1000 % 60;
|
|
|
- String wokeTime = minutes + ":" + seconds;
|
|
|
- // 设置时间显示
|
|
|
- timer_label.setText(wokeTime);
|
|
|
- } catch (ParseException e) {
|
|
|
- throw new RuntimeException(e);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }, 100,1000);
|
|
|
- }
|
|
|
|
|
|
//设置tcp连接状态显示
|
|
|
public static void setTcpStatus() {
|
|
|
@@ -293,10 +272,9 @@ public class MesClient extends JFrame {
|
|
|
MesClient.finish_ok_bt.setEnabled(false);
|
|
|
MesClient.finish_ng_bt.setEnabled(false);
|
|
|
product_sn.setText("");
|
|
|
- time = "";
|
|
|
MesClient.f_scan_data_bt_1.setEnabled(true);
|
|
|
MesClient.setMenuStatus("请扫工件码",0);
|
|
|
-
|
|
|
+ MesClient.index = 0;
|
|
|
updateMaterailData();
|
|
|
// shiftUserCheck();
|
|
|
}
|
|
|
@@ -574,7 +552,7 @@ public class MesClient extends JFrame {
|
|
|
f_scan_data_bt_1.setIcon(new ImageIcon(MesClient.class.getResource("/bg/scan_barcode.png")));
|
|
|
f_scan_data_bt_1.setFont(new Font("微软雅黑", Font.PLAIN, 32));
|
|
|
f_scan_data_bt_1.setBounds(693, 70, 198, 70);
|
|
|
- indexPanelA.add(f_scan_data_bt_1);
|
|
|
+// indexPanelA.add(f_scan_data_bt_1);
|
|
|
|
|
|
|
|
|
|
|
|
@@ -584,33 +562,11 @@ public class MesClient extends JFrame {
|
|
|
public void actionPerformed(ActionEvent e) {
|
|
|
if(work_status == 1 && check_quality_result){
|
|
|
|
|
|
- String qret = "";
|
|
|
- String nowTime = DateLocalUtils.getCurrentTime();
|
|
|
- try {
|
|
|
- long time = DateLocalUtils.DATA_FORMAT.parse(nowTime).getTime() - DateLocalUtils.DATA_FORMAT.parse(MesClient.time).getTime();
|
|
|
- System.out.println("时间差:" + time);
|
|
|
- long minutes = time / 1000 / 60;
|
|
|
- long seconds = time / 1000 % 60;
|
|
|
- String wokeTime = minutes + ":" + seconds;
|
|
|
- qret = wokeTime;
|
|
|
- System.out.println("时间差:" + wokeTime);
|
|
|
- // 判断时间是否在5到7分钟之内
|
|
|
- if (time<5*60*1000){
|
|
|
- MesClient.setMenuStatus("时长过短",-1);
|
|
|
- }
|
|
|
- if(time > 7*60*1000){
|
|
|
- MesClient.setMenuStatus("已超时",-1);
|
|
|
- }
|
|
|
- } catch (ParseException ex) {
|
|
|
- throw new RuntimeException(ex);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
String sn = getBarcode(product_sn.getText());
|
|
|
getUser();
|
|
|
|
|
|
|
|
|
- Boolean result = DataUtil.sendQualityByTime(sn,qret,user20);
|
|
|
+ Boolean result = DataUtil.sendQuality(sn,"OK",user20);
|
|
|
if(result) {
|
|
|
MesClient.resetScanA();
|
|
|
MesClient.setMenuStatus("结果提交成功,请扫下一件", 0);
|
|
|
@@ -637,7 +593,7 @@ public class MesClient extends JFrame {
|
|
|
String sn = getBarcode(product_sn.getText());
|
|
|
getUser();
|
|
|
String qret = "NG";
|
|
|
- Boolean result = DataUtil.sendQualityByTime(sn,qret,user20);
|
|
|
+ Boolean result = DataUtil.sendQuality(sn,qret,user20);
|
|
|
if(result) {
|
|
|
MesClient.resetScanA();
|
|
|
MesClient.setMenuStatus("结果提交成功,请扫下一件", 0);
|
|
|
@@ -655,17 +611,9 @@ public class MesClient extends JFrame {
|
|
|
finish_ng_bt.setEnabled(false);
|
|
|
indexPanelA.add(finish_ng_bt);
|
|
|
|
|
|
- timer_label = new JLabel("00:00:00");
|
|
|
- timer_label.setFont(new Font("微软雅黑", Font.PLAIN, 35));
|
|
|
- timer_label.setHorizontalAlignment(SwingConstants.CENTER);
|
|
|
- timer_label.setBounds(411, 220, 240, 60);
|
|
|
- indexPanelA.add(timer_label);
|
|
|
|
|
|
- JLabel lblNewLabel = new JLabel("计时");
|
|
|
- lblNewLabel.setFont(new Font("微软雅黑", Font.PLAIN, 35));
|
|
|
- lblNewLabel.setHorizontalAlignment(SwingConstants.CENTER);
|
|
|
- lblNewLabel.setBounds(306, 220, 156, 60);
|
|
|
- indexPanelA.add(lblNewLabel);
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
tabbedPane.addTab("工作面板", new ImageIcon(MesClient.class.getResource("/bg/a_side.png")), indexScrollPaneA, null);
|
|
|
@@ -846,4 +794,80 @@ public class MesClient extends JFrame {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ // 流程
|
|
|
+ public static void process() {
|
|
|
+ new Timer().schedule(new TimerTask() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ if (MesClient.index == 0){
|
|
|
+ // 等待允许扫码信号
|
|
|
+ // 提示栏显示等待扫码
|
|
|
+ if (ModbusUtils.isGetDate(modbusTcp)){
|
|
|
+ ModbusUtils.rechargeYjgetDate(modbusTcp);
|
|
|
+ }
|
|
|
+ MesClient.setMenuStatus("等待扫码",0);
|
|
|
+ if (ModbusUtils.isReadable(modbusTcp)){
|
|
|
+ // 允许扫码,进入下一阶段
|
|
|
+ String sn = 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(),"",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);
|
|
|
+ // 当两个都为false时
|
|
|
+ if (!ok && !ng){
|
|
|
+ ModbusUtils.rechargeYjgetDate(modbusTcp);
|
|
|
+ MesClient.index = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 1秒执行一次循环
|
|
|
+ }, 1000, 1000);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 传入字符串,字符串两个一组,换位置
|
|
|
+ public static String change(String str){
|
|
|
+ StringBuffer sb = new StringBuffer();
|
|
|
+ for(int i = 0; i < str.length(); i += 2){
|
|
|
+ sb.append(str.charAt(i + 1));
|
|
|
+ sb.append(str.charAt(i));
|
|
|
+ }
|
|
|
+ return sb.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|