sunxianglong 5 дней назад
Родитель
Сommit
823eba7998

+ 1 - 0
.classpath

@@ -21,4 +21,5 @@
 	<classpathentry kind="lib" path="lib/sqlite-jdbc-3.36.0.3.jar"/>
 	<classpathentry kind="lib" path="lib/commons-codec-1.15.jar"/>
 	<classpathentry kind="lib" path="lib/fastjson2-2.0.16.jar"/>
+	<classpathentry kind="lib" path="lib/jSerialComm-2.6.2.jar"/>
 </classpath>

+ 1 - 1
.project

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <projectDescription>
-	<name>mesclient-sd</name>
+	<name>MesOP260</name>
 	<comment></comment>
 	<projects>
 	</projects>

BIN
lib/jSerialComm-2.6.2.jar


+ 0 - 148
src/com/mes/netty/TCPClient.java

@@ -1,148 +0,0 @@
-package com.mes.netty;
-
-import com.mes.ui.MesClient;
-
-import java.io.*;
-import java.net.*;
-import java.util.concurrent.*;
-
-public class TCPClient {
-    public String serverIP;
-    public int serverPort;
-    public Socket socket;
-    public PrintWriter out;
-    public BufferedReader in;
-
-    public TCPClient(String serverIP, int serverPort) {
-        this.serverIP = serverIP;
-        this.serverPort = serverPort;
-    }
-
-    public void connect() throws Exception {
-            try {
-                // 创建Socket对象并连接到服务器
-                socket = new Socket(serverIP, serverPort);
-                // 连接成功后初始化输入输出流
-                OutputStream outputStream = socket.getOutputStream();
-                out = new PrintWriter(outputStream, true);
-
-                InputStream inputStream = socket.getInputStream();
-                in = new BufferedReader(new InputStreamReader(inputStream));
-                MesClient.setMenuStatus("扫码枪连接成功",0);
-
-                System.out.println("扫码枪连接成功");
-            } catch (Exception e) {
-                // 连接失败,重新连接
-                MesClient.setMenuStatus("扫码枪连接异常,请重试",1);
-                MesClient.tcpClient.close();
-                throw new Exception(e);
-            }
-    }
-
-//    public void sendCommand(String command)  {
-//        try {
-//            out.println(command);
-//        } catch (Exception e) {
-//            MesClient.scan_tcp_connect_flag=false;
-//        }
-//    }
-    //LON==扫码   LOFF==停止扫码
-    public void sendCommand(String command)  {
-            out.println(command);
-    }
-
-    private ExecutorService executor = Executors.newSingleThreadExecutor();
-//    public String receiveResponse() {
-//
-//        try {
-//            MesClient.tcpClient.sendCommand("LON\r\n");
-//            Future<String> future = executor.submit(() -> {
-//                try {
-//                    String response = null;
-//                    long startTime = System.currentTimeMillis();
-//                    while ((response = in.readLine()) == null) {
-//                        // 检查是否超时
-//                        long elapsedTime = System.currentTimeMillis() - startTime;
-//                        if (elapsedTime >= 10000) { // 10秒超时
-//                            throw new TimeoutException("Read operation timed out");
-//                        }
-//                    }
-//                    return response;
-//                } catch (TimeoutException e) {
-//                    MesClient.scan_tcp_connect_flag = false;
-//                    //发送停止指令
-//                    MesClient.tcpClient.sendCommand("LOFF\r\n");
-//                    MesClient.status_menu.setText("扫码枪识别超时,请重试");
-//                    e.printStackTrace();
-//                    return null;
-//                }catch (Exception e) {
-//                    MesClient.scan_tcp_connect_flag = false;
-//                    //发送停止指令
-//                    MesClient.tcpClient.sendCommand("LOFF\r\n");
-//                    MesClient.status_menu.setText("扫码枪识别超时,请重试");
-//                    e.printStackTrace();
-//                    return null;
-//                }
-//            });
-//
-//            return future.get();
-//        } catch (Exception  e) {
-//            MesClient.scan_tcp_connect_flag = false;
-//            MesClient.tcpClient.sendCommand("LOFF\r\n");
-//            MesClient.status_menu.setText("扫码枪连接异常,请重试");
-//            e.printStackTrace();
-//            return null;
-//        }
-//    }
-
-    public String receiveResponse() {
-        try {
-            MesClient.tcpClient.sendCommand("LON\r\n");
-
-            // 创建一个Future来读取行
-            Future<String> future = executor.submit(() -> {
-                try {
-                    return in.readLine();
-                } catch (IOException e) {
-                    throw new RuntimeException(e);
-                }
-            });
-
-            try {
-                // 尝试在10秒内获取结果
-                return future.get(15, TimeUnit.SECONDS);
-            } catch (TimeoutException e) {
-                // 处理超时情况future.cancel(true);
-                throw new TimeoutException("Read operation timed out");
-            }
-        } catch (TimeoutException e) {
-            MesClient.tcpClient.sendCommand("LOFF\r\n");
-            MesClient.setMenuStatus("扫码枪识别超时,请点击扫码或刷新后重试",1);
-            e.printStackTrace();
-            return null;
-        } catch (Exception e) {
-            MesClient.tcpClient.sendCommand("LOFF\r\n");
-            MesClient.setMenuStatus("扫码枪连接异常,请重试",1);
-            if (socket != null && !socket.isClosed()) {
-                try {
-                    socket.close();
-                } catch (IOException ioException) {
-                    ioException.printStackTrace();
-                }
-            }
-            e.printStackTrace();
-            return null;
-        }
-    }
-    public void close() {
-        try {
-            // 关闭Socket连接
-            if (socket != null) {
-                socket.close();
-            }
-        } catch (IOException e) {
-            e.printStackTrace();
-        }
-    }
-
-}

+ 26 - 0
src/com/mes/ui/DataUtil.java

@@ -214,6 +214,32 @@ public class DataUtil {
         }
     }
 
+    public static JSONObject getCheckResult() {
+        try{
+            String enconding = "UTF-8";
+            InputStream is = ClassLoader.getSystemResourceAsStream("config/config.properties");
+            Properties pro = new Properties();
+            BufferedReader br = new BufferedReader(new InputStreamReader(is, enconding));
+            pro.load(br);
+            String mes_server_ip = pro.getProperty("mes.server_ip");
+            String oprno = pro.getProperty("mes.gw").trim();
+            String lineSn = pro.getProperty("mes.line_sn").trim();
+            String url = "http://"+mes_server_ip+":8980/js/a/mes/mesProcessCheckRecord/check";
+            String params = "__ajax=json&oprno="+oprno+"&lineSn="+lineSn;
+            System.out.println("params="+params);
+            String result = doPost(url,params);
+            System.out.println("result="+result);
+
+            if(result.equalsIgnoreCase("false")) {
+                return null;
+            }else {
+                return JSONObject.parseObject(result);
+            }
+        }catch (Exception e){
+            return null;
+        }
+    }
+
     public static String doPost(String httpUrl, String param) {
         HttpURLConnection connection = null;
         InputStream is = null;

+ 1 - 8
src/com/mes/ui/LoginFarme.java

@@ -10,7 +10,6 @@ import javax.swing.*;
 import java.awt.*;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
-import java.time.LocalDateTime;
 
 public class LoginFarme extends JFrame {
     //登录模块组件
@@ -142,8 +141,7 @@ public class LoginFarme extends JFrame {
                 }
             }
         }else {
-            MesClient.setMenuStatus("扫码内容错误",0);
-//            JOptionPane.showMessageDialog(MesClient.mesClientFrame,"扫码内容错误","提示窗口", JOptionPane.INFORMATION_MESSAGE);
+            JOptionPane.showMessageDialog(MesClient.mesClientFrame,"扫码内容错误","提示窗口", JOptionPane.INFORMATION_MESSAGE);
             return;
         }
     }
@@ -170,11 +168,6 @@ public class LoginFarme extends JFrame {
                     JOptionPane.showMessageDialog(MesClient.mesClientFrame,"您无权登录该工位","提示窗口", JOptionPane.INFORMATION_MESSAGE);
                     return;
                 }else if(MesClient.mes_auth==1||MesClient.mes_auth==2) {
-
-                    // 获取等于所处时间-当前小时
-                    LocalDateTime now = LocalDateTime.now();
-                    MesClient.userLoginHours = now.getHour();
-
                     //初始化tcp连接,发送同步报文
                     MesClient.initTcpConnection();
                     //启动timer心跳包

+ 165 - 354
src/com/mes/ui/MesClient.java

@@ -1,15 +1,11 @@
 package com.mes.ui;
 
 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.fazecast.jSerialComm.SerialPort;
 import com.mes.component.MesRadio;
 import com.mes.component.MesWebView;
-import com.mes.component.MyDialog;
 import com.mes.netty.NettyClient;
-import com.mes.netty.TCPClient;
 import com.mes.util.DateLocalUtils;
-import com.mes.util.HttpUtils;
 import com.mes.util.JdbcUtils;
 import javafx.embed.swing.JFXPanel;
 
@@ -26,15 +22,10 @@ import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
-import java.time.LocalDateTime;
-import java.util.HashMap;
 import java.util.List;
 import java.util.Properties;
 import java.util.Timer;
 import java.util.TimerTask;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.TimeUnit;
 
 public class MesClient extends JFrame {
 
@@ -48,8 +39,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 S7PLC s7PLC = new S7PLC(EPlcType.S200_SMART, "192.168.6.40"); //
-    public static TCPClient tcpClient = new TCPClient("192.168.16.143",9004);//扫码枪
+
     //TCP连接
     public static NettyClient nettyClient;
     //TCP连接状态
@@ -76,8 +66,6 @@ public class MesClient extends JFrame {
     public static JButton user_menu;
 
     public static int scan_type = 0;
-    public static int scan_status = 0;//0未扫码  1已扫码
-    public static int scan_mark = 1;//扫码标记 (上料一次智能扫一次码)
     public static JButton finish_ok_bt;
     public static JButton finish_ng_bt;
     public static JTextField product_sn;
@@ -92,27 +80,15 @@ public class MesClient extends JFrame {
     public static JPanel indexPanelC;
     public static MesWebView jfxPanel2 = null;
     public static MesRadio mesRadioHj;
-    public static Timer cjTimer;//机器人交互
-    public static Timer cjTimer2;//获取设备状态
-    public static Boolean shangLiaoOStatus = false;
-    public static Integer tjFlag = 0; // 0=未扫码 1=已扫码,设备未运行 2=设备运行中 3=设备运行结束,结果未提交到MES
-    public static Integer tjStatus = 0; // 0=重置 1=提交失败
-    public static String tcTitle = "提示";
-    public static String tjFlagText2 = "设备运行中";
-
-    public static String tjFlagText3 = "设备运行结束,提交结果中";
-
-    public static String tjFlagText4 = "结果已上传MES,请扫下一件";
-
-    public static String tjFlagText5 = "已扫码,等待设备运行";
 
-    public static String tjFlagTextErr = "结果上传MES失败,请重试";
-
-    // 添加绑定物料窗口
     public static JTable table;
     public static Object[] columnNames = { "物料名称", "绑定批次", "剩余次数", "操作" };
     public static Object[][] rowData = null;
 
+    public static Boolean checkState = false; // 点检状态 false=未点检 true=已点检
+
+    public static SerialPort serialPort; // 串口对象
+
     public static void main(String[] args) {
         EventQueue.invokeLater(new Runnable() {
             @Override
@@ -129,10 +105,13 @@ public class MesClient extends JFrame {
 
                     welcomeWin = new LoginFarme();
                     welcomeWin.setVisible(true);
+
                     getMaterailData();
 
-                    getPlcParam();
-                    getDeviceStaus();
+                    serialPort = ModbusRtu.connect();
+
+                    startJsTimer();
+
                 }catch (Exception e){
                     e.printStackTrace();
                 }
@@ -173,222 +152,91 @@ public class MesClient extends JFrame {
 
                 DataUtil.synrTcp(nettyClient,mes_gw);
             }
-
         } catch (Exception e) {
             // TODO Auto-generated catch block
             e.printStackTrace();
         }
     }
 
-    public static void getPlcParam() {
-        if(cjTimer!=null) {
-            cjTimer.cancel();
+    //启动心跳包程序
+    public static java.util.Timer heartBeatTimer;
+    public static java.util.Timer heartBeatIconTimer;
+    public static boolean iconREDFlag = true;
+    public static void startHeartBeatTimer() {
+        if(heartBeatTimer!=null) {
+            heartBeatTimer.cancel();
         }
-        cjTimer = new Timer();
-        cjTimer.schedule(new TimerTask() {
+        heartBeatTimer = new java.util.Timer();
+        heartBeatTimer.schedule(new TimerTask() {
             public void run() {
+                if(nettyClient!=null&&tcp_connect_flag) {
+                    //System.out.println("发送心跳报文");
+                    DataUtil.heartBeat(nettyClient,mes_gw);
 
-
-                try {
-
-                    if (tcp_connect_flag) {
-                        if (tcpClient.socket != null && tcpClient.socket.isConnected() && !tcpClient.socket.isClosed()) {
-
-                            if (!shangLiaoOStatus) {
-                                MesClient.setMenuStatus("MES等待上料信号", 0);
-                                shangLiaoOStatus = S7Util.getShangLiaoOk(s7PLC);
-                                if (shangLiaoOStatus) {
-                                    MesClient.setMenuStatus("MES收到上料信号,等待扫码", 0);
-                                }
-                            }
-                            //上料成功并且未扫码进行扫码
-                            if (shangLiaoOStatus) {
-                                scan_type = 1;
-                                if (scan_status == 0 && scan_mark == 1) {
-                                    MesClient.setMenuStatus("扫码枪正在扫码,请勿操作!", 0);
-                                    //扫码中不让点击扫码避免重复扫码线程卡死
-                                    MesClient.f_scan_data_bt_1.setEnabled(false);
-                                    String scanBarcode = MesClient.tcpClient.receiveResponse();
-                                    MesClient.f_scan_data_bt_1.setEnabled(true);
-
-                                    scan_mark = 0;//无论扫码是否成功,代表已经扫过一次  扫码次数清零
-
-                                    if (scanBarcode == null || scanBarcode.equals("")) {
-                                        S7Util.sendStartMessage(MesClient.s7PLC, false);
-                                    } else {
-                                        if (!product_sn.getText().equals(scanBarcode)) {
-                                            scan_status = 1;
-                                            System.out.println(scanBarcode);
-                                            //补充到工件码输入框,发送mes进行质量检测
-                                            productSnSetValue(scanBarcode);
-                                        }
-                                    }
-
-                                }
-
-                            }
-                            //设备检测合格之后---》提交结果到MES
-                            checkToMes();
-
-                        } else {
-                            tcpClient.connect();
-                        }
-                    }
-                } catch (Exception e) {
-                    e.printStackTrace();
+                    heart_beat_menu.setText(DateLocalUtils.getCurrentTime());
                 }
-
             }
-        }, 2000,2000);
-    }
-
-    //获取到扫码枪工件码,则输入框赋值工件码
-    public static void productSnSetValue(String scanBarcode) {
-        try {
-            if (scanBarcode != null && !scanBarcode.equals("")) {
-                //获取用户
-                getUser();
-                //获取扫码内容36位
-                String barcode36 = getBarcode(scanBarcode);//处理36为码
-                //工位号
-                String gw = "";
-                switch (scan_type) {
-                    case 1:
-                        product_sn.setText(scanBarcode);
-                        break;
-                }
-                //刷新界面
-                mesClientFrame.repaint();
-
-                if (!tcp_connect_flag) {
-                    MesClient.setMenuStatus("设备未连接Mes服务器",1);
-//                    JOptionPane.showMessageDialog(mesClientFrame, "设备未连接Mes服务器", "提示窗口", JOptionPane.INFORMATION_MESSAGE);
-                    return;
-                }
+        }, 100,mes_heart_beat_cycle*1000);
 
-                // 查询工件质量
-                Boolean sendret = DataUtil.checkQuality(nettyClient, barcode36, user20);
-                if (!sendret) {
-                    MesClient.setMenuStatus("消息发送失败,请重试",1);
-//                    JOptionPane.showMessageDialog(mesClientFrame, "消息发送失败,请重试", "提示窗口", JOptionPane.INFORMATION_MESSAGE);
-                    return;
-                }
-            }
-            else {
-                MesClient.setMenuStatus("请扫工件码",1);
-//                JOptionPane.showMessageDialog(mesClientFrame,"请扫工件码","提示窗口", JOptionPane.INFORMATION_MESSAGE);
-            }
-        } catch (HeadlessException e) {
-            e.printStackTrace();
+        //心跳显示图标
+        if(heartBeatIconTimer!=null) {
+            heartBeatIconTimer.cancel();
         }
-    }
-    public static void checkToMes() {
-        try {
-            if (work_status == 1) {
-                if(!S7Util.getShangLiaoOk(s7PLC)){
-                    //重置上料mes反馈
-                    S7Util.sendStartMessage(MesClient.s7PLC,false);
-                }
-                if (tjFlag == 1) {//已扫码,设备未运行--检测设备启动指令
-                    boolean startMessage = S7Util.getstartMessage(s7PLC);
-                    if (startMessage) {//设备正常启动
-
-                        tjFlag = 2;
-                        MesClient.status_menu.setText(MesClient.tjFlagText2);
-                    }
-                }
-                if (tjFlag == 2) {//运行中 --检测设备停止指令
-
-                    boolean stopMessage = S7Util.getstopMessage(s7PLC);
-                    if (stopMessage) {//设备正常停止
-
-                        tjFlag = 3;
-                        MesClient.status_menu.setText(MesClient.tjFlagText3);
-
-                        MesClient.finish_ok_bt.setEnabled(true);
-                        MesClient.finish_ng_bt.setEnabled(true);
-
-                        S7Util.sendEndMessage(s7PLC,true);
-//                        if (tjStatus == 0) {
-//                            //提交结果到MES
-//                            Boolean ret = DataUtil.sendQuality(MesClient.nettyClient, MesClient.product_sn.getText(), "OK", MesClient.user20);
-//                            if (!ret) {
-//                                MesClient.tjStatus = 1; // 未提交成功
-//                                new MyDialog(MesClient.mesClientFrame, MesClient.tcTitle, MesClient.tjFlagTextErr);
-//                            }
-//                        }
-                    }
-                }
-                if (tjFlag == 3){
-                    boolean getstoped = S7Util.getstopMessage(s7PLC);
-                    if (!getstoped){
-                        S7Util.sendEndMessage(s7PLC,false);
-                        //提交结果值MES
-                        if (tjStatus == 0) {
-                            //提交结果到MES
-                            Boolean ret = DataUtil.sendQuality(MesClient.nettyClient, MesClient.product_sn.getText(), "OK", MesClient.user20);
-                            if (!ret) {
-                                MesClient.tjStatus = 1; // 未提交成功
-                                new MyDialog(MesClient.mesClientFrame, MesClient.tcTitle, MesClient.tjFlagTextErr);
-                            }
-                        }
+        heartBeatIconTimer = new Timer();
+        heartBeatIconTimer.schedule(new TimerTask() {
+            public void run() {
+                if(tcp_connect_flag) {
+                    if(iconREDFlag) {
+                        heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/grey_dot.png")));
+                        iconREDFlag = false;
+                    }else {
+                        heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/green_dot.png")));
+                        iconREDFlag = true;
                     }
-                }
-            }
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-    }
+                    heart_beat_menu.setText(DateLocalUtils.getCurrentTime());
+                    heart_beat_menu.repaint();
+                }else {
+                    heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/grey_dot.png")));
+                    heart_beat_menu.setText(DateLocalUtils.getCurrentTime());
+                    heart_beat_menu.repaint();
 
+                    //若未连接则尝试连接
+                    if(nettyClient!=null&&!tcp_connect_flag){
+                        System.out.println("TCP已断开");
+                        //TCP重新同步连接
+                        if(!connect_request_flag) {
+                            //System.out.println("TCP重新同步连接");
+                            //设置TCP请求状态,只重新同步连接一次
+                            connect_request_flag = true;
 
-    public static HashMap<String, String> hashMapParam = new HashMap<>();
-    public static void getDeviceStaus() {
-        if(cjTimer2!=null) {
-            cjTimer2.cancel();
-        }
-        cjTimer2 = new Timer();
-        cjTimer2.schedule(new TimerTask() {
-            public void run() {
+                            DataUtil.synrTcp(nettyClient,mes_gw);
+                        }
 
-                try {
-                    boolean status = S7Util.getStatus(s7PLC);
-                    hashMapParam.put("deviceSn", mes_line_sn + mes_gw);
-                    hashMapParam.put("sn", product_sn.getText());
-                    if (status) {//正常
-                        hashMapParam.put("state", "1");
-                    } else {//故障
-                        hashMapParam.put("state", "3");
                     }
-                    HttpUtils.sendPostRequestJson("http://" + MesClient.mes_server_ip + ":8980/js/a/mes/mesDeviceState/add", JSONObject.toJSONString(hashMapParam));
-                } catch (Exception e) {
-                    e.printStackTrace();
-                }finally {
-                    hashMapParam.clear();
                 }
-
             }
-        }, 10000,10000);
+        }, 100,mes_heart_icon_cycle*1000);
     }
 
-    //启动心跳包程序
-    public static java.util.Timer heartBeatTimer;
-    public static java.util.Timer heartBeatIconTimer;
-    public static boolean iconREDFlag = true;
-    public static void startHeartBeatTimer() {
-        if(heartBeatTimer!=null) {
-            heartBeatTimer.cancel();
+    public static java.util.Timer jsTimer;
+    public static Integer jsCount = 0;
+    public static Integer jsFlag = 0; // 0=未关闭 1=已关闭
+    public static void startJsTimer() { // 定时关闭继电器
+        if(jsTimer!=null) {
+            jsTimer.cancel();
         }
-        heartBeatTimer = new java.util.Timer();
-        heartBeatTimer.schedule(new TimerTask() {
+        jsTimer = new java.util.Timer();
+        jsTimer.schedule(new TimerTask() {
             public void run() {
-                if(nettyClient!=null&&tcp_connect_flag) {
-                    //System.out.println("发送心跳报文");
-                    DataUtil.heartBeat(nettyClient,mes_gw);
-
-                    heart_beat_menu.setText(DateLocalUtils.getCurrentTime());
+                if(work_status == 1) {
+                    jsCount++;
+                    if(jsCount > 2*60 && jsFlag == 0){
+                        ModbusRtu.closeDevice(serialPort);
+                        jsFlag = 1;
+                    }
                 }
             }
-        }, 100,mes_heart_beat_cycle*1000);
+        }, 100,1000);
 
         //心跳显示图标
         if(heartBeatIconTimer!=null) {
@@ -448,12 +296,7 @@ public class MesClient extends JFrame {
     }
 
     public static void resetScanA() {
-        scan_mark=1;
-        shangLiaoOStatus=false;
-        scan_status=0;
         work_status = 0;
-        tjFlag = 0;
-        tjStatus = 0; //恢复提交状态
         check_quality_result = false;
 //		MesClient.start_work_bt.setVisible(false);
 //        MesClient.finish_ng_bt.setVisible(false);
@@ -464,43 +307,23 @@ public class MesClient extends JFrame {
 
         MesClient.f_scan_data_bt_1.setEnabled(true);
 //		DataUtil.stopWork(sessionid);
-        MesClient.setMenuStatus("MES等待上料信号",0);
-
-        S7Util.sendStartMessage(s7PLC,false);
-        S7Util.sendEndMessage(s7PLC,false);
+        MesClient.status_menu.setText("请扫工件码");
 //		product_result_text.setText("");
 //		work_status_text.setText("");
-        shiftUserCheck();
+//        MesClient.setMenuStatus("上件牙套数据个数不符合要求",-1);
+
+        MesClient.checkState = false;
+        MesClient.jsFlag = 0;
+        MesClient.jsCount = 0;
+//        MesClient.formatDeviceState();
+        ModbusRtu.closeDevice(serialPort);
+        updateMaterailData();
     }
 
-    public static int userLoginHours;//用户登录所处小时
-    //换班用户信息检查
-    private static  void  shiftUserCheck() {
-        LocalDateTime now = LocalDateTime.now();
-        // 判断时间范围
-        if (userLoginHours >= 8 && userLoginHours < 20) {
+    public static void resetScanB() {
 
-            int hour = now.getHour();
-            if (hour >= 20 || hour < 8) {
-                logoff();
-            }
-        } else {
-            int hour = now.getHour();
-            if (hour >= 8 && hour < 20) {
-                logoff();
-            }
-        }
     }
 
-
-    public static void setMenuStatus(String msg,int error){
-        if(error == 0){
-            MesClient.status_menu.setForeground(Color.GREEN);
-        }else{
-            MesClient.status_menu.setForeground(Color.RED);
-        }
-        MesClient.status_menu.setText(msg);
-    }
     //获取用户20位
     public static void getUser() {
         user20 = user_menu.getText().toString();
@@ -530,7 +353,6 @@ public class MesClient extends JFrame {
         return barcodeRet;
     }
 
-
     public static void scanBarcode() {
         if(work_status == 1){
             JOptionPane.showMessageDialog(mesClientFrame,"工作中,勿扫码","提示窗口", JOptionPane.INFORMATION_MESSAGE);
@@ -646,61 +468,11 @@ public class MesClient extends JFrame {
             @Override
             public void mousePressed(MouseEvent e) {
                 super.mouseClicked(e);
-                cjTimer=null;
                 resetScanA();
             }
         });
         settingMenu.add(resetTcpMenu_1);
 
-        JMenuItem recoverMenu = new JMenuItem("恢复");
-        recoverMenu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png")));
-        recoverMenu.setFont(new Font("微软雅黑", Font.PLAIN, 20));
-        recoverMenu.addMouseListener(new MouseAdapter() {
-            @Override
-            public void mousePressed(MouseEvent e) {
-                super.mouseClicked(e);
-                cjTimer.cancel();
-
-                resetScanA();
-            }
-        });
-        settingMenu.add(recoverMenu);
-
-        JMenu robot = new JMenu("机器人");
-        //settingMenu.setVisible(false);
-        robot.setIcon(new ImageIcon(MesClient.class.getResource("/bg/menu_setting.png")));
-        robot.setFont(new Font("微软雅黑", Font.PLAIN, 20));
-        menuBar.add(robot);
-
-        JMenuItem xiaLiaoBack = new JMenuItem("下料反馈");
-        xiaLiaoBack.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png")));
-        xiaLiaoBack.setFont(new Font("微软雅黑", Font.PLAIN, 20));
-        xiaLiaoBack.addMouseListener(new MouseAdapter() {
-            @Override
-            public void mousePressed(MouseEvent e) {
-                //下料反馈-true
-                S7Util.sendEndMessage(s7PLC,true);
-                boolean result = S7Util.readEndMessage(s7PLC);
-                if (result){
-                    JOptionPane.showMessageDialog(mesClientFrame,"发送下料反馈成功","提示窗口", JOptionPane.INFORMATION_MESSAGE);
-
-                }else{
-                    JOptionPane.showMessageDialog(mesClientFrame,"发送下料反馈失败","提示窗口", JOptionPane.INFORMATION_MESSAGE);
-                }
-                ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
-
-                // 安排一个延时任务执行并在执行后关闭调度器
-                scheduler.schedule(() -> {
-                    try {
-                        resetScanA();
-                    } finally {
-                        scheduler.shutdown();
-                    }
-                }, 5, TimeUnit.SECONDS);
-            }
-        });
-        robot.add(xiaLiaoBack);
-
         contentPane = new JPanel();
         contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
         setContentPane(contentPane);
@@ -793,11 +565,8 @@ public class MesClient extends JFrame {
         f_scan_data_bt_1 = new JButton("扫码");
         f_scan_data_bt_1.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent e) {
-                scan_mark = 1;
-//                testStaus=true;
-//                scan_type = 1;
-//                product_sn.setText("");
-                //                scanBarcode();
+                scan_type = 1;
+                scanBarcode();
             }
         });
         f_scan_data_bt_1.setIcon(new ImageIcon(MesClient.class.getResource("/bg/scan_barcode.png")));
@@ -824,8 +593,7 @@ public class MesClient extends JFrame {
                     String qret = "OK";
                     Boolean sendret = DataUtil.sendQuality(nettyClient,sn,qret,user20);
                     if(!sendret){
-                        MesClient.setMenuStatus("消息发送失败,请重试",1);
-//                        JOptionPane.showMessageDialog(mesClientFrame,"消息发送失败,请重试","提示窗口", JOptionPane.INFORMATION_MESSAGE);
+                        JOptionPane.showMessageDialog(mesClientFrame,"消息发送失败,请重试","提示窗口", JOptionPane.INFORMATION_MESSAGE);
                         return;
                     }
                 }
@@ -848,8 +616,7 @@ public class MesClient extends JFrame {
                     String qret = "NG";
                     Boolean sendret = DataUtil.sendQuality(nettyClient,sn,qret,user20);
                     if(!sendret){
-                        MesClient.setMenuStatus("消息发送失败,请重试",1);
-//                        JOptionPane.showMessageDialog(mesClientFrame,"消息发送失败,请重试","提示窗口", JOptionPane.INFORMATION_MESSAGE);
+                        JOptionPane.showMessageDialog(mesClientFrame,"消息发送失败,请重试","提示窗口", JOptionPane.INFORMATION_MESSAGE);
                         return;
                     }
                 }
@@ -887,39 +654,58 @@ public class MesClient extends JFrame {
                 int selectedIndex = tabbedPane.getSelectedIndex();
                 System.out.println("selectedIndex:"+selectedIndex);
 
-                if(selectedIndex == 1){
+                if(selectedIndex == 0){
 
                 }
             }
         });
     }
 
-    // 绑定物料批次码
-    public static void scanBatchSn(BindMaterialResp bindMaterialResp) {
-        //弹窗扫工件码
-        String scanBarcodeTitle = "请扫物料:"+bindMaterialResp.getMaterialTitle();
-        String scanBarcode = JOptionPane.showInputDialog(null, scanBarcodeTitle);
-        if(scanBarcode!=null&&!scanBarcode.equalsIgnoreCase("")) {
+    public static void setMenuStatus(String msg,int error){
+        if(error == 0){
+            MesClient.status_menu.setForeground(Color.GREEN);
+        }else{
+            MesClient.status_menu.setForeground(Color.RED);
+        }
+        MesClient.status_menu.setText(msg);
+    }
 
-            JSONObject retObj = DataUtil.saveBindMaterail(scanBarcode,bindMaterialResp.getCraft(),bindMaterialResp.getMaterialId(),bindMaterialResp.getType());
-            if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
-                MesClient.setMenuStatus("扫物料:"+bindMaterialResp.getMaterialTitle()+"成功",0);
-                updateMaterailData();
-            }else{
-                if(retObj.get("result")==null){
-                    MesClient.setMenuStatus("请求失败,请重试",-1);
+    // 格式化设备启动状态
+    public static void formatDeviceState(){
+        try{
+            if(MesClient.checkState){ // 检查物料是否已绑定
+                if(rowData == null){
+                    ModbusRtu.openDevice(serialPort);
                 }else{
-                    if(retObj.get("result").toString().equalsIgnoreCase("false")){
-                        MesClient.setMenuStatus(retObj.getString("message"),-1);
+                    // 判断物料是否可启动
+                    int flag = 0;
+                    int i = 0;
+                    for (Object object:rowData){
+                        Integer times = Integer.valueOf(String.valueOf(rowData[i][2]));
+                        if(times < 1){
+                            flag = 1;
+                        }
+                        i++;
+                    }
+                    if(flag == 1){ // 不能启动
+                        ModbusRtu.closeDevice(serialPort);
+                    }else{
+                        // 可启动
+                        ModbusRtu.openDevice(serialPort);
                     }
                 }
+            }else{
+                //不能启动
+                ModbusRtu.closeDevice(serialPort);
             }
+        }catch (Exception e){
+            e.printStackTrace();
         }
     }
 
     public static void getMaterailData(){
         JSONObject retObj = DataUtil.getBindMaterail();
-        if(retObj.get("result")!=null && retObj.get("result").toString().equalsIgnoreCase("true")) {
+        if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
             java.util.List<BindMaterialResp> arrs = retObj.getList("data",BindMaterialResp.class);
             int i = 0;
             rowData = new Object[arrs.size()][7];
@@ -937,6 +723,51 @@ public class MesClient extends JFrame {
         }
     }
 
+    public static void updateMaterailData(){
+        JSONObject retObj = DataUtil.getBindMaterail();
+        if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
+            List<BindMaterialResp> arrs = retObj.getList("data",BindMaterialResp.class);
+
+            int i = 0;
+            for (BindMaterialResp bindMaterialResp:arrs){
+                rowData[i][0] = bindMaterialResp.getMaterialTitle();
+                rowData[i][1] = bindMaterialResp.getBatchSn();
+                rowData[i][2] = bindMaterialResp.getLastTimes();
+                rowData[i][3] = "";
+                rowData[i][4] = bindMaterialResp.getCraft();
+                rowData[i][5] = bindMaterialResp.getMaterialId();
+                rowData[i][6] = bindMaterialResp.getType();
+                i++;
+            }
+
+            MesClient.table.repaint();
+            MesClient.formatDeviceState();
+        }
+    }
+
+    // 绑定物料批次码
+    public static void scanBatchSn(BindMaterialResp bindMaterialResp) {
+        //弹窗扫工件码
+        String scanBarcodeTitle = "请扫物料:"+bindMaterialResp.getMaterialTitle();
+        String scanBarcode = JOptionPane.showInputDialog(null, scanBarcodeTitle);
+        if(scanBarcode!=null&&!scanBarcode.equalsIgnoreCase("")) {
+
+            JSONObject retObj = DataUtil.saveBindMaterail(scanBarcode,bindMaterialResp.getCraft(),bindMaterialResp.getMaterialId(),bindMaterialResp.getType());
+            if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
+                MesClient.setMenuStatus("扫物料:"+bindMaterialResp.getMaterialTitle()+"成功",0);
+                updateMaterailData();
+            }else{
+                if(retObj.get("result")==null){
+                    MesClient.setMenuStatus("请求失败,请重试",-1);
+                }else{
+                    if(retObj.get("result").toString().equalsIgnoreCase("false")){
+                        MesClient.setMenuStatus(retObj.getString("message"),-1);
+                    }
+                }
+            }
+        }
+    }
+
     public static void bindBatchPanel(){
         JPanel indexPanelBB = new JPanel();
         JPanel panel = new JPanel();
@@ -969,24 +800,4 @@ public class MesClient extends JFrame {
         tabbedPane.addTab("绑定物料", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), indexScrollPaneB, null);
     }
 
-    public static void updateMaterailData(){
-        JSONObject retObj = DataUtil.getBindMaterail();
-        if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
-            List<BindMaterialResp> arrs = retObj.getList("data",BindMaterialResp.class);
-
-            int i = 0;
-            for (BindMaterialResp bindMaterialResp:arrs){
-                rowData[i][0] = bindMaterialResp.getMaterialTitle();
-                rowData[i][1] = bindMaterialResp.getBatchSn();
-                rowData[i][2] = bindMaterialResp.getLastTimes();
-                rowData[i][3] = "";
-                rowData[i][4] = bindMaterialResp.getCraft();
-                rowData[i][5] = bindMaterialResp.getMaterialId();
-                rowData[i][6] = bindMaterialResp.getType();
-                i++;
-            }
-
-            MesClient.table.repaint();
-        }
-    }
 }

+ 21 - 15
src/com/mes/ui/MesRevice.java

@@ -25,12 +25,13 @@ public class MesRevice {
                     DataUtil.startWork(MesClient.nettyClient,barcode36,MesClient.user20);
                 }
             }else {
-                //不合格工件 禁止启动信号
-                S7Util.sendStartMessage(MesClient.s7PLC,false);
                 MesClient.check_quality_result = false;
+
                 String lmsg = ErrorMsg.getErrorMsg(processMsgRet, ProtocolParam.getLx(mes_msg));
 
-                MesClient.setMenuStatus(lmsg,1);
+                MesClient.setMenuStatus(lmsg,-1);
+                ModbusRtu.closeDevice(MesClient.serialPort);
+//                MesClient.status_menu.setText(lmsg);
 //                new MyDialog(MesClient.mesClientFrame,"提示",lmsg);
             }
             if(MesClient.check_quality_result){
@@ -58,15 +59,18 @@ public class MesRevice {
 
                 MesClient.f_scan_data_bt_1.setEnabled(false);
 
-                String sn = MesClient.getBarcode(MesClient.product_sn.getText());
-                MesClient.getUser();
-                DataUtil.bindUser(MesClient.nettyClient,sn,MesClient.user20);
+//                String sn = MesClient.getBarcode(MesClient.product_sn.getText());
+//                MesClient.getUser();
+//                DataUtil.bindUser(MesClient.nettyClient,sn,MesClient.user20);
+
+                MesClient.finish_ok_bt.setEnabled(true);
+                MesClient.finish_ng_bt.setEnabled(true);
+
+//                MesClient.checkState = true;
+//                MesClient.formatDeviceState();
 
-                //质量合格,发送可以反馈可以加工
-                S7Util.sendStartMessage(MesClient.s7PLC,true);
-                //
-                MesClient.setMenuStatus(MesClient.tjFlagText5,0);
-                MesClient.tjFlag=1;
+                MesClient.jsFlag = 0;
+                ModbusRtu.openDevice(MesClient.serialPort);
 
 
                 /*String qret = "OK";
@@ -116,14 +120,16 @@ public class MesRevice {
             if(processMsgRet.equalsIgnoreCase("OK")) {
 
                 MesClient.resetScanA();
-                MesClient.status_menu.setText(MesClient.tjFlagText4);
+//                MesClient.status_menu.setText("结果提交成功,请扫下一件");
+                MesClient.setMenuStatus("结果提交成功,请扫下一件",0);
                 MesClient.scan_type = 1;
-//                MesClient.scanBarcode();
+                MesClient.scanBarcode();
 
             }else{
-                MesClient.status_menu.setText("结果提交失败,请重试");
+                MesClient.setMenuStatus("结果提交失败,请重试",-1);
+//                MesClient.status_menu.setText("结果提交失败,请重试");
 //                JOptionPane.showMessageDialog(MesClient.mesClientFrame,"结果提交失败,请重试","提示窗口", JOptionPane.INFORMATION_MESSAGE);
-                return;
+//                return;
             }
         }catch (Exception e){
             e.printStackTrace();

+ 227 - 0
src/com/mes/ui/ModbusRtu.java

@@ -0,0 +1,227 @@
+package com.mes.ui;
+
+import com.fazecast.jSerialComm.*;
+
+import java.math.BigInteger;
+
+public class ModbusRtu {
+    public static SerialPort connect(){
+        try{
+            SerialPort serialPort = SerialPort.getCommPort("COM2"); // 替换为你的端口名
+            serialPort.setComPortParameters(38400, 8, SerialPort.ONE_STOP_BIT, SerialPort.NO_PARITY); // 设置端口参数
+            serialPort.setComPortTimeouts(SerialPort.TIMEOUT_READ_BLOCKING, 1000, 0);
+
+            if (serialPort.openPort()) {
+                System.out.println("Port opened successfully.");
+                return serialPort;
+            } else {
+               return null;
+            }
+        }catch (Exception e){
+            e.printStackTrace();
+            return null;
+        }
+    }
+
+    public static void disconnect(SerialPort serialPort) {
+        if (serialPort != null && serialPort.isOpen()) {
+            serialPort.closePort();
+        }
+    }
+
+    public static SerialPort reconnect(SerialPort serialPort) {
+        disconnect(serialPort);
+        return connect();
+    }
+
+    public static void openDevice(SerialPort serialPort) {
+        System.out.println("isOpen:");
+        if(serialPort ==null || !serialPort.isOpen()){
+            serialPort = reconnect(serialPort);
+        }
+
+        try {
+            String writeString = "010600000000"; // 关
+            String crc = getCRC16_Modbus_Str(writeString);
+            byte[] writeBuffer = hexStringToByteArray(writeString+crc);
+            serialPort.writeBytes(writeBuffer, writeBuffer.length);
+
+            // 接收数据
+            byte[] readBuffer = new byte[512]; // 调整数组大小以适应预期的响应长度
+            int numRead = serialPort.readBytes(readBuffer, readBuffer.length);
+            System.out.println("Read " + numRead + " bytes.");
+
+            // 将读取的字节转换为十六进制字符串
+            StringBuilder data = new StringBuilder();
+            for (int i = 0; i < numRead; i++) {
+                data.append(String.format("%02X", readBuffer[i]));
+            }
+            String revStr = data.toString();
+//            String ret = revStr.substring(6,8);
+            System.out.println("Received data: " + revStr);
+//            System.out.println("ret data: " + ret);
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            serialPort.closePort();
+        } finally {
+
+        }
+    }
+
+    public static void closeDevice(SerialPort serialPort) {
+        if(serialPort ==null || !serialPort.isOpen()){
+            serialPort = reconnect(serialPort);
+        }
+        try {
+            String writeString = "010600000001"; // 开
+            String crc = getCRC16_Modbus_Str(writeString);
+            byte[] writeBuffer = hexStringToByteArray(writeString+crc);
+            serialPort.writeBytes(writeBuffer, writeBuffer.length);
+
+            // 接收数据
+            byte[] readBuffer = new byte[512]; // 调整数组大小以适应预期的响应长度
+            int numRead = serialPort.readBytes(readBuffer, readBuffer.length);
+            System.out.println("Read " + numRead + " bytes.");
+
+            // 将读取的字节转换为十六进制字符串
+            StringBuilder data = new StringBuilder();
+            for (int i = 0; i < numRead; i++) {
+                data.append(String.format("%02X", readBuffer[i]));
+            }
+            String revStr = data.toString();
+//            String ret = revStr.substring(6,8);
+            System.out.println("Received data: " + revStr);
+//            System.out.println("ret data: " + ret);
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            serialPort.closePort();
+        } finally {
+
+        }
+    }
+
+    public static Boolean readCoil(SerialPort serialPort,int pos) {
+        if(serialPort ==null || !serialPort.isOpen()){
+            serialPort = reconnect(serialPort);
+        }
+        try {
+            String writeString = "010100000"+pos+"01"; // 线圈地址 0/1,目前只有2路
+            String crc = getCRC16_Modbus_Str(writeString);
+            byte[] writeBuffer = hexStringToByteArray(writeString+crc);
+            serialPort.writeBytes(writeBuffer, writeBuffer.length);
+
+            // 接收数据
+            byte[] readBuffer = new byte[512]; // 调整数组大小以适应预期的响应长度
+            int numRead = serialPort.readBytes(readBuffer, readBuffer.length);
+            System.out.println("Read " + numRead + " bytes.");
+
+            // 将读取的字节转换为十六进制字符串
+            StringBuilder data = new StringBuilder();
+            for (int i = 0; i < numRead; i++) {
+                data.append(String.format("%02X", readBuffer[i]));
+            }
+            String revStr = data.toString();
+            String ret = revStr.substring(6,8);
+            System.out.println("Received data: " + revStr);
+            System.out.println("ret data: " + ret);
+
+            if(ret.equals("01")){
+                MesClient.setMenuStatus("当前结果为:true",0);
+                return true;
+            }else{
+                MesClient.setMenuStatus("当前结果为:false",0);
+                return false;
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+            MesClient.setMenuStatus("串口断线",0);
+            serialPort.closePort();
+            return false;
+        }
+    }
+
+
+    /**
+     * CRC16(modbus)校验
+     * 获取crc16校验码,参数data中不能有空格
+     * @param data
+     * @return
+     */
+    public static String getCRC16_Modbus_Str(String data) {
+        data = data.replace(" ", "");
+        int len = data.length();
+        if (!(len % 2 == 0)) {
+            return "0000";
+        }
+        int num = len / 2;
+        byte[] para = new byte[num];
+        for (int i = 0; i < num; i++) {
+            int value = Integer.valueOf(data.substring(i * 2, 2 * (i + 1)), 16);
+            para[i] = (byte) value;
+        }
+        return getCRC(para);
+    }
+
+    /**
+     * 计算CRC16校验码
+     * @param bytes
+     *            字节数组
+     * @return {@link String} 校验码
+     * @since 1.0
+     */
+    public static String getCRC(byte[] bytes) {
+        // CRC寄存器全为1
+        int CRC = 0x0000ffff;
+        // 多项式校验值
+        int POLYNOMIAL = 0x0000a001;
+        int i, j;
+        for (i = 0; i < bytes.length; i++) {
+            CRC ^= ((int) bytes[i] & 0x000000ff);
+            for (j = 0; j < 8; j++) {
+                if ((CRC & 0x00000001) != 0) {
+                    CRC >>= 1;
+                    CRC ^= POLYNOMIAL;
+                } else {
+                    CRC >>= 1;
+                }
+            }
+        }
+        // 结果转换为16进制
+        String result = Integer.toHexString(CRC).toUpperCase();
+        if (result.length() != 4) {
+            StringBuffer sb = new StringBuffer("0000");
+            result = sb.replace(4 - result.length(), 4, result).toString();
+        }
+        //高位在前地位在后
+        //return result.substring(2, 4) + " " + result.substring(0, 2);
+        // 交换高低位,低位在前高位在后
+        return result.substring(2, 4) +  result.substring(0, 2);
+    }
+
+    public static byte[] hexStringToByteArray(String hexString) {
+        // 去除字符串前后的空格
+        hexString = hexString.trim();
+
+        // 确保字符串的长度是偶数
+        if (hexString.length() % 2 != 0) {
+            throw new IllegalArgumentException("Invalid hex string");
+        }
+
+        // 将字符串转换为BigInteger对象
+        BigInteger bigInt = new BigInteger(hexString, 16);
+
+        // 获取BigInteger表示的字节数组
+        byte[] byteArray = bigInt.toByteArray();
+
+        // 处理符号位,如果数组的长度大于字符串的长度,则将符号位字节去除
+        if (byteArray.length > hexString.length() / 2) {
+            byte[] trimmedArray = new byte[hexString.length() / 2];
+            System.arraycopy(byteArray, 1, trimmedArray, 0, trimmedArray.length);
+            return trimmedArray;
+        }
+
+        return byteArray;
+    }
+}

+ 2 - 2
src/com/mes/ui/OprnoUtil.java

@@ -14,9 +14,9 @@ public class OprnoUtil {
     };
     public static String[] xtoprnodes = new String[]{
             "镭雕二维码","单部件压套筒、装牙套","安装支架、单部件拉铆","预拼装","CMT焊接","人工焊接","焊道检验","焊道打磨",
-            "框架气密安装后挂载点、加强件","CNC总成正面加工","CNC总成反面加工","去毛刺、清洁","总成压套筒、压铆","焊接封堵片","框架GP12",
+            "框架气密","安装后挂载点、加强件","CNC总成正面加工","CNC总成反面加工","去毛刺、清洁","总成压套筒、压铆","焊接封堵片","框架GP12",
             "总成正面拉铆","总成反面拉铆","框架涂胶","FDS","手工反面拉铆、安装牙套","正反面清理溢胶","FDS钉头涂胶","固化1",
-            "安装中吊点、涂封堵胶","固化2","正面拉铆","半成品气密","泡棉安装、底护板安装、定位销","成品气密","液冷板气密","内腔装配",
+            "安装中吊点、涂封堵胶","正面拉铆","固化2","半成品气密","泡棉安装、底护板安装、定位销","成品气密","液冷板气密","内腔装配",
             "总成检具","清洁、模拟客户装配","CCD","终检、卸螺栓","GP12","包装"
     };
     public static String[] lboprnos = new String[]{

+ 0 - 76
src/com/mes/ui/S7Util.java

@@ -1,76 +0,0 @@
-package com.mes.ui;
-
-import com.github.xingshuangs.iot.protocol.s7.service.S7PLC;
-
-public class S7Util {
-
-
-    //上料MES输出 上料成功可以进行扫码
-    public static boolean getShangLiaoOk(S7PLC s7PLC) {
-        try {
-            boolean result = s7PLC.readBoolean("DB0201.0.0");
-            return result;
-        } catch (Exception e) {
-            e.printStackTrace();
-            return false;
-        }
-    }
-
-
-
-
-    //质量检测合格,发送上料mes反馈  即该工件合格可以进行生产
-    public static void sendStartMessage(S7PLC s7PLC,Boolean bool) {
-        try {
-          s7PLC.writeBoolean("DB0201.0.1",bool);
-        } catch (Exception e) {
-//            MesClient.setMenuStatus("机器人连接失败,请检查网络!",1);
-            e.printStackTrace();
-        }
-    }
-
-    //获取设备质量检测合格够是否正常启动   MES启动
-    public static boolean getstartMessage(S7PLC s7PLC) {
-        try {
-            boolean result = s7PLC.readBoolean("DB0201.0.2");
-            return result;
-        } catch (Exception e) {
-            e.printStackTrace();
-            return false;
-        }
-    }
-
-    //获取设备结束指令  下料MES输出
-    public static boolean getstopMessage(S7PLC s7PLC) {
-        try {
-            boolean result = s7PLC.readBoolean("DB0201.0.3");
-            return result;
-        } catch (Exception e) {
-            e.printStackTrace();
-            return false;
-        }
-    }
-
-    //设备停止,发送已读取结果指令   下料MES反馈
-    public static void sendEndMessage(S7PLC s7PLC,Boolean bool) {
-        try {
-            s7PLC.writeBoolean("DB0201.0.4",bool);
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-    }
-    public static boolean readEndMessage(S7PLC s7PLC) {
-        try {
-            return  s7PLC.readBoolean("DB0201.0.4");
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-        return false;
-    }
-
-    //获取设备故障状态
-    public static boolean getStatus(S7PLC s7PLC) {
-        return s7PLC.readBoolean("DB0201.1.1");
-    }
-
-}

+ 5 - 31
src/com/mes/util/HttpUtils.java

@@ -1,6 +1,9 @@
 package com.mes.util;
 
-import java.io.*;
+import java.io.BufferedReader;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
 import java.net.HttpURLConnection;
 import java.net.URISyntaxException;
 import java.net.URL;
@@ -123,35 +126,6 @@ public class HttpUtils {
         return ret;
     }
 
+	
 
-    public static String sendPostRequestJson(String apiUrl, String jsonData) throws IOException {
-        URL url = new URL(apiUrl);
-        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
-        conn.setRequestMethod("POST");
-        conn.setRequestProperty("Content-Type", "application/json");
-        conn.setDoOutput(true);
-
-        // 发送请求数据
-        try (OutputStream os = conn.getOutputStream()) {
-            byte[] input = jsonData.getBytes("utf-8");
-            os.write(input, 0, input.length);
-        }
-
-        // 获取响应数据
-        StringBuilder response = new StringBuilder();
-        int responseCode = conn.getResponseCode();
-        System.out.println("Sending POST request to URL: " + apiUrl);
-        System.out.println("Post parameters: " + jsonData);
-        System.out.println("Response Code: " + responseCode);
-
-        try (BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream(), "utf-8"))) {
-            String responseLine;
-            while ((responseLine = br.readLine()) != null) {
-                response.append(responseLine.trim());
-            }
-        }
-
-        conn.disconnect();
-        return response.toString();
-    }
 }

+ 0 - 17
src/com/mes/util/Test.java

@@ -1,17 +0,0 @@
-package com.mes.util;
-
-import com.github.xingshuangs.iot.protocol.s7.enums.EPlcType;
-import com.github.xingshuangs.iot.protocol.s7.service.S7PLC;
-
-public class Test {
-    public static void main(String[] args) {
-       S7PLC s7PLC = new S7PLC(EPlcType.S200_SMART, "192.168.6.40"); //
-        boolean result = s7PLC.readBoolean("DB0101.0.0");
-        System.out.println("上料成功是否可以进行扫码"+result);
-//        s7PLC.writeBoolean("DB0101.0.1",true);
-        System.out.println("上料mes反馈"+s7PLC.readBoolean("DB0101.0.1"));
-        System.out.println("设备是否启动"+s7PLC.readBoolean("DB0101.0.2"));
-        System.out.println("设备是否结束"+s7PLC.readBoolean("DB0101.0.3"));
-        System.out.println("已读取结果反馈"+s7PLC.readBoolean("DB0101.0.4"));
-    }
-}

+ 3 - 9
src/resources/config/config.properties

@@ -1,12 +1,6 @@
-#\u5DE5\u4F4D\u53F7
-#XT OP090 OP100 OP110 OP120 OP160 OP180 OP190 OP250 OP260 OP280 OP360 OP370 OP390 OP400
-mes.gw=OP220
-#\u670D\u52A1\u5668IP\u5730\u5740
+mes.gw=OP240
 #mes.server_ip=127.0.0.1
-mes.server_ip=192.168.16.99
-#TCP\u7AEF\u53E3
+mes.server_ip=10.0.20.10
 mes.tcp_port=3000
-#\u5FC3\u8DF3\u5468\u671F
 mes.heart_beat_cycle=60
-#\u4EA7\u7EBF\u7F16\u53F7
-mes.line_sn=XT
+mes.line_sn=XT