|
|
@@ -40,6 +40,8 @@ public class MesClient extends JFrame {
|
|
|
public static int mes_heart_icon_cycle = 1;
|
|
|
public static String mes_line_sn = ""; // 产线编号
|
|
|
|
|
|
+ public static boolean mes_shield_flag = false; // MES 屏蔽标志
|
|
|
+
|
|
|
//TCP连接
|
|
|
public static NettyClient nettyClient;
|
|
|
//TCP连接状态
|
|
|
@@ -79,6 +81,7 @@ public class MesClient extends JFrame {
|
|
|
public static MesWebView jfxPanel = null;
|
|
|
public static JPanel indexPanelC;
|
|
|
public static MesWebView jfxPanel2 = null;
|
|
|
+ public static JPanel indexPanelD;
|
|
|
public static MesRadio mesRadioHj;
|
|
|
|
|
|
public static JTextField param1;
|
|
|
@@ -86,8 +89,10 @@ public class MesClient extends JFrame {
|
|
|
public static JTextField param3;
|
|
|
public static JTextField param4;
|
|
|
|
|
|
- public static ModbusTcp plcA = new ModbusTcp(1, "192.168.1.7");
|
|
|
- public static ModbusTcp plcB = new ModbusTcp(1, "192.168.1.8");
|
|
|
+ public static ModbusTcp plcA;
|
|
|
+ public static ModbusTcp plcB;
|
|
|
+ public static String curIpA = "";
|
|
|
+ public static String curIpB = "";
|
|
|
// public static ModbusTcp plcA = new ModbusTcp(1, "192.168.1.27");
|
|
|
// public static ModbusTcp plcB = new ModbusTcp(1, "192.168.1.28");
|
|
|
|
|
|
@@ -124,15 +129,17 @@ public class MesClient extends JFrame {
|
|
|
@Override
|
|
|
public void run() {
|
|
|
try{
|
|
|
- //读文件配置
|
|
|
+ // 读文件配置
|
|
|
readProperty();
|
|
|
|
|
|
+ JdbcUtils.getConn();
|
|
|
+
|
|
|
+ initLocalConfig();
|
|
|
+
|
|
|
// 显示界面
|
|
|
mesClientFrame = new MesClient();
|
|
|
mesClientFrame.setVisible(false);
|
|
|
|
|
|
- JdbcUtils.getConn();
|
|
|
-
|
|
|
welcomeWin = new LoginFarme();
|
|
|
welcomeWin.setVisible(true);
|
|
|
|
|
|
@@ -216,6 +223,33 @@ public class MesClient extends JFrame {
|
|
|
System.out.println(mes_gw + ";" + mes_gw_des + ";" + mes_server_ip + ";" + mes_tcp_port + ";" + mes_heart_beat_cycle);
|
|
|
}
|
|
|
|
|
|
+ private static void initLocalConfig() {
|
|
|
+ Map<String, Object> config = JdbcUtils.getConfig();
|
|
|
+ if (config.size() > 0) {
|
|
|
+ aSetNum = (Short) config.get("a_set_num");
|
|
|
+ bSetNum = (Short) config.get("b_set_num");
|
|
|
+ curIpA = (String) config.get("plc_ip_a");
|
|
|
+ curIpB = (String) config.get("plc_ip_b");
|
|
|
+ plcA = new ModbusTcp(1, curIpA);
|
|
|
+ plcB = new ModbusTcp(1, curIpB);
|
|
|
+
|
|
|
+ // 初始化工作面板显示的预设数量
|
|
|
+ if (param1 != null) param1.setText(String.valueOf(aSetNum));
|
|
|
+ if (param3 != null) param3.setText(String.valueOf(bSetNum));
|
|
|
+
|
|
|
+ System.out.println("加载本地配置成功:aSetNum=" + aSetNum + ", bSetNum=" + bSetNum + ", plcA=" + curIpA + ", plcB=" + curIpB);
|
|
|
+ } else {
|
|
|
+ // 兜底默认值
|
|
|
+ aSetNum = 40;
|
|
|
+ bSetNum = 22;
|
|
|
+ curIpA = "192.168.1.7";
|
|
|
+ curIpB = "192.168.1.8";
|
|
|
+ plcA = new ModbusTcp(1, curIpA);
|
|
|
+ plcB = new ModbusTcp(1, curIpB);
|
|
|
+ System.out.println("未找到本地配置,使用默认值");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public static void getPlcParam() {
|
|
|
if(cjTimer!=null) {
|
|
|
cjTimer.cancel();
|
|
|
@@ -416,9 +450,9 @@ public class MesClient extends JFrame {
|
|
|
MesClient.blist = new ArrayList<>();
|
|
|
MesClient.sortB = 0;
|
|
|
MesClient.sortA = 0;
|
|
|
- MesClient.param1.setText("");
|
|
|
+ MesClient.param1.setText(String.valueOf(aSetNum));
|
|
|
MesClient.param2.setText("");
|
|
|
- MesClient.param3.setText("");
|
|
|
+ MesClient.param3.setText(String.valueOf(bSetNum));
|
|
|
MesClient.param4.setText("");
|
|
|
|
|
|
deviceControl = ModbusUtil.getControlModel(plcA);
|
|
|
@@ -533,6 +567,7 @@ public class MesClient extends JFrame {
|
|
|
connect_request_flag = false;
|
|
|
}
|
|
|
|
|
|
+ public static int lastSelectedIndex = 0;
|
|
|
public MesClient() {
|
|
|
setIconImage(Toolkit.getDefaultToolkit().getImage(MesClient.class.getResource("/bg/logo.png")));
|
|
|
setTitle("MES系统客户端:"+mes_gw + "- " + mes_gw_des);
|
|
|
@@ -591,6 +626,26 @@ public class MesClient extends JFrame {
|
|
|
});
|
|
|
settingMenu.add(resetTcpMenu_1);
|
|
|
|
|
|
+ JMenuItem shieldMesMenu = new JMenuItem("MES屏蔽: 关");
|
|
|
+ shieldMesMenu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/menu_setting.png")));
|
|
|
+ shieldMesMenu.setFont(new Font("微软雅黑", Font.PLAIN, 20));
|
|
|
+ shieldMesMenu.addActionListener(new ActionListener() {
|
|
|
+ @Override
|
|
|
+ public void actionPerformed(ActionEvent e) {
|
|
|
+ mes_shield_flag = !mes_shield_flag;
|
|
|
+ if (mes_shield_flag) {
|
|
|
+ shieldMesMenu.setText("MES屏蔽: 开");
|
|
|
+ shieldMesMenu.setForeground(Color.RED);
|
|
|
+ JOptionPane.showMessageDialog(mesClientFrame, "MES屏蔽已开启", "提示", JOptionPane.WARNING_MESSAGE);
|
|
|
+ } else {
|
|
|
+ shieldMesMenu.setText("MES屏蔽: 关");
|
|
|
+ shieldMesMenu.setForeground(Color.BLACK);
|
|
|
+ JOptionPane.showMessageDialog(mesClientFrame, "MES屏蔽已关闭", "提示", JOptionPane.INFORMATION_MESSAGE);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ settingMenu.add(shieldMesMenu);
|
|
|
+
|
|
|
contentPane = new JPanel();
|
|
|
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
|
|
setContentPane(contentPane);
|
|
|
@@ -763,7 +818,7 @@ public class MesClient extends JFrame {
|
|
|
param1 = new JTextField();
|
|
|
param1.setHorizontalAlignment(SwingConstants.CENTER);
|
|
|
param1.setFont(new Font("微软雅黑", Font.PLAIN, 18));
|
|
|
- param1.setText("0");
|
|
|
+ param1.setText(String.valueOf(aSetNum));
|
|
|
param1.setEditable(false);
|
|
|
param1.setBounds(288, 241, 83, 34);
|
|
|
indexPanelA.add(param1);
|
|
|
@@ -795,7 +850,7 @@ public class MesClient extends JFrame {
|
|
|
indexPanelA.add(lblNewLabel_1_2);
|
|
|
|
|
|
param3 = new JTextField();
|
|
|
- param3.setText("0");
|
|
|
+ param3.setText(String.valueOf(bSetNum));
|
|
|
param3.setHorizontalAlignment(SwingConstants.CENTER);
|
|
|
param3.setFont(new Font("微软雅黑", Font.PLAIN, 18));
|
|
|
param3.setEditable(false);
|
|
|
@@ -835,16 +890,124 @@ 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);
|
|
|
|
|
|
tabbedPane.addChangeListener(new ChangeListener() {
|
|
|
@Override
|
|
|
public void stateChanged(ChangeEvent e) {
|
|
|
JTabbedPane tabbedPane = (JTabbedPane) e.getSource();
|
|
|
int selectedIndex = tabbedPane.getSelectedIndex();
|
|
|
- System.out.println("selectedIndex:"+selectedIndex);
|
|
|
-
|
|
|
- if(selectedIndex == 1){
|
|
|
|
|
|
+ if (selectedIndex == 3) { // 设备管理
|
|
|
+ String input = JOptionPane.showInputDialog(mesClientFrame, "请输入管理员密码以进入设备管理:", "权限验证", JOptionPane.QUESTION_MESSAGE);
|
|
|
+ if (input != null && input.equalsIgnoreCase("mes")) {
|
|
|
+ lastSelectedIndex = selectedIndex;
|
|
|
+ } else {
|
|
|
+ if (input != null) {
|
|
|
+ JOptionPane.showMessageDialog(mesClientFrame, "密码错误,请重试", "错误", JOptionPane.ERROR_MESSAGE);
|
|
|
+ }
|
|
|
+ // 跳回上一个页面
|
|
|
+ tabbedPane.setSelectedIndex(lastSelectedIndex);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ lastSelectedIndex = selectedIndex;
|
|
|
}
|
|
|
}
|
|
|
});
|