|
|
@@ -67,11 +67,9 @@ public class MesClient extends JFrame {
|
|
|
public static JButton status_menu;
|
|
|
public static JButton user_menu;
|
|
|
|
|
|
- public static int scan_type = 0;
|
|
|
public static JButton finish_ok_bt;
|
|
|
public static JButton finish_ng_bt;
|
|
|
public static JTextField product_sn;
|
|
|
- public static JButton f_scan_data_bt_1;
|
|
|
|
|
|
public static String user20 = "";
|
|
|
|
|
|
@@ -88,6 +86,11 @@ public class MesClient extends JFrame {
|
|
|
public static JTextField param2;
|
|
|
public static JTextField param3;
|
|
|
public static JTextField param4;
|
|
|
+ // A/B枪实时拉力、行程显示
|
|
|
+ public static JTextField param5;
|
|
|
+ public static JTextField param6;
|
|
|
+ public static JTextField param7;
|
|
|
+ public static JTextField param8;
|
|
|
|
|
|
public static ModbusTcp plcA;
|
|
|
public static ModbusTcp plcB;
|
|
|
@@ -116,10 +119,21 @@ public class MesClient extends JFrame {
|
|
|
public static Short deviceControl = 0; // 0=本地 1=远程
|
|
|
public static Integer tjStatus = 0; // 1=提交失败
|
|
|
|
|
|
+ // 铆接参数区间配置(内存缓存)
|
|
|
+ public static List<RivetParamRange> rivetParamRangesA = new ArrayList<>();
|
|
|
+ public static List<RivetParamRange> rivetParamRangesB = new ArrayList<>();
|
|
|
+
|
|
|
public static String tjFlagTextErr = "结果上传MES失败,请重试";
|
|
|
|
|
|
public static String curSn = "";
|
|
|
|
|
|
+ // 后台拉码定时器
|
|
|
+ public static Timer getSnBeatTimer;
|
|
|
+ // 已提交质量询问、等待TCP应答的工件码
|
|
|
+ public static String backendPollingSn = "";
|
|
|
+ // 质量检查未通过的后台码,避免重复轮询
|
|
|
+ public static String lastRejectedBackendSn = "";
|
|
|
+
|
|
|
public static JTable table;
|
|
|
public static Object[] columnNames = { "物料名称", "绑定批次", "剩余次数", "操作" };
|
|
|
public static Object[][] rowData = null;
|
|
|
@@ -167,6 +181,14 @@ public class MesClient extends JFrame {
|
|
|
cjTimer4.schedule(new TimerTask() {
|
|
|
public void run() {
|
|
|
try{
|
|
|
+ // MES屏蔽时仅维持拉铆枪运行,不做空闲关机等干预
|
|
|
+ if (mes_shield_flag) {
|
|
|
+ if (work_status == 1) {
|
|
|
+ keepGunRunningIfNeeded(plcA, sortA, aMax);
|
|
|
+ keepGunRunningIfNeeded(plcB, sortB, bMax);
|
|
|
+ }
|
|
|
+ return;
|
|
|
+ }
|
|
|
if(work_status == 1){
|
|
|
List<Boolean> yxstatus = plcA.readCoil(3128,1);
|
|
|
if(yxstatus.size() >= 1 && !yxstatus.get(0)){
|
|
|
@@ -203,6 +225,20 @@ public class MesClient extends JFrame {
|
|
|
}, 1000,1000);
|
|
|
}
|
|
|
|
|
|
+ // MES屏蔽期间:任务未完成时保持拉铆枪运行
|
|
|
+ private static void keepGunRunningIfNeeded(ModbusTcp plc, Short sort, Short max) {
|
|
|
+ try {
|
|
|
+ List<Boolean> yxstatus = plc.readCoil(3128, 1);
|
|
|
+ if (yxstatus.size() >= 1 && !yxstatus.get(0)) {
|
|
|
+ if (!curSn.isEmpty() && max > 0 && max != sort) {
|
|
|
+ ModbusUtil.setPowerOn(plc);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
//读配置文件
|
|
|
private static void readProperty() throws IOException{
|
|
|
String enconding = "UTF-8";
|
|
|
@@ -248,6 +284,13 @@ public class MesClient extends JFrame {
|
|
|
plcB = new ModbusTcp(1, curIpB);
|
|
|
System.out.println("未找到本地配置,使用默认值");
|
|
|
}
|
|
|
+ loadRivetParamConfig();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 加载铆接参数区间配置
|
|
|
+ public static void loadRivetParamConfig() {
|
|
|
+ rivetParamRangesA = JdbcUtils.getRivetParams("A");
|
|
|
+ rivetParamRangesB = JdbcUtils.getRivetParams("B");
|
|
|
}
|
|
|
|
|
|
public static void getPlcParam() {
|
|
|
@@ -258,7 +301,7 @@ public class MesClient extends JFrame {
|
|
|
cjTimer.schedule(new TimerTask() {
|
|
|
public void run() {
|
|
|
try{
|
|
|
- if(work_status == 1){
|
|
|
+ if(work_status == 1 && !mes_shield_flag){
|
|
|
ModbusUtil.getDataA(plcA);
|
|
|
}
|
|
|
|
|
|
@@ -267,7 +310,7 @@ public class MesClient extends JFrame {
|
|
|
}
|
|
|
|
|
|
try{
|
|
|
- if(work_status == 1){
|
|
|
+ if(work_status == 1 && !mes_shield_flag){
|
|
|
ModbusUtil.getDataB(plcB);
|
|
|
}
|
|
|
|
|
|
@@ -289,15 +332,7 @@ public class MesClient extends JFrame {
|
|
|
String cSn = ModbusUtil.getSn(plcA);
|
|
|
if(!cSn.isEmpty()){
|
|
|
if(curSn.isEmpty()){
|
|
|
- product_sn.setText(cSn);
|
|
|
- curSn = cSn;
|
|
|
-
|
|
|
- //发送AQDW质量询问报文,当收到返回UD才能工作
|
|
|
- getUser();
|
|
|
- Boolean sendret = DataUtil.checkQuality(nettyClient,curSn,user20);
|
|
|
- if(!sendret){
|
|
|
- MesClient.setMenuStatus("消息发送失败,请重试",-1);
|
|
|
- }
|
|
|
+ submitSnForQualityCheck(cSn, true);
|
|
|
}else if(!curSn.isEmpty() && !cSn.equals(curSn)){
|
|
|
resetScanA();
|
|
|
}
|
|
|
@@ -432,7 +467,117 @@ public class MesClient extends JFrame {
|
|
|
resetScanA();
|
|
|
}
|
|
|
|
|
|
+ // 启动后台拉码轮询
|
|
|
+ public static void startGetCurSn() {
|
|
|
+ if (getSnBeatTimer != null) {
|
|
|
+ getSnBeatTimer.cancel();
|
|
|
+ }
|
|
|
+ getSnBeatTimer = new Timer();
|
|
|
+ getSnBeatTimer.schedule(new TimerTask() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ pollBackendSn();
|
|
|
+ }
|
|
|
+ }, 100, 1000);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 停止后台拉码轮询
|
|
|
+ public static void stopGetCurSn() {
|
|
|
+ if (getSnBeatTimer != null) {
|
|
|
+ getSnBeatTimer.cancel();
|
|
|
+ getSnBeatTimer = null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 清除后台拉码中间状态
|
|
|
+ public static void clearBackendSnState() {
|
|
|
+ backendPollingSn = "";
|
|
|
+ lastRejectedBackendSn = "";
|
|
|
+ }
|
|
|
+
|
|
|
+ // 清除后台工位工件码
|
|
|
+ public static void clearBackendCurSn() {
|
|
|
+ if (sessionid != null && !sessionid.isEmpty()) {
|
|
|
+ DataUtil.delCurSn(mes_gw, mes_server_ip, mes_line_sn);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 轮询后台工件码
|
|
|
+ public static void pollBackendSn() {
|
|
|
+ try {
|
|
|
+ if (mes_shield_flag) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (work_status == 1) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (sessionid == null || sessionid.isEmpty()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (!backendPollingSn.isEmpty()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (!tcp_connect_flag) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ JSONObject result = DataUtil.getCurSn(mes_gw, mes_server_ip, mes_line_sn);
|
|
|
+ if (result == null || !result.containsKey("data")) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String data = result.getString("data");
|
|
|
+ if (data == null || data.trim().isEmpty()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ data = data.trim();
|
|
|
+
|
|
|
+ if (data.equals(lastRejectedBackendSn)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (!curSn.isEmpty() && data.equals(curSn.trim())) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ submitSnForQualityCheck(data, true);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 提交工件码进行质量询问(手动扫码与后台拉码共用)
|
|
|
+ public static boolean submitSnForQualityCheck(String scanBarcode, boolean fromBackend) {
|
|
|
+ getUser();
|
|
|
+ String barcode36 = getBarcode(scanBarcode);
|
|
|
+ product_sn.setText(scanBarcode);
|
|
|
+ curSn = scanBarcode;
|
|
|
+ backendPollingSn = scanBarcode.trim();
|
|
|
+ lastRejectedBackendSn = "";
|
|
|
+ mesClientFrame.repaint();
|
|
|
+
|
|
|
+ if (!tcp_connect_flag) {
|
|
|
+ backendPollingSn = "";
|
|
|
+ setMenuStatus("设备未连接Mes服务器", -1);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ Boolean sendret = DataUtil.checkQuality(nettyClient, barcode36, user20);
|
|
|
+ if (!sendret) {
|
|
|
+ backendPollingSn = "";
|
|
|
+ setMenuStatus("消息发送失败,请重试", -1);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (fromBackend) {
|
|
|
+ setMenuStatus("已从后台获取工件码,质量检查中", 0);
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
public static void resetScanA() {
|
|
|
+ // 闭环:提交完成或刷新时清除后台工位码
|
|
|
+ clearBackendCurSn();
|
|
|
+ clearBackendSnState();
|
|
|
+
|
|
|
work_status = 0;
|
|
|
check_quality_result = false;
|
|
|
MesClient.finish_ok_bt.setEnabled(false);
|
|
|
@@ -440,8 +585,7 @@ public class MesClient extends JFrame {
|
|
|
product_sn.setText("");
|
|
|
curSn = "";
|
|
|
|
|
|
- MesClient.f_scan_data_bt_1.setEnabled(true);
|
|
|
- MesClient.setMenuStatus("请扫工件码",0);
|
|
|
+ MesClient.setMenuStatus("等待后台工件码",0);
|
|
|
|
|
|
MesClient.aMax = 0;
|
|
|
MesClient.bMax = 0;
|
|
|
@@ -454,6 +598,7 @@ public class MesClient extends JFrame {
|
|
|
MesClient.param2.setText("");
|
|
|
MesClient.param3.setText(String.valueOf(bSetNum));
|
|
|
MesClient.param4.setText("");
|
|
|
+ resetForceStrokeDisplay();
|
|
|
|
|
|
deviceControl = ModbusUtil.getControlModel(plcA);
|
|
|
if(deviceControl == 1){
|
|
|
@@ -465,8 +610,8 @@ public class MesClient extends JFrame {
|
|
|
ModbusUtil.setPowerOff(MesClient.plcA); // 远程关机
|
|
|
ModbusUtil.setPowerOff(MesClient.plcB); // 远程关机
|
|
|
|
|
|
- ModbusUtil.setTask(MesClient.plcA,MesClient.aSetNum);
|
|
|
- ModbusUtil.setTask(MesClient.plcB,MesClient.bSetNum);
|
|
|
+ ModbusUtil.setTask(MesClient.plcA, MesClient.aSetNum, "A");
|
|
|
+ ModbusUtil.setTask(MesClient.plcB, MesClient.bSetNum, "B");
|
|
|
|
|
|
updateMaterailData();
|
|
|
}
|
|
|
@@ -504,56 +649,19 @@ public class MesClient extends JFrame {
|
|
|
return barcodeRet;
|
|
|
}
|
|
|
|
|
|
- public static void scanBarcode() {
|
|
|
- if(work_status == 1){
|
|
|
- JOptionPane.showMessageDialog(mesClientFrame,"工作中,勿扫码","提示窗口", JOptionPane.INFORMATION_MESSAGE);
|
|
|
- return;
|
|
|
- }
|
|
|
- String scanBarcodeTitle = "";
|
|
|
- switch(scan_type) {
|
|
|
- case 1:
|
|
|
- product_sn.setText("");
|
|
|
- scanBarcodeTitle = "请扫工件码";
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
- //弹窗扫工件码
|
|
|
- String scanBarcode = JOptionPane.showInputDialog(null, scanBarcodeTitle);
|
|
|
- if(scanBarcode!=null&&!scanBarcode.equalsIgnoreCase("")) {
|
|
|
- //获取用户
|
|
|
- getUser();
|
|
|
- //获取扫码内容36位
|
|
|
- String barcode36 = getBarcode(scanBarcode);//处理36为码
|
|
|
- //工位号
|
|
|
- String gw = "";
|
|
|
- switch(scan_type) {
|
|
|
- case 1:
|
|
|
- product_sn.setText(scanBarcode);
|
|
|
- curSn = scanBarcode;
|
|
|
- break;
|
|
|
- }
|
|
|
- //刷新界面
|
|
|
- mesClientFrame.repaint();
|
|
|
-
|
|
|
- if(!tcp_connect_flag) {
|
|
|
- JOptionPane.showMessageDialog(mesClientFrame,"设备未连接Mes服务器","提示窗口", JOptionPane.INFORMATION_MESSAGE);
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- // 查询工件质量
|
|
|
- Boolean sendret = DataUtil.checkQuality(nettyClient,barcode36,user20);
|
|
|
- if(!sendret){
|
|
|
- JOptionPane.showMessageDialog(mesClientFrame,"消息发送失败,请重试","提示窗口", JOptionPane.INFORMATION_MESSAGE);
|
|
|
- return;
|
|
|
- }
|
|
|
- }else {
|
|
|
- JOptionPane.showMessageDialog(mesClientFrame,"请扫工件码","提示窗口", JOptionPane.INFORMATION_MESSAGE);
|
|
|
- return;
|
|
|
- }
|
|
|
+ // 重置拉力、行程显示
|
|
|
+ public static void resetForceStrokeDisplay() {
|
|
|
+ if (param5 != null) param5.setText("-");
|
|
|
+ if (param6 != null) param6.setText("-");
|
|
|
+ if (param7 != null) param7.setText("-");
|
|
|
+ if (param8 != null) param8.setText("-");
|
|
|
}
|
|
|
|
|
|
public static void logoff() {
|
|
|
// welcomeWin.setVisible(true);
|
|
|
+ stopGetCurSn();
|
|
|
+ clearBackendCurSn();
|
|
|
+ clearBackendSnState();
|
|
|
mesClientFrame.setVisible(false);
|
|
|
|
|
|
nettyClient = null;
|
|
|
@@ -636,11 +744,15 @@ public class MesClient extends JFrame {
|
|
|
if (mes_shield_flag) {
|
|
|
shieldMesMenu.setText("MES屏蔽: 开");
|
|
|
shieldMesMenu.setForeground(Color.RED);
|
|
|
- JOptionPane.showMessageDialog(mesClientFrame, "MES屏蔽已开启", "提示", JOptionPane.WARNING_MESSAGE);
|
|
|
+ setMenuStatus("MES屏蔽已开启:拉铆枪保持运行,客户端暂停读取", 0);
|
|
|
+ JOptionPane.showMessageDialog(mesClientFrame,
|
|
|
+ "MES屏蔽已开启\n拉铆枪不会被远程关机,可继续打钉\n客户端暂停读取PLC数据及MES后台工件码",
|
|
|
+ "提示", JOptionPane.WARNING_MESSAGE);
|
|
|
} else {
|
|
|
shieldMesMenu.setText("MES屏蔽: 关");
|
|
|
shieldMesMenu.setForeground(Color.BLACK);
|
|
|
- JOptionPane.showMessageDialog(mesClientFrame, "MES屏蔽已关闭", "提示", JOptionPane.INFORMATION_MESSAGE);
|
|
|
+ setMenuStatus("MES屏蔽已关闭", 0);
|
|
|
+ JOptionPane.showMessageDialog(mesClientFrame, "MES屏蔽已关闭,恢复正常读取", "提示", JOptionPane.INFORMATION_MESSAGE);
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
@@ -731,22 +843,10 @@ public class MesClient extends JFrame {
|
|
|
product_sn.setHorizontalAlignment(SwingConstants.CENTER);
|
|
|
product_sn.setEditable(false);
|
|
|
product_sn.setFont(new Font("微软雅黑", Font.PLAIN, 28));
|
|
|
- product_sn.setBounds(81, 70, 602, 70);
|
|
|
+ product_sn.setBounds(81, 70, 810, 70);
|
|
|
indexPanelA.add(product_sn);
|
|
|
product_sn.setColumns(10);
|
|
|
|
|
|
- f_scan_data_bt_1 = new JButton("扫码");
|
|
|
- f_scan_data_bt_1.addActionListener(new ActionListener() {
|
|
|
- public void actionPerformed(ActionEvent e) {
|
|
|
- scan_type = 1;
|
|
|
- scanBarcode();
|
|
|
- }
|
|
|
- });
|
|
|
- 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);
|
|
|
-
|
|
|
// String[] hjtitles = new String[]{"焊机1","焊机2","焊机3"};
|
|
|
// String[] hjvals = new String[]{"HJ001","HJ002","HJ003"};
|
|
|
// mesRadioHj = new MesRadio(hjtitles,hjvals);
|
|
|
@@ -872,6 +972,62 @@ public class MesClient extends JFrame {
|
|
|
param4.setBounds(608, 285, 83, 34);
|
|
|
indexPanelA.add(param4);
|
|
|
|
|
|
+ JLabel lblForceA = new JLabel("\u62c9\u529b");
|
|
|
+ lblForceA.setFont(new Font("微软雅黑", Font.PLAIN, 18));
|
|
|
+ lblForceA.setBounds(204, 329, 50, 34);
|
|
|
+ indexPanelA.add(lblForceA);
|
|
|
+
|
|
|
+ param5 = new JTextField();
|
|
|
+ param5.setHorizontalAlignment(SwingConstants.CENTER);
|
|
|
+ param5.setFont(new Font("微软雅黑", Font.PLAIN, 18));
|
|
|
+ param5.setText("-");
|
|
|
+ param5.setEditable(false);
|
|
|
+ param5.setColumns(10);
|
|
|
+ param5.setBounds(260, 329, 65, 34);
|
|
|
+ indexPanelA.add(param5);
|
|
|
+
|
|
|
+ JLabel lblStrokeA = new JLabel("\u884c\u7a0b");
|
|
|
+ lblStrokeA.setFont(new Font("微软雅黑", Font.PLAIN, 18));
|
|
|
+ lblStrokeA.setBounds(330, 329, 50, 34);
|
|
|
+ indexPanelA.add(lblStrokeA);
|
|
|
+
|
|
|
+ param6 = new JTextField();
|
|
|
+ param6.setHorizontalAlignment(SwingConstants.CENTER);
|
|
|
+ param6.setFont(new Font("微软雅黑", Font.PLAIN, 18));
|
|
|
+ param6.setText("-");
|
|
|
+ param6.setEditable(false);
|
|
|
+ param6.setColumns(10);
|
|
|
+ param6.setBounds(380, 329, 65, 34);
|
|
|
+ indexPanelA.add(param6);
|
|
|
+
|
|
|
+ JLabel lblForceB = new JLabel("\u62c9\u529b");
|
|
|
+ lblForceB.setFont(new Font("微软雅黑", Font.PLAIN, 18));
|
|
|
+ lblForceB.setBounds(525, 329, 50, 34);
|
|
|
+ indexPanelA.add(lblForceB);
|
|
|
+
|
|
|
+ param7 = new JTextField();
|
|
|
+ param7.setHorizontalAlignment(SwingConstants.CENTER);
|
|
|
+ param7.setFont(new Font("微软雅黑", Font.PLAIN, 18));
|
|
|
+ param7.setText("-");
|
|
|
+ param7.setEditable(false);
|
|
|
+ param7.setColumns(10);
|
|
|
+ param7.setBounds(581, 329, 65, 34);
|
|
|
+ indexPanelA.add(param7);
|
|
|
+
|
|
|
+ JLabel lblStrokeB = new JLabel("\u884c\u7a0b");
|
|
|
+ lblStrokeB.setFont(new Font("微软雅黑", Font.PLAIN, 18));
|
|
|
+ lblStrokeB.setBounds(651, 329, 50, 34);
|
|
|
+ indexPanelA.add(lblStrokeB);
|
|
|
+
|
|
|
+ param8 = new JTextField();
|
|
|
+ param8.setHorizontalAlignment(SwingConstants.CENTER);
|
|
|
+ param8.setFont(new Font("微软雅黑", Font.PLAIN, 18));
|
|
|
+ param8.setText("-");
|
|
|
+ param8.setEditable(false);
|
|
|
+ param8.setColumns(10);
|
|
|
+ param8.setBounds(701, 329, 65, 34);
|
|
|
+ indexPanelA.add(param8);
|
|
|
+
|
|
|
tabbedPane.addTab("工作面板", new ImageIcon(MesClient.class.getResource("/bg/a_side.png")), indexScrollPaneA, null);
|
|
|
tabbedPane.setEnabledAt(0, true);
|
|
|
|
|
|
@@ -890,104 +1046,11 @@ public class MesClient extends JFrame {
|
|
|
|
|
|
tabbedPane.addTab("工作记录", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), searchScrollPane, null);
|
|
|
|
|
|
- indexPanelD = new JPanel();
|
|
|
- indexPanelD.setLayout(null);
|
|
|
-
|
|
|
- JLabel lblASet = new JLabel("A枪预设数量:");
|
|
|
- lblASet.setFont(new Font("微软雅黑", Font.PLAIN, 20));
|
|
|
- lblASet.setBounds(100, 50, 150, 40);
|
|
|
- indexPanelD.add(lblASet);
|
|
|
-
|
|
|
- JTextField txtASet = new JTextField(String.valueOf(aSetNum));
|
|
|
- txtASet.setFont(new Font("微软雅黑", Font.PLAIN, 20));
|
|
|
- txtASet.setBounds(260, 50, 200, 40);
|
|
|
- indexPanelD.add(txtASet);
|
|
|
-
|
|
|
- JLabel lblBSet = new JLabel("B枪预设数量:");
|
|
|
- lblBSet.setFont(new Font("微软雅黑", Font.PLAIN, 20));
|
|
|
- lblBSet.setBounds(100, 110, 150, 40);
|
|
|
- indexPanelD.add(lblBSet);
|
|
|
-
|
|
|
- JTextField txtBSet = new JTextField(String.valueOf(bSetNum));
|
|
|
- txtBSet.setFont(new Font("微软雅黑", Font.PLAIN, 20));
|
|
|
- txtBSet.setBounds(260, 110, 200, 40);
|
|
|
- indexPanelD.add(txtBSet);
|
|
|
-
|
|
|
- JLabel lblIpA = new JLabel("A枪IP地址:");
|
|
|
- lblIpA.setFont(new Font("微软雅黑", Font.PLAIN, 20));
|
|
|
- lblIpA.setBounds(100, 170, 150, 40);
|
|
|
- indexPanelD.add(lblIpA);
|
|
|
-
|
|
|
- JTextField txtIpA = new JTextField(curIpA);
|
|
|
- txtIpA.setFont(new Font("微软雅黑", Font.PLAIN, 20));
|
|
|
- txtIpA.setBounds(260, 170, 200, 40);
|
|
|
- indexPanelD.add(txtIpA);
|
|
|
-
|
|
|
- JLabel lblIpB = new JLabel("B枪IP地址:");
|
|
|
- lblIpB.setFont(new Font("微软雅黑", Font.PLAIN, 20));
|
|
|
- lblIpB.setBounds(100, 230, 150, 40);
|
|
|
- indexPanelD.add(lblIpB);
|
|
|
-
|
|
|
- JTextField txtIpB = new JTextField(curIpB);
|
|
|
- txtIpB.setFont(new Font("微软雅黑", Font.PLAIN, 20));
|
|
|
- txtIpB.setBounds(260, 230, 200, 40);
|
|
|
- indexPanelD.add(txtIpB);
|
|
|
-
|
|
|
- JButton btnSave = new JButton("保存设置");
|
|
|
- btnSave.setFont(new Font("微软雅黑", Font.PLAIN, 20));
|
|
|
- btnSave.setBounds(180, 310, 150, 50);
|
|
|
- btnSave.addActionListener(new ActionListener() {
|
|
|
- @Override
|
|
|
- public void actionPerformed(ActionEvent e) {
|
|
|
- try {
|
|
|
- short newASet = Short.parseShort(txtASet.getText());
|
|
|
- short newBSet = Short.parseShort(txtBSet.getText());
|
|
|
- String newIpA = txtIpA.getText().trim();
|
|
|
- String newIpB = txtIpB.getText().trim();
|
|
|
-
|
|
|
- if (newIpA.isEmpty() || newIpB.isEmpty()) {
|
|
|
- JOptionPane.showMessageDialog(mesClientFrame, "IP地址不能为空", "错误", JOptionPane.ERROR_MESSAGE);
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- // 更新数据库
|
|
|
- JdbcUtils.updateConfig(newASet, newBSet, newIpA, newIpB);
|
|
|
-
|
|
|
- // 更新内存变量
|
|
|
- aSetNum = newASet;
|
|
|
- bSetNum = newBSet;
|
|
|
-
|
|
|
- // 同步更新工作面板显示的预设数量
|
|
|
- param1.setText(String.valueOf(aSetNum));
|
|
|
- param3.setText(String.valueOf(bSetNum));
|
|
|
-
|
|
|
- // 检查 IP 是否发生变化,仅在变化时重连
|
|
|
- boolean ipAChanged = !newIpA.equals(curIpA);
|
|
|
- boolean ipBChanged = !newIpB.equals(curIpB);
|
|
|
-
|
|
|
- if (ipAChanged) {
|
|
|
- if (plcA != null) plcA.close();
|
|
|
- curIpA = newIpA;
|
|
|
- plcA = new ModbusTcp(1, curIpA);
|
|
|
- System.out.println("A枪IP已变更,重新连接: " + curIpA);
|
|
|
- }
|
|
|
-
|
|
|
- if (ipBChanged) {
|
|
|
- if (plcB != null) plcB.close();
|
|
|
- curIpB = newIpB;
|
|
|
- plcB = new ModbusTcp(1, curIpB);
|
|
|
- System.out.println("B枪IP已变更,重新连接: " + curIpB);
|
|
|
- }
|
|
|
-
|
|
|
- JOptionPane.showMessageDialog(mesClientFrame, "配置已保存", "提示", JOptionPane.INFORMATION_MESSAGE);
|
|
|
- } catch (NumberFormatException ex) {
|
|
|
- JOptionPane.showMessageDialog(mesClientFrame, "请输入有效的数字", "错误", JOptionPane.ERROR_MESSAGE);
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- indexPanelD.add(btnSave);
|
|
|
-
|
|
|
- tabbedPane.addTab("设备管理", new ImageIcon(MesClient.class.getResource("/bg/menu_setting.png")), indexPanelD, null);
|
|
|
+ indexPanelD = new DeviceManagePanel();
|
|
|
+ JScrollPane scrollPanelD = new JScrollPane(indexPanelD);
|
|
|
+ scrollPanelD.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
|
|
+ scrollPanelD.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
|
|
|
+ tabbedPane.addTab("设备管理", new ImageIcon(MesClient.class.getResource("/bg/menu_setting.png")), scrollPanelD, null);
|
|
|
|
|
|
tabbedPane.addChangeListener(new ChangeListener() {
|
|
|
@Override
|
|
|
@@ -997,7 +1060,7 @@ public class MesClient extends JFrame {
|
|
|
|
|
|
if (selectedIndex == 3) { // 设备管理
|
|
|
String input = JOptionPane.showInputDialog(mesClientFrame, "请输入管理员密码以进入设备管理:", "权限验证", JOptionPane.QUESTION_MESSAGE);
|
|
|
- if (input != null && input.equalsIgnoreCase("mes")) {
|
|
|
+ if (input != null && input.equals("503833")) {
|
|
|
lastSelectedIndex = selectedIndex;
|
|
|
} else {
|
|
|
if (input != null) {
|